mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en guardar
This commit is contained in:
@ -9,6 +9,7 @@ import PreviewFormasAdmin from './sections/previewFormasAdmin.js';
|
||||
import Servicios from './sections/servicios.js';
|
||||
import Envios from './sections/envios.js';
|
||||
import TiradasAlernativas from './sections/tiradasAlternativas.js';
|
||||
import Resumen from './sections/resumen.js';
|
||||
|
||||
class PresupuestoAdminEdit {
|
||||
|
||||
@ -44,6 +45,10 @@ class PresupuestoAdminEdit {
|
||||
this.tiradasAlternativas = new TiradasAlernativas({
|
||||
getDimensionLibro: this.getDimensionLibro,
|
||||
});
|
||||
this.resumen = new Resumen();
|
||||
|
||||
this.guardar = $('#saveForm');
|
||||
|
||||
this.calcularPresupuesto = false;
|
||||
}
|
||||
|
||||
@ -89,6 +94,7 @@ class PresupuestoAdminEdit {
|
||||
this.servicios.init();
|
||||
this.envios.init();
|
||||
this.tiradasAlternativas.init();
|
||||
this.resumen.init();
|
||||
|
||||
if (window.location.href.includes("edit")) {
|
||||
|
||||
@ -103,8 +109,62 @@ class PresupuestoAdminEdit {
|
||||
}
|
||||
}
|
||||
this.downloadPreviewImage();
|
||||
|
||||
$(document).on('update-presupuesto', this.updatePresupuesto.bind(this));
|
||||
|
||||
this.guardar.on('click', this.guardarPresupuesto.bind(this));
|
||||
}
|
||||
|
||||
|
||||
guardarPresupuesto() {
|
||||
|
||||
this.servicios.guardar();
|
||||
}
|
||||
|
||||
|
||||
async updatePresupuesto(event, {
|
||||
update_lineas = true,
|
||||
update_servicios = true,
|
||||
update_envios = true,
|
||||
update_resumen = true,
|
||||
update_tiradas_alternativas = true
|
||||
}) {
|
||||
const waitForEvent = (eventName) => {
|
||||
return new Promise((resolve) => {
|
||||
$(document).one(eventName, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Ejecutar los pasos de forma secuencial si están habilitados
|
||||
if (update_lineas) {
|
||||
$(document).trigger('update-lineas-presupuesto');
|
||||
await waitForEvent('update-lineas-presupuesto-completed');
|
||||
}
|
||||
|
||||
if (update_servicios) {
|
||||
$(document).trigger('update-servicios');
|
||||
await waitForEvent('update-servicios-completed');
|
||||
}
|
||||
|
||||
if (update_envios) {
|
||||
$(document).trigger('update-envios');
|
||||
await waitForEvent('update-envios-completed');
|
||||
}
|
||||
|
||||
if (update_resumen) {
|
||||
$(document).trigger('update-totales');
|
||||
await waitForEvent('update-totales-completed');
|
||||
}
|
||||
|
||||
if (update_tiradas_alternativas) {
|
||||
$(document).trigger('update-tiradas-alternativas');
|
||||
await waitForEvent('update-tiradas-alternativas-completed');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#cargarPresupuesto() {
|
||||
|
||||
const self = this;
|
||||
@ -140,14 +200,9 @@ class PresupuestoAdminEdit {
|
||||
$('#comentariosProduccion').val(response.data.comentarios_produccion);
|
||||
|
||||
self.tiradasAlternativas.cargar(response.data.tiradasAlternativas);
|
||||
|
||||
/*self.direcciones.handleChangeCliente();
|
||||
|
||||
self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);
|
||||
self.resumen.cargar(response.data.resumen);
|
||||
|
||||
self.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente);
|
||||
self.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta);
|
||||
*/
|
||||
setTimeout(() => {
|
||||
|
||||
$('#loader').modal('hide');
|
||||
@ -187,7 +242,7 @@ class PresupuestoAdminEdit {
|
||||
cantidad_total += parseInt(rowData.paginas)
|
||||
})
|
||||
htmlString = ''
|
||||
|
||||
|
||||
if (cantidad_total != parseInt($('#paginas').val())) {
|
||||
htmlString = `
|
||||
<div class="alert alert-warning d-flex align-items-baseline" role="alert">
|
||||
|
||||
@ -93,18 +93,6 @@ class DatosLibro {
|
||||
|
||||
this.paginas.on('change', this.changePaginas.bind(this));
|
||||
this.tirada.on('change', this.changeTirada.bind(this));
|
||||
|
||||
$('.formato-libro').on('change', function () {
|
||||
$(document).trigger('update-lineas-presupuesto');
|
||||
$(document).trigger('update-servicios');
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,14 +171,13 @@ class DatosLibro {
|
||||
|
||||
this.checkPaginasPresupuesto();
|
||||
|
||||
$(document).trigger('update-lineas-presupuesto');
|
||||
$(document).trigger('update-servicios');
|
||||
// TO-DO
|
||||
/*updatePresupuesto({
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : true,
|
||||
update_servicios : true,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})*/
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -273,17 +260,15 @@ class DatosLibro {
|
||||
$('#compPaginasNegrohq').trigger('change');
|
||||
}
|
||||
|
||||
$(document).trigger('update-lineas-presupuesto');
|
||||
$(document).trigger('update-servicios');
|
||||
|
||||
// TO-DO
|
||||
/*
|
||||
updatePresupuesto({
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : true,
|
||||
update_servicios : true,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})
|
||||
*/
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,29 +282,8 @@ class DatosLibro {
|
||||
|
||||
if (url_parts2[url_parts2.length - 2] == 'edit') {
|
||||
$(document).trigger('update-lineas-presupuesto');
|
||||
//update_servicios(false)
|
||||
//updateLineasPresupuesto()
|
||||
|
||||
/* TO-DO
|
||||
if(update_tiradas_alternativas)
|
||||
updatePresupuesto({
|
||||
update_lineas: true,
|
||||
update_servicios: false,
|
||||
update_envios: false,
|
||||
update_resumen: false,
|
||||
update_tiradas_alternativas: false
|
||||
})
|
||||
else
|
||||
updatePresupuesto({
|
||||
update_lineas: true,
|
||||
update_servicios: false,
|
||||
update_envios: false,
|
||||
update_resumen: false,
|
||||
update_tiradas_alternativas: false
|
||||
})
|
||||
|
||||
checkInsertar()
|
||||
*/
|
||||
|
||||
$(document).trigger('ckeck-lineas-envios');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,16 @@ class Envios {
|
||||
this.modalYesNo = null;
|
||||
|
||||
this.insertarEnvio = $('#insertar_direccion');
|
||||
|
||||
this.actionBtns_direcciones = function (data) {
|
||||
return `
|
||||
<span class="edit-add"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit-add mx-2" data-id="${data.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>
|
||||
`;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
@ -91,6 +99,15 @@ class Envios {
|
||||
});
|
||||
}
|
||||
|
||||
// obtener la suma del precio de los envios
|
||||
let total = 0;
|
||||
self.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let data = this.data();
|
||||
total += parseFloat(data.precio);
|
||||
});
|
||||
|
||||
$("#costeEnvios").text(total.toFixed(2) + "€" || "0€");
|
||||
|
||||
self.check_unidades_enviadas();
|
||||
}
|
||||
|
||||
@ -168,6 +185,15 @@ class Envios {
|
||||
this.insertarEnvio.on('click', this.addEnvio.bind(this));
|
||||
|
||||
this.initFormularioDireccionEnvio();
|
||||
|
||||
$(document).on('update-envios', async function () {
|
||||
|
||||
await self.updateTablaEnvios();
|
||||
|
||||
$(document).trigger('update-envios-completed');
|
||||
|
||||
});
|
||||
$(document).on('ckeck-lineas-envios', this.check_unidades_enviadas.bind(this));
|
||||
}
|
||||
|
||||
addEnvio() {
|
||||
@ -193,6 +219,189 @@ class Envios {
|
||||
newAddDialog.modal('show');
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
guardarEnvios() {
|
||||
/* TO-DO
|
||||
var id = $('#presupuesto_id').val()
|
||||
|
||||
$.post(window.routes_envios.dataTableOfPresupuestoDirecciones,
|
||||
Object.assign({ tipo: "clear_lineas", presupuesto_id: id }, window.token_ajax))
|
||||
.done(function (data) {
|
||||
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var data = this.data();
|
||||
$.post('/presupuestos/presupuestodirecciones/add',
|
||||
Object.assign({
|
||||
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,
|
||||
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,
|
||||
entregaPieCalle: data.entregaPieCalle
|
||||
}, window.token_ajax))
|
||||
});
|
||||
|
||||
})
|
||||
*/
|
||||
}
|
||||
|
||||
async updateTiradaBase() {
|
||||
|
||||
const self = this;
|
||||
var peso_total_libro = this.get_peso_libro();
|
||||
|
||||
const tirada = parseInt($('#tirada').val());
|
||||
const peso_envio = peso_total_libro * tirada / 1000.0;
|
||||
|
||||
let pais = 1;
|
||||
let cp = 18000;
|
||||
let entrega = 'cajas';
|
||||
|
||||
var datos_tarifa = await self.get_precio_envio(peso_envio, pais, cp, entrega);
|
||||
|
||||
if (datos_tarifa.id != null) {
|
||||
|
||||
if (peso_envio > parseFloat(datos_tarifa.peso_max) || parseFloat(datos_tarifa.peso_max) == 0) {
|
||||
datos_tarifa.precio = parseFloat(datos_tarifa.peso_min) + (peso_envio - parseFloat(datos_tarifa.peso_min)) * parseFloat(datos_tarifa.precio_adicional);
|
||||
}
|
||||
// si no se calcula linealmente
|
||||
else {
|
||||
let m = ((parseFloat(datos_tarifa.precio_max) - parseFloat(datos_tarifa.precio_min)) / (parseFloat(datos_tarifa.peso_max) - parseFloat(datos_tarifa.peso_min)));
|
||||
let b = parseFloat(datos_tarifa.precio_max) - m * parseFloat(datos_tarifa.peso_max);
|
||||
datos_tarifa.precio = parseFloat(m * peso_envio + b);
|
||||
}
|
||||
|
||||
$('#envio_base').val(datos_tarifa.precio.toFixed(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async updateTablaEnvios(event, input_data = {}) {
|
||||
|
||||
const self = this;
|
||||
var peso_total_libro = this.get_peso_libro();
|
||||
|
||||
await self.updateTiradaBase();
|
||||
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every(async function (rowIdx, tableLoop, rowLoop) {
|
||||
|
||||
var rowData = this.data();
|
||||
|
||||
if (Object.keys(input_data).length > 0) {
|
||||
const porcentaje = parseInt(rowData.cantidad) / input_data.tirada_inicial * 100.0;
|
||||
const cantidad = Math.floor(input_data.tirada * porcentaje / 100.0);
|
||||
rowData.cantidad = cantidad;
|
||||
}
|
||||
|
||||
const peso_envio = peso_total_libro * parseInt(rowData.cantidad) / 1000.0;
|
||||
const tirada = parseInt($('#tirada').val());
|
||||
var datos_tarifa = await self.get_precio_envio(peso_envio, rowData.pais_id, rowData.cp, parseInt(rowData.entregaPieCalle) == 1 ? 'palets' : 'cajas');
|
||||
|
||||
|
||||
if (datos_tarifa.id != null) {
|
||||
|
||||
if (peso_envio > parseFloat(datos_tarifa.peso_max) || parseFloat(datos_tarifa.peso_max) == 0) {
|
||||
datos_tarifa.precio = parseFloat(datos_tarifa.peso_min) + (peso_envio - parseFloat(datos_tarifa.peso_min)) * parseFloat(datos_tarifa.precio_adicional);
|
||||
}
|
||||
// si no se calcula linealmente
|
||||
else {
|
||||
let m = ((parseFloat(datos_tarifa.precio_max) - parseFloat(datos_tarifa.precio_min)) / (parseFloat(datos_tarifa.peso_max) - parseFloat(datos_tarifa.peso_min)));
|
||||
let b = parseFloat(datos_tarifa.precio_max) - m * parseFloat(datos_tarifa.peso_max);
|
||||
datos_tarifa.precio = parseFloat(m * peso_envio + b);
|
||||
}
|
||||
|
||||
|
||||
datos_tarifa.cantidad = parseInt($('#add_cantidad').val());
|
||||
datos_tarifa.peso = peso_envio;
|
||||
|
||||
$('#tableOfDireccionesEnvio').DataTable().row(rowIdx)
|
||||
.data({
|
||||
'tarifa_id': datos_tarifa.id,
|
||||
'cantidad': rowData.cantidad,
|
||||
'peso': datos_tarifa.peso.toFixed(3),
|
||||
'att': rowData.att,
|
||||
'email': rowData.email,
|
||||
'direccion': rowData.direccion,
|
||||
'cp': rowData.cp,
|
||||
'municipio': rowData.municipio,
|
||||
'provincia': rowData.provincia,
|
||||
'pais_id': rowData.pais_id,
|
||||
'pais': datos_tarifa.pais,
|
||||
'telefono': rowData.telefono,
|
||||
'proveedor': datos_tarifa.proveedor,
|
||||
'proveedor_id': datos_tarifa.proveedor_id,
|
||||
'precio': datos_tarifa.precio.toFixed(2),
|
||||
'margen': datos_tarifa.margen,
|
||||
'entregaPieCalle': rowData.entregaPieCalle,
|
||||
'actionBtns_direcciones': self.actionBtns_direcciones,
|
||||
})
|
||||
.draw();
|
||||
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
else {
|
||||
popErrorAlert(window.error_no_tarifa_envio, 'error-tarifa')
|
||||
}
|
||||
})
|
||||
|
||||
if (Object.keys(input_data).length > 0) {
|
||||
|
||||
$('#tirada').val(input_data.tirada);
|
||||
$('#tirada').trigger('change', [false]);
|
||||
}
|
||||
}
|
||||
|
||||
async get_precio_envio(peso, paisId, cp, tipo_envio) {
|
||||
|
||||
let data = {
|
||||
tipo: 'get_tarifa',
|
||||
peso: peso,
|
||||
paisId: paisId,
|
||||
cp: cp,
|
||||
tipo_envio: tipo_envio,
|
||||
}
|
||||
|
||||
const response = await fetch('/presupuestodirecciones/datatable_2', {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
}
|
||||
});
|
||||
|
||||
const values = await response.json();
|
||||
return values.data;
|
||||
}
|
||||
|
||||
initFormularioDireccionEnvio() {
|
||||
|
||||
const self = this;
|
||||
@ -363,17 +572,16 @@ class Envios {
|
||||
})
|
||||
}
|
||||
|
||||
/* TO-DO
|
||||
checkInsertar()
|
||||
//updateTotales(false, false, true)
|
||||
updatePresupuesto({
|
||||
update_lineas: false,
|
||||
update_servicios: true,
|
||||
$(document).trigger('ckeck-lineas-envios');
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : true,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})
|
||||
*/
|
||||
});
|
||||
|
||||
$('#addressForm').modal("hide");
|
||||
|
||||
}
|
||||
|
||||
@ -35,12 +35,15 @@ class LineasPresupuesto {
|
||||
.remove()
|
||||
.draw();
|
||||
|
||||
// TO-DO
|
||||
/*updatePresupuesto({
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas: false,
|
||||
update_servicios: false,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})
|
||||
});
|
||||
// TO-DO
|
||||
/*
|
||||
if (data.row_id == 'lp_guardas')
|
||||
servicioGuardas(false)
|
||||
*/
|
||||
@ -52,7 +55,12 @@ class LineasPresupuesto {
|
||||
});
|
||||
|
||||
// Evento para recalcular las lineas de presupuesto
|
||||
$(document).on('update-lineas-presupuesto', this.updateLineasPresupuesto.bind(this));
|
||||
$(document).on('update-lineas-presupuesto', async function () {
|
||||
|
||||
await self.updateLineasPresupuesto();
|
||||
|
||||
$(document).trigger('update-lineas-presupuesto-completed');
|
||||
});
|
||||
|
||||
$('.insertarLinea').on("click", this.#insertarLineaComparador.bind(this));
|
||||
$('.paginas-lp').on('change', this.checkPaginasLineasPresupuesto.bind(this));
|
||||
@ -355,8 +363,8 @@ class LineasPresupuesto {
|
||||
}
|
||||
|
||||
|
||||
updateLineasPresupuesto() {
|
||||
|
||||
async updateLineasPresupuesto() {
|
||||
|
||||
$('#tableLineasPresupuesto tbody tr:visible ').each(function () {
|
||||
|
||||
$('#' + this.id + '_maquina').trigger('change');
|
||||
@ -1462,7 +1470,7 @@ class LineasPresupuesto {
|
||||
cliente_id: $('#clienteId').find(":selected").val(),
|
||||
};
|
||||
|
||||
if(datos.ancho==0 || datos.alto==0 || datos.ancho=='' || datos.alto=='' || isNaN(datos.ancho) || isNaN(datos.alto)){
|
||||
if (datos.ancho == 0 || datos.alto == 0 || datos.ancho == '' || datos.alto == '' || isNaN(datos.ancho) || isNaN(datos.alto)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1522,7 +1530,7 @@ class LineasPresupuesto {
|
||||
borrar_linea = false;
|
||||
}
|
||||
|
||||
for(let $i=0; $i<response.lineas.length; $i++){
|
||||
for (let $i = 0; $i < response.lineas.length; $i++) {
|
||||
|
||||
// Se cogen los valores de la linea con los datos correspondientes
|
||||
if (response.lineas[$i].fields.maquina_id === input_data.maquina_id &&
|
||||
@ -1546,7 +1554,7 @@ class LineasPresupuesto {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(borrar_linea){
|
||||
if (borrar_linea) {
|
||||
self.table.row('#' + linea).remove().draw();
|
||||
}
|
||||
}
|
||||
@ -1602,13 +1610,16 @@ class LineasPresupuesto {
|
||||
|
||||
/* TO-DO
|
||||
calcular_mermas()
|
||||
|
||||
updatePresupuesto({
|
||||
*/
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : true,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
// Si existe cubierta, hay que actualizar con el valor del lomo
|
||||
if (linea != 'lp_cubierta' && linea != 'lp_sobrecubierta' && this.table.row('#lp_cubierta').length > 0) {
|
||||
@ -1886,17 +1897,15 @@ class LineasPresupuesto {
|
||||
for (const row of rows) {
|
||||
if (row.tipo == 'cubierta') {
|
||||
this.rellenarDatosLinea('lp_cubierta', row, true);
|
||||
/* TO-DO
|
||||
|
||||
if ($('#acabado_cubierta_id').val() > 0)
|
||||
insertar_acabado_exterior($('#acabado_cubierta_id').val(), window.Presupuestos.cubierta)
|
||||
*/
|
||||
$(document).trigger('add-servicio-lineas', 'acabadoCubierta');
|
||||
|
||||
}
|
||||
if (row.tipo == 'sobrecubierta') {
|
||||
this.rellenarDatosLinea('lp_sobrecubierta', row, true);
|
||||
/* TO-DO
|
||||
if ($('#acabado_sobrecubierta_id').val() > 0)
|
||||
insertar_acabado_exterior($('#acabado_sobrecubierta_id').val(), window.Presupuestos.sobrecubierta)
|
||||
*/
|
||||
$(document).trigger('add-servicio-lineas', 'acabadoSobrecubierta');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1920,15 +1929,14 @@ class LineasPresupuesto {
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_envios: false,
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : true,
|
||||
update_envios: true,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
})
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,311 @@
|
||||
class Resumen {
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
$(".update-totales").on("change", function () {
|
||||
self.updateTotales(true, true, true)
|
||||
});
|
||||
|
||||
$(document).on('update-totales', async function () {
|
||||
await self.updateTotales();
|
||||
$(document).trigger('update-totales-completed');
|
||||
});
|
||||
}
|
||||
|
||||
cargar(resumen) {
|
||||
|
||||
// Mapear los valores a los elementos HTML por ID
|
||||
$("#totalCostePapel").text(resumen.total_coste_papel + "€" || "0€");
|
||||
$("#porcentajeMargenPapel").text(resumen.total_margenPercent_papel ? resumen.total_margenPercent_papel + "%" : "0%");
|
||||
$("#margenPapel").text(resumen.total_margen_papel + "€" || "0€");
|
||||
|
||||
$("#totalCosteImpresion").text(resumen.total_coste_impresion + "€" || "0€");
|
||||
$("#porcentajeMargenImpresion").text(resumen.total_margenPercent_impresion ? resumen.total_margenPercent_impresion + "%" : "0%");
|
||||
$("#margenImpresion").text(resumen.total_margen_impresion + "€" || "0€");
|
||||
|
||||
$("#totalServicios").text(resumen.total_coste_servicios + "€" || "0€");
|
||||
$("#porcentajeMargenServicios").text(resumen.total_margenPercent_servicios ? resumen.total_margenPercent_servicios + "%" : "0%");
|
||||
$("#margenServicios").text(resumen.total_margen_servicios + "€" || "0€");
|
||||
|
||||
//$("#costeEnvios").text(resumen.total_coste_envios + "€" || "0€");
|
||||
$("#totalEnvios").text(resumen.total_coste_envios + "€" || "0€");
|
||||
$("#margenEnvios").text(resumen.total_margen_envios + "€" || "0€");
|
||||
|
||||
$("#totalCostes").text(resumen.total_costes + "€" || "0€");
|
||||
$("#porcentajeMargen").text(resumen.porcentajeMargen ? resumen.porcentajeMargen + "%" : "0%");
|
||||
$("#totalMargenes").text(resumen.total_margenes + "€" || "0€");
|
||||
|
||||
$("#totalAntesDescuento").text(resumen.total_antes_descuento + "€" || "0€");
|
||||
$("#total_descuentoPercent").val(resumen.total_descuentoPercent + "€" || "0€");
|
||||
$("#descuentoTotal").text(resumen.total_descuento + "€" || "0€");
|
||||
$("#totalDespuesDecuento").text(resumen.total_presupuesto + "€" || "0€");
|
||||
$("#precioUnidadPresupuesto").text(resumen.total_precio_unidad + "€" || "0€");
|
||||
$("#factor").text(resumen.total_factor + "€" || "0€");
|
||||
$("#factor_ponderado").text(resumen.total_factor_ponderado + "€" || "0€");
|
||||
|
||||
if (resumen.total_aceptado !== undefined) {
|
||||
$("#totalAceptado").val(resumen.total_aceptado + "€" || "0€");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Formatear agregando separadores de miles
|
||||
addSeparatorsNF(nStr, inD, outD, sep) {
|
||||
nStr += '';
|
||||
let dpos = nStr.indexOf(inD);
|
||||
let nStrEnd = '';
|
||||
if (dpos != -1) {
|
||||
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
|
||||
nStr = nStr.substring(0, dpos);
|
||||
}
|
||||
let rgx = /(\d+)(\d{3})/;
|
||||
while (rgx.test(nStr)) {
|
||||
nStr = nStr.replace(rgx, '$1' + sep + '$2');
|
||||
}
|
||||
return nStr + nStrEnd;
|
||||
}
|
||||
|
||||
|
||||
async updateTotales(event, data = {}) {
|
||||
|
||||
let updateLP = data.updateLP || true;
|
||||
let updateServicios = data.updateServicios || true;
|
||||
let updateEnvio = data.updateEnvio || true;
|
||||
let totalPapel = 0;
|
||||
let margenPapel = 0;
|
||||
|
||||
let totalImpresion = 0;
|
||||
let totalImpresionforMargen = 0;
|
||||
let margenImpresion = 0;
|
||||
|
||||
let totalServicios = 0;
|
||||
let margenServicios = 0;
|
||||
|
||||
let totalEnvios = 0;
|
||||
let margenEnvios = 0;
|
||||
|
||||
let sumForFactor = 0.0;
|
||||
let sumForFactorPonderado = 0.0;
|
||||
|
||||
|
||||
let margenPorHoras = 0.0;
|
||||
|
||||
if (updateLP) {
|
||||
|
||||
if (typeof $("#tableLineasPresupuesto").DataTable() !== 'undefined') {
|
||||
$("#tableLineasPresupuesto").DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
|
||||
if (rowData.check_papel_total) {
|
||||
totalPapel += parseFloat($('#' + rowData.row_id + '_totalPapelPedido').val())
|
||||
margenPapel += parseFloat($('#' + rowData.row_id + '_margenPapelPedido').val())
|
||||
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalPapelPedido').val())
|
||||
sumForFactor -= parseFloat($('#' + rowData.row_id + '_margenPapelPedido').val())
|
||||
|
||||
}
|
||||
if (rowData.check_impresion_total) {
|
||||
//totalImpresion += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
margenPorHoras += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
|
||||
if (rowData.maquinaTipo == 'inkjet') {
|
||||
totalImpresion += parseFloat(rowData.totalTinta)
|
||||
totalImpresion += parseFloat(rowData.totalCorte)
|
||||
|
||||
sumForFactor += (parseFloat(rowData.totalTinta) + parseFloat(rowData.totalCorte))
|
||||
}
|
||||
//margenImpresion += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
//margenPorHoras += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
margenImpresion += parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
|
||||
sumForFactor -= parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
if (!isNaN(parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val()))) {
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
totalImpresion -= margenImpresion
|
||||
totalPapel -= margenPapel
|
||||
|
||||
margenImpresion += margenPorHoras
|
||||
|
||||
let porcentajeMargenPapel = isNaN(margenPapel / (totalPapel) * 100.0) ? 0 : margenPapel / (totalPapel) * 100.0
|
||||
$('#porcentajeMargenPapel').text(porcentajeMargenPapel.toFixed(0) + '%')
|
||||
$('#totalCostePapel').text((this.addSeparatorsNF(totalPapel.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenPapel').text((this.addSeparatorsNF(margenPapel.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCostePapel').attr('val', totalPapel.toFixed(2))
|
||||
$('#margenPapel').attr('val', margenPapel.toFixed(2))
|
||||
|
||||
let porcentajeMargenImpresion = isNaN(margenImpresion / (totalImpresion) * 100.0) ? 0 : margenImpresion / (totalImpresion) * 100.0
|
||||
$('#porcentajeMargenImpresion').text(porcentajeMargenImpresion.toFixed(0) + '%')
|
||||
$('#totalCosteImpresion').text((this.addSeparatorsNF(totalImpresion.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenImpresion').text((this.addSeparatorsNF(margenImpresion.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCosteImpresion').attr('val', totalImpresion.toFixed(2))
|
||||
$('#margenImpresion').attr('val', margenImpresion.toFixed(2))
|
||||
|
||||
}
|
||||
else {
|
||||
totalPapel = parseFloat($('#totalCostePapel').attr('val'))
|
||||
margenPapel = parseFloat($('#margenPapel').attr('val'))
|
||||
totalImpresion = parseFloat($('#totalCosteImpresion').attr('val'))
|
||||
margenImpresion = parseFloat($('#margenImpresion').attr('val'))
|
||||
}
|
||||
|
||||
sumForFactorPonderado = sumForFactor;
|
||||
|
||||
if (updateServicios) {
|
||||
|
||||
if (typeof $("#tableOfServiciosEncuadernacion").DataTable() !== 'undefined' && $("#tableOfServiciosEncuadernacion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosEncuadernacion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosAcabado").DataTable() !== 'undefined' && $("#tableOfServiciosAcabado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosAcabado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosPreimpresion").DataTable() !== 'undefined' && $("#tableOfServiciosPreimpresion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosPreimpresion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio;
|
||||
let coste_servicio = rowData.coste;
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosExtra").DataTable() !== 'undefined' && $("#tableOfServiciosExtra").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosExtra').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio;
|
||||
let coste_servicio = rowData.coste;
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof $("#tableOfServiciosManipulado").DataTable() !== 'undefined' && $("#tableOfServiciosManipulado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosManipulado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
});
|
||||
}
|
||||
|
||||
totalServicios -= margenServicios;
|
||||
|
||||
sumForFactorPonderado += totalServicios;
|
||||
|
||||
let porcentajeMargenServicios = margenServicios / (totalServicios) * 100
|
||||
$('#porcentajeMargenServicios').text(isNaN(porcentajeMargenServicios.toFixed(0)) ? 0 : porcentajeMargenServicios.toFixed(0) + '%')
|
||||
$('#totalServicios').text((this.addSeparatorsNF(totalServicios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenServicios').text((this.addSeparatorsNF(margenServicios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalServicios').attr('val', totalServicios.toFixed(2) + '€')
|
||||
$('#margenServicios').attr('val', margenServicios.toFixed(2) + '€')
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
totalServicios = parseFloat($('#totalServicios').attr('val'))
|
||||
margenServicios = parseFloat($('#margenServicios').attr('val'))
|
||||
|
||||
sumForFactorPonderado += totalServicios;
|
||||
}
|
||||
|
||||
if (updateEnvio) {
|
||||
|
||||
totalEnvios = parseFloat($('#envio_base').val());
|
||||
if (typeof $('#tableOfDireccionesEnvio').DataTable() !== 'undefined' && $('#tableOfDireccionesEnvio').DataTable().rows().count() > 0) {
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
if (rowIdx == 0) {
|
||||
return;
|
||||
}
|
||||
let data = this.data()
|
||||
totalEnvios += parseFloat(data.precio)
|
||||
margenEnvios += parseFloat((data.precio) * data.margen / 100)
|
||||
});
|
||||
}
|
||||
|
||||
totalEnvios -= margenEnvios
|
||||
$('#totalEnvios').text((this.addSeparatorsNF(totalEnvios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenEnvios').text((this.addSeparatorsNF(margenEnvios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalEnvios').attr('val', totalEnvios.toFixed(2) + '€')
|
||||
$('#margenEnvios').attr('val', margenEnvios.toFixed(2) + '€')
|
||||
}
|
||||
else {
|
||||
totalEnvios = parseFloat($('#totalEnvios').attr('val'))
|
||||
margenEnvios = parseFloat($('#margenEnvios').attr('val'))
|
||||
}
|
||||
|
||||
let totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2))
|
||||
let totalMargenes = parseFloat(margenPapel.toFixed(2)) + parseFloat(margenImpresion.toFixed(2)) + parseFloat(margenServicios.toFixed(2)) + parseFloat(margenEnvios.toFixed(2))
|
||||
let porcentajeMargen = totalCostes + totalMargenes > 0 ? (100 * totalMargenes / (totalCostes + totalMargenes)).toFixed(0) : 0
|
||||
$('#totalCostes').text((this.addSeparatorsNF(totalCostes.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalMargenes').text((this.addSeparatorsNF(totalMargenes.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCostes').attr('val', (totalCostes).toFixed(2) + '€')
|
||||
$('#totalMargenes').attr('val', (totalMargenes).toFixed(2) + '€')
|
||||
$('#porcentajeMargen').text(porcentajeMargen + '%')
|
||||
$('#porcentajeMargen').attr('val', porcentajeMargen)
|
||||
|
||||
if ($('#total_descuentoPercent').val() < 0) {
|
||||
$('#total_descuentoPercent').val(0)
|
||||
}
|
||||
let totalAntesDescuento = totalCostes + totalMargenes
|
||||
let totalDescuento = totalAntesDescuento * parseInt($('#total_descuentoPercent').val() || 0) / 100
|
||||
let totalPresupuesto = totalAntesDescuento - totalDescuento
|
||||
let precioUnidad = totalPresupuesto / parseInt($('#tirada').val())
|
||||
|
||||
$('#totalAntesDescuento').text((this.addSeparatorsNF(totalAntesDescuento.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#descuentoTotal').text((this.addSeparatorsNF(totalDescuento.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalDespuesDecuento').text((this.addSeparatorsNF(totalPresupuesto.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#precioUnidadPresupuesto').text((this.addSeparatorsNF(precioUnidad.toFixed(4), ".", ",", ".")) + "€")
|
||||
$('#totalAntesDescuento').attr('val', (totalAntesDescuento).toFixed(2))
|
||||
$('#descuentoTotal').attr('val', (totalDescuento).toFixed(2))
|
||||
$('#totalDespuesDecuento').attr('val', (totalPresupuesto).toFixed(2))
|
||||
$('#precioUnidadPresupuesto').attr('val', (precioUnidad).toFixed(4))
|
||||
|
||||
|
||||
$('#factor').text(this.addSeparatorsNF(((totalPresupuesto - totalEnvios - margenEnvios) / sumForFactor).toFixed(2), ".", ",", "."))
|
||||
$('#factor').attr('val', ((totalPresupuesto - totalEnvios - margenEnvios) / sumForFactor).toFixed(2))
|
||||
$('#factor_ponderado').text(this.addSeparatorsNF(((totalPresupuesto - totalEnvios - margenEnvios) / sumForFactorPonderado).toFixed(2), ".", ",", "."))
|
||||
$('#factor_ponderado').attr('val', ((totalPresupuesto - totalEnvios - margenEnvios) / sumForFactorPonderado).toFixed(2))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default Resumen;
|
||||
@ -71,7 +71,11 @@ class Servicios {
|
||||
showBreadCrumbSaveButton(true);
|
||||
});
|
||||
|
||||
$(document).on('update-servicios', this.updateServicios.bind(this));
|
||||
$(document).on('update-servicios', async function(){
|
||||
await self.updateServicios()
|
||||
|
||||
$(document).trigger('update-servicios-completed');
|
||||
});
|
||||
}
|
||||
|
||||
cargar(datos) {
|
||||
@ -89,6 +93,15 @@ class Servicios {
|
||||
|
||||
}
|
||||
|
||||
async guardar(){
|
||||
await this.serviciosAcabado.guardarServiciosAcabado();
|
||||
await this.serviciosPreimpresion.guardarServiciosPreimpresion();
|
||||
await this.ServiciosEncuadernacion.guardarServiciosEncuadernacion();
|
||||
await this.ServiciosManipulado.guardarServiciosManipulado();
|
||||
await this.serviciosExtra.guardarServiciosExtra();
|
||||
}
|
||||
|
||||
|
||||
addServicio(event, servicio) {
|
||||
|
||||
if (servicio == 'acabadoCubierta') {
|
||||
@ -110,7 +123,7 @@ class Servicios {
|
||||
}
|
||||
}
|
||||
|
||||
updateServicios() {
|
||||
async updateServicios() {
|
||||
|
||||
this.serviciosAcabado.updateServicios();
|
||||
this.ServiciosEncuadernacion.updateServicios();
|
||||
@ -243,12 +256,15 @@ class ServiciosAcabado {
|
||||
})
|
||||
|
||||
self.check_serv_acabado_error();
|
||||
}
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
*/
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -260,15 +276,6 @@ class ServiciosAcabado {
|
||||
|
||||
|
||||
this.addServicio.on('click', this.addServicioAcabado.bind(this));
|
||||
|
||||
/*this.table.on('draw.dt', function () {
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
|
||||
}); */
|
||||
}
|
||||
|
||||
updateServicios() {
|
||||
@ -413,17 +420,28 @@ class ServiciosAcabado {
|
||||
cargarServiciosAcabado(datos) {
|
||||
|
||||
this.table.rows.add(datos).draw();
|
||||
|
||||
}
|
||||
|
||||
guardarServiciosAcabado() {
|
||||
/* TO-DO
|
||||
|
||||
*/
|
||||
async guardarServiciosAcabado() {
|
||||
|
||||
let datos = [];
|
||||
this.table.rows().every(function () {
|
||||
datos.push(this.data());
|
||||
});
|
||||
const domain = window.location.origin;
|
||||
await fetch(domain + "/presupuestos/presupuestoacabados/edit/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({datos: datos}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
check_serv_acabado_error() {
|
||||
|
||||
var htmlString = '';
|
||||
@ -518,11 +536,14 @@ class ServiciosPreimpresion {
|
||||
drawCallback: function (settings) {
|
||||
|
||||
self.check_serv_preimpresion_error();
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
*/
|
||||
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -537,15 +558,6 @@ class ServiciosPreimpresion {
|
||||
|
||||
|
||||
this.addServicio.on('click', this.addServicioPreimpresion.bind(this));
|
||||
|
||||
/*this.table.on('draw.dt', function () {
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
|
||||
}); */
|
||||
}
|
||||
|
||||
getPresupuestoPreimpresion(tarifa_id = -1) {
|
||||
@ -628,11 +640,20 @@ class ServiciosPreimpresion {
|
||||
$('#serv-preimpresion-error').html(htmlString)
|
||||
}
|
||||
|
||||
guardarServiciosPreimpresion() {
|
||||
/* TO-DO
|
||||
|
||||
*/
|
||||
|
||||
async guardarServiciosPreimpresion() {
|
||||
|
||||
let datos = [];
|
||||
this.table.rows().every(function () {
|
||||
datos.push(this.data());
|
||||
});
|
||||
const domain = window.location.origin;
|
||||
await fetch(domain + "/presupuestos/presupuestopreimpresiones/edit/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({datos: datos}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -813,11 +834,13 @@ class ServiciosEncuadernacion {
|
||||
|
||||
self.check_serv_enc_error();
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
*/
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -826,18 +849,7 @@ class ServiciosEncuadernacion {
|
||||
self.table.row(rowId).remove().draw();
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.addServicio.on('click', this.addServicioEncuadernacion.bind(this));
|
||||
|
||||
/*this.table.on('draw.dt', function () {
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
|
||||
}); */
|
||||
}
|
||||
|
||||
updateServicios() {
|
||||
@ -1009,10 +1021,20 @@ class ServiciosEncuadernacion {
|
||||
|
||||
}
|
||||
|
||||
guardarServiciosEncuadernacion() {
|
||||
/* TO-DO
|
||||
|
||||
*/
|
||||
async guardarServiciosEncuadernacion() {
|
||||
|
||||
let datos = [];
|
||||
this.table.rows().every(function () {
|
||||
datos.push(this.data());
|
||||
});
|
||||
const domain = window.location.origin;
|
||||
await fetch(domain + "/presupuestos/presupuestoencuadernaciones/edit/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({datos: datos}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -1155,11 +1177,13 @@ class ServiciosManipulado {
|
||||
|
||||
self.check_serv_manipulado_error();
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
*/
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -1335,10 +1359,20 @@ class ServiciosManipulado {
|
||||
this.table.rows.add(datos).draw();
|
||||
}
|
||||
|
||||
guardarServiciosManipulado() {
|
||||
/* TO-DO
|
||||
async guardarServiciosManipulado() {
|
||||
|
||||
*/
|
||||
let datos = [];
|
||||
this.table.rows().every(function () {
|
||||
datos.push(this.data());
|
||||
});
|
||||
const domain = window.location.origin;
|
||||
await fetch(domain + "/presupuestos/presupuestomanipulados/edit/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({datos: datos}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
check_serv_manipulado_error() {
|
||||
@ -1437,14 +1471,14 @@ class ServiciosExtra {
|
||||
|
||||
self.check_serv_extra_error();
|
||||
|
||||
/* TO-DO
|
||||
updatePresupuesto({
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true})
|
||||
*/
|
||||
$(document).trigger('update-presupuesto', {
|
||||
update_lineas : false,
|
||||
update_servicios : false,
|
||||
update_envios: false,
|
||||
update_resumen: true,
|
||||
update_tiradas_alternativas: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-delete-servextra', function () {
|
||||
@ -1482,10 +1516,20 @@ class ServiciosExtra {
|
||||
this.table.rows.add(datos).draw();
|
||||
}
|
||||
|
||||
guardarServiciosExtra() {
|
||||
/* TO-DO
|
||||
|
||||
*/
|
||||
async guardarServiciosExtra() {
|
||||
|
||||
let datos = [];
|
||||
this.table.rows().every(function () {
|
||||
datos.push(this.data());
|
||||
});
|
||||
const domain = window.location.origin;
|
||||
await fetch(domain + "/presupuestos/presupuestoserviciosextra/edit/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({datos: datos}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getPresupuestoExtra(tarifa_id = -1) {
|
||||
|
||||
@ -83,13 +83,49 @@ class TiradasAlernativas {
|
||||
$(document).on('click', '.btn-delete-tirada', function (e) {
|
||||
|
||||
const row = $(this).closest('tr');
|
||||
self.table.row(row)
|
||||
$('#tableTiradas').DataTable().row(row)
|
||||
.remove()
|
||||
.draw();
|
||||
showBreadCrumbSaveButton(true);
|
||||
})
|
||||
|
||||
$(document).on('click', '.comfirm-tirada-alt', function (e) {
|
||||
|
||||
const row = $(this).closest('tr');
|
||||
const data = self.table.row(row).data();
|
||||
|
||||
self.table.row(row).remove().draw();
|
||||
|
||||
$(document).trigger('update-envios', {tirada_inicial:$('#tirada').val(), tirada: data.tirada});
|
||||
|
||||
});
|
||||
|
||||
$(document).on('update-tiradas-alternativas', async function(){
|
||||
|
||||
await self.updateTiradasAlternativas();
|
||||
|
||||
$(document).trigger('update-tiradas-alternativas-completed');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
async updateTiradasAlternativas(){
|
||||
|
||||
const self = this;
|
||||
|
||||
if($('#tableTiradas').DataTable().rows().count() > 0){
|
||||
// se obtiene la primera columna de la tabla de tiradas
|
||||
const data = $('#tableTiradas').DataTable().rows().data().toArray();
|
||||
// se borra la tabla de tiradas
|
||||
$('#tableTiradas').DataTable().clear().draw();
|
||||
const tiradas = data.map(row => row.tirada);
|
||||
// por cada tirada, se añade una fila a la tabla de tiradas
|
||||
tiradas.forEach(function(tirada){
|
||||
self.addTiradaAlt(tirada);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cargar(datos) {
|
||||
|
||||
@ -98,12 +134,12 @@ class TiradasAlernativas {
|
||||
}
|
||||
|
||||
|
||||
addTiradaAlt() {
|
||||
addTiradaAlt(tiradaExterna = null) {
|
||||
|
||||
const self = this;
|
||||
const id = window.location.href.split('/').pop();
|
||||
|
||||
const tirada = parseInt(this.tirada.val());
|
||||
const tirada = tiradaExterna===null?parseInt(this.tirada.val()):tiradaExterna;
|
||||
const tirada_ejemplo = parseInt($('#tirada').val());
|
||||
const POD = parseInt($('#POD').val());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user