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:
@ -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;
|
||||
Reference in New Issue
Block a user