mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
haciendo formulario de editar tarifa envio
This commit is contained in:
@ -424,16 +424,9 @@ $routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tari
|
||||
|
||||
|
||||
$routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
|
||||
/* $routes->get('', 'Tarifasenvioszonas::index', ['as' => 'tarifaEnvioZonaList']);
|
||||
$routes->get('add', 'Tarifasenvioszonas::add', ['as' => 'newTarifaEnvioZona']);
|
||||
$routes->post('add', 'Tarifasenvioszonas::add', ['as' => 'createTarifaEnvioZona']);
|
||||
$routes->post('create', 'Tarifasenvioszonas::create', ['as' => 'ajaxCreateTarifaEnvioZona']);
|
||||
$routes->put('(:num)/update', 'Tarifasenvioszonas::update/$1', ['as' => 'ajaxUpdateTarifaEnvioZona']);
|
||||
$routes->post('(:num)/edit', 'Tarifasenvioszonas::edit/$1', ['as' => 'updateTarifaEnvioZona']);
|
||||
$routes->post('datatable', 'Tarifasenvioszonas::datatable', ['as' => 'dataTableOfTarifasEnviosZonas']);
|
||||
$routes->post('allmenuitems', 'Tarifasenvioszonas::allItemsSelect', ['as' => 'select2ItemsOfTarifasEnviosZonas']);
|
||||
$routes->post('menuitems', 'Tarifasenvioszonas::menuItems', ['as' => 'menuItemsOfTarifasEnviosZonas']);
|
||||
*/});
|
||||
$routes->post('datatable', 'Tarifasenvioszonas::datatable', ['as' => 'dataTableOfTarifasEnvioZonas']);
|
||||
$routes->post('datatable_editor', 'Tarifasenvioszonas::datatable_editor', ['as' => 'editorOfTarifasEnvioZonas']);
|
||||
});
|
||||
$routes->resource('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvioszonas', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
|
||||
@ -32,6 +32,20 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('TarifasEnvios.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_tarifasenvios"), 'route' => site_url('tarifas/tarifasenvios'), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
@ -54,7 +68,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
@ -66,6 +81,10 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
@ -95,7 +114,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
return redirect()->to(site_url('tarifas/tarifasenvios/edit/' . $id))->with('sweet-success', $message);
|
||||
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
@ -119,6 +139,9 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
@ -139,9 +162,12 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_updated_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
@ -11,6 +11,10 @@ use App\Models\Tarifas\TarifaEnvioModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioZonaModel;
|
||||
|
||||
use
|
||||
DataTables\Editor,
|
||||
DataTables\Editor\Field;
|
||||
|
||||
class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaEnvioZonaModel::class;
|
||||
@ -196,6 +200,90 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
public function datatable_editor()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
|
||||
|
||||
// Build our Editor instance and process the data coming from _POST
|
||||
$response = Editor::inst($db, 'tarifas_envios_zonas')
|
||||
->fields(
|
||||
Field::inst('cp_inicial')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required'))
|
||||
)
|
||||
->validator('Validate::maxLen(10)', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.max_length'))
|
||||
),
|
||||
Field::inst('cp_final')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.required'))
|
||||
)
|
||||
->validator('Validate::maxLen(10)', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.max_length'))
|
||||
),
|
||||
Field::inst('importe_fijo')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.integer'))
|
||||
),
|
||||
Field::inst('tarifa_envio_id'),
|
||||
Field::inst('user_created_id'),
|
||||
Field::inst('created_at'),
|
||||
Field::inst('user_updated_id'),
|
||||
Field::inst('updated_at'),
|
||||
Field::inst('is_deleted'),
|
||||
Field::inst('deleted_at'),
|
||||
|
||||
)
|
||||
->validator(function ($editor, $action, $data) {
|
||||
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
||||
foreach ($data['data'] as $pkey => $values) {
|
||||
// Si no se quiere borrar...
|
||||
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
||||
/*Los CP son string... consultar si checkear*/
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
->on('preCreate', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_created_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('created_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->on('preEdit', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_updated_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('updated_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->debug(true)
|
||||
->process($_POST)
|
||||
->data();
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$response[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -10,7 +10,7 @@ class TarifaEnvioZonaEntity extends \CodeIgniter\Entity\Entity
|
||||
"tarifa_envio_id" => null,
|
||||
"cp_inicial" => null,
|
||||
"cp_final" => null,
|
||||
"inporte_fijo" => 0,
|
||||
"importe_fijo" => 0,
|
||||
"user_created_id" => 0,
|
||||
"user_updated_id" => 0,
|
||||
"is_deleted" => 0,
|
||||
@ -19,7 +19,7 @@ class TarifaEnvioZonaEntity extends \CodeIgniter\Entity\Entity
|
||||
];
|
||||
protected $casts = [
|
||||
"tarifa_envio_id" => "int",
|
||||
"inporte_fijo" => "int",
|
||||
"importe_fijo" => "int",
|
||||
"user_created_id" => "int",
|
||||
"user_updated_id" => "int",
|
||||
"is_deleted" => "int",
|
||||
|
||||
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.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
62
ci4/app/Language/en/TarifasEnviosPrecios.php
Normal file
62
ci4/app/Language/en/TarifasEnviosPrecios.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'a domicilio' => 'Home delivery',
|
||||
'cajas' => 'Boxes',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Weights and Costs',
|
||||
'palets' => 'Pallets',
|
||||
'pesoMax' => 'Max Weight',
|
||||
'pesoMin' => 'Min Weight',
|
||||
'precio' => 'Price',
|
||||
'precioAdicional' => 'Additional Price',
|
||||
'proveedorId' => 'Provider',
|
||||
'tarifaEnvioId' => 'Shipping Rate',
|
||||
'tarifaEnvioPrecio' => 'Weight and Cost',
|
||||
'tarifaEnvioPrecioList' => 'Weights and Costs List',
|
||||
'tarifasenviosprecios' => 'Weights and Costs',
|
||||
'tipoEnvio' => 'Shipping type',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'peso_max' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'peso_min' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'precio' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'precio_adicional' => [
|
||||
'decimal' => 'The field must contain a decimal number.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
'tipo_envio' => [
|
||||
'in_list' => 'The field must be one of the are included in the list.',
|
||||
'required' => 'The field is required.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
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.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
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.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
62
ci4/app/Language/es/TarifasEnviosPrecios.php
Normal file
62
ci4/app/Language/es/TarifasEnviosPrecios.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'a domicilio' => 'A domicilio',
|
||||
'cajas' => 'Cajas',
|
||||
'createdAt' => 'Created At',
|
||||
'deletedAt' => 'Deleted At',
|
||||
'id' => 'ID',
|
||||
'isDeleted' => 'Is Deleted',
|
||||
'moduleTitle' => 'Pesos y Precios',
|
||||
'palets' => 'Palets',
|
||||
'pesoMax' => 'Peso Max',
|
||||
'pesoMin' => 'Peso Min',
|
||||
'precio' => 'Precio',
|
||||
'precioAdicional' => 'Precio Adicional',
|
||||
'proveedorId' => 'Proveedor',
|
||||
'tarifaEnvioId' => 'Tarifa Envío',
|
||||
'tarifaEnvioPrecio' => 'Peso y Precio',
|
||||
'tarifaEnvioPrecioList' => 'Lista Pesos y Precios',
|
||||
'tarifasenviosprecios' => 'Pesos y Precios',
|
||||
'tipoEnvio' => 'Tipo Envío',
|
||||
'updatedAt' => 'Updated At',
|
||||
'userCreatedId' => 'User Created ID',
|
||||
'userUpdatedId' => 'User Updated ID',
|
||||
'validation' => [
|
||||
'peso_max' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'peso_min' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'precio' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'precio_adicional' => [
|
||||
'decimal' => 'El campo debe contener un número decimal.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
'tipo_envio' => [
|
||||
'in_list' => 'El campo debe ser uno de la lista.',
|
||||
'required' => 'El campo es obligatorio.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
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.',
|
||||
|
||||
],
|
||||
|
||||
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
@ -17,7 +17,7 @@ class TarifaEnvioModel extends \App\Models\GoBaseModel
|
||||
1 => "t2.nombre",
|
||||
];
|
||||
|
||||
protected $allowedFields = ["pais_id", "nombre"];
|
||||
protected $allowedFields = ["pais_id", "nombre","deleted_at","is_deleted"];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
@ -76,6 +76,9 @@ class TarifaEnvioModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db->table($this->table . " t1")->select("t1.id as id, t1.nombre AS nombre, t2.nombre AS pais_id");
|
||||
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
|
||||
@ -128,6 +128,9 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
|
||||
$builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left");
|
||||
$builder->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
|
||||
@ -16,11 +16,11 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
||||
1 => "t1.tarifa_envio_id",
|
||||
2 => "t1.cp_inicial",
|
||||
3 => "t1.cp_final",
|
||||
4 => "t1.inporte_fijo",
|
||||
4 => "t1.importe_fijo",
|
||||
5 => "t2.id",
|
||||
];
|
||||
|
||||
protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "inporte_fijo"];
|
||||
protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo"];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
@ -41,8 +41,8 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
||||
"label" => "TarifasEnviosZonas.cpInicial",
|
||||
"rules" => "trim|required|max_length[10]",
|
||||
],
|
||||
"inporte_fijo" => [
|
||||
"label" => "TarifasEnviosZonas.inporteFijo",
|
||||
"importe_fijo" => [
|
||||
"label" => "TarifasEnviosZonas.importeFijo",
|
||||
"rules" => "required|integer",
|
||||
],
|
||||
];
|
||||
@ -56,9 +56,9 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
||||
"max_length" => "TarifasEnviosZonas.validation.cp_inicial.max_length",
|
||||
"required" => "TarifasEnviosZonas.validation.cp_inicial.required",
|
||||
],
|
||||
"inporte_fijo" => [
|
||||
"integer" => "TarifasEnviosZonas.validation.inporte_fijo.integer",
|
||||
"required" => "TarifasEnviosZonas.validation.inporte_fijo.required",
|
||||
"importe_fijo" => [
|
||||
"integer" => "TarifasEnviosZonas.validation.importe_fijo.integer",
|
||||
"required" => "TarifasEnviosZonas.validation.importe_fijo.required",
|
||||
],
|
||||
];
|
||||
|
||||
@ -95,22 +95,25 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.inporte_fijo AS inporte_fijo, t2.id AS tarifa_envio"
|
||||
"t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.importe_fijo AS importe_fijo, t2.id AS tarifa_envio"
|
||||
);
|
||||
$builder->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left");
|
||||
|
||||
//JJO
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.cp_inicial", $search)
|
||||
->orLike("t1.cp_final", $search)
|
||||
->orLike("t1.inporte_fijo", $search)
|
||||
->orLike("t1.importe_fijo", $search)
|
||||
->orLike("t2.id", $search)
|
||||
->orLike("t1.tarifa_envio_id", $search)
|
||||
->orLike("t1.cp_inicial", $search)
|
||||
->orLike("t1.cp_final", $search)
|
||||
->orLike("t1.inporte_fijo", $search)
|
||||
->orLike("t1.importe_fijo", $search)
|
||||
->orLike("t2.id", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
<?= $this->include("themes/_commonPartialsBs/datatables") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
||||
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
|
||||
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
|
||||
@ -22,5 +23,290 @@
|
||||
</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></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('tiradas')){
|
||||
remove_tiradas(dataId, row);
|
||||
}
|
||||
else if ($(this).attr('table').includes('lineas')){
|
||||
remove_lineas(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: function ( d ) {
|
||||
d.tarifa_envio_id = id;
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columns: [
|
||||
{ 'data': 'cp_inicial' },
|
||||
{ 'data': 'cp_final' },
|
||||
{ 'data': 'importe_fijo' },
|
||||
{
|
||||
data: actionBtns,
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr]
|
||||
},
|
||||
{"orderData": [ 0, 1 ], "targets": 0 },
|
||||
|
||||
],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= 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_lineas(dataId, row){
|
||||
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenvioszonas/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable.clearPipeline();
|
||||
theTable.row($(row)).invalidate().draw();
|
||||
popSuccessAlert(data.msg ?? jqXHR.statusText);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
popErrorAlert(jqXHR.responseJSON.messages.error)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
theTable.on( 'select', function ( e, dt, type, indexes ) {
|
||||
if ( type === 'row' ) {
|
||||
selected_zona_id = parseInt(theTable.rows( indexes ).data().pluck( 'id' )[0]);
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
}
|
||||
} );
|
||||
|
||||
theTable.on( 'deselect', function ( e, dt, type, indexes ) {
|
||||
if ( theTable.rows( '.selected' ).count() == 0 ) {
|
||||
selected_zona_id = -1;
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
}
|
||||
} );
|
||||
<?= $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">
|
||||
|
||||
<?=$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; ?>
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
responsive: true,
|
||||
scrollX: true,
|
||||
lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
|
||||
pageLength: 10,
|
||||
pageLength: 25,
|
||||
lengthChange: true,
|
||||
"dom": 'lfBrtip',
|
||||
"buttons": [
|
||||
@ -108,7 +108,7 @@
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenvio/delete/${dataId}`,
|
||||
url: `/tarifas/tarifasenvios/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
|
||||
Reference in New Issue
Block a user