From 014b48e6933c416b238eb49b28ba90f9e3042198 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Wed, 9 Apr 2025 07:04:06 +0200 Subject: [PATCH 01/18] fix user model imports --- .../Controllers/Produccion/Ordentrabajo.php | 39 ++++++++++++------- .../Produccion/OrdenTrabajoEntity.php | 10 ++--- ci4/app/Services/ProductionService.php | 4 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 24d9cf75..103befb3 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -15,6 +15,7 @@ use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\I18n\Time; use CodeIgniter\Validation\Validation; use Config\LogoImpresion; +use Exception; use Hermawan\DataTables\DataTable; use Psr\Log\LoggerInterface; @@ -276,16 +277,26 @@ class Ordentrabajo extends BaseController } public function get_portada_img($orden_trabajo_id) { - $ot = $this->otModel->find($orden_trabajo_id); - if ($ot->portada_path) { - $filePath = WRITEPATH . 'uploads/' . $ot->portada_path; - $mimeType = mime_content_type($filePath); - return $this->response - ->setHeader('Content-Type', $mimeType) - ->setHeader('Content-Length', filesize($filePath)) - ->setBody(file_get_contents($filePath)); - } else { - return $this->response->setJSON(["message" => "Portada error", "error" => "No hay portada"])->setStatusCode(400); + try { + $ot = $this->otModel->find($orden_trabajo_id); + if ($ot->portada_path) { + $filePath = WRITEPATH . 'uploads/' . $ot->portada_path; + if (file_exists($filePath)) { + + $mimeType = mime_content_type($filePath); + return $this->response + ->setHeader('Content-Type', $mimeType) + ->setHeader('Content-Length', filesize($filePath)) + ->setBody(file_get_contents($filePath)); + } else { + throw new Exception('File' . $ot->portada_path . ' does not exist'); + } + } else { + return $this->response->setJSON(["message" => "Portada error", "error" => "No hay portada"])->setStatusCode(400); + } + } catch (\Throwable $th) { + return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode(500); + } } public function planning_rotativa_datatable() @@ -302,8 +313,8 @@ class Ordentrabajo extends BaseController { $q = $this->produccionService->planningPlanaQueryDatatable(); $padreId = $this->request->getGet('padre_id'); - if($padreId){ - $q->where('lg_maquinas.padre_id',$padreId); + if ($padreId) { + $q->where('lg_maquinas.padre_id', $padreId); } return DataTable::of($q) ->edit("tiempo_real_sum", fn($q) => $q->tiempo_real_sum) @@ -372,9 +383,9 @@ class Ordentrabajo extends BaseController $ps = $this->produccionService->init($bodyData["orden_trabajo_id"]); $existingFiles = json_decode($bodyData["oldFiles"]); $ps->deleteOtFiles($existingFiles); - if($files){ + if ($files) { $response = $ps->storeOtFiles($files); - }else{ + } else { $response = null; } return $this->response->setJSON([ diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php index 2ad1b2fc..67861987 100644 --- a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php @@ -2,17 +2,15 @@ namespace App\Entities\Produccion; -use App\Controllers\Produccion\Ordentrabajo; -use App\Database\Migrations\OrdenTrabajoDatesTable; use App\Entities\Pedidos\PedidoEntity; use App\Entities\Usuarios\UserEntity; -use App\Entities\Usuarios\UsersEntity; use App\Models\OrdenTrabajo\OrdenTrabajoDate; use App\Models\OrdenTrabajo\OrdenTrabajoFileModel; use App\Models\OrdenTrabajo\OrdenTrabajoTarea; use App\Models\OrdenTrabajo\OrdenTrabajoUser; use App\Models\Pedidos\PedidoModel; -use App\Models\UserModel; +use App\Models\Usuarios\UserModel; + use CodeIgniter\Entity\Entity; use Picqer\Barcode\Renderers\PngRenderer; use Picqer\Barcode\Types\TypeCode128; @@ -123,7 +121,7 @@ class OrdenTrabajoEntity extends Entity $m = model(OrdenTrabajoFileModel::class); return $m->where('orden_trabajo_id',$this->attributes['id'])->findAll() ?? []; } - public function pedidoEsperaBy() : ?UsersEntity + public function pedidoEsperaBy() : ?UserEntity { $m = model(UserModel::class); if($this->attributes['pedido_espera_by']){ @@ -132,7 +130,7 @@ class OrdenTrabajoEntity extends Entity return null; } } - public function getPedidoEsperaBy(): ?UsersEntity + public function getPedidoEsperaBy(): ?UserEntity { return $this->pedidoEsperaBy(); } diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index bbe61afb..8c9286cd 100644 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -2,7 +2,6 @@ namespace App\Services; -use App\Database\Migrations\ConfigVariablesApp; use App\Entities\Clientes\ClienteEntity; use App\Entities\Pedidos\PedidoEntity; use App\Entities\Presupuestos\PresupuestoEntity; @@ -12,7 +11,6 @@ use App\Models\OrdenTrabajo\OrdenTrabajoDate; use App\Models\OrdenTrabajo\OrdenTrabajoModel; use App\Models\OrdenTrabajo\OrdenTrabajoTarea; use App\Models\OrdenTrabajo\OrdenTrabajoUser; -use App\Models\Usuarios\UserModel; use CodeIgniter\Config\BaseService; use App\Entities\Configuracion\Maquina as MaquinaEntity; use App\Entities\Produccion\OrdenTrabajoFileEntity; @@ -20,10 +18,10 @@ use App\Entities\Produccion\OrdenTrabajoTareaEntity; use App\Models\Configuracion\ConfigVariableModel; use App\Models\Configuracion\MaquinaModel; use App\Models\OrdenTrabajo\OrdenTrabajoFileModel; +use App\Models\Usuarios\UserModel; use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseResult; use CodeIgniter\Database\Exceptions\DatabaseException; -use CodeIgniter\Files\File; use CodeIgniter\HTTP\Files\UploadedFile; use CodeIgniter\I18n\Time; use Exception; From d8cb02271ea4965562457901f9abdd1c0cb3427d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Apr 2025 14:33:35 +0200 Subject: [PATCH 02/18] Actualizado el pdf de facturas para eliminar precio por linea --- ci4/app/Views/themes/vuexy/pdfs/factura.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/pdfs/factura.php b/ci4/app/Views/themes/vuexy/pdfs/factura.php index 55a05982..63017db1 100644 --- a/ci4/app/Views/themes/vuexy/pdfs/factura.php +++ b/ci4/app/Views/themes/vuexy/pdfs/factura.php @@ -66,7 +66,6 @@ Tipo y Nombre del trabajo Uds. - Precio IVA Subtotal @@ -81,9 +80,6 @@ cantidad > 0) ? $linea->cantidad : '' ?> - - cantidad > 0) ? $linea->precio_unidad : '' ?> - cantidad > 0) ? $linea->iva : '' ?> 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 03/18] 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); 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 04/18] 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 } From 64e4f51e13bb28a77faec33b1ed918791622c8e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Apr 2025 22:41:38 +0200 Subject: [PATCH 05/18] Arreglado bug al generar PDF de facturas --- ci4/app/Views/themes/vuexy/pdfs/factura.php | 315 ++++++++++---------- 1 file changed, 162 insertions(+), 153 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/pdfs/factura.php b/ci4/app/Views/themes/vuexy/pdfs/factura.php index 63017db1..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,171 +20,179 @@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FACTURA Nº:estado == 'draft') ? 'BORRADOR' : $factura->numero ?>FECHA:fecha_factura_at ?>
Dirección:
Persona de contacto:cliente_direccion ?>
Razón social: cliente ?> - cliente_cp ?> - , cliente_ciudad ?>
CIF: cliente_cif ?>cliente_pais ?>
- -
- - +
+
- - - - + - - - - precio_unidad > 0): ?> - - - - - - - - - -
- - -
- -
- Sello Solunion - -
- - - +
- - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + -
BASEIVATOTAL
base ?> €iva ?> %total_iva ?> €total ?> €FACTURA Nº:estado == 'draft') ? 'BORRADOR' : $factura->numero ?>FECHA:fecha_factura_at ?>
Dirección:
Persona de contacto:cliente_direccion ?>
Razón social: + cliente ?> + cliente_cp ?> + , cliente_ciudad ?>
CIF: cliente_cif ?> + cliente_pais ?>
- - - - - -
TOTALtotal ?> €
-
- - - - - - - - - - - - - - - - - - -
VencimientoFechaForma de pagoBIC / IBAN
dias_vencimiento ?> díasvencimiento ?>forma_pago ?> - forma_pago == "Transferencias") ? 'ES33 2100 1134 14 1300319844' : $factura->cliente_ccc ?> -
- - - -
+ + + + - + + \ No newline at end of file From 1e339b550302eb5e5c0bd1eb0834b39d71de3f7f Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 11 Apr 2025 06:56:55 +0200 Subject: [PATCH 06/18] delete is_deleted field --- ci4/app/Controllers/Clientes/Cliente.php | 2 +- .../Controllers/Clientes/ClientePrecios.php | 3 -- .../Clienteplantillaprecioslineas.php | 1 - .../2025-04-11-040000_DropIsDeletedField.php | 49 +++++++++++++++++++ .../Models/Clientes/ClienteContactoModel.php | 6 +-- ci4/app/Models/Clientes/ClienteModel.php | 25 +++++----- .../ClientePlantillaPreciosLineasModel.php | 9 ++-- .../Clientes/ClientePlantillaPreciosModel.php | 7 +-- .../Models/Clientes/ClientePreciosModel.php | 19 ++++--- .../Models/Clientes/ClienteUsuariosModel.php | 3 +- .../clientes/cliente/_clienteFormItems.php | 5 +- 11 files changed, 84 insertions(+), 45 deletions(-) create mode 100644 ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 23a7d20f..21a5d3db 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -464,7 +464,7 @@ class Cliente extends \App\Controllers\BaseResourceController return null; } $modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel'); - $plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first(); + $plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("deleted_at", null)->first(); if ($plantilla == false) { return null; } else { diff --git a/ci4/app/Controllers/Clientes/ClientePrecios.php b/ci4/app/Controllers/Clientes/ClientePrecios.php index 61cfb986..49a0b4bf 100755 --- a/ci4/app/Controllers/Clientes/ClientePrecios.php +++ b/ci4/app/Controllers/Clientes/ClientePrecios.php @@ -135,7 +135,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController Field::inst('tipo_impresion'), Field::inst('user_updated_id'), Field::inst('updated_at'), - Field::inst('is_deleted'), Field::inst('tiempo_min') ->getFormatter('Format::toDecimalChar')->setFormatter('Format::fromDecimalChar') ->validator( @@ -205,7 +204,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) { foreach ($data['data'] as $pkey => $values) { // Si no se quiere borrar... - if ($data['data'][$pkey]['is_deleted'] != 1) { $process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min']; $process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max']; $process_data['tipo'] = $data['data'][$pkey]['tipo']; @@ -217,7 +215,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController if (!empty($response)) { return $response; } - } } } }) diff --git a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php index d0b4d98a..f5a29dbc 100755 --- a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php +++ b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php @@ -155,7 +155,6 @@ class Clienteplantillaprecioslineas extends \App\Controllers\BaseResourceControl Field::inst( 'tipo_impresion' ), Field::inst( 'user_updated_id' ), Field::inst( 'deleted_at' ), - Field::inst( 'is_deleted' ), Field::inst( 'updated_at' ), Field::inst( 'tiempo_min' ) ->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar') diff --git a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php new file mode 100644 index 00000000..311fe867 --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php @@ -0,0 +1,49 @@ +db->table('clientes'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('clientes',"is_deleted"); + + $m = $this->db->table('cliente_contactos'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_contactos',"is_deleted"); + + $m = $this->db->table('cliente_precios'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_precios',"is_deleted"); + + $m = $this->db->table('cliente_plantilla_precios_lineas'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_plantilla_precios_lineas',"is_deleted"); + + $m = $this->db->table('cliente_plantilla_precios'); + $m->where('is_deleted',1)->update(['deleted_at' => Time::now()]); + $m->where('is_deleted',0)->update(['deleted_at' => null]); + $this->forge->dropColumn('cliente_plantilla_precios',"is_deleted"); + + + } + + public function down() + { + + } +} diff --git a/ci4/app/Models/Clientes/ClienteContactoModel.php b/ci4/app/Models/Clientes/ClienteContactoModel.php index 5338f71a..5571db67 100755 --- a/ci4/app/Models/Clientes/ClienteContactoModel.php +++ b/ci4/app/Models/Clientes/ClienteContactoModel.php @@ -25,12 +25,12 @@ class ClienteContactoModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClienteContactoEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; protected $updatedField = "updated_at"; - protected $deletedField = 'deleted_at'; public static $labelField = "nombre"; @@ -113,7 +113,7 @@ class ClienteContactoModel extends \App\Models\BaseModel ); $builder->where('t1.cliente_id', $cliente_id); - $builder->where("t1.is_deleted", 0); + $builder->where("t1.deleted_at", null); $builder->join("clientes t2", "t1.cliente_id = t2.id", "left"); return empty($search) diff --git a/ci4/app/Models/Clientes/ClienteModel.php b/ci4/app/Models/Clientes/ClienteModel.php index 12df2831..57de29a4 100755 --- a/ci4/app/Models/Clientes/ClienteModel.php +++ b/ci4/app/Models/Clientes/ClienteModel.php @@ -2,6 +2,8 @@ namespace App\Models\Clientes; +use App\Entities\Clientes\ClienteEntity; + class ClienteModel extends \App\Models\BaseModel { protected $table = "clientes"; @@ -57,13 +59,11 @@ class ClienteModel extends \App\Models\BaseModel "comentarios_tirada_flexible", "margen_plantilla_id", "comentarios", - "is_deleted", - "deleted_at", "user_created_id", "user_update_id", ]; - protected $returnType = "App\Entities\Clientes\ClienteEntity"; - + protected $returnType = ClienteEntity::class; + protected $useSoftDeletes = true; protected $deletedField = 'deleted_at'; public static $labelField = "nombre"; @@ -197,10 +197,7 @@ class ClienteModel extends \App\Models\BaseModel "fecha_vencimiento" => [ "max_length" => "Clientes.validation.fecha_vencimiento.max_length", ], - "is_deleted" => [ - "integer" => "Clientes.validation.is_deleted.integer", - "required" => "Clientes.validation.is_deleted.required", - ], + "limite_credito" => [ "decimal" => "Clientes.validation.limite_credito.decimal", "required" => "Clientes.validation.limite_credito.required", @@ -287,7 +284,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id" ) - ->where("is_deleted", 0);; + ->where("t1.deleted_at", null);; $builder->join("users t5", "t1.comercial_id = t5.id", "left"); $builder->join("formas_pago t7", "t1.forma_pago_id = t7.id", "left"); @@ -315,7 +312,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.limite_credito AS limite_credito" ) - ->where("t1.is_deleted", 0) + ->where("t1.deleted_at", null) ->where("t1.id", $cliente_id); $limite = $builder->get()->getResultObject(); @@ -340,7 +337,7 @@ class ClienteModel extends \App\Models\BaseModel t2.nombre AS cliente_pais, t1.cp AS cliente_cp, t1.ciudad AS cliente_ciudad, t3.nombre AS cliente_provincia, t1.credito_asegurado AS creditoAsegurado" ) - ->where("t1.is_deleted", 0) + ->where("t1.deleted_at", null) ->where("t1.id", $cliente_id); $builder->join("lg_paises t2", "t1.pais_id = t2.id", "left"); $builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left"); @@ -394,7 +391,7 @@ class ClienteModel extends \App\Models\BaseModel "t1.nombre AS nombre" ) ->where("id", $id) - ->where("is_deleted", 0); + ->where("t1.deleted_at", null); return $builder->get()->getResultObject()[0]->nombre; } catch (\Exception $e) { @@ -409,7 +406,7 @@ class ClienteModel extends \App\Models\BaseModel ->select( "t1.id AS id, t1.nombre AS name" ) - ->where("is_deleted", 0); + ->where("t1.deleted_at", null); return empty($search) ? $builder->get()->getResultObject() : $builder @@ -586,7 +583,7 @@ class ClienteModel extends \App\Models\BaseModel $result['limite_credito'] = $this->db->table('clientes') ->select('limite_credito') ->where('id', $cliente_id) - ->where('is_deleted', 0) + ->where("deleted_at", null) ->get() ->getResultObject()[0]->limite_credito; $result['limite_credito'] = round(floatval($result['limite_credito']), 2); diff --git a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php index 8b6562e3..c15bbad2 100755 --- a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php +++ b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php @@ -36,7 +36,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel "tiempo_max", "precio_hora", "margen", - "is_deleted", "deleted_at", "created_at", "updated_at", @@ -45,11 +44,12 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosLineasEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; protected $createdField = "created_at"; protected $updatedField = "updated_at"; + protected $deletedField = 'deleted_at'; public static $labelField = "plantilla_id"; @@ -121,7 +121,6 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $this->db ->table($this->table . " t1") ->where('t1.plantilla_id', $plantilla_id) - ->set('is_deleted', 1) ->set('deleted_at', $date_value) ->update(); @@ -152,7 +151,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $builder->join("users t2", "t1.user_updated_id = t2.id", "left"); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', 0); $builder->where('t1.plantilla_id', $plantilla_id); if (empty($search)) @@ -181,7 +180,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel $rows = $this->db ->table($this->table) ->select("id, tiempo_min, tiempo_max") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("tipo", $data["tipo"]) ->where("tipo_maquina", $data["tipo_maquina"]) ->where("tipo_impresion", $data["tipo_impresion"]) diff --git a/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php b/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php index c3f55da2..4b30e15f 100755 --- a/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePlantillaPreciosModel.php @@ -19,11 +19,12 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel protected $useAutoIncrement = true; - protected $allowedFields = ["nombre", "is_deleted", "deleted_at", "created_at", "updated_at"]; + protected $allowedFields = ["nombre", "deleted_at", "created_at", "updated_at"]; protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; @@ -61,7 +62,7 @@ class ClientePlantillaPreciosModel extends \App\Models\BaseModel "t1.id as id, t1.nombre AS nombre" ); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', null); if (empty($search)) return $builder; diff --git a/ci4/app/Models/Clientes/ClientePreciosModel.php b/ci4/app/Models/Clientes/ClientePreciosModel.php index dd749161..17693fd2 100755 --- a/ci4/app/Models/Clientes/ClientePreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePreciosModel.php @@ -34,7 +34,6 @@ class ClientePreciosModel extends \App\Models\BaseModel "tiempo_max", "precio_hora", "margen", - "is_deleted", "deleted_at", "created_at", "updated_at", @@ -45,7 +44,8 @@ class ClientePreciosModel extends \App\Models\BaseModel protected $returnType = "App\Entities\Clientes\ClientePreciosEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; @@ -140,7 +140,6 @@ class ClientePreciosModel extends \App\Models\BaseModel $this->db ->table($this->table . " t1") ->where('cliente_id', $cliente_id) - ->set('is_deleted', 1) ->set('deleted_at', $date_value) ->set('user_updated_id', $session->id_user) ->update(); @@ -153,7 +152,7 @@ class ClientePreciosModel extends \App\Models\BaseModel // Se borran los valores existentes para todos los clientes en una sola consulta $modelCliente = model('App\Models\Clientes\ClienteModel'); - $clientes = $modelCliente->select('id')->where('is_deleted', 0)->findAll(); + $clientes = $modelCliente->select('id')->where('deleted_at', null)->findAll(); // Se borra la tabla $this->db->table($this->table)->truncate(); @@ -288,7 +287,7 @@ class ClientePreciosModel extends \App\Models\BaseModel ->table($this->table . " t1") ->select("t1.cliente_id AS id") ->where('t1.plantilla_id', $plantilla_id) - ->where('t1.is_deleted', 0) + ->where('t1.deleted_at', null) ->distinct() ->get()->getResultArray(); // Extraer solo los IDs de los clientes @@ -359,7 +358,7 @@ class ClientePreciosModel extends \App\Models\BaseModel ->where('tipo_impresion', $config->tipo_impresion) ->where('tiempo_min <=', $tiempo) ->where('tiempo_max >=', $tiempo) - ->where('is_deleted', 0) + ->where('deleted_at', null) ->get()->getResultObject(); if (count($values) > 0) { @@ -389,7 +388,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $builder->join("users t2", "t1.user_updated_id = t2.id", "left"); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', 0); $builder->where('t1.cliente_id', $cliente_id); if (empty($search)) @@ -415,7 +414,7 @@ class ClientePreciosModel extends \App\Models\BaseModel "t1.plantilla_id AS id, t2.nombre AS nombre" ); - $builder->where('t1.is_deleted', 0); + $builder->where('t1.deleted_at', null); $builder->where('t1.cliente_id', $cliente_id); $builder->join("cliente_plantilla_precios t2", "t1.plantilla_id = t2.id", "left"); $builder->limit(1); @@ -442,7 +441,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $rows = $this->db ->table($this->table) ->select("id, tiempo_min, tiempo_max") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("tipo", $data["tipo"]) ->where("tipo_maquina", $data["tipo_maquina"]) ->where("tipo_impresion", $data["tipo_impresion"]) @@ -476,7 +475,7 @@ class ClientePreciosModel extends \App\Models\BaseModel $value = $this->db ->table($this->table) ->select("plantilla_id") - ->where("is_deleted", 0) + ->where("deleted_at", null) ->where("cliente_id", $cliente_id) ->limit(1)->get()->getResultObject(); diff --git a/ci4/app/Models/Clientes/ClienteUsuariosModel.php b/ci4/app/Models/Clientes/ClienteUsuariosModel.php index e735d7d2..c1b5ade5 100644 --- a/ci4/app/Models/Clientes/ClienteUsuariosModel.php +++ b/ci4/app/Models/Clientes/ClienteUsuariosModel.php @@ -26,7 +26,8 @@ class ClienteUsuariosModel extends ShieldUserModel protected $returnType = "App\Entities\Usuarios\UserEntity"; protected $useTimestamps = true; - protected $useSoftDeletes = false; + protected $useSoftDeletes = true; + protected $deletedField = 'deleted_at'; protected $createdField = "created_at"; diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 6a237646..317bd12d 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -787,10 +787,7 @@ $(document).on('click', '.btn-remove', function(e) { },{ "name": "deleted_at", "type": "hidden" - },{ - "name": "is_deleted", - "type": "hidden" - }, + } ] } ); From a4f6f8cdb3ee63cf13730f172dc2143caefa170d Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 11 Apr 2025 07:01:39 +0200 Subject: [PATCH 07/18] migration drop is_deleted --- .../2025-04-11-040000_DropIsDeletedField.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php index 311fe867..1c23cde0 100644 --- a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php +++ b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php @@ -44,6 +44,35 @@ class DropIsDeletedField extends Migration public function down() { + $column = [ + 'is_deleted' => [ + 'type' => 'BOOLEAN', + 'default' => false, + ], + ]; + $this->forge->addColumn('clientes',$column); + $m = $this->db->table('clientes'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + $this->forge->addColumn('cliente_contactos',$column); + $m = $this->db->table('cliente_contactos'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_precios',$column); + $m = $this->db->table('cliente_precios'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_plantilla_precios_lineas',$column); + $m = $this->db->table('cliente_plantilla_precios_lineas'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); + + $this->forge->addColumn('cliente_plantilla_precios',$column); + $m = $this->db->table('cliente_plantilla_precios'); + $m->where('deleted_at IS NOT NULL',null,false)->update(['is_deleted' => true]); + $m->where('deleted_at',null)->update(['is_deleted' => false]); } } From defb7373c4a9decb11b65ee314c8f79dad56edde Mon Sep 17 00:00:00 2001 From: amazuecos Date: Fri, 11 Apr 2025 07:03:08 +0200 Subject: [PATCH 08/18] remove unused imports --- .../Migrations/2025-04-11-040000_DropIsDeletedField.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php index 1c23cde0..db9b6c88 100644 --- a/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php +++ b/ci4/app/Database/Migrations/2025-04-11-040000_DropIsDeletedField.php @@ -2,10 +2,6 @@ namespace App\Database\Migrations; -use App\Models\Clientes\ClienteContactoModel; -use App\Models\Clientes\ClienteModel; -use App\Models\Clientes\ClientePlantillaPreciosModel; -use App\Models\Clientes\ClientePreciosModel; use CodeIgniter\Database\Migration; use CodeIgniter\I18n\Time; From efb50383b7dd8718d79a3afcc6c9a158abf9da2f Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 12 Apr 2025 07:59:33 +0200 Subject: [PATCH 09/18] add class table-responsive --- .../clientes/cliente/_clienteFormItems.php | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 317bd12d..fd9280ac 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -591,29 +591,31 @@
+
- - - - - - - - - - - - - - - - - - - - - -
IDplantilla_id
+ + + + + + + + + + + + + + + + + + + + + +
IDplantilla_id
+
@@ -637,10 +639,11 @@
- - - - +
+
+ + + @@ -653,9 +656,10 @@ - - -
+ + + +
From ba54d99185840ebcbaa3d0b4d97de5ef715ef653 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 12 Apr 2025 07:59:57 +0200 Subject: [PATCH 10/18] remove doble slash ad form url --- .../themes/vuexy/form/clientes/cliente/viewClienteForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php index 09193e58..5ba23c96 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/viewClienteForm.php @@ -13,7 +13,7 @@
" method="post" class="card-body" action="">
From e7394999ab75cbf065fe2736d817f8b851e954d3 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 12 Apr 2025 08:00:26 +0200 Subject: [PATCH 11/18] constraint btn-edit event inside table not in $(document) --- httpdocs/assets/js/safekat/pages/cliente/clienteFacturacion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpdocs/assets/js/safekat/pages/cliente/clienteFacturacion.js b/httpdocs/assets/js/safekat/pages/cliente/clienteFacturacion.js index 3b0d05ab..d8a48c0a 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/clienteFacturacion.js +++ b/httpdocs/assets/js/safekat/pages/cliente/clienteFacturacion.js @@ -18,7 +18,7 @@ class ClienteFacturacion { $(this).tab('show'); }); - $(document).on('click', '.btn-edit', function (e) { + $('#tableOfFacturasCliente').on('click', '.btn-edit', function (e) { window.location.href = '/facturas/edit/' + $(this).attr('data-id'); }); From 38d60402c0adebba74e567445e355e89c84109c5 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 12 Apr 2025 08:00:32 +0200 Subject: [PATCH 12/18] constraint btn-edit event inside table not in $(document) --- httpdocs/assets/js/safekat/pages/cliente/clientePedidos.js | 2 +- .../assets/js/safekat/pages/cliente/clientePresupuestos.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/cliente/clientePedidos.js b/httpdocs/assets/js/safekat/pages/cliente/clientePedidos.js index 0d5d924d..9f0ef800 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/clientePedidos.js +++ b/httpdocs/assets/js/safekat/pages/cliente/clientePedidos.js @@ -18,7 +18,7 @@ class ClientePedidos { $(this).tab('show'); }); - $(document).on('click', '.btn-edit', function (e) { + $('#tableOfPedidosCliente').on('click', '.btn-edit', function (e) { window.location.href = '/pedidos/edit/' + $(this).attr('data-id'); }); diff --git a/httpdocs/assets/js/safekat/pages/cliente/clientePresupuestos.js b/httpdocs/assets/js/safekat/pages/cliente/clientePresupuestos.js index ad558b0a..07540a54 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/clientePresupuestos.js +++ b/httpdocs/assets/js/safekat/pages/cliente/clientePresupuestos.js @@ -17,8 +17,8 @@ class ClientePresupuestos { $(this).tab('show'); }); - $(document).on('click', '.btn-edit', function (e) { - window.location.href = $('#clienteForm').attr('data-url'); + $(this).attr('data-id'); + $('#tableOfPresupuestosCliente').on('click', '.btn-edit', function (e) { + window.location.href = $('#clienteForm').attr('data-url') + $(this).attr('data-id'); }); const lastColNr = $('#tableOfPresupuestosCliente').find("tr:first th").length - 1; From bb9f6210e746ec3f01d73347c115fb3f0f33dca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 12 Apr 2025 10:00:24 +0200 Subject: [PATCH 13/18] =?UTF-8?q?terminado=20a=C3=B1adir=20usuarios=20y=20?= =?UTF-8?q?fechas=20a=20pedidos.=20a=C3=B1adido=20inaplazable.=20color=20e?= =?UTF-8?q?n=20rojo=20en=20fechas=20cuando=20inaplazable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- ci4/app/Config/RBAC/permissionMatrix.php | 387 ------------------ ci4/app/Config/RBAC/permissions.php | 111 ----- ci4/app/Config/RBAC/roles.json | 22 - ci4/app/Config/RBAC/roles.php | 48 --- ci4/app/Controllers/Pedidos/Pedido.php | 28 +- ...-11-180001_AddUserIdFechaEntregaPedido.php | 61 +++ ci4/app/Entities/Pedidos/PedidoEntity.php | 6 + ci4/app/Models/Pedidos/PedidoModel.php | 6 + .../vuexy/form/pedidos/_cabeceraItems.php | 64 ++- 10 files changed, 152 insertions(+), 584 deletions(-) delete mode 100644 ci4/app/Config/RBAC/permissionMatrix.php delete mode 100644 ci4/app/Config/RBAC/permissions.php delete mode 100644 ci4/app/Config/RBAC/roles.json delete mode 100644 ci4/app/Config/RBAC/roles.php create mode 100644 ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php diff --git a/.gitignore b/.gitignore index 4bee8902..3815dd22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ ci4/.env .vscode/ launch.json -*xdebug*.log* \ No newline at end of file +*xdebug*.log* +ci4/app/Config/RBAC/* \ No newline at end of file diff --git a/ci4/app/Config/RBAC/permissionMatrix.php b/ci4/app/Config/RBAC/permissionMatrix.php deleted file mode 100644 index c78c032c..00000000 --- a/ci4/app/Config/RBAC/permissionMatrix.php +++ /dev/null @@ -1,387 +0,0 @@ - [ - "clientes.create", - "clientes.edit", - "clientes.delete", - "clientes.menu", - "plantilla-tarifa.create", - "plantilla-tarifa.edit", - "plantilla-tarifa.delete", - "plantilla-tarifa.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.delete", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.delete", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.delete", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "tarifa-preimpresion.create", - "tarifa-preimpresion.edit", - "tarifa-preimpresion.delete", - "tarifa-preimpresion.menu", - "tarifa-manipulado.create", - "tarifa-manipulado.edit", - "tarifa-manipulado.delete", - "tarifa-manipulado.menu", - "tarifa-acabado.create", - "tarifa-acabado.edit", - "tarifa-acabado.delete", - "tarifa-acabado.menu", - "tarifa-encuadernacion.create", - "tarifa-encuadernacion.edit", - "tarifa-encuadernacion.delete", - "tarifa-encuadernacion.menu", - "tarifa-extra.create", - "tarifa-extra.edit", - "tarifa-extra.delete", - "tarifa-extra.menu", - "tarifa-envio.create", - "tarifa-envio.edit", - "tarifa-envio.delete", - "tarifa-envio.menu", - "servicio-acabado.create", - "servicio-acabado.edit", - "servicio-acabado.delete", - "servicio-acabado.menu", - "proveedores.create", - "proveedores.edit", - "proveedores.delete", - "proveedores.menu", - "ajustes.create", - "ajustes.edit", - "ajustes.delete", - "ajustes.menu", - "actividad.create", - "actividad.edit", - "actividad.delete", - "actividad.menu", - "paises.create", - "paises.edit", - "paises.delete", - "paises.menu", - "maquinas.create", - "maquinas.edit", - "maquinas.delete", - "maquinas.menu", - "maquinas-defecto.create", - "maquinas-defecto.edit", - "maquinas-defecto.delete", - "maquinas-defecto.menu", - "papel-generico.create", - "papel-generico.edit", - "papel-generico.delete", - "papel-generico.menu", - "papel-impresion.create", - "papel-impresion.edit", - "papel-impresion.delete", - "papel-impresion.menu", - "usuarios.create", - "usuarios.edit", - "usuarios.delete", - "usuarios.menu", - "roles-permisos.create", - "roles-permisos.edit", - "roles-permisos.delete", - "roles-permisos.menu", - "tickets.create", - "tickets.edit", - "tickets.menu", - "facturas.create", - "facturas.edit", - "facturas.vencimientos", - "facturas.menu", - ], - "cliente-admin" => [ - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.delete", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - ], - "cliente-editor" => [ - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - ], - "comercial" => [ - "clientes.create", - "clientes.edit", - "clientes.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - ], - "produccion" => [ - "direcciones.create", - "direcciones.edit", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.menu", - "pedidos-validacion.view", - "pedidos-validacion.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "pedidos-gestion.toprod", - "pedidos-gestion.menu", - "tickets.edit", - "tickets.menu", - ], - "maquina" => [ - "token.token", - "token.menu", - ], - "maquetador" => [ - "token.token", - "token.menu", - ], - "director" => [ - "clientes.create", - "clientes.edit", - "clientes.menu", - "plantilla-tarifa.create", - "plantilla-tarifa.edit", - "plantilla-tarifa.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "pedidos-gestion.toprod", - "pedidos-gestion.menu", - "tarifa-preimpresion.create", - "tarifa-preimpresion.edit", - "tarifa-preimpresion.menu", - "tarifa-manipulado.create", - "tarifa-manipulado.edit", - "tarifa-manipulado.menu", - "tarifa-acabado.create", - "tarifa-acabado.edit", - "tarifa-acabado.menu", - "tarifa-encuadernacion.create", - "tarifa-encuadernacion.edit", - "tarifa-encuadernacion.menu", - "tarifa-extra.create", - "tarifa-extra.edit", - "tarifa-extra.menu", - "tarifa-envio.create", - "tarifa-envio.edit", - "tarifa-envio.menu", - "servicio-acabado.create", - "servicio-acabado.edit", - "servicio-acabado.menu", - "proveedores.create", - "proveedores.edit", - "proveedores.menu", - "tickets.edit", - "tickets.menu", - "facturas.create", - "facturas.edit", - "facturas.vencimientos", - "facturas.menu", - ], - "contabilidad" => [ - "clientes.create", - "clientes.edit", - "clientes.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.menu", - "pedidos-validacion.view", - "pedidos-validacion.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "proveedores.create", - "proveedores.edit", - "proveedores.menu", - "tickets.edit", - "tickets.menu", - "facturas.create", - "facturas.edit", - "facturas.vencimientos", - "facturas.menu", - ], - "editor" => [ - "token.token", - "token.menu", - "Profile.index", - "Profile.menu", - ], - "beta" => [ - "clientes.create", - "clientes.edit", - "clientes.delete", - "clientes.menu", - "plantilla-tarifa.create", - "plantilla-tarifa.edit", - "plantilla-tarifa.delete", - "plantilla-tarifa.menu", - "direcciones.create", - "direcciones.edit", - "direcciones.delete", - "direcciones.menu", - "presupuesto.create", - "presupuesto.edit", - "presupuesto.delete", - "presupuesto.menu", - "presupuesto-cliente.create", - "presupuesto-cliente.edit", - "presupuesto-cliente.delete", - "presupuesto-cliente.menu", - "pedidos-activos.view", - "pedidos-activos.menu", - "pedidos-finalizados.view", - "pedidos-finalizados.menu", - "pedidos-cancelados.view", - "pedidos-cancelados.menu", - "pedidos-todos.view", - "pedidos-todos.menu", - "tarifa-preimpresion.create", - "tarifa-preimpresion.edit", - "tarifa-preimpresion.delete", - "tarifa-preimpresion.menu", - "tarifa-manipulado.create", - "tarifa-manipulado.edit", - "tarifa-manipulado.delete", - "tarifa-manipulado.menu", - "tarifa-acabado.create", - "tarifa-acabado.edit", - "tarifa-acabado.delete", - "tarifa-acabado.menu", - "tarifa-encuadernacion.create", - "tarifa-encuadernacion.edit", - "tarifa-encuadernacion.delete", - "tarifa-encuadernacion.menu", - "tarifa-extra.create", - "tarifa-extra.edit", - "tarifa-extra.delete", - "tarifa-extra.menu", - "tarifa-envio.create", - "tarifa-envio.edit", - "tarifa-envio.delete", - "tarifa-envio.menu", - "servicio-acabado.create", - "servicio-acabado.edit", - "servicio-acabado.delete", - "servicio-acabado.menu", - "proveedores.create", - "proveedores.edit", - "proveedores.delete", - "proveedores.menu", - "ajustes.create", - "ajustes.edit", - "ajustes.delete", - "ajustes.menu", - "actividad.create", - "actividad.edit", - "actividad.delete", - "actividad.menu", - "paises.create", - "paises.edit", - "paises.delete", - "paises.menu", - "maquinas.create", - "maquinas.edit", - "maquinas.delete", - "maquinas.menu", - "maquinas-defecto.create", - "maquinas-defecto.edit", - "maquinas-defecto.delete", - "maquinas-defecto.menu", - "papel-generico.create", - "papel-generico.edit", - "papel-generico.delete", - "papel-generico.menu", - "papel-impresion.create", - "papel-impresion.edit", - "papel-impresion.delete", - "papel-impresion.menu", - "usuarios.create", - "usuarios.edit", - "usuarios.delete", - "usuarios.menu", - "roles-permisos.create", - "roles-permisos.edit", - "roles-permisos.delete", - "roles-permisos.menu", - "tickets.edit", - "tickets.menu", - "facturas.create", - "facturas.edit", - "facturas.vencimientos", - "facturas.menu", - ], -]; diff --git a/ci4/app/Config/RBAC/permissions.php b/ci4/app/Config/RBAC/permissions.php deleted file mode 100644 index 9bb8fcb3..00000000 --- a/ci4/app/Config/RBAC/permissions.php +++ /dev/null @@ -1,111 +0,0 @@ - 'Can create', - 'clientes.edit' => 'Can edit', - 'clientes.delete' => 'Can delete', - 'clientes.menu' => 'Menu shall be visualize', - 'plantilla-tarifa.create' => 'Can create', - 'plantilla-tarifa.edit' => 'Can edit', - 'plantilla-tarifa.delete' => 'Can delete', - 'plantilla-tarifa.menu' => 'Menu shall be visualize', - 'direcciones.create' => 'Can create', - 'direcciones.edit' => 'Can edit', - 'direcciones.delete' => 'Can delete', - 'direcciones.menu' => 'Menu shall be visualize', - 'presupuesto.create' => 'Can create', - 'presupuesto.edit' => 'Can edit', - 'presupuesto.delete' => 'Can delete', - 'presupuesto.menu' => 'Menu shall be visualize', - 'presupuesto-cliente.create' => 'Can create', - 'presupuesto-cliente.edit' => 'Can edit', - 'presupuesto-cliente.delete' => 'Can delete', - 'presupuesto-cliente.menu' => 'Menu shall be visualize', - 'pedidos-validacion.view' => 'Can view', - 'pedidos-validacion.menu' => 'Menu shall be visualize', - 'pedidos-activos.view' => 'Can view', - 'pedidos-activos.menu' => 'Menu shall be visualize', - 'pedidos-finalizados.view' => 'Can view', - 'pedidos-finalizados.menu' => 'Menu shall be visualize', - 'pedidos-cancelados.view' => 'Can view', - 'pedidos-cancelados.menu' => 'Menu shall be visualize', - 'pedidos-todos.view' => 'Can view', - 'pedidos-todos.menu' => 'Menu shall be visualize', - 'pedidos-gestion.toprod' => 'Can toprod', - 'pedidos-gestion.menu' => 'Menu shall be visualize', - 'tarifa-preimpresion.create' => 'Can create', - 'tarifa-preimpresion.edit' => 'Can edit', - 'tarifa-preimpresion.delete' => 'Can delete', - 'tarifa-preimpresion.menu' => 'Menu shall be visualize', - 'tarifa-manipulado.create' => 'Can create', - 'tarifa-manipulado.edit' => 'Can edit', - 'tarifa-manipulado.delete' => 'Can delete', - 'tarifa-manipulado.menu' => 'Menu shall be visualize', - 'tarifa-acabado.create' => 'Can create', - 'tarifa-acabado.edit' => 'Can edit', - 'tarifa-acabado.delete' => 'Can delete', - 'tarifa-acabado.menu' => 'Menu shall be visualize', - 'tarifa-encuadernacion.create' => 'Can create', - 'tarifa-encuadernacion.edit' => 'Can edit', - 'tarifa-encuadernacion.delete' => 'Can delete', - 'tarifa-encuadernacion.menu' => 'Menu shall be visualize', - 'tarifa-extra.create' => 'Can create', - 'tarifa-extra.edit' => 'Can edit', - 'tarifa-extra.delete' => 'Can delete', - 'tarifa-extra.menu' => 'Menu shall be visualize', - 'tarifa-envio.create' => 'Can create', - 'tarifa-envio.edit' => 'Can edit', - 'tarifa-envio.delete' => 'Can delete', - 'tarifa-envio.menu' => 'Menu shall be visualize', - 'servicio-acabado.create' => 'Can create', - 'servicio-acabado.edit' => 'Can edit', - 'servicio-acabado.delete' => 'Can delete', - 'servicio-acabado.menu' => 'Menu shall be visualize', - 'proveedores.create' => 'Can create', - 'proveedores.edit' => 'Can edit', - 'proveedores.delete' => 'Can delete', - 'proveedores.menu' => 'Menu shall be visualize', - 'ajustes.create' => 'Can create', - 'ajustes.edit' => 'Can edit', - 'ajustes.delete' => 'Can delete', - 'ajustes.menu' => 'Menu shall be visualize', - 'actividad.create' => 'Can create', - 'actividad.edit' => 'Can edit', - 'actividad.delete' => 'Can delete', - 'actividad.menu' => 'Menu shall be visualize', - 'paises.create' => 'Can create', - 'paises.edit' => 'Can edit', - 'paises.delete' => 'Can delete', - 'paises.menu' => 'Menu shall be visualize', - 'maquinas.create' => 'Can create', - 'maquinas.edit' => 'Can edit', - 'maquinas.delete' => 'Can delete', - 'maquinas.menu' => 'Menu shall be visualize', - 'maquinas-defecto.create' => 'Can create', - 'maquinas-defecto.edit' => 'Can edit', - 'maquinas-defecto.delete' => 'Can delete', - 'maquinas-defecto.menu' => 'Menu shall be visualize', - 'papel-generico.create' => 'Can create', - 'papel-generico.edit' => 'Can edit', - 'papel-generico.delete' => 'Can delete', - 'papel-generico.menu' => 'Menu shall be visualize', - 'papel-impresion.create' => 'Can create', - 'papel-impresion.edit' => 'Can edit', - 'papel-impresion.delete' => 'Can delete', - 'papel-impresion.menu' => 'Menu shall be visualize', - 'usuarios.create' => 'Can create', - 'usuarios.edit' => 'Can edit', - 'usuarios.delete' => 'Can delete', - 'usuarios.menu' => 'Menu shall be visualize', - 'roles-permisos.create' => 'Can create', - 'roles-permisos.edit' => 'Can edit', - 'roles-permisos.delete' => 'Can delete', - 'roles-permisos.menu' => 'Menu shall be visualize', - 'tickets.create' => 'Can create', - 'tickets.edit' => 'Can edit', - 'tickets.menu' => 'Menu shall be visualize', - 'facturas.create' => 'Can create', - 'facturas.edit' => 'Can edit', - 'facturas.vencimientos' => 'Can vencimientos', - 'facturas.menu' => 'Menu shall be visualize', -]; diff --git a/ci4/app/Config/RBAC/roles.json b/ci4/app/Config/RBAC/roles.json deleted file mode 100644 index a95d9582..00000000 --- a/ci4/app/Config/RBAC/roles.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "superadmin": { - "title": "Super Admin", - "description": "Complete control of the site." - }, - "admin": { - "title": "Admin", - "description": "Day to day administrators of the site." - }, - "developer": { - "title": "Developer", - "description": "Site programmers." - }, - "user": { - "title": "User", - "description": "General users of the site. Often customers." - }, - "beta": { - "title": "Beta User", - "description": "Has access to beta-level features." - } -} \ No newline at end of file diff --git a/ci4/app/Config/RBAC/roles.php b/ci4/app/Config/RBAC/roles.php deleted file mode 100644 index d39a912a..00000000 --- a/ci4/app/Config/RBAC/roles.php +++ /dev/null @@ -1,48 +0,0 @@ - [ - 'title' => 'Administrador', - 'description' => 'Administrador del ERP', - ], - 'cliente-admin' => [ - 'title' => 'Cliente administrador', - 'description' => 'Rol de cliente con permisos de administración', - ], - 'cliente-editor' => [ - 'title' => 'Cliente editor', - 'description' => 'Rol de cliente con permisos de edición', - ], - 'comercial' => [ - 'title' => 'Comercial', - 'description' => '', - ], - 'produccion' => [ - 'title' => 'Producción', - 'description' => '', - ], - 'maquina' => [ - 'title' => 'Máquina', - 'description' => '', - ], - 'maquetador' => [ - 'title' => 'Maquetador', - 'description' => '', - ], - 'director' => [ - 'title' => 'Director', - 'description' => 'Para los directores de área', - ], - 'contabilidad' => [ - 'title' => 'Contabilidad', - 'description' => '', - ], - 'editor' => [ - 'title' => 'Editor', - 'description' => '', - ], - 'beta' => [ - 'title' => 'Beta', - 'description' => '', - ], -]; diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 6e28240e..51f911c6 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -211,6 +211,8 @@ class Pedido extends \App\Controllers\BaseResourceController public function update($id = null){ + $data = []; + if ($this->request->isAJAX()) { $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); @@ -242,6 +244,14 @@ class Pedido extends \App\Controllers\BaseResourceController $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + foreach(array_keys($sanitizedData) as $key){ + if(str_starts_with($key, "fecha_")){ + $sanitizedData[$key . "_change_user_id"] = + auth()->user()->id; + $data[$key . "_change_user"] = + model('App\Models\Usuarios\UserModel')->getFullName(auth()->user()->id); + } + } // JJO $sanitizedData['user_updated_id'] = auth()->user()->id; @@ -268,10 +278,9 @@ class Pedido extends \App\Controllers\BaseResourceController $id = $pedidoEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; - $data = [ - 'error' => 0, - $csrfTokenName => $newTokenHash - ]; + $data['error'] = 0; + $data[$csrfTokenName] = $newTokenHash; + return $this->respond($data); endif; // $noException && $successfulResult @@ -303,7 +312,15 @@ class Pedido extends \App\Controllers\BaseResourceController $this->obtenerDatosFormulario($pedidoEntity); - + $pedidoEntity->fecha_entrega_real_change_user = $pedidoEntity->fecha_entrega_real_change_user_id?model('App\Models\Usuarios\UserModel')-> + getFullName($pedidoEntity->fecha_entrega_real_change_user_id):""; + $pedidoEntity->fecha_impresion_change_user = $pedidoEntity->fecha_impresion_change_user_id?model('App\Models\Usuarios\UserModel')-> + getFullName($pedidoEntity->fecha_impresion_change_user_id):""; + $pedidoEntity->fecha_encuadernado_change_user = $pedidoEntity->fecha_encuadernado_change_user_id?model('App\Models\Usuarios\UserModel')-> + getFullName($pedidoEntity->fecha_encuadernado_change_user_id):""; + $pedidoEntity->fecha_entrega_change_externo_user = $pedidoEntity->fecha_entrega_change_externo_user_id?model('App\Models\Usuarios\UserModel')-> + getFullName($pedidoEntity->fecha_entrega_change_externo_user_id):""; + $this->viewData['pedidoEntity'] = $pedidoEntity; if($pedidoEntity->estado == 'validacion'){ @@ -321,6 +338,7 @@ class Pedido extends \App\Controllers\BaseResourceController $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3'); + return $this->displayForm(__METHOD__, $id); } diff --git a/ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php b/ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php new file mode 100644 index 00000000..b8313fcb --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php @@ -0,0 +1,61 @@ + [ + "type" => "INT", + "unsigned" => true, + "constraint" => 1, + "null" => true, + ], + 'fecha_entrega_real_change_user_id' => [ + 'type' => 'INT', + "constraint" => 10, + "unsigned" => true, + "null" => true, + ], + "fecha_impresion_change_user_id" => [ + "type" => "INT", + "constraint" => 10, + "unsigned" => true, + "null" => true, + ], + + "fecha_encuadernado_change_user_id" => [ + "type" => "INT", + "unsigned" => true, + "constraint" => 10, + "null" => true, + ], + "fecha_entrega_externo_change_user_id" => [ + "type" => "INT", + "unsigned" => true, + "constraint" => 10, + "null" => true, + ], + "inaplazable_change_user_id" => [ + "type" => "INT", + "unsigned" => true, + "constraint" => 10, + "null" => true, + ], + + ]; + + public function up() + { + $this->forge->addColumn("pedidos", $this->USER_COLUMNS); + } + + public function down() + { + $this->forge->dropColumn("pedidos", array_keys($this->USER_COLUMNS)); + + } +} diff --git a/ci4/app/Entities/Pedidos/PedidoEntity.php b/ci4/app/Entities/Pedidos/PedidoEntity.php index 57b81396..61c40e25 100644 --- a/ci4/app/Entities/Pedidos/PedidoEntity.php +++ b/ci4/app/Entities/Pedidos/PedidoEntity.php @@ -18,6 +18,7 @@ class PedidoEntity extends \CodeIgniter\Entity\Entity "total_precio" => null, "total_tirada" => null, "estado" => null, + "inaplazable" => null, "user_created_id" => null, "user_updated_id" => null, "user_validated_id" => null, @@ -25,6 +26,11 @@ class PedidoEntity extends \CodeIgniter\Entity\Entity "fecha_impresion" => null, "fecha_encuadernado" => null, "fecha_entrega_externo" => null, + "fecha_entrega_real_change_user_id" => null, + "fecha_impresion_change_user_id" => null, + "fecha_encuadernado_change_user_id" => null, + "fecha_entrega_change_externo_user_id" => null, + "inaplazable_change_user_id" => null, "created_at" => null, "updated_at" => null, "validated_at" => null, diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 1ab7dea5..7a7bdbf0 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -37,6 +37,7 @@ class PedidoModel extends \App\Models\BaseModel "total_precio", "total_tirada", "estado", + "inaplazable", "user_created_id", "user_updated_id", "user_validated_id", @@ -44,6 +45,11 @@ class PedidoModel extends \App\Models\BaseModel "fecha_impresion", "fecha_encuadernado", "fecha_entrega_externo", + "fecha_entrega_real_change_user_id", + "fecha_impresion_change_user_id", + "fecha_encuadernado_change_user_id", + "fecha_entrega_externo_change_user_id", + "inaplazable_change_user_id", "created_at", "updated_at", "validated_at", diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index 85711c1b..559c0925 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -100,6 +100,7 @@
+ @@ -121,7 +122,8 @@ - + +
fecha_entrega_real_change_user?>
@@ -129,7 +131,8 @@ - + +
fecha_impresion_change_user?>
@@ -137,7 +140,8 @@ - + +
fecha_encuadernado_change_user?>
@@ -145,10 +149,25 @@ - + +
fecha_entrega_externo_change_user?>
+
+ +
@@ -183,6 +202,15 @@ section('additionalInlineJs') ?> +document.getElementById('inaplazable').addEventListener('change', () => { + updateDate('inaplazable', $('#inaplazable').prop('checked') ? 1 : 0); +}); + +if(inaplazable ?>){ + $('.inaplazable-date').addClass('text-danger fw-bold'); +} + + $("#fecha_entrega_real").flatpickr({ defaultDate: fecha_entrega_real_text ? "'".$pedidoEntity->fecha_entrega_real_text."'" : 'null' ?>, dateFormat: "d/m/Y", @@ -321,10 +349,21 @@ function updateDate(elementId, dateStr) { data = { : v, }; - var parts = dateStr.split('/'); - var newFormat = parts[2] + '-' + parts[1] + '-' + parts[0]; // Asume dateStr en formato d/m/Y. - - data[elementId] = newFormat; + + if(elementId == 'inaplazable'){ + data[elementId] = dateStr; + if(dateStr == 1){ + $('.inaplazable-date').addClass('text-danger fw-bold'); + } + else{ + $('.inaplazable-date').removeClass('text-danger fw-bold'); + } + }else{ + var parts = dateStr.split('/'); + var newFormat = parts[2] + '-' + parts[1] + '-' + parts[0]; // Asume dateStr en formato d/m/Y. + + data[elementId] = newFormat; + } var url = ''; url = url.replace(':id', id ); @@ -336,11 +375,16 @@ function updateDate(elementId, dateStr) { success: function(response){ if('error' in response){ - + if(response.error == 0){ + for (const [key, value] of Object.entries(response)) { + if (key.endsWith('_change_user')) { + $("#" + key).html(value); + } + } + } } } }); - } endSection() ?> \ No newline at end of file From 79fcb1e3fef04de874f017ae03b9f731da211e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 12 Apr 2025 10:18:32 +0200 Subject: [PATCH 14/18] arreglado problema --- ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index 559c0925..70d89973 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -206,7 +206,7 @@ document.getElementById('inaplazable').addEventListener('change', () => { updateDate('inaplazable', $('#inaplazable').prop('checked') ? 1 : 0); }); -if(inaplazable ?>){ +if(inaplazable?1:0 ?>){ $('.inaplazable-date').addClass('text-danger fw-bold'); } From 2e845b735540a9fef47bf0adc7f8ac865d55f1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 12 Apr 2025 10:50:50 +0200 Subject: [PATCH 15/18] solucionado --- .../form/facturas/_facturaLineasItems.php | 57 +++++++++++++------ .../form/facturas/_pagosFacturasItems.php | 51 ++++++++++++----- 2 files changed, 77 insertions(+), 31 deletions(-) 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 From 8912606c9a55ec0ae489d0a3ffaa334c80aee608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 12 Apr 2025 12:37:57 +0200 Subject: [PATCH 16/18] pagos en borrador --- ci4/app/Controllers/Facturacion/Facturas.php | 4 ++++ .../vuexy/form/facturas/_addPedidosItems.php | 1 + .../vuexy/form/facturas/_facturaLineasItems.php | 13 +++++-------- .../vuexy/form/facturas/_pagosFacturasItems.php | 14 +++++--------- .../themes/vuexy/form/facturas/viewFacturaForm.php | 5 ++++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index b9c445bc..195da7a5 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -230,6 +230,10 @@ class Facturas extends \App\Controllers\BaseResourceController $factura->updated_by = $userModel->getFullName($factura->user_updated_id); $factura->created_at_footer = $factura->created_at ? date(' H:i d/m/Y', strtotime($factura->created_at)) : ''; $factura->updated_at_footer = $factura->updated_at ? date(' H:i d/m/Y', strtotime($factura->updated_at)) : ''; + + $factura->showDeleteButton = model('App\Models\Facturas\FacturaPagoModel') + ->where('factura_id', $factura->id)->countAllResults() == 0; + $this->viewData['facturaEntity'] = $factura; $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Facturas.factura') . ' ' . lang('Basic.global.edit3'); diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_addPedidosItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_addPedidosItems.php index c2db9dba..a6f390aa 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_addPedidosItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_addPedidosItems.php @@ -121,6 +121,7 @@ $('#addNewPedidoImpresion').on('click', function(){ $('#pedidoImpresion').val(null).trigger('change'); // Se actualiza la tabla de lineas de factura $('#tableOfLineasFactura').DataTable().clearPipeline().draw(); + $('#tableOfLineasPagos').DataTable().clearPipeline().draw(); } }); }); diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index 5f3c7331..9cd3136e 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php @@ -455,14 +455,9 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ 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; - - + var total_pagos = autoNumericTotalCobrado.getNumber(); + var pendientePago = totalTotal - total_pagos; + if (isNaN(pendientePago)) pendientePago = 0; autoNumericPendientePago.set(pendientePago); @@ -522,6 +517,8 @@ function deleteConfirmedLinea(params){ : v } }).done((data, textStatus, jqXHR) => { + tablelineas.clearPipeline().footerCallback().draw(); + $('#tableOfLineasPagos').DataTable().clearPipeline().footerCallback().draw(); }).fail((jqXHR, textStatus, errorThrown) => { popErrorAlert(jqXHR.responseJSON.messages.error) diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php index 78cbed7d..943f8e8d 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php @@ -185,6 +185,7 @@ editor_pagos.on( 'postSubmit', function ( e, json, data, action ) { yeniden(json.); tablePagos.clearPipeline(); tablePagos.draw(); + updateFooterLineas(tableLineas); }); const autoNumericTotalCobrado = new AutoNumeric('#totalCobrado-sum', 0, { @@ -340,13 +341,8 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({ function updateFooterLineas(table){ // Assuming pendiente de pago is totalTotal - totalIVA for this example - estado == 'borrador') :?> - var pendientePago = autoNumericTotal.getNumber(); - var total_pagos = 0; - - var total_pagos = autoNumericTotalCobrado.getNumber(); - var pendientePago = autoNumericTotal.getNumber() - 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; @@ -363,10 +359,10 @@ function updateFooterLineas(table){ pendiente: pendientePago } }).done((data, textStatus, jqXHR) => { - if($('#pendiente-pago').html() == '0.00'){ + if(autoNumericPendientePago.getNumber() == 0){ $('#addPagoRow').hide(); } else { - $('#validarFactura').show(); + $('#addPagoRow').show(); } if(data.estado_pago == 'pagada'){ $('#estado_pago_text').text(''); diff --git a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php index 0736152a..23911b81 100644 --- a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php @@ -22,7 +22,7 @@ - estado !='borrador' && (strpos($facturaEntity->numero, "REC ") !== 0) ) : ?> + numero, "REC ") !== 0) ) : ?> estado !='borrador' && (strpos($facturaEntity->numero, "REC ") === 0) ) : ?> @@ -38,6 +38,9 @@ name="validarFactura" value="" /> + + + showDeleteButton == true && $facturaEntity->estado !='validada') : ?> Date: Sat, 12 Apr 2025 17:47:36 +0200 Subject: [PATCH 17/18] terminado el flujo completo de facturas, incluyendo cambio en el texto de pedidos y facturas cuando no tiene factura validada --- ci4/app/Controllers/Facturacion/Facturas.php | 2 +- .../Presupuestos/Presupuestoadmin.php | 30 +++++++++++++++++ ...0001_AddUserIdFechaEntregaPedido copy.php} | 0 ...-130000_AddCantidadConceptoPedidoLinea.php | 33 +++++++++++++++++++ .../Entities/Pedidos/PedidoLineaEntity.php | 3 ++ ci4/app/Models/Facturas/FacturaLineaModel.php | 2 +- ci4/app/Models/Facturas/FacturaModel.php | 21 ++++++++++++ ci4/app/Models/Pedidos/PedidoLineaModel.php | 2 ++ ci4/app/Models/Pedidos/PedidoModel.php | 17 ++++++++-- ci4/app/Services/PresupuestoService.php | 3 ++ .../vuexy/form/pedidos/_cabeceraItems.php | 11 ++++++- 11 files changed, 119 insertions(+), 5 deletions(-) rename ci4/app/Database/Migrations/{2025-04-11-180001_AddUserIdFechaEntregaPedido.php => 2025-04-11-180001_AddUserIdFechaEntregaPedido copy.php} (100%) create mode 100644 ci4/app/Database/Migrations/2025-04-12-130000_AddCantidadConceptoPedidoLinea.php diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index 195da7a5..d8feb554 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -707,7 +707,7 @@ class Facturas extends \App\Controllers\BaseResourceController $data = (object) [ 'factura_id' => $factura_id, - 'pedido_linea_impresion_id' => $linea->pedido_id, + 'pedido_linea_impresion_id' => $pedido_linea_id, 'descripcion' => $descripcion[0]->concepto, 'cantidad' => $cantidad, 'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21, diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index beef112f..75ac450d 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -366,6 +366,36 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController PresupuestoService::crearPedido($id); } + // modificar los datos del pedido y de la factura si no está la factura validada + if ($presupuestoEntity->estado_id == 2){ + $facturaModel = model('App\Models\Facturas\FacturaModel'); + if(!$facturaModel->presupuestoHasFacturaValidada($id)){ + // se actualiza primero el pedido + $pedidoModel = model('App\Models\Pedidos\PedidoLineaModel'); + $pedidoLineaId = $pedidoModel->where('presupuesto_id', $id)->first()->id; + $linea_pedido = $this->model->generarLineaPedido($id)[0]; + $idPedido = $pedidoModel->join('pedidos', 'pedidos_linea.pedido_id = pedidos.id') + ->where('pedidos_linea.presupuesto_id', $id) + ->first()->pedido_id; + $pedidoModel->update($pedidoLineaId, [ + 'cantidad' => $linea_pedido->unidades, + 'descripcion' => $linea_pedido->concepto + ]); + + // se actualiza la factura + $linea_pedido = $this->model->generarLineaPedido($id, true, $idPedido)[0]; + $facturaLineaModel = model('App\Models\Facturas\FacturaLineaModel'); + $facturaLineaId = $facturaLineaModel->where('pedido_linea_impresion_id', $pedidoLineaId)-> + where('deleted_at', null)->first()->id; + $facturaLineaModel->update($facturaLineaId, [ + 'cantidad' => $linea_pedido->unidades, + 'descripcion' => $linea_pedido->concepto + ]); + + } + + } + $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $data = [ diff --git a/ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php b/ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido copy.php similarity index 100% rename from ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido.php rename to ci4/app/Database/Migrations/2025-04-11-180001_AddUserIdFechaEntregaPedido copy.php diff --git a/ci4/app/Database/Migrations/2025-04-12-130000_AddCantidadConceptoPedidoLinea.php b/ci4/app/Database/Migrations/2025-04-12-130000_AddCantidadConceptoPedidoLinea.php new file mode 100644 index 00000000..471151fd --- /dev/null +++ b/ci4/app/Database/Migrations/2025-04-12-130000_AddCantidadConceptoPedidoLinea.php @@ -0,0 +1,33 @@ + [ + "type" => "INT", + "unsigned" => true, + "constraint" => 10, + "null" => true, + ], + 'descripcion' => [ + 'type' => 'TEXT', + "null" => true, + ], + ]; + + public function up() + { + $this->forge->addColumn("pedidos_linea", $this->USER_COLUMNS); + } + + public function down() + { + $this->forge->dropColumn("pedidos_linea", array_keys($this->USER_COLUMNS)); + + } +} diff --git a/ci4/app/Entities/Pedidos/PedidoLineaEntity.php b/ci4/app/Entities/Pedidos/PedidoLineaEntity.php index dc059079..f103a8ca 100644 --- a/ci4/app/Entities/Pedidos/PedidoLineaEntity.php +++ b/ci4/app/Entities/Pedidos/PedidoLineaEntity.php @@ -16,6 +16,8 @@ class PedidoLineaEntity extends \CodeIgniter\Entity\Entity "user_updated_id" => null, "created_at" => null, "updated_at" => null, + "cantidad" => null, + "descripcion" => null, ]; @@ -23,6 +25,7 @@ class PedidoLineaEntity extends \CodeIgniter\Entity\Entity "pedido_id" => "int", "presupuesto_id" => "int", "ubicacion_id" => "int", + "cantidad" => "int", ]; public function ubicacion() : UbicacionesEntity { diff --git a/ci4/app/Models/Facturas/FacturaLineaModel.php b/ci4/app/Models/Facturas/FacturaLineaModel.php index 82888d06..cb13de58 100644 --- a/ci4/app/Models/Facturas/FacturaLineaModel.php +++ b/ci4/app/Models/Facturas/FacturaLineaModel.php @@ -39,7 +39,7 @@ class FacturaLineaModel extends \App\Models\BaseModel { 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.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, + t3.total_aceptado_revisado AS total_aceptado, t4.tirada_flexible AS tirada_flexible, t4.descuento_tirada_flexible AS descuento_tirada_flexible, t6.cantidad AS cantidad_albaran" ) ->join("pedidos_linea t2", "t2.id = t1.pedido_linea_impresion_id", "left") diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php index dc11b5e2..7c2c8142 100644 --- a/ci4/app/Models/Facturas/FacturaModel.php +++ b/ci4/app/Models/Facturas/FacturaModel.php @@ -145,6 +145,27 @@ class FacturaModel extends \App\Models\BaseModel return $builder; } + + public function presupuestoHasFacturaValidada($presupuesto_id = null) + { + if ($presupuesto_id == null) { + return false; + } + + $result = $this->db->table($this->table . " t1") + ->select("t1.id") + ->join("facturas_lineas t2", "t2.factura_id = t1.id", "left") + ->join("pedidos_linea t3", "t2.pedido_linea_impresion_id = t3.id", "left") + ->where("t3.presupuesto_id", $presupuesto_id) + ->where("t1.deleted_at IS NULL") + ->where("t2.deleted_at IS NULL") + ->where("t1.estado", "validada") + ->get() + ->getResultObject(); + + return !empty($result); + } + public function getSumatoriosFacturacionCliente($cliente_id = -1){ if($cliente_id == -1){ diff --git a/ci4/app/Models/Pedidos/PedidoLineaModel.php b/ci4/app/Models/Pedidos/PedidoLineaModel.php index ca0e9b56..1e19c4cf 100644 --- a/ci4/app/Models/Pedidos/PedidoLineaModel.php +++ b/ci4/app/Models/Pedidos/PedidoLineaModel.php @@ -36,6 +36,8 @@ class PedidoLineaModel extends \App\Models\BaseModel "user_updated_id", "created_at", "updated_at", + "cantidad", + "descripcion", ]; protected $returnType = "App\Entities\Pedidos\PedidoLineaEntity"; diff --git a/ci4/app/Models/Pedidos/PedidoModel.php b/ci4/app/Models/Pedidos/PedidoModel.php index 7a7bdbf0..a5379fba 100644 --- a/ci4/app/Models/Pedidos/PedidoModel.php +++ b/ci4/app/Models/Pedidos/PedidoModel.php @@ -117,15 +117,28 @@ class PedidoModel extends \App\Models\BaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t2.presupuesto_id" + "t2.presupuesto_id, t3.total_aceptado, t2.descripcion, t2.cantidad" ); $builder->where("t1.id", $pedido_id); $builder->join("pedidos_linea t2", "t2.pedido_id = t1.id", "left"); + $builder->join("presupuestos t3", "t2.presupuesto_id = t3.id", "left"); $model_presupuesto = model("App\Models\Presupuestos\PresupuestoModel"); $lineasPresupuesto = []; foreach ($builder->get()->getResultObject() as $row) { - array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]); + if($row->descripcion == null){ + array_push($lineasPresupuesto, $model_presupuesto->generarLineaPedido($row->presupuesto_id)[0]); + } + else{ + $presupuesto = (object) [ + 'numero' => $row->presupuesto_id, + 'unidades' => $row->cantidad, + 'total' => $row->total_aceptado, + 'concepto' => $row->descripcion, + ]; + array_push($lineasPresupuesto, $presupuesto); + } + } $builder->groupBy("t1.id"); diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index 894259a1..74c73088 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -1885,9 +1885,12 @@ class PresupuestoService extends BaseService $pedido_id = $model_pedido->insert($data_pedido); if ($pedido_id) { + $lineas_pedido = $model_presupuesto->generarLineaPedido($presupuesto_id)[0]; $data_pedido_linea = [ "pedido_id" => $pedido_id, "presupuesto_id" => $presupuesto_id, + 'cantidad' => $lineas_pedido->unidades, + 'descripcion' => $lineas_pedido->concepto, "ubicacion_id" => 1, // safetak por defecto "user_created_id" => auth()->user()->id, "user_updated_id" => auth()->user()->id, diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index 70d89973..21221dd2 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -86,7 +86,7 @@ - + @@ -210,6 +210,15 @@ if(inaplazable?1:0 ?>){ $('.inaplazable-date').addClass('text-danger fw-bold'); } +const autonumericTotalPrecio = new AutoNumeric('#total_precio', { + decimalPlaces: 2, + digitGroupSeparator: '.', + decimalCharacter: ',', + allowDecimalPadding: true, + unformatOnSubmit: true, +}); + + $("#fecha_entrega_real").flatpickr({ defaultDate: fecha_entrega_real_text ? "'".$pedidoEntity->fecha_entrega_real_text."'" : 'null' ?>, From 9ee2a833b5abad1f5b194eef2e2db143ada67387 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 12 Apr 2025 21:11:20 +0200 Subject: [PATCH 18/18] =?UTF-8?q?Comprobar=20que=20el=20directorio=20RBAC?= =?UTF-8?q?=20existe=20y=20a=C3=B1adido=20.gitkeep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Helpers/rbac_helper.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/ci4/app/Helpers/rbac_helper.php b/ci4/app/Helpers/rbac_helper.php index 422250a6..5ab2808b 100644 --- a/ci4/app/Helpers/rbac_helper.php +++ b/ci4/app/Helpers/rbac_helper.php @@ -29,8 +29,12 @@ if (!function_exists('generate_php_roles_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/roles.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/roles.php"; file_put_contents($filePath, $phpCode); } @@ -58,9 +62,14 @@ if (!function_exists('generate_php_permissions_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/permissions.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/permissions.php"; file_put_contents($filePath, $phpCode); + } } @@ -87,8 +96,12 @@ if (!function_exists('generate_php_permissions_matrix_constant')) { // Close the array $phpCode .= "];\n"; - // Write PHP code to a file - $filePath = APPPATH . "Config/RBAC/permissionMatrix.php"; + $dirPath = APPPATH . "Config/RBAC"; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0775, true); // true permite crear carpetas anidadas + } + + $filePath = $dirPath . "/permissionMatrix.php"; file_put_contents($filePath, $phpCode); } } @@ -130,9 +143,9 @@ if (!function_exists('checkGroups')) { */ function checkGroups(array $groups, string $redirectRoute = null) { - $session = \Config\Services::session(); + $session = \Config\Services::session(); $response = \Config\Services::response(); - $auth = auth(); // Shield auth service + $auth = auth(); // Shield auth service $user = $auth->user();