mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminados envios
This commit is contained in:
@ -99,7 +99,7 @@ class ClienteDireccionesModel extends \App\Models\BaseModel
|
|||||||
->table($this->table . " t1")
|
->table($this->table . " t1")
|
||||||
->select(
|
->select(
|
||||||
"t1.id AS id, t1.cliente_id AS cliente_id, t2.nombre as cliente_nombre, t1.att AS att, t1.alias AS alias,
|
"t1.id AS id, t1.cliente_id AS cliente_id, t2.nombre as cliente_nombre, t1.att AS att, t1.alias AS alias,
|
||||||
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais,
|
t1.email AS email, t1.direccion AS direccion, t1.pais_id AS pais_id, t3.nombre AS pais, t3.nombre AS pais,
|
||||||
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"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<div id='alert-envios'></div>
|
<div id='alert-envios'></div>
|
||||||
<?= view("themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm") ?>
|
<?= view("themes/vuexy/form/presupuestos/admin/_presupuestoDireccionesForm") ?>
|
||||||
<div id='rowTable' class='row'>
|
<div id='rowTable' class='row'>
|
||||||
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-2 update-resumen-presupuesto" style="width: 95%;">
|
<table id="tableOfDireccionesEnvio" class="table comparator-table dt-responsive dataTable px-2 update-resumen-presupuesto" style="width: 95%;">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="lp-header">TARIFA ID</th>
|
<th class="lp-header">TARIFA ID</th>
|
||||||
@ -23,12 +23,13 @@
|
|||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.cp') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.cp') ?></th>
|
||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.municipio') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.municipio') ?></th>
|
||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.pais') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.pais') ?></th>
|
||||||
|
<th class="lp-header">pais_id</th>
|
||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.telefono') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.telefono') ?></th>
|
||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.proveedor') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.proveedor') ?></th>
|
||||||
<th>Proveedor_id</th>
|
<th class="lp-header">Proveedor_id</th>
|
||||||
<th class="lp-header"><?= lang('PresupuestosDirecciones.precio') ?></th>
|
<th class="lp-header"><?= lang('PresupuestosDirecciones.precio') ?></th>
|
||||||
<th><?= lang('Tarifaacabado.margen') ?></th>
|
<th class="lp-header"><?= lang('Tarifaacabado.margen') ?></th>
|
||||||
<th>Pallets?</th>
|
<th class="lp-header">Pallets?</th>
|
||||||
<th style="min-width:120px !important;" class="lp-header"><?= lang('Basic.global.Action') ?></th>
|
<th style="min-width:120px !important;" class="lp-header"><?= lang('Basic.global.Action') ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@ -133,260 +133,3 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<?= $this->section("additionalInlineJs") ?>
|
|
||||||
/*
|
|
||||||
$('#cancelAdd').on('click', function(){
|
|
||||||
$('#addressForm').modal("hide");
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
$('#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(){
|
|
||||||
|
|
||||||
if(validate_fields()){
|
|
||||||
|
|
||||||
if($('#addressForm').attr('action')=='edit'){
|
|
||||||
tableEnvios.row( $("#addressForm").attr('row') )
|
|
||||||
.remove()
|
|
||||||
.draw();
|
|
||||||
}
|
|
||||||
var peso_total_libro = 0
|
|
||||||
|
|
||||||
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
|
||||||
var rowData = this.data();
|
|
||||||
peso_total_libro += parseFloat(rowData.peso)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
const peso_envio = peso_total_libro*parseInt($('#add_cantidad').val())/1000.0
|
|
||||||
|
|
||||||
|
|
||||||
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
|
||||||
{
|
|
||||||
tipo: "get_tarifa",
|
|
||||||
peso: peso_envio,
|
|
||||||
paisId: $("#add_pais_id").val(),
|
|
||||||
cp: $('#add_cp').val(),
|
|
||||||
tipo_envio: $('#add_entregaPieCalle').is(":checked")?'palets':'cajas',
|
|
||||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
|
||||||
})
|
|
||||||
.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_max == 0){
|
|
||||||
data[i].precio = (parseFloat(data[i].precio_min) + (peso_envio-parseFloat(data[i].peso_min))*parseFloat(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 = parseFloat(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(),
|
|
||||||
'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,
|
|
||||||
'entregaPieCalle': $('#add_entregaPieCalle').is(":checked")?1:0,
|
|
||||||
'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(),
|
|
||||||
'paisId': $('#add_pais_id').val(),
|
|
||||||
'telefono': $('#add_telefono').val(),
|
|
||||||
'alias': $('#add_alias').val(),
|
|
||||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
|
||||||
})
|
|
||||||
.done(function( data ) {
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
checkInsertar()
|
|
||||||
//updateTotales(false, false, true)
|
|
||||||
updatePresupuesto({
|
|
||||||
update_lineas: false,
|
|
||||||
update_servicios: true,
|
|
||||||
update_envios: false,
|
|
||||||
update_resumen: true,
|
|
||||||
update_tiradas_alternativas: true
|
|
||||||
})
|
|
||||||
$('#addressForm').modal("hide");
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
popErrorAlert('<?= lang('PresupuestosDirecciones.validation.no_tarifa') ?>', 'error-tarifa')
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function validate_fields(){
|
|
||||||
|
|
||||||
$( ".error-text-form" ).remove();
|
|
||||||
|
|
||||||
var returnValue = false
|
|
||||||
|
|
||||||
$("input.new-address").each( function() {
|
|
||||||
if($('#' + this.id).val().length == 0 && $('#' + this.id).css('display') != 'none'){
|
|
||||||
$('#' + this.id).after(
|
|
||||||
"<p style='font-size: 11px !important;" +
|
|
||||||
"padding: 0 !important; " +
|
|
||||||
"color: #b11f1f !important;' " +
|
|
||||||
"class='error-text-form'>" +'<?= lang('PresupuestosDirecciones.validation.required'); ?>' + '</p>')
|
|
||||||
}
|
|
||||||
returnValue = true
|
|
||||||
})
|
|
||||||
return returnValue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$('#add_saveDirection').change(function() {
|
|
||||||
if(this.checked) {
|
|
||||||
$('.save-alias').css('display', 'inline')
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$('.save-alias').css('display', 'none')
|
|
||||||
}
|
|
||||||
$('#add_saveDirection').val(this.checked);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#add_clientedAdd').select2({
|
|
||||||
allowClear: false,
|
|
||||||
minimumResultsForSearch: Infinity,
|
|
||||||
dropdownParent: $('#addressForm'),
|
|
||||||
ajax: {
|
|
||||||
url: '<?= route_to("menuItemsOfClienteDirecciones") ?>',
|
|
||||||
type: 'post',
|
|
||||||
dataType: 'json',
|
|
||||||
|
|
||||||
data: function (params) {
|
|
||||||
return {
|
|
||||||
cliente_id: $('#clienteId').val(),
|
|
||||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
|
||||||
};
|
|
||||||
},
|
|
||||||
delay: 60,
|
|
||||||
processResults: function (response) {
|
|
||||||
|
|
||||||
yeniden(response.<?= csrf_token() ?>);
|
|
||||||
|
|
||||||
return {
|
|
||||||
results: response.menu
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
cache: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
$('#add_clientedAdd').on('select2:select', function (e) {
|
|
||||||
|
|
||||||
$('.save-alias').css('display', 'none')
|
|
||||||
$('#add_alias').val('')
|
|
||||||
$('#add_saveDirection').attr("disabled", true)
|
|
||||||
|
|
||||||
var data = e.params.data;
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: '<?=route_to('dataTableOfClienteDirecciones') ?>',
|
|
||||||
dataType: 'json',
|
|
||||||
data: {
|
|
||||||
tipo: 'direccion',
|
|
||||||
id: data.id,
|
|
||||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
|
||||||
|
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
if(data.length>0){
|
|
||||||
$('#add_att').val(data[0].att)
|
|
||||||
$('#add_direccion').val(data[0].direccion)
|
|
||||||
$('#add_cp').val(data[0].cp)
|
|
||||||
$('#add_municipio').val(data[0].municipio)
|
|
||||||
$('#add_provincia').val(data[0].provincia)
|
|
||||||
$('#add_telefono').val(data[0].telefono)
|
|
||||||
$('#add_email').val(data[0].email)
|
|
||||||
$('#add_pais_id').val(data[0].pais_id).change();
|
|
||||||
}
|
|
||||||
yeniden(data.<?= csrf_token() ?>);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
error: function(e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.new-address').on('change', function(e){
|
|
||||||
if (e.originalEvent) {
|
|
||||||
// user-triggered event
|
|
||||||
$('#add_clientedAdd').val(null).trigger('change');
|
|
||||||
$('#add_saveDirection').removeAttr("disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// clear modal items when close
|
|
||||||
$('#addressForm').on('hidden.bs.modal', function () {
|
|
||||||
$('#add_alias').val("")
|
|
||||||
$('#add_att').val("")
|
|
||||||
$('#add_email').val("")
|
|
||||||
$('#add_direccion').val("")
|
|
||||||
$("#add_pais_id").val(1).change()
|
|
||||||
$("#add_clientedAdd").val("").change()
|
|
||||||
$('#add_municipio').val("")
|
|
||||||
$('#add_provincia').val("")
|
|
||||||
$('#add_cp').val("")
|
|
||||||
$('#add_telefono').val("")
|
|
||||||
$('#add_saveDirection').prop('checked', false)
|
|
||||||
$('#add_entregaPieCalle').prop('checked', false)
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
<?=$this->endSection() ?>
|
|
||||||
@ -294,7 +294,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
|
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
|
||||||
|
|
||||||
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Presupuestos'] }, {},
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Presupuestos', 'PresupuestosDirecciones'] }, {},
|
||||||
function (translations) {
|
function (translations) {
|
||||||
window.language = JSON.parse(translations);
|
window.language = JSON.parse(translations);
|
||||||
new PresupuestoAdminEdit().init();
|
new PresupuestoAdminEdit().init();
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import Ajax from "../../../components/ajax.js";
|
import Ajax from "../../../components/ajax.js";
|
||||||
import { getToken } from "../../../common/common.js";
|
import { getToken } from "../../../common/common.js";
|
||||||
|
import ClassSelect from "../../../components/select2.js";
|
||||||
|
import ModalYesNo from "../../../components/modalYesNo.js";
|
||||||
|
|
||||||
|
|
||||||
class Envios {
|
class Envios {
|
||||||
|
|
||||||
@ -11,12 +14,19 @@ class Envios {
|
|||||||
this.recogerTaller = $('#recoger_en_taller');
|
this.recogerTaller = $('#recoger_en_taller');
|
||||||
|
|
||||||
this.table = null;
|
this.table = null;
|
||||||
|
this.direccionesClienteForm = new ClassSelect($('#add_clientedAdd'), '/misdirecciones/getSelect2', 'Seleccione una direccion', false, {});
|
||||||
|
this.paisesClienteForm = new ClassSelect($('#add_pais_id'), '/paises/menuitems2', 'Seleccione país', false, {});
|
||||||
|
this.modalYesNo = null;
|
||||||
|
|
||||||
|
this.insertarEnvio = $('#insertar_direccion');
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
this.paisesClienteForm.init();
|
||||||
|
|
||||||
this.table = $('#tableOfDireccionesEnvio').DataTable({
|
this.table = $('#tableOfDireccionesEnvio').DataTable({
|
||||||
draw: 5,
|
draw: 5,
|
||||||
serverSide: false,
|
serverSide: false,
|
||||||
@ -41,23 +51,25 @@ class Envios {
|
|||||||
{ 'data': 'cp' },
|
{ 'data': 'cp' },
|
||||||
{ 'data': 'municipio' },
|
{ 'data': 'municipio' },
|
||||||
{ 'data': 'pais' },
|
{ 'data': 'pais' },
|
||||||
|
{ 'data': 'pais_id', visible: false },
|
||||||
{ 'data': 'telefono' },
|
{ 'data': 'telefono' },
|
||||||
{ 'data': 'proveedor' },
|
{ 'data': 'proveedor' },
|
||||||
{ 'data': 'proveedor_id' },
|
{ 'data': 'proveedor_id', visible: false },
|
||||||
{ 'data': 'precio' },
|
{ 'data': 'precio' },
|
||||||
{ 'data': 'margen' },
|
{ 'data': 'margen', render: function (data, type, row) { return Math.round(data) } },
|
||||||
{ 'data': 'entregaPieCalle' },
|
{ 'data': 'entregaPieCalle' },
|
||||||
{
|
{
|
||||||
data: function (row, type, set, meta) {
|
data: function (row, type, set, meta) {
|
||||||
return `
|
return `
|
||||||
<span class="edit-add"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit-add mx-2" data-id="${row.id}"></i></a></span>
|
<span class="edit-add"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit-envio mx-2" data-id="${row.id}"></i></a></span>
|
||||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm tiradas-alternativas delete-add-row mx-2"></i></a>
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm tiradas-alternativas btn-delete-envio mx-2"></i></a>
|
||||||
`;
|
`;
|
||||||
},
|
},
|
||||||
className: 'row-edit dt-center'
|
className: 'row-edit dt-center'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
columnDefs: [
|
columnDefs: [
|
||||||
|
|
||||||
{
|
{
|
||||||
orderable: false,
|
orderable: false,
|
||||||
searchable: false,
|
searchable: false,
|
||||||
@ -66,22 +78,351 @@ class Envios {
|
|||||||
{ "orderData": [0], "targets": 0 },
|
{ "orderData": [0], "targets": 0 },
|
||||||
|
|
||||||
],
|
],
|
||||||
columnDefs: [
|
|
||||||
{
|
|
||||||
target: [11],
|
|
||||||
visible: false,
|
|
||||||
searchable: false
|
|
||||||
},
|
|
||||||
],
|
|
||||||
language: {
|
language: {
|
||||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||||
},
|
},
|
||||||
|
|
||||||
drawCallback: function (settings) {
|
drawCallback: function (settings) {
|
||||||
|
|
||||||
|
const boolCols = [15];
|
||||||
|
for (let coln of boolCols) {
|
||||||
|
self.table.column(coln, { page: 'current' }).nodes().each(function (cell, i) {
|
||||||
|
cell.innerHTML = cell.innerHTML == '1' ? '<i class="ti ti-check"></i>' : '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
self.check_unidades_enviadas();
|
self.check_unidades_enviadas();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete-envio', function () {
|
||||||
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
||||||
|
self.table.row(rowId).remove().draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-edit-envio', function () {
|
||||||
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
||||||
|
const data = $('#tableOfDireccionesEnvio').DataTable().row(rowId).data();
|
||||||
|
|
||||||
|
$("#addressForm").attr('action', 'edit')
|
||||||
|
$("#addressForm").attr('row', rowId)
|
||||||
|
$("#addressForm").attr('presupuestodireccion_id', data.id)
|
||||||
|
let $newAddDialog = $("#addressForm")
|
||||||
|
let maximaCantidad = parseInt($('#tirada').val())
|
||||||
|
$("#add_cantidad").attr("max", maximaCantidad);
|
||||||
|
$("#add_cantidad").val(maximaCantidad);
|
||||||
|
$("#add_cantidad").on('change', function () {
|
||||||
|
$("#add_cantidad").val(parseInt($("#add_cantidad").val()) > maximaCantidad ? maximaCantidad : $("#add_cantidad").val())
|
||||||
|
})
|
||||||
|
|
||||||
|
let cantidad_total = 0
|
||||||
|
$('#tableOfDireccionesEnvio').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
let data2 = this.data();
|
||||||
|
cantidad_total += parseInt(data2.cantidad)
|
||||||
|
});
|
||||||
|
cantidad_total -= parseInt(data.cantidad) // Si es editar tienes que restar los de la linea actual
|
||||||
|
$('#add_cantidad').attr('max-value', parseInt($('#tirada').val()) - cantidad_total)
|
||||||
|
$('#add_cantidad').val(parseInt($('#tirada').val()) - cantidad_total)
|
||||||
|
|
||||||
|
$('#add_att').val(data.att)
|
||||||
|
$('#add_direccion').val(data.direccion)
|
||||||
|
$('#add_email').val(data.email)
|
||||||
|
$('#add_cp').val(data.cp)
|
||||||
|
$('#add_municipio').val(data.municipio)
|
||||||
|
$('#add_provincia').val(data.provincia)
|
||||||
|
self.paisesClienteForm.setOption(data.pais_id, data.pais);
|
||||||
|
$('#add_telefono').val(data.telefono)
|
||||||
|
$('#add_cantidad').val(data.cantidad)
|
||||||
|
$('#add_entregaPieCalle').prop('checked', data.entregaPieCalle == 1 ? true : false)
|
||||||
|
|
||||||
|
self.direccionesClienteForm.setParams({ 'cliente_id': () => $("#clienteId").select2('data')[0].id });
|
||||||
|
self.direccionesClienteForm.init();
|
||||||
|
|
||||||
|
$newAddDialog.modal('show')
|
||||||
|
});
|
||||||
|
|
||||||
|
this.recogerTaller.on('change', function () {
|
||||||
|
|
||||||
|
const current_value = this.checked;
|
||||||
|
self.recogerTaller.prop('checked', false);
|
||||||
|
|
||||||
|
if (current_value) {
|
||||||
|
self.modalYesNo = new ModalYesNo("Esto borrará todas las direcciones de envío. ¿Está seguro?", "modalYesNoEnvios");
|
||||||
|
self.modalYesNo.init();
|
||||||
|
self.modalYesNo.show(() => {
|
||||||
|
self.table.clear().draw();
|
||||||
|
self.check_unidades_enviadas();
|
||||||
|
self.recogerTaller.prop('checked', true);
|
||||||
|
self.modalYesNo.hide();
|
||||||
|
self.insertarEnvio.addClass('d-none');
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.insertarEnvio.removeClass('d-none');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.insertarEnvio.on('click', this.addEnvio.bind(this));
|
||||||
|
|
||||||
|
this.initFormularioDireccionEnvio();
|
||||||
|
}
|
||||||
|
|
||||||
|
addEnvio() {
|
||||||
|
|
||||||
|
$("#addressForm").attr('action', 'create');
|
||||||
|
let newAddDialog = $("#addressForm");
|
||||||
|
this.direccionesClienteForm.setParams({ 'cliente_id': () => $("#clienteId").select2('data')[0].id });
|
||||||
|
this.direccionesClienteForm.init();
|
||||||
|
let maximaCantidad = parseInt($('#tirada').val());
|
||||||
|
$("#add_cantidad").attr("max", maximaCantidad);;
|
||||||
|
$("#add_cantidad").val(maximaCantidad);
|
||||||
|
$("#add_cantidad").on('change', function () {
|
||||||
|
$("#add_cantidad").val(parseInt($("#add_cantidad").val()) > maximaCantidad ? maximaCantidad : $("#add_cantidad").val());
|
||||||
|
})
|
||||||
|
|
||||||
|
let cantidad_total = 0;
|
||||||
|
$('#tableOfDireccionesEnvio').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
let data = this.data();
|
||||||
|
cantidad_total += parseInt(data.cantidad);
|
||||||
|
});
|
||||||
|
$('#add_cantidad').attr('max-value', parseInt($('#tirada').val()) - cantidad_total);
|
||||||
|
$('#add_cantidad').val(parseInt($('#tirada').val()) - cantidad_total);
|
||||||
|
newAddDialog.modal('show');
|
||||||
|
}
|
||||||
|
|
||||||
|
initFormularioDireccionEnvio() {
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
this.direccionesClienteForm.item.on('select2:select', function (e) {
|
||||||
|
|
||||||
|
$('.save-alias').css('display', 'none');
|
||||||
|
$('#add_alias').val('');
|
||||||
|
$('#add_saveDirection').attr("disabled", true);
|
||||||
|
|
||||||
|
let data = e.params.data;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: '/clientedirecciones/datatable',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
tipo: 'direccion',
|
||||||
|
id: data.id,
|
||||||
|
[self.csrf_token]: self.csrf_hash
|
||||||
|
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
$('#add_att').val(data[0].att);
|
||||||
|
$('#add_direccion').val(data[0].direccion);
|
||||||
|
$('#add_cp').val(data[0].cp);
|
||||||
|
$('#add_municipio').val(data[0].municipio);
|
||||||
|
$('#add_provincia').val(data[0].provincia);
|
||||||
|
$('#add_telefono').val(data[0].telefono);
|
||||||
|
$('#add_email').val(data[0].email);
|
||||||
|
self.paisesClienteForm.empty();
|
||||||
|
self.paisesClienteForm.setOption(data[0].pais_id, data[0].pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#addressForm').on('hidden.bs.modal', function () {
|
||||||
|
$('#add_alias').val("");
|
||||||
|
$('#add_att').val("");
|
||||||
|
$('#add_email').val("");
|
||||||
|
$('#add_direccion').val("");
|
||||||
|
self.paisesClienteForm.empty();
|
||||||
|
self.direccionesClienteForm.empty();
|
||||||
|
$('#add_municipio').val("");
|
||||||
|
$('#add_provincia').val("");
|
||||||
|
$('#add_cp').val("");
|
||||||
|
$('#add_telefono').val("");
|
||||||
|
$('#add_saveDirection').prop('checked', false)
|
||||||
|
$('#add_entregaPieCalle').prop('checked', false)
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#cancelAdd').on('click', function () {
|
||||||
|
$('#addressForm').modal("hide");
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#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 () {
|
||||||
|
|
||||||
|
if (self.validate_fields()) {
|
||||||
|
|
||||||
|
if ($('#addressForm').attr('action') == 'edit') {
|
||||||
|
self.table.row($("#addressForm").attr('row'))
|
||||||
|
.remove()
|
||||||
|
.draw();
|
||||||
|
}
|
||||||
|
let peso_total_libro = 0
|
||||||
|
|
||||||
|
$('#tableLineasPresupuesto').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
let rowData = this.data();
|
||||||
|
peso_total_libro += parseFloat(rowData.peso)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
const peso_envio = peso_total_libro * parseInt($('#add_cantidad').val()) / 1000.0
|
||||||
|
|
||||||
|
|
||||||
|
$.post('/presupuestodirecciones/datatable',
|
||||||
|
{
|
||||||
|
tipo: "get_tarifa",
|
||||||
|
peso: peso_envio,
|
||||||
|
paisId: $("#add_pais_id").val(),
|
||||||
|
cp: $('#add_cp').val(),
|
||||||
|
tipo_envio: $('#add_entregaPieCalle').is(":checked") ? 'palets' : 'cajas',
|
||||||
|
[self.csrf_token]: self.csrf_hash
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
|
||||||
|
let precios = []
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
if (peso_envio > data[i].peso_max || data[i].precio_max == 0) {
|
||||||
|
data[i].precio = (parseFloat(data[i].precio_min) + (peso_envio - parseFloat(data[i].peso_min)) * parseFloat(data[i].precio_adicional)).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
let m = ((data[i].precio_max - data[i].precio_min) / (data[i].peso_max - data[i].peso_min))
|
||||||
|
let b = data[i].precio_max - m * data[i].peso_max
|
||||||
|
data[i].precio = parseFloat(m * peso_envio + b).toFixed(2);
|
||||||
|
}
|
||||||
|
data[i].margen = data[i].margen
|
||||||
|
}
|
||||||
|
|
||||||
|
let 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
|
||||||
|
|
||||||
|
|
||||||
|
self.table.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(),
|
||||||
|
'pais_id': $('#add_pais_id').select2('data')[0].id,
|
||||||
|
'pais': $('#add_pais_id').select2('data')[0].text,
|
||||||
|
'telefono': $('#add_telefono').val(),
|
||||||
|
'proveedor': tarifa_final.proveedor,
|
||||||
|
'proveedor_id': tarifa_final.proveedor_id,
|
||||||
|
'precio': tarifa_final.precio,
|
||||||
|
'margen': tarifa_final.margen,
|
||||||
|
'entregaPieCalle': $('#add_entregaPieCalle').is(":checked") ? 1 : 0,
|
||||||
|
'actionBtns_direcciones': `
|
||||||
|
<span class="edit-add"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit-envio mx-2"></i></a></span>
|
||||||
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm tiradas-alternativas btn-delete-envio mx-2"></i></a>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
.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(),
|
||||||
|
'paisId': $('#add_pais_id').val(),
|
||||||
|
'telefono': $('#add_telefono').val(),
|
||||||
|
'alias': $('#add_alias').val(),
|
||||||
|
[self.csrf_token]: self.csrf_hash
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TO-DO
|
||||||
|
checkInsertar()
|
||||||
|
//updateTotales(false, false, true)
|
||||||
|
updatePresupuesto({
|
||||||
|
update_lineas: false,
|
||||||
|
update_servicios: true,
|
||||||
|
update_envios: false,
|
||||||
|
update_resumen: true,
|
||||||
|
update_tiradas_alternativas: true
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
$('#addressForm').modal("hide");
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
popErrorAlert(window.language.PresupuestosDirecciones.validation.no_tarifa, 'error-tarifa')
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#add_saveDirection').on('change', function () {
|
||||||
|
if (this.checked) {
|
||||||
|
$('.save-alias').css('display', 'inline')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('.save-alias').css('display', 'none')
|
||||||
|
}
|
||||||
|
$('#add_saveDirection').val(this.checked);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('.new-address').on('change', function (e) {
|
||||||
|
if (e.originalEvent) {
|
||||||
|
// user-triggered event
|
||||||
|
$('#add_clientedAdd').val(null).trigger('change');
|
||||||
|
$('#add_saveDirection').removeAttr("disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
validate_fields() {
|
||||||
|
|
||||||
|
$(".error-text-form").remove();
|
||||||
|
|
||||||
|
let returnValue = false
|
||||||
|
|
||||||
|
$("input.new-address").each(function () {
|
||||||
|
if ($('#' + this.id).val().length == 0 && $('#' + this.id).css('display') != 'none') {
|
||||||
|
$('#' + this.id).after(
|
||||||
|
"<p style='font-size: 11px !important;" +
|
||||||
|
"padding: 0 !important; " +
|
||||||
|
"color: #b11f1f !important;' " +
|
||||||
|
"class='error-text-form'>" + window.language.PresupuestosDirecciones.validation.required + '</p>')
|
||||||
|
}
|
||||||
|
returnValue = true
|
||||||
|
})
|
||||||
|
return returnValue
|
||||||
}
|
}
|
||||||
|
|
||||||
cargar(datos) {
|
cargar(datos) {
|
||||||
@ -95,7 +436,7 @@ class Envios {
|
|||||||
|
|
||||||
check_unidades_enviadas() {
|
check_unidades_enviadas() {
|
||||||
|
|
||||||
var cantidad_total = 0
|
let cantidad_total = 0
|
||||||
this.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
this.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
cantidad_total += parseInt(this.data().cantidad)
|
cantidad_total += parseInt(this.data().cantidad)
|
||||||
});
|
});
|
||||||
@ -115,8 +456,10 @@ class Envios {
|
|||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
$('#alert-envios').html(htmlString);
|
$('#alert-envios').html(htmlString);
|
||||||
|
this.insertarEnvio.removeClass('d-none');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
this.insertarEnvio.addClass('d-none');
|
||||||
$('#alert-envios').html(htmlString);
|
$('#alert-envios').html(htmlString);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,11 +38,16 @@ table.dataTable.table-hover>tbody>tr.selected:hover>* {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tableOfDireccionesEnvio.comparator-table td {
|
||||||
|
text-align: center !important;
|
||||||
|
}
|
||||||
|
|
||||||
.comparator-table td.dt-result-value {
|
.comparator-table td.dt-result-value {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.lp-cell {
|
.lp-cell {
|
||||||
padding-left: 1px;
|
padding-left: 1px;
|
||||||
padding-right: 1px;
|
padding-right: 1px;
|
||||||
|
|||||||
Reference in New Issue
Block a user