From 7139bb377c56e5ddb38bbab3e39c408ab2d79fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 10 Apr 2025 15:34:14 +0200 Subject: [PATCH] falta autonumeric --- ci4/app/Controllers/Facturacion/Facturas.php | 5 +- .../Facturacion/FacturasLineas.php | 16 +- .../Controllers/Facturacion/FacturasPagos.php | 5 +- ...4-09-173000_RemovePrecioUnidadFacturas.php | 24 ++ .../Entities/Facturas/FacturaLineaEntity.php | 2 - ci4/app/Models/Facturas/FacturaLineaModel.php | 5 +- .../form/facturas/_facturaLineasItems.php | 224 +++++++----------- .../form/facturas/_pagosFacturasItems.php | 6 +- 8 files changed, 126 insertions(+), 161 deletions(-) create mode 100644 ci4/app/Database/Migrations/2024-04-09-173000_RemovePrecioUnidadFacturas.php diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index 9469b5ec..b9c445bc 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -692,7 +692,9 @@ class Facturas extends \App\Controllers\BaseResourceController // Se aƱade la linea de factura $descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id); $cantidad = intval($presupuesto->tirada) - intval($model_factura->getCantidadLineaPedidoFacturada($linea->id)); - $base = $cantidad * floatval($presupuesto->total_precio_unidad); + $base = + floatval($presupuesto->total_aceptado_revisado && $presupuesto->total_aceptado_revisado != 0 ? + $presupuesto->total_aceptado_revisado : $presupuesto->total_aceptado); $base = round($base, 2); $total_iva = $base * ($presupuesto->iva_reducido == 1 ? 0.04 : 0.21); // se redondea a dos decimales @@ -704,7 +706,6 @@ class Facturas extends \App\Controllers\BaseResourceController 'pedido_linea_impresion_id' => $linea->pedido_id, 'descripcion' => $descripcion[0]->concepto, 'cantidad' => $cantidad, - 'precio_unidad' => $presupuesto->total_precio_unidad, 'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21, 'base' => $base, 'total_iva' => $total_iva, diff --git a/ci4/app/Controllers/Facturacion/FacturasLineas.php b/ci4/app/Controllers/Facturacion/FacturasLineas.php index 21ae2c0a..42a00d05 100644 --- a/ci4/app/Controllers/Facturacion/FacturasLineas.php +++ b/ci4/app/Controllers/Facturacion/FacturasLineas.php @@ -101,15 +101,6 @@ class FacturasLineas extends \App\Controllers\BaseResourceController ->validator('Validate::notEmpty', array( 'message' => lang('Facturas.validation.requerido')) ), - Field::inst( 'precio_unidad' ) - ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') - ->validator('Validate::numeric', array( - "decimal" => ',', - 'message' => lang('Facturas.validation.decimal')) - ) - ->validator('Validate::notEmpty', array( - 'message' => lang('Facturas.validation.requerido')) - ), Field::inst( 'iva' ) ->validator('Validate::numeric', array( 'message' => lang('Facturas.validation.numerico')) @@ -128,7 +119,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController $totales = $this->generate_totales( $values['factura_id'], $values['pedido_linea_impresion_id'], - $values['precio_unidad'], + $values['total'], $values['iva'], $values['cantidad'], $values['old_cantidad']); @@ -152,7 +143,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController $totales = $this->generate_totales( $values['factura_id'], $values['pedido_linea_impresion_id'], - $values['precio_unidad'], + $values['total'], $values['iva'], $values['cantidad'], $values['old_cantidad']); @@ -203,7 +194,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController $model->updateTotales($factura_id); } - private function generate_totales($factura_id, $pedido_linea_id, $precio_unidad, $iva, $cantidad, $old_cantidad) + private function generate_totales($factura_id, $pedido_linea_id, $total, $iva, $cantidad, $old_cantidad) { // si es una linea que se refiere a pedido @@ -214,6 +205,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController // se calcula y se actualiza el subtotal, total_iva y total // redondeando a 4 decimales el precio_unidad y a dos el resto + $precio_unidad = round($total / $old_cantidad, 4); $base = round($precio_unidad * $cantidad, 2); $total_iva = round($base * $iva / 100, 2); $total = round($base + $total_iva, 2); diff --git a/ci4/app/Controllers/Facturacion/FacturasPagos.php b/ci4/app/Controllers/Facturacion/FacturasPagos.php index a7559933..42a46009 100644 --- a/ci4/app/Controllers/Facturacion/FacturasPagos.php +++ b/ci4/app/Controllers/Facturacion/FacturasPagos.php @@ -57,10 +57,7 @@ class FacturasPagos extends \App\Controllers\BaseResourceController ->fields( Field::inst( 'id' ), Field::inst( 'forma_pago_id' ), - Field::inst( 'notes' ) - ->validator('Validate::notEmpty', array( - 'message' => lang('Facturas.validation.requerido')) - ), + Field::inst( 'notes' ), Field::inst( 'fecha_pago_at' ) ->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) ) ->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) ) diff --git a/ci4/app/Database/Migrations/2024-04-09-173000_RemovePrecioUnidadFacturas.php b/ci4/app/Database/Migrations/2024-04-09-173000_RemovePrecioUnidadFacturas.php new file mode 100644 index 00000000..7f2e0d75 --- /dev/null +++ b/ci4/app/Database/Migrations/2024-04-09-173000_RemovePrecioUnidadFacturas.php @@ -0,0 +1,24 @@ +forge->dropColumn('facturas_lineas', 'precio_unidad'); + } + + public function down() + { + $fields = [ + 'precio_unidad' => [ + 'type' => 'DOUBLE', + 'null' => false, + ], + ]; + $this->forge->addColumn('facturas_lineas', $fields); + } +} diff --git a/ci4/app/Entities/Facturas/FacturaLineaEntity.php b/ci4/app/Entities/Facturas/FacturaLineaEntity.php index 7ce467bb..87f6365c 100644 --- a/ci4/app/Entities/Facturas/FacturaLineaEntity.php +++ b/ci4/app/Entities/Facturas/FacturaLineaEntity.php @@ -12,7 +12,6 @@ class FacturaLineaEntity extends \CodeIgniter\Entity\Entity 'pedido_maquetacion_id' => null, 'descripcion' => null, 'cantidad' => null, - 'precio_unidad' => null, 'iva' => null, 'base' => null, 'total_iva' => null, @@ -29,7 +28,6 @@ class FacturaLineaEntity extends \CodeIgniter\Entity\Entity 'pedido_linea_impresion_id' => 'int', 'pedido_maquetacion_id' => 'int', 'cantidad' => 'float', - 'precio_unidad' => 'float', 'iva' => 'float', 'base' => 'float', 'total_iva' => 'float', diff --git a/ci4/app/Models/Facturas/FacturaLineaModel.php b/ci4/app/Models/Facturas/FacturaLineaModel.php index 0254c301..82888d06 100644 --- a/ci4/app/Models/Facturas/FacturaLineaModel.php +++ b/ci4/app/Models/Facturas/FacturaLineaModel.php @@ -14,7 +14,6 @@ class FacturaLineaModel extends \App\Models\BaseModel { 'pedido_maquetacion_id', 'descripcion', 'cantidad', - 'precio_unidad', 'iva', 'base', 'total_iva', @@ -38,7 +37,7 @@ class FacturaLineaModel extends \App\Models\BaseModel { ->select( "t1.id AS id, t1.factura_id AS factura_id, t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id, - t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva, + t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.iva AS iva, t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data, t2.pedido_id AS pedido_id, t3.total_aceptado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible, t6.cantidad AS cantidad_albaran" @@ -89,7 +88,7 @@ class FacturaLineaModel extends \App\Models\BaseModel { ->select( "t1.id AS id, t1.factura_id AS factura_id, t1.pedido_linea_impresion_id AS pedido_linea_impresion_id, t1.pedido_maquetacion_id AS pedido_maquetacion_id, - t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.precio_unidad AS precio_unidad, t1.iva AS iva, + t1.descripcion AS descripcion, t1.cantidad as cantidad, t1.iva AS iva, t1.base AS base, t1.total_iva AS total_iva, t1.total AS total, t1.data AS data" ) ->where("t1.factura_id", $factura_id) diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index 3ef7a7d4..b559f2be 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php @@ -20,7 +20,6 @@ - @@ -31,25 +30,25 @@ - Subtotal: + Subtotal: - I.V.A.: + I.V.A.: - Total: + Total: - serie_id == 7 || $facturaEntity->serie_id == 9)? "style='display:none;'":"" ?> colspan="9" style="text-align:right">Pendiente de pago: + 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"> @@ -79,56 +78,52 @@ section('additionalInlineJs') ?> const actionBtns = function(data) { - - // se comprueba si data es null - estado != 'borrador') :?> - if (data.pedido_id != null) { - return ` -
-
- -
-
- `; - } - else - { - return ``; - } - + estado != 'borrador') : ?> + if (data.pedido_id != null) { + return ` +
+
+ +
+
+ `; + } else { + return ``; + } - if (data.pedido_id === null) { - return ` - -
-
- - - + if (data.pedido_id === null) { + return ` +
+
+
+ + + +
+
-
- `; - } - else{ - return ` -
-
-
- - - + `; + } else { + return ` +
+
+
+ + + +
+
+
+ +
-
-
- -
-
- `; - } + `; + } }; + var editor_lineas = new $.fn.dataTable.Editor( { ajax: { url: "", @@ -153,14 +148,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: { @@ -310,7 +297,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
- +
`; @@ -366,7 +353,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,7 +377,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ }, { visible: false, - targets: [1, 2, 3, 4, 10, 11] + targets: [1, 2, 3, 4, 9, 10] } ], @@ -400,85 +386,54 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ this.api().columns.adjust(); }, 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); + + $('#subtotal-sum').html(totalSubtotal.toFixed(2)); + $('#total-iva-sum').html(totalIVA.toFixed(2)); + $('#total-sum').html(totalTotal.toFixed(2)); + + estado == 'borrador') :?> + var pendientePago = totalTotal; + var total_pagos = 0; + + var total_pagos = parseFloat($('#totalCobrado-sum').html().replace(',', '.')) || 0; + var pendientePago = totalTotal - total_pagos; + + + if (isNaN(pendientePago)) pendientePago = 0; + + $('#pendiente-pago').html(pendientePago.toFixed(2)); + + $.ajax({ + url: 'id) ?>', + method: 'POST', + data: { + base: totalSubtotal, + total: totalTotal, + total_pagos: total_pagos, + pendiente: pendientePago, + : v + } + }).done(function (data) { + if (data.estado_pago === 'pagada') { + $('#estado_pago_text').text('').css('color', 'green'); + } else { + $('#estado_pago_text').text('').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: 'id) ?>', - method: 'POST', - data: { - base: totalSubtotal, - total: totalTotal, - total_pagos: total_pagos, - pendiente: pendientePago, - : v - } - }).done((data, textStatus, jqXHR) => { - if(data.estado_pago == 'pagada'){ - $('#estado_pago_text').text(''); - $('#estado_pago_text').css('color', 'green'); - } - else{ - $('#estado_pago_text').text(''); - $('#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 +532,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..7042589c 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php @@ -281,21 +281,21 @@ function updateFooterLineas(table){ // Total over all pages var totalSubtotal = table - .column(9) + .column(8) .data() .reduce(function (a, b) { return intVal(a) + intVal(b); }, 0); var totalIVA = table - .column(10) + .column(9) .data() .reduce(function (a, b) { return intVal(a) + intVal(b); }, 0); var totalTotal = table - .column(11) + .column(10) .data() .reduce(function (a, b) { return intVal(a) + intVal(b);