mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en los envios
This commit is contained in:
@ -0,0 +1,56 @@
|
||||
// Funcion para obtener el peso total del libro
|
||||
function get_peso_libro(){
|
||||
|
||||
var peso_total_libro = 0.0
|
||||
$('#tableLineasPresupuesto').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
peso_total_libro += parseFloat(rowData.peso)
|
||||
})
|
||||
return peso_total_libro;
|
||||
}
|
||||
|
||||
|
||||
async function get_precio_envio(peso, paisId, cp, tipo_envio){
|
||||
|
||||
data = {
|
||||
tipo: 'get_tarifa',
|
||||
peso: peso,
|
||||
paisId: paisId,
|
||||
cp: cp,
|
||||
tipo_envio: tipo_envio,
|
||||
}
|
||||
data = Object.assign(data, window.token_ajax);
|
||||
|
||||
|
||||
const response = await fetch(window.location.origin + window.url_get_precio_envio , {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
}
|
||||
})
|
||||
const values = await response.json();
|
||||
yeniden(values[window.csrf_token]);
|
||||
console.log(values.data);
|
||||
return values.data;
|
||||
}
|
||||
|
||||
async function get_coste_envio_tiradasAlternativas(tirada){
|
||||
|
||||
var peso_libro = get_peso_libro();
|
||||
var tirada_inicial = parseInt($('#tirada').val());
|
||||
var precio_envio = 0.0;
|
||||
var margen_envio = 0.0;
|
||||
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
const rowData = this.data();
|
||||
const porcentaje = parseInt(rowData.cantidad)/tirada_inicial*100.0;
|
||||
const cantidad = Math.floor(tirada*porcentaje/100.0);
|
||||
const precio_linea = get_precio_envio(cantidad*peso_libro/1000.0, rowData.paisId, rowData.cp, parseInt(rowData.entregaPieCalle)==1?'palets':'cajas');
|
||||
console.log(precio_linea);
|
||||
precio_envio += parseFloat(precio_linea.precio);
|
||||
margen_envio += parseFloat(precio_linea.precio*precio_linea.margen/100.0);
|
||||
})
|
||||
return {precio_envio, margen_envio};
|
||||
|
||||
}
|
||||
@ -90,89 +90,74 @@ const actionBtns_direcciones = function(data) {
|
||||
`;
|
||||
};
|
||||
|
||||
function updateTablaEnvios(){
|
||||
async function updateTablaEnvios(){
|
||||
|
||||
var peso_total_libro = 0
|
||||
tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
peso_total_libro += parseFloat(rowData.peso)
|
||||
|
||||
})
|
||||
var peso_total_libro = get_peso_libro();
|
||||
|
||||
tableEnvios.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
|
||||
var rowData = this.data();
|
||||
const peso_envio = peso_total_libro*parseInt(rowData.cantidad)/1000.0
|
||||
const peso_envio = peso_total_libro*parseInt(rowData.cantidad)/1000.0;
|
||||
|
||||
const data = get_precio_envio(peso_envio, rowData.paisId, rowData.cp, parseInt(rowData.entregaPieCalle)==1?'palets':'cajas');
|
||||
|
||||
$.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)
|
||||
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);
|
||||
}
|
||||
else{
|
||||
popErrorAlert('<?= lang('PresupuestosDirecciones.validation.no_tarifa') ?>', 'error-tarifa')
|
||||
// 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')
|
||||
}
|
||||
/**
|
||||
* @var mixed })
|
||||
*/
|
||||
})
|
||||
}
|
||||
|
||||
$(document).on('click', '.delete-add-row', function(e) {
|
||||
@ -411,5 +396,6 @@ function load_datos_envios(){
|
||||
}
|
||||
|
||||
|
||||
window.url_get_precio_envio = '<?= route_to('processDataDirecciones') ?>';
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@ -0,0 +1,266 @@
|
||||
/****************************************************************************************
|
||||
* Seccion para los servicios de acabado
|
||||
***************************************************************************************/
|
||||
function get_datos_acabado(){
|
||||
|
||||
var datosAcabado = []
|
||||
if($('#tableOfServiciosAcabado').DataTable().rows().count()>0){
|
||||
$("#tableOfServiciosAcabado tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 1:
|
||||
if($(this).text().includes(' '+ lang_text_cubierta))
|
||||
values['cubierta'] = 1
|
||||
else
|
||||
values['cubierta'] = 0
|
||||
if($(this).text().includes(' '+ lang_text_sobrecubierta))
|
||||
values['sobrecubierta'] = 1
|
||||
else
|
||||
values['sobrecubierta'] = 0
|
||||
break
|
||||
case 2:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 3:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 4:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosAcabado.push(values)
|
||||
})
|
||||
}
|
||||
return datosAcabado
|
||||
}
|
||||
|
||||
|
||||
async function get_servAcabados_tiradasAlternativas(tirada){
|
||||
serviciosAcabados ={
|
||||
coste: 0.0,
|
||||
margen: 0.0,
|
||||
}
|
||||
json_data = {
|
||||
datos: get_datos_acabado(),
|
||||
tirada: parseInt(tirada),
|
||||
POD: $('#POD').val()
|
||||
}
|
||||
json_data = Object.assign(json_data, window.token_ajax);
|
||||
|
||||
const response = await fetch(window.location.origin + "/presupuestos/presupuestoacabados/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify(json_data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
const values = await response.json();
|
||||
yeniden(values[window.csrf_token]);
|
||||
values.lines.forEach((line) => {
|
||||
|
||||
serviciosAcabados.coste += parseFloat(line[0].total);
|
||||
serviciosAcabados.margen += parseFloat(line[0].total)*parseFloat(line[0].margen)/100.0;
|
||||
});
|
||||
return serviciosAcabados;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Seccion para los servicios de encuadernación
|
||||
***************************************************************************************/
|
||||
function get_datos_encuadernacion(){
|
||||
|
||||
var datosEnc = []
|
||||
if($("#tableOfServiciosEncuadernacion").DataTable().rows().count()>0){
|
||||
$("#tableOfServiciosEncuadernacion tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['proveedor_id'] = $(this).children(":first").select2('data')[0].id
|
||||
break
|
||||
case 3:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 4:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 5:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosEnc.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosEnc
|
||||
}
|
||||
|
||||
|
||||
async function get_servEncuadernacion_tiradasAlternativas(tirada, paginas, ancho, alto){
|
||||
serviciosEncuadernacion ={
|
||||
coste: 0.0,
|
||||
margen: 0.0,
|
||||
}
|
||||
json_data = {
|
||||
datos: get_datos_encuadernacion(),
|
||||
tirada: parseInt(tirada),
|
||||
paginas: parseInt(paginas),
|
||||
ancho: ancho,
|
||||
alto: alto,
|
||||
POD: $('#POD').val()
|
||||
}
|
||||
json_data = Object.assign(json_data, window.token_ajax);
|
||||
|
||||
const response = await fetch(window.location.origin + "/presupuestos/presupuestoencuadernaciones/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify(json_data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
const values = await response.json();
|
||||
yeniden(values[window.csrf_token]);
|
||||
values.lines.forEach((line) => {
|
||||
serviciosEncuadernacion.coste += parseFloat(line[0].total);
|
||||
serviciosEncuadernacion.margen += parseFloat(line[0].total)*parseFloat(line[0].margen)/100.0;
|
||||
});
|
||||
return serviciosEncuadernacion;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Seccion para los servicios de manipulado
|
||||
***************************************************************************************/
|
||||
function get_datos_manipulado(){
|
||||
|
||||
var datosManipulado = []
|
||||
if($("#tableOfServiciosManipulado").DataTable().rows().count()>0){
|
||||
|
||||
$("#tableOfServiciosManipulado tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 3:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 4:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosManipulado.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosManipulado
|
||||
}
|
||||
|
||||
|
||||
async function get_servManipulado_tiradasAlternativas(tirada){
|
||||
serviciosManipulado ={
|
||||
coste: 0.0,
|
||||
margen: 0.0,
|
||||
}
|
||||
json_data = {
|
||||
datos: get_datos_manipulado(),
|
||||
tirada: parseInt(tirada),
|
||||
POD: $('#POD').val()
|
||||
}
|
||||
json_data = Object.assign(json_data, window.token_ajax);
|
||||
|
||||
const response = await fetch(window.location.origin + "/presupuestos/presupuestomanipulados/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify(json_data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
const values = await response.json();
|
||||
yeniden(values[window.csrf_token]);
|
||||
values.lines.forEach((line) => {
|
||||
serviciosManipulado.coste += parseFloat(line[0].total);
|
||||
serviciosManipulado.margen += parseFloat(line[0].total)*parseFloat(line[0].margen)/100.0;
|
||||
});
|
||||
return serviciosManipulado;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Seccion para los servicios de preimpresión
|
||||
***************************************************************************************/
|
||||
function get_datos_preimpresion(){
|
||||
|
||||
var datosPreimpresion = []
|
||||
if($("#tableOfServiciosPreimpresion").DataTable().rows().count()>0){
|
||||
|
||||
$("#tableOfServiciosPreimpresion tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['precio'] = $(this).children(":first").val()
|
||||
break
|
||||
case 3:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosPreimpresion.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosPreimpresion
|
||||
}
|
||||
|
||||
async function get_servPreimpresion_tiradasAlternativas(){
|
||||
serviciosPreimpresion ={
|
||||
coste: 0.0,
|
||||
margen: 0.0,
|
||||
}
|
||||
json_data = {
|
||||
datos: get_datos_preimpresion(),
|
||||
POD: $('#POD').val()
|
||||
}
|
||||
json_data = Object.assign(json_data, window.token_ajax);
|
||||
|
||||
const response = await fetch(window.location.origin + "/presupuestos/presupuestopreimpresiones/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify(json_data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
const values = await response.json();
|
||||
yeniden(values[window.csrf_token]);
|
||||
values.lines.forEach((line) => {
|
||||
serviciosPreimpresion.coste += parseFloat(line[0].total);
|
||||
serviciosPreimpresion.margen += parseFloat(line[0].total)*parseFloat(line[0].margen)/100.0;
|
||||
});
|
||||
return serviciosPreimpresion;
|
||||
}
|
||||
@ -710,47 +710,7 @@
|
||||
}
|
||||
|
||||
|
||||
function get_datos_acabado(){
|
||||
|
||||
var datosAcabado = []
|
||||
if(tableServiciosAcabado.rows().count()>0){
|
||||
$("#tableOfServiciosAcabado tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 1:
|
||||
if($(this).text().includes(' (<?= lang("Presupuestos.cubierta") ?>)'))
|
||||
values['cubierta'] = 1
|
||||
else
|
||||
values['cubierta'] = 0
|
||||
if($(this).text().includes(' (<?= lang("Presupuestos.sobrecubierta") ?>)'))
|
||||
values['sobrecubierta'] = 1
|
||||
else
|
||||
values['sobrecubierta'] = 0
|
||||
break
|
||||
case 2:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 3:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 4:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosAcabado.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosAcabado
|
||||
}
|
||||
|
||||
|
||||
init_servicio_acabado()
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@ -1026,41 +986,6 @@
|
||||
check_serv_enc_error()
|
||||
})
|
||||
|
||||
function get_datos_encuadernacion(){
|
||||
|
||||
var datosEnc = []
|
||||
if(tableServiciosEnc.rows().count()>0){
|
||||
$("#tableOfServiciosEncuadernacion tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['proveedor_id'] = $(this).children(":first").select2('data')[0].id
|
||||
break
|
||||
case 3:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 4:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 5:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosEnc.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosEnc
|
||||
}
|
||||
|
||||
|
||||
init_servicio_encuadernado()
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@ -1200,38 +1125,7 @@
|
||||
check_serv_manipulado_error()
|
||||
})
|
||||
|
||||
function get_datos_manipulado(){
|
||||
|
||||
var datosManipulado = []
|
||||
if(tableServiciosManipulado.rows().count()>0){
|
||||
|
||||
$("#tableOfServiciosManipulado tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['precio_unidad'] = $(this).text()
|
||||
break
|
||||
case 3:
|
||||
values['precio_total'] = $(this).children(":first").val()
|
||||
break
|
||||
case 4:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosManipulado.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosManipulado
|
||||
}
|
||||
|
||||
|
||||
function servicioGuardas(add_service = false){
|
||||
if(add_service){
|
||||
$('#add_servicio_manipulado_list').val(<?php echo $serviciosAutomaticos['plegadoGuardas'] ?>)
|
||||
@ -1403,35 +1297,12 @@
|
||||
check_serv_preimpresion_error()
|
||||
})
|
||||
|
||||
function get_datos_preimpresion(){
|
||||
|
||||
var datosPreimpresion = []
|
||||
if(tableServiciosPreimpresion.rows().count()>0){
|
||||
|
||||
$("#tableOfServiciosPreimpresion tr").each(function (index,tr) {
|
||||
var values = {}
|
||||
$(this).find("td").each(function (index2) {
|
||||
|
||||
switch (index2) {
|
||||
case 0:
|
||||
values['tarifa_id'] = $(this).text()
|
||||
break
|
||||
case 2:
|
||||
values['precio'] = $(this).children(":first").val()
|
||||
break
|
||||
case 3:
|
||||
values['margen'] = $(this).text()
|
||||
break
|
||||
}
|
||||
})
|
||||
if(Object.keys(values).length>0)
|
||||
datosPreimpresion.push(values)
|
||||
})
|
||||
}
|
||||
|
||||
return datosPreimpresion
|
||||
}
|
||||
|
||||
|
||||
init_servicio_preimpresion()
|
||||
|
||||
|
||||
// Definición de varibles para el js (actualizar el lang)
|
||||
lang_text_cubierta = '<?= lang("Presupuestos.cubierta") ?>';
|
||||
lang_text_sobrecubierta = '<?= lang("Presupuestos.sobrecubierta") ?>';
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
@ -14,6 +14,7 @@ const actionBtns_tiradasAlt = function (data) {
|
||||
var tableTiradas;
|
||||
|
||||
|
||||
// Espera a que todas las variables necesarias estén definidas
|
||||
(async () => {
|
||||
|
||||
while (!window.hasOwnProperty("datatable_lang_url") && !window.hasOwnProperty("datatable_TA_url"))
|
||||
@ -29,16 +30,18 @@ var tableTiradas;
|
||||
total_pedido: 0,
|
||||
precio_unidad: 0
|
||||
}).draw(false);
|
||||
|
||||
})();
|
||||
|
||||
|
||||
// Evento de añadir una tirada alternativa
|
||||
$('#add_tirada_alt').on('click', function () {
|
||||
|
||||
const dimension = getDimensionLibro();
|
||||
|
||||
let datos = {
|
||||
tirada: $('#tirada_alt').val(),
|
||||
merma: 20, ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>calcular merma
|
||||
merma: get_merma_tirada_alternativa($('#tirada_alt').val()),
|
||||
tipo_impresion_id: $('#tipo_impresion_id').val(),
|
||||
json_tiradas: generate_json_tiradas(),
|
||||
ancho: dimension.ancho,
|
||||
@ -53,32 +56,66 @@ $('#add_tirada_alt').on('click', function () {
|
||||
|
||||
datos = Object.assign(datos, window.token_ajax);
|
||||
|
||||
// Se realiza la petición AJAX
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: window.get_tirada_url,
|
||||
data: datos,
|
||||
success: function (data) {
|
||||
success: async function (data) {
|
||||
|
||||
var coste_total = 0.0;
|
||||
var margen_total = 0.0;
|
||||
|
||||
var costes_servicios = 0.0;
|
||||
var margen_servicios = 0.0;
|
||||
|
||||
if(data.lineas.length >0){
|
||||
// Se cogen los valores de la linea con los datos correspondientes
|
||||
$.each(data.lineas, function(key, value) {
|
||||
|
||||
console.log(value);
|
||||
coste_total += value.total_coste;
|
||||
margen_total += value.total_margen;
|
||||
});
|
||||
|
||||
// Se obtiene el precio de los servicios
|
||||
const valueAcabados = await get_servAcabados_tiradasAlternativas(parseInt(datos.tirada));
|
||||
costes_servicios += valueAcabados.coste;
|
||||
margen_servicios += valueAcabados.margen;
|
||||
|
||||
}
|
||||
else{
|
||||
const valueEncuadernacion = await get_servEncuadernacion_tiradasAlternativas(
|
||||
parseInt(datos.tirada), parseInt( $('#paginas').val()), parseInt(dimension.ancho), parseInt(dimension.alto));
|
||||
costes_servicios += valueEncuadernacion.coste;
|
||||
margen_servicios += valueEncuadernacion.margen;
|
||||
|
||||
const valueManipulado = await get_servManipulado_tiradasAlternativas(parseInt(datos.tirada));
|
||||
costes_servicios += valueManipulado.coste;
|
||||
margen_servicios += valueManipulado.margen;
|
||||
|
||||
const valuePreimpresion = await get_servPreimpresion_tiradasAlternativas(parseInt(datos.tirada));
|
||||
costes_servicios += valuePreimpresion.coste;
|
||||
margen_servicios += valuePreimpresion.margen;
|
||||
|
||||
const valueTransporte = await get_coste_envio_tiradasAlternativas(parseInt(datos.tirada));
|
||||
|
||||
console.log(coste_total);
|
||||
console.log(margen_total);
|
||||
console.log(costes_servicios);
|
||||
console.log(margen_servicios);
|
||||
console.log(valueTransporte);
|
||||
}
|
||||
|
||||
yeniden(data[window.csrf_token]);
|
||||
|
||||
},
|
||||
error: function(e){
|
||||
|
||||
}
|
||||
error: function(e){}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Función para obtener el lomo exterior
|
||||
function getLomoExterior(){
|
||||
let lomoTotal = 0
|
||||
try{
|
||||
@ -94,6 +131,7 @@ function getLomoExterior(){
|
||||
return lomoTotal
|
||||
}
|
||||
|
||||
|
||||
// Inicialización de la tabla de tiradas
|
||||
function initTableTiradas() {
|
||||
tableTiradas = $('#tableTiradas').DataTable({
|
||||
@ -185,4 +223,35 @@ function filterData(data, keys) {
|
||||
});
|
||||
return newObj;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Función para obtener la merma de la tirada alternativa
|
||||
function get_merma_tirada_alternativa(tirada){
|
||||
|
||||
var merma = 0
|
||||
|
||||
if(tirada>parseInt($('#POD').val())){
|
||||
|
||||
merma = tirada*0.1<=30 ? tirada*0.1 : 30
|
||||
}
|
||||
else{
|
||||
merma_lineas = []
|
||||
$('#tableLineasPresupuesto').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
if(rowData.row_id != 'lp_guardas' && rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta'){
|
||||
const formas_linea = $('#isCosido').val()==0?parseInt(rowData.formas):parseInt(rowData.formas)/2
|
||||
if(formas_linea > tirada)
|
||||
merma_lineas.push(formas_linea-tirada)
|
||||
else
|
||||
merma_lineas.push(tirada%formas_linea)
|
||||
}
|
||||
})
|
||||
|
||||
if(merma_lineas.length>0)
|
||||
merma = Math.max(...merma_lineas)
|
||||
else
|
||||
merma = 0
|
||||
}
|
||||
return merma;
|
||||
}
|
||||
@ -54,11 +54,7 @@
|
||||
|
||||
window.datatable_TA_url = "<?= route_to('dataTableOfPresupuestoTiradasAlternativas') ?>";
|
||||
window.get_tirada_url = "<?= route_to('getTiradaData') ?>";
|
||||
|
||||
window.token_ajax= {<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v};
|
||||
|
||||
window.csrf_token = '<?= csrf_token() ?>';
|
||||
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
|
||||
@ -15,6 +15,10 @@
|
||||
<?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
|
||||
<input type="hidden" name="tipo_impresion_id" id="tipo_impresion_id" class="form-control"
|
||||
value="<?= $tipo_impresion_id ?>"></input>
|
||||
<input type="hidden" name="isCosido" id="isCosido" class="form-control"
|
||||
value="<?= $isCosido ?>"></input>
|
||||
<input type="hidden" name="POD" id="POD" class="form-control"
|
||||
value="<?= $POD ?>"></input>
|
||||
<?= view("themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosPresupuestoItems") ?>
|
||||
<?= view("themes/backend/vuexy/form/presupuestos/cosidotapablanda/_datosLibroItems") ?>
|
||||
<?php if (str_contains($formAction, 'edit')): ?>
|
||||
@ -227,9 +231,22 @@ const url_parts = url.split('/');
|
||||
return false; //stop the actual form post !important!
|
||||
});
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Variables generales usadas en los ficheros js -->
|
||||
<!------------------------------------------->
|
||||
<?php if (str_contains($formAction, 'edit')): ?>
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
|
||||
window.token_ajax= {<?= csrf_token() ?? "token" ?>: <?= csrf_token() ?>v};
|
||||
window.csrf_token = '<?= csrf_token() ?>';
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -251,6 +268,8 @@ const url_parts = url.split('/');
|
||||
<script src="<?= site_url('js_loader/comparadorCosidoTapaBlanda_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/previsualizador_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/tiradasAlternativas_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/datosServicios_js') ?>"></script>
|
||||
<script src="<?= site_url('js_loader/datosEnvios_js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/two/two.js') ?>"></script>
|
||||
<?php endif; ?>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
Reference in New Issue
Block a user