mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'feat/prov_envio_cajas_palets' into 'main'
Feat/prov envio cajas palets See merge request jjimenez/safekat!58
This commit is contained in:
@ -395,6 +395,34 @@ $routes->group('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\T
|
||||
$routes->resource('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernaciontiradas', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
$routes->group('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
|
||||
$routes->get('', 'Tarifasenvios::index', ['as' => 'tarifaEnvioList']);
|
||||
$routes->get('add', 'Tarifasenvios::add', ['as' => 'newTarifaEnvio']);
|
||||
$routes->post('add', 'Tarifasenvios::add', ['as' => 'createTarifaEnvio']);
|
||||
$routes->post('create', 'Tarifasenvios::create', ['as' => 'ajaxCreateTarifaEnvio']);
|
||||
$routes->put('(:num)/update', 'Tarifasenvios::update/$1', ['as' => 'ajaxUpdateTarifaEnvio']);
|
||||
$routes->post('edit/(:num)', 'Tarifasenvios::edit/$1', ['as' => 'updateTarifaEnvio']);
|
||||
$routes->post('datatable', 'Tarifasenvios::datatable', ['as' => 'dataTableOfTarifaEnvio']);
|
||||
$routes->post('allmenuitems', 'Tarifasenvios::allItemsSelect', ['as' => 'select2ItemsOfTarifaEnvio']);
|
||||
$routes->post('menuitems', 'Tarifasenvios::menuItems', ['as' => 'menuItemsOfTarifaEnvio']);
|
||||
});
|
||||
$routes->resource('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvios', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
$routes->group('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
|
||||
$routes->post('datatable', 'Tarifasenviosprecios::datatable', ['as' => 'dataTableOfTarifasEnvioPrecios']);
|
||||
$routes->post('datatable_editor', 'Tarifasenviosprecios::datatable_editor', ['as' => 'editorOfTarifasEnvioPrecios']);
|
||||
});
|
||||
$routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenviosprecios', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
$routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
|
||||
$routes->post('datatable', 'Tarifasenvioszonas::datatable', ['as' => 'dataTableOfTarifasEnvioZonas']);
|
||||
$routes->post('datatable_editor', 'Tarifasenvioszonas::datatable_editor', ['as' => 'editorOfTarifasEnvioZonas']);
|
||||
});
|
||||
$routes->resource('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvioszonas', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
$routes->group('proveedores', ['namespace' => 'App\Controllers\Compras'], function ($routes) {
|
||||
$routes->get('', 'Proveedores::index', ['as' => 'proveedorList']);
|
||||
$routes->get('add', 'Proveedores::add', ['as' => 'newProveedor']);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
322
ci4/app/Controllers/Tarifas/Tarifasenvios.php
Normal file
322
ci4/app/Controllers/Tarifas/Tarifasenvios.php
Normal file
@ -0,0 +1,322 @@
|
||||
<?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\Compras\ProveedorModel;
|
||||
use App\Models\Compras\ProveedorTipoModel;
|
||||
|
||||
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;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_tarifaenvio"), 'route' => site_url('tarifas/tarifasenvios'), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnvios.tarifaEnvio')]),
|
||||
'tarifaEnvioEntity' => new TarifaEnvioEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewTarifaEnvioList', $viewData);
|
||||
}
|
||||
|
||||
|
||||
public function add() {
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.';
|
||||
$message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(site_url('tarifas/tarifasenvios/edit/' . $id))->with('sweet-success', $message);
|
||||
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioEntity'] = isset($sanitizedData) ? new TarifaEnvioEntity($sanitizedData) : new TarifaEnvioEntity();
|
||||
$this->viewData['paisList'] = $this->getPaisListItems();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTarifaEnvio');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tarifaEnvioEntity = $this->model->find($id);
|
||||
|
||||
if ($tarifaEnvioEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_updated_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tarifaEnvioEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tarifaEnvioEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.';
|
||||
//$message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioEntity'] = $tarifaEnvioEntity;
|
||||
$this->viewData['paisList'] = $this->getPaisListItems();
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTarifaEnvio', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.edit3');
|
||||
|
||||
//JJO
|
||||
$this->viewData['proveedores'] = $this->getProveedores();
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
|
||||
return $response;
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
||||
$order = TarifaEnvioModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getPaisListItems() {
|
||||
$paisModel = model('App\Models\Configuracion\PaisModel');
|
||||
$onlyActiveOnes = true;
|
||||
$data = $paisModel->getAllForMenu('id, nombre','nombre', $onlyActiveOnes );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getProveedores(){
|
||||
$provTipoModel = new ProveedorTipoModel();
|
||||
$provModel = new ProveedorModel();
|
||||
|
||||
$tipoId = $provTipoModel->getTipoId("Transporte");
|
||||
return $provModel->getProvList($tipoId);
|
||||
}
|
||||
|
||||
}
|
||||
438
ci4/app/Controllers/Tarifas/Tarifasenviosprecios.php
Normal file
438
ci4/app/Controllers/Tarifas/Tarifasenviosprecios.php
Normal file
@ -0,0 +1,438 @@
|
||||
<?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;
|
||||
|
||||
use
|
||||
DataTables\Editor,
|
||||
DataTables\Editor\Field;
|
||||
|
||||
class Tarifasenviosprecios 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;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnviosPrecios.tarifaEnvioPrecio')]),
|
||||
'tarifaEnvioPrecioEntity' => new TarifaEnvioPrecioEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewTarifaEnvioPrecioList', $viewData);
|
||||
}
|
||||
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]).'.';
|
||||
$message .= anchor( "admin/tarifasenviosprecios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioPrecioEntity'] = isset($sanitizedData) ? new TarifaEnvioPrecioEntity($sanitizedData) : new TarifaEnvioPrecioEntity();
|
||||
$this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioPrecioEntity->tarifa_envio_id ?? null);
|
||||
$this->viewData['proveedorList'] = $this->getProveedorListItems($tarifaEnvioPrecioEntity->proveedor_id ?? null);
|
||||
$this->viewData['tipoEnvioList'] = $this->getTipoEnvioOptions();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTarifaEnvioPrecio');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnviosPrecios.moduleTitle').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tarifaEnvioPrecioEntity = $this->model->find($id);
|
||||
|
||||
if ($tarifaEnvioPrecioEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tarifaEnvioPrecioEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tarifaEnvioPrecioEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnviosPrecios.tarifaEnvioPrecio'))]).'.';
|
||||
$message .= anchor( "admin/tarifasenviosprecios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioPrecioEntity'] = $tarifaEnvioPrecioEntity;
|
||||
$this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioPrecioEntity->tarifa_envio_id ?? null);
|
||||
$this->viewData['proveedorList'] = $this->getProveedorListItems($tarifaEnvioPrecioEntity->proveedor_id ?? null);
|
||||
$this->viewData['tipoEnvioList'] = $this->getTipoEnvioOptions();
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTarifaEnvioPrecio', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnviosPrecios.moduleTitle').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
public function datatable_editor()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
|
||||
|
||||
// Build our Editor instance and process the data coming from _POST
|
||||
$response = Editor::inst($db, 'tarifas_envios_precios')
|
||||
->fields(
|
||||
Field::inst('tipo_envio')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.tipo_envio.required'))
|
||||
),
|
||||
Field::inst('peso_min')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.peso_min.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.peso_min.decimal'))
|
||||
),
|
||||
Field::inst('peso_max')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.peso_max.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.peso_max.decimal'))
|
||||
),
|
||||
Field::inst('precio')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio.decimal'))
|
||||
),
|
||||
Field::inst('precio_adicional')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio_adicional.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosPrecios.validation.precio_adicional.decimal'))
|
||||
),
|
||||
Field::inst('zona_envio_id'),
|
||||
Field::inst('proveedor_id'),
|
||||
Field::inst('user_created_id'),
|
||||
Field::inst('created_at'),
|
||||
Field::inst('user_updated_id'),
|
||||
Field::inst('updated_at'),
|
||||
Field::inst('is_deleted'),
|
||||
Field::inst('deleted_at'),
|
||||
|
||||
)
|
||||
->validator(function ($editor, $action, $data) {
|
||||
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
||||
foreach ($data['data'] as $pkey => $values) {
|
||||
// Si no se quiere borrar...
|
||||
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
||||
$process_data['peso_min'] = $data['data'][$pkey]['peso_min'];
|
||||
$process_data['peso_max'] = $data['data'][$pkey]['peso_max'];
|
||||
$process_data['proveedor_id'] = $data['data'][$pkey]['proveedor_id'];
|
||||
$process_data['tipo_envio'] = $data['data'][$pkey]['tipo_envio'];
|
||||
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['zona_envio_id']);
|
||||
// No se pueden duplicar valores al crear o al editar
|
||||
if (!empty($response)) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
->on('preCreate', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_created_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('created_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->on('preEdit', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_updated_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('updated_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->debug(true)
|
||||
->process($_POST)
|
||||
->data();
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$response[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
|
||||
return $response;
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
||||
$order = TarifaEnvioPrecioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$zona_envio_id = $reqData['zona_envio_id'] ?? -1;
|
||||
|
||||
$resourceData = $this->model->getResource($search, $zona_envio_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search, $zona_envio_id)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', tarifa_envio_id', 'tarifa_envio_id', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->tarifa_envio_id = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_envio_id'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getTarifaEnvioListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))])];
|
||||
if (!empty($selId)) :
|
||||
$tarifaEnvioModel = model('App\Models\Tarifas\TarifaEnvioModel');
|
||||
|
||||
$selOption = $tarifaEnvioModel->where('id', $selId)->findColumn('id');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getProveedorListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('LgProveedores.proveedor'))])];
|
||||
if (!empty($selId)) :
|
||||
$proveedorModel = model('App\Models\compras\ProveedorModel');
|
||||
|
||||
$selOption = $proveedorModel->where('id', $selId)->findColumn('id');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getTipoEnvioOptions() {
|
||||
$tipoEnvioOptions = [
|
||||
'' => lang('Basic.global.pleaseSelect'),
|
||||
'a domicilio' => 'a domicilio',
|
||||
'cajas' => 'cajas',
|
||||
'palets' => 'palets',
|
||||
];
|
||||
return $tipoEnvioOptions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
425
ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
Normal file
425
ci4/app/Controllers/Tarifas/Tarifasenvioszonas.php
Normal file
@ -0,0 +1,425 @@
|
||||
<?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;
|
||||
use App\Models\Tarifas\TarifaEnvioPrecioModel;
|
||||
|
||||
use
|
||||
DataTables\Editor,
|
||||
|
||||
DataTables\Editor\Validate,
|
||||
DataTables\Editor\Field;
|
||||
|
||||
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;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifasEnviosZonas.tarifaEnvioZona')]),
|
||||
'tarifaEnvioZonaEntity' => new TarifaEnvioZonaEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewTarifaEnvioZonaList', $viewData);
|
||||
}
|
||||
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]).'.';
|
||||
$message .= anchor( "admin/tarifasenvioszonas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioZonaEntity'] = isset($sanitizedData) ? new TarifaEnvioZonaEntity($sanitizedData) : new TarifaEnvioZonaEntity();
|
||||
$this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioZonaEntity->tarifa_envio_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTarifaEnvioZona');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifasEnviosZonas.moduleTitle').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tarifaEnvioZonaEntity = $this->model->find($id);
|
||||
|
||||
if ($tarifaEnvioZonaEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona')), $id]);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tarifaEnvioZonaEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tarifaEnvioZonaEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnviosZonas.tarifaEnvioZona'))]).'.';
|
||||
$message .= anchor( "admin/tarifasenvioszonas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifaEnvioZonaEntity'] = $tarifaEnvioZonaEntity;
|
||||
$this->viewData['tarifaEnvioList'] = $this->getTarifaEnvioListItems($tarifaEnvioZonaEntity->tarifa_envio_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTarifaEnvioZona', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnviosZonas.moduleTitle').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
|
||||
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
|
||||
} else {
|
||||
$objName = lang('Basic.global.record');
|
||||
}
|
||||
|
||||
if (!$this->soft_delete){
|
||||
|
||||
if (!$this->model->delete($id)) {
|
||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||
}
|
||||
}
|
||||
else{
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
|
||||
$precioModel = new TarifaEnvioPrecioModel();
|
||||
$precioResult = $precioModel->removeAllPrecioLineas($id, $datetime, $this->delete_flag);
|
||||
|
||||
$rawResult = $this->model->where('id',$id)
|
||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||
'is_deleted' => $this->delete_flag])
|
||||
->update();
|
||||
|
||||
if (!$rawResult && !$precioResult) {
|
||||
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
|
||||
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
|
||||
$response = $this->respondDeleted(['id' => $id, 'msg' => $message]);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function datatable_editor()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
|
||||
|
||||
// Build our Editor instance and process the data coming from _POST
|
||||
$response = Editor::inst($db, 'tarifas_envios_zonas')
|
||||
->fields(
|
||||
Field::inst('cp_inicial')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required'))
|
||||
)
|
||||
->validator(Validate::maxLen(10), array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.max_length'))
|
||||
),
|
||||
Field::inst('cp_final')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.required'))
|
||||
)
|
||||
->validator(Validate::maxLen(10), array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.max_length'))
|
||||
),
|
||||
Field::inst('importe_fijo')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.integer'))
|
||||
),
|
||||
Field::inst('tarifa_envio_id'),
|
||||
Field::inst('user_created_id'),
|
||||
Field::inst('created_at'),
|
||||
Field::inst('user_updated_id'),
|
||||
Field::inst('updated_at'),
|
||||
Field::inst('is_deleted'),
|
||||
Field::inst('deleted_at'),
|
||||
|
||||
)
|
||||
->validator(function ($editor, $action, $data) {
|
||||
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
||||
foreach ($data['data'] as $pkey => $values) {
|
||||
// Si no se quiere borrar...
|
||||
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
||||
/*Los CP son string... consultar si checkear*/
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
->on('preCreate', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_created_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('created_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->on('preEdit', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_updated_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('updated_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->debug(true)
|
||||
->process($_POST)
|
||||
->data();
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$response[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$reqData = $this->request->getPost();
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
|
||||
return $response;
|
||||
}
|
||||
$start = $reqData['start'] ?? 0;
|
||||
$length = $reqData['length'] ?? 5;
|
||||
$search = $reqData['search']['value'];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
||||
$order = TarifaEnvioZonaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$tarifa_envio_id = $reqData['tarifa_envio_id'] ?? -1;
|
||||
|
||||
$resourceData = $this->model->getResource($search, $tarifa_envio_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search, $tarifa_envio_id)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', tarifa_envio_id', 'tarifa_envio_id', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->tarifa_envio_id = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_envio_id'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getTarifaEnvioListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))])];
|
||||
if (!empty($selId)) :
|
||||
$tarifaEnvioModel = model('App\Models\Tarifas\TarifaEnvioModel');
|
||||
|
||||
$selOption = $tarifaEnvioModel->where('id', $selId)->findColumn('id');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,
|
||||
"importe_fijo" => 0,
|
||||
"user_created_id" => 0,
|
||||
"user_updated_id" => 0,
|
||||
"is_deleted" => 0,
|
||||
"created_at" => null,
|
||||
"updated_at" => null,
|
||||
];
|
||||
protected $casts = [
|
||||
"tarifa_envio_id" => "int",
|
||||
"importe_fijo" => "int",
|
||||
"user_created_id" => "int",
|
||||
"user_updated_id" => "int",
|
||||
"is_deleted" => "int",
|
||||
];
|
||||
}
|
||||
@ -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.',
|
||||
|
||||
30
ci4/app/Language/en/TarifasEnvios.php
Normal file
30
ci4/app/Language/en/TarifasEnvios.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Shipping Rates',
|
||||
'nombre' => 'Name',
|
||||
'paisId' => 'Country',
|
||||
'tarifaEnvio' => 'Shipping Rate',
|
||||
'tarifaEnvioList' => 'Shipping Rate List',
|
||||
'tarifasenvios' => 'Shipping Rates',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'nombre' => [
|
||||
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
|
||||
'required' => 'The {field} field is required.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
65
ci4/app/Language/en/TarifasEnviosPrecios.php
Normal file
65
ci4/app/Language/en/TarifasEnviosPrecios.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'aDomicilio' => 'Home delivery',
|
||||
'cajas' => 'Boxes',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Weights and Costs',
|
||||
'palets' => 'Pallets',
|
||||
'pesoMax' => 'Max Weight',
|
||||
'pesoMin' => 'Min Weight',
|
||||
'precio' => 'Price',
|
||||
'precioAdicional' => 'Additional Price',
|
||||
'proveedorId' => 'Provider',
|
||||
'tarifaEnvioId' => 'Shipping Rate',
|
||||
'tarifaEnvioPrecio' => 'Weight and Cost',
|
||||
'tarifaEnvioPrecioList' => 'Weights and Costs List',
|
||||
'tarifasenviosprecios' => 'Weights and Costs',
|
||||
'tipoEnvio' => 'Shipping type',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'error_seleccion_zonas' => 'A line from the zones table must be selected before creating a new record.',
|
||||
'error_precio_overlap' => 'The range [Min Weight, Max Weight] is overlapped with another one for the selected provider and type.',
|
||||
'error_precio_range' => 'The field Min Weight must be lower than the field Max Weight',
|
||||
'peso_max' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'peso_min' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'precio' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'precio_adicional' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'tipo_envio' => [
|
||||
'in_list' => 'The field must be one of the are included in the list.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
45
ci4/app/Language/en/TarifasEnviosZonas.php
Normal file
45
ci4/app/Language/en/TarifasEnviosZonas.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'cpFinal' => 'Final Postcode',
|
||||
'cpInicial' => 'Initial Postcode',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'importeFijo' => 'Fixed cost',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Zones',
|
||||
'tarifaEnvioId' => 'Shipping Rate',
|
||||
'tarifaEnvioZona' => 'Zone and cost',
|
||||
'tarifaEnvioZonaList' => 'Zones List',
|
||||
'tarifasEnviosZonas' => 'Zones Zonas',
|
||||
'tarifasenvioszonas' => 'Zones Zonas',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'cp_final' => [
|
||||
'max_length' => 'The field cannot exceed 10 characters in length.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'cp_inicial' => [
|
||||
'max_length' => 'The field cannot exceed 10 characters in length.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'importe_fijo' => [
|
||||
'integer' => 'The field must contain an integer.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
@ -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.',
|
||||
|
||||
30
ci4/app/Language/es/TarifasEnvios.php
Normal file
30
ci4/app/Language/es/TarifasEnvios.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Tarifas Envíos',
|
||||
'nombre' => 'Nombre',
|
||||
'paisId' => 'Pais',
|
||||
'tarifaEnvio' => 'Tarifa Envío',
|
||||
'tarifaEnvioList' => 'Lista Tarifas Envío',
|
||||
'tarifasenvios' => 'Tarifa Envío',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'nombre' => [
|
||||
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
||||
'required' => 'El campo {field} es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
65
ci4/app/Language/es/TarifasEnviosPrecios.php
Normal file
65
ci4/app/Language/es/TarifasEnviosPrecios.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'aDomicilio' => 'A domicilio',
|
||||
'cajas' => 'Cajas',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Pesos y Precios',
|
||||
'palets' => 'Palets',
|
||||
'pesoMax' => 'Peso Max',
|
||||
'pesoMin' => 'Peso Min',
|
||||
'precio' => 'Precio peso mín.',
|
||||
'precioAdicional' => 'Precio Kg Adicional',
|
||||
'proveedorId' => 'Proveedor',
|
||||
'tarifaEnvioId' => 'Tarifa Envío',
|
||||
'tarifaEnvioPrecio' => 'Peso y Precio',
|
||||
'tarifaEnvioPrecioList' => 'Lista Pesos y Precios',
|
||||
'tarifasenviosprecios' => 'Pesos y Precios',
|
||||
'tipoEnvio' => 'Tipo Envío',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'error_seleccion_zonas' => 'Debe seleccionar una línea de la tabla zonas antes de crear un registro nuevo.',
|
||||
'error_precio_overlap' => 'El rango [Peso Min, Peso Max] se solapa con otro existente para el proveedor y tipo seleccionado.',
|
||||
'error_precio_range' => 'El campo Peso Min debe ser menor que el campo Peso Max',
|
||||
'peso_max' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'peso_min' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'precio' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'precio_adicional' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'tipo_envio' => [
|
||||
'in_list' => 'El campo debe ser uno de la lista.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
45
ci4/app/Language/es/TarifasEnviosZonas.php
Normal file
45
ci4/app/Language/es/TarifasEnviosZonas.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'cpFinal' => 'CP Final',
|
||||
'cpInicial' => 'CP Inicial',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'importeFijo' => 'Importe Fijo',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Zonas',
|
||||
'tarifaEnvioId' => 'Tarifa Envío',
|
||||
'tarifaEnvioZona' => 'Zona',
|
||||
'tarifaEnvioZonaList' => 'Lista de Zonas',
|
||||
'tarifasEnviosZonas' => 'Zonas',
|
||||
'tarifasenvioszonas' => 'Zonas',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'cp_final' => [
|
||||
'max_length' => 'El campo no puede exceder 10 caracteres en longitud.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'cp_inicial' => [
|
||||
'max_length' => 'El campo no puede exceder 10 caracteres en longitud.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'importe_fijo' => [
|
||||
'integer' => 'El campo debe contener un número.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
@ -15,7 +15,6 @@ class ProveedorModel extends \App\Models\GoBaseModel
|
||||
const SORTABLE = [
|
||||
0 => "t1.nombre",
|
||||
1 => "t2.nombre",
|
||||
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
@ -31,6 +30,7 @@ class ProveedorModel extends \App\Models\GoBaseModel
|
||||
"persona_contacto",
|
||||
"email",
|
||||
"telefono",
|
||||
"propiedades",
|
||||
"is_deleted",
|
||||
"deleted_at"
|
||||
];
|
||||
@ -155,7 +155,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp, t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono, t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais"
|
||||
"t1.id AS id, t1.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp,
|
||||
t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono,
|
||||
t1.propiedades AS propiedades, t2.nombre AS tipo, t2.id AS tipo_id, t3.nombre AS provincia, t4.nombre AS pais"
|
||||
);
|
||||
$builder->join("lg_proveedores_tipos t2", "t1.tipo_id = t2.id", "left");
|
||||
$builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left");
|
||||
@ -205,8 +207,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS value, t1.nombre AS label")
|
||||
->where("tipo_id", $tipoId);
|
||||
"t1.id AS value, t1.nombre AS label, t1.propiedades AS options")
|
||||
->where("tipo_id", $tipoId)
|
||||
->orderBy('t1.nombre', 'asc');
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
|
||||
93
ci4/app/Models/Tarifas/TarifaEnvioModel.php
Normal file
93
ci4/app/Models/Tarifas/TarifaEnvioModel.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?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","deleted_at","is_deleted"];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "nombre";
|
||||
|
||||
protected $validationRules = [
|
||||
"nombre" => [
|
||||
"label" => "TarifasEnvios.nombre",
|
||||
"rules" => "trim|required|max_length[255]",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"nombre" => [
|
||||
"max_length" => "TarifasEnvios.validation.nombre.max_length",
|
||||
"required" => "TarifasEnvios.validation.nombre.required",
|
||||
],
|
||||
];
|
||||
|
||||
public function findAllWithPaises(string $selcols = "pais_id, t1.nombre", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.nombre AS pais_id FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN lg_paises t2 ON t1.pais_id = t2.id";
|
||||
if (!is_null($limit) && intval($limit) > 0) {
|
||||
$sql .= " LIMIT " . $limit;
|
||||
}
|
||||
|
||||
if (!is_null($offset) && intval($offset) > 0) {
|
||||
$sql .= " OFFSET " . $offset;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "")
|
||||
{
|
||||
$builder = $this->db->table($this->table . " t1")->select("t1.id as id, t1.nombre AS nombre, t2.nombre AS pais_id");
|
||||
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.nombre", $search)
|
||||
->orLike("t2.id", $search)
|
||||
->orLike("t1.pais_id", $search)
|
||||
->orLike("t1.nombre", $search)
|
||||
->orLike("t2.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
}
|
||||
198
ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
Normal file
198
ci4/app/Models/Tarifas/TarifaEnvioPrecioModel.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?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 = [
|
||||
0 => "t1.proveedor",
|
||||
1 => "t1.tipo_envio",
|
||||
2 => "t1.peso_min",
|
||||
3 => "t1.peso_max",
|
||||
4 => "t1.precio",
|
||||
5 => "t1.precio_adicional"
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"tarifa_envio_id",
|
||||
"proveedor_id",
|
||||
"tipo_envio",
|
||||
"peso_min",
|
||||
"peso_max",
|
||||
"precio",
|
||||
"precio_adicional",
|
||||
"deleted_at",
|
||||
"is_deleted",
|
||||
];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioPrecioEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "tarifa_envio_id";
|
||||
|
||||
protected $validationRules = [
|
||||
"peso_max" => [
|
||||
"label" => "TarifasEnviosPrecios.pesoMax",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"peso_min" => [
|
||||
"label" => "TarifasEnviosPrecios.pesoMin",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"precio" => [
|
||||
"label" => "TarifasEnviosPrecios.precio",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"precio_adicional" => [
|
||||
"label" => "TarifasEnviosPrecios.precioAdicional",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"tipo_envio" => [
|
||||
"label" => "TarifasEnviosPrecios.tipoEnvio",
|
||||
"rules" => "required|in_list[a domicilio,cajas,palets]",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"peso_max" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.peso_max.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.peso_max.required",
|
||||
],
|
||||
"peso_min" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.peso_min.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.peso_min.required",
|
||||
],
|
||||
"precio" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.precio.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.precio.required",
|
||||
],
|
||||
"precio_adicional" => [
|
||||
"decimal" => "TarifasEnviosPrecios.validation.precio_adicional.decimal",
|
||||
"required" => "TarifasEnviosPrecios.validation.precio_adicional.required",
|
||||
],
|
||||
"tipo_envio" => [
|
||||
"in_list" => "TarifasEnviosPrecios.validation.tipo_envio.in_list",
|
||||
"required" => "TarifasEnviosPrecios.validation.tipo_envio.required",
|
||||
],
|
||||
];
|
||||
public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.id AS tarifa_envio, t3.id AS proveedor FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN lg_tarifas_envios t2 ON t1.tarifa_envio_id = t2.id LEFT JOIN lg_proveedores t3 ON t1.proveedor_id = t3.id";
|
||||
if (!is_null($limit) && intval($limit) > 0) {
|
||||
$sql .= " LIMIT " . intval($limit);
|
||||
}
|
||||
|
||||
if (!is_null($offset) && intval($offset) > 0) {
|
||||
$sql .= " OFFSET " . intval($offset);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $zona_envio_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.tipo_envio AS tipo_envio, t1.peso_min AS peso_min, t1.peso_max AS peso_max, t1.precio AS precio,
|
||||
t1.precio_adicional AS precio_adicional, t2.id AS tarifa_envio, t3.id AS proveedor_id, t3.nombre AS proveedor"
|
||||
);
|
||||
$builder->join("tarifas_envios_zonas t2", "t1.zona_envio_id = t2.id", "left");
|
||||
$builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
|
||||
$builder->where("t1.zona_envio_id", $zona_envio_id);
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.tipo_envio", $search)
|
||||
->orLike("t1.peso_min", $search)
|
||||
->orLike("t1.peso_max", $search)
|
||||
->orLike("t1.precio", $search)
|
||||
->orLike("t1.precio_adicional", $search)
|
||||
->orLike("t3.nombre", $search)
|
||||
->orLike("t1.tipo_envio", $search)
|
||||
->orLike("t1.peso_min", $search)
|
||||
->orLike("t1.peso_max", $search)
|
||||
->orLike("t1.precio", $search)
|
||||
->orLike("t1.precio_adicional", $search)
|
||||
->orLike("t3.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
|
||||
public function checkIntervals($data = [], $precio_id = null, $zona_id = null){
|
||||
|
||||
helper('general');
|
||||
|
||||
if(floatval($data["peso_min"])>= floatval($data["peso_max"])){
|
||||
return lang('TarifasEnviosPrecios.validation.error_precio_range');
|
||||
}
|
||||
|
||||
$rows = $this->db
|
||||
->table($this->table)
|
||||
->select("id, proveedor_id, tipo_envio, peso_min, peso_max")
|
||||
->where("is_deleted", 0)
|
||||
->where("zona_envio_id", $zona_id)
|
||||
->get()->getResultObject();
|
||||
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (!is_null($precio_id)){
|
||||
if($row->id == $precio_id){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if($row->proveedor_id == $data["proveedor_id"] && $row->tipo_envio == $data["tipo_envio"]){
|
||||
if(check_overlap(floatval($data["peso_min"]), floatval($data["peso_max"]),
|
||||
$row->peso_min, $row->peso_max)){
|
||||
return lang('TarifasEnviosPrecios.validation.error_precio_overlap');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public function removeAllPrecioLineas($zona_id = -1, $datetime = null, $delete_flag=1){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table)
|
||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||
'is_deleted' => $delete_flag])
|
||||
->where('zona_envio_id',$zona_id)
|
||||
->update();
|
||||
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
116
ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
Normal file
116
ci4/app/Models/Tarifas/TarifaEnvioZonaModel.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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 = [
|
||||
0 => "t1.cp_inicial",
|
||||
1 => "t1.cp_final",
|
||||
2 => "t1.importe_fijo",
|
||||
];
|
||||
|
||||
protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo", "is_deleted", "deleted_at"];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "tarifa_envio_id";
|
||||
|
||||
protected $validationRules = [
|
||||
"cp_final" => [
|
||||
"label" => "TarifasEnviosZonas.cpFinal",
|
||||
"rules" => "trim|required|max_length[10]",
|
||||
],
|
||||
"cp_inicial" => [
|
||||
"label" => "TarifasEnviosZonas.cpInicial",
|
||||
"rules" => "trim|required|max_length[10]",
|
||||
],
|
||||
"importe_fijo" => [
|
||||
"label" => "TarifasEnviosZonas.importeFijo",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"cp_final" => [
|
||||
"max_length" => "TarifasEnviosZonas.validation.cp_final.max_length",
|
||||
"required" => "TarifasEnviosZonas.validation.cp_final.required",
|
||||
],
|
||||
"cp_inicial" => [
|
||||
"max_length" => "TarifasEnviosZonas.validation.cp_inicial.max_length",
|
||||
"required" => "TarifasEnviosZonas.validation.cp_inicial.required",
|
||||
],
|
||||
"importe_fijo" => [
|
||||
"integer" => "TarifasEnviosZonas.validation.importe_fijo.integer",
|
||||
"required" => "TarifasEnviosZonas.validation.importe_fijo.required",
|
||||
],
|
||||
];
|
||||
|
||||
public function findAllWithTarifasEnvios(string $selcols = "*", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.id AS tarifa_envio FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN lg_tarifas_envios t2 ON t1.tarifa_envio_id = t2.id";
|
||||
if (!is_null($limit) && intval($limit) > 0) {
|
||||
$sql .= " LIMIT " . $limit;
|
||||
}
|
||||
|
||||
if (!is_null($offset) && intval($offset) > 0) {
|
||||
$sql .= " OFFSET " . $offset;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $tarifa_envio_id=-1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id as id, t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.importe_fijo AS importe_fijo, t2.id AS tarifa_envio"
|
||||
);
|
||||
$builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left");
|
||||
$builder->where("t1.tarifa_envio_id", $tarifa_envio_id);
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.cp_inicial", $search)
|
||||
->orLike("t1.cp_final", $search)
|
||||
->orLike("t1.importe_fijo", $search)
|
||||
->orLike("t1.cp_inicial", $search)
|
||||
->orLike("t1.cp_final", $search)
|
||||
->orLike("t1.importe_fijo", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
}
|
||||
@ -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,562 @@
|
||||
<?= $this->include("themes/_commonPartialsBs/datatables") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
|
||||
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
|
||||
<?= $this->section("content") ?>
|
||||
<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="pt-4">
|
||||
<input type="submit"
|
||||
class="btn btn-primary float-start me-sm-3 me-1"
|
||||
name="save"
|
||||
value="<?= lang("Basic.global.Save") ?>"
|
||||
/>
|
||||
<?= anchor(route_to("tarifaEnvioList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start",]) ?>
|
||||
</div><!-- /.card-footer -->
|
||||
|
||||
</form>
|
||||
</div><!-- //.card -->
|
||||
</div><!--//.col -->
|
||||
|
||||
<?php if(str_contains($formAction, 'edit')): ?>
|
||||
<div class="accordion mt-3" id="accordionZonas" style="visibility:visible" >
|
||||
<div class="card accordion-item active">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip1" aria-expanded="false" aria-controls="accordionTip1">
|
||||
<h3><?= lang("TarifasEnviosZonas.moduleTitle") ?></h3>
|
||||
</button>
|
||||
|
||||
</h2>
|
||||
|
||||
<div id="accordionTip1" class="accordion-collapse collapse show" data-bs-parent="#accordionZonas">
|
||||
<div class="accordion-body">
|
||||
|
||||
<table id="tableOfZonas" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('TarifasEnviosZonas.cpInicial') ?></th>
|
||||
<th><?= lang('TarifasEnviosZonas.cpFinal') ?></th>
|
||||
<th><?= lang('TarifasEnviosZonas.importeFijo') ?></th>
|
||||
<th style="min-width:100px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- //.accordion -->
|
||||
|
||||
|
||||
<div class="accordion mt-3" id="accordionPrecios" style="visibility:visible" >
|
||||
<div class="card accordion-item active">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip2" aria-expanded="false" aria-controls="accordionTip2">
|
||||
<h3><?= lang("TarifasEnviosPrecios.moduleTitle") ?></h3>
|
||||
</button>
|
||||
|
||||
</h2>
|
||||
|
||||
<div id="accordionTip2" class="accordion-collapse collapse show" data-bs-parent="#accordionPrecios">
|
||||
<div class="accordion-body">
|
||||
|
||||
<table id="tableOfPrecios" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('TarifasEnviosPrecios.proveedorId') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.tipoEnvio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMin') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMax') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precioAdicional') ?></th>
|
||||
<th style="min-width:100px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- //.accordion -->
|
||||
<?php endif; ?>
|
||||
|
||||
</div><!--//.row -->
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
|
||||
<?php if(str_contains($formAction, 'edit')): ?>
|
||||
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Código JS para general -->
|
||||
<!------------------------------------------->
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
const url = window.location.href;
|
||||
const url_parts = url.split('/');
|
||||
var id = -1;
|
||||
if(url_parts[url_parts.length-2] == 'edit'){
|
||||
id = url_parts[url_parts.length-1];
|
||||
}
|
||||
else{
|
||||
id = -1;
|
||||
}
|
||||
|
||||
<?php if(str_contains($formAction, 'edit')): ?>
|
||||
const actionBtns = function(data) {
|
||||
return `
|
||||
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
||||
<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>
|
||||
<span class="cancel"></span>
|
||||
`;
|
||||
};
|
||||
|
||||
// Delete row
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
|
||||
if($(this).closest('table').attr('id').includes('Zonas')){
|
||||
$(".btn-remove").attr('table', "zonas");
|
||||
}
|
||||
else if($(this).closest('table').attr('id').includes('Precios')){
|
||||
$(".btn-remove").attr('table', "precios");
|
||||
}
|
||||
else{
|
||||
$(".btn-remove").attr('table', );
|
||||
}
|
||||
});
|
||||
|
||||
var selected_zona_id = -1;
|
||||
|
||||
|
||||
$(document).on('click', '.btn-remove', function(e) {
|
||||
const dataId = $(this).attr('data-id');
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
|
||||
if($(this).attr('table').includes('zonas')){
|
||||
remove_zonas(dataId, row);
|
||||
}
|
||||
else if ($(this).attr('table').includes('precios')){
|
||||
remove_precios(dataId, row);
|
||||
}
|
||||
}
|
||||
});
|
||||
<?php endif; ?>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Código JS para tableOfZonas -->
|
||||
<!------------------------------------------->
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
const lastColNr = $('#tableOfZonas').find("tr:first th").length - 1;
|
||||
|
||||
var editor = new $.fn.dataTable.Editor( {
|
||||
ajax: {
|
||||
url: "<?= route_to('editorOfTarifasEnvioZonas') ?>",
|
||||
headers: {
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||
},
|
||||
},
|
||||
table : "#tableOfZonas",
|
||||
idSrc: 'id',
|
||||
fields: [ {
|
||||
name: "cp_inicial"
|
||||
}, {
|
||||
name: "cp_final"
|
||||
}, {
|
||||
name: "importe_fijo"
|
||||
}, {
|
||||
"name": "tarifa_envio_id",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "deleted_at",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "is_deleted",
|
||||
"type": "hidden"
|
||||
},
|
||||
]
|
||||
} );
|
||||
|
||||
|
||||
editor.on( 'preSubmit', function ( e, d, type ) {
|
||||
if ( type === 'create'){
|
||||
d.data[0]['tarifa_envio_id'] = id;
|
||||
}
|
||||
else if(type === 'edit' ) {
|
||||
for (v in d.data){
|
||||
d.data[v]['tarifa_envio_id'] = id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editor.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
|
||||
yeniden(json.<?= csrf_token() ?>);
|
||||
});
|
||||
|
||||
|
||||
editor.on( 'submitSuccess', function ( e, json, data, action ) {
|
||||
|
||||
theTable.clearPipeline();
|
||||
theTable.draw();
|
||||
});
|
||||
|
||||
|
||||
var theTable = $('#tableOfZonas').DataTable( {
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
lengthMenu: [ 5, 10, 25],
|
||||
order: [[ 0, "asc" ], [ 1, "asc" ]],
|
||||
pageLength: 10,
|
||||
lengthChange: true,
|
||||
searching: false,
|
||||
paging: true,
|
||||
select: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifasEnvioZonas') ?>',
|
||||
data: {
|
||||
tarifa_envio_id: id,
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columns: [
|
||||
{ 'data': 'cp_inicial' },
|
||||
{ 'data': 'cp_final' },
|
||||
{ 'data': 'importe_fijo' },
|
||||
{
|
||||
data: actionBtns,
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr]
|
||||
},
|
||||
{"orderData": [ 0, 1 ], "targets": 0 },
|
||||
|
||||
],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||
},
|
||||
buttons: [ {
|
||||
className: 'btn btn-primary float-end me-sm-3 me-1',
|
||||
extend: "createInline",
|
||||
editor: editor,
|
||||
formOptions: {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
|
||||
}
|
||||
} ]
|
||||
} );
|
||||
|
||||
|
||||
// Activate an inline edit on click of a table cell
|
||||
$('#tableOfZonas').on( 'click', 'tbody span.edit', function (e) {
|
||||
editor.inline(
|
||||
theTable.cells(this.parentNode.parentNode, '*').nodes(),
|
||||
{
|
||||
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
|
||||
cancelTrigger: 'span.cancel',
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
|
||||
submitTrigger: 'span.edit',
|
||||
submit: 'allIfChanged'
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
// Delete row
|
||||
function remove_zonas(dataId, row){
|
||||
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenvioszonas/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable.clearPipeline();
|
||||
theTable.row($(row)).invalidate().draw();
|
||||
popSuccessAlert(data.msg ?? jqXHR.statusText);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
if(typeof jqXHR.responseJSON.messages != "undefined")
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error);
|
||||
else
|
||||
popErrorAlert(jqXHR.responseJSON.message);
|
||||
$('#confirm2delete').modal('toggle');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
theTable.on( 'select', function ( e, dt, type, indexes ) {
|
||||
if ( type === 'row' ) {
|
||||
selected_zona_id = parseInt(theTable.rows( indexes ).data().pluck( 'id' )[0]);
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
}
|
||||
} );
|
||||
|
||||
theTable.on( 'deselect', function ( e, dt, type, indexes ) {
|
||||
if ( theTable.rows( '.selected' ).count() == 0 ) {
|
||||
selected_zona_id = -1;
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
}
|
||||
} );
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Código JS para tableOfPrecios -->
|
||||
<!------------------------------------------->
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
|
||||
|
||||
var editor2 = new $.fn.dataTable.Editor( {
|
||||
ajax: {
|
||||
url: "<?= route_to('editorOfTarifasEnvioPrecios') ?>",
|
||||
headers: {
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||
},
|
||||
},
|
||||
table : "#tableOfPrecios",
|
||||
idSrc: 'id',
|
||||
fields: [
|
||||
{
|
||||
"name": "proveedor_id",
|
||||
"type": "select"
|
||||
}, {
|
||||
name: "tipo_envio",
|
||||
"type": "select"
|
||||
}, {
|
||||
name: "peso_min"
|
||||
}, {
|
||||
name: "peso_max"
|
||||
}, {
|
||||
name: "precio"
|
||||
}, {
|
||||
name: "precio_adicional"
|
||||
}, {
|
||||
"name": "zona_envio_id",
|
||||
"type": "hidden"
|
||||
}, {
|
||||
"name": "deleted_at",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "is_deleted",
|
||||
"type": "hidden"
|
||||
},
|
||||
]
|
||||
} );
|
||||
|
||||
// Generación de la lista de proveedores (id, nombre)
|
||||
const suppliersList = <?php echo json_encode($proveedores); ?>;
|
||||
editor2.field( 'proveedor_id' ).update( suppliersList );
|
||||
|
||||
editor2.on( 'preSubmit', function ( e, d, type ) {
|
||||
if ( type === 'create'){
|
||||
d.data[0]['zona_envio_id'] = selected_zona_id;
|
||||
}
|
||||
else if(type === 'edit' ) {
|
||||
for (v in d.data){
|
||||
d.data[v]['zona_envio_id'] = selected_zona_id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editor2.dependent('proveedor_id', function (val, data, callback, e ) {
|
||||
|
||||
var supplier = suppliersList.find(o => o.value === val);
|
||||
values = [{label:'<?= lang('TarifasEnviosPrecios.aDomicilio') ?>', value: "a domicilio"}];
|
||||
|
||||
if(supplier.options != null)
|
||||
{
|
||||
if(supplier.options.includes("cajas")){
|
||||
values.push({label:'<?= lang('TarifasEnviosPrecios.cajas') ?>', value: "cajas"});
|
||||
}
|
||||
if(supplier.options.includes("palets")){
|
||||
values.push({label:'<?= lang('TarifasEnviosPrecios.palets') ?>', value: "palets"});
|
||||
}
|
||||
}
|
||||
editor2.field( 'tipo_envio' ).update( values );
|
||||
callback(true);
|
||||
});
|
||||
|
||||
editor2.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
|
||||
yeniden(json.<?= csrf_token() ?>);
|
||||
});
|
||||
|
||||
|
||||
editor2.on( 'submitSuccess', function ( e, json, data, action ) {
|
||||
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
});
|
||||
|
||||
|
||||
var theTable2 = $('#tableOfPrecios').DataTable( {
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
lengthMenu: [ 5, 10, 25, 50, 100],
|
||||
order: [[ 0, "asc" ], [ 1, "asc" ]],
|
||||
pageLength: 25,
|
||||
lengthChange: true,
|
||||
searching: false,
|
||||
paging: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifasEnvioPrecios') ?>',
|
||||
data: function ( d ) {
|
||||
d.zona_envio_id = selected_zona_id;
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columns: [
|
||||
{'data': 'proveedor_id',
|
||||
render: function(data, type, row, meta) {
|
||||
var value = suppliersList.find(element => element.value === data);
|
||||
return value['label'];
|
||||
},
|
||||
},
|
||||
{ 'data': 'tipo_envio', "render": function ( data, type, row, meta ) {
|
||||
if(data=='a domicilio')
|
||||
return '<?= lang('TarifasEnviosPrecios.aDomicilio') ?>';
|
||||
else if (data=='cajas')
|
||||
return '<?= lang('TarifasEnviosPrecios.cajas') ?>';
|
||||
else if (data=='palets')
|
||||
return '<?= lang('TarifasEnviosPrecios.palets') ?>';
|
||||
}
|
||||
},
|
||||
{ 'data': 'peso_min' },
|
||||
{ 'data': 'peso_max' },
|
||||
{ 'data': 'precio' },
|
||||
{ 'data': 'precio_adicional' },
|
||||
{
|
||||
data: actionBtns,
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr2]
|
||||
},
|
||||
{"orderData": [ 0, 1 ], "targets": 0 },
|
||||
|
||||
],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||
},
|
||||
buttons: [ {
|
||||
className: 'btn btn-primary float-end me-sm-3 me-1',
|
||||
extend: "createInline",
|
||||
editor: editor2,
|
||||
formOptions: {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
|
||||
},
|
||||
action: function ( e, dt, node, config ) {
|
||||
if(selected_zona_id == -1){
|
||||
popErrorAlert("<?= lang('TarifasEnviosPrecios.validation.error_seleccion_zonas') ?>");
|
||||
}
|
||||
else{
|
||||
formOptions= {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
|
||||
};
|
||||
editor2.inlineCreate(config.position, formOptions);
|
||||
}
|
||||
},
|
||||
} ],
|
||||
|
||||
} );
|
||||
|
||||
|
||||
// Activate an inline edit on click of a table cell
|
||||
$('#tableOfPrecios').on( 'click', 'tbody span.edit', function (e) {
|
||||
editor.inline(
|
||||
theTable2.cells(this.parentNode.parentNode, '*').nodes(),
|
||||
{
|
||||
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
|
||||
cancelTrigger: 'span.cancel',
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
|
||||
submitTrigger: 'span.edit',
|
||||
submit: 'allIfChanged'
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
// Delete row
|
||||
function remove_precios(dataId, row){
|
||||
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenviosprecios/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable2.clearPipeline();
|
||||
theTable2.row($(row)).invalidate().draw();
|
||||
popSuccessAlert(data.msg ?? jqXHR.statusText);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
});
|
||||
}
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?=$this->section('css') ?>
|
||||
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/sk-datatables.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.bootstrap5.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/select/1.7.0/js/dataTables.select.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>
|
||||
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.js') ?>"></script>
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
@ -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: 25,
|
||||
lengthChange: true,
|
||||
"dom": 'lfBrtip',
|
||||
"buttons": [
|
||||
'copy', 'csv', 'excel', 'print', {
|
||||
extend: 'pdfHtml5',
|
||||
orientation: 'landscape',
|
||||
pageSize: 'A4'
|
||||
}
|
||||
],
|
||||
stateSave: true,
|
||||
order: [[0, 'asc']],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||
},
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfTarifaEnvio') ?>',
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr]
|
||||
}
|
||||
],
|
||||
columns : [
|
||||
{ 'data': 'nombre' },
|
||||
{ 'data': 'pais_id' },
|
||||
{ 'data': actionBtns }
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
$(document).on('click', '.btn-edit', function(e) {
|
||||
|
||||
window.location.href = `/tarifas/tarifasenvios/edit/${$(this).attr('data-id')}`;
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-remove', function(e) {
|
||||
const dataId = $(this).attr('data-id');
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenvios/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable.clearPipeline();
|
||||
theTable.row($(row)).invalidate().draw();
|
||||
popSuccessAlert(data.msg ?? jqXHR.statusText);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?=$this->section('css') ?>
|
||||
<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