Avance en Servicios de acabado

This commit is contained in:
imnavajas
2023-10-03 00:23:00 +02:00
parent 3fcf88aa2a
commit 26e9e7c27b
12 changed files with 868 additions and 953 deletions

View File

@ -247,7 +247,7 @@
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button id="accordion-button-int-plana" type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionCompInteriorPlanaTip" aria-expanded="false" aria-controls="accordionCompInteriorPlanaTip">
<h6><?= lang("Presupuestos.compInteriorPlana") ?></h4>
<h4><?= lang("Presupuestos.compInteriorPlana") ?></h4>
</button>
</h2>
@ -301,7 +301,7 @@
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingTwo">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionCompInteriorRotativaTip" aria-expanded="false" aria-controls="accordionCompInteriorRotativaTip">
<h6><?= lang("Presupuestos.compInteriorRotativa") ?></h4>
<h4><?= lang("Presupuestos.compInteriorRotativa") ?></h4>
</button>
</h2>
@ -353,7 +353,7 @@
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingThree">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionCompCubiertaSobrecubiertaTip" aria-expanded="false" aria-controls="accordionCompCubiertaSobrecubiertaTip">
<h6><?= lang("Presupuestos.cubierta") ?></h4>
<h4><?= lang("Presupuestos.cubierta") ?></h4>
</button>
</h2>

View File

@ -64,7 +64,18 @@
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="servicios-acabado" role="tabpanel">
<h3>Proximanente</h3>
<table id="tableOfServiciosAcabado" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('Tarifaacabado.tarifaacabado') ?></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-preimpresion" role="tabpanel">
@ -85,4 +96,185 @@
</div> <!-- //.accordion-body -->
</div> <!-- //.accordion-collapse -->
</div> <!-- //.accordion-item -->
</div> <!-- //.accordion -->
</div> <!-- //.accordion -->
<!------------------------------------------------------->
<!-- Código JS comportamiento tabla servicios acabado. -->
<!------------------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
const lastColNr = $('#tableOfServiciosAcabado').find("tr:first th").length - 1;
const url = window.location.href;
const url_parts = url.split('/');
if(url_parts[url_parts.length-2] == 'edit'){
id = url_parts[url_parts.length-1];
}
else{
id = 200000; // id=-1
}
const actionBtns = function(data) {
return `
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
`;
};
editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfPresupuestoAcabados') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfServiciosAcabado",
idSrc: 'id',
fields: [ {
"name": "tarifa_acabado_id",
"type": "select"
}, {
"name": "precio_unitario"
}, {
"name": "precio_total"
}, {
"name": "presupuesto_id",
"type": "hidden"
},
]
} );
// Generación de la lista de servicios de acabado (id, nombre)
const acabadosList = <?php echo json_encode($serviciosAcabado); ?>;
editor.field( 'tarifa_acabado_id' ).update( acabadosList );
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
$('#tableOfServiciosAcabado').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
$('#tableOfServiciosAcabado').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 = $('#tableOfServiciosAcabado').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('dataTableOfPresupuestoAcabados') ?>',
data: {
id_presupuesto: id,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns: [
{'data': 'tarifa_acabado_id',
render: function(data, type, row, meta) {
var value = acabadosList.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: [lastColNr]
},
{
"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() ?>

View File

@ -477,11 +477,9 @@
<?= $this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/sk-datatables.css') ?>">
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
@ -493,6 +491,8 @@
<?= $this->section('additionalExternalJs') ?>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/select/1.7.0/js/dataTables.select.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.print.min.js"></script>
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.min.js') ?>"></script>
<?=$this->endSection() ?>