From 3171c32283977b99029515d302285dbce6765fed Mon Sep 17 00:00:00 2001 From: jaimejimenezortega Date: Sun, 16 Jun 2024 01:47:34 +0200 Subject: [PATCH] faltan las fechas --- ci4/app/Config/Routes.php | 9 + ci4/app/Controllers/Pedidos/Albaran.php | 262 ++++++++++++++- ci4/app/Controllers/Pedidos/Pedido.php | 93 ++++++ .../Entities/Pedidos/AlbaranLineaEntity.php | 7 + ci4/app/Language/en/Pedidos.php | 5 + ci4/app/Language/es/Pedidos.php | 6 + ci4/app/Models/Pedidos/AlbaranLineaModel.php | 11 + ci4/app/Models/Pedidos/AlbaranModel.php | 10 +- .../vuexy/form/pedidos/_albaranesItems.php | 302 +++++++++++++++--- .../vuexy/form/pedidos/_cabeceraItems.php | 87 ++++- 10 files changed, 738 insertions(+), 54 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 4888631d..62f6a3e7 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -628,6 +628,9 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->post('add', 'Pedido::add', ['as' => 'crearPedido']); $routes->get('edit/(:any)', 'Pedido::edit/$1', ['as' => 'editarPedido']); $routes->post('getlineas', 'Pedido::getLineas', ['as' => 'tablaLineasPedido']); + $routes->post('cambiarestado', 'Pedido::cambiarEstado', ['as' => 'cambiarEstadoPedido']); + $routes->post('update/(:any)', 'Pedido::update/$1', ['as' => 'actualizarPedido']); + }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); @@ -635,6 +638,12 @@ $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'control $routes->group('albaranes', ['namespace' => 'App\Controllers\Pedidos'], function ($routes) { $routes->post('add', 'Albaran::add', ['as' => 'crearAlbaranesPedido']); $routes->post('update/(:any)', 'Albaran::update/$1', ['as' => 'actualizarAlbaran']); + $routes->post('updateLinea/(:any)', 'Albaran::updateLinea/$1', ['as' => 'actualizarLineaAlbaran']); + $routes->post('deletelinea', 'Albaran::borrarlinea', ['as' => 'borrarAlbaranLinea']); + $routes->get('delete/(:any)', 'Albaran::delete/$1', ['as' => 'borrarAlbaran']); + $routes->get('getalbaranes/(:any)', 'Albaran::getAlbaranes/$1', ['as' => 'getAlbaranes']); + $routes->get('nuevalinea/(:any)', 'Albaran::addLinea/$1', ['as' => 'addAlbaranLinea']); + $routes->post('nuevalinea/(:any)', 'Albaran::addLinea/$1', ['as' => 'addIVA']); }); $routes->resource('albaranes', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Albaran', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Pedidos/Albaran.php b/ci4/app/Controllers/Pedidos/Albaran.php index af89d98f..f5af3504 100644 --- a/ci4/app/Controllers/Pedidos/Albaran.php +++ b/ci4/app/Controllers/Pedidos/Albaran.php @@ -1,6 +1,7 @@ request->isAJAX()) { + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $model_linea->where('albaran_id', $id)->delete(); + + $this->model->where('id', $id)->delete(); + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } } + public function addLinea($albaran_id){ + + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + // si es un post, es el iva + if($this->request->getPost()){ + $reqData = $this->request->getPost(); + $albaran_id = $reqData['albaran_id'] ?? 0; + + $albaran = $this->model->find($albaran_id); + if($albaran == false){ + $data = [ + 'error' => 'Albaran no encontrado', + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + $presupuesto_model = model('App\Models\Presupuestos\PresupuestoModel'); + $presupuesto = $presupuesto_model->find($albaran->presupuesto_id); + if($presupuesto == false){ + $data = [ + 'error' => 'Presupuesto no encontrado', + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + $iva_reducido = $presupuesto->iva_reducido; + $lineas = $model_linea->where('albaran_id', $albaran_id)->findAll(); + $total = 0; + foreach($lineas as $linea){ + $total += $linea->total; + } + $iva = $iva_reducido? $total * 4.0 / 100: $total * 21.0 / 100; + $data_linea= [ + 'albaran_id' => $albaran_id, + 'titulo' => $iva_reducido?lang('Pedidos.iva4'):lang('Pedidos.iva21'), + 'cantidad' => 1, + 'precio_unidad' => round($iva,2), + 'total' => round($iva,2), + 'user_created_id' => auth()->user()->id, + 'user_updated_id' => auth()->user()->id + ]; + $id_linea = $model_linea->insert($data_linea); + $linea = $model_linea->find($id_linea); + $data = [ + 'error' => 0, + 'data' => $linea, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else{ + $linea = [ + 'albaran_id' => $albaran_id, + 'user_created_id' => auth()->user()->id, + 'user_updated_id' => auth()->user()->id + ]; + $id_linea = $model_linea->insert($linea); + $data = $model_linea->find($id_linea); + + $data = [ + 'error' => 0, + 'data' => $data, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } public function add() { @@ -64,14 +159,22 @@ class Albaran extends \App\Controllers\BaseResourceController $csrfTokenName = csrf_token(); if ($id == null) : - return $this->redirect2listView(); + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); endif; $id = filter_var($id, FILTER_SANITIZE_URL); $albaranEntity = $this->model->find($id); if ($albaranEntity == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); - return $this->redirect2listView('sweet-error', $message); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); endif; if ($this->request->getPost()) : @@ -128,5 +231,158 @@ class Albaran extends \App\Controllers\BaseResourceController } } + + public function updateLinea($id = null){ + + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($id == null) : + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + $id = filter_var($id, FILTER_SANITIZE_URL); + $albaranEntity = $model_linea->find($id); + + if ($albaranEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + if ($this->request->getPost()) : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = auth()->user()->id; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + try { + $successfulResult = $model_linea->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); + $this->session->setFlashdata('formErrors', $model_linea->errors()); + + endif; + + $albaranEntity->fill($sanitizedData); + + endif; + if ($noException && $successfulResult) : + $id = $albaranEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function borrarLinea(){ + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $reqData = $this->request->getPost(); + $id = $reqData['id'] ?? 0; + $id = filter_var($id, FILTER_SANITIZE_URL); + $albaranLineaEntity = $model_linea->find($id); + + if ($albaranLineaEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + $successfulResult = $model_linea->skipValidation(true)->update($id, ['deleted_at' => date('Y-m-d H:i:s')]); + + if ($successfulResult) : + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + else: + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + endif; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function getAlbaranes($pedido_id = null){ + if ($this->request->isAJAX()) { + + $model_linea = model('App\Models\Pedidos\AlbaranLineaModel'); + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $returnData = []; + $albaranes = $this->model->asArray()->where('pedido_id', $pedido_id)->findAll(); + + foreach($albaranes as $albaran){ + $albaran['fecha_albaran'] = $albaran['updated_at']; + array_push($returnData, + [ + 'albaran' => $albaran, + 'lineas' => $model_linea->asArray()->where('albaran_id', $albaran['id'])->findAll()] + ); + } + + $data = [ + 'data' => $returnData, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } } \ No newline at end of file diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index 1fa366fd..d17b0902 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -80,6 +80,99 @@ class Pedido extends \App\Controllers\BaseResourceController } + public function cambiarEstado(){ + if($this->request->isAJAX()){ + + $id = $this->request->getPost('id'); + $estado = $this->request->getPost('estado'); + + $this->model->where('id', $id)->set(['estado' => $estado])->update(); + return $this->respond(['status' => 'success', 'message' => lang('Basic.global.success')]); + }else{ + return $this->failUnauthorized('Invalid request', 403); + } + } + + + public function update($id = null){ + + if ($this->request->isAJAX()) { + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + if ($id == null) : + $data = [ + 'error' => 2, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + $id = filter_var($id, FILTER_SANITIZE_URL); + $pedidoEntity = $this->model->find($id); + + if ($pedidoEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]); + $data = [ + 'error' => $message, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + endif; + + if ($this->request->getPost()) : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = auth()->user()->id; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $pedidoEntity->fill($sanitizedData); + + endif; + if ($noException && $successfulResult) : + $id = $pedidoEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + $data = [ + 'error' => 0, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $data = [ + 'error' => 1, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } + else { + return $this->failUnauthorized('Invalid request', 403); + } + } + public function edit($id=null){ if ($id == null) : diff --git a/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php b/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php index de5bda52..c2137df8 100644 --- a/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php +++ b/ci4/app/Entities/Pedidos/AlbaranLineaEntity.php @@ -16,6 +16,11 @@ class AlbaranLineaEntity extends \CodeIgniter\Entity\Entity 'ejemplares_por_caja' => null, 'precio_unidad' => null, 'total' => null, + 'user_created_id' => null, + 'user_updated_id' => null, + 'created_at' => null, + 'updated_at' => null, + 'deleted_at' => null, ]; protected $casts = [ @@ -29,5 +34,7 @@ class AlbaranLineaEntity extends \CodeIgniter\Entity\Entity 'ejemplares_por_caja' => '?integer', 'precio_unidad' => 'float', 'total' => 'float', + 'user_created_id' => 'integer', + 'user_updated_id' => 'integer', ]; } \ No newline at end of file diff --git a/ci4/app/Language/en/Pedidos.php b/ci4/app/Language/en/Pedidos.php index 4ca46f10..0e58640a 100644 --- a/ci4/app/Language/en/Pedidos.php +++ b/ci4/app/Language/en/Pedidos.php @@ -45,6 +45,9 @@ return [ 'pedidos' => 'Orders', 'pedidosList' => 'Orders List', + 'cancelar' => 'Cancel', + 'finalizar' => 'Finish', + 'unaCara' => '1 side', 'dosCaras' => '2 sides', @@ -68,6 +71,8 @@ return [ 'nuevaLinea' => 'New line', 'addIva' => "Add VAT", 'mostrarPrecios' => 'Show prices', + 'iva4' => "4,00 % VAT", + 'iva21' => "21,00 % VAT", 'facturas' => 'Invoices', diff --git a/ci4/app/Language/es/Pedidos.php b/ci4/app/Language/es/Pedidos.php index 906321ee..5e790760 100644 --- a/ci4/app/Language/es/Pedidos.php +++ b/ci4/app/Language/es/Pedidos.php @@ -44,6 +44,9 @@ return [ 'pedidos' => 'Pedidos', 'pedidosList' => 'Lista de Pedidos', + 'cancelar' => 'Cancelar', + 'finalizar' => 'Finalizar', + 'unaCara' => '1 cara', 'dosCaras' => '2 caras', @@ -67,6 +70,9 @@ return [ 'nuevaLinea' => 'Nueva línea', 'addIva' => "Añadir IVA", 'mostrarPrecios' => 'Mostrar precios', + 'iva4' => "4,00 % IVA", + 'iva21' => "21,00 % IVA", + 'facturas' => 'Facturas', diff --git a/ci4/app/Models/Pedidos/AlbaranLineaModel.php b/ci4/app/Models/Pedidos/AlbaranLineaModel.php index a384fb22..62f6ccd4 100644 --- a/ci4/app/Models/Pedidos/AlbaranLineaModel.php +++ b/ci4/app/Models/Pedidos/AlbaranLineaModel.php @@ -25,6 +25,17 @@ class AlbaranLineaModel extends \App\Models\BaseModel 'ejemplares_por_caja', 'precio_unidad', 'total', + 'user_created_id', + 'user_updated_id', + 'created_at', + 'updated_at', + 'deleted_at', ]; + protected $useSoftDeletes = true; + protected $useTimestamps = true; + protected $createdField = 'created_at'; + protected $updatedField = 'updated_at'; + protected $deletedField = 'deleted_at'; + } \ No newline at end of file diff --git a/ci4/app/Models/Pedidos/AlbaranModel.php b/ci4/app/Models/Pedidos/AlbaranModel.php index 63415da1..3834ca30 100644 --- a/ci4/app/Models/Pedidos/AlbaranModel.php +++ b/ci4/app/Models/Pedidos/AlbaranModel.php @@ -2,6 +2,8 @@ namespace App\Models\Pedidos; + + class AlbaranModel extends \App\Models\BaseModel { protected $table = "albaranes"; @@ -33,9 +35,11 @@ class AlbaranModel extends \App\Models\BaseModel 'deleted_at', ]; + protected $useSoftDeletes = true; protected $useTimestamps = true; protected $createdField = 'created_at'; protected $updatedField = 'updated_at'; + protected $deletedField = 'deleted_at'; public function generarAlbaranes($pedido_id, $presupuestos_id, $user_id){ @@ -64,7 +68,9 @@ class AlbaranModel extends \App\Models\BaseModel 'cajas' => 1, 'ejemplares_por_caja' => $envio->cantidad, 'precio_unidad' => $precio_unidad, - 'total' => $precio_unidad * $envio->cantidad + 'total' => $precio_unidad * $envio->cantidad, + 'user_created_id' => $user_id, + 'user_updated_id' => $user_id, ]; @@ -98,7 +104,7 @@ class AlbaranModel extends \App\Models\BaseModel $id_albaran_linea =$model_albaran_linea->insert($albaran_linea); $albaran_linea['id'] = $id_albaran_linea; - array_push($return_data, ["albaran"=>$albaran, "albaran_linea" =>$albaran_linea]); + array_push($return_data, ["albaran"=>$albaran, "lineas" =>[$albaran_linea]]); } } diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php index caf1a195..55eacaac 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_albaranesItems.php @@ -59,7 +59,7 @@ const deleteLineaBtns = function(data) { return `
- +
`; }; @@ -68,8 +68,9 @@ function generarAlbaran(item){ // Crear los elementos necesarios const accordion = $('
', { - class: 'accordion accordion-bordered mt-3', - id: 'albaran' + item.albaran_linea.id + class: 'accordion accordion-bordered mt-3 accordion-albaran', + id: 'accordioAlbaran' + item.albaran.id, + albaran: item.albaran.id }); const card = $('
', { @@ -78,16 +79,17 @@ function generarAlbaran(item){ const header = $('

', { class: 'accordion-header', - id: 'headingAlbaran' + item.albaran_linea.id + id: 'headingAlbaran' + item.albaran.id }); const button = $('

`; @@ -182,7 +184,7 @@ function generarAlbaran(item){ $(''), $('').append( $('').append( - $('', { colspan: '5', style: 'text-align:right' }).text('') + $('', { colspan: '9', style: 'text-align:right' }).text('') ) ), ); @@ -200,20 +202,20 @@ function generarAlbaran(item){
-
+
-
+
-
+
-
+
@@ -260,12 +262,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'unidades_' + item.albaran_linea.id, - name: 'unidades_' + item.albaran_linea.id, + id: 'cantidad_' + row.id, + name: 'cantidad_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -279,12 +282,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'titulo_' + item.albaran_linea.id, - name: 'titulo_' + item.albaran_linea.id, + id: 'titulo_' + row.id, + name: 'titulo_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -298,12 +302,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'isbn_' + item.albaran_linea.id, - name: 'isbn_' + item.albaran_linea.id, + id: 'isbn_' + row.id, + name: 'isbn_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller' @@ -316,12 +321,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'ref_cliente_' + item.albaran_linea.id, - name: 'ref_cliente_' + item.albaran_linea.id, + id: 'ref_cliente_' + row.id, + name: 'ref_cliente_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller' @@ -334,12 +340,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'cajas_' + item.albaran_linea.id, - name: 'cajas_' + item.albaran_linea.id, + id: 'cajas_' + row.id, + name: 'cajas_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -353,12 +360,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'ejemplares_por_caja_' + item.albaran_linea.id, - name: 'ejemplares_por_caja_' + item.albaran_linea.id, + id: 'ejemplares_por_caja_' + row.id, + name: 'ejemplares_por_caja_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -373,12 +381,13 @@ function generarAlbaran(item){ value = parseFloat(data).toFixed(4); var input = $('', { - id: 'precio_unidad_' + item.albaran_linea.id, - name: 'precio_unidad_' + item.albaran_linea.id, + id: 'precio_unidad_' + row.id, + name: 'precio_unidad_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: value + value: value, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -392,12 +401,13 @@ function generarAlbaran(item){ render: function ( data, type, row, meta ) { var input = $('', { - id: 'total_' + item.albaran_linea.id, - name: 'total_' + item.albaran_linea.id, + id: 'total_' + row.id, + name: 'total_' + row.id, class: 'lp-cell lp-input albaran_linea', albaran: item.albaran.numero_albaran, type: 'text', - value: data + value: data, + linea: row.id }).css({ 'text-align': 'center', 'font-size': 'smaller', @@ -423,16 +433,58 @@ function generarAlbaran(item){ this.api().column(numColumns - 2).visible(true); } - } + }, + footerCallback: function (row, data, start, end, display) { + + /* + let api = this.api(); + var numColumns = api.columns().count(); + + if(item.albaran.mostrar_precios == 1){ + + // Remove the formatting to get integer data for summation + let intVal = function (i) { + return typeof i === 'string' + ? i.replace(/[\$,]/g, '') * 1 + : typeof i === 'number' + ? i + : 0; + }; + + // Total over all pages + total = api + .column(9) + .data() + .reduce((a, b) => intVal(a) + intVal(b), 0); + + // Update footer + api.column(numColumns-1).footer().innerHTML = + 'Total: ' + total.toFixed(2); + } + else{ + api.column(numColumns-1).footer().innerHTML = ''; + } + */ + }, }); // Añadir la nueva fila a la tabla - datatableAlbaran.row.add(item.albaran_linea).draw(); - - + if(Array.isArray(item.lineas)) { + item.lineas.forEach(function(linea) { + datatableAlbaran.row.add(linea).draw(); + }); + } } +$(document).on('click', '.accordion-button', function(){ + + var albaran_id = $(this).attr('albaran'); + var table = $('#tablaAlbaran' + albaran_id).DataTable(); + table.columns.adjust(); +}); + $(document).on('change', '.cambios-albaran', function(){ + var elementId = $(this).attr('id'); data = { @@ -492,6 +544,166 @@ $(document).on('change', '.mostrar-precios', function(){ }); }); +$(document).on('click', '.btn-delete-linea', function(){ + var elementId = $(this).attr('id'); + var domTable = $(this).closest('table'); + var table = domTable.DataTable(); + const row = $(this).closest('tr'); + var url = ''; + $.ajax({ + url: url, + type: 'POST', + data: { + id: $(this).attr('data-id'), + : v, + }, + success: function(response){ + + if('error' in response){ + if(response.error == 0){ + table.row($(row)).remove().draw(); + } + } + } + }); +}); +$(document).on('change', '.albaran_linea', function(){ + + var elementId = $(this).attr('id'); + + data = { + : v, + }; + data[elementId.split('_').slice(0, -1).join('_')] = $(this).val(); + + var linea_id = $(this).attr('linea'); + var url = ''; + url = url.replace(':id', linea_id ); + + $.ajax({ + url: url, + type: 'POST', + data: data, + success: function(response){ + + if('error' in response){ + + } + } + }); + +}); + +$(document).on('click', '#borrar_albaranes', function(){ + + // seleccionan todos los accordion dentro del body del accordion accordioAlbaranes + $('.accordion-albaran').each(function() { + // Aquí puedes trabajar con cada acordeón interno encontrado + var albaran_id = $(this).attr('albaran'); + var url = ''; + url = url.replace(':id', albaran_id ); + $.ajax({ + url: url, + type: 'GET', + success: function(response){ + if(response){ + if('error' in response){ + if(response.error == 0){ + $('#accordioAlbaran' + albaran_id).remove(); + } + } + } + } + }); + }); +}); + +$(document).on('click', '.borrar-albaran', function(){ + + var albaran_id = $(this).attr('id').split('_').slice(-1)[0]; + var url = ''; + url = url.replace(':id', albaran_id ); + $.ajax({ + url: url, + type: 'GET', + success: function(response){ + if(response){ + if('error' in response){ + if(response.error == 0){ + $('#accordioAlbaran' + albaran_id).remove(); + } + } + } + } + }); +}); + +$(document).on('click', '.nueva-linea-albaran', function(){ + + var albaran_id = $(this).attr('id').split('_').slice(-1)[0]; + var url = ''; + url = url.replace(':id', albaran_id ); + $.ajax({ + url: url, + type: 'GET', + success: function(response){ + if(response){ + if('error' in response){ + if(response.error == 0){ + var table = $('#tablaAlbaran' + albaran_id).DataTable(); + table.row.add(response.data).draw(); + } + } + } + } + }); +}); + +$(document).on('click', '.add-iva-albaran', function(){ + + var albaran_id = $(this).attr('id').split('_').slice(-1)[0]; + var url = ''; + url = url.replace(':id', albaran_id ); + data = { + albaran_id: albaran_id, + : v, + }; + $.ajax({ + url: url, + type: 'POST', + data: data, + success: function(response){ + if(response){ + if('error' in response){ + if(response.error == 0){ + var table = $('#tablaAlbaran' + albaran_id).DataTable(); + table.row.add(response.data).draw(); + } + } + } + } + }); +}); + +$(document).on('click', '.imprimir-albaran', function(){ + + var albaran_id = $(this).attr('id').split('_').slice(-1)[0]; + + //NACHO AQUI +}); + +$.ajax({ + url: 'id) ?>', + type: 'GET', + success: function(response){ + + if(response.data.length > 0){ + Object.values(response.data).forEach(function(item){ + generarAlbaran(item); + }); + } + } +}); endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php index d1a0f0f9..9dc42d6f 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/_cabeceraItems.php @@ -104,7 +104,7 @@
-
@@ -123,7 +123,7 @@ - +
@@ -131,7 +131,7 @@ - +
@@ -139,6 +139,20 @@
+ + estado !== 'finalizado' && $pedidoEntity->estado !== 'cancelado'): ?> +
+
+ + +
+
+ + +
+
+ + @@ -160,6 +174,9 @@ $("#fecha_entrega_real").flatpickr({ longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], }, }, + onChange: function(selectedDates, instance) { + updateDate('fecha_entrega_real', selectedDates); + } }); $("#fecha_impresion").flatpickr({ @@ -175,6 +192,9 @@ $("#fecha_impresion").flatpickr({ longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], }, }, + onChange: function(selectedDates, dateStr, instance) { + updateDate('fecha_impresion', dateStr); + } }); $("#fecha_encuadernado").flatpickr({ @@ -190,6 +210,9 @@ $("#fecha_encuadernado").flatpickr({ longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], }, }, + onChange: function(selectedDates, dateStr, instance) { + updateDate('fecha_encuadernado', dateStr); + } }); $("#fecha_entrega_externo").flatpickr({ @@ -205,6 +228,62 @@ $("#fecha_entrega_externo").flatpickr({ longhand: ['Enero', 'Febreo', 'Мarzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], }, }, + onChange: function(selectedDates, dateStr, instance) { + updateDate('fecha_entrega_externo', dateStr); + } }); +estado !== 'finalizado' && $pedidoEntity->estado !== 'cancelado'): ?> +$('.buton-estado').on('click', function() { + var id = id ?>; + var estado = $(this).attr('id').split('_')[1]; + var url = ''; + var data = { + id: id, + estado: estado + }; + $.ajax({ + url: url, + type: 'POST', + data: data, + success: function(response) { + try{ + if (response.status=="success") { + location.reload(); + } + } + catch(e){ + console.log(e); + } + } + }); +}); + + + +function updateDate(elementId, dateStr) { + var id = id ?>; + + data = { + : v, + }; + data[elementId] = dateStr; + + var url = ''; + url = url.replace(':id', id ); + + $.ajax({ + url: url, + type: 'POST', + data: data, + success: function(response){ + + if('error' in response){ + + } + } + }); + +} + endSection() ?> \ No newline at end of file