terminado tarifas envio

This commit is contained in:
Jaime Jimenez
2023-08-31 11:21:04 +02:00
parent 227441583f
commit 370fd7289f
11 changed files with 178 additions and 42 deletions

View File

@ -401,7 +401,7 @@ $routes->group('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas'], func
$routes->post('add', 'Tarifasenvios::add', ['as' => 'createTarifaEnvio']); $routes->post('add', 'Tarifasenvios::add', ['as' => 'createTarifaEnvio']);
$routes->post('create', 'Tarifasenvios::create', ['as' => 'ajaxCreateTarifaEnvio']); $routes->post('create', 'Tarifasenvios::create', ['as' => 'ajaxCreateTarifaEnvio']);
$routes->put('(:num)/update', 'Tarifasenvios::update/$1', ['as' => 'ajaxUpdateTarifaEnvio']); $routes->put('(:num)/update', 'Tarifasenvios::update/$1', ['as' => 'ajaxUpdateTarifaEnvio']);
$routes->post('(:num)/edit', 'Tarifasenvios::edit/$1', ['as' => 'updateTarifaEnvio']); $routes->post('edit/(:num)', 'Tarifasenvios::edit/$1', ['as' => 'updateTarifaEnvio']);
$routes->post('datatable', 'Tarifasenvios::datatable', ['as' => 'dataTableOfTarifaEnvio']); $routes->post('datatable', 'Tarifasenvios::datatable', ['as' => 'dataTableOfTarifaEnvio']);
$routes->post('allmenuitems', 'Tarifasenvios::allItemsSelect', ['as' => 'select2ItemsOfTarifaEnvio']); $routes->post('allmenuitems', 'Tarifasenvios::allItemsSelect', ['as' => 'select2ItemsOfTarifaEnvio']);
$routes->post('menuitems', 'Tarifasenvios::menuItems', ['as' => 'menuItemsOfTarifaEnvio']); $routes->post('menuitems', 'Tarifasenvios::menuItems', ['as' => 'menuItemsOfTarifaEnvio']);
@ -410,10 +410,10 @@ $routes->resource('tarifasenvios', ['namespace' => 'App\Controllers\Tarifas', '
$routes->group('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { $routes->group('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
$routes->post('datatable', 'Tarifasenvioserecios::datatable', ['as' => 'dataTableOfTarifasEnvioPrecios']); $routes->post('datatable', 'Tarifasenviosprecios::datatable', ['as' => 'dataTableOfTarifasEnvioPrecios']);
$routes->post('datatable_editor', 'Tarifasenvioserecios::datatable_editor', ['as' => 'editorOfTarifasEnvioPrecios']); $routes->post('datatable_editor', 'Tarifasenviosprecios::datatable_editor', ['as' => 'editorOfTarifasEnvioPrecios']);
}); });
$routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenvioserecios', 'except' => 'show,new,create,update']); $routes->resource('tarifasenviosprecios', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifasenviosprecios', 'except' => 'show,new,create,update']);
$routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { $routes->group('tarifasenvioszonas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {

View File

@ -191,12 +191,12 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
$tarifaEnvioEntity->fill($sanitizedData); $tarifaEnvioEntity->fill($sanitizedData);
$thenRedirect = true; $thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaEnvioEntity->id ?? $id; $id = $tarifaEnvioEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.'; $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifasEnvios.tarifaEnvio'))]).'.';
$message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?'); //$message .= anchor( "admin/tarifasenvios/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message)); $message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
@ -215,7 +215,7 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
$this->viewData['tarifaEnvioEntity'] = $tarifaEnvioEntity; $this->viewData['tarifaEnvioEntity'] = $tarifaEnvioEntity;
$this->viewData['paisList'] = $this->getPaisListItems(); $this->viewData['paisList'] = $this->getPaisListItems();
$this->viewData['formAction'] = route_to('updateTarifaEnvio', $id); $this->viewData['formAction'] = route_to('updateTarifaEnvio', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifasEnvios.moduleTitle').' '.lang('Basic.global.edit3');
@ -238,8 +238,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5; $length = $reqData['length'] ?? 5;
$search = $reqData['search']['value']; $search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1; $requestedOrder = $reqData['order']['0']['column'] ?? 0;
$order = TarifaEnvioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; $order = TarifaEnvioModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();

View File

@ -17,7 +17,7 @@ use
DataTables\Editor, DataTables\Editor,
DataTables\Editor\Field; DataTables\Editor\Field;
class Tarifasenvioserecios extends \App\Controllers\GoBaseResourceController { class Tarifasenviosprecios extends \App\Controllers\GoBaseResourceController {
protected $modelName = TarifaEnvioPrecioModel::class; protected $modelName = TarifaEnvioPrecioModel::class;
protected $format = 'json'; protected $format = 'json';
@ -268,7 +268,15 @@ class Tarifasenvioserecios extends \App\Controllers\GoBaseResourceController {
foreach ($data['data'] as $pkey => $values) { foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar... // Si no se quiere borrar...
if ($data['data'][$pkey]['is_deleted'] != 1) { if ($data['data'][$pkey]['is_deleted'] != 1) {
/*Los CP son string... consultar si checkear*/ $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;
}
} }
} }
} }
@ -325,12 +333,14 @@ class Tarifasenvioserecios extends \App\Controllers\GoBaseResourceController {
$order = TarifaEnvioPrecioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; $order = TarifaEnvioPrecioModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $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( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
$this->model->getResource()->countAllResults(), $this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults() $this->model->getResource($search, $zona_envio_id)->countAllResults()
)); ));
} else { } else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);

View File

@ -10,6 +10,7 @@ use App\Entities\Tarifas\TarifaEnvioZonaEntity;
use App\Models\Tarifas\TarifaEnvioModel; use App\Models\Tarifas\TarifaEnvioModel;
use App\Models\Tarifas\TarifaEnvioZonaModel; use App\Models\Tarifas\TarifaEnvioZonaModel;
use App\Models\Tarifas\TarifaEnvioPrecioModel;
use use
DataTables\Editor, DataTables\Editor,
@ -208,6 +209,43 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
} // end function edit(...) } // 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() public function datatable_editor()
{ {
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
@ -308,12 +346,14 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
$order = TarifaEnvioZonaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; $order = TarifaEnvioZonaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $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( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
$this->model->getResource()->countAllResults(), $this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults() $this->model->getResource($search, $tarifa_envio_id)->countAllResults()
)); ));
} else { } else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);

View File

@ -3,7 +3,7 @@
return [ return [
'a domicilio' => 'Home delivery', 'aDomicilio' => 'Home delivery',
'cajas' => 'Boxes', 'cajas' => 'Boxes',
'createdAt' => 'Created At', 'createdAt' => 'Created At',
'deletedAt' => 'Deleted At', 'deletedAt' => 'Deleted At',
@ -26,6 +26,8 @@ return [
'userUpdatedId' => 'User Updated ID', 'userUpdatedId' => 'User Updated ID',
'validation' => [ 'validation' => [
'error_seleccion_zonas' => 'A line from the zones table must be selected before creating a new record.', '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' => [ 'peso_max' => [
'decimal' => 'The field must contain a decimal number.', 'decimal' => 'The field must contain a decimal number.',
'required' => 'The field is required.', 'required' => 'The field is required.',

View File

@ -3,7 +3,7 @@
return [ return [
'a domicilio' => 'A domicilio', 'aDomicilio' => 'A domicilio',
'cajas' => 'Cajas', 'cajas' => 'Cajas',
'createdAt' => 'Created At', 'createdAt' => 'Created At',
'deletedAt' => 'Deleted At', 'deletedAt' => 'Deleted At',
@ -26,6 +26,8 @@ return [
'userUpdatedId' => 'User Updated ID', 'userUpdatedId' => 'User Updated ID',
'validation' => [ 'validation' => [
'error_seleccion_zonas' => 'Debe seleccionar una línea de la tabla zonas antes de crear un registro nuevo.', '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' => [ 'peso_max' => [
'decimal' => 'El campo debe contener un número decimal.', 'decimal' => 'El campo debe contener un número decimal.',
'required' => 'El campo es obligatorio.', 'required' => 'El campo es obligatorio.',

View File

@ -207,8 +207,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
$builder = $this->db $builder = $this->db
->table($this->table . " t1") ->table($this->table . " t1")
->select( ->select(
"t1.id AS value, t1.nombre AS label") "t1.id AS value, t1.nombre AS label, t1.propiedades AS options")
->where("tipo_id", $tipoId); ->where("tipo_id", $tipoId)
->orderBy('t1.nombre', 'asc');
return $builder->get()->getResultObject(); return $builder->get()->getResultObject();
} }

View File

@ -116,7 +116,7 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
* *
* @return \CodeIgniter\Database\BaseBuilder * @return \CodeIgniter\Database\BaseBuilder
*/ */
public function getResource(string $search = "") public function getResource(string $search = "", $zona_envio_id = -1)
{ {
$builder = $this->db $builder = $this->db
->table($this->table . " t1") ->table($this->table . " t1")
@ -126,6 +126,7 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
); );
$builder->join("tarifas_envios_zonas t2", "t1.zona_envio_id = t2.id", "left"); $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->join("lg_proveedores t3", "t1.proveedor_id = t3.id", "left");
$builder->where("t1.zona_envio_id", $zona_envio_id);
//JJO //JJO
$builder->where("t1.is_deleted", 0); $builder->where("t1.is_deleted", 0);
@ -148,4 +149,50 @@ class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
->orLike("t3.nombre", $search) ->orLike("t3.nombre", $search)
->groupEnd(); ->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;
}
} }

View File

@ -18,7 +18,7 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
2 => "t1.importe_fijo", 2 => "t1.importe_fijo",
]; ];
protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo"]; protected $allowedFields = ["tarifa_envio_id", "cp_inicial", "cp_final", "importe_fijo", "is_deleted", "deleted_at"];
protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity"; protected $returnType = "App\Entities\Tarifas\TarifaEnvioZonaEntity";
protected $useTimestamps = true; protected $useTimestamps = true;
@ -88,14 +88,15 @@ class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
* *
* @return \CodeIgniter\Database\BaseBuilder * @return \CodeIgniter\Database\BaseBuilder
*/ */
public function getResource(string $search = "") public function getResource(string $search = "", $tarifa_envio_id=-1)
{ {
$builder = $this->db $builder = $this->db
->table($this->table . " t1") ->table($this->table . " t1")
->select( ->select(
"t1.cp_inicial AS cp_inicial, t1.cp_final AS cp_final, t1.importe_fijo AS importe_fijo, t2.id AS tarifa_envio" "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->join("lg_tarifas_envios t2", "t1.tarifa_envio_id = t2.id", "left");
$builder->where("t1.tarifa_envio_id", $tarifa_envio_id);
//JJO //JJO
$builder->where("t1.is_deleted", 0); $builder->where("t1.is_deleted", 0);

View File

@ -48,7 +48,7 @@
<th><?= lang('TarifasEnviosZonas.cpInicial') ?></th> <th><?= lang('TarifasEnviosZonas.cpInicial') ?></th>
<th><?= lang('TarifasEnviosZonas.cpFinal') ?></th> <th><?= lang('TarifasEnviosZonas.cpFinal') ?></th>
<th><?= lang('TarifasEnviosZonas.importeFijo') ?></th> <th><?= lang('TarifasEnviosZonas.importeFijo') ?></th>
<th></th> <th style="min-width:100px"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -81,7 +81,7 @@
<th><?= lang('TarifasEnviosPrecios.pesoMax') ?></th> <th><?= lang('TarifasEnviosPrecios.pesoMax') ?></th>
<th><?= lang('TarifasEnviosPrecios.precio') ?></th> <th><?= lang('TarifasEnviosPrecios.precio') ?></th>
<th><?= lang('TarifasEnviosPrecios.precioAdicional') ?></th> <th><?= lang('TarifasEnviosPrecios.precioAdicional') ?></th>
<th></th> <th style="min-width:100px"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -127,10 +127,10 @@
// Delete row // Delete row
$(document).on('click', '.btn-delete', function(e) { $(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id')); $(".btn-remove").attr('data-id', $(this).attr('data-id'));
if($(this).closest('table').attr('id').includes('zonas')){ if($(this).closest('table').attr('id').includes('Zonas')){
$(".btn-remove").attr('table', "zonas"); $(".btn-remove").attr('table', "zonas");
} }
else if($(this).closest('table').attr('id').includes('precios')){ else if($(this).closest('table').attr('id').includes('Precios')){
$(".btn-remove").attr('table', "precios"); $(".btn-remove").attr('table', "precios");
} }
else{ else{
@ -234,8 +234,8 @@
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>', dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( { ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfTarifasEnvioZonas') ?>', url: '<?= route_to('dataTableOfTarifasEnvioZonas') ?>',
data: function ( d ) { data: {
d.tarifa_envio_id = id; tarifa_envio_id: id,
}, },
method: 'POST', method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'}, headers: {'X-Requested-With': 'XMLHttpRequest'},
@ -301,7 +301,11 @@
theTable.row($(row)).invalidate().draw(); theTable.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText); popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error) if(typeof jqXHR.responseJSON.messages != "undefined")
popErrorAlert(jqXHR.responseJSON.messages.error);
else
popErrorAlert(jqXHR.responseJSON.message);
$('#confirm2delete').modal('toggle');
}); });
} }
@ -344,7 +348,8 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
"name": "proveedor_id", "name": "proveedor_id",
"type": "select" "type": "select"
}, { }, {
name: "tipo_envio" name: "tipo_envio",
"type": "select"
}, { }, {
name: "peso_min" name: "peso_min"
}, { }, {
@ -356,9 +361,6 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
}, { }, {
"name": "zona_envio_id", "name": "zona_envio_id",
"type": "hidden" "type": "hidden"
}, {
"name": "proveedor_id",
"type": "hidden"
}, { }, {
"name": "deleted_at", "name": "deleted_at",
"type": "hidden" "type": "hidden"
@ -369,7 +371,7 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
] ]
} ); } );
// Generación de la lista de proveedores (id, nombre) para encuadernación // Generación de la lista de proveedores (id, nombre)
const suppliersList = <?php echo json_encode($proveedores); ?>; const suppliersList = <?php echo json_encode($proveedores); ?>;
editor2.field( 'proveedor_id' ).update( suppliersList ); editor2.field( 'proveedor_id' ).update( suppliersList );
@ -385,6 +387,24 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
}); });
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 ) { editor2.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>); yeniden(json.<?= csrf_token() ?>);
@ -421,8 +441,21 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
async: true, async: true,
}), }),
columns: [ columns: [
{ 'data': 'proveedor' }, {'data': 'proveedor_id',
{ 'data': 'tipo_envio' }, 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_min' },
{ 'data': 'peso_max' }, { 'data': 'peso_max' },
{ 'data': 'precio' }, { 'data': 'precio' },

View File

@ -81,7 +81,7 @@
{ {
orderable: false, orderable: false,
searchable: false, searchable: false,
targets: [0,lastColNr] targets: [lastColNr]
} }
], ],
columns : [ columns : [
@ -96,7 +96,7 @@
$(document).on('click', '.btn-edit', function(e) { $(document).on('click', '.btn-edit', function(e) {
window.location.href = `/tarifas/tarifasenvios/edit/${$(this).attr('data-id')}/edit`; window.location.href = `/tarifas/tarifasenvios/edit/${$(this).attr('data-id')}`;
}); });
$(document).on('click', '.btn-delete', function(e) { $(document).on('click', '.btn-delete', function(e) {