mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
arreglado bug en envios. ahora se actualizan los envios cuando se añaden lp. lp alineadas bottom
This commit is contained in:
@ -90,6 +90,91 @@ const actionBtns_direcciones = function(data) {
|
||||
`;
|
||||
};
|
||||
|
||||
function updateTablaEnvios(){
|
||||
|
||||
var peso_total_libro = 0
|
||||
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
peso_total_libro += parseFloat(rowData.peso)
|
||||
|
||||
})
|
||||
|
||||
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
const peso_envio = peso_total_libro*parseInt(rowData.cantidad)/1000.0
|
||||
|
||||
|
||||
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
||||
{
|
||||
tipo: "get_tarifa",
|
||||
peso: peso_envio,
|
||||
paisId: rowData.paisId,
|
||||
cp: rowData.cp,
|
||||
tipo_envio: parseInt(rowData.entregaPieCalle)==1?'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 = (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(rowIdx)
|
||||
.data({
|
||||
'tarifa_id': tarifa_final.id,
|
||||
'cantidad': rowData.cantidad,
|
||||
'peso': tarifa_final.peso.toFixed(3),
|
||||
'att': rowData.att,
|
||||
'email': rowData.email,
|
||||
'direccion': rowData.direccion,
|
||||
'cp': rowData.cp,
|
||||
'municipio': rowData.municipio,
|
||||
'provincia': rowData.provincia,
|
||||
'paisId': rowData.paisId,
|
||||
'telefono': rowData.telefono,
|
||||
'proveedor': tarifa_final.proveedor,
|
||||
'proveedor_id': tarifa_final.proveedor_id,
|
||||
'precio': tarifa_final.precio,
|
||||
'margen': tarifa_final.margen,
|
||||
'entregaPieCalle': rowData.entregaPieCalle,
|
||||
'actionBtns_direcciones': actionBtns_direcciones,
|
||||
})
|
||||
.draw();
|
||||
|
||||
|
||||
checkInsertar()
|
||||
updateTotales(false, false, true)
|
||||
|
||||
}
|
||||
else{
|
||||
popErrorAlert('<?= lang('PresupuestosDirecciones.validation.no_tarifa') ?>', 'error-tarifa')
|
||||
}
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$(document).on('click', '.delete-add-row', function(e) {
|
||||
const row = $(this).closest('tr');
|
||||
tableEnvios.row( row )
|
||||
|
||||
@ -249,7 +249,11 @@
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
|
||||
$('#paginas').on("change", function () {
|
||||
if(url_parts[url_parts.length-2] == 'edit'){
|
||||
|
||||
const url2 = window.location.href;
|
||||
const url_parts2 = url2.split('/');
|
||||
|
||||
if(url_parts2[url_parts2.length-2] == 'edit'){
|
||||
|
||||
checkPaginasPresupuesto()
|
||||
updateLineasPresupuesto()
|
||||
@ -274,9 +278,10 @@ $('#tirada').on("change", function () {
|
||||
|
||||
calcular_mermas()
|
||||
|
||||
const url = window.location.href;
|
||||
const url_parts = url.split('/');
|
||||
if(url_parts[url_parts.length-2] == 'edit'){
|
||||
const url2 = window.location.href;
|
||||
const url_parts2 = url2.split('/');
|
||||
|
||||
if(url_parts2[url_parts2.length-2] == 'edit'){
|
||||
update_servicios(false)
|
||||
updateLineasPresupuesto()
|
||||
checkInsertar()
|
||||
|
||||
@ -88,7 +88,7 @@ function format(d) {
|
||||
'<td></td>'+
|
||||
'<td></td>'+
|
||||
'<td colspan="10">'+
|
||||
'<div class="row">' +
|
||||
'<div class="row flex-grow-1 d-flex justify-content-center align-items-end">' +
|
||||
'<div class="col-md-12 col-lg-1">' +
|
||||
"<?= lang("Presupuestos.numeroPliegos") ?>" +
|
||||
'<input id="' + d.row_id +'_numeroPliegos" name="' + d.row_id +'_numeroPliegos" class="lp-input lp-cell lp-cell-disabled ' + d.row_class +'-input" type="text" value="' + d.numeroPliegos +'">'+
|
||||
@ -151,7 +151,7 @@ function format(d) {
|
||||
'<td></td>'+
|
||||
'<td></td>'+
|
||||
'<td colspan="10">'+
|
||||
'<div class="row">' +
|
||||
'<div class="row flex-grow-1 d-flex justify-content-center align-items-end">' +
|
||||
'<div class="col-md-12 col-lg-1">' +
|
||||
'<button id="' + d.row_id +'_defecto" name="' + d.row_id +'_defecto" type="button" class="btn btn-label-primary waves-effect lp-button"><?= lang('Presupuestos.porDefecto') ?></button>' +
|
||||
'</div>'+
|
||||
@ -183,7 +183,7 @@ function format(d) {
|
||||
'<?= lang('Presupuestos.gotaNegro') ?>' +
|
||||
'<input type="text" id="' + d.row_id +'_gotaNegro" name="' + d.row_id +'_gotaNegro" class="lp-cell lp-input ' + d.row_class +'-input ' + d.row_class +'-tipologia" value="' + d.gotaNegro +'">' +
|
||||
'</div>' +
|
||||
'<div class="col-md-12 col-lg-1">' +
|
||||
'<div class="col-md-12 col-lg-1 ">' +
|
||||
'<?= lang('Presupuestos.gotaColor') ?>' +
|
||||
'<input type="text" id="' + d.row_id +'_gotaColor" name="' + d.row_id +'_gotaColor" class="lp-cell lp-input ' + d.row_class +'-input ' + d.row_class +'-tipologia" value="' + d.gotaColor +'">' +
|
||||
'</div>' +
|
||||
@ -202,7 +202,7 @@ function format(d) {
|
||||
'<td></td>'+
|
||||
'<td></td>'+
|
||||
'<td colspan="10">'+
|
||||
'<div class="row">' +
|
||||
'<div class="row flex-grow-1 d-flex justify-content-center align-items-end">' +
|
||||
(d.row_id.includes('rot')?'<div class="col-md-12 col-lg-1">': '<div class="col-md-12 col-lg-1" style="display:none;">') +
|
||||
'<?= lang('Presupuestos.metrosMinuto') ?>' +
|
||||
'<input type="text" id="' + d.row_id +'_metrosMinuto" name="' + d.row_id +'_metrosMinuto" class="lp-cell lp-cell-disabled lp-input ' + d.row_class +'-input" readonly value="' + d.metrosMinuto +'">' +
|
||||
@ -258,7 +258,7 @@ function format(d) {
|
||||
'<td></td>'+
|
||||
'<td></td>'+
|
||||
'<td colspan="10">'+
|
||||
'<div class="row">' +
|
||||
'<div class="row flex-grow-1 d-flex justify-content-center align-items-end">' +
|
||||
(d.row_id.includes('rot')?'<div class="col-md-12 col-lg-1">': '<div class="col-md-12 col-lg-1" style="display:none;">') +
|
||||
'<?= lang('Presupuestos.metrosPapelLibro') ?>' +
|
||||
'<input type="text" id="' + d.row_id +'_metrosPapelLibro" name="' + d.row_id +'_metrosPapelLibro" class="lp-cell lp-cell-disabled lp-input ' + d.row_class +'-input" readonly value="' + d.metrosPapelLibro +'">' +
|
||||
@ -314,7 +314,7 @@ function format(d) {
|
||||
'<td></td>'+
|
||||
'<td></td>'+
|
||||
'<td colspan="10">'+
|
||||
'<div class="row">' +
|
||||
'<div class="row flex-grow-1 d-flex justify-content-center align-items-end" >' +
|
||||
(d.row_id.includes('rot')?'<div class="col-md-12 col-lg-1">': '<div class="col-md-12 col-lg-1" style="display:none;">') +
|
||||
'<?= lang('Presupuestos.velocidadCorte') ?>' +
|
||||
'<input type="text" id="' + d.row_id +'_velocidadCorte" name="' + d.row_id +'_velocidadCorte" class="lp-cell lp-input lp-cell-disabled" readonly value="' + d.velocidadCorte +'">' +
|
||||
@ -539,10 +539,9 @@ const actionBtns_lp = function(data) {
|
||||
]
|
||||
});
|
||||
|
||||
tableLineasPresupuesto.on( 'draw', function () {
|
||||
tableLineasPresupuesto.on( 'draw.dt', function () {
|
||||
checkPaginasPresupuesto()
|
||||
getVisibleTabs()
|
||||
|
||||
} );
|
||||
|
||||
|
||||
@ -553,6 +552,7 @@ $(document).on('click', '.btn-delete-lp', function(e) {
|
||||
.remove()
|
||||
.draw();
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
})
|
||||
|
||||
|
||||
@ -863,6 +863,7 @@ $('.insertarLinea').on("click", function (e) {
|
||||
fill_lp_cubierta(row, true);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -1266,6 +1267,7 @@ function fill_lp_bn(row, fromComparator=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$("#tableLineasPresupuesto").DataTable().columns.adjust();
|
||||
@ -1546,6 +1548,7 @@ function fill_lp_color(row, fromComparator=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$("#tableLineasPresupuesto").DataTable().columns.adjust();
|
||||
@ -1829,6 +1832,7 @@ function fill_lp_bnhq(row, fromComparator=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$("#tableLineasPresupuesto").DataTable().columns.adjust();
|
||||
@ -2112,6 +2116,7 @@ function fill_lp_colorhq(row, fromComparator=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$("#tableLineasPresupuesto").DataTable().columns.adjust();
|
||||
@ -2428,6 +2433,7 @@ function fill_lp_rot_bn(row, fromComparador=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$('.lp_rot_bn').css('display', '')
|
||||
@ -2747,6 +2753,7 @@ function fill_lp_rot_color(row, fromComparador=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
}
|
||||
|
||||
$("#tableLineasPresupuesto").DataTable().columns.adjust();
|
||||
@ -3008,6 +3015,7 @@ function fill_lp_cubierta(row, fromComparador=false){
|
||||
|
||||
calcular_mermas()
|
||||
updateTotales(true, false, false)
|
||||
updateTablaEnvios()
|
||||
|
||||
}
|
||||
|
||||
@ -3333,10 +3341,9 @@ function checkPaginasPresupuesto(){
|
||||
|
||||
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
if((rowData.row_id != 'lp_cubierta') && (rowData.row_id != 'lp_sobrecubierta'))
|
||||
cantidad_total += rowData.paginas
|
||||
if(rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta')
|
||||
cantidad_total += parseInt(rowData.paginas)
|
||||
})
|
||||
|
||||
htmlString = ''
|
||||
|
||||
if(cantidad_total != parseInt($('#paginas').val())){
|
||||
|
||||
@ -165,10 +165,12 @@ $('#saveDireccionEnvio').on('click', function(){
|
||||
|
||||
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
peso_total_libro += rowData.peso
|
||||
peso_total_libro += parseFloat(rowData.peso)
|
||||
|
||||
})
|
||||
|
||||
const peso_envio = peso_total_libro*parseInt($('#add_cantidad').val())/1000.0
|
||||
|
||||
|
||||
|
||||
$.post( '<?= route_to('dataTableOfPresupuestoDirecciones') ?>',
|
||||
{
|
||||
@ -181,7 +183,7 @@ $('#saveDireccionEnvio').on('click', function(){
|
||||
})
|
||||
.done(function( data ) {
|
||||
if(data.length >0){
|
||||
//console.log(data)
|
||||
|
||||
var precios = []
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if(peso_envio>data[i].peso_max){
|
||||
|
||||
Reference in New Issue
Block a user