From 9a781eb6d66d6b6c2e617fbb48139c30fe79dd1c Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Wed, 30 Aug 2023 13:12:38 +0200 Subject: [PATCH] haciendo formulario de editar tarifa envio --- ci4/app/Config/Routes.php | 13 +- ci4/app/Controllers/Tarifas/Tarifasenvios.php | 34 ++- .../Tarifas/Tarifasenvioszonas.php | 88 ++++++ .../Tarifas/TarifaEnvioZonaEntity.php | 4 +- ci4/app/Language/en/TarifasEnvios.php | 30 ++ ci4/app/Language/en/TarifasEnviosPrecios.php | 62 ++++ ci4/app/Language/en/TarifasEnviosZonas.php | 45 +++ ci4/app/Language/es/TarifasEnvios.php | 30 ++ ci4/app/Language/es/TarifasEnviosPrecios.php | 62 ++++ ci4/app/Language/es/TarifasEnviosZonas.php | 45 +++ ci4/app/Models/Tarifas/TarifaEnvioModel.php | 5 +- .../Models/Tarifas/TarifaEnvioPrecioModel.php | 3 + .../Models/Tarifas/TarifaEnvioZonaModel.php | 23 +- .../tarifas/envios/viewTarifaEnvioForm.php | 286 ++++++++++++++++++ .../tarifas/envios/viewTarifaEnvioList.php | 4 +- 15 files changed, 705 insertions(+), 29 deletions(-) create mode 100644 ci4/app/Language/en/TarifasEnvios.php create mode 100644 ci4/app/Language/en/TarifasEnviosPrecios.php create mode 100644 ci4/app/Language/en/TarifasEnviosZonas.php create mode 100644 ci4/app/Language/es/TarifasEnvios.php create mode 100644 ci4/app/Language/es/TarifasEnviosPrecios.php create mode 100644 ci4/app/Language/es/TarifasEnviosZonas.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 927cd617..3c958310 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -424,16 +424,9 @@ $routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tari $routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { -/* $routes->get('', 'Tarifasenvioszonas::index', ['as' => 'tarifaEnvioZonaList']); - $routes->get('add', 'Tarifasenvioszonas::add', ['as' => 'newTarifaEnvioZona']); - $routes->post('add', 'Tarifasenvioszonas::add', ['as' => 'createTarifaEnvioZona']); - $routes->post('create', 'Tarifasenvioszonas::create', ['as' => 'ajaxCreateTarifaEnvioZona']); - $routes->put('(:num)/update', 'Tarifasenvioszonas::update/$1', ['as' => 'ajaxUpdateTarifaEnvioZona']); - $routes->post('(:num)/edit', 'Tarifasenvioszonas::edit/$1', ['as' => 'updateTarifaEnvioZona']); - $routes->post('datatable', 'Tarifasenvioszonas::datatable', ['as' => 'dataTableOfTarifasEnviosZonas']); - $routes->post('allmenuitems', 'Tarifasenvioszonas::allItemsSelect', ['as' => 'select2ItemsOfTarifasEnviosZonas']); - $routes->post('menuitems', 'Tarifasenvioszonas::menuItems', ['as' => 'menuItemsOfTarifasEnviosZonas']); -*/}); + $routes->post('datatable', 'Tarifasenvioszonas::datatable', ['as' => 'dataTableOfTarifasEnvioZonas']); + $routes->post('datatable_editor', 'Tarifasenvioszonas::datatable_editor', ['as' => 'editorOfTarifasEnvioZonas']); +}); $routes->resource('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvioszonas', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Tarifas/Tarifasenvios.php b/ci4/app/Controllers/Tarifas/Tarifasenvios.php index 200f35a9..13dda667 100644 --- a/ci4/app/Controllers/Tarifas/Tarifasenvios.php +++ b/ci4/app/Controllers/Tarifas/Tarifasenvios.php @@ -32,6 +32,20 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { $this->viewData['pageTitle'] = lang('TarifasEnvios.moduleTitle'); $this->viewData['usingSweetAlert'] = true; + + // Se indica que este controlador trabaja con soft_delete + $this->soft_delete = true; + // Se indica el flag para los ficheros borrados + $this->delete_flag = 1; + + $this->viewData = ['usingServerSideDataTable' => true]; // JJO + + // Breadcrumbs + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_tarifasenvios"), 'route' => site_url('tarifas/tarifasenvios'), 'active' => true] + ]; + parent::initController($request, $response, $logger); } @@ -54,7 +68,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { public function add() { - + // JJO + $session = session(); $requestMethod = $this->request->getMethod(); @@ -66,6 +81,10 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + // JJO + if (isset($this->model->user_updated_id)) { + $sanitizedData['user_created_id'] = $session->id_user; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : @@ -95,7 +114,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { if ($thenRedirect) : if (!empty($this->indexRoute)) : - return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); + return redirect()->to(site_url('tarifas/tarifasenvios/edit/' . $id))->with('sweet-success', $message); + //return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); else: return $this->redirect2listView('sweet-success', $message); endif; @@ -119,6 +139,9 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { } // end function add() public function edit($requestedId = null) { + + // JJO + $session = session(); if ($requestedId == null) : return $this->redirect2listView(); @@ -139,9 +162,12 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController { $postData = $this->request->getPost(); - $sanitizedData = $this->sanitized($postData, $nullIfEmpty); - + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + // JJO + if (isset($this->model->user_updated_id)) { + $sanitizedData['user_updated_id'] = $session->id_user; + } $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : diff --git a/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php b/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php index 4e7b188d..2dd85204 100644 --- a/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php +++ b/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php @@ -11,6 +11,10 @@ use App\Models\Tarifas\TarifaEnvioModel; use App\Models\Tarifas\TarifaEnvioZonaModel; +use + DataTables\Editor, + DataTables\Editor\Field; + class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController { protected $modelName = TarifaEnvioZonaModel::class; @@ -196,6 +200,90 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController { } // end function edit(...) + public function datatable_editor() + { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst($db, 'tarifas_envios_zonas') + ->fields( + Field::inst('cp_inicial') + ->validator('Validate::required', array( + 'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required')) + ) + ->validator('Validate::maxLen(10)', array( + 'message' => lang('TarifasEnviosZonas.validation.cp_inicial.max_length')) + ), + Field::inst('cp_final') + ->validator('Validate::required', array( + 'message' => lang('TarifasEnviosZonas.validation.cp_final.required')) + ) + ->validator('Validate::maxLen(10)', array( + 'message' => lang('TarifasEnviosZonas.validation.cp_final.max_length')) + ), + Field::inst('importe_fijo') + ->validator('Validate::required', array( + 'message' => lang('TarifasEnviosZonas.validation.importe_fijo.required')) + ) + ->validator('Validate::numeric', array( + 'message' => lang('TarifasEnviosZonas.validation.importe_fijo.integer')) + ), + Field::inst('tarifa_envio_id'), + Field::inst('user_created_id'), + Field::inst('created_at'), + Field::inst('user_updated_id'), + Field::inst('updated_at'), + Field::inst('is_deleted'), + Field::inst('deleted_at'), + + ) + ->validator(function ($editor, $action, $data) { + 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) { + /*Los CP son string... consultar si checkear*/ + } + } + } + }) + ->on('preCreate', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_created_id') + ->setValue($session->id_user); + $editor + ->field('created_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->on('preEdit', function ($editor, &$values) { + $session = session(); + $datetime = (new \CodeIgniter\I18n\Time("now")); + $editor + ->field('user_updated_id') + ->setValue($session->id_user); + $editor + ->field('updated_at') + ->setValue($datetime->format('Y-m-d H:i:s')); + }) + ->debug(true) + ->process($_POST) + ->data(); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } public function datatable() { if ($this->request->isAJAX()) { diff --git a/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php b/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php index 77a3da96..85907228 100644 --- a/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php @@ -10,7 +10,7 @@ class TarifaEnvioZonaEntity extends \CodeIgniter\Entity\Entity "tarifa_envio_id" => null, "cp_inicial" => null, "cp_final" => null, - "inporte_fijo" => 0, + "importe_fijo" => 0, "user_created_id" => 0, "user_updated_id" => 0, "is_deleted" => 0, @@ -19,7 +19,7 @@ class TarifaEnvioZonaEntity extends \CodeIgniter\Entity\Entity ]; protected $casts = [ "tarifa_envio_id" => "int", - "inporte_fijo" => "int", + "importe_fijo" => "int", "user_created_id" => "int", "user_updated_id" => "int", "is_deleted" => "int", diff --git a/ci4/app/Language/en/TarifasEnvios.php b/ci4/app/Language/en/TarifasEnvios.php new file mode 100644 index 00000000..55044083 --- /dev/null +++ b/ci4/app/Language/en/TarifasEnvios.php @@ -0,0 +1,30 @@ + 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Shipping Rates', + 'nombre' => 'Name', + 'paisId' => 'Country', + 'tarifaEnvio' => 'Shipping Rate', + 'tarifaEnvioList' => 'Shipping Rate List', + 'tarifasenvios' => 'Shipping Rates', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'nombre' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + 'required' => 'The {field} field is required.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/en/TarifasEnviosPrecios.php b/ci4/app/Language/en/TarifasEnviosPrecios.php new file mode 100644 index 00000000..8e05f238 --- /dev/null +++ b/ci4/app/Language/en/TarifasEnviosPrecios.php @@ -0,0 +1,62 @@ + 'Home delivery', + 'cajas' => 'Boxes', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Weights and Costs', + 'palets' => 'Pallets', + 'pesoMax' => 'Max Weight', + 'pesoMin' => 'Min Weight', + 'precio' => 'Price', + 'precioAdicional' => 'Additional Price', + 'proveedorId' => 'Provider', + 'tarifaEnvioId' => 'Shipping Rate', + 'tarifaEnvioPrecio' => 'Weight and Cost', + 'tarifaEnvioPrecioList' => 'Weights and Costs List', + 'tarifasenviosprecios' => 'Weights and Costs', + 'tipoEnvio' => 'Shipping type', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'peso_max' => [ + 'decimal' => 'The field must contain a decimal number.', + 'required' => 'The field is required.', + + ], + + 'peso_min' => [ + 'decimal' => 'The field must contain a decimal number.', + 'required' => 'The field is required.', + + ], + + 'precio' => [ + 'decimal' => 'The field must contain a decimal number.', + 'required' => 'The field is required.', + + ], + + 'precio_adicional' => [ + 'decimal' => 'The field must contain a decimal number.', + 'required' => 'The field is required.', + + ], + + 'tipo_envio' => [ + 'in_list' => 'The field must be one of the are included in the list.', + 'required' => 'The field is required.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/en/TarifasEnviosZonas.php b/ci4/app/Language/en/TarifasEnviosZonas.php new file mode 100644 index 00000000..137ae7cd --- /dev/null +++ b/ci4/app/Language/en/TarifasEnviosZonas.php @@ -0,0 +1,45 @@ + 'Final Postcode', + 'cpInicial' => 'Initial Postcode', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'importeFijo' => 'Fixed cost', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Zones', + 'tarifaEnvioId' => 'Shipping Rate', + 'tarifaEnvioZona' => 'Zone and cost', + 'tarifaEnvioZonaList' => 'Zones List', + 'tarifasEnviosZonas' => 'Zones Zonas', + 'tarifasenvioszonas' => 'Zones Zonas', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'cp_final' => [ + 'max_length' => 'The field cannot exceed 10 characters in length.', + 'required' => 'The field is required.', + + ], + + 'cp_inicial' => [ + 'max_length' => 'The field cannot exceed 10 characters in length.', + 'required' => 'The field is required.', + + ], + + 'importe_fijo' => [ + 'integer' => 'The field must contain an integer.', + 'required' => 'The field is required.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/TarifasEnvios.php b/ci4/app/Language/es/TarifasEnvios.php new file mode 100644 index 00000000..5591a894 --- /dev/null +++ b/ci4/app/Language/es/TarifasEnvios.php @@ -0,0 +1,30 @@ + 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Tarifas Envíos', + 'nombre' => 'Nombre', + 'paisId' => 'Pais', + 'tarifaEnvio' => 'Tarifa Envío', + 'tarifaEnvioList' => 'Lista Tarifas Envío', + 'tarifasenvios' => 'Tarifa Envío', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'nombre' => [ + 'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/TarifasEnviosPrecios.php b/ci4/app/Language/es/TarifasEnviosPrecios.php new file mode 100644 index 00000000..278dd1ab --- /dev/null +++ b/ci4/app/Language/es/TarifasEnviosPrecios.php @@ -0,0 +1,62 @@ + 'A domicilio', + 'cajas' => 'Cajas', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Pesos y Precios', + 'palets' => 'Palets', + 'pesoMax' => 'Peso Max', + 'pesoMin' => 'Peso Min', + 'precio' => 'Precio', + 'precioAdicional' => 'Precio Adicional', + 'proveedorId' => 'Proveedor', + 'tarifaEnvioId' => 'Tarifa Envío', + 'tarifaEnvioPrecio' => 'Peso y Precio', + 'tarifaEnvioPrecioList' => 'Lista Pesos y Precios', + 'tarifasenviosprecios' => 'Pesos y Precios', + 'tipoEnvio' => 'Tipo Envío', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'peso_max' => [ + 'decimal' => 'El campo debe contener un número decimal.', + 'required' => 'El campo es obligatorio.', + + ], + + 'peso_min' => [ + 'decimal' => 'El campo debe contener un número decimal.', + 'required' => 'El campo es obligatorio.', + + ], + + 'precio' => [ + 'decimal' => 'El campo debe contener un número decimal.', + 'required' => 'El campo es obligatorio.', + + ], + + 'precio_adicional' => [ + 'decimal' => 'El campo debe contener un número decimal.', + 'required' => 'El campo es obligatorio.', + + ], + + 'tipo_envio' => [ + 'in_list' => 'El campo debe ser uno de la lista.', + 'required' => 'El campo es obligatorio.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/TarifasEnviosZonas.php b/ci4/app/Language/es/TarifasEnviosZonas.php new file mode 100644 index 00000000..9421c1df --- /dev/null +++ b/ci4/app/Language/es/TarifasEnviosZonas.php @@ -0,0 +1,45 @@ + 'CP Final', + 'cpInicial' => 'CP Inicial', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'importeFijo' => 'Importe Fijo', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Zonas', + 'tarifaEnvioId' => 'Tarifa Envío', + 'tarifaEnvioZona' => 'Zona', + 'tarifaEnvioZonaList' => 'Lista de Zonas', + 'tarifasEnviosZonas' => 'Zonas', + 'tarifasenvioszonas' => 'Zonas', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'cp_final' => [ + 'max_length' => 'El campo no puede exceder 10 caracteres en longitud.', + 'required' => 'El campo es obligatorio.', + + ], + + 'cp_inicial' => [ + 'max_length' => 'El campo no puede exceder 10 caracteres en longitud.', + 'required' => 'El campo es obligatorio.', + + ], + + 'importe_fijo' => [ + 'integer' => 'El campo debe contener un número.', + 'required' => 'El campo es obligatorio.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Tarifas/TarifaEnvioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioModel.php index 3e38eb44..0aeb1bce 100644 --- a/ci4/app/Models/Tarifas/TarifaEnvioModel.php +++ b/ci4/app/Models/Tarifas/TarifaEnvioModel.php @@ -17,7 +17,7 @@ class TarifaEnvioModel extends \App\Models\GoBaseModel 1 => "t2.nombre", ]; - protected $allowedFields = ["pais_id", "nombre"]; + protected $allowedFields = ["pais_id", "nombre","deleted_at","is_deleted"]; protected $returnType = "App\Entities\Tarifas\TarifaEnvioEntity"; protected $useTimestamps = true; @@ -76,6 +76,9 @@ class TarifaEnvioModel extends \App\Models\GoBaseModel $builder = $this->db->table($this->table . " t1")->select("t1.id as id, t1.nombre AS nombre, t2.nombre AS pais_id"); $builder->join("lg_paises t2", "t1.pais_id = t2.id", "left"); + //JJO + $builder->where("t1.is_deleted", 0); + return empty($search) ? $builder : $builder diff --git a/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php index 01d51533..3b842fa8 100644 --- a/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php +++ b/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php @@ -128,6 +128,9 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel $builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left"); $builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left"); + //JJO + $builder->where("t1.is_deleted", 0); + return empty($search) ? $builder : $builder diff --git a/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php index 053cc410..a872ff99 100644 --- a/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php +++ b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php @@ -16,11 +16,11 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel 1 => "t1.tarifa_envio_id", 2 => "t1.cp_inicial", 3 => "t1.cp_final", - 4 => "t1.inporte_fijo", + 4 => "t1.importe_fijo", 5 => "t2.id", ]; - protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "inporte_fijo"]; + protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo"]; protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity"; protected $useTimestamps = true; @@ -41,8 +41,8 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel "label" => "TarifasEnviosZonas.cpInicial", "rules" => "trim|required|max_length[10]", ], - "inporte_fijo" => [ - "label" => "TarifasEnviosZonas.inporteFijo", + "importe_fijo" => [ + "label" => "TarifasEnviosZonas.importeFijo", "rules" => "required|integer", ], ]; @@ -56,9 +56,9 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel "max_length" => "TarifasEnviosZonas.validation.cp_inicial.max_length", "required" => "TarifasEnviosZonas.validation.cp_inicial.required", ], - "inporte_fijo" => [ - "integer" => "TarifasEnviosZonas.validation.inporte_fijo.integer", - "required" => "TarifasEnviosZonas.validation.inporte_fijo.required", + "importe_fijo" => [ + "integer" => "TarifasEnviosZonas.validation.importe_fijo.integer", + "required" => "TarifasEnviosZonas.validation.importe_fijo.required", ], ]; @@ -95,22 +95,25 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel $builder = $this->db ->table($this->table . " t1") ->select( - "t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.inporte_fijo AS inporte_fijo, t2.id AS tarifa_envio" + "t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.importe_fijo AS importe_fijo, t2.id AS tarifa_envio" ); $builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left"); + //JJO + $builder->where("t1.is_deleted", 0); + return empty($search) ? $builder : $builder ->groupStart() ->like("t1.cp_inicial", $search) ->orLike("t1.cp_final", $search) - ->orLike("t1.inporte_fijo", $search) + ->orLike("t1.importe_fijo", $search) ->orLike("t2.id", $search) ->orLike("t1.tarifa_envio_id", $search) ->orLike("t1.cp_inicial", $search) ->orLike("t1.cp_final", $search) - ->orLike("t1.inporte_fijo", $search) + ->orLike("t1.importe_fijo", $search) ->orLike("t2.id", $search) ->groupEnd(); } diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php index 33c32c8d..96ed63a8 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php @@ -1,3 +1,4 @@ +include("themes/_commonPartialsBs/datatables") ?> include("themes/_commonPartialsBs/select2bs5") ?> include("themes/_commonPartialsBs/sweetalert") ?> extend('themes/backend/vuexy/main/defaultlayout') ?> @@ -22,5 +23,290 @@ + + +
+
+

+ + +

+ +
+
+ + + + + + + + + + + + +
+
+
+
+
+ + + endSection() ?> + + + + + + + + + +section("additionalInlineJs") ?> + const url = window.location.href; + const url_parts = url.split('/'); + var id = -1; + if(url_parts[url_parts.length-2] == 'edit'){ + id = url_parts[url_parts.length-1]; + } + else{ + id = -1; + } + + + const actionBtns = function(data) { + return ` + + + + `; + }; + + // Delete row + $(document).on('click', '.btn-delete', function(e) { + $(".btn-remove").attr('data-id', $(this).attr('data-id')); + if($(this).closest('table').attr('id').includes('zonas')){ + $(".btn-remove").attr('table', "zonas"); + } + else if($(this).closest('table').attr('id').includes('precios')){ + $(".btn-remove").attr('table', "precios"); + } + else{ + $(".btn-remove").attr('table', ); + } + }); + + var selected_zona_id = -1; + + + $(document).on('click', '.btn-remove', function(e) { + const dataId = $(this).attr('data-id'); + const row = $(this).closest('tr'); + if ($.isNumeric(dataId)) { + + if($(this).attr('table').includes('tiradas')){ + remove_tiradas(dataId, row); + } + else if ($(this).attr('table').includes('lineas')){ + remove_lineas(dataId, row); + } + } + }); + +endSection() ?> + + + + + +section("additionalInlineJs") ?> + const lastColNr = $('#tableOfZonas').find("tr:first th").length - 1; + + var editor = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfZonas", + idSrc: 'id', + fields: [ { + name: "cp_inicial" + }, { + name: "cp_final" + }, { + name: "importe_fijo" + }, { + "name": "tarifa_envio_id", + "type": "hidden" + },{ + "name": "deleted_at", + "type": "hidden" + },{ + "name": "is_deleted", + "type": "hidden" + }, + ] + } ); + + + editor.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['tarifa_envio_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['tarifa_envio_id'] = id; + } + } + }); + + + editor.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + + editor.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable.clearPipeline(); + theTable.draw(); + }); + + + var theTable = $('#tableOfZonas').DataTable( { + serverSide: true, + processing: true, + autoWidth: true, + responsive: true, + lengthMenu: [ 5, 10, 25], + order: [[ 0, "asc" ], [ 1, "asc" ]], + pageLength: 10, + lengthChange: true, + searching: false, + paging: true, + select: true, + info: false, + dom: '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>', + ajax : $.fn.dataTable.pipeline( { + url: '', + data: function ( d ) { + d.tarifa_envio_id = id; + }, + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columns: [ + { 'data': 'cp_inicial' }, + { 'data': 'cp_final' }, + { 'data': 'importe_fijo' }, + { + data: actionBtns, + className: 'row-edit dt-center' + } + ], + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + }, + {"orderData": [ 0, 1 ], "targets": 0 }, + + ], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" + }, + buttons: [ { + className: 'btn btn-primary float-end me-sm-3 me-1', + extend: "createInline", + editor: editor, + formOptions: { + submitTrigger: -1, + submitHtml: '' + + } + } ] + } ); + + + // Activate an inline edit on click of a table cell + $('#tableOfZonas').on( 'click', 'tbody span.edit', function (e) { + editor.inline( + theTable.cells(this.parentNode.parentNode, '*').nodes(), + { + cancelHtml: '', + cancelTrigger: 'span.cancel', + submitHtml: '', + submitTrigger: 'span.edit', + submit: 'allIfChanged' + } + ); + } ); + + // Delete row + function remove_lineas(dataId, row){ + + $.ajax({ + url: `/tarifas/tarifasenvioszonas/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + $('#confirm2delete').modal('toggle'); + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + popSuccessAlert(data.msg ?? jqXHR.statusText); + }).fail((jqXHR, textStatus, errorThrown) => { + popErrorAlert(jqXHR.responseJSON.messages.error) + }); + } + + + theTable.on( 'select', function ( e, dt, type, indexes ) { + if ( type === 'row' ) { + selected_zona_id = parseInt(theTable.rows( indexes ).data().pluck( 'id' )[0]); + theTable2.clearPipeline(); + theTable2.draw(); + } + } ); + + theTable.on( 'deselect', function ( e, dt, type, indexes ) { + if ( theTable.rows( '.selected' ).count() == 0 ) { + selected_zona_id = -1; + theTable2.clearPipeline(); + theTable2.draw(); + } + } ); +endSection() ?> + + +section('css') ?> + + + + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + +endSection() ?> + + + + diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php index 0bf51bfe..4d56ae20 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php @@ -56,7 +56,7 @@ responsive: true, scrollX: true, lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], - pageLength: 10, + pageLength: 25, lengthChange: true, "dom": 'lfBrtip', "buttons": [ @@ -108,7 +108,7 @@ const row = $(this).closest('tr'); if ($.isNumeric(dataId)) { $.ajax({ - url: `/tarifas/tarifasenvio/delete/${dataId}`, + url: `/tarifas/tarifasenvios/delete/${dataId}`, method: 'GET', }).done((data, textStatus, jqXHR) => { $('#confirm2delete').modal('toggle');