mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en el comparador
This commit is contained in:
@ -3,6 +3,7 @@ import Ajax from '../../components/ajax.js';
|
||||
|
||||
import DatosGenerales from './sections/datosGenerales.js';
|
||||
import DatosLibro from './sections/datosLibro.js';
|
||||
import Comparador from './sections/comparador.js';
|
||||
|
||||
class PresupuestoAdminEdit {
|
||||
|
||||
@ -26,6 +27,7 @@ class PresupuestoAdminEdit {
|
||||
removeService: this.removeService,
|
||||
checkPaginasPresupuesto: this.checkPaginasPresupuesto,
|
||||
}));
|
||||
this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip'));
|
||||
|
||||
this.calcularPresupuesto = false;
|
||||
}
|
||||
@ -39,6 +41,7 @@ class PresupuestoAdminEdit {
|
||||
|
||||
this.datosGenerales.init();
|
||||
this.datosLibro.init();
|
||||
this.comparador.init();
|
||||
|
||||
if (window.location.href.includes("edit")) {
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
import ClassSelect from '../../../components/select2.js';
|
||||
import { getToken } from '../../../common/common.js';
|
||||
|
||||
class Comparador {
|
||||
|
||||
constructor(domItem) {
|
||||
|
||||
this.domItem = domItem;
|
||||
|
||||
this.csrf_token = getToken();
|
||||
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
|
||||
|
||||
this.comparador_json = this.domItem.find("#comparador_json_data");
|
||||
this.tipo_impresion = $("#tipoImpresion");
|
||||
|
||||
this.paginasNegro = $('#compPaginasNegro');
|
||||
this.papelNegro = new ClassSelect($('#compPapelNegro'),
|
||||
'/papelesgenericos/getpapelcliente', 'Seleccione papel', false,
|
||||
{
|
||||
[this.csrf_token]: this.csrf_hash,
|
||||
tirada: $('#tirada').val(),
|
||||
tipo: 'negro',
|
||||
cubierta: 0,
|
||||
});
|
||||
|
||||
this.gramajeNegro = $('#compGramajeNegro');
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
this.papelNegro.init();
|
||||
}
|
||||
|
||||
cargarDatos(datos) {
|
||||
|
||||
this.tipo_impresion.val(datos.tipo_impresion);
|
||||
this.comparador_json.val(JSON.stringify(datos.json_data));
|
||||
|
||||
//if (datos.json_data.bn)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default Comparador;
|
||||
@ -16,7 +16,7 @@ class DatosLibro {
|
||||
|
||||
this.paginas = this.domItem.find('#paginas');
|
||||
this.tirada = this.domItem.find('#tirada');
|
||||
this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language["formatoLibro"]);
|
||||
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');
|
||||
@ -24,8 +24,8 @@ class DatosLibro {
|
||||
this.mermaCubierta = this.domItem.find('#mermacubierta');
|
||||
this.solapasCubierta = this.domItem.find('#solapas');
|
||||
this.solapasSobrecubierta = this.domItem.find('#solapas_sobrecubierta');
|
||||
this.anchoSolapasCubierta = this.domItem.find('#anchoSolapasCubierta');
|
||||
this.anchoSolapasSobrecubierta = this.domItem.find('#anchoSolapasSobrecubierta');
|
||||
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');
|
||||
@ -81,6 +81,10 @@ class DatosLibro {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,9 +170,31 @@ class DatosLibro {
|
||||
})*/
|
||||
}
|
||||
|
||||
|
||||
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 + '*');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
changeSolapasCubierta() {
|
||||
|
||||
if (this.solapasCubierta.prop('checked', true)) {
|
||||
if (this.solapasCubierta.prop('checked')) {
|
||||
this.divSolapasCubierta.removeClass('d-none');
|
||||
}
|
||||
else {
|
||||
@ -181,7 +207,7 @@ class DatosLibro {
|
||||
|
||||
changeSolapasSobrecubierta() {
|
||||
|
||||
if (this.solapasSobrecubierta.prop('checked', true)) {
|
||||
if (this.solapasSobrecubierta.prop('checked')) {
|
||||
this.divSolapasSobrecubierta.removeClass('d-none');
|
||||
}
|
||||
else {
|
||||
@ -191,6 +217,125 @@ class DatosLibro {
|
||||
$('#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')){
|
||||
|
||||
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'){
|
||||
//update_servicios(false)
|
||||
//updateLineasPresupuesto()
|
||||
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())
|
||||
var merma = 0
|
||||
htmlString = ''
|
||||
|
||||
if(tirada> parseInt($('#POD').val())){
|
||||
merma = tirada*0.1<=30 ? tirada*0.1 : 30
|
||||
}
|
||||
else{
|
||||
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) {
|
||||
|
||||
@ -217,14 +362,14 @@ class DatosLibro {
|
||||
$(".impresion-con-solapas").addClass('d-none');
|
||||
}
|
||||
else {
|
||||
if (datos.solapas) {
|
||||
this.solapasCubierta.val(datos.solapas);
|
||||
this.anchoSolapasCubierta.val(datos.ancho_solapas);
|
||||
if (datos.solapasCubierta) {
|
||||
this.solapasCubierta.prop('checked', true);
|
||||
this.anchoSolapasCubierta.val(datos.solapasCubiertaAncho);
|
||||
$('#div_solapas_ancho').removeClass('d-none');
|
||||
}
|
||||
if (datos.solapas_sobrecubierta) {
|
||||
if (datos.solapasSobrecubierta) {
|
||||
this.solapasSobrecubierta.prop('checked', true);
|
||||
this.anchoSolapasSobrecubierta.val(datos.ancho_solapas_sobrecubierta);
|
||||
this.anchoSolapasSobrecubierta.val(datos.solapasSobrecubiertaAncho);
|
||||
$('#div_solapas_ancho_sobrecubierta').removeClass('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user