-
-
-
-
-
+ `;
+ } else {
+ return `
+
-
-
-
-
-
- `;
- }
+ `;
+ }
};
+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: {
@@ -153,14 +174,6 @@ var editor_lineas = new $.fn.dataTable.Editor( {
rows: 5,
style: "height: 120px;"
}
- }, {
- name: "precio_unidad",
- attr: {
- type: "text",
- name : "precio_unidad",
- class :"autonumeric",
- style: "min-width: 65px;"
- }
}, {
name: "iva",
attr: {
@@ -187,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'] = = $facturaEntity->id ?>;
+ d.data[0]['old_cantidad'] = null;
+ }
+ else if(type === 'edit' ) {
+ for (v in d.data){
+ d.data[v]['factura_id'] = = $facturaEntity->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'] = = $facturaEntity->id ?>;
- d.data[0]['old_cantidad'] = null;
- }
- else if(type === 'edit' ) {
- for (v in d.data){
- d.data[v]['factura_id'] = = $facturaEntity->id ?>;
- d.data[v]['old_cantidad'] = old_cantidad;
- }
- }
-});
-
editor_lineas.on( 'postSubmit', function ( e, json, data, action ) {
@@ -310,7 +319,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
-
+
`;
@@ -366,7 +375,6 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
}
}
},
- {data: "precio_unidad",render : (d) => `
${d}`},
{data: "iva",render : (d) => `
${d}`},
{data: "base",render : (d) => `
${d}`},
{data: "total_iva",render : (d) => `
${d}`},
@@ -391,94 +399,75 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
},
{
visible: false,
- targets: [1, 2, 3, 4, 10, 11]
+ targets: [1, 2, 3, 4, 9, 10]
}
],
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) {
- updateFooterLineas(this.api());
+ 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);
+
+ autoNumericSubtotal.set(totalSubtotal);
+ autoNumericIVA.set(totalIVA);
+ autoNumericTotal.set(totalTotal);
+
+ estado == 'borrador') :?>
+ var pendientePago = totalTotal;
+ var total_pagos = 0;
+
+ var total_pagos = autoNumericTotalCobrado.getNumber();
+ var pendientePago = totalTotal - total_pagos;
+
+
+ if (isNaN(pendientePago)) pendientePago = 0;
+
+ autoNumericPendientePago.set(pendientePago);
+
+ $.ajax({
+ url: '= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
+ method: 'POST',
+ data: {
+ base: totalSubtotal,
+ total: totalTotal,
+ total_pagos: total_pagos,
+ pendiente: pendientePago,
+ = csrf_token() ?? "token" ?> : = csrf_token() ?>v
+ }
+ }).done(function (data) {
+ if (data.estado_pago === 'pagada') {
+ $('#estado_pago_text').text('= lang('Facturas.pagada') ?>').css('color', 'green');
+ } else {
+ $('#estado_pago_text').text('= lang('Facturas.pendiente') ?>').css('color', 'red');
+ }
+ }).fail(function (jqXHR) {
+ popErrorAlert(jqXHR.responseJSON.messages.error);
+ });
}
+
});
-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(9)
- .data()
- .reduce(function (a, b) {
- return intVal(a) + intVal(b);
- }, 0);
-
- var totalIVA = table
- .column(10)
- .data()
- .reduce(function (a, b) {
- return intVal(a) + intVal(b);
- }, 0);
-
- var totalTotal = table
- .column(11)
- .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 total_pagos = 0;
-
- var total_pagos = parseFloat($('#totalCobrado-sum').html()).toFixed(2);
- var pendientePago = totalTotal - total_pagos;
-
- if(isNaN(pendientePago)){
- pendientePago = 0;
- }
- $('#pendiente-pago').html(pendientePago.toFixed(2));
-
- $.ajax({
- url: '= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
- method: 'POST',
- data: {
- base: totalSubtotal,
- total: totalTotal,
- total_pagos: total_pagos,
- pendiente: pendientePago,
- = csrf_token() ?? "token" ?> : = csrf_token() ?>v
- }
- }).done((data, textStatus, jqXHR) => {
- if(data.estado_pago == 'pagada'){
- $('#estado_pago_text').text('= lang('Facturas.pagada') ?>');
- $('#estado_pago_text').css('color', 'green');
- }
- else{
- $('#estado_pago_text').text('= lang('Facturas.pendiente') ?>');
- $('#estado_pago_text').css('color', 'red');
- }
- }).fail((jqXHR, textStatus, errorThrown) => {
- popErrorAlert(jqXHR.responseJSON.messages.error)
- })
-}
-
// Delete row
$(document).on('click', '.btn-delete', function(e) {
@@ -577,7 +566,6 @@ $(document).on('click', '.btn-excedentes', function(e) {
pedido_id: pedido_id,
pedido_linea_impresion_id: pedido_linea_impresion_id,
pedido_linea_maquetacion_id: pedido_linea_maquetacion_id,
- precio_unidad: row_data.precio_unidad,
descripcion: row_data.descripcion,
iva: row_data.iva,
descuento: row_data.descuento_tirada_flexible,
diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php
index 136d4181..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: "= route_to('editorOfPagosFacturas') ?>",
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'] = = $facturaEntity->id ?>;
- }
- else if(type === 'edit' ) {
- for (v in d.data){
- d.data[v]['factura_id'] = = $facturaEntity->id ?>;
+ if (d.data) {
+ if ( type === 'create'){
+ d.data[0]['factura_id'] = = $facturaEntity->id ?>;
}
+ else if(type === 'edit' ) {
+ for (v in d.data){
+ d.data[v]['factura_id'] = = $facturaEntity->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(9)
- .data()
- .reduce(function (a, b) {
- return intVal(a) + intVal(b);
- }, 0);
-
- var totalIVA = table
- .column(10)
- .data()
- .reduce(function (a, b) {
- return intVal(a) + intVal(b);
- }, 0);
-
- var totalTotal = table
- .column(11)
- .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: '= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
- base: totalSubtotal,
- total: totalTotal,
+ base: autoNumericSubtotal.getNumber(),
+ total: autoNumericTotal.getNumber(),
total_pagos: total_pagos,
pendiente: pendientePago
}
diff --git a/ci4/app/Views/themes/vuexy/pdfs/factura.php b/ci4/app/Views/themes/vuexy/pdfs/factura.php
index 55a05982..66862b0b 100644
--- a/ci4/app/Views/themes/vuexy/pdfs/factura.php
+++ b/ci4/app/Views/themes/vuexy/pdfs/factura.php
@@ -1,5 +1,6 @@
+
@@ -19,175 +20,179 @@
-
-
-
-
-
-
- |
-
-
-
-
-
- | FACTURA Nº: |
- = ($factura->estado == 'draft') ? 'BORRADOR' : $factura->numero ?> |
- FECHA: |
- = $factura->fecha_factura_at ?> |
-
-
-
-
- | Dirección: |
-
-
- | Persona de contacto: |
- = $factura->cliente_direccion ?> |
-
-
- | Razón social: = $factura->cliente ?>
- |
- = $factura->cliente_cp ?>
- , = $factura->cliente_ciudad ?> |
-
-
- | CIF: = $factura->cliente_cif ?> |
- = $factura->cliente_pais ?> |
-
-
-
-
-
-
-
+
+
- | Tipo y Nombre del trabajo |
- Uds. |
- Precio |
- IVA |
- Subtotal |
+
+
+
+ |
-
-
-
- precio_unidad > 0): ?>
-
- |
- = nl2br($linea->descripcion); ?>
- |
-
- = ($linea->cantidad > 0) ? $linea->cantidad : '' ?>
- |
-
- = ($linea->cantidad > 0) ? $linea->precio_unidad : '' ?>
- |
-
- = ($linea->cantidad > 0) ? $linea->iva : '' ?>
- |
-
- = ($linea->cantidad > 0) ? $linea->base : '' ?>
- |
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
+
-
- | BASE |
- IVA |
- TOTAL |
-
-
-
-
- | = $tipo_iva->base ?> € |
- = $tipo_iva->iva ?> % |
- = $tipo_iva->total_iva ?> € |
- = $tipo_iva->total ?> € |
+ FACTURA Nº: |
+ = ($factura->estado == 'draft') ? 'BORRADOR' : $factura->numero ?> |
+ FECHA: |
+ = $factura->fecha_factura_at ?> |
+
+
+
+
+ | Dirección: |
+
+
+ | Persona de contacto: |
+ = $factura->cliente_direccion ?> |
+
+
+ | Razón social:
+ = $factura->cliente ?>
+ |
+ = $factura->cliente_cp ?>
+ , = $factura->cliente_ciudad ?> |
+
+
+ | CIF: = $factura->cliente_cif ?> |
+
+ = $factura->cliente_pais ?> |
-
-
-
- | TOTAL |
- = $factura->total ?> € |
-
-
-
-
-
-
-
- | Vencimiento |
- Fecha |
- Forma de pago |
- BIC / IBAN |
-
-
-
-
- | = $factura->dias_vencimiento ?> días |
- = $factura->vencimiento ?> |
- = $factura->forma_pago ?> |
-
- = ($factura->forma_pago == "Transferencias") ? 'ES33 2100 1134 14 1300319844' : $factura->cliente_ccc ?>
- |
-
-
-
-
-
-