mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadiendo tarifas envio
This commit is contained in:
@ -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']);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php namespace App\Controllers\Compras;
|
||||
|
||||
use stdClass;
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
@ -75,6 +76,9 @@ class Proveedores extends \App\Controllers\GoBaseResourceController {
|
||||
$nullIfEmpty = true; // !(phpversion() >= '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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
284
ci4/app/Controllers/Tarifas/Tarifasenvios.php
Normal file
284
ci4/app/Controllers/Tarifas/Tarifasenvios.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php namespace App\Controllers\Tarifas;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Tarifas\TarifaEnvioEntity;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioModel;
|
||||
|
||||
class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaEnvioModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Tarifa Envio';
|
||||
protected static $singularObjectNameCc = 'tarifaEnvio';
|
||||
protected static $pluralObjectName = 'Tarifa Envio';
|
||||
protected static $pluralObjectNameCc = 'tarifaEnvio';
|
||||
|
||||
protected static $controllerSlug = 'tarifasenvios';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/tarifas/envios/';
|
||||
|
||||
protected $indexRoute = 'tarifaEnvioList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('TarifasEnvios.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
321
ci4/app/Controllers/Tarifas/Tarifasenvioserecios.php
Normal file
321
ci4/app/Controllers/Tarifas/Tarifasenvioserecios.php
Normal file
@ -0,0 +1,321 @@
|
||||
<?php namespace App\Controllers\Tarifas;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Tarifas\TarifaEnvioPrecioEntity;
|
||||
|
||||
use App\Models\compras\ProveedorModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioPrecioModel;
|
||||
|
||||
class Tarifasenvioserecios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaEnvioPrecioModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Tarifa Envio Precio';
|
||||
protected static $singularObjectNameCc = 'tarifaEnvioPrecio';
|
||||
protected static $pluralObjectName = 'Tarifa Envio Precio';
|
||||
protected static $pluralObjectNameCc = 'tarifaEnvioPrecio';
|
||||
|
||||
protected static $controllerSlug = 'tarifasenviosprecios';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/tarifas/envios/';
|
||||
|
||||
protected $indexRoute = 'tarifaEnvioPrecioList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
289
ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
Normal file
289
ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
Normal file
@ -0,0 +1,289 @@
|
||||
<?php namespace App\Controllers\Tarifas;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Tarifas\TarifaEnvioZonaEntity;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioZonaModel;
|
||||
|
||||
class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaEnvioZonaModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Tarifa Envio Zona';
|
||||
protected static $singularObjectNameCc = 'tarifaEnvioZona';
|
||||
protected static $pluralObjectName = 'Tarifas Envios Zonas';
|
||||
protected static $pluralObjectNameCc = 'tarifasEnviosZonas';
|
||||
|
||||
protected static $controllerSlug = 'tarifasenvioszonas';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/tarifas/envios/';
|
||||
|
||||
protected $indexRoute = 'tarifaEnvioZonaList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,
|
||||
|
||||
24
ci4/app/Entities/Tarifas/TarifaEnvioEntity.php
Normal file
24
ci4/app/Entities/Tarifas/TarifaEnvioEntity.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace App\Entities\Tarifas;
|
||||
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class TarifaEnvioEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => 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",
|
||||
];
|
||||
}
|
||||
34
ci4/app/Entities/Tarifas/TarifaEnvioPrecioEntity.php
Normal file
34
ci4/app/Entities/Tarifas/TarifaEnvioPrecioEntity.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace App\Entities\Tarifas;
|
||||
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class TarifaEnvioPrecioEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => 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",
|
||||
];
|
||||
}
|
||||
27
ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php
Normal file
27
ci4/app/Entities/Tarifas/TarifaEnvioZonaEntity.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace App\Entities\Tarifas;
|
||||
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class TarifaEnvioZonaEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => 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",
|
||||
];
|
||||
}
|
||||
@ -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.',
|
||||
|
||||
@ -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.',
|
||||
|
||||
@ -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");
|
||||
|
||||
90
ci4/app/Models/Tarifas/TarifaEnvioModel.php
Normal file
90
ci4/app/Models/Tarifas/TarifaEnvioModel.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEnvioModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "lg_tarifas_envios";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "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();
|
||||
}
|
||||
}
|
||||
155
ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
Normal file
155
ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "tarifas_envios_precios";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
1 => "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();
|
||||
}
|
||||
}
|
||||
117
ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
Normal file
117
ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "tarifas_envios_zonas";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
1 => "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();
|
||||
}
|
||||
}
|
||||
@ -114,4 +114,28 @@
|
||||
|
||||
</div><!--//.col -->
|
||||
|
||||
</div><!-- //.row -->
|
||||
</div><!-- //.row -->
|
||||
|
||||
<div class="row" id="row_transporte" style="display:none;">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
|
||||
<label for="cajas" class="form-check-label">
|
||||
<input type="checkbox" id="cajas" name="cajas" value="1" class="form-check-input" <?= $proveedorEntity->cajas == true ? 'checked' : ''; ?>>
|
||||
<?= lang('Proveedores.cajas') ?>
|
||||
</label>
|
||||
</div><!--//.form-check -->
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
|
||||
<label for="palets" class="form-check-label">
|
||||
<input type="checkbox" id="palets" name="palets" value="1" class="form-check-input" <?= $proveedorEntity->palets == true ? 'checked' : ''; ?>>
|
||||
<?= lang('Proveedores.palets') ?>
|
||||
</label>
|
||||
</div><!--//.form-check -->
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
</div><!-- //.row -->
|
||||
@ -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() ?>
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12 px-4">
|
||||
<div class="mb-3">
|
||||
<label for="paisId" class="form-label">
|
||||
<?=lang('TarifasEnvios.paisId') ?>
|
||||
</label>
|
||||
<select id="paisId" name="pais_id" class="form-control select2bs" style="width: 100%;" >
|
||||
<option value=""><?=lang('Basic.global.pleaseSelectA', [lang('TarifasEnvios.paisId')]) ?></option>
|
||||
|
||||
<?php foreach ($paisList as $item) : ?>
|
||||
<option value="<?=$item->id ?>"<?=$item->id==$tarifaEnvioEntity->pais_id ? ' selected':'' ?>>
|
||||
<?=$item->nombre ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="nombre" class="form-label">
|
||||
<?=lang('TarifasEnvios.nombre') ?>*
|
||||
</label>
|
||||
<input type="text" id="nombre" name="nombre" required maxLength="255" class="form-control" value="<?=old('nombre', $tarifaEnvioEntity->nombre) ?>">
|
||||
</div><!--//.mb-3 -->
|
||||
|
||||
</div><!--//.col -->
|
||||
|
||||
</div><!-- //.row -->
|
||||
@ -0,0 +1,26 @@
|
||||
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
|
||||
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
|
||||
<?= $this->section("content") ?>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
|
||||
</div><!--//.card-header -->
|
||||
<form id="tarifaEnvioForm" method="post" action="<?= $formAction ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="card-body">
|
||||
<?= view("themes/_commonPartialsBs/_alertBoxes") ?>
|
||||
<?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
|
||||
<?= view("themes/backend/vuexy/form/tarifas/envios/_tarifaEnvioFormItems") ?>
|
||||
</div><!-- /.card-body -->
|
||||
<div class="card-footer">
|
||||
<?= anchor(route_to("tarifaEnvioList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start"]) ?>
|
||||
<input type="submit" class="btn btn-primary float-end" name="save" value="<?= lang("Basic.global.Save") ?>">
|
||||
</div><!-- /.card-footer -->
|
||||
</form>
|
||||
</div><!-- //.card -->
|
||||
</div><!--//.col -->
|
||||
</div><!--//.row -->
|
||||
<?= $this->endSection() ?>
|
||||
@ -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'); ?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?=lang('TarifasEnvios.tarifaEnvioList') ?></h3>
|
||||
<?=anchor(route_to('newTarifaEnvio'), lang('Basic.global.addNew').' '.lang('TarifasEnvios.tarifaEnvio'), ['class'=>'btn btn-primary float-end']); ?>
|
||||
</div><!--//.card-header -->
|
||||
<div class="card-body">
|
||||
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
|
||||
|
||||
<table id="tableOfTarifaenvio" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('TarifasEnvios.nombre') ?></th>
|
||||
<th><?= lang('Paises.pais') ?></th>
|
||||
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!--//.card-body -->
|
||||
<div class="card-footer">
|
||||
|
||||
</div><!--//.card-footer -->
|
||||
</div><!--//.card -->
|
||||
</div><!--//.col -->
|
||||
</div><!--//.row -->
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?=$this->section('additionalInlineJs') ?>
|
||||
|
||||
const lastColNr = $('#tableOfTarifaenvio').find("tr:first th").length - 1;
|
||||
const actionBtns = function(data) {
|
||||
return `
|
||||
<td class="text-right py-0 align-middle">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
|
||||
</div>
|
||||
</td>`;
|
||||
};
|
||||
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/<?= 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: [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)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?=$this->section('css') ?>
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.<?=config('Basics')->theme['name'] == 'Bootstrap5' ? 'bootstrap5' : 'bootstrap4' ?>.min.css">
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?= $this->section('additionalExternalJs') ?>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.<?=config('Basics')->theme['name'] == 'Bootstrap5' ? 'bootstrap5' : 'bootstrap4' ?>.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.html5.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.print.min.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js" integrity="sha512-xcHCGC5tQ0SHlRX8Anbz6oy/OullASJkEhb4gjkneVpGE3/QGYejf14CUO5n5q5paiHfRFTa9HKgByxzidw2Bw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/pdfmake.min.js" integrity="sha512-rDbVu5s98lzXZsmJoMa0DjHNE+RwPJACogUCLyq3Xxm2kJO6qsQwjbE5NDk2DqmlKcxDirCnU1wAzVLe12IM3w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/vfs_fonts.js" integrity="sha512-cktKDgjEiIkPVHYbn8bh/FEyYxmt4JDJJjOCu5/FQAkW4bc911XtKYValiyzBiJigjVEvrIAyQFEbRJZyDA1wQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
@ -403,7 +403,7 @@
|
||||
* MENU TARIFAS
|
||||
*/
|
||||
if (allowMenuSection($menus,
|
||||
['Tarifaacabado', 'Tarifaenvio', 'Tarifaimpresion', 'Tarifamanipulado', 'Tarifaencuadernacion',
|
||||
['Tarifaacabado', 'Tarifasenvios', 'Tarifaimpresion', 'Tarifamanipulado', 'Tarifaencuadernacion',
|
||||
'Tarifapapelcompra', 'Tarifapapeldefecto', 'Tarifapreimpresion'
|
||||
], 'index')): ?>
|
||||
<!-- Prices -->
|
||||
@ -422,10 +422,10 @@
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if (count($temp = getArrayItem($menus, 'name', 'Tarifaenvio')) > 0): ?>
|
||||
<?php if (count($temp = getArrayItem($menus, 'name', 'Tarifasenvios')) > 0): ?>
|
||||
<?php if (count(getArrayItem($temp, 'methods', 'index', true)) > 0): ?>
|
||||
<li class="menu-item">
|
||||
<a href="<?= site_url("tarifas/tarifaenvio") ?>" class="menu-link">
|
||||
<a href="<?= site_url("tarifas/tarifasenvios") ?>" class="menu-link">
|
||||
<div data-i18n="<?= lang("App.menu_tarifaenvio") ?>"><?= lang("App.menu_tarifaenvio") ?></div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -538,7 +538,7 @@
|
||||
* MENU TARIFAS
|
||||
*/
|
||||
if (allowMenuSection($menus,
|
||||
['Tarifapreimpresion', 'Tarifasmanipulado', 'Tarifaacabado', 'Tarifaenvio', 'Tarifasencuadernacion'], 'index')): ?>
|
||||
['Tarifapreimpresion', 'Tarifasmanipulado', 'Tarifaacabado', 'Tarifasenvios', 'Tarifasencuadernacion'], 'index')): ?>
|
||||
<!-- Prices -->
|
||||
<li class="menu-item">
|
||||
<a href="javascript:void(0);" class="menu-link menu-toggle">
|
||||
@ -582,10 +582,10 @@
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php if (count($temp = getArrayItem($menus, 'name', 'Tarifaenvio')) > 0): ?>
|
||||
<?php if (count($temp = getArrayItem($menus, 'name', 'Tarifasenvios')) > 0): ?>
|
||||
<?php if (count(getArrayItem($temp, 'methods', 'index', true)) > 0): ?>
|
||||
<li class="menu-item">
|
||||
<a href="<?= site_url("tarifas/tarifaenvio") ?>" class="menu-link">
|
||||
<a href="<?= site_url("tarifas/tarifasenvios") ?>" class="menu-link">
|
||||
<div data-i18n="<?= lang("App.menu_tarifaenvio") ?>"><?= lang("App.menu_tarifaenvio") ?></div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user