diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index a4619549..5f3c7331 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"> @@ -126,28 +126,36 @@ const autoNumericSubtotal = new AutoNumeric('#subtotal-sum', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); const autoNumericIVA = new AutoNumeric('#total-iva-sum', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); const autoNumericTotal = new AutoNumeric('#total-sum', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); const autoNumericPendientePago = new AutoNumeric('#pendiente-pago', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); var editor_lineas = new $.fn.dataTable.Editor( { @@ -375,10 +383,10 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ } } }, - {data: "iva",render : (d) => `${d}`}, - {data: "base",render : (d) => `${d}`}, - {data: "total_iva",render : (d) => `${d}`}, - {data: "total",render : (d) => `${d}`}, + {data: "iva", className: "text-end", render : (d) => `${d}`}, + {data: "base", className: "text-end", render : (d) => `${d}`}, + {data: "total_iva", className: "text-end",render : (d) => `${d}`}, + {data: "total", className: "text-end", render : (d) => `${d}`}, ], order: [[1, "asc"]], dom: 't', @@ -417,16 +425,31 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ }); } }); + + $("span.autonumeric-facturas").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if(autoNumericInstance){ + autoNumericInstance.remove() + } + new AutoNumeric(this, { + digitGroupSeparator: ".", + decimalCharacter: ",", + allowDecimalPadding : 'floats', + decimalPlaces: 2, + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, + allowDecimalPadding: true, + }); + }); }, footerCallback: function (row, data, start, end, display) { const table = this.api(); - const intVal = i => typeof i === 'string' ? parseFloat(i.replace(/\./g, '').replace(',', '.')) || 0 : i || 0; - - const totalSubtotal = table.column(8).data().reduce((a, b) => intVal(a) + intVal(b), 0); - 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); + const totalSubtotal = table.column(8).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0); + const totalIVA = table.column(9).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0); + const totalTotal = table.column(10).data().reduce((a, b) => parseFloat(a) + parseFloat(b), 0); autoNumericSubtotal.set(totalSubtotal); autoNumericIVA.set(totalIVA); diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php index fc891a6d..78cbed7d 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php @@ -22,12 +22,12 @@ - Total cobrado: - + Total cobrado: + - Total pendiente: - + Total pendiente: + @@ -147,6 +147,8 @@ editor_pagos.on('open',(event)=>{ allowDecimalPadding : 'floats', decimalPlaces: 2, unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); }) @@ -189,14 +191,18 @@ const autoNumericTotalCobrado = new AutoNumeric('#totalCobrado-sum', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); const autoNumericPendienteCobro = new AutoNumeric('#pendienteCobro-sum', 0, { decimalPlaces: 2, digitGroupSeparator: ',', decimalCharacter: '.', - unformatOnSubmit: true + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, }); var tablePagos = $('#tableOfLineasPagos').DataTable({ @@ -237,7 +243,11 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : ''; } }, - {data: "total",render : (d) => `${d}`}, + { + data: "total", + className: "text-end", + render : (d) => `${d}` + }, ], order: [[1, "asc"]], dom: 't', @@ -270,14 +280,27 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ }, ], + drawCallback: function (settings) { + $("span.autonumeric-pagos").each(function () { + let autoNumericInstance = AutoNumeric.getAutoNumericElement(this) + if(autoNumericInstance){ + autoNumericInstance.remove() + } + new AutoNumeric(this, { + digitGroupSeparator: ".", + decimalCharacter: ",", + allowDecimalPadding : 'floats', + decimalPlaces: 2, + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, + allowDecimalPadding: true, + }); + }); + }, footerCallback: function (row, data, start, end, display) { var api = this.api(); - var intVal = function (i) { - // Convertir a número o devolver 0 si no es válido - return typeof i === 'string' ? i.replace(/[\$,]/g, '')*1 : typeof i === 'number' ? i : 0; - }; - var filas = []; api.rows().every(function() { var data = this.data(); @@ -287,7 +310,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ }); var totalPagos = filas .reduce(function(a, data) { - return a + intVal(data['total']); // Aquí asumimos que la columna 6 está en el índice 5 + return parseFloat(a) + parseFloat(data['total']); }, 0); var filas = []; @@ -299,7 +322,7 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ }); var totalPendiente = filas .reduce(function(a, data) { - return a + intVal(data['total']); // Aquí asumimos que la columna 6 está en el índice 5 + return parseFloat(a) + parseFloat(data['total']); }, 0); // Update footer