From 026a109b5e41abe7ba7c093a0eb2bef1cbd971fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 10 Apr 2025 16:58:54 +0200 Subject: [PATCH] terminado --- .../form/facturas/_facturaLineasItems.php | 136 +++++++++++------- .../form/facturas/_pagosFacturasItems.php | 116 ++++++++------- 2 files changed, 148 insertions(+), 104 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index b559f2be..a4619549 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php @@ -31,25 +31,25 @@ Subtotal: - + I.V.A.: - + Total: - + serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="8" style="text-align:right">Pendiente de pago: - serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"> + serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> id="pendiente-pago"> @@ -122,7 +122,33 @@ const actionBtns = function(data) { }; +const autoNumericSubtotal = new AutoNumeric('#subtotal-sum', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); +const autoNumericIVA = new AutoNumeric('#total-iva-sum', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); + +const autoNumericTotal = new AutoNumeric('#total-sum', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); + +const autoNumericPendientePago = new AutoNumeric('#pendiente-pago', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); var editor_lineas = new $.fn.dataTable.Editor( { ajax: { @@ -174,56 +200,52 @@ var editor_lineas = new $.fn.dataTable.Editor( { var old_cantidad = 0; editor_lineas.on('open', (event) => { - $("input.autonumeric").each(function () { - let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) - if (autoNumericInstance) { - autoNumericInstance.remove() + $("input.autonumeric").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if (autoNumericInstance) { + autoNumericInstance.remove() - } - new AutoNumeric(this, { - decimalCharacter: ",", - digitGroupSeparator: ".", - allowDecimalPadding : 'floats', - decimalPlaces: 2, - unformatOnSubmit: true, - }); - }) + } + new AutoNumeric(this, { + decimalCharacter: ",", + digitGroupSeparator: ".", + allowDecimalPadding : 'floats', + decimalPlaces: 2, + unformatOnSubmit: true, + }); }) - editor_lineas.on('preSubmit', (e, d, type) => { - if (d.data) { - Object.keys(d.data).forEach(function (key) { - // Find all elements with class .autonumeric - $("input.autonumeric").each(function () { - let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) - if (autoNumericInstance) { - // Get raw value and update the corresponding field - let rawValue = autoNumericInstance.getNumericString(); - d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used - } - }); - }); + }) +editor_lineas.on('preSubmit', (e, d, type) => { + if (d.data) { + if ( type === 'create'){ + d.data[0]['factura_id'] = id ?>; + d.data[0]['old_cantidad'] = null; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['factura_id'] = id ?>; + d.data[v]['old_cantidad'] = old_cantidad; } - }) + } + Object.keys(d.data).forEach(function (key) { + // Find all elements with class .autonumeric + $("input.autonumeric").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if (autoNumericInstance) { + // Get raw value and update the corresponding field + let rawValue = autoNumericInstance.getNumericString(); + d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used + } + }); + }); + } +}) editor_lineas.on( 'preEdit', function ( e, json, data, id ) { old_cantidad = data.cantidad; }); -editor_lineas.on( 'preSubmit', function ( e, d, type ) { - - if ( type === 'create'){ - d.data[0]['factura_id'] = id ?>; - d.data[0]['old_cantidad'] = null; - } - else if(type === 'edit' ) { - for (v in d.data){ - d.data[v]['factura_id'] = id ?>; - d.data[v]['old_cantidad'] = old_cantidad; - } - } -}); - editor_lineas.on( 'postSubmit', function ( e, json, data, action ) { @@ -297,7 +319,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
- +
`; @@ -384,6 +406,18 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ drawCallback: function() { $(this.api().table().container()).find('table').css('width', '100%'); this.api().columns.adjust(); + + $('.autonumeric-datatable-lineas').each(function() { + if (!$(this).data('autoNumeric')) { + new AutoNumeric(this, { + decimalPlaces: 2, + digitGroupSeparator: '.', + decimalCharacter: ',', + unformatOnSubmit: true + }); + } + }); + }, footerCallback: function (row, data, start, end, display) { const table = this.api(); @@ -394,21 +428,21 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ const totalIVA = table.column(9).data().reduce((a, b) => intVal(a) + intVal(b), 0); const totalTotal = table.column(10).data().reduce((a, b) => intVal(a) + intVal(b), 0); - $('#subtotal-sum').html(totalSubtotal.toFixed(2)); - $('#total-iva-sum').html(totalIVA.toFixed(2)); - $('#total-sum').html(totalTotal.toFixed(2)); + autoNumericSubtotal.set(totalSubtotal); + autoNumericIVA.set(totalIVA); + autoNumericTotal.set(totalTotal); estado == 'borrador') :?> var pendientePago = totalTotal; var total_pagos = 0; - var total_pagos = parseFloat($('#totalCobrado-sum').html().replace(',', '.')) || 0; + var total_pagos = autoNumericTotalCobrado.getNumber(); var pendientePago = totalTotal - total_pagos; if (isNaN(pendientePago)) pendientePago = 0; - $('#pendiente-pago').html(pendientePago.toFixed(2)); + autoNumericPendientePago.set(pendientePago); $.ajax({ url: 'id) ?>', diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php index 7042589c..fc891a6d 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php @@ -73,7 +73,7 @@ const actionBtns_pagos = function(data) { } -var editor_pagos = new $.fn.dataTable.Editor( { +const editor_pagos = new $.fn.dataTable.Editor( { ajax: { url: "", headers: { @@ -99,8 +99,10 @@ var editor_pagos = new $.fn.dataTable.Editor( { { name: "total", attr: { - style: "min-width: 65px;" - } + style: "min-width: 65px;", + class :"autonumeric", + name: 'total' + }, }, { name: "fecha_pago_at", @@ -132,17 +134,46 @@ var editor_pagos = new $.fn.dataTable.Editor( { ] }); +editor_pagos.on('open',(event)=>{ + $("input.autonumeric").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if(autoNumericInstance){ + autoNumericInstance.remove() + } + new AutoNumeric(this, { + digitGroupSeparator: ".", + decimalCharacter: ",", + allowDecimalPadding : 'floats', + decimalPlaces: 2, + unformatOnSubmit: true, + + }); + }) +}) editor_pagos.on( 'preSubmit', function ( e, d, type ) { - if ( type === 'create'){ - d.data[0]['factura_id'] = id ?>; - } - else if(type === 'edit' ) { - for (v in d.data){ - d.data[v]['factura_id'] = id ?>; + if (d.data) { + if ( type === 'create'){ + d.data[0]['factura_id'] = id ?>; } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['factura_id'] = id ?>; + } + } + Object.keys(d.data).forEach(function (key) { + // Find all elements with class .autonumeric + $("input.autonumeric").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if (autoNumericInstance) { + // Get raw value and update the corresponding field + let rawValue = autoNumericInstance.getNumericString(); + d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used + } + }); + }); } }); @@ -154,6 +185,19 @@ editor_pagos.on( 'postSubmit', function ( e, json, data, action ) { tablePagos.draw(); }); +const autoNumericTotalCobrado = new AutoNumeric('#totalCobrado-sum', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); + +const autoNumericPendienteCobro = new AutoNumeric('#pendienteCobro-sum', 0, { + decimalPlaces: 2, + digitGroupSeparator: ',', + decimalCharacter: '.', + unformatOnSubmit: true +}); var tablePagos = $('#tableOfLineasPagos').DataTable({ processing: true, @@ -193,7 +237,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : ''; } }, - {data: "total"}, + {data: "total",render : (d) => `${d}`}, ], order: [[1, "asc"]], dom: 't', @@ -259,8 +303,8 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ }, 0); // Update footer - $('#totalCobrado-sum').html(totalPagos.toFixed(2)); - $('#pendienteCobro-sum').html(totalPendiente.toFixed(2)); + autoNumericTotalCobrado.set(totalPagos); + autoNumericPendienteCobro.set(totalPendiente); // call footerCallback of the other table if (typeof tableLineas !== 'undefined') { @@ -269,63 +313,29 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ } }); + function updateFooterLineas(table){ - // Remove the formatting to get integer data for summation - var intVal = function (i) { - return typeof i === 'string' ? - i.replace(/[\$,]/g, '')*1 : - typeof i === 'number' ? - i : 0; - }; - - // Total over all pages - var totalSubtotal = table - .column(8) - .data() - .reduce(function (a, b) { - return intVal(a) + intVal(b); - }, 0); - - var totalIVA = table - .column(9) - .data() - .reduce(function (a, b) { - return intVal(a) + intVal(b); - }, 0); - - var totalTotal = table - .column(10) - .data() - .reduce(function (a, b) { - return intVal(a) + intVal(b); - }, 0); - - // Update footer - $('#subtotal-sum').html(totalSubtotal.toFixed(2)); - $('#total-iva-sum').html(totalIVA.toFixed(2)); - $('#total-sum').html(totalTotal.toFixed(2)); - // Assuming pendiente de pago is totalTotal - totalIVA for this example estado == 'borrador') :?> - var pendientePago = totalTotal ; + var pendientePago = autoNumericTotal.getNumber(); var total_pagos = 0; - var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2); - var pendientePago = totalTotal - total_pagos; + var total_pagos = autoNumericTotalCobrado.getNumber(); + var pendientePago = autoNumericTotal.getNumber() - total_pagos; // Se comprueba si pendientePago es un numero o NAN if(isNaN(pendientePago)){ pendientePago = 0; } - $('#pendiente-pago').html(pendientePago.toFixed(2)); + autoNumericPendientePago.set(pendientePago); $.ajax({ url: 'id) ?>', method: 'POST', data: { - base: totalSubtotal, - total: totalTotal, + base: autoNumericSubtotal.getNumber(), + total: autoNumericTotal.getNumber(), total_pagos: total_pagos, pendiente: pendientePago }