mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'add/envio_ferros' into 'main'
Add/envio ferros See merge request jjimenez/safekat!745
This commit is contained in:
@ -4,11 +4,14 @@ import ClassSelect from '../../components/select2.js';
|
||||
$(() => {
|
||||
|
||||
let otsFilter = '';
|
||||
const tipo_envio = $('#tipo_envio').val();
|
||||
|
||||
const selectPedidos = new ClassSelect($('#buscadorPedidos'), '/logistica/selectForNewEnvio', "");
|
||||
const selectPedidos = new ClassSelect($('#buscadorPedidos'), '/logistica/selectForNewEnvio', "", true, {
|
||||
tipo_envio: () => $('#tipo_envio').val()
|
||||
});
|
||||
selectPedidos.init();
|
||||
const selectDirecciones = new ClassSelect($('#selectDirecciones'), '/logistica/selectDireccionForEnvio', "", true, {
|
||||
pedido_id: () => selectPedidos.getVal()
|
||||
ot_id: () => selectPedidos.getVal()
|
||||
});
|
||||
selectDirecciones.init();
|
||||
|
||||
@ -19,7 +22,10 @@ $(() => {
|
||||
})
|
||||
selectPedidos.item.on('change', () => {
|
||||
selectDirecciones.empty();
|
||||
$('.select-direcciones').removeClass('d-none');
|
||||
if(tipo_envio == 'ferro_prototipo')
|
||||
$('.add-envio').removeClass('d-none');
|
||||
else
|
||||
$('.select-direcciones').removeClass('d-none');
|
||||
})
|
||||
selectDirecciones.item.on('select2:open', () => {
|
||||
$('.add-envio').addClass('d-none');
|
||||
@ -31,12 +37,24 @@ $(() => {
|
||||
|
||||
|
||||
$('#btnAddEnvio').on('click', () => {
|
||||
const pedido_id = selectPedidos.getVal();
|
||||
const direccionSeleccionada = selectDirecciones.getText();
|
||||
$.post('/logistica/generateEnvio', {
|
||||
pedido_id: pedido_id,
|
||||
direccion: direccionSeleccionada
|
||||
}, function (response) {
|
||||
let url = '';
|
||||
let data = {};
|
||||
if(tipo_envio == 'ferro_prototipo'){
|
||||
url = '/logistica/generateEnvioFerro';
|
||||
data = {
|
||||
ot_id: selectPedidos.getVal()
|
||||
};
|
||||
}
|
||||
else{
|
||||
url = '/logistica/generateEnvio';
|
||||
data = {
|
||||
ot_id: selectPedidos.getVal(),
|
||||
direccion: selectDirecciones.getText()
|
||||
};
|
||||
}
|
||||
$.post(
|
||||
url,
|
||||
data, function (response) {
|
||||
if (response.status) {
|
||||
window.open(`${window.location.origin}/logistica/envio/${response.data.id_envio}`);
|
||||
selectDirecciones.empty();
|
||||
@ -51,7 +69,7 @@ $(() => {
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
const tableEnvios = $('#tableOfEnvios').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
@ -66,6 +84,7 @@ $(() => {
|
||||
"url": "/logistica/datatableEnvios",
|
||||
"data": function (d) {
|
||||
d.otsFilter = otsFilter;
|
||||
d.tipo_envio = $('#tipo_envio').val();
|
||||
}
|
||||
},
|
||||
"columns": [
|
||||
|
||||
@ -235,9 +235,35 @@ class DatosLibro {
|
||||
|
||||
if (this.ferro.prop('checked')) {
|
||||
$(document).trigger('add-servicio-lineas', 'ferro');
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: true,
|
||||
update_resumen: false,
|
||||
update_tiradas_alternativas: false
|
||||
});
|
||||
}
|
||||
else {
|
||||
$(document).trigger('remove-servicio-lineas', 'ferro');
|
||||
if(!this.prototipo.prop('checked')){
|
||||
const table = $('#tableOfDireccionesEnvio').DataTable();
|
||||
const rows = table.rows().data();
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const rowData = rows[i];
|
||||
if (rowData.is_ferro_prototipo == 1) {
|
||||
table.rows(i).remove();
|
||||
table.draw();
|
||||
break;
|
||||
}
|
||||
}
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,9 +287,35 @@ class DatosLibro {
|
||||
|
||||
if (this.prototipo.prop('checked')) {
|
||||
$(document).trigger('add-servicio-lineas', 'prototipo');
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: true,
|
||||
update_resumen: false,
|
||||
update_tiradas_alternativas: false
|
||||
});
|
||||
}
|
||||
else {
|
||||
$(document).trigger('remove-servicio-lineas', 'prototipo');
|
||||
if(!this.ferro.prop('checked')){
|
||||
const table = $('#tableOfDireccionesEnvio').DataTable();
|
||||
const rows = table.rows().data();
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const rowData = rows[i];
|
||||
if (rowData.is_ferro_prototipo == 1) {
|
||||
table.rows(i).remove();
|
||||
table.draw();
|
||||
break;
|
||||
}
|
||||
}
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,6 +71,7 @@ class Envios {
|
||||
},
|
||||
{ 'data': 'margen', render: function (data, type, row) { return Math.round(data) } },
|
||||
{ 'data': 'entregaPieCalle' },
|
||||
{ 'data': 'is_ferro_prototipo' },
|
||||
{
|
||||
data: function (row, type, set, meta) {
|
||||
return `
|
||||
@ -87,7 +88,7 @@ class Envios {
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
// all columns
|
||||
targets: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
||||
targets: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
//targets: [$('#tableOfDireccionesEnvio').find("tr:first th").length - 1]
|
||||
},
|
||||
],
|
||||
@ -97,7 +98,7 @@ class Envios {
|
||||
|
||||
drawCallback: function (settings) {
|
||||
|
||||
const boolCols = [15];
|
||||
const boolCols = [15, 16];
|
||||
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>' : '';
|
||||
@ -164,6 +165,19 @@ class Envios {
|
||||
$('#add_telefono').val(data.telefono)
|
||||
$('#add_cantidad').val(data.cantidad)
|
||||
$('#add_entregaPieCalle').prop('checked', data.entregaPieCalle == 1 ? true : false)
|
||||
$('#dirFerroProto').prop('checked', data.is_ferro_prototipo == 1 ? true : false)
|
||||
|
||||
if (data.is_ferro_prototipo == 1) {
|
||||
$('#add_cantidad').val(1);
|
||||
$('#add_cantidad').attr('disabled', true);
|
||||
$('#dirFerroProto').prop('disabled', true);
|
||||
$('#direccionFerroProto').removeClass('d-none');
|
||||
}
|
||||
else {
|
||||
$('#add_cantidad').attr('disabled', false);
|
||||
$('#dirFerroProto').prop('disabled', false);
|
||||
$('#direccionFerroProto').addClass('d-none');
|
||||
}
|
||||
|
||||
self.direccionesClienteForm.setParams({ 'cliente_id': () => $("#clienteId").select2('data')[0].id });
|
||||
self.direccionesClienteForm.init();
|
||||
@ -220,6 +234,7 @@ class Envios {
|
||||
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);
|
||||
@ -228,16 +243,39 @@ class Envios {
|
||||
})
|
||||
|
||||
let cantidad_total = 0;
|
||||
let hasFerroPrototipo = false;
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let data = this.data();
|
||||
cantidad_total += parseInt(data.cantidad);
|
||||
if (data.is_ferro_prototipo == 0)
|
||||
cantidad_total += parseInt(data.cantidad);
|
||||
else
|
||||
hasFerroPrototipo = true;
|
||||
});
|
||||
$('#add_cantidad').attr('max-value', parseInt($('#tirada').val()) - cantidad_total);
|
||||
$('#add_cantidad').val(parseInt($('#tirada').val()) - cantidad_total);
|
||||
const restante = parseInt($('#tirada').val()) - cantidad_total;
|
||||
$('#add_cantidad').attr('max-value', restante);
|
||||
$('#add_cantidad').val(restante > 0 ? restante : 0);
|
||||
|
||||
if (hasFerroPrototipo) {
|
||||
$('#dirFerroProto').prop('checked', false);
|
||||
$('#direccionFerroProto').addClass('d-none');
|
||||
$('#add_cantidad').attr('disabled', false);
|
||||
}
|
||||
else {
|
||||
if (restante == 0) {
|
||||
$('#direccionFerroProto').removeClass('d-none');
|
||||
$('#dirFerroProto').prop('checked', true);
|
||||
$('#dirFerroProto').prop('disabled', true);
|
||||
$('#add_cantidad').attr('disabled', true);
|
||||
$('#add_cantidad').val(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
newAddDialog.modal('show');
|
||||
}
|
||||
|
||||
|
||||
|
||||
get_peso_libro() {
|
||||
|
||||
var peso_total_libro = 0.0
|
||||
@ -277,11 +315,12 @@ class Envios {
|
||||
margen: data.margen,
|
||||
proveedor: data.proveedor,
|
||||
proveedor_id: data.proveedor_id,
|
||||
entregaPieCalle: data.entregaPieCalle
|
||||
entregaPieCalle: data.entregaPieCalle,
|
||||
is_ferro_prototipo: data.is_ferro_prototipo,
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -379,11 +418,14 @@ class Envios {
|
||||
'precio': datos_tarifa.precio.toFixed(2),
|
||||
'margen': datos_tarifa.margen,
|
||||
'entregaPieCalle': rowData.entregaPieCalle,
|
||||
'is_ferro_prototipo': rowData.is_ferro_prototipo,
|
||||
'actionBtns_direcciones': self.actionBtns_direcciones,
|
||||
})
|
||||
.draw();
|
||||
|
||||
|
||||
self.check_unidades_enviadas(null,null);
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
@ -566,6 +608,7 @@ class Envios {
|
||||
'precio': tarifa_final.precio,
|
||||
'margen': tarifa_final.margen,
|
||||
'entregaPieCalle': $('#add_entregaPieCalle').is(":checked") ? 1 : 0,
|
||||
'is_ferro_prototipo': $('#dirFerroProto').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>
|
||||
@ -673,8 +716,12 @@ class Envios {
|
||||
}
|
||||
|
||||
let cantidad_total = 0
|
||||
let hasFerroPrototipo = false
|
||||
this.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
cantidad_total += parseInt(this.data().cantidad)
|
||||
if (this.data().is_ferro_prototipo == 0)
|
||||
cantidad_total += parseInt(this.data().cantidad);
|
||||
else
|
||||
hasFerroPrototipo = true;
|
||||
});
|
||||
|
||||
const tirada = parseInt($('#tirada').val());
|
||||
@ -695,7 +742,11 @@ class Envios {
|
||||
this.insertarEnvio.removeClass('d-none');
|
||||
return false;
|
||||
}
|
||||
this.insertarEnvio.addClass('d-none');
|
||||
|
||||
if (($('#ferro').is(':checked') || $('#prototipo').is(':checked')) && !hasFerroPrototipo)
|
||||
this.insertarEnvio.removeClass('d-none');
|
||||
else
|
||||
this.insertarEnvio.addClass('d-none');
|
||||
$('#alert-envios').html(htmlString);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user