diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php
index 5b811dcb..01b4b1e4 100644
--- a/ci4/app/Config/Routes.php
+++ b/ci4/app/Config/Routes.php
@@ -395,6 +395,34 @@ $routes->group('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\T
$routes->resource('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernaciontiradas', 'except' => 'show,new,create,update']);
+$routes->group('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
+ $routes->get('', 'Tarifasenvios::index', ['as' => 'tarifaEnvioList']);
+ $routes->get('add', 'Tarifasenvios::add', ['as' => 'newTarifaEnvio']);
+ $routes->post('add', 'Tarifasenvios::add', ['as' => 'createTarifaEnvio']);
+ $routes->post('create', 'Tarifasenvios::create', ['as' => 'ajaxCreateTarifaEnvio']);
+ $routes->put('(:num)/update', 'Tarifasenvios::update/$1', ['as' => 'ajaxUpdateTarifaEnvio']);
+ $routes->post('edit/(:num)', 'Tarifasenvios::edit/$1', ['as' => 'updateTarifaEnvio']);
+ $routes->post('datatable', 'Tarifasenvios::datatable', ['as' => 'dataTableOfTarifaEnvio']);
+ $routes->post('allmenuitems', 'Tarifasenvios::allItemsSelect', ['as' => 'select2ItemsOfTarifaEnvio']);
+ $routes->post('menuitems', 'Tarifasenvios::menuItems', ['as' => 'menuItemsOfTarifaEnvio']);
+});
+$routes->resource('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvios', 'except' => 'show,new,create,update']);
+
+
+$routes->group('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
+ $routes->post('datatable', 'Tarifasenviosprecios::datatable', ['as' => 'dataTableOfTarifasEnvioPrecios']);
+ $routes->post('datatable_editor', 'Tarifasenviosprecios::datatable_editor', ['as' => 'editorOfTarifasEnvioPrecios']);
+});
+$routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenviosprecios', 'except' => 'show,new,create,update']);
+
+
+$routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
+ $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']);
+
+
$routes->group('proveedores', ['namespace' => 'App\Controllers\Compras'], function ($routes) {
$routes->get('', 'Proveedores::index', ['as' => 'proveedorList']);
$routes->get('add', 'Proveedores::add', ['as' => 'newProveedor']);
diff --git a/ci4/app/Controllers/Compras/Proveedores.php b/ci4/app/Controllers/Compras/Proveedores.php
index 6c524d49..1229cdf7 100644
--- a/ci4/app/Controllers/Compras/Proveedores.php
+++ b/ci4/app/Controllers/Compras/Proveedores.php
@@ -1,5 +1,6 @@
= '8.1');
$postData = $this->request->getPost();
+
+ // Rellenar el campo "propiedades" si es necesario
+ $postData = $this->getPropiedadesFromPost($postData);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
@@ -107,7 +111,8 @@ class Proveedores 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('/compras/proveedores/edit/' . $id))->with('message', $message);
+ //return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
@@ -139,6 +144,13 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
endif;
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
$proveedorEntity = $this->model->find($id);
+
+ // Propiedades para proveedores tipo transporte
+ if(!is_null($proveedorEntity->propiedades))
+ {
+ $proveedorEntity = $this->getPropiedadesFromEntity($proveedorEntity);
+ }
+
if ($proveedorEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Proveedores.proveedor')), $id]);
@@ -153,10 +165,11 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
$postData = $this->request->getPost();
- $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
-
-
+ // Rellenar el campo "propiedades" si es necesario
+ $postData = $this->getPropiedadesFromPost($postData);
+ $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
+
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@@ -177,7 +190,7 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
$proveedorEntity->fill($sanitizedData);
- $thenRedirect = false;
+ $thenRedirect = true;
endif;
if ($noException && $successfulResult) :
$id = $proveedorEntity->id ?? $id;
@@ -188,7 +201,9 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
- return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ //return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ $this->session->setFlashData('sweet-success', $message);
+ return redirect()->to(site_url('/compras/proveedores/edit/' . $id))->with('message', $message);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
@@ -199,6 +214,7 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
+
$this->viewData['proveedorEntity'] = $proveedorEntity;
$this->viewData['proveedorTipoList'] = $this->getProveedorTipoListItems($proveedorEntity->tipo_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($proveedorEntity->provincia_id ?? null);
@@ -326,4 +342,43 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
return $data;
}
+
+ private function getPropiedadesFromEntity($entity){
+
+ $temp_data = $entity;
+ $config = json_decode($temp_data->propiedades);
+ if (in_array("palets",$config->config)){
+ $temp_data->palets=1;
+ }
+ if (in_array("cajas",$config->config)){
+ $temp_data->cajas=1;
+ }
+ return $temp_data;
+ }
+
+ private function getPropiedadesFromPost($postData){
+
+ if (array_key_exists("cajas",$postData) || array_key_exists("palets",$postData)){
+
+ $temp_data = $postData;
+ $prop = new stdClass();
+ $prop->config = [];
+ if (array_key_exists("cajas",$temp_data)){
+ array_push($prop->config, "cajas");
+ unset($temp_data["cajas"]);
+ }
+ if (array_key_exists("palets",$temp_data)){
+ array_push($prop->config, "palets");
+ unset($temp_data["palets"]);
+ }
+ $temp_data["propiedades"] = json_encode($prop);
+ return $temp_data;
+ }
+ else{
+ $temp_data = $postData;
+ $temp_data["propiedades"] = null;
+ return $temp_data;
+ }
+ }
+
}
diff --git a/ci4/app/Controllers/Tarifas/Tarifasenvios.php b/ci4/app/Controllers/Tarifas/Tarifasenvios.php
new file mode 100644
index 00000000..0eb098b9
--- /dev/null
+++ b/ci4/app/Controllers/Tarifas/Tarifasenvios.php
@@ -0,0 +1,322 @@
+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_tarifaenvio"), 'route' => site_url('tarifas/tarifasenvios'), 'active' => true]
+ ];
+
+ parent::initController($request, $response, $logger);
+ }
+
+
+ public function index() {
+
+ $viewData = [
+ 'currentModule' => static::$controllerSlug,
+ 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnvios.tarifaEnvio')]),
+ 'tarifaEnvioEntity' => new TarifaEnvioEntity(),
+ 'usingServerSideDataTable' => true,
+
+ ];
+
+ $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
+
+ return view(static::$viewPath.'viewTarifaEnvioList', $viewData);
+ }
+
+
+ public function add() {
+
+ // JJO
+ $session = session();
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $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) ) :
+
+
+ if ($this->canValidate()) :
+ try {
+ $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
+ } catch (\Exception $e) {
+ $noException = false;
+ $this->dealWithException($e);
+ }
+ else:
+ $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+ endif;
+
+ $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
+ endif;
+ if ($noException && $successfulResult) :
+
+ $id = $this->model->db->insertID();
+
+ $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.';
+ $message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ 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;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioEntity'] = isset($sanitizedData) ? new TarifaEnvioEntity($sanitizedData) : new TarifaEnvioEntity();
+ $this->viewData['paisList'] = $this->getPaisListItems();
+
+ $this->viewData['formAction'] = route_to('createTarifaEnvio');
+
+ $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.addNewSuffix');
+
+
+ return $this->displayForm(__METHOD__);
+ } // end function add()
+
+ public function edit($requestedId = null) {
+
+ // JJO
+ $session = session();
+
+ if ($requestedId == null) :
+ return $this->redirect2listView();
+ endif;
+ $id = filter_var($requestedId, FILTER_SANITIZE_URL);
+ $tarifaEnvioEntity = $this->model->find($id);
+
+ if ($tarifaEnvioEntity == false) :
+ $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio')), $id]);
+ return $this->redirect2listView('sweet-error', $message);
+ endif;
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $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) ) :
+
+
+
+ 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('TarifasEnvios.tarifaEnvio'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+
+ endif;
+
+ $tarifaEnvioEntity->fill($sanitizedData);
+
+ $thenRedirect = false;
+ endif;
+ if ($noException && $successfulResult) :
+ $id = $tarifaEnvioEntity->id ?? $id;
+ $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.';
+ //$message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ else:
+ return $this->redirect2listView('sweet-success', $message);
+ endif;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioEntity'] = $tarifaEnvioEntity;
+ $this->viewData['paisList'] = $this->getPaisListItems();
+
+ $this->viewData['formAction'] = route_to('updateTarifaEnvio', $id);
+
+ $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.edit3');
+
+ //JJO
+ $this->viewData['proveedores'] = $this->getProveedores();
+
+ return $this->displayForm(__METHOD__, $id);
+ } // end function edit(...)
+
+
+
+ public function datatable() {
+ if ($this->request->isAJAX()) {
+ $reqData = $this->request->getPost();
+ if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
+ $errstr = 'No data available in response to this specific request.';
+ $response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
+ return $response;
+ }
+ $start = $reqData['start'] ?? 0;
+ $length = $reqData['length'] ?? 5;
+ $search = $reqData['search']['value'];
+ $requestedOrder = $reqData['order']['0']['column'] ?? 0;
+ $order = TarifaEnvioModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
+ $dir = $reqData['order']['0']['dir'] ?? 'asc';
+
+ $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
+
+ return $this->respond(Collection::datatable(
+ $resourceData,
+ $this->model->getResource()->countAllResults(),
+ $this->model->getResource($search)->countAllResults()
+ ));
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function allItemsSelect() {
+ if ($this->request->isAJAX()) {
+ $onlyActiveOnes = true;
+ $reqVal = $this->request->getPost('val') ?? 'id';
+ $menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->nombre = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function menuItems() {
+ if ($this->request->isAJAX()) {
+ $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
+ $reqId = goSanitize($this->request->getPost('id'))[0];
+ $reqText = goSanitize($this->request->getPost('text'))[0];
+ $onlyActiveOnes = false;
+ $columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
+ $onlyActiveOnes = false;
+ $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->text = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ protected function getPaisListItems() {
+ $paisModel = model('App\Models\Configuracion\PaisModel');
+ $onlyActiveOnes = true;
+ $data = $paisModel->getAllForMenu('id, nombre','nombre', $onlyActiveOnes );
+
+ return $data;
+ }
+
+ private function getProveedores(){
+ $provTipoModel = new ProveedorTipoModel();
+ $provModel = new ProveedorModel();
+
+ $tipoId = $provTipoModel->getTipoId("Transporte");
+ return $provModel->getProvList($tipoId);
+ }
+
+}
diff --git a/ci4/app/Controllers/Tarifas/Tarifasenviosprecios.php b/ci4/app/Controllers/Tarifas/Tarifasenviosprecios.php
new file mode 100644
index 00000000..6284a4a4
--- /dev/null
+++ b/ci4/app/Controllers/Tarifas/Tarifasenviosprecios.php
@@ -0,0 +1,438 @@
+viewData['pageTitle'] = lang('TarifasEnviosPrecios.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;
+
+ parent::initController($request, $response, $logger);
+ }
+
+
+ public function index() {
+
+ $viewData = [
+ 'currentModule' => static::$controllerSlug,
+ 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnviosPrecios.tarifaEnvioPrecio')]),
+ 'tarifaEnvioPrecioEntity' => new TarifaEnvioPrecioEntity(),
+ 'usingServerSideDataTable' => true,
+
+ ];
+
+ $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
+
+ return view(static::$viewPath.'viewTarifaEnvioPrecioList', $viewData);
+ }
+
+
+ public function add() {
+
+
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
+
+
+ $noException = true;
+ if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
+
+
+ if ($this->canValidate()) :
+ try {
+ $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
+ } catch (\Exception $e) {
+ $noException = false;
+ $this->dealWithException($e);
+ }
+ else:
+ $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+ endif;
+
+ $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
+ endif;
+ if ($noException && $successfulResult) :
+
+ $id = $this->model->db->insertID();
+
+ $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]).'.';
+ $message .= anchor( "admin/tarifasenviosprecios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ else:
+ return $this->redirect2listView('sweet-success', $message);
+ endif;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioPrecioEntity'] = isset($sanitizedData) ? new TarifaEnvioPrecioEntity($sanitizedData) : new TarifaEnvioPrecioEntity();
+ $this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioPrecioEntity->tarifa_envio_id ?? null);
+ $this->viewData['proveedorList'] = $this->getProveedorListItems($tarifaEnvioPrecioEntity->proveedor_id ?? null);
+ $this->viewData['tipoEnvioList'] = $this->getTipoEnvioOptions();
+
+ $this->viewData['formAction'] = route_to('createTarifaEnvioPrecio');
+
+ $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnviosPrecios.moduleTitle').' '.lang('Basic.global.addNewSuffix');
+
+
+ return $this->displayForm(__METHOD__);
+ } // end function add()
+
+ public function edit($requestedId = null) {
+
+ if ($requestedId == null) :
+ return $this->redirect2listView();
+ endif;
+ $id = filter_var($requestedId, FILTER_SANITIZE_URL);
+ $tarifaEnvioPrecioEntity = $this->model->find($id);
+
+ if ($tarifaEnvioPrecioEntity == false) :
+ $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio')), $id]);
+ return $this->redirect2listView('sweet-error', $message);
+ endif;
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
+
+
+
+ $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('TarifasEnviosPrecios.tarifaEnvioPrecio'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+
+ endif;
+
+ $tarifaEnvioPrecioEntity->fill($sanitizedData);
+
+ $thenRedirect = true;
+ endif;
+ if ($noException && $successfulResult) :
+ $id = $tarifaEnvioPrecioEntity->id ?? $id;
+ $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]).'.';
+ $message .= anchor( "admin/tarifasenviosprecios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ else:
+ return $this->redirect2listView('sweet-success', $message);
+ endif;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioPrecioEntity'] = $tarifaEnvioPrecioEntity;
+ $this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioPrecioEntity->tarifa_envio_id ?? null);
+ $this->viewData['proveedorList'] = $this->getProveedorListItems($tarifaEnvioPrecioEntity->proveedor_id ?? null);
+ $this->viewData['tipoEnvioList'] = $this->getTipoEnvioOptions();
+
+ $this->viewData['formAction'] = route_to('updateTarifaEnvioPrecio', $id);
+
+ $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnviosPrecios.moduleTitle').' '.lang('Basic.global.edit3');
+
+
+ return $this->displayForm(__METHOD__, $id);
+ } // 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_precios')
+ ->fields(
+ Field::inst('tipo_envio')
+ ->validator('Validate::required', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.tipo_envio.required'))
+ ),
+ Field::inst('peso_min')
+ ->validator('Validate::required', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.peso_min.required'))
+ )
+ ->validator('Validate::numeric', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.peso_min.decimal'))
+ ),
+ Field::inst('peso_max')
+ ->validator('Validate::required', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.peso_max.required'))
+ )
+ ->validator('Validate::numeric', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.peso_max.decimal'))
+ ),
+ Field::inst('precio')
+ ->validator('Validate::required', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.precio.required'))
+ )
+ ->validator('Validate::numeric', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.precio.decimal'))
+ ),
+ Field::inst('precio_adicional')
+ ->validator('Validate::required', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.precio_adicional.required'))
+ )
+ ->validator('Validate::numeric', array(
+ 'message' => lang('TarifasEnviosPrecios.validation.precio_adicional.decimal'))
+ ),
+ Field::inst('zona_envio_id'),
+ Field::inst('proveedor_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) {
+ $process_data['peso_min'] = $data['data'][$pkey]['peso_min'];
+ $process_data['peso_max'] = $data['data'][$pkey]['peso_max'];
+ $process_data['proveedor_id'] = $data['data'][$pkey]['proveedor_id'];
+ $process_data['tipo_envio'] = $data['data'][$pkey]['tipo_envio'];
+ $response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['zona_envio_id']);
+ // No se pueden duplicar valores al crear o al editar
+ if (!empty($response)) {
+ return $response;
+ }
+ }
+ }
+ }
+ })
+ ->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()) {
+ $reqData = $this->request->getPost();
+ if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
+ $errstr = 'No data available in response to this specific request.';
+ $response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
+ return $response;
+ }
+ $start = $reqData['start'] ?? 0;
+ $length = $reqData['length'] ?? 5;
+ $search = $reqData['search']['value'];
+ $requestedOrder = $reqData['order']['0']['column'] ?? 1;
+ $order = TarifaEnvioPrecioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
+ $dir = $reqData['order']['0']['dir'] ?? 'asc';
+
+ $zona_envio_id = $reqData['zona_envio_id'] ?? -1;
+
+ $resourceData = $this->model->getResource($search, $zona_envio_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
+
+ return $this->respond(Collection::datatable(
+ $resourceData,
+ $this->model->getResource()->countAllResults(),
+ $this->model->getResource($search, $zona_envio_id)->countAllResults()
+ ));
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function allItemsSelect() {
+ if ($this->request->isAJAX()) {
+ $onlyActiveOnes = true;
+ $reqVal = $this->request->getPost('val') ?? 'id';
+ $menu = $this->model->getAllForMenu($reqVal.', tarifa_envio_id', 'tarifa_envio_id', $onlyActiveOnes, false);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->tarifa_envio_id = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function menuItems() {
+ if ($this->request->isAJAX()) {
+ $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
+ $reqId = goSanitize($this->request->getPost('id'))[0];
+ $reqText = goSanitize($this->request->getPost('text'))[0];
+ $onlyActiveOnes = false;
+ $columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_envio_id'];
+ $onlyActiveOnes = false;
+ $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->text = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ protected function getTarifaEnvioListItems($selId = null) {
+ $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))])];
+ if (!empty($selId)) :
+ $tarifaEnvioModel = model('App\Models\Tarifas\TarifaEnvioModel');
+
+ $selOption = $tarifaEnvioModel->where('id', $selId)->findColumn('id');
+ if (!empty($selOption)) :
+ $data[$selId] = $selOption[0];
+ endif;
+ endif;
+ return $data;
+ }
+
+
+ protected function getProveedorListItems($selId = null) {
+ $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('LgProveedores.proveedor'))])];
+ if (!empty($selId)) :
+ $proveedorModel = model('App\Models\compras\ProveedorModel');
+
+ $selOption = $proveedorModel->where('id', $selId)->findColumn('id');
+ if (!empty($selOption)) :
+ $data[$selId] = $selOption[0];
+ endif;
+ endif;
+ return $data;
+ }
+
+
+ protected function getTipoEnvioOptions() {
+ $tipoEnvioOptions = [
+ '' => lang('Basic.global.pleaseSelect'),
+ 'a domicilio' => 'a domicilio',
+ 'cajas' => 'cajas',
+ 'palets' => 'palets',
+ ];
+ return $tipoEnvioOptions;
+ }
+
+
+}
diff --git a/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php b/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
new file mode 100644
index 00000000..1c3271c2
--- /dev/null
+++ b/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
@@ -0,0 +1,425 @@
+viewData['pageTitle'] = lang('TarifasEnviosZonas.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;
+
+ parent::initController($request, $response, $logger);
+ }
+
+
+ public function index() {
+
+ $viewData = [
+ 'currentModule' => static::$controllerSlug,
+ 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnviosZonas.tarifaEnvioZona')]),
+ 'tarifaEnvioZonaEntity' => new TarifaEnvioZonaEntity(),
+ 'usingServerSideDataTable' => true,
+
+ ];
+
+ $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
+
+ return view(static::$viewPath.'viewTarifaEnvioZonaList', $viewData);
+ }
+
+
+ public function add() {
+
+
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
+
+
+ $noException = true;
+ if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
+
+
+ if ($this->canValidate()) :
+ try {
+ $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
+ } catch (\Exception $e) {
+ $noException = false;
+ $this->dealWithException($e);
+ }
+ else:
+ $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+ endif;
+
+ $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
+ endif;
+ if ($noException && $successfulResult) :
+
+ $id = $this->model->db->insertID();
+
+ $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]).'.';
+ $message .= anchor( "admin/tarifasenvioszonas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ else:
+ return $this->redirect2listView('sweet-success', $message);
+ endif;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioZonaEntity'] = isset($sanitizedData) ? new TarifaEnvioZonaEntity($sanitizedData) : new TarifaEnvioZonaEntity();
+ $this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioZonaEntity->tarifa_envio_id ?? null);
+
+ $this->viewData['formAction'] = route_to('createTarifaEnvioZona');
+
+ $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnviosZonas.moduleTitle').' '.lang('Basic.global.addNewSuffix');
+
+
+ return $this->displayForm(__METHOD__);
+ } // end function add()
+
+ public function edit($requestedId = null) {
+
+ if ($requestedId == null) :
+ return $this->redirect2listView();
+ endif;
+ $id = filter_var($requestedId, FILTER_SANITIZE_URL);
+ $tarifaEnvioZonaEntity = $this->model->find($id);
+
+ if ($tarifaEnvioZonaEntity == false) :
+ $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona')), $id]);
+ return $this->redirect2listView('sweet-error', $message);
+ endif;
+
+ $requestMethod = $this->request->getMethod();
+
+ if ($requestMethod === 'post') :
+
+ $nullIfEmpty = true; // !(phpversion() >= '8.1');
+
+ $postData = $this->request->getPost();
+
+ $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
+
+
+
+ $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('TarifasEnviosZonas.tarifaEnvioZona'))]);
+ $this->session->setFlashdata('formErrors', $this->model->errors());
+
+ endif;
+
+ $tarifaEnvioZonaEntity->fill($sanitizedData);
+
+ $thenRedirect = true;
+ endif;
+ if ($noException && $successfulResult) :
+ $id = $tarifaEnvioZonaEntity->id ?? $id;
+ $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]).'.';
+ $message .= anchor( "admin/tarifasenvioszonas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
+ $message = ucfirst(str_replace("'", "\'", $message));
+
+ if ($thenRedirect) :
+ if (!empty($this->indexRoute)) :
+ return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
+ else:
+ return $this->redirect2listView('sweet-success', $message);
+ endif;
+ else:
+ $this->session->setFlashData('sweet-success', $message);
+ endif;
+
+ endif; // $noException && $successfulResult
+ endif; // ($requestMethod === 'post')
+
+ $this->viewData['tarifaEnvioZonaEntity'] = $tarifaEnvioZonaEntity;
+ $this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioZonaEntity->tarifa_envio_id ?? null);
+
+ $this->viewData['formAction'] = route_to('updateTarifaEnvioZona', $id);
+
+ $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnviosZonas.moduleTitle').' '.lang('Basic.global.edit3');
+
+
+ return $this->displayForm(__METHOD__, $id);
+ } // end function edit(...)
+
+
+ public function delete($id = null)
+ {
+ if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
+ $objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
+ } else {
+ $objName = lang('Basic.global.record');
+ }
+
+ if (!$this->soft_delete){
+
+ if (!$this->model->delete($id)) {
+ return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
+ }
+ }
+ else{
+ $datetime = (new \CodeIgniter\I18n\Time("now"));
+
+ $precioModel = new TarifaEnvioPrecioModel();
+ $precioResult = $precioModel->removeAllPrecioLineas($id, $datetime, $this->delete_flag);
+
+ $rawResult = $this->model->where('id',$id)
+ ->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
+ 'is_deleted' => $this->delete_flag])
+ ->update();
+
+ if (!$rawResult && !$precioResult) {
+ return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
+ }
+
+ }
+
+ // $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
+ $message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
+ $response = $this->respondDeleted(['id' => $id, 'msg' => $message]);
+ return $response;
+ }
+
+ 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()) {
+ $reqData = $this->request->getPost();
+ if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
+ $errstr = 'No data available in response to this specific request.';
+ $response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
+ return $response;
+ }
+ $start = $reqData['start'] ?? 0;
+ $length = $reqData['length'] ?? 5;
+ $search = $reqData['search']['value'];
+ $requestedOrder = $reqData['order']['0']['column'] ?? 0;
+ $order = TarifaEnvioZonaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
+ $dir = $reqData['order']['0']['dir'] ?? 'asc';
+
+ $tarifa_envio_id = $reqData['tarifa_envio_id'] ?? -1;
+
+ $resourceData = $this->model->getResource($search, $tarifa_envio_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
+
+ return $this->respond(Collection::datatable(
+ $resourceData,
+ $this->model->getResource()->countAllResults(),
+ $this->model->getResource($search, $tarifa_envio_id)->countAllResults()
+ ));
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function allItemsSelect() {
+ if ($this->request->isAJAX()) {
+ $onlyActiveOnes = true;
+ $reqVal = $this->request->getPost('val') ?? 'id';
+ $menu = $this->model->getAllForMenu($reqVal.', tarifa_envio_id', 'tarifa_envio_id', $onlyActiveOnes, false);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->tarifa_envio_id = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+ public function menuItems() {
+ if ($this->request->isAJAX()) {
+ $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
+ $reqId = goSanitize($this->request->getPost('id'))[0];
+ $reqText = goSanitize($this->request->getPost('text'))[0];
+ $onlyActiveOnes = false;
+ $columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_envio_id'];
+ $onlyActiveOnes = false;
+ $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
+ $nonItem = new \stdClass;
+ $nonItem->id = '';
+ $nonItem->text = '- '.lang('Basic.global.None').' -';
+ array_unshift($menu , $nonItem);
+
+ $newTokenHash = csrf_hash();
+ $csrfTokenName = csrf_token();
+ $data = [
+ 'menu' => $menu,
+ $csrfTokenName => $newTokenHash
+ ];
+ return $this->respond($data);
+ } else {
+ return $this->failUnauthorized('Invalid request', 403);
+ }
+ }
+
+
+ protected function getTarifaEnvioListItems($selId = null) {
+ $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))])];
+ if (!empty($selId)) :
+ $tarifaEnvioModel = model('App\Models\Tarifas\TarifaEnvioModel');
+
+ $selOption = $tarifaEnvioModel->where('id', $selId)->findColumn('id');
+ if (!empty($selOption)) :
+ $data[$selId] = $selOption[0];
+ endif;
+ endif;
+ return $data;
+ }
+
+}
diff --git a/ci4/app/Entities/Compras/ProveedorEntity.php b/ci4/app/Entities/Compras/ProveedorEntity.php
index c909ed1c..0dba1fd9 100644
--- a/ci4/app/Entities/Compras/ProveedorEntity.php
+++ b/ci4/app/Entities/Compras/ProveedorEntity.php
@@ -19,6 +19,7 @@ class ProveedorEntity extends \CodeIgniter\Entity\Entity
"persona_contacto" => null,
"email" => null,
"telefono" => null,
+ "propiedades" => null,
"is_deleted" => 0,
"created_at" => null,
"updated_at" => null,
diff --git a/ci4/app/Entities/Tarifas/TarifaEnvioEntity.php b/ci4/app/Entities/Tarifas/TarifaEnvioEntity.php
new file mode 100644
index 00000000..0becbc9d
--- /dev/null
+++ b/ci4/app/Entities/Tarifas/TarifaEnvioEntity.php
@@ -0,0 +1,24 @@
+ null,
+ "pais_id" => null,
+ "nombre" => null,
+ "user_created_id" => 0,
+ "user_updated_id" => 0,
+ "is_deleted" => 0,
+ "created_at" => null,
+ "updated_at" => null,
+ ];
+ protected $casts = [
+ "pais_id" => "?int",
+ "user_created_id" => "int",
+ "user_updated_id" => "int",
+ "is_deleted" => "int",
+ ];
+}
diff --git a/ci4/app/Entities/Tarifas/TarifaEnvioPrecioEntity.php b/ci4/app/Entities/Tarifas/TarifaEnvioPrecioEntity.php
new file mode 100644
index 00000000..2b52b4ca
--- /dev/null
+++ b/ci4/app/Entities/Tarifas/TarifaEnvioPrecioEntity.php
@@ -0,0 +1,34 @@
+ null,
+ "tarifa_envio_id" => null,
+ "proveedor_id" => null,
+ "tipo_envio" => null,
+ "peso_min" => null,
+ "peso_max" => null,
+ "precio" => null,
+ "precio_adicional" => 0,
+ "user_created_id" => 0,
+ "user_updated_id" => 0,
+ "is_deleted" => 0,
+ "created_at" => null,
+ "updated_at" => null,
+ ];
+ protected $casts = [
+ "tarifa_envio_id" => "int",
+ "proveedor_id" => "int",
+ "peso_min" => "float",
+ "peso_max" => "float",
+ "precio" => "float",
+ "precio_adicional" => "float",
+ "user_created_id" => "int",
+ "user_updated_id" => "int",
+ "is_deleted" => "int",
+ ];
+}
diff --git a/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php b/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php
new file mode 100644
index 00000000..85907228
--- /dev/null
+++ b/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php
@@ -0,0 +1,27 @@
+ null,
+ "tarifa_envio_id" => null,
+ "cp_inicial" => null,
+ "cp_final" => null,
+ "importe_fijo" => 0,
+ "user_created_id" => 0,
+ "user_updated_id" => 0,
+ "is_deleted" => 0,
+ "created_at" => null,
+ "updated_at" => null,
+ ];
+ protected $casts = [
+ "tarifa_envio_id" => "int",
+ "importe_fijo" => "int",
+ "user_created_id" => "int",
+ "user_updated_id" => "int",
+ "is_deleted" => "int",
+ ];
+}
diff --git a/ci4/app/Language/en/Proveedores.php b/ci4/app/Language/en/Proveedores.php
index 16ff6992..996091a2 100644
--- a/ci4/app/Language/en/Proveedores.php
+++ b/ci4/app/Language/en/Proveedores.php
@@ -25,6 +25,8 @@ return [
'telefono' => 'Phone',
'tipoId' => 'Type',
'updatedAt' => 'Updated At',
+ 'cajas' => 'boxes',
+ 'palets' => 'pallets',
'validation' => [
'cif' => [
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
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..e58a12c2
--- /dev/null
+++ b/ci4/app/Language/en/TarifasEnviosPrecios.php
@@ -0,0 +1,65 @@
+ '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' => [
+ 'error_seleccion_zonas' => 'A line from the zones table must be selected before creating a new record.',
+ 'error_precio_overlap' => 'The range [Min Weight, Max Weight] is overlapped with another one for the selected provider and type.',
+ 'error_precio_range' => 'The field Min Weight must be lower than the field Max Weight',
+ '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/Proveedores.php b/ci4/app/Language/es/Proveedores.php
index d6928648..a9806e58 100644
--- a/ci4/app/Language/es/Proveedores.php
+++ b/ci4/app/Language/es/Proveedores.php
@@ -25,6 +25,8 @@ return [
'telefono' => 'Teléfono',
'tipoId' => 'Tipo',
'updatedAt' => 'Updated At',
+ 'cajas' => 'Cajas',
+ 'palets' => 'Palets',
'validation' => [
'cif' => [
'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.',
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..c2af4492
--- /dev/null
+++ b/ci4/app/Language/es/TarifasEnviosPrecios.php
@@ -0,0 +1,65 @@
+ '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 peso mín.',
+ 'precioAdicional' => 'Precio Kg 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' => [
+ 'error_seleccion_zonas' => 'Debe seleccionar una línea de la tabla zonas antes de crear un registro nuevo.',
+ 'error_precio_overlap' => 'El rango [Peso Min, Peso Max] se solapa con otro existente para el proveedor y tipo seleccionado.',
+ 'error_precio_range' => 'El campo Peso Min debe ser menor que el campo Peso Max',
+ '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/Compras/ProveedorModel.php b/ci4/app/Models/Compras/ProveedorModel.php
index 2366636d..45ec3589 100644
--- a/ci4/app/Models/Compras/ProveedorModel.php
+++ b/ci4/app/Models/Compras/ProveedorModel.php
@@ -15,7 +15,6 @@ class ProveedorModel extends \App\Models\GoBaseModel
const SORTABLE = [
0 => "t1.nombre",
1 => "t2.nombre",
-
];
protected $allowedFields = [
@@ -31,6 +30,7 @@ class ProveedorModel extends \App\Models\GoBaseModel
"persona_contacto",
"email",
"telefono",
+ "propiedades",
"is_deleted",
"deleted_at"
];
@@ -155,7 +155,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id AS id, t1.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp, t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono, t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais"
+ "t1.id AS id, t1.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp,
+ t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono,
+ t1.propiedades AS propiedades, t2.nombre AS tipo, t2.id AS tipo_id, t3.nombre AS provincia, t4.nombre AS pais"
);
$builder->join("lg_proveedores_tipos t2", "t1.tipo_id = t2.id", "left");
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
@@ -205,8 +207,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id AS value, t1.nombre AS label")
- ->where("tipo_id", $tipoId);
+ "t1.id AS value, t1.nombre AS label, t1.propiedades AS options")
+ ->where("tipo_id", $tipoId)
+ ->orderBy('t1.nombre', 'asc');
return $builder->get()->getResultObject();
}
diff --git a/ci4/app/Models/Tarifas/TarifaEnvioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioModel.php
new file mode 100644
index 00000000..0aeb1bce
--- /dev/null
+++ b/ci4/app/Models/Tarifas/TarifaEnvioModel.php
@@ -0,0 +1,93 @@
+ "t1.nombre",
+ 1 => "t2.nombre",
+ ];
+
+ protected $allowedFields = ["pais_id", "nombre","deleted_at","is_deleted"];
+ protected $returnType = "App\Entities\Tarifas\TarifaEnvioEntity";
+
+ protected $useTimestamps = true;
+ protected $useSoftDeletes = false;
+
+ protected $createdField = "created_at";
+
+ protected $updatedField = "updated_at";
+
+ public static $labelField = "nombre";
+
+ protected $validationRules = [
+ "nombre" => [
+ "label" => "TarifasEnvios.nombre",
+ "rules" => "trim|required|max_length[255]",
+ ],
+ ];
+
+ protected $validationMessages = [
+ "nombre" => [
+ "max_length" => "TarifasEnvios.validation.nombre.max_length",
+ "required" => "TarifasEnvios.validation.nombre.required",
+ ],
+ ];
+
+ public function findAllWithPaises(string $selcols = "pais_id, t1.nombre", int $limit = null, int $offset = 0)
+ {
+ $sql =
+ "SELECT t1." .
+ $selcols .
+ ", t2.nombre AS pais_id FROM " .
+ $this->table .
+ " t1 LEFT JOIN lg_paises t2 ON t1.pais_id = t2.id";
+ if (!is_null($limit) && intval($limit) > 0) {
+ $sql .= " LIMIT " . $limit;
+ }
+
+ if (!is_null($offset) && intval($offset) > 0) {
+ $sql .= " OFFSET " . $offset;
+ }
+
+ $query = $this->db->query($sql);
+ $result = $query->getResultObject();
+ return $result;
+ }
+
+ /**
+ * Get resource data.
+ *
+ * @param string $search
+ *
+ * @return \CodeIgniter\Database\BaseBuilder
+ */
+ public function getResource(string $search = "")
+ {
+ $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
+ ->groupStart()
+ ->like("t1.nombre", $search)
+ ->orLike("t2.id", $search)
+ ->orLike("t1.pais_id", $search)
+ ->orLike("t1.nombre", $search)
+ ->orLike("t2.nombre", $search)
+ ->groupEnd();
+ }
+}
diff --git a/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
new file mode 100644
index 00000000..b7cb9f50
--- /dev/null
+++ b/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
@@ -0,0 +1,198 @@
+ "t1.proveedor",
+ 1 => "t1.tipo_envio",
+ 2 => "t1.peso_min",
+ 3 => "t1.peso_max",
+ 4 => "t1.precio",
+ 5 => "t1.precio_adicional"
+ ];
+
+ protected $allowedFields = [
+ "tarifa_envio_id",
+ "proveedor_id",
+ "tipo_envio",
+ "peso_min",
+ "peso_max",
+ "precio",
+ "precio_adicional",
+ "deleted_at",
+ "is_deleted",
+ ];
+ protected $returnType = "App\Entities\Tarifas\TarifaEnvioPrecioEntity";
+
+ protected $useTimestamps = true;
+ protected $useSoftDeletes = false;
+
+ protected $createdField = "created_at";
+
+ protected $updatedField = "updated_at";
+
+ public static $labelField = "tarifa_envio_id";
+
+ protected $validationRules = [
+ "peso_max" => [
+ "label" => "TarifasEnviosPrecios.pesoMax",
+ "rules" => "required|decimal",
+ ],
+ "peso_min" => [
+ "label" => "TarifasEnviosPrecios.pesoMin",
+ "rules" => "required|decimal",
+ ],
+ "precio" => [
+ "label" => "TarifasEnviosPrecios.precio",
+ "rules" => "required|decimal",
+ ],
+ "precio_adicional" => [
+ "label" => "TarifasEnviosPrecios.precioAdicional",
+ "rules" => "required|decimal",
+ ],
+ "tipo_envio" => [
+ "label" => "TarifasEnviosPrecios.tipoEnvio",
+ "rules" => "required|in_list[a domicilio,cajas,palets]",
+ ],
+ ];
+
+ protected $validationMessages = [
+ "peso_max" => [
+ "decimal" => "TarifasEnviosPrecios.validation.peso_max.decimal",
+ "required" => "TarifasEnviosPrecios.validation.peso_max.required",
+ ],
+ "peso_min" => [
+ "decimal" => "TarifasEnviosPrecios.validation.peso_min.decimal",
+ "required" => "TarifasEnviosPrecios.validation.peso_min.required",
+ ],
+ "precio" => [
+ "decimal" => "TarifasEnviosPrecios.validation.precio.decimal",
+ "required" => "TarifasEnviosPrecios.validation.precio.required",
+ ],
+ "precio_adicional" => [
+ "decimal" => "TarifasEnviosPrecios.validation.precio_adicional.decimal",
+ "required" => "TarifasEnviosPrecios.validation.precio_adicional.required",
+ ],
+ "tipo_envio" => [
+ "in_list" => "TarifasEnviosPrecios.validation.tipo_envio.in_list",
+ "required" => "TarifasEnviosPrecios.validation.tipo_envio.required",
+ ],
+ ];
+ public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
+ {
+ $sql =
+ "SELECT t1." .
+ $selcols .
+ ", t2.id AS tarifa_envio, t3.id AS proveedor FROM " .
+ $this->table .
+ " t1 LEFT JOIN lg_tarifas_envios t2 ON t1.tarifa_envio_id = t2.id LEFT JOIN lg_proveedores t3 ON t1.proveedor_id = t3.id";
+ if (!is_null($limit) && intval($limit) > 0) {
+ $sql .= " LIMIT " . intval($limit);
+ }
+
+ if (!is_null($offset) && intval($offset) > 0) {
+ $sql .= " OFFSET " . intval($offset);
+ }
+
+ $query = $this->db->query($sql);
+ $result = $query->getResultObject();
+ return $result;
+ }
+
+ /**
+ * Get resource data.
+ *
+ * @param string $search
+ *
+ * @return \CodeIgniter\Database\BaseBuilder
+ */
+ public function getResource(string $search = "", $zona_envio_id = -1)
+ {
+ $builder = $this->db
+ ->table($this->table . " t1")
+ ->select(
+ "t1.id AS id, t1.tipo_envio AS tipo_envio, t1.peso_min AS peso_min, t1.peso_max AS peso_max, t1.precio AS precio,
+ t1.precio_adicional AS precio_adicional, t2.id AS tarifa_envio, t3.id AS proveedor_id, t3.nombre AS proveedor"
+ );
+ $builder->join("tarifas_envios_zonas t2", "t1.zona_envio_id = t2.id", "left");
+ $builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
+ $builder->where("t1.zona_envio_id", $zona_envio_id);
+
+ //JJO
+ $builder->where("t1.is_deleted", 0);
+
+ return empty($search)
+ ? $builder
+ : $builder
+ ->groupStart()
+ ->like("t1.tipo_envio", $search)
+ ->orLike("t1.peso_min", $search)
+ ->orLike("t1.peso_max", $search)
+ ->orLike("t1.precio", $search)
+ ->orLike("t1.precio_adicional", $search)
+ ->orLike("t3.nombre", $search)
+ ->orLike("t1.tipo_envio", $search)
+ ->orLike("t1.peso_min", $search)
+ ->orLike("t1.peso_max", $search)
+ ->orLike("t1.precio", $search)
+ ->orLike("t1.precio_adicional", $search)
+ ->orLike("t3.nombre", $search)
+ ->groupEnd();
+ }
+
+
+ public function checkIntervals($data = [], $precio_id = null, $zona_id = null){
+
+ helper('general');
+
+ if(floatval($data["peso_min"])>= floatval($data["peso_max"])){
+ return lang('TarifasEnviosPrecios.validation.error_precio_range');
+ }
+
+ $rows = $this->db
+ ->table($this->table)
+ ->select("id, proveedor_id, tipo_envio, peso_min, peso_max")
+ ->where("is_deleted", 0)
+ ->where("zona_envio_id", $zona_id)
+ ->get()->getResultObject();
+
+
+ foreach ($rows as $row) {
+ if (!is_null($precio_id)){
+ if($row->id == $precio_id){
+ continue;
+ }
+ }
+ if($row->proveedor_id == $data["proveedor_id"] && $row->tipo_envio == $data["tipo_envio"]){
+ if(check_overlap(floatval($data["peso_min"]), floatval($data["peso_max"]),
+ $row->peso_min, $row->peso_max)){
+ return lang('TarifasEnviosPrecios.validation.error_precio_overlap');
+ }
+ }
+ }
+
+ return "";
+ }
+
+ public function removeAllPrecioLineas($zona_id = -1, $datetime = null, $delete_flag=1){
+
+ $builder = $this->db
+ ->table($this->table)
+ ->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
+ 'is_deleted' => $delete_flag])
+ ->where('zona_envio_id',$zona_id)
+ ->update();
+
+ return $builder;
+ }
+}
diff --git a/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
new file mode 100644
index 00000000..f6c8e6d4
--- /dev/null
+++ b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
@@ -0,0 +1,116 @@
+ "t1.cp_inicial",
+ 1 => "t1.cp_final",
+ 2 => "t1.importe_fijo",
+ ];
+
+ protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo", "is_deleted", "deleted_at"];
+ protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity";
+
+ protected $useTimestamps = true;
+ protected $useSoftDeletes = false;
+
+ protected $createdField = "created_at";
+
+ protected $updatedField = "updated_at";
+
+ public static $labelField = "tarifa_envio_id";
+
+ protected $validationRules = [
+ "cp_final" => [
+ "label" => "TarifasEnviosZonas.cpFinal",
+ "rules" => "trim|required|max_length[10]",
+ ],
+ "cp_inicial" => [
+ "label" => "TarifasEnviosZonas.cpInicial",
+ "rules" => "trim|required|max_length[10]",
+ ],
+ "importe_fijo" => [
+ "label" => "TarifasEnviosZonas.importeFijo",
+ "rules" => "required|integer",
+ ],
+ ];
+
+ protected $validationMessages = [
+ "cp_final" => [
+ "max_length" => "TarifasEnviosZonas.validation.cp_final.max_length",
+ "required" => "TarifasEnviosZonas.validation.cp_final.required",
+ ],
+ "cp_inicial" => [
+ "max_length" => "TarifasEnviosZonas.validation.cp_inicial.max_length",
+ "required" => "TarifasEnviosZonas.validation.cp_inicial.required",
+ ],
+ "importe_fijo" => [
+ "integer" => "TarifasEnviosZonas.validation.importe_fijo.integer",
+ "required" => "TarifasEnviosZonas.validation.importe_fijo.required",
+ ],
+ ];
+
+ public function findAllWithTarifasEnvios(string $selcols = "*", int $limit = null, int $offset = 0)
+ {
+ $sql =
+ "SELECT t1." .
+ $selcols .
+ ", t2.id AS tarifa_envio FROM " .
+ $this->table .
+ " t1 LEFT JOIN lg_tarifas_envios t2 ON t1.tarifa_envio_id = t2.id";
+ if (!is_null($limit) && intval($limit) > 0) {
+ $sql .= " LIMIT " . $limit;
+ }
+
+ if (!is_null($offset) && intval($offset) > 0) {
+ $sql .= " OFFSET " . $offset;
+ }
+
+ $query = $this->db->query($sql);
+ $result = $query->getResultObject();
+ return $result;
+ }
+
+ /**
+ * Get resource data.
+ *
+ * @param string $search
+ *
+ * @return \CodeIgniter\Database\BaseBuilder
+ */
+ public function getResource(string $search = "", $tarifa_envio_id=-1)
+ {
+ $builder = $this->db
+ ->table($this->table . " t1")
+ ->select(
+ "t1.id as id, 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");
+ $builder->where("t1.tarifa_envio_id", $tarifa_envio_id);
+
+ //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.importe_fijo", $search)
+ ->orLike("t1.cp_inicial", $search)
+ ->orLike("t1.cp_final", $search)
+ ->orLike("t1.importe_fijo", $search)
+ ->groupEnd();
+ }
+}
diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php
index a0902c32..9ac985b2 100644
--- a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php
+++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php
@@ -114,4 +114,28 @@
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php
index a96c6207..8c100dec 100644
--- a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php
+++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php
@@ -94,4 +94,32 @@
});
+ const TRANSPORTE_ID = 2; // Añadir consulta para obtener el id del tipo transporte
+
+ $( document ).ready(function() {
+
+ var e = document.getElementById("tipoId");
+ var value = e.value;
+ if(value == TRANSPORTE_ID) {
+ document.getElementById("row_transporte").style.display = "block";
+ }
+ else{
+ document.getElementById("row_transporte").style.display = "none";
+ }
+ });
+
+
+ $('#tipoId').on('select2:select', function (e) {
+
+ if(this.value == TRANSPORTE_ID) {
+ document.getElementById("row_transporte").style.display = "block";
+ }
+ else{
+ document.getElementById("row_transporte").style.display = "none";
+ document.getElementById("cajas").checked = 0;
+ document.getElementById("palets").checked = 0;
+ }
+ });
+
+
= $this->endSection() ?>
diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/_tarifaEnvioFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/_tarifaEnvioFormItems.php
new file mode 100644
index 00000000..3950f782
--- /dev/null
+++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/_tarifaEnvioFormItems.php
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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
new file mode 100644
index 00000000..07dfc502
--- /dev/null
+++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php
@@ -0,0 +1,562 @@
+= $this->include("themes/_commonPartialsBs/datatables") ?>
+= $this->include("themes/_commonPartialsBs/select2bs5") ?>
+= $this->include("themes/_commonPartialsBs/sweetalert") ?>
+= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
+= $this->section("content") ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | = lang('TarifasEnviosZonas.cpInicial') ?> |
+ = lang('TarifasEnviosZonas.cpFinal') ?> |
+ = lang('TarifasEnviosZonas.importeFijo') ?> |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | = lang('TarifasEnviosPrecios.proveedorId') ?> |
+ = lang('TarifasEnviosPrecios.tipoEnvio') ?> |
+ = lang('TarifasEnviosPrecios.pesoMin') ?> |
+ = lang('TarifasEnviosPrecios.pesoMax') ?> |
+ = lang('TarifasEnviosPrecios.precio') ?> |
+ = lang('TarifasEnviosPrecios.precioAdicional') ?> |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+= $this->endSection() ?>
+
+
+
+
+
+
+
+
+
+= $this->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('zonas')){
+ remove_zonas(dataId, row);
+ }
+ else if ($(this).attr('table').includes('precios')){
+ remove_precios(dataId, row);
+ }
+ }
+ });
+
+= $this->endSection() ?>
+
+
+
+
+
+= $this->section("additionalInlineJs") ?>
+ const lastColNr = $('#tableOfZonas').find("tr:first th").length - 1;
+
+ var editor = new $.fn.dataTable.Editor( {
+ ajax: {
+ url: "= route_to('editorOfTarifasEnvioZonas') ?>",
+ headers: {
+ = csrf_token() ?? "token" ?> : = csrf_token() ?>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.= csrf_token() ?>);
+ });
+
+
+ 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: '= route_to('dataTableOfTarifasEnvioZonas') ?>',
+ data: {
+ 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/= config('Basics')->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_zonas(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) => {
+ if(typeof jqXHR.responseJSON.messages != "undefined")
+ popErrorAlert(jqXHR.responseJSON.messages.error);
+ else
+ popErrorAlert(jqXHR.responseJSON.message);
+ $('#confirm2delete').modal('toggle');
+ });
+ }
+
+
+ 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();
+ }
+ } );
+= $this->endSection() ?>
+
+
+
+
+
+= $this->section("additionalInlineJs") ?>
+const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
+
+ var editor2 = new $.fn.dataTable.Editor( {
+ ajax: {
+ url: "= route_to('editorOfTarifasEnvioPrecios') ?>",
+ headers: {
+ = csrf_token() ?? "token" ?> : = csrf_token() ?>v,
+ },
+ },
+ table : "#tableOfPrecios",
+ idSrc: 'id',
+ fields: [
+ {
+ "name": "proveedor_id",
+ "type": "select"
+ }, {
+ name: "tipo_envio",
+ "type": "select"
+ }, {
+ name: "peso_min"
+ }, {
+ name: "peso_max"
+ }, {
+ name: "precio"
+ }, {
+ name: "precio_adicional"
+ }, {
+ "name": "zona_envio_id",
+ "type": "hidden"
+ }, {
+ "name": "deleted_at",
+ "type": "hidden"
+ },{
+ "name": "is_deleted",
+ "type": "hidden"
+ },
+ ]
+ } );
+
+ // Generación de la lista de proveedores (id, nombre)
+ const suppliersList = ;
+ editor2.field( 'proveedor_id' ).update( suppliersList );
+
+ editor2.on( 'preSubmit', function ( e, d, type ) {
+ if ( type === 'create'){
+ d.data[0]['zona_envio_id'] = selected_zona_id;
+ }
+ else if(type === 'edit' ) {
+ for (v in d.data){
+ d.data[v]['zona_envio_id'] = selected_zona_id;
+ }
+ }
+ });
+
+
+ editor2.dependent('proveedor_id', function (val, data, callback, e ) {
+
+ var supplier = suppliersList.find(o => o.value === val);
+ values = [{label:'= lang('TarifasEnviosPrecios.aDomicilio') ?>', value: "a domicilio"}];
+
+ if(supplier.options != null)
+ {
+ if(supplier.options.includes("cajas")){
+ values.push({label:'= lang('TarifasEnviosPrecios.cajas') ?>', value: "cajas"});
+ }
+ if(supplier.options.includes("palets")){
+ values.push({label:'= lang('TarifasEnviosPrecios.palets') ?>', value: "palets"});
+ }
+ }
+ editor2.field( 'tipo_envio' ).update( values );
+ callback(true);
+ });
+
+ editor2.on( 'postSubmit', function ( e, json, data, action ) {
+
+ yeniden(json.= csrf_token() ?>);
+ });
+
+
+ editor2.on( 'submitSuccess', function ( e, json, data, action ) {
+
+ theTable2.clearPipeline();
+ theTable2.draw();
+ });
+
+
+ var theTable2 = $('#tableOfPrecios').DataTable( {
+ serverSide: true,
+ processing: true,
+ autoWidth: true,
+ responsive: true,
+ lengthMenu: [ 5, 10, 25, 50, 100],
+ order: [[ 0, "asc" ], [ 1, "asc" ]],
+ pageLength: 25,
+ lengthChange: true,
+ searching: false,
+ paging: true,
+ info: false,
+ dom: '<"mt-4"><"float-end"B><"float-start"l><"mt-4 mb-3"p>',
+ ajax : $.fn.dataTable.pipeline( {
+ url: '= route_to('dataTableOfTarifasEnvioPrecios') ?>',
+ data: function ( d ) {
+ d.zona_envio_id = selected_zona_id;
+ },
+ method: 'POST',
+ headers: {'X-Requested-With': 'XMLHttpRequest'},
+ async: true,
+ }),
+ columns: [
+ {'data': 'proveedor_id',
+ render: function(data, type, row, meta) {
+ var value = suppliersList.find(element => element.value === data);
+ return value['label'];
+ },
+ },
+ { 'data': 'tipo_envio', "render": function ( data, type, row, meta ) {
+ if(data=='a domicilio')
+ return '= lang('TarifasEnviosPrecios.aDomicilio') ?>';
+ else if (data=='cajas')
+ return '= lang('TarifasEnviosPrecios.cajas') ?>';
+ else if (data=='palets')
+ return '= lang('TarifasEnviosPrecios.palets') ?>';
+ }
+ },
+ { 'data': 'peso_min' },
+ { 'data': 'peso_max' },
+ { 'data': 'precio' },
+ { 'data': 'precio_adicional' },
+ {
+ data: actionBtns,
+ className: 'row-edit dt-center'
+ }
+ ],
+ columnDefs: [
+ {
+ orderable: false,
+ searchable: false,
+ targets: [lastColNr2]
+ },
+ {"orderData": [ 0, 1 ], "targets": 0 },
+
+ ],
+ language: {
+ url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/= config('Basics')->i18n ?>.json"
+ },
+ buttons: [ {
+ className: 'btn btn-primary float-end me-sm-3 me-1',
+ extend: "createInline",
+ editor: editor2,
+ formOptions: {
+ submitTrigger: -1,
+ submitHtml: ''
+
+ },
+ action: function ( e, dt, node, config ) {
+ if(selected_zona_id == -1){
+ popErrorAlert("= lang('TarifasEnviosPrecios.validation.error_seleccion_zonas') ?>");
+ }
+ else{
+ formOptions= {
+ submitTrigger: -1,
+ submitHtml: ''
+
+ };
+ editor2.inlineCreate(config.position, formOptions);
+ }
+ },
+ } ],
+
+ } );
+
+
+ // Activate an inline edit on click of a table cell
+ $('#tableOfPrecios').on( 'click', 'tbody span.edit', function (e) {
+ editor.inline(
+ theTable2.cells(this.parentNode.parentNode, '*').nodes(),
+ {
+ cancelHtml: '',
+ cancelTrigger: 'span.cancel',
+ submitHtml: '',
+ submitTrigger: 'span.edit',
+ submit: 'allIfChanged'
+ }
+ );
+ } );
+
+ // Delete row
+ function remove_precios(dataId, row){
+
+ $.ajax({
+ url: `/tarifas/tarifasenviosprecios/delete/${dataId}`,
+ method: 'GET',
+ }).done((data, textStatus, jqXHR) => {
+ $('#confirm2delete').modal('toggle');
+ theTable2.clearPipeline();
+ theTable2.row($(row)).invalidate().draw();
+ popSuccessAlert(data.msg ?? jqXHR.statusText);
+ }).fail((jqXHR, textStatus, errorThrown) => {
+ popErrorAlert(jqXHR.responseJSON.messages.error)
+ });
+ }
+
+= $this->endSection() ?>
+
+=$this->section('css') ?>
+
+
+
+
+
+=$this->endSection() ?>
+
+
+= $this->section('additionalExternalJs') ?>
+
+
+
+
+
+
+
+
+
+=$this->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
new file mode 100644
index 00000000..fa923f6a
--- /dev/null
+++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php
@@ -0,0 +1,148 @@
+=$this->include('themes/_commonPartialsBs/datatables') ?>
+=$this->include('themes/_commonPartialsBs/sweetalert') ?>
+= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
+= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
+=$this->section('content'); ?>
+
+
+
+
+
+
+ = view('themes/_commonPartialsBs/_alertBoxes'); ?>
+
+
+
+
+ | = lang('TarifasEnvios.nombre') ?> |
+ = lang('Paises.pais') ?> |
+ = lang('Basic.global.Action') ?> |
+
+
+
+
+
+
+
+
+
+
+
+
+=$this->endSection() ?>
+
+
+=$this->section('additionalInlineJs') ?>
+
+ const lastColNr = $('#tableOfTarifaenvio').find("tr:first th").length - 1;
+ const actionBtns = function(data) {
+ return `
+
+
+ | `;
+ };
+ theTable = $('#tableOfTarifaenvio').DataTable({
+ processing: true,
+ serverSide: true,
+ autoWidth: true,
+ responsive: true,
+ scrollX: true,
+ lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
+ pageLength: 25,
+ lengthChange: true,
+ "dom": 'lfBrtip',
+ "buttons": [
+ 'copy', 'csv', 'excel', 'print', {
+ extend: 'pdfHtml5',
+ orientation: 'landscape',
+ pageSize: 'A4'
+ }
+ ],
+ stateSave: true,
+ order: [[0, 'asc']],
+ language: {
+ url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/= config('Basics')->i18n ?>.json"
+ },
+ ajax : $.fn.dataTable.pipeline( {
+ url: '= route_to('dataTableOfTarifaEnvio') ?>',
+ method: 'POST',
+ headers: {'X-Requested-With': 'XMLHttpRequest'},
+ async: true,
+ }),
+ columnDefs: [
+ {
+ orderable: false,
+ searchable: false,
+ targets: [lastColNr]
+ }
+ ],
+ columns : [
+ { 'data': 'nombre' },
+ { 'data': 'pais_id' },
+ { 'data': actionBtns }
+ ]
+ });
+
+
+
+
+ $(document).on('click', '.btn-edit', function(e) {
+
+ window.location.href = `/tarifas/tarifasenvios/edit/${$(this).attr('data-id')}`;
+ });
+
+ $(document).on('click', '.btn-delete', function(e) {
+ $(".btn-remove").attr('data-id', $(this).attr('data-id'));
+ });
+
+ $(document).on('click', '.btn-remove', function(e) {
+ const dataId = $(this).attr('data-id');
+ const row = $(this).closest('tr');
+ if ($.isNumeric(dataId)) {
+ $.ajax({
+ url: `/tarifas/tarifasenvios/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)
+ })
+ }
+ });
+
+
+
+
+
+=$this->endSection() ?>
+
+
+=$this->section('css') ?>
+
+=$this->endSection() ?>
+
+
+= $this->section('additionalExternalJs') ?>
+
+
+
+
+
+
+
+
+
+
+=$this->endSection() ?>
+
diff --git a/ci4/app/Views/themes/backend/vuexy/main/menu.php b/ci4/app/Views/themes/backend/vuexy/main/menu.php
index 50a80092..d4c25b10 100644
--- a/ci4/app/Views/themes/backend/vuexy/main/menu.php
+++ b/ci4/app/Views/themes/backend/vuexy/main/menu.php
@@ -403,7 +403,7 @@
* MENU TARIFAS
*/
if (allowMenuSection($menus,
- ['Tarifaacabado', 'Tarifaenvio', 'Tarifaimpresion', 'Tarifamanipulado', 'Tarifaencuadernacion',
+ ['Tarifaacabado', 'Tarifasenvios', 'Tarifaimpresion', 'Tarifamanipulado', 'Tarifaencuadernacion',
'Tarifapapelcompra', 'Tarifapapeldefecto', 'Tarifapreimpresion'
], 'index')): ?>
@@ -422,10 +422,10 @@
- 0): ?>
+ 0): ?>
0): ?>
diff --git a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php
index 187a1062..226a3005 100644
--- a/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php
+++ b/ci4/app/Views/themes/backend/vuexy/main/menu_impresion.php
@@ -538,7 +538,7 @@
* MENU TARIFAS
*/
if (allowMenuSection($menus,
- ['Tarifapreimpresion', 'Tarifasmanipulado', 'Tarifaacabado', 'Tarifaenvio', 'Tarifasencuadernacion'], 'index')): ?>
+ ['Tarifapreimpresion', 'Tarifasmanipulado', 'Tarifaacabado', 'Tarifasenvios', 'Tarifasencuadernacion'], 'index')): ?>
- 0): ?>
+ 0): ?>
0): ?>