mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
432 lines
16 KiB
JavaScript
432 lines
16 KiB
JavaScript
import ClassSelect from '../../../components/select2.js';
|
|
import { getToken } from '../../../common/common.js';
|
|
|
|
class DatosLibro {
|
|
|
|
constructor(domItem, functions = {}) {
|
|
|
|
this.domItem = domItem;
|
|
|
|
this.addService = functions.addService;
|
|
this.removeService = functions.removeService;
|
|
this.checkPaginasPresupuesto = functions.checkPaginasPresupuesto;
|
|
|
|
this.csrf_token = getToken();
|
|
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
|
|
|
|
this.paginas = this.domItem.find('#paginas');
|
|
this.tirada = this.domItem.find('#tirada');
|
|
this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language.Presupuestos.formatoLibro);
|
|
this.tamanioPersonalizado = this.domItem.find('#papelFormatoPersonalizado');
|
|
this.anchoPersonalizado = this.domItem.find('#papelFormatoAncho');
|
|
this.altoPersonalizado = this.domItem.find('#papelFormatoAlto');
|
|
this.merma = this.domItem.find('#merma');
|
|
this.mermaCubierta = this.domItem.find('#mermacubierta');
|
|
this.solapasCubierta = this.domItem.find('#solapas');
|
|
this.solapasSobrecubierta = this.domItem.find('#solapas_sobrecubierta');
|
|
this.anchoSolapasCubierta = this.domItem.find('#solapas_ancho');
|
|
this.anchoSolapasSobrecubierta = this.domItem.find('#solapas_ancho_sobrecubierta');
|
|
|
|
this.divSolapasCubierta = this.domItem.find('#div_solapas_ancho');
|
|
this.divSolapasSobrecubierta = this.domItem.find('#div_solapas_ancho_sobrecubierta');
|
|
|
|
this.acabadoCubierta = new ClassSelect($("#acabado_cubierta_id"),
|
|
'/serviciosacabados/getacabados',
|
|
'',
|
|
false,
|
|
{
|
|
[this.csrf_token]: this.csrf_hash,
|
|
"cubierta": 1
|
|
}
|
|
);
|
|
this.acabadoSobrecubierta = new ClassSelect($("#acabado_sobrecubierta_id"),
|
|
'/serviciosacabados/getacabados',
|
|
'',
|
|
false,
|
|
{
|
|
[this.csrf_token]: this.csrf_hash,
|
|
"sobrecubierta": 1
|
|
}
|
|
);
|
|
|
|
this.retractilado = this.domItem.find('#retractilado');
|
|
this.retractilado5 = this.domItem.find('#retractilado5');
|
|
this.imprimirFajaColor = this.domItem.find('#fajaColor');
|
|
this.prototipo = this.domItem.find('#prototipo');
|
|
this.ferro = this.domItem.find('#ferro');
|
|
this.ferroDigital = this.domItem.find('#ferroDigital');
|
|
this.marcapaginas = this.domItem.find('#marcapaginas');
|
|
|
|
}
|
|
|
|
init() {
|
|
|
|
this.tamanio.init();
|
|
this.acabadoCubierta.init();
|
|
this.acabadoSobrecubierta.init();
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
this.retractilado.on('change', this.checkRetractilado.bind(this));
|
|
this.retractilado5.on('change', this.checkRetractilado.bind(this));
|
|
this.imprimirFajaColor.on('change', (this.changeFajaColor.bind(this)));
|
|
this.ferro.on('change', this.changeFerro.bind(this));
|
|
this.prototipo.on('change', this.changePrototipo.bind(this));
|
|
|
|
this.tamanio.item.on('select2:select', this.changeFormato.bind(this));
|
|
$('.formato_libro').on('change', this.changeFormato.bind(this));
|
|
|
|
if ($('#tipo_impresion_id').val() != 1 && $('#tipo_impresion_id').val() != 3 &&
|
|
$('#tipo_impresion_id').val() != 5 && $('#tipo_impresion_id').val() != 7) {
|
|
this.solapasCubierta.on('change', this.changeSolapasCubierta.bind(this));
|
|
}
|
|
|
|
this.solapasSobrecubierta.on('change', this.changeSolapasSobrecubierta.bind(this));
|
|
this.tamanioPersonalizado.on('change', this.changeTipoTamanio.bind(this));
|
|
|
|
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');
|
|
/* TO-DO
|
|
updatePresupuesto({
|
|
update_servicios: true,
|
|
update_envios: true,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
})*/
|
|
});
|
|
}
|
|
}
|
|
|
|
changeFajaColor() {
|
|
|
|
if (this.imprimirFajaColor.prop('checked')) {
|
|
this.addService('fajaColor');
|
|
}
|
|
else {
|
|
this.removeService('fajaColor');
|
|
}
|
|
}
|
|
|
|
changeFerro() {
|
|
|
|
if (this.ferro.prop('checked')) {
|
|
this.addService('ferro');
|
|
}
|
|
else {
|
|
this.removeService('ferro');
|
|
}
|
|
}
|
|
|
|
changePrototipo() {
|
|
|
|
if (this.prototipo.prop('checked')) {
|
|
this.addService('prototipo');
|
|
this.ferro.prop('checked', true).trigger('change');
|
|
}
|
|
else {
|
|
this.removeService('prototipo');
|
|
}
|
|
}
|
|
|
|
|
|
checkRetractilado(element) {
|
|
|
|
switch (element.id) {
|
|
case 'retractilado':
|
|
if ($('#' + element.id).prop('checked')) {
|
|
$('#retractilado5').prop('checked', false);
|
|
this.removeService('retractilado5');
|
|
this.addService('retractilado');
|
|
}
|
|
break;
|
|
case 'retractilado5':
|
|
if ($('#' + element.id).prop('checked')) {
|
|
$('#retractilado').prop('checked', false);
|
|
this.removeService('retractilado');
|
|
this.addService('retractilado5');
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
changeFormato() {
|
|
|
|
// Si es negro o color
|
|
if ($('#tipoImpresion').select2('data')[0].id == 'negro' ||
|
|
$('#tipoImpresion').select2('data')[0].id == 'color') {
|
|
$('#compPaginasNegro').trigger('change')
|
|
}
|
|
// Si es negrohq o colorhq
|
|
if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' ||
|
|
$('#tipoImpresion').select2('data')[0].id == 'colorhq') {
|
|
$('#compPaginasNegrohq').trigger('change');
|
|
}
|
|
|
|
$('.solapas_cubierta').trigger('change');
|
|
$('.solapas_sobrecubierta').trigger('change');
|
|
|
|
this.checkPaginasPresupuesto();
|
|
|
|
$(document).trigger('update-lineas-presupuesto');
|
|
|
|
// TO-DO
|
|
/*updatePresupuesto({
|
|
update_servicios: true,
|
|
update_envios: true,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
})*/
|
|
}
|
|
|
|
|
|
changeTipoTamanio(){
|
|
|
|
if(this.tamanioPersonalizado.prop('checked')){
|
|
$('.tamanio-personalizado').removeClass('d-none');
|
|
$('.tamanio-estandar').addClass('d-none');
|
|
this.tamanio.setVal('');
|
|
$("#label_papelFormatoId").text(
|
|
window.language.Presupuestos.papelFormatoId + " (" +
|
|
window.language.Presupuestos.papelFormatoAncho + " x " + window.language.Presupuestos.papelFormatoAncho + ")*");
|
|
}
|
|
else{
|
|
this.anchoPersonalizado.val("");
|
|
this.altoPersonalizado.val("");
|
|
$('.tamanio-personalizado').addClass('d-none');
|
|
$('.tamanio-estandar').removeClass('d-none');
|
|
$("#label_papelFormatoId").text(
|
|
window.language.Presupuestos.papelFormatoId + '*');
|
|
}
|
|
$(document).trigger('update-lineas-presupuesto');
|
|
}
|
|
|
|
|
|
changeSolapasCubierta() {
|
|
|
|
if (this.solapasCubierta.prop('checked')) {
|
|
$('#div_solapas_ancho_sobrecubierta').removeClass('d-none');
|
|
}
|
|
else {
|
|
$('#div_solapas_ancho_sobrecubierta').divSolapasCubierta.addClass('d-none');
|
|
this.anchoSolapasCubierta.val(0);
|
|
}
|
|
$('#serv_default').trigger('click');
|
|
}
|
|
|
|
|
|
changeSolapasSobrecubierta() {
|
|
|
|
if (this.solapasSobrecubierta.prop('checked')) {
|
|
this.divSolapasSobrecubierta.removeClass('d-none');
|
|
}
|
|
else {
|
|
this.divSolapasSobrecubierta.addClass('d-none');
|
|
this.anchoSolapasSobrecubierta.val(0);
|
|
}
|
|
$('#serv_default').trigger('click');
|
|
}
|
|
|
|
changePaginas() {
|
|
|
|
if($('#tipo_impresion_id').val() == 21){
|
|
if(parseInt($('#paginas').val()) > 80){
|
|
$('#paginas').val(80)
|
|
}
|
|
}
|
|
|
|
if(window.location.href.includes('edit')){
|
|
|
|
this.checkPaginasPresupuesto();
|
|
|
|
// Si es negro o color
|
|
if ($('#tipoImpresion').select2('data')[0].id == 'negro' ||
|
|
$('#tipoImpresion').select2('data')[0].id == 'color') {
|
|
$('#compPaginasNegro').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColor').val()));
|
|
$('#compPaginasNegro').trigger('change')
|
|
}
|
|
// Si es negrohq o colorhq
|
|
if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' ||
|
|
$('#tipoImpresion').select2('data')[0].id == 'colorhq') {
|
|
$('#compPaginasNegrohq').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColorhq').val()));
|
|
$('#compPaginasNegrohq').trigger('change');
|
|
}
|
|
|
|
// TO-DO
|
|
/*
|
|
updatePresupuesto({
|
|
update_lineas: true,
|
|
update_servicios: true,
|
|
update_envios: true,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
})
|
|
*/
|
|
}
|
|
}
|
|
|
|
|
|
changeTirada(update_tiradas_alternativas = true) {
|
|
|
|
this.calcular_mermas()
|
|
|
|
const url2 = window.location.href;
|
|
const url_parts2 = url2.split('/');
|
|
|
|
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()
|
|
*/
|
|
}
|
|
}
|
|
|
|
calcular_mermas(){
|
|
|
|
const tirada = parseInt($('#tirada').val());
|
|
const POD = parseInt($('#POD').val());
|
|
let merma = 0;
|
|
let htmlString = '';
|
|
|
|
if(tirada> POD){
|
|
merma = tirada*0.1<=POD ? tirada*0.1 : POD;
|
|
}
|
|
else{
|
|
let merma_lineas = []
|
|
tableLineasPresupuesto.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 = parseInt($('#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{
|
|
htmlString = `
|
|
<div class="alert alert-warning d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-bell ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.Presupuestos.validation.no_lp_for_merma +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
|
|
|
|
merma = 0
|
|
|
|
}
|
|
|
|
}
|
|
$('#mermacubierta').val(parseInt(merma))
|
|
$('#merma').val(parseInt(merma))
|
|
$('#alert-datosLibro').html(htmlString)
|
|
}
|
|
|
|
|
|
cargarDatos(datos) {
|
|
|
|
this.paginas.val(datos.paginas);
|
|
this.tirada.val(datos.tirada);
|
|
this.calcular_mermas();
|
|
if (datos.papelFormatoPersonalizado) {
|
|
this.tamanioPersonalizado.prop('checked', true);
|
|
$(".tamanio-personalizado").removeClass('d-none');
|
|
$(".tamanio-estandar").addClass('d-none');
|
|
this.anchoPersonalizado.val(datos.papelFormatoAlto);
|
|
this.altoPersonalizado.val(datos.papelFormatoAncho);
|
|
}
|
|
else {
|
|
$(".tamanio-personalizado").addClass('d-none');
|
|
$(".tamanio-estandar").removeClass('d-none');
|
|
this.tamanio.setOption(datos.papelFormatoId, datos.papelFormatoNombre);
|
|
}
|
|
|
|
this.merma.val(datos.merma);
|
|
this.mermaCubierta.val(datos.mermaCubierta);
|
|
|
|
if ($('#tipo_impresion_id').val() == 1 || $('#tipo_impresion_id').val() == 3 ||
|
|
$('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 7) {
|
|
$(".solapas-cubierta-div").addClass('d-none');
|
|
}
|
|
else{
|
|
if (datos.solapasCubierta) {
|
|
this.solapasCubierta.prop('checked', true);
|
|
this.anchoSolapasCubierta.val(datos.solapasCubiertaAncho);
|
|
this.divSolapasSobrecubierta.removeClass('d-none');
|
|
}
|
|
else{
|
|
this.solapasCubierta.prop('checked', false);
|
|
this.anchoSolapasCubierta.val(0);
|
|
this.divSolapasSobrecubierta.addClass('d-none');
|
|
}
|
|
}
|
|
if (datos.solapasSobrecubierta) {
|
|
this.solapasSobrecubierta.prop('checked', true);
|
|
this.anchoSolapasSobrecubierta.val(datos.solapasSobrecubiertaAncho);
|
|
$('#div_solapas_ancho_sobrecubierta').removeClass('d-none');
|
|
}
|
|
else{
|
|
this.solapasSobrecubierta.prop('checked', false);
|
|
this.anchoSolapasSobrecubierta.val(60);
|
|
$('#div_solapas_ancho_sobrecubierta').addClass('d-none');
|
|
}
|
|
|
|
|
|
this.acabadoCubierta.setOption(datos.acabadoCubierta.id, datos.acabadoCubierta.text);
|
|
|
|
if ($('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 6 ||
|
|
$('#tipo_impresion_id').val() == 7 || $('#tipo_impresion_id').val() == 8
|
|
|| $('#tipo_impresion_id').val() == 21) {
|
|
$(".impresion-con-sobrecubierta").addClass('d-none');
|
|
}
|
|
else {
|
|
|
|
this.acabadoSobrecubierta.setOption(datos.acabadoSobrecubierta.id, datos.acabadoSobrecubierta.text);
|
|
}
|
|
|
|
this.retractilado.prop('checked', datos.retractilado);
|
|
this.retractilado5.prop('checked', datos.retractilado5);
|
|
this.imprimirFajaColor.prop('checked', datos.fajaColor);
|
|
this.prototipo.prop('checked', datos.prototipo);
|
|
this.ferro.prop('checked', datos.ferro);
|
|
this.ferroDigital.prop('checked', datos.ferroDigital);
|
|
this.marcapaginas.prop('checked', datos.marcapaginas);
|
|
}
|
|
}
|
|
|
|
|
|
export default DatosLibro; |