From a54838d468e8158132c623995cad12b338b83cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= <“jaimejimenezortega@gmail.com”> Date: Tue, 2 Jan 2024 21:01:42 +0100 Subject: [PATCH] terminado plantillas --- ci4/app/Controllers/Clientes/Cliente.php | 6 +- .../Clientes/Clienteplantillaprecios.php | 53 ++++++++++++--- .../Clienteplantillaprecioslineas.php | 33 ++++++++++ .../Controllers/Clientes/Clienteprecios.php | 9 +-- ci4/app/Language/en/ClientePrecios.php | 8 ++- ci4/app/Language/es/ClientePrecios.php | 4 ++ .../ClientePlantillaPreciosLineasModel.php | 37 +++++++++++ .../Models/Clientes/ClientePreciosModel.php | 11 +++- .../clientes/cliente/_clienteFormItems.php | 41 ++++++++---- .../cliente/convert2templateModal.php | 65 +++++++++++++++++++ .../form/clientes/cliente/viewClienteForm.php | 7 +- .../viewClienteplantillapreciosList.php | 13 ++++ 12 files changed, 250 insertions(+), 37 deletions(-) create mode 100644 ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/convert2templateModal.php diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 5aa05865..0d027c33 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -445,12 +445,12 @@ class Cliente extends \App\Controllers\GoBaseResourceController $modelPreciosCliente = model('App\Models\Clientes\ClientePreciosModel'); $plantilla_id = $modelPreciosCliente->get_plantilla_precios($cliente_id); if (is_null($plantilla_id)){ - return []; + return null; } $modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel'); - $plantilla = $modelPlantillaPreciosCliente->find($plantilla_id); + $plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first(); if ($plantilla == false){ - return []; + return null; } else{ return (object)array( diff --git a/ci4/app/Controllers/Clientes/Clienteplantillaprecios.php b/ci4/app/Controllers/Clientes/Clienteplantillaprecios.php index c6fa3ade..741c500e 100755 --- a/ci4/app/Controllers/Clientes/Clienteplantillaprecios.php +++ b/ci4/app/Controllers/Clientes/Clienteplantillaprecios.php @@ -66,6 +66,32 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController } + // Este metodo aqui se usa para poner el is_deleted a 1 cuando se borra una + // plantilla desde la lista + public function update($requestedId = null) + { + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + if ($requestedId == null) : + return; + endif; + $model = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel'); + $model->delete_values($requestedId); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + endif; // ($requestMethod === 'post') + } + + public function add() { // JJO @@ -79,6 +105,8 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController $postData = $this->request->getPost(); + $cliente_id = $postData['cliente_id'] ?? -1; + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO @@ -108,16 +136,25 @@ class Clienteplantillaprecios extends \App\Controllers\GoBaseResourceController $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.'; - if ($thenRedirect) : - if (!empty($this->indexRoute)) : - //return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); - return redirect()->to(site_url('/clientes/clientesplantillaprecios/edit/' . $id))->with('message', $message); + if($cliente_id != -1){ + $modelLineas = model('App\Models\Clientes\ClientePlantillaPreciosLineasModel'); + $modelLineas->copy_from_cliente($cliente_id, $id); + $modelClientePrecios = model('App\Models\Clientes\ClientePreciosModel'); + $modelClientePrecios->set_plantilla_id($cliente_id, $id); + return ; + } + else{ + if ($thenRedirect) : + if (!empty($this->indexRoute)) : + //return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + return redirect()->to(site_url('/clientes/clienteplantillaprecios/edit/' . $id))->with('message', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; else: - return $this->redirect2listView('sweet-success', $message); + $this->session->setFlashData('sweet-success', $message); endif; - else: - $this->session->setFlashData('sweet-success', $message); - endif; + } endif; // $noException && $successfulResult diff --git a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php index 6f32762b..3eae3b23 100755 --- a/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php +++ b/ci4/app/Controllers/Clientes/Clienteplantillaprecioslineas.php @@ -47,6 +47,39 @@ class Clienteplantillaprecioslineas extends \App\Controllers\GoBaseResourceContr } + public function update($requestedId = null){ + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + if ($requestedId == null) : + return; + endif; + + $postData = $this->request->getJSON(); + + $plantilla_id = $postData->plantilla_id ?? -1; + + // Se ha actualizado un registro por lo que no es una plantilla + if($plantilla_id == -1){ + $this->model->clean_plantilla_id($requestedId); + } + else{ + $this->model->copy_from_plantilla($requestedId, $plantilla_id); + } + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + $csrfTokenName => $newTokenHash + ]; + + return $this->respond($data); + + endif; // ($requestMethod === 'post') + + } public function datatable() diff --git a/ci4/app/Controllers/Clientes/Clienteprecios.php b/ci4/app/Controllers/Clientes/Clienteprecios.php index ad096cb2..a148c170 100755 --- a/ci4/app/Controllers/Clientes/Clienteprecios.php +++ b/ci4/app/Controllers/Clientes/Clienteprecios.php @@ -45,7 +45,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController parent::initController($request, $response, $logger); } - public function update($requestedId = null) { $requestMethod = $this->request->getMethod(); @@ -80,10 +79,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController } - - - - public function datatable() { if ($this->request->isAJAX()) { @@ -136,6 +131,7 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController $response = Editor::inst( $db, 'cliente_precios' ) ->fields( Field::inst( 'plantilla_id' ), + Field::inst( 'cliente_id' ), Field::inst( 'tipo' ), Field::inst( 'tipo_maquina' ), Field::inst( 'tipo_impresion' ), @@ -215,9 +211,6 @@ class ClientePrecios extends \App\Controllers\GoBaseResourceController ->field('updated_at') ->setValue($datetime->format('Y-m-d H:i:s')); }) - ->on('postCreate', function ($editor,$id, $values, $row ) { - $this->model->clean_plantilla_id($values['cliente_id']); - }) ->debug(true) ->process($_POST) ->data(); diff --git a/ci4/app/Language/en/ClientePrecios.php b/ci4/app/Language/en/ClientePrecios.php index c48561eb..2eccdb44 100755 --- a/ci4/app/Language/en/ClientePrecios.php +++ b/ci4/app/Language/en/ClientePrecios.php @@ -10,6 +10,9 @@ return [ 'plantilla_id' => 'Template ID', 'plantilla' => 'Prices template', 'convertir2plantilla' => 'Convert to template', + 'convertir2plantillaText' => 'You have selected to convert the customer\'s current pricing table as a template.', + 'convertir2plantillaText2' => 'Next, type the name for the template and hit Save', + 'nombrePlantilla' => 'Name for the template', 'tipo' => 'Type', 'tipo_maquina' => 'Machine type', 'tipo_impresion' => 'Print type', @@ -37,10 +40,11 @@ return [ 'required' => 'Field required', 'decimal' => 'Decimal number', ], + 'errors' => [ 'error_tiempo_range' => 'The field Min Time must be lower than the field Max Time', 'error_tiempo_overlap' => 'The range [Min Time, Max Time] is overlapped with another one for the selected type.', - ] + 'error_nombre_template' => 'The template name is required' + ], - } ]; \ No newline at end of file diff --git a/ci4/app/Language/es/ClientePrecios.php b/ci4/app/Language/es/ClientePrecios.php index 4641a22f..b54205e1 100755 --- a/ci4/app/Language/es/ClientePrecios.php +++ b/ci4/app/Language/es/ClientePrecios.php @@ -10,6 +10,9 @@ return [ 'plantilla_id' => 'Plantilla ID', 'plantilla' => 'Plantilla de precios', 'convertir2plantilla' => 'Convertir a plantilla', + 'convertir2plantillaText' => 'Ha seleccionado convertir la tabla de precios actual del cliente como una plantilla.', + 'convertir2plantillaText2' => 'A continuación, escriba el nombre para la plantilla y pulse Guardar', + 'nombrePlantilla' => 'Nombre para la plantilla', 'tipo' => 'Tipo', 'tipo_maquina' => 'Tipo de máquina', 'tipo_impresion' => 'Tipo de impresión', @@ -39,6 +42,7 @@ return [ 'errors' => [ 'error_tiempo_range' => 'El campo Tiempo Mín debe ser menor que el campo Tiempo Máx', 'error_tiempo_overlap' => 'El rango [Tiempo Min, Tiempo Máx] se solapa con otro con los mismos parámetros.', + 'error_nombre_template' => 'El nombre de la plantilla es obligatorio' ] ]; \ No newline at end of file diff --git a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php index 5f2a7dbe..3b663fda 100755 --- a/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php +++ b/ci4/app/Models/Clientes/ClientePlantillaPreciosLineasModel.php @@ -111,6 +111,15 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel ]; + + function delete_values($plantilla_id = 0){ + $this->db + ->table($this->table . " t1") + ->where('t1.plantilla_id', $plantilla_id) + ->set('is_deleted', 1) + ->update(); + } + /** * Get resource data. * @@ -171,4 +180,32 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel return ""; } + + function copy_from_cliente($cliente_id = 0, $plantilla_id = 0){ + + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $date_value = $datetime->format('Y-m-d H:i:s'); + + + // Se cargan los valores en la plantilla + $clientePreciosModel = model('App\Models\Clientes\ClientePreciosModel'); + $values = $clientePreciosModel->getResource($cliente_id)->get()->getResultObject(); + foreach ($values as $value) { + $this->db + ->table($this->table . " t1") + ->set('plantilla_id', $plantilla_id) + ->set('tipo', $value->tipo) + ->set('tipo_maquina', $value->tipo_maquina) + ->set('tipo_impresion', $value->tipo_impresion) + ->set('tiempo_min', $value->tiempo_min) + ->set('tiempo_max', $value->tiempo_max) + ->set('margen', $value->margen) + ->set('user_updated_id', $session->id_user) + ->set('updated_at', $date_value) + ->insert(); + } + + } + } diff --git a/ci4/app/Models/Clientes/ClientePreciosModel.php b/ci4/app/Models/Clientes/ClientePreciosModel.php index 8e2b9f44..ee83c460 100644 --- a/ci4/app/Models/Clientes/ClientePreciosModel.php +++ b/ci4/app/Models/Clientes/ClientePreciosModel.php @@ -119,12 +119,21 @@ class ClientePreciosModel extends \App\Models\GoBaseModel ->update(); } + function set_plantilla_id($cliente_id = 0, $plantilla_id = null){ + $this->db + ->table($this->table . " t1") + ->where('cliente_id', $cliente_id) + ->set('plantilla_id', $plantilla_id) + ->update(); + } + function delete_values($cliente_id = 0){ $this->db ->table($this->table . " t1") ->where('cliente_id', $cliente_id) - ->delete(); + ->set('is_deleted', 1) + ->update(); } function copy_from_plantilla($cliente_id = 0, $plantilla_id = 0){ diff --git a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php index ec6ab53f..eedcb9d1 100755 --- a/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -567,7 +567,7 @@