finalizado datos envios

This commit is contained in:
2023-12-19 22:43:22 +01:00
parent 9e97329abf
commit f2a0d4fb16
11 changed files with 409 additions and 59 deletions

View File

@ -10,29 +10,34 @@
<div class="accordion-body">
<?= view("themes/backend/vuexy/form/presupuestos/cosidotapablanda/_presupuestoDireccionesForm") ?>
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-4" style="width: 100%;">
<thead>
<tr>
<th><?= lang('PresupuestosDirecciones.cantidad') ?></th>
<th><?= lang('PresupuestosDirecciones.peso') ?></th>
<th><?= lang('PresupuestosDirecciones.att') ?></th>
<th><?= lang('PresupuestosDirecciones.email') ?></th>
<th><?= lang('PresupuestosDirecciones.direccion') ?></th>
<th><?= lang('PresupuestosDirecciones.cp') ?></th>
<th><?= lang('PresupuestosDirecciones.municipio') ?></th>
<th><?= lang('PresupuestosDirecciones.provincia') ?></th>
<th><?= lang('PresupuestosDirecciones.ccaa') ?></th>
<th><?= lang('PresupuestosDirecciones.pais') ?></th>
<th><?= lang('PresupuestosDirecciones.telefono') ?></th>
<th><?= lang('PresupuestosDirecciones.precio') ?></th>
<th></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id='rowTable' class='row'>
<table id="tableOfDireccionesEnvio" class="table dt-responsive dataTable px-4" style="width: 95%;">
<thead>
<tr>
<th class="lp-header">Tarifa_id</th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.cantidad') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.peso') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.att') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.email') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.direccion') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.cp') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.municipio') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.provincia') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.ccaa') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.pais') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.telefono') ?></th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.proveedor') ?></th>
<th>Proveedor_id</th>
<th class="lp-header"><?= lang('PresupuestosDirecciones.precio') ?></th>
<th>Margen</th>
<th class="lp-header"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-12 col-lg-4 px-4 py-2">
@ -41,7 +46,7 @@
</div>
</div>
<div class="row">
<div id="rowInsertar" class="row">
<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>
</div>
@ -57,6 +62,7 @@
<?= $this->section("additionalInlineJs") ?>
$('#insertar_direccion').on('click', function(){
$("#addressForm").attr('action','create')
var $newAddDialog = $("#addressForm")
var maximaCantidad = parseInt($('#tirada').val())
@ -65,22 +71,54 @@ $('#insertar_direccion').on('click', function(){
$("#add_cantidad").on('change', function(){
$("#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')
})
const lastColNr = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
const lastColNr_direcciones = $('#tableOfDireccionesEnvio').find("tr:first th").length - 1;
const actionBtns_direcciones = function(data) {
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 btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm delete-add-row mx-2"></i></a>
`;
};
$(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( {
draw:5,
serverSide: true,
serverSide: false,
processing: true,
autoWidth: true,
responsive: true,
@ -90,17 +128,10 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
searching: false,
paging: 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: [
{ 'data': 'tarifa_id' },
{ 'data': 'cantidad' },
{ 'data': 'peso' },
{ 'data': 'att' },
@ -109,9 +140,21 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
{ 'data': 'cp' },
{ 'data': 'municipio' },
{ 'data': 'provincia' },
{ 'data': 'ccaaId' },
{ 'data': 'paisId' },
{ 'data': 'ccaaId' ,
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': 'proveedor'},
{ 'data': 'proveedor_id'},
{ 'data': 'precio' },
{ 'data': 'margen' },
{
@ -123,14 +166,118 @@ var tableEnvios = $('#tableOfDireccionesEnvio').DataTable( {
{
orderable: false,
searchable: false,
targets: [lastColNr]
targets: [lastColNr_direcciones]
},
{"orderData": [ 0], "targets": 0 },
],
columnDefs: [
{
target: [0,13,15],
visible: false,
searchable: false
},
],
language: {
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() ?>

View File

@ -286,12 +286,12 @@ $('#paginas').on("change", function () {
document.getElementById('compPaginasColorhq').value = 0;
}
update_servicios()
update_servicios(false)
});
$('#tirada').on("change", function () {
update_servicios()
update_servicios(false)
})
$('#papelFormatoId').select2({

View File

@ -367,7 +367,7 @@
)
}
function update_servicios(){
function update_servicios(update_preimpresion=false){
const domain = window.location.origin
const dimension = getDimensionLibro();
@ -382,7 +382,8 @@
var datosAcabado = get_datos_acabado()
var datosEnc = get_datos_encuadernacion()
var datosManipulado = get_datos_manipulado()
var datosPreimpresion = get_datos_preimpresion()
if(update_preimpresion)
var datosPreimpresion = get_datos_preimpresion()
fetch(domain + "/presupuestos/presupuestoacabados/update/" + id , {
method: "POST",
@ -471,10 +472,12 @@
})
.then(response => response.json())
.then(data => {
data.lines.forEach((line) => {
$('#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))
});
if(update_preimpresion){
data.lines.forEach((line) => {
$('#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() ?>);
})
)

View File

@ -6,6 +6,7 @@
</div>
<div class="modal-body">
<div id='error-tarifa'></div>
<div class="mb-3">
<label for="add_clientedAdd" class="form-label">
<?=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(){
if(validate_fields()){
@ -182,16 +189,88 @@ $('#saveDireccionEnvio').on('click', function(){
peso: peso_envio,
paisId: $("#add_pais_id").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 ) {
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_cp').val("")
$('#add_telefono').val("")
$('#add_saveDirection').prop('checked', false)
})
<?=$this->endSection() ?>

View File

@ -131,6 +131,9 @@ else{
$('#presupuestoForm').on( "submit", function( event ) {
event.preventDefault();
save_servicios();
save_datos_envios();
$.when(fill_bbdd_from_lp(id).then(function (data, textStatus, jqXHR){
generateCompJSON()
form = $('#presupuestoForm').serialize()