Creando presupuestos encuandernado

This commit is contained in:
imnavajas
2023-10-03 15:39:47 +02:00
parent 26e9e7c27b
commit 080bc225a1
9 changed files with 459 additions and 23 deletions

View File

@ -83,7 +83,18 @@
</div>
<div class="tab-pane fade" id="servicios-encuadernacion" role="tabpanel">
<h3>Proximanente</h3>
<table id="tableOfServiciosEncuadernacion" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Tarifaencuadernacion.tarifaaencuadernacion') ?></th>
<th><?= lang('Presupuestos.precioUnidad') ?></th>
<th><?= lang('Presupuestos.precioTotal') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="servicios-manipulado" role="tabpanel">
@ -137,7 +148,7 @@
"name": "tarifa_acabado_id",
"type": "select"
}, {
"name": "precio_unitario"
"name": "precio_unidad"
}, {
"name": "precio_total"
}, {
@ -278,3 +289,163 @@
<?= $this->endSection() ?>
<!------------------------------------------------------->
<!-- Código JS comportamiento tabla servicios acabado. -->
<!------------------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
const lastColNr2 = $('#tableOfServiciosEncuadernacion').find("tr:first th").length - 1;
editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfPresupuestoEncuadernaciones') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfServiciosEncuadernacion",
idSrc: 'id',
fields: [ {
"name": "tarifa_encuadernado_id",
"type": "select"
}, {
"name": "precio_unidad"
}, {
"name": "precio_total"
}, {
"name": "presupuesto_id",
"type": "hidden"
},
]
} );
// Generación de la lista de servicios de acabado (id, nombre)
const encuadernadosList = <?php echo json_encode($serviciosEncuadernacion); ?>;
editor.field( 'tarifa_encuadernado_id' ).update( encuadernadosList );
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['presupuesto_id'] = id;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['presupuesto_id'] = id;
}
}
});
editor.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
});
editor.on( 'submitSuccess', function ( e, json, data, action ) {
theTable.clearPipeline();
theTable.draw();
});
// Activate an inline edit on click of a table cell
$('#tableOfServiciosEncuadernacion').on( 'click', 'tbody span.edit', function (e) {
editor.inline(
theTable.cells(this.parentNode.parentNode, '*').nodes(),
{
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
submitTrigger: 'span.edit',
submit: 'allIfChanged'
}
);
} );
// Delete row
$('#tableOfServiciosEncuadernacion').on( 'click', 'tbody span.remove', function (e) {
Swal.fire({
title: '<?= lang('Basic.global.sweet.sureToDeleteTitle', [mb_strtolower(lang('Basic.global.sweet.line'))]) ?>',
text: '<?= lang('Basic.global.sweet.sureToDeleteText') ?>',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '<?= lang('Basic.global.sweet.deleteConfirmationButton') ?>',
cancelButtonText: '<?= lang('Basic.global.Cancel') ?>',
cancelButtonColor: '#d33'
})
.then((result) => {
const dataId = $(this).data('id');
const row = $(this).closest('tr');
if (result.value) {
editor
.create( false )
.edit( this.parentNode, false)
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
.set( 'is_deleted', 1 )
.submit();
}
});
});
var theTable = $('#tableOfServiciosEncuadernacion').DataTable( {
serverSide: true,
processing: true,
autoWidth: true,
responsive: true,
lengthMenu: [ 5, 10, 25],
order: [[ 0, "asc" ], [ 1, "asc" ]],
pageLength: 10,
lengthChange: true,
searching: false,
paging: true,
info: false,
dom: '<"mt-4"><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfPresupuestoEncuadernaciones') ?>',
data: {
id_presupuesto: id,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns: [
{'data': 'tarifa_encuadernado_id',
render: function(data, type, row, meta) {
var value = encuadernadosList.find(element => element.value === data);
return value['label'];
},
},
{ 'data': 'precio_unidad' },
{ 'data': 'precio_total' },
{
data: actionBtns,
className: 'row-edit dt-center'
}
],
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNr2]
},
{
"orderData": [ 0, 1 ],
"targets": 0
},
],
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
},
buttons: [ {
className: 'btn btn-primary float-end me-sm-3 me-1',
extend: "createInline",
editor: editor,
formOptions: {
submitTrigger: -1,
submitHtml: '<i class="ti ti-device-floppy"/>'
}
} ]
} );
<?= $this->endSection() ?>