diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 5b811dcb..927cd617 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -395,6 +395,48 @@ $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('(:num)/edit', '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->get('', 'Tarifasenvioserecios::index', ['as' => 'tarifaEnvioPrecioList']); + $routes->get('add', 'Tarifasenvioserecios::add', ['as' => 'newTarifaEnvioPrecio']); + $routes->post('add', 'Tarifasenvioserecios::add', ['as' => 'createTarifaEnvioPrecio']); + $routes->post('create', 'Tarifasenvioserecios::create', ['as' => 'ajaxCreateTarifaEnvioPrecio']); + $routes->put('(:num)/update', 'Tarifasenvioserecios::update/$1', ['as' => 'ajaxUpdateTarifaEnvioPrecio']); + $routes->post('(:num)/edit', 'Tarifasenvioserecios::edit/$1', ['as' => 'updateTarifaEnvioPrecio']); + $routes->post('datatable', 'Tarifasenvioserecios::datatable', ['as' => 'dataTableOfTarifaEnvioPrecio']); + $routes->post('allmenuitems', 'Tarifasenvioserecios::allItemsSelect', ['as' => 'select2ItemsOfTarifaEnvioPrecio']); + $routes->post('menuitems', 'Tarifasenvioserecios::menuItems', ['as' => 'menuItemsOfTarifaEnvioPrecio']); +*/}); +$routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvioserecios', 'except' => 'show,new,create,update']); + + +$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->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..200f35a9 --- /dev/null +++ b/ci4/app/Controllers/Tarifas/Tarifasenvios.php @@ -0,0 +1,284 @@ +viewData['pageTitle'] = lang('TarifasEnvios.moduleTitle'); + $this->viewData['usingSweetAlert'] = 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() { + + + + $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('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(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) { + + 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); + + + + $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 = true; + 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'); + + + 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'] ?? 1; + $order = TarifaEnvioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; + $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; + } + +} diff --git a/ci4/app/Controllers/Tarifas/Tarifasenvioserecios.php b/ci4/app/Controllers/Tarifas/Tarifasenvioserecios.php new file mode 100644 index 00000000..41745e29 --- /dev/null +++ b/ci4/app/Controllers/Tarifas/Tarifasenvioserecios.php @@ -0,0 +1,321 @@ +viewData['pageTitle'] = lang('TarifasEnviosPrecios.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + 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() { + 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'; + + $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.', 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..4e7b188d --- /dev/null +++ b/ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php @@ -0,0 +1,289 @@ +viewData['pageTitle'] = lang('TarifasEnviosZonas.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + 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 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 = TarifaEnvioZonaModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; + $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.', 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..77a3da96 --- /dev/null +++ b/ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php @@ -0,0 +1,27 @@ + null, + "tarifa_envio_id" => null, + "cp_inicial" => null, + "cp_final" => null, + "inporte_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", + "inporte_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/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/Models/Compras/ProveedorModel.php b/ci4/app/Models/Compras/ProveedorModel.php index 2366636d..4acbc281 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"); diff --git a/ci4/app/Models/Tarifas/TarifaEnvioModel.php b/ci4/app/Models/Tarifas/TarifaEnvioModel.php new file mode 100644 index 00000000..3e38eb44 --- /dev/null +++ b/ci4/app/Models/Tarifas/TarifaEnvioModel.php @@ -0,0 +1,90 @@ + "t1.nombre", + 1 => "t2.nombre", + ]; + + protected $allowedFields = ["pais_id", "nombre"]; + 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"); + + 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..01d51533 --- /dev/null +++ b/ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php @@ -0,0 +1,155 @@ + "t1.id", + 2 => "t1.tarifa_envio_id", + 3 => "t1.proveedor_id", + 4 => "t1.tipo_envio", + 5 => "t1.peso_min", + 6 => "t1.peso_max", + 7 => "t1.precio", + 8 => "t1.precio_adicional", + 9 => "t2.id", + 10 => "t3.id", + ]; + + protected $allowedFields = [ + "tarifa_envio_id", + "proveedor_id", + "tipo_envio", + "peso_min", + "peso_max", + "precio", + "precio_adicional", + ]; + 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 = "") + { + $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" + ); + $builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left"); + $builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left"); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $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("t2.id", $search) + ->orLike("t3.id", $search) + ->orLike("t1.id", $search) + ->orLike("t1.tarifa_envio_id", $search) + ->orLike("t1.proveedor_id", $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("t2.id", $search) + ->orLike("t3.id", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php new file mode 100644 index 00000000..053cc410 --- /dev/null +++ b/ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php @@ -0,0 +1,117 @@ + "t1.tarifa_envio_id", + 2 => "t1.cp_inicial", + 3 => "t1.cp_final", + 4 => "t1.inporte_fijo", + 5 => "t2.id", + ]; + + protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "inporte_fijo"]; + 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]", + ], + "inporte_fijo" => [ + "label" => "TarifasEnviosZonas.inporteFijo", + "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", + ], + "inporte_fijo" => [ + "integer" => "TarifasEnviosZonas.validation.inporte_fijo.integer", + "required" => "TarifasEnviosZonas.validation.inporte_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 = "") + { + $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" + ); + $builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left"); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.cp_inicial", $search) + ->orLike("t1.cp_final", $search) + ->orLike("t1.inporte_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("t2.id", $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; + } + }); + + 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..33c32c8d --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioForm.php @@ -0,0 +1,26 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+ +
+
+
+
+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..0bf51bfe --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/envios/viewTarifaEnvioList.php @@ -0,0 +1,148 @@ +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section('content'); ?> +
+
+ +
+
+

+ 'btn btn-primary float-end']); ?> +
+
+ + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +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: 10, + 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/i18n ?>.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [0,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')}/edit`; + }); + + $(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/tarifasenvio/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) + }) + } + }); + + + + + +endSection() ?> + + +section('css') ?> + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + + +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): ?>