From fe164c4ab3ba137e411c0280c7f2c258913de625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Mon, 21 Apr 2025 12:43:09 +0200 Subject: [PATCH] trabajando --- ci4/app/Controllers/Albaranes/Albaran.php | 42 +++++++++++++++++-- .../js/safekat/components/albaranComponent.js | 31 ++++++++++++++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/ci4/app/Controllers/Albaranes/Albaran.php b/ci4/app/Controllers/Albaranes/Albaran.php index 3fc586e9..a9680853 100644 --- a/ci4/app/Controllers/Albaranes/Albaran.php +++ b/ci4/app/Controllers/Albaranes/Albaran.php @@ -339,16 +339,19 @@ class Albaran extends \App\Controllers\BaseResourceController return '' . $q->pedido . ''; }) ->edit('unidades', function ($q) { - return ''; + return ''; }) ->edit('titulo', function ($q) { - return ''; + return ''; }) ->edit('total', function ($q) { - return ''; + return ''; }) ->edit('precio_unidad', function ($q) { - return ''; }); @@ -357,6 +360,37 @@ class Albaran extends \App\Controllers\BaseResourceController return $result->toJson(returnAsObject: true); } + public function updateAlbaranLinea(){ + + if ($this->request->isAJAX()) { + + $fieldName = $this->request->getPost('fieldName'); + $fieldValue = $this->request->getPost('fieldValue'); + $id = $this->request->getPost('lineaId'); + + if ($id == null) { + $data = [ + 'success' => false, + 'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]), + ]; + return $this->respond($data); + } + $albaranEntity = model('App\Models\Albaranes\AlbaranLineaModel')->find($id); + + if ($albaranEntity == false) { + $data = [ + 'success' => false, + 'message' => lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]), + ]; + return $this->respond($data); + } + + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + public function borrarLinea() { diff --git a/httpdocs/assets/js/safekat/components/albaranComponent.js b/httpdocs/assets/js/safekat/components/albaranComponent.js index 3abf586a..2ec916ce 100644 --- a/httpdocs/assets/js/safekat/components/albaranComponent.js +++ b/httpdocs/assets/js/safekat/components/albaranComponent.js @@ -440,6 +440,37 @@ class AlbaranComponent { }); }); + + $('#tablaAlbaran' + this.id).on('change', '.input-albaran-linea', (e) => { + + const fieldName = $(e.currentTarget).attr('data-field'); + const fieldValue = $(e.currentTarget).val(); + const albaranId = this.id; + const lineaId = $(e.currentTarget).attr('data-id'); + + $.post('/albaranes/updateAlbaranLinea', { + fieldName: fieldName, + fieldValue: fieldValue, + lineaId: lineaId + }, (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 + }); + } + }); + }); } _initAutoNumericInputs() {