From 6450231b53cbab517fc9d99c97f80187d10c0674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 22 Apr 2025 10:26:33 +0200 Subject: [PATCH] terminados albaranes --- ci4/app/Controllers/Albaranes/Albaran.php | 7 +++ ci4/app/Entities/Albaranes/AlbaranEntity.php | 2 + ci4/app/Models/Albaranes/AlbaranModel.php | 1 + .../form/logistica/viewEnvioEditForm.php | 3 +- ci4/app/Views/themes/vuexy/pdfs/albaran.php | 2 +- .../js/safekat/components/albaranComponent.js | 45 ++++++++++++++++++- 6 files changed, 56 insertions(+), 4 deletions(-) diff --git a/ci4/app/Controllers/Albaranes/Albaran.php b/ci4/app/Controllers/Albaranes/Albaran.php index 3531c2c4..109d00f0 100755 --- a/ci4/app/Controllers/Albaranes/Albaran.php +++ b/ci4/app/Controllers/Albaranes/Albaran.php @@ -175,6 +175,13 @@ class Albaran extends \App\Controllers\BaseResourceController return $this->respond($data); } + if($fieldName == 'fecha_albaran'){ + if($fieldValue == null || $fieldValue == '') + $fieldValue = null; + else + $fieldValue = date('Y-m-d H:i:s', strtotime($fieldValue)); + } + $albaranEntity->fill([ $fieldName => $fieldValue, 'user_updated_id' => auth()->user()->id, diff --git a/ci4/app/Entities/Albaranes/AlbaranEntity.php b/ci4/app/Entities/Albaranes/AlbaranEntity.php index 6c2d61e3..b5928c10 100755 --- a/ci4/app/Entities/Albaranes/AlbaranEntity.php +++ b/ci4/app/Entities/Albaranes/AlbaranEntity.php @@ -14,6 +14,7 @@ class AlbaranEntity extends \CodeIgniter\Entity\Entity 'mostrar_precios' => null, 'direccion_albaran' => null, 'att_albaran' => null, + 'fecha_albaran' => null, 'user_created_id' => null, 'user_updated_id' => null, 'created_at' => null, @@ -38,6 +39,7 @@ class AlbaranEntity extends \CodeIgniter\Entity\Entity 'att_albaran' => '?string', 'user_created_id' => 'integer', 'user_updated_id' => 'integer', + 'fecha_albaran' => '?datetime', ]; // Agrega tus métodos personalizados aquí diff --git a/ci4/app/Models/Albaranes/AlbaranModel.php b/ci4/app/Models/Albaranes/AlbaranModel.php index acd67487..42b492f2 100644 --- a/ci4/app/Models/Albaranes/AlbaranModel.php +++ b/ci4/app/Models/Albaranes/AlbaranModel.php @@ -22,6 +22,7 @@ class AlbaranModel extends \App\Models\BaseModel 'numero_albaran', 'mostrar_precios', 'direccion_albaran', + 'fecha_albaran', 'att_albaran', 'user_created_id', 'user_updated_id', diff --git a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php index 4214feea..d9016dc6 100644 --- a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php +++ b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php @@ -283,6 +283,7 @@ +"> endSection() ?> @@ -290,7 +291,5 @@ - - endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/pdfs/albaran.php b/ci4/app/Views/themes/vuexy/pdfs/albaran.php index f7effbe6..00ebc343 100755 --- a/ci4/app/Views/themes/vuexy/pdfs/albaran.php +++ b/ci4/app/Views/themes/vuexy/pdfs/albaran.php @@ -52,7 +52,7 @@ FECHA: - fecha_albaran ? date('d-m-Y', strtotime($albaran->fecha_albaran)) : date('d-m-Y') ?> + fecha_albaran ? $albaran->fecha_albaran : date('d-m-Y') ?> diff --git a/httpdocs/assets/js/safekat/components/albaranComponent.js b/httpdocs/assets/js/safekat/components/albaranComponent.js index 5064e583..92ca1c32 100644 --- a/httpdocs/assets/js/safekat/components/albaranComponent.js +++ b/httpdocs/assets/js/safekat/components/albaranComponent.js @@ -1,3 +1,4 @@ +import DatePicker from "./datepicker.js"; class AlbaranComponent { constructor(item) { @@ -8,9 +9,15 @@ class AlbaranComponent { this.att = item.att; this.direccion = item.direccion; this.envio_id = item.envio_id; + this.fecha = null; + if(this.item.fecha_albaran != null){ + const [dia, mes, anio] = item.fecha_albaran.split('/'); + this.fecha = `${anio}-${mes.padStart(2, '0')}-${dia.padStart(2, '0')}`; + } this.selectorTabla = `#tablaAlbaran${this.id}`; this.table = null; + this.fechaAlbaran = null; } mount(selector) { @@ -257,6 +264,15 @@ class AlbaranComponent { } }); + const option = { + altInput: true, + altFormat: "d/m/Y", + dateFormat: "Y-m-d", + allowInput: true, + } + this.fechaAlbaran = new DatePicker($('#fecha_albaran_' + this.id), option); + this.fechaAlbaran.setDate(this.fecha); + $('#tablaAlbaran' + this.id).on('click', '.btn-delete-albaran-lineas', (e) => { e.preventDefault(); const table = $('#tablaAlbaran' + this.id).DataTable(); @@ -386,6 +402,33 @@ class AlbaranComponent { }); }); + $('#fecha_albaran_' + this.item.id).on('change', (e) => { + const value = $(e.currentTarget).val(); + const albaranId = this.id; + + $.post('/albaranes/updateAlbaran', { + albaranId: albaranId, + fieldName: 'fecha_albaran', + fieldValue: value + }, (response) => { + if (response.success) { + this.table.ajax.reload(null, false); + } else { + Swal.fire({ + title: 'Error', + text: 'No se ha podido actualizar el albarán', + icon: 'error', + showCancelButton: false, + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }); + } + }); + }); $("#borrar_albaran_" + this.item.id).on('click', (e) => { e.preventDefault(); @@ -547,7 +590,7 @@ class AlbaranComponent { var albaran_id = this.id; window.open('/print-albaran/generar/'+ albaran_id , '_blank'); - }); + }); } _initAutoNumericInputs() {