trabajando en lineas presupuesto

This commit is contained in:
2024-12-27 18:10:35 +01:00
parent ef58fe7209
commit 1ccade47a3
12 changed files with 974 additions and 766 deletions

View File

@ -145,13 +145,28 @@ class Comparador {
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
tipo: 'guardas',
tipo: 'colorhq',
uso: 'guardas',
});
this.gramajeGuardas = new ClassSelect($('#compGramajeGuardas'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelCubierta.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
tipo: 'colorhq',
uso: 'guardas',
});
this.carasGuardas = $('#compCarasGuardas');
this.gramajeGuardas = $('#compGramajeGuardas');
this.btnInsertarGuardas = $('#insertarGuardasBtn');
}
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){
this.lomoRedondo = $('#compLomoRedondo');
this.cabezada = $('#cabezada');
}
this.posPagColor = $('#compPosPaginasColor');
this.calculatedColorPages = $('#compCalPaginasColor');
@ -188,9 +203,7 @@ class Comparador {
if ($('#tipo_impresion_id').val() == 1 || $('#tipo_impresion_id').val() == 3 ||
$('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 7) {
this.papelGuardas.select2({
allowClear: false,
});
this.papelGuardas.init();
this.carasGuardas.select2({
allowClear: false,
@ -207,6 +220,18 @@ class Comparador {
this.gramajeColorhq.init();
this.papelCubierta.init();
this.gramajeCubierta.init();
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){
this.lomoRedondo.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
this.cabezada.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
}
if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) {
this.sobrecubierta.select2({
@ -233,6 +258,8 @@ class Comparador {
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.papelGuardas.init();
this.gramajeGuardas.init();
this.papelGuardas.onChange(() => this.gramajeGuardas.setVal(0))
}
this.papelNegro.onChange(() => this.gramajeNegro.setVal(0))
@ -282,6 +309,10 @@ class Comparador {
$('.comp_sobrecubierta_items').on('change', this.obtenerComparadorExteriores.bind(this));
}
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
$('.comp_guardas_items').on('change', this.obtenerComparadorGuardas.bind(this));
}
}
#changePaginasComparador(element) {
@ -349,8 +380,18 @@ class Comparador {
this.papelSobrecubierta.setOption(datos.json_data.sobrecubierta.papel_id, datos.json_data.sobrecubierta.papel_nombre);
this.gramajeSobrecubierta.setOption(datos.json_data.sobrecubierta.gramaje, datos.json_data.sobrecubierta.gramaje);
}
if (datos.json_data.guardas) {
this.carasGuardas.val(datos.json_data.guardas.paginas).trigger('change');
this.papelGuardas.setOption(datos.json_data.guardas.papel_id, datos.json_data.guardas.papel_nombre);
this.gramajeGuardas.setOption(datos.json_data.guardas.gramaje, datos.json_data.guardas.gramaje);
}
if (datos.posPagColor.length > 0) {
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){
this.lomoRedondo.val(datos.lomoRedondo?1:0).trigger('change');
this.cabezada.val(datos.cabezada).trigger('change');
}
if (datos.posPagColor != null && datos.posPagColor.length > 0) {
this.posPagColor.val(datos.posPagColor);
this.#computarPaginasColor(datos.posPagColor);
}
@ -358,6 +399,10 @@ class Comparador {
this.cargando = false;
this.paginasNegro.trigger('change');
this.paginasCubierta.trigger('change');
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.carasGuardas.trigger('change');
}
}
@ -743,6 +788,9 @@ class Comparador {
$('#total_comp_plana').html("0.00");
}
}
if(!this.cargando)
$('#paginas').trigger('change');
}
getDataForComp(uso = 'interior') {
@ -874,6 +922,22 @@ class Comparador {
}
else if (uso == 'guardas') {
if (this.papelGuardas.getVal() == 0 || this.papelGuardas.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (this.gramajeGuardas.getVal() == 0 || this.gramajeGuardas.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
papel_generico = { id: this.papelGuardas.getVal(), nombre: this.papelGuardas.getText() };
gramaje = this.gramajeGuardas.getVal();
paginas = this.carasGuardas.val();
}
const datosPedido = {
paginas: paginas,
tirada: $('#tirada').val(),
@ -906,20 +970,24 @@ class Comparador {
datos.datosPedido.lomo = this.getLomoLineasPresupuesto('interior');
datos.datosPedido.solapas = $('#solapas').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas').prop('checked') ? parseInt($('#solapas_ancho').val()) : 0;
// TO-DO
datos.lomoRedondo = false;
datos.lomoRedondo = this.lomoRedondo.val();
}
else if (uso == 'sobrecubierta') {
datos.datosPedido.lomo = this.getLomoLineasPresupuesto() + this.getLomoLineasPresupuesto('cubierta');
datos.datosPedido.solapas = $('#solapas_sobrecubierta').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas_sobrecubierta').prop('checked') ? parseInt($('#solapas_ancho_sobrecubierta').val()) : 0;
}
else if (uso == 'guardas') {
datos.datosPedido.isCosido = 1;
datos.datosPedido.isHq = 1;
datos.paginas_color = datos.datosPedido.paginas;
}
return { error: false, data: datos };
}
getLomoLineasPresupuesto(tipo_lomo='interior') {
getLomoLineasPresupuesto(tipo_lomo = 'interior') {
let lomoTotal = 0
try {
@ -1163,6 +1231,66 @@ class Comparador {
}
}
obtenerComparadorGuardas(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
const self = this;
if (this.cargando) {
return
}
this.tableCompGuardas.clear().draw();
this.btnInsertarGuardas.addClass('d-none');
$('#title_guardas').html(window.language.Presupuestos.Guardas);
let datosComp = {};
datosComp = this.getDataForComp('guardas');
if (datosComp.error) {
return;
}
datosComp.data[this.csrf_token] = this.csrf_hash;
new Ajax('/presupuestoadmin/comparadorguardas',
datosComp.data,
{},
(response) => {
if (response.data && Object.keys(response.data).length > 0) {
let sorted = Object.values(response.data).sort(
(p1, p2) => ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) < (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ?
-1 : ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) > (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? 1 : 0);
sorted[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompGuardas.row
.add(self.getRowFromLinea('guardas', linea))
.draw();
});
}
self.selectLineas('guardas');
if (self.tableCompGuardas.rows().count() > 0) {
$('#title_guardas').html(window.language.Presupuestos.Guardas +
(' (' + self.tableCompGuardas.rows().count() + ')'));
self.btnInsertarGuardas.removeClass('d-none');
}
else {
$('#title_guardas').html(window.language.Presupuestos.Guardas);
self.btnInsertarGuardas.addClass('d-none');
}
},
(error) => {
console.log(error);
}
).post();
} catch (e) {
console.log(e)
}
}
selectLineas(tabla) {
@ -1173,6 +1301,12 @@ class Comparador {
let tipo2 = 'color';
let total_label = '#total_comp_plana'
switch (tabla) {
case 'guardas':
table = this.tableCompGuardas;
tipo1 = 'guardas';
total_label = '#total_comp_guardas';
break;
case 'cubierta':
table = this.tableCompCubierta;
tipo1 = 'cubierta';
@ -1407,402 +1541,7 @@ class Comparador {
data_str = JSON.stringify(data)
$('#comparador_json_data').val(data_str)
}
}
/*
function checkComparadorGuardas(actualizarLinea = false){
if ($('#compPapelGuardas').select2('data')[0].id > 0 ){
const dimension = getDimensionLibro();
let datos = {
tipo_impresion_id: <?php echo $tipo_impresion_id ?>,
type: 'guardas',
paginas: 8,
paginas_impresion: parseInt($('#compCarasGuardas').select2('data')[0].id),
tirada: parseInt($('#tirada').val()),
merma: parseInt($('#mermacubierta').val()),
color: 1,
hq: 1,
ancho: dimension.ancho,
alto: dimension.alto,
papel_generico_id: $('#compPapelGuardas').select2('data')[0].id,
papel_generico: $('#compPapelGuardas').select2('data')[0].text.trim(),
gramaje: parseInt($('#compGramajeGuardas').val()),
cliente_id: $('#clienteId').find(":selected").val(),
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
};
$.ajax({
type: "POST",
url: "/presupuestoadmin/datatable",
data: datos,
success: function (data) {
clearGuardas();
if(data.lineas.length >0){
fillGuardas(data);
selectGuardasLineas();
$('#title_guardas').html('<?= lang("Presupuestos.Guardas") ?>' + ' (' + tableCompGuardas.rows().count() + ')');
$('#insertarGuardasBtn').removeClass('d-none')
if(actualizarLinea){
var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray();
for(row of rows){
fill_lp_guardas(row, true);
}
}
}
else{
$('#title_guardas').html('<?= lang("Presupuestos.Guardas") ?>');
$('#insertarGuardasBtn').addClass('d-none')
$('#total_comp_guardas').html('0.00')
}
yeniden(data.<?= csrf_token() ?>);
return true;
},
error: function(e){
return false;
}
})
}
else{
clearGuardas();
}
}
}
$('.comp_guardas_items').on('change', function (e) {
checkComparadorGuardas(false);
});
<?php endif; ?>
async function getLineasIntPlana(is_color, is_hq, actualizarLinea){
const dimension = getDimensionLibro();
let datos = {
tipo_impresion_id: <?php echo $tipo_impresion_id ?>,
type: 'interior',
color: is_color?1:0,
hq: is_hq?1:0,
paginas: parseInt($(''+ elementos.paginas).val()),
tirada: parseInt($('#tirada').val()),
merma: parseInt($('#merma').val()),
ancho: dimension.ancho,
alto: dimension.alto,
papel_generico_id: $(''+ elementos.papel).select2('data')[0].id,
papel_generico: $(''+ elementos.papel).select2('data')[0].text.trim(),
gramaje: $(''+ elementos.gramaje).select2('data')[0].text.trim() ,
cliente_id: $('#clienteId').find(":selected").val(),
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
};
$.ajax({
type: "POST",
url: "/presupuestoadmin/datatable",
data: datos,
success: function (data) {
clearIntLineas(is_color);
if(data.lineas.length >0){
fillIntPlana(data, is_color, is_hq);
selectIntLineas();
$('#title_int_plana').html('<?= lang("Presupuestos.compInteriorPlana") ?>' + ' (' + tableCompIntPlana.rows().count() + ')');
$('#insertarPlanaBtn').removeClass('d-none')
if(actualizarLinea){
var rows = $("#tableCompIntPlana").DataTable().rows( '.selected' ).data().toArray();
for(row of rows){
if(row['tipo'] =='bn' && !is_color && !is_hq){
if($('#lp_bn').css('display')!='none')
fill_lp_bn(row, true);
}
else if(row['tipo'] =='bnhq' && !is_color && is_hq){
if($('#lp_bnhq').css('display')!='none')
fill_lp_bnhq(row, true);
}
else if(row['tipo'] =='color' && is_color && !is_hq){
if($('#lp_color').css('display')!='none')
fill_lp_color(row, true);
}
else if(row['tipo'] =='colorhq' && is_color && is_hq){
if($('#lp_colorhq').css('display')!='none')
fill_lp_colorhq(row, true);
}
}
}
}
else{
$('#title_int_plana').html('<?= lang("Presupuestos.compInteriorPlana") ?>');
$('#insertarPlanaBtn').addClass('d-none')
$('#total_comp_plana').html('0.00');
}
yeniden(data.<?= csrf_token() ?>);
return true;
},
error: function(e){
return false;
}
})
return false;
}
async function getLineasIntRot(is_hq, actualizarLinea=false){
const dimension = getDimensionLibro();
// Rotativa solo negro o color (no hq)
if ( is_hq==false){
if(checkInputsForRotativa()){
let datos = {
tipo_impresion_id: <?php echo $tipo_impresion_id ?>,
type: 'interior_rot',
paginas: parseInt($('#paginas').val()),
paginas_negro: parseInt($('#compPaginasNegro').val()),
paginas_color: parseInt($('#compPaginasColor').val()),
tirada: parseInt($('#tirada').val()),
merma: parseInt($('#merma').val()),
ancho: dimension.ancho,
alto: dimension.alto,
// el papel y el gramaje se coge del negro (siempre estará)
papel_generico_id: $('#compPapelNegro').select2('data')[0].id,
papel_generico: $('#compPapelNegro').select2('data')[0].text.trim(),
gramaje: $('#compGramajeNegro').select2('data')[0].text.trim() ,
cliente_id: $('#clienteId').find(":selected").val(),
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
};
$.ajax({
type: "POST",
url: "/presupuestoadmin/datatable",
data: datos,
success: function (data) {
clearIntRot();
if(data.lineas.length >0){
fillIntRot(data);
selectIntRotLineas();
$('#title_int_rot').html('<?= lang("Presupuestos.compInteriorRotativa") ?>' + ' (' + tableCompIntRotativa.rows().count() + ')');
$('#insertarRotativaBtn').removeClass('d-none')
if(actualizarLinea){
var rows = $("#tableCompIntRotativa").DataTable().rows( '.selected' ).data().toArray();
for(row of rows){
if(row['paginasColor'] ==0){
if($('#lp_rot_bn').css('display')!='none')
fill_lp_rot_bn(row, true);
}
else if(row['paginasColor'] >0){
if($('#lp_rot_color').css('display')!='none')
fill_lp_rot_color(row, true);
}
}
}
}
else{
$('#title_int_rot').html('<?= lang("Presupuestos.compInteriorRotativa") ?>');
$('#insertarRotativaBtn').addClass('d-none')
$('#total_comp_rot').html('0.00')
}
yeniden(data.<?= csrf_token() ?>);
return true;
},
error: function(e){
return false;
}
})
}
}
return false;
}
$('.comp_cubierta_items').on('change', function (){
checkComparadorCubierta()
});
function checkComparadorCubierta(actualizarLinea = false){
if ($('#compCarasCubierta option:selected').val().length > 0 &&
$('#compPapelCubierta').select2('data').length > 0 &&
$('#compGramajeCubierta').select2('data').length > 0 ){
const dimension = getDimensionLibro();
let datos = {
tipo_impresion_id: <?php echo $tipo_impresion_id ?>,
type: 'cubierta',
paginas: parseInt($('#compCarasCubierta option:selected').val()),
tirada: parseInt($('#tirada').val()),
merma: parseInt($('#mermacubierta').val()),
color: 1,
ancho: dimension.ancho,
alto: dimension.alto,
lomo: getLomoLineasPresupuesto(),
solapas: $('#solapas').is(':checked')?1:0,
solapas_ancho: $('#solapas').is(':checked')?parseInt($('#solapas_ancho').val()):0,
papel_generico_id: $('#compPapelCubierta').select2('data')[0].id,
papel_generico: $('#compPapelCubierta').select2('data')[0].text.trim(),
gramaje: $('#compGramajeCubierta').select2('data')[0].text.trim() ,
cliente_id: $('#clienteId').find(":selected").val(),
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
};
$.ajax({
type: "POST",
url: "/presupuestoadmin/datatable",
data: datos,
success: function (data) {
clearCubierta();
if(data.lineas.length >0){
fillCubierta(data);
selectCubiertaLineas();
tableCompCubierta.order([0, 'asc']).draw()
$('#title_cubierta').html('<?= lang("Presupuestos.compCubiertaSobrecubierta") ?>' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):''));
$('#insertarCubiertaBtn').removeClass('d-none')
if(actualizarLinea){
var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray();
for(row of rows){
if (row.tipo=='cubierta')
fill_lp_cubierta(row, true);
}
}
}
else{
$('#title_cubierta').html('<?= lang("Presupuestos.compCubiertaSobrecubierta") ?>' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):''));
if(tableCompCubierta.rows().count()==0){
$('#insertarCubiertaBtn').addClass('d-none')
$('#total_comp_cubierta').html('0.00')
}
else{
selectCubiertaLineas();
}
}
yeniden(data.<?= csrf_token() ?>);
return true;
},
error: function(e){
return false;
}
})
}
else{
clearCubierta();
}
}
$('.comp_sobrecubierta_items').on('change', function (){
checkComparadorSobrecubierta()
});
function checkComparadorSobrecubierta(actualizarLinea = false){
if ($('#compSobrecubierta option:selected').val() == 1 &&
$('#compPapelSobrecubierta').select2('data').length > 0 &&
$('#compGramajeSobrecubierta').select2('data').length > 0 ){
const dimension = getDimensionLibro();
let datos = {
tipo_impresion_id: <?php echo $tipo_impresion_id ?>,
type: 'sobrecubierta',
paginas: 4,
tirada: parseInt($('#tirada').val()),
merma: parseInt($('#mermacubierta').val()),
color: 1,
ancho: dimension.ancho,
alto: dimension.alto,
lomo: getLomoLineasPresupuesto() + getLomoCubiertaLineasPresupuesto(),
solapas: $('#solapas_sobrecubierta').is(':checked')?1:0,
solapas_ancho: $('#solapas_sobrecubierta').is(':checked')?parseInt($('#solapas_ancho_sobrecubierta').val()):0,
papel_generico_id: $('#compPapelSobrecubierta').select2('data')[0].id,
papel_generico: $('#compPapelSobrecubierta').select2('data')[0].text.trim(),
gramaje: $('#compGramajeSobrecubierta').select2('data')[0].text.trim() ,
cliente_id: $('#clienteId').find(":selected").val(),
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
};
$.ajax({
type: "POST",
url: "/presupuestoadmin/datatable",
data: datos,
success: function (data) {
clearSobrecubierta();
if(data.lineas.length >0){
fillSobrecubierta(data);
selectCubiertaLineas();
tableCompCubierta.order([ [0, 'asc'],[15, 'asc'] ]).draw()
$('#title_cubierta').html('<?= lang("Presupuestos.compCubiertaSobrecubierta") ?>' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):''));
$('#insertarCubiertaBtn').removeClass('d-none')
if(actualizarLinea){
var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray();
for(row of rows){
if (row.tipo=='sobrecubierta')
fill_lp_sobrecubierta(row, true);
}
}
}
else{
$('#title_cubierta').html('<?= lang("Presupuestos.compCubiertaSobrecubierta") ?>' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):''));
if(tableCompCubierta.rows().count()==0){
$('#insertarCubiertaBtn').addClass('d-none')
$('#total_comp_cubierta').html('0.00')
}
else{
selectCubiertaLineas();
}
}
yeniden(data.<?= csrf_token() ?>);
return true;
},
error: function(e){
return false;
}
})
}
else{
clearSobrecubierta();
}
}
$('#tipoImpresion').on("select2:close", function () {
$('#paginas').change()
})
*/
export default Comparador;