mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
finalizado datos envios
This commit is contained in:
@ -22,7 +22,50 @@ class Clientedirecciones extends \App\Controllers\GoBaseResourceController
|
|||||||
|
|
||||||
protected static $controllerSlug = 'clientedirecciones';
|
protected static $controllerSlug = 'clientedirecciones';
|
||||||
|
|
||||||
|
public function add(){
|
||||||
|
if ($this->request->isAJAX()) {
|
||||||
|
|
||||||
|
$reqData = $this->request->getPost();
|
||||||
|
$cliente_id = $reqData['cliente_id'] ?? -1;
|
||||||
|
$att = $reqData['att'] ?? "";
|
||||||
|
$email = $reqData['email'] ?? "";
|
||||||
|
$direccion = $reqData['direccion'] ?? "";
|
||||||
|
$pais_id = $reqData['paisId'] ?? -1;
|
||||||
|
$ccaa_id = $reqData['ccaaId'] ?? -1;
|
||||||
|
$provincia = $reqData['provincia'] ?? "";
|
||||||
|
$municipio = $reqData['municipio'] ?? "";
|
||||||
|
$cp = $reqData['cp'] ?? "";
|
||||||
|
$telefono = $reqData['telefono'] ?? "";
|
||||||
|
$alias = $reqData['alias'] ?? "";
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"cliente_id" => $cliente_id,
|
||||||
|
"att" => $att,
|
||||||
|
"email" => $email,
|
||||||
|
"direccion" => $direccion,
|
||||||
|
"pais_id" => $pais_id,
|
||||||
|
"ccaa_id" => $ccaa_id,
|
||||||
|
"provincia" => $provincia,
|
||||||
|
"municipio" => $municipio,
|
||||||
|
"cp" => $cp,
|
||||||
|
"telefono" => $telefono,
|
||||||
|
"alias" => $alias,
|
||||||
|
];
|
||||||
|
$response = $this->model->insert($data);
|
||||||
|
|
||||||
|
$newTokenHash = csrf_hash();
|
||||||
|
$csrfTokenName = csrf_token();
|
||||||
|
$data_ret = [
|
||||||
|
'data' => $response,
|
||||||
|
$csrfTokenName => $newTokenHash
|
||||||
|
];
|
||||||
|
return $this->respond($data_ret);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $this->failUnauthorized('Invalid request', 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function menuItems()
|
public function menuItems()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -33,6 +33,61 @@ class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function add(){
|
||||||
|
if ($this->request->isAJAX()) {
|
||||||
|
|
||||||
|
$reqData = $this->request->getPost();
|
||||||
|
$presupuesto_id = $reqData['presupuesto_id'] ?? -1;
|
||||||
|
$tarifa_id = $reqData['tarifa_id'] ?? -1;
|
||||||
|
$cantidad = $reqData['cantidad'] ?? -1;
|
||||||
|
$peso = $reqData['peso'] ?? -1;
|
||||||
|
$att = $reqData['att'] ?? "";
|
||||||
|
$email = $reqData['email'] ?? "";
|
||||||
|
$direccion = $reqData['direccion'] ?? "";
|
||||||
|
$pais_id = $reqData['paisId'] ?? -1;
|
||||||
|
$ccaa_id = $reqData['ccaaId'] ?? -1;
|
||||||
|
$provincia = $reqData['provincia'] ?? "";
|
||||||
|
$municipio = $reqData['municipio'] ?? "";
|
||||||
|
$cp = $reqData['cp'] ?? "";
|
||||||
|
$telefono = $reqData['telefono'] ?? "";
|
||||||
|
$precio = $reqData['precio'] ?? "";
|
||||||
|
$margen = $reqData['margen'] ?? "";
|
||||||
|
$proveedor = $reqData['proveedor'] ?? "";
|
||||||
|
$proveedor_id = $reqData['proveedor_id'] ?? "";
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"presupuesto_id" => $presupuesto_id,
|
||||||
|
"tarifa_id" => $tarifa_id,
|
||||||
|
"cantidad" => $cantidad,
|
||||||
|
"peso" => $peso,
|
||||||
|
"att" => $att,
|
||||||
|
"email" => $email,
|
||||||
|
"direccion" => $direccion,
|
||||||
|
"pais_id" => $pais_id,
|
||||||
|
"ccaa_id" => $ccaa_id,
|
||||||
|
"provincia" => $provincia,
|
||||||
|
"municipio" => $municipio,
|
||||||
|
"cp" => $cp,
|
||||||
|
"telefono" => $telefono,
|
||||||
|
"precio" => $precio,
|
||||||
|
"margen" => $margen,
|
||||||
|
"proveedor" => $proveedor,
|
||||||
|
"proveedor_id" => $proveedor_id,
|
||||||
|
];
|
||||||
|
$response = $this->model->insert($data);
|
||||||
|
|
||||||
|
$newTokenHash = csrf_hash();
|
||||||
|
$csrfTokenName = csrf_token();
|
||||||
|
$data_ret = [
|
||||||
|
'data' => $response,
|
||||||
|
$csrfTokenName => $newTokenHash
|
||||||
|
];
|
||||||
|
return $this->respond($data_ret);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $this->failUnauthorized('Invalid request', 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function datatable()
|
public function datatable()
|
||||||
{
|
{
|
||||||
@ -73,6 +128,11 @@ class Presupuestodirecciones extends \App\Controllers\GoBaseResourceController
|
|||||||
$model = model('App\Models\Tarifas\TarifaEnvioModel');
|
$model = model('App\Models\Tarifas\TarifaEnvioModel');
|
||||||
return $this->respond($model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio));
|
return $this->respond($model->getTarifaEnvio($paisId, $cp, $peso, $tipo_envio));
|
||||||
}
|
}
|
||||||
|
else if($reqData['tipo']=='clear_lineas'){
|
||||||
|
|
||||||
|
$presupuesto_id = $reqData['presupuesto_id'] ?? 0;
|
||||||
|
return $this->respond($this->model->where('presupuesto_id', $presupuesto_id)->delete());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
|
|||||||
{
|
{
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
"id" => null,
|
"id" => null,
|
||||||
|
"tarifa_id" => null,
|
||||||
"presupuesto_id" => null,
|
"presupuesto_id" => null,
|
||||||
"cantidad" => null,
|
"cantidad" => null,
|
||||||
"peso" => null,
|
"peso" => null,
|
||||||
@ -20,10 +21,13 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
|
|||||||
"cp" => null,
|
"cp" => null,
|
||||||
"telefono" => null,
|
"telefono" => null,
|
||||||
"precio" => null,
|
"precio" => null,
|
||||||
|
"proveedor" => null,
|
||||||
|
"proveedor_id" => null,
|
||||||
"margen" => null,
|
"margen" => null,
|
||||||
];
|
];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
"presupuesto_id" => "int",
|
"presupuesto_id" => "int",
|
||||||
|
"tarifa_id" => "int",
|
||||||
"cantidad" => "int",
|
"cantidad" => "int",
|
||||||
"peso" => "float",
|
"peso" => "float",
|
||||||
"pais_id" => "int",
|
"pais_id" => "int",
|
||||||
@ -31,6 +35,7 @@ class PresupuestoDireccionesEntity extends \CodeIgniter\Entity\Entity
|
|||||||
"cp" => "int",
|
"cp" => "int",
|
||||||
"precio" => "float",
|
"precio" => "float",
|
||||||
"margen" => "float",
|
"margen" => "float",
|
||||||
|
"proveedor_id" => "int",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,13 +14,14 @@ return [
|
|||||||
'telefono' => 'Phone',
|
'telefono' => 'Phone',
|
||||||
'peso' => 'Weight',
|
'peso' => 'Weight',
|
||||||
'cantidad' => 'Quantity',
|
'cantidad' => 'Quantity',
|
||||||
|
'proveedor' => 'Supplier',
|
||||||
'precio' => 'Price',
|
'precio' => 'Price',
|
||||||
'saveDirection' => 'Save to client addresses',
|
'saveDirection' => 'Save to client addresses',
|
||||||
'validation' => [
|
'validation' => [
|
||||||
'max_length' => 'Max. length ',
|
'max_length' => 'Max. length ',
|
||||||
'required' => 'Field required',
|
'required' => 'Field required',
|
||||||
'valid_email' => 'The email is not valid',
|
'valid_email' => 'The email is not valid',
|
||||||
|
'no_tarifa' => 'There is no rate for the indicated address'
|
||||||
],
|
],
|
||||||
|
|
||||||
'selectPais' => 'Select a country',
|
'selectPais' => 'Select a country',
|
||||||
|
|||||||
@ -16,13 +16,15 @@ return [
|
|||||||
'telefono' => 'Teléfono',
|
'telefono' => 'Teléfono',
|
||||||
'peso' => 'Peso',
|
'peso' => 'Peso',
|
||||||
'cantidad' => 'Cantidad',
|
'cantidad' => 'Cantidad',
|
||||||
'precio' => 'Precio',
|
'proveedor' => 'Proveedor',
|
||||||
|
'precio' => 'Precio',
|
||||||
'saveDirection' => 'Guardar en direcciones de cliente',
|
'saveDirection' => 'Guardar en direcciones de cliente',
|
||||||
'entregaPieCalle' => 'Entrega a pie de calle',
|
'entregaPieCalle' => 'Entrega a pie de calle',
|
||||||
'validation' => [
|
'validation' => [
|
||||||
'max_length' => 'Max. valor caracteres alcanzado',
|
'max_length' => 'Max. valor caracteres alcanzado',
|
||||||
'required' => 'Campo obligatorio',
|
'required' => 'Campo obligatorio',
|
||||||
'valid_email' => 'El email introducido no es válido',
|
'valid_email' => 'El email introducido no es válido',
|
||||||
|
'no_tarifa' => 'No hay tarifa para la dirección indicada'
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,9 +23,12 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel
|
|||||||
6 => "t1.provincia",
|
6 => "t1.provincia",
|
||||||
7 => "t2.nombre",
|
7 => "t2.nombre",
|
||||||
8 => "t1.telefono",
|
8 => "t1.telefono",
|
||||||
|
9 => "t1.precio",
|
||||||
|
10 => "t1.proveedor",
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $allowedFields = [
|
protected $allowedFields = [
|
||||||
|
"tarifa_id",
|
||||||
"presupuesto_id",
|
"presupuesto_id",
|
||||||
"cantidad",
|
"cantidad",
|
||||||
"peso",
|
"peso",
|
||||||
@ -40,6 +43,8 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel
|
|||||||
"telefono",
|
"telefono",
|
||||||
'precio',
|
'precio',
|
||||||
'margen',
|
'margen',
|
||||||
|
"proveedor_id",
|
||||||
|
"proveedor",
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity";
|
protected $returnType = "App\Entities\Clientes\ClienteDireccionesEntity";
|
||||||
@ -60,11 +65,12 @@ class PresupuestoDireccionesModel extends \App\Models\GoBaseModel
|
|||||||
$builder = $this->db
|
$builder = $this->db
|
||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
"t1.id AS id, t1.presupuesto_id AS presupuesto_id, t1.att AS att,
|
"t1.id AS id, t1.presupuesto_id AS presupuesto_id, t1.tarifa_id AS tarifa_id, t1.att AS att,
|
||||||
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t2.nombre AS pais,
|
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t2.nombre AS pais,
|
||||||
t1.ccaa_id AS ccaa_id, t3.nombre AS ccaa_nombre,
|
t1.ccaa_id AS ccaa_id, t3.nombre AS ccaa_nombre,
|
||||||
t1.municipio AS municipio, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono,
|
t1.municipio AS municipio, t1.provincia AS provincia, t1.cp AS cp, t1.telefono AS telefono,
|
||||||
t1.cantidad AS cantidad, t1.precio AS precio, t1.margen AS margen"
|
t1.peso AS peso, t1.cantidad AS cantidad, t1.precio AS precio, t1.margen AS margen,
|
||||||
|
t1.proveedor_id AS proveedor_id, t1.proveedor AS proveedor"
|
||||||
);
|
);
|
||||||
|
|
||||||
$builder->where('t1.presupuesto_id', $presupuesto_id);
|
$builder->where('t1.presupuesto_id', $presupuesto_id);
|
||||||
|
|||||||
@ -10,29 +10,34 @@
|
|||||||
<div class="accordion-body">
|
<div class="accordion-body">
|
||||||
|
|
||||||
<?= view("themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm") ?>
|
<?= view("themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm") ?>
|
||||||
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-4" style="width: 100%;">
|
<div id='rowTable' class='row'>
|
||||||
<thead>
|
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-4" style="width: 95%;">
|
||||||
<tr>
|
<thead>
|
||||||
<th><?= lang('PresupuestosDirecciones.cantidad') ?></th>
|
<tr>
|
||||||
<th><?= lang('PresupuestosDirecciones.peso') ?></th>
|
<th class="lp-header">Tarifa_id</th>
|
||||||
<th><?= lang('PresupuestosDirecciones.att') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.cantidad') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.email') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.peso') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.direccion') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.att') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.cp') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.email') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.municipio') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.direccion') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.provincia') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.cp') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.ccaa') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.municipio') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.pais') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.provincia') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.telefono') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.ccaa') ?></th>
|
||||||
<th><?= lang('PresupuestosDirecciones.precio') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.pais') ?></th>
|
||||||
<th></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.telefono') ?></th>
|
||||||
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.proveedor') ?></th>
|
||||||
</tr>
|
<th>Proveedor_id</th>
|
||||||
</thead>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.precio') ?></th>
|
||||||
<tbody>
|
<th>Margen</th>
|
||||||
|
<th class="lp-header"><?= lang('Basic.global.Action') ?></th>
|
||||||
</tbody>
|
</tr>
|
||||||
</table>
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 col-lg-4 px-4 py-2">
|
<div class="col-md-12 col-lg-4 px-4 py-2">
|
||||||
@ -41,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div id="rowInsertar" class="row">
|
||||||
<div class="col-md-12 col-lg-4 px-4 py-2">
|
<div class="col-md-12 col-lg-4 px-4 py-2">
|
||||||
<button id="insertar_direccion" type="button" class="btn btn-secondary waves-effect waves-light float-start"><?= lang("Presupuestos.insertar")?></button>
|
<button id="insertar_direccion" type="button" class="btn btn-secondary waves-effect waves-light float-start"><?= lang("Presupuestos.insertar")?></button>
|
||||||
</div>
|
</div>
|
||||||
@ -57,6 +62,7 @@
|
|||||||
<?= $this->section("additionalInlineJs") ?>
|
<?= $this->section("additionalInlineJs") ?>
|
||||||
|
|
||||||
$('#insertar_direccion').on('click', function(){
|
$('#insertar_direccion').on('click', function(){
|
||||||
|
|
||||||
$("#addressForm").attr('action','create')
|
$("#addressForm").attr('action','create')
|
||||||
var $newAddDialog = $("#addressForm")
|
var $newAddDialog = $("#addressForm")
|
||||||
var maximaCantidad = parseInt($('#tirada').val())
|
var maximaCantidad = parseInt($('#tirada').val())
|
||||||
@ -65,22 +71,54 @@ $('#insertar_direccion').on('click', function(){
|
|||||||
$("#add_cantidad").on('change', function(){
|
$("#add_cantidad").on('change', function(){
|
||||||
$("#add_cantidad").val(parseInt($("#add_cantidad").val())>maximaCantidad ? maximaCantidad : $("#add_cantidad").val())
|
$("#add_cantidad").val(parseInt($("#add_cantidad").val())>maximaCantidad ? maximaCantidad : $("#add_cantidad").val())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cantidad_total = 0
|
||||||
|
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||||
|
var data = this.data();
|
||||||
|
cantidad_total += data.cantidad
|
||||||
|
} );
|
||||||
|
$('#add_cantidad').attr('max-value', parseInt($('#tirada').val())-cantidad_total)
|
||||||
|
$('#add_cantidad').val(parseInt($('#tirada').val())-cantidad_total)
|
||||||
$newAddDialog.modal('show')
|
$newAddDialog.modal('show')
|
||||||
})
|
})
|
||||||
|
|
||||||
const lastColNr = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
|
const lastColNr_direcciones = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
|
||||||
|
|
||||||
const actionBtns_direcciones = function(data) {
|
const actionBtns_direcciones = function(data) {
|
||||||
return `
|
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 delete-add-row mx-2"></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>
|
|
||||||
<span class="cancel"></span>
|
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$(document).on('click', '.delete-add-row', function(e) {
|
||||||
|
const row = $(this).closest('tr');
|
||||||
|
tableEnvios.row( row )
|
||||||
|
.remove()
|
||||||
|
.draw();
|
||||||
|
checkInsertar()
|
||||||
|
})
|
||||||
|
|
||||||
|
const paisList = <?php echo json_encode($paisList); ?>;
|
||||||
|
const ccaaList = <?php echo json_encode($ccaaList); ?>;
|
||||||
|
|
||||||
|
|
||||||
|
$('#recoger_en_taller').change(function(){
|
||||||
|
if(this.checked) {
|
||||||
|
$('#rowTable').css('display', 'none')
|
||||||
|
$('#rowInsertar').css('display', 'none')
|
||||||
|
tableEnvios.clear().draw()
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#rowTable').css('display', 'flex')
|
||||||
|
$('#rowInsertar').css('display', 'flex')
|
||||||
|
tableEnvios.columns.adjust();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
|
var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
|
||||||
draw:5,
|
draw:5,
|
||||||
serverSide: true,
|
serverSide: false,
|
||||||
processing: true,
|
processing: true,
|
||||||
autoWidth: true,
|
autoWidth: true,
|
||||||
responsive: true,
|
responsive: true,
|
||||||
@ -90,17 +128,10 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
|
|||||||
searching: false,
|
searching: false,
|
||||||
paging: false,
|
paging: false,
|
||||||
info: false,
|
info: false,
|
||||||
|
scrollX: true,
|
||||||
|
|
||||||
ajax : $.fn.dataTable.pipeline( {
|
|
||||||
url: '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
|
||||||
data: function ( d ) {
|
|
||||||
d.presupuesto_id = id;
|
|
||||||
},
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
||||||
async: true,
|
|
||||||
}),
|
|
||||||
columns: [
|
columns: [
|
||||||
|
{ 'data': 'tarifa_id' },
|
||||||
{ 'data': 'cantidad' },
|
{ 'data': 'cantidad' },
|
||||||
{ 'data': 'peso' },
|
{ 'data': 'peso' },
|
||||||
{ 'data': 'att' },
|
{ 'data': 'att' },
|
||||||
@ -109,9 +140,21 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
|
|||||||
{ 'data': 'cp' },
|
{ 'data': 'cp' },
|
||||||
{ 'data': 'municipio' },
|
{ 'data': 'municipio' },
|
||||||
{ 'data': 'provincia' },
|
{ 'data': 'provincia' },
|
||||||
{ 'data': 'ccaaId' },
|
{ 'data': 'ccaaId' ,
|
||||||
{ 'data': 'paisId' },
|
render: function(data, type, row, meta) {
|
||||||
|
var value = ccaaList.find(element => element.id === data);
|
||||||
|
return value['nombre'];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ 'data': 'paisId' ,
|
||||||
|
render: function(data, type, row, meta) {
|
||||||
|
var value = paisList.find(element => element.id === data);
|
||||||
|
return value['nombre'];
|
||||||
|
},
|
||||||
|
},
|
||||||
{ 'data': 'telefono' },
|
{ 'data': 'telefono' },
|
||||||
|
{ 'data': 'proveedor'},
|
||||||
|
{ 'data': 'proveedor_id'},
|
||||||
{ 'data': 'precio' },
|
{ 'data': 'precio' },
|
||||||
{ 'data': 'margen' },
|
{ 'data': 'margen' },
|
||||||
{
|
{
|
||||||
@ -123,14 +166,118 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
|
|||||||
{
|
{
|
||||||
orderable: false,
|
orderable: false,
|
||||||
searchable: false,
|
searchable: false,
|
||||||
targets: [lastColNr]
|
targets: [lastColNr_direcciones]
|
||||||
},
|
},
|
||||||
{"orderData": [ 0], "targets": 0 },
|
{"orderData": [ 0], "targets": 0 },
|
||||||
|
|
||||||
],
|
],
|
||||||
|
columnDefs: [
|
||||||
|
{
|
||||||
|
target: [0,13,15],
|
||||||
|
visible: false,
|
||||||
|
searchable: false
|
||||||
|
},
|
||||||
|
],
|
||||||
language: {
|
language: {
|
||||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||||
},
|
},
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
function checkInsertar(){
|
||||||
|
cantidad_total = 0
|
||||||
|
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||||
|
var data = this.data();
|
||||||
|
cantidad_total += data.cantidad
|
||||||
|
} );
|
||||||
|
if(cantidad_total < parseInt($('#tirada').val())){
|
||||||
|
$('#rowInsertar').css('display', 'flex')
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#rowInsertar').css('display', 'none')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_datos_envios(){
|
||||||
|
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
||||||
|
{
|
||||||
|
tipo: "clear_lineas",
|
||||||
|
presupuesto_id: id,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||||
|
})
|
||||||
|
.done(function( data ) {
|
||||||
|
|
||||||
|
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||||
|
var data = this.data();
|
||||||
|
$.post( '/presupuestos/presupuestodirecciones/add',
|
||||||
|
{
|
||||||
|
presupuesto_id : id,
|
||||||
|
tarifa_id : data.tarifa_id,
|
||||||
|
cantidad : data.cantidad,
|
||||||
|
peso : data.peso,
|
||||||
|
att : data.att,
|
||||||
|
email : data.email,
|
||||||
|
direccion : data.direccion,
|
||||||
|
paisId : data.paisId,
|
||||||
|
ccaaId : data.ccaaId,
|
||||||
|
provincia : data.provincia,
|
||||||
|
municipio : data.municipio,
|
||||||
|
cp : data.cp,
|
||||||
|
telefono : data.telefono,
|
||||||
|
precio : data.precio,
|
||||||
|
margen : data.margen,
|
||||||
|
proveedor : data.proveedor,
|
||||||
|
proveedor_id : data.proveedor_id,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_datos_envios(){
|
||||||
|
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
||||||
|
{
|
||||||
|
draw: 1,
|
||||||
|
columns: 1,
|
||||||
|
search: {
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
presupuesto_id: id,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||||
|
})
|
||||||
|
.done(function( data ) {
|
||||||
|
console.log(data)
|
||||||
|
data.data.forEach((linea) => {
|
||||||
|
tableEnvios.row
|
||||||
|
.add({
|
||||||
|
'tarifa_id': linea.tarifa_id,
|
||||||
|
'cantidad': linea.cantidad,
|
||||||
|
'peso': linea.peso,
|
||||||
|
'att': linea.att,
|
||||||
|
'email': linea.email,
|
||||||
|
'direccion': linea.direccion,
|
||||||
|
'cp': linea.cp,
|
||||||
|
'municipio': linea.municipio,
|
||||||
|
'provincia': linea.provincia,
|
||||||
|
'ccaaId': linea.ccaa_id,
|
||||||
|
'paisId': linea.pais_id,
|
||||||
|
'telefono': linea.telefono,
|
||||||
|
'proveedor': linea.proveedor,
|
||||||
|
'proveedor_id': linea.proveedor_id,
|
||||||
|
'precio': linea.precio,
|
||||||
|
'margen': linea.margen,
|
||||||
|
'actionBtns_direcciones': actionBtns_direcciones,
|
||||||
|
})
|
||||||
|
.draw();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
checkInsertar()
|
||||||
|
load_datos_envios()
|
||||||
|
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
@ -286,12 +286,12 @@ $('#paginas').on("change", function () {
|
|||||||
document.getElementById('compPaginasColorhq').value = 0;
|
document.getElementById('compPaginasColorhq').value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_servicios()
|
update_servicios(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#tirada').on("change", function () {
|
$('#tirada').on("change", function () {
|
||||||
|
|
||||||
update_servicios()
|
update_servicios(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#papelFormatoId').select2({
|
$('#papelFormatoId').select2({
|
||||||
|
|||||||
@ -367,7 +367,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_servicios(){
|
function update_servicios(update_preimpresion=false){
|
||||||
const domain = window.location.origin
|
const domain = window.location.origin
|
||||||
const dimension = getDimensionLibro();
|
const dimension = getDimensionLibro();
|
||||||
|
|
||||||
@ -382,7 +382,8 @@
|
|||||||
var datosAcabado = get_datos_acabado()
|
var datosAcabado = get_datos_acabado()
|
||||||
var datosEnc = get_datos_encuadernacion()
|
var datosEnc = get_datos_encuadernacion()
|
||||||
var datosManipulado = get_datos_manipulado()
|
var datosManipulado = get_datos_manipulado()
|
||||||
var datosPreimpresion = get_datos_preimpresion()
|
if(update_preimpresion)
|
||||||
|
var datosPreimpresion = get_datos_preimpresion()
|
||||||
|
|
||||||
fetch(domain + "/presupuestos/presupuestoacabados/update/" + id , {
|
fetch(domain + "/presupuestos/presupuestoacabados/update/" + id , {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -471,10 +472,12 @@
|
|||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
data.lines.forEach((line) => {
|
if(update_preimpresion){
|
||||||
$('#precio_preimpresion_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2))
|
data.lines.forEach((line) => {
|
||||||
$('#preimpresion_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2))
|
$('#precio_preimpresion_' + line[0].tarifa_id).val(parseFloat(line[0].total).toFixed(2))
|
||||||
});
|
$('#preimpresion_margen_' + line[0].tarifa_id).val(parseFloat(line[0].margen).toFixed(2))
|
||||||
|
});
|
||||||
|
}
|
||||||
yeniden(data.<?= csrf_token() ?>);
|
yeniden(data.<?= csrf_token() ?>);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<div id='error-tarifa'></div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="add_clientedAdd" class="form-label">
|
<label for="add_clientedAdd" class="form-label">
|
||||||
<?=lang('PresupuestosDirecciones.clientedAdd') ?>*
|
<?=lang('PresupuestosDirecciones.clientedAdd') ?>*
|
||||||
@ -164,6 +165,12 @@ $('#cancelAdd').on('click', function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
$('#add_cantidad').on('change', function(){
|
||||||
|
if(parseInt($('#add_cantidad').val()) > $('#add_cantidad').attr('max-value'))
|
||||||
|
$('#add_cantidad').val($('#add_cantidad').attr('max-value'))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
$('#saveDireccionEnvio').on('click', function(){
|
$('#saveDireccionEnvio').on('click', function(){
|
||||||
|
|
||||||
if(validate_fields()){
|
if(validate_fields()){
|
||||||
@ -182,16 +189,88 @@ $('#saveDireccionEnvio').on('click', function(){
|
|||||||
peso: peso_envio,
|
peso: peso_envio,
|
||||||
paisId: $("#add_pais_id").val(),
|
paisId: $("#add_pais_id").val(),
|
||||||
cp: $('#add_cp').val(),
|
cp: $('#add_cp').val(),
|
||||||
tipo_envio: $('#add_entregaPieCalle').is(":checked")?'palets':'cajas'
|
tipo_envio: $('#add_entregaPieCalle').is(":checked")?'palets':'cajas',
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||||
})
|
})
|
||||||
.done(function( data ) {
|
.done(function( data ) {
|
||||||
|
if(data.length >0){
|
||||||
|
var precios = []
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
if(peso_envio>data[i].peso_max){
|
||||||
|
data[i].precio = (data[i].peso_min + (peso_envio-data[i].peso_min)*data[i].precio_adicional).toFixed(2);
|
||||||
|
}
|
||||||
|
// si no se calcula linealmente
|
||||||
|
else{
|
||||||
|
m=((data[i].precio_max-data[i].precio_min)/(data[i].peso_max-data[i].peso_min))
|
||||||
|
b=data[i].precio_max-m*data[i].peso_max
|
||||||
|
data[i].precio = (m*peso_envio+b).toFixed(2);
|
||||||
|
}
|
||||||
|
data[i].margen = data[i].margen
|
||||||
|
}
|
||||||
|
|
||||||
|
const tarifa_final = data.reduce((previous, current) => {
|
||||||
|
return current.precio < previous.precio ? current : previous;
|
||||||
|
});
|
||||||
|
tarifa_final.cantidad=parseInt($('#add_cantidad').val())
|
||||||
|
tarifa_final.peso=peso_envio
|
||||||
|
|
||||||
|
|
||||||
|
tableEnvios.row
|
||||||
|
.add({
|
||||||
|
'tarifa_id': tarifa_final.id,
|
||||||
|
'cantidad': tarifa_final.cantidad,
|
||||||
|
'peso': tarifa_final.peso.toFixed(3),
|
||||||
|
'att': $('#add_att').val(),
|
||||||
|
'email': $('#add_email').val(),
|
||||||
|
'direccion': $('#add_direccion').val(),
|
||||||
|
'cp': $('#add_cp').val(),
|
||||||
|
'municipio': $('#add_municipio').val(),
|
||||||
|
'provincia': $('#add_provincia').val(),
|
||||||
|
'ccaaId': $('#add_ccaa').val(),
|
||||||
|
'paisId': $('#add_pais_id').val(),
|
||||||
|
'telefono': $('#add_telefono').val(),
|
||||||
|
'proveedor': tarifa_final.proveedor,
|
||||||
|
'proveedor_id': tarifa_final.proveedor_id,
|
||||||
|
'precio': tarifa_final.precio,
|
||||||
|
'margen': tarifa_final.margen,
|
||||||
|
'actionBtns_direcciones': actionBtns_direcciones,
|
||||||
|
})
|
||||||
|
.draw();
|
||||||
|
|
||||||
|
|
||||||
|
// Se guarda la dirección
|
||||||
|
if($('#add_saveDirection').is(":checked") &&
|
||||||
|
$('#add_alias').val().length>0){
|
||||||
|
$.post( '/clientes/clientedirecciones/add',
|
||||||
|
{
|
||||||
|
cliente_id: $('#clienteId').val(),
|
||||||
|
'att': $('#add_att').val(),
|
||||||
|
'email': $('#add_email').val(),
|
||||||
|
'direccion': $('#add_direccion').val(),
|
||||||
|
'cp': $('#add_cp').val(),
|
||||||
|
'municipio': $('#add_municipio').val(),
|
||||||
|
'provincia': $('#add_provincia').val(),
|
||||||
|
'ccaaId': $('#add_ccaa').val(),
|
||||||
|
'paisId': $('#add_pais_id').val(),
|
||||||
|
'telefono': $('#add_telefono').val(),
|
||||||
|
'alias': $('#add_alias').val(),
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||||
|
})
|
||||||
|
.done(function( data ) {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
checkInsertar()
|
||||||
|
$('#addressForm').modal("hide");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
popErrorAlert('<?= lang('PresupuestosDirecciones.validation.no_tarifa') ?>', 'error-tarifa')
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Se guarda la dirección
|
|
||||||
if($('#add_saveDirection').is(":checked")){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -332,6 +411,7 @@ $('#addressForm').on('hidden.bs.modal', function () {
|
|||||||
$('#add_provincia').val("")
|
$('#add_provincia').val("")
|
||||||
$('#add_cp').val("")
|
$('#add_cp').val("")
|
||||||
$('#add_telefono').val("")
|
$('#add_telefono').val("")
|
||||||
|
$('#add_saveDirection').prop('checked', false)
|
||||||
})
|
})
|
||||||
|
|
||||||
<?=$this->endSection() ?>
|
<?=$this->endSection() ?>
|
||||||
@ -131,6 +131,9 @@ else{
|
|||||||
$('#presupuestoForm').on( "submit", function( event ) {
|
$('#presupuestoForm').on( "submit", function( event ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
save_servicios();
|
save_servicios();
|
||||||
|
save_datos_envios();
|
||||||
|
|
||||||
|
|
||||||
$.when(fill_bbdd_from_lp(id).then(function (data, textStatus, jqXHR){
|
$.when(fill_bbdd_from_lp(id).then(function (data, textStatus, jqXHR){
|
||||||
generateCompJSON()
|
generateCompJSON()
|
||||||
form = $('#presupuestoForm').serialize()
|
form = $('#presupuestoForm').serialize()
|
||||||
|
|||||||
Reference in New Issue
Block a user