trabajando en direcciones!

This commit is contained in:
2025-01-13 01:51:36 +01:00
parent c6d1d06d8a
commit 522e026ded
15 changed files with 572 additions and 2263 deletions

View File

@ -7,6 +7,7 @@ import Comparador from './sections/comparador.js';
import LineasPresupuesto from './sections/lineasPresupuesto.js';
import PreviewFormasAdmin from './sections/previewFormasAdmin.js';
import Servicios from './sections/servicios.js';
import Envios from './sections/envios.js';
class PresupuestoAdminEdit {
@ -38,6 +39,7 @@ class PresupuestoAdminEdit {
this.previewFormasAdmin = null;
this.servicios = new Servicios();
this.envios = new Envios();
this.calcularPresupuesto = false;
}
@ -67,6 +69,7 @@ class PresupuestoAdminEdit {
this.datosLibro.init();
this.comparador.init();
this.lineasPresupuesto.init();
this.envios.init();
this.previewFormasAdmin = new PreviewFormasAdmin(tipoLibro, this.tipoTapa,
{
@ -124,6 +127,7 @@ class PresupuestoAdminEdit {
self.lineasPresupuesto.cargarDatos(response.data.lineasPresupuesto);
self.servicios.cargar(response.data.servicios);
self.envios.cargar(response.data.direcciones);
/*self.direcciones.handleChangeCliente();
self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);

View File

@ -66,8 +66,8 @@ class DatosLibro {
this.acabadoSobrecubierta.init();
this.acabadoCubierta.item.on('select2:select', function () {
$(document).trigger('add-servicio-lineas', 'acabadoCubierta');
$(document).trigger('add-servicio-lineas', 'acabadoCubierta');
});
this.acabadoSobrecubierta.item.on('select2:select', function () {
$(document).trigger('add-servicio-lineas', 'acabadoSobrecubierta');
@ -96,9 +96,10 @@ class DatosLibro {
$('.formato-libro').on('change', function () {
$(document).trigger('update-lineas-presupuesto');
$(document).trigger('update-servicios');
/* TO-DO
updatePresupuesto({
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
@ -116,7 +117,7 @@ class DatosLibro {
$(document).trigger('remove-servicio-lineas', 'fajaColor');
}
}
changeFerro() {
if (this.ferro.prop('checked')) {
@ -130,7 +131,7 @@ class DatosLibro {
changePrototipo() {
if (this.prototipo.prop('checked')) {
$(document).trigger('add-servicio-lineas', 'prototipo');
this.ferro.prop('checked', true).trigger('change');
}
@ -183,33 +184,32 @@ class DatosLibro {
this.checkPaginasPresupuesto();
$(document).trigger('update-lineas-presupuesto');
$(document).trigger('update-servicios');
// TO-DO
/*updatePresupuesto({
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
})*/
}
changeTipoTamanio(){
if(this.tamanioPersonalizado.prop('checked')){
changeTipoTamanio() {
if (this.tamanioPersonalizado.prop('checked')) {
$('.tamanio-personalizado').removeClass('d-none');
$('.tamanio-estandar').addClass('d-none');
this.tamanio.setVal('');
$("#label_papelFormatoId").text(
$("#label_papelFormatoId").text(
window.language.Presupuestos.papelFormatoId + " (" +
window.language.Presupuestos.papelFormatoAncho + " x " + window.language.Presupuestos.papelFormatoAncho + ")*");
}
else{
else {
this.anchoPersonalizado.val("");
this.altoPersonalizado.val("");
$('.tamanio-personalizado').addClass('d-none');
$('.tamanio-estandar').removeClass('d-none');
$("#label_papelFormatoId").text(
$("#label_papelFormatoId").text(
window.language.Presupuestos.papelFormatoId + '*');
}
$(document).trigger('update-lineas-presupuesto');
@ -218,59 +218,67 @@ class DatosLibro {
changeSolapasCubierta() {
if (this.solapasCubierta.prop('checked')) {
$('#div_solapas_ancho').removeClass('d-none');
}
else {
$('#div_solapas_ancho').divSolapasCubierta.addClass('d-none');
this.anchoSolapasCubierta.val(0);
}
$('#serv_default').trigger('click');
setTimeout(() => {
if (this.solapasCubierta.prop('checked')) {
$('#div_solapas_ancho').removeClass('d-none');
$(document).trigger('add-servicio-lineas', 'solapas');
}
else {
$('#div_solapas_ancho').addClass('d-none');
this.anchoSolapasCubierta.val(60);
$(document).trigger('remove-servicio-lineas', 'solapas');
}
}, 100);
$(document).trigger('update-servicios');
}
changeSolapasSobrecubierta() {
if (this.solapasSobrecubierta.prop('checked')) {
this.divSolapasSobrecubierta.removeClass('d-none');
$(document).trigger('remove-servicio-lineas', 'solapas');
}
else {
this.divSolapasSobrecubierta.addClass('d-none');
this.anchoSolapasSobrecubierta.val(0);
this.anchoSolapasSobrecubierta.val(60);
$(document).trigger('add-servicio-lineas', 'solapas');
}
$('#serv_default').trigger('click');
$(document).trigger('update-servicios');
}
changePaginas() {
if($('#tipo_impresion_id').val() == 21){
if(parseInt($('#paginas').val()) > 80){
if ($('#tipo_impresion_id').val() == 21) {
if (parseInt($('#paginas').val()) > 80) {
$('#paginas').val(80)
}
}
if(window.location.href.includes('edit')){
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').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').val(parseInt($('#paginas').val()) - parseInt($('#compPaginasColorhq').val()));
$('#compPaginasNegrohq').trigger('change');
}
$(document).trigger('update-lineas-presupuesto');
$(document).trigger('update-servicios');
// TO-DO
/*
updatePresupuesto({
update_lineas: true,
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
@ -278,16 +286,16 @@ class DatosLibro {
*/
}
}
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'){
if (url_parts2[url_parts2.length - 2] == 'edit') {
$(document).trigger('update-lineas-presupuesto');
//update_servicios(false)
//updateLineasPresupuesto()
@ -314,35 +322,35 @@ class DatosLibro {
*/
}
}
calcular_mermas(){
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;
if (tirada > POD) {
merma = tirada * 0.1 <= POD ? tirada * 0.1 : POD;
}
else{
else {
let merma_lineas = []
$('#tableLineasPresupuesto').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
$('#tableLineasPresupuesto').DataTable().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)
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)
merma_lineas.push(tirada % formas_linea)
}
})
if(merma_lineas.length>0)
if (merma_lineas.length > 0)
merma = Math.max(...merma_lineas)
else{
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">
@ -350,16 +358,16 @@ class DatosLibro {
</span>
<div class="d-flex flex-column ps-1">
<h5 class="alert-heading mb-2">` +
window.language.Presupuestos.validation.no_lp_for_merma +
`</h5>
window.language.Presupuestos.validation.no_lp_for_merma +
`</h5>
</div>
</div>`;
</div>`;
merma = 0
}
}
$('#mermacubierta').val(parseInt(merma))
$('#merma').val(parseInt(merma))
@ -392,15 +400,15 @@ class DatosLibro {
$('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 7) {
$(".solapas-cubierta-div").addClass('d-none');
}
else{
else {
if (datos.solapasCubierta) {
this.solapasCubierta.prop('checked', true);
this.anchoSolapasCubierta.val(datos.solapasCubiertaAncho);
this.divSolapasSobrecubierta.removeClass('d-none');
}
else{
else {
this.solapasCubierta.prop('checked', false);
this.anchoSolapasCubierta.val(0);
this.anchoSolapasCubierta.val(60);
this.divSolapasSobrecubierta.addClass('d-none');
}
}
@ -409,12 +417,12 @@ class DatosLibro {
this.anchoSolapasSobrecubierta.val(datos.solapasSobrecubiertaAncho);
$('#div_solapas_ancho_sobrecubierta').removeClass('d-none');
}
else{
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);

View File

@ -0,0 +1,125 @@
import Ajax from "../../../components/ajax.js";
import { getToken } from "../../../common/common.js";
class Envios {
constructor() {
this.csrf_token = getToken();
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
this.recogerTaller = $('#recoger_en_taller');
this.table = null;
}
init() {
const self = this;
this.table = $('#tableOfDireccionesEnvio').DataTable({
draw: 5,
serverSide: false,
processing: true,
autoWidth: true,
responsive: true,
order: [[0, "asc"]],
pageLength: 20,
lengthChange: false,
searching: false,
paging: false,
info: false,
scrollX: true,
columns: [
{ 'data': 'tarifa_id' },
{ 'data': 'cantidad' },
{ 'data': 'peso' },
{ 'data': 'att' },
{ 'data': 'email' },
{ 'data': 'direccion' },
{ 'data': 'cp' },
{ 'data': 'municipio' },
{ 'data': 'pais' },
{ 'data': 'telefono' },
{ 'data': 'proveedor' },
{ 'data': 'proveedor_id' },
{ 'data': 'precio' },
{ 'data': 'margen' },
{ 'data': 'entregaPieCalle' },
{
data: function (row, type, set, meta) {
return `
<span class="edit-add"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit-add mx-2" data-id="${row.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>
`;
},
className: 'row-edit dt-center'
}
],
columnDefs: [
{
orderable: false,
searchable: false,
targets: [$('#tableOfDireccionesEnvio').find("tr:first th").length - 1]
},
{ "orderData": [0], "targets": 0 },
],
columnDefs: [
{
target: [11],
visible: false,
searchable: false
},
],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
drawCallback: function (settings) {
self.check_unidades_enviadas();
}
});
}
cargar(datos) {
if (datos.entrega_taller) {
this.recogerTaller.prop('checked', true);
}
else {
this.table.rows.add(datos).draw();
}
}
check_unidades_enviadas() {
var cantidad_total = 0
this.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
cantidad_total += parseInt(this.data().cantidad)
});
const tirada = parseInt($('#tirada').val());
let htmlString = '';
if (cantidad_total < tirada && this.recogerTaller.prop('checked') === false) {
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.language.Presupuestos.validation.ejemplares_envio +
`</h5>
</div>
</div>`;
$('#alert-envios').html(htmlString);
return false;
}
$('#alert-envios').html(htmlString);
return true;
}
}
export default Envios;

View File

@ -37,7 +37,6 @@ class LineasPresupuesto {
// TO-DO
/*updatePresupuesto({
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
@ -1605,8 +1604,6 @@ class LineasPresupuesto {
calcular_mermas()
updatePresupuesto({
update_lineas: false,
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
@ -1923,10 +1920,10 @@ class LineasPresupuesto {
*/
}
/* TO-DO
updatePresupuesto({
update_lineas: false,
update_servicios: true,
update_envios: false,
update_resumen: true,
update_tiradas_alternativas: true

View File

@ -53,9 +53,9 @@ class Servicios {
})
$(document).on('add-servicio-lineas', this.addServicio.bind(this));
$(document).on('remove-servicio-lineas', this.addServicio.bind(this));
$(document).on('remove-servicio-lineas', this.removeServicio.bind(this));
$(document).on('change', '.update-totales-servicios', function () {
@ -71,6 +71,7 @@ class Servicios {
showBreadCrumbSaveButton(true);
});
$(document).on('update-servicios', this.updateServicios.bind(this));
}
cargar(datos) {
@ -96,13 +97,25 @@ class Servicios {
else if (servicio == 'acabadoSobrecubierta') {
this.serviciosAcabado.updateAcabadosExteriores(0, 1);
}
else if (servicio == 'solapas') {
this.ServiciosManipulado.addSolapas();
}
}
removeServicio(servicio) {
removeServicio(event, servicio) {
if (servicio == 'solapas') {
this.ServiciosManipulado.removeSolapas();
}
}
updateServicios() {
this.serviciosAcabado.updateServicios();
this.ServiciosEncuadernacion.updateServicios();
this.ServiciosManipulado.updateServicios();
}
}
class ServiciosAcabado {
@ -231,6 +244,11 @@ class ServiciosAcabado {
self.check_serv_acabado_error();
}
/* TO-DO
updatePresupuesto({
update_resumen: true,
update_tiradas_alternativas: true})
*/
});
@ -253,6 +271,45 @@ class ServiciosAcabado {
}); */
}
updateServicios() {
const self = this;
const id = window.location.href.split('/').pop();
const tarifa_ids = this.table.rows().data().toArray().map(row => row.tarifa_id);
const proveedor_ids = this.table.rows().data().toArray().map(row => row.proveedor_id);
const cubiertas = this.table.rows().data().toArray().map(row => row.cubierta);
const sobrecubiertas = this.table.rows().data().toArray().map(row => row.sobrecubierta);
// emparejar los tarifa_ids con los proveedor_ids
let tarifa_data = [];
for (let i = 0; i < tarifa_ids.length; i++) {
tarifa_data.push({ tarifa_id: tarifa_ids[i], proveedor_id: proveedor_ids[i], cubierta: cubiertas[i], sobrecubierta: sobrecubiertas[i] });
}
let tirada = 0;
if (parseInt($('#tirada').val()) > 0) {
tirada = parseInt($('#tirada').val())
}
if (tarifa_ids.length > 0 && tirada > 0) {
const data = {
datos: tarifa_data,
tirada: tirada
};
new Ajax('/serviciosacabados/update/' + id, data, {},
function (response) {
if (response.lineas) {
self.table.clear().draw();
self.table.rows.add(response.lineas).draw();
}
},
function (error) {
console.error(error);
}
).post();
}
}
updateAcabadosExteriores(cubierta, sobrecubierta) {
this.table.rows().every(function () {
@ -461,6 +518,11 @@ class ServiciosPreimpresion {
drawCallback: function (settings) {
self.check_serv_preimpresion_error();
/* TO-DO
updatePresupuesto({
update_resumen: true,
update_tiradas_alternativas: true})
*/
}
@ -750,6 +812,12 @@ class ServiciosEncuadernacion {
})
self.check_serv_enc_error();
/* TO-DO
updatePresupuesto({
update_resumen: true,
update_tiradas_alternativas: true})
*/
}
});
@ -772,6 +840,52 @@ class ServiciosEncuadernacion {
}); */
}
updateServicios() {
const self = this;
const id = window.location.href.split('/').pop();
const tarifa_ids = this.table.rows().data().toArray().map(row => row.tarifa_id);
const proveedor_ids = this.table.rows().data().toArray().map(row => row.proveedor_id);
const cuadernillos = this.table.rows().data().toArray().map(row => row.paginas_por_cuadernillo);
let tarifa_data = [];
for (let i = 0; i < tarifa_ids.length; i++) {
tarifa_data.push({ tarifa_id: tarifa_ids[i], proveedor_id: proveedor_ids[i], paginas_por_cuadernillo: cuadernillos[i] });
}
let tirada = 0;
if (parseInt($('#tirada').val()) > 0) {
tirada = parseInt($('#tirada').val())
}
let paginas = 0;
if (parseInt($('#paginas').val()) > 0) {
paginas = parseInt($('#paginas').val())
}
const dimension = self.getDimensionLibro();
if (tarifa_ids.length > 0 && tirada > 0) {
const data = {
datos: tarifa_data,
tirada: tirada,
paginas: paginas,
ancho: dimension.ancho,
alto: dimension.alto,
};
new Ajax('/serviciosencuadernaciones/update/' + id, data, {},
function (response) {
if (response.lineas) {
self.table.clear().draw();
self.table.rows.add(response.lineas).draw();
}
},
function (error) {
console.error(error);
}
).post();
}
}
cargarServiciosEncuadernacion(datos) {
this.table.rows.add(datos).draw();
@ -779,8 +893,6 @@ class ServiciosEncuadernacion {
async getServiciosDefecto() {
this.table.clear().draw();
const self = this;
let tirada = 0;
@ -806,6 +918,7 @@ class ServiciosEncuadernacion {
new Ajax('/serviciosencuadernaciones/datatable', datos, {},
function (response) {
if (response.values) {
self.table.clear().draw();
self.table.rows.add(response.values).draw();
}
},
@ -1041,6 +1154,12 @@ class ServiciosManipulado {
drawCallback: function (settings) {
self.check_serv_manipulado_error();
/* TO-DO
updatePresupuesto({
update_resumen: true,
update_tiradas_alternativas: true})
*/
}
});
@ -1072,8 +1191,6 @@ class ServiciosManipulado {
async getServiciosDefecto() {
this.table.clear().draw();
const self = this;
let tirada = 0;
@ -1091,6 +1208,7 @@ class ServiciosManipulado {
new Ajax('/serviciosmanipulados/datatable', datos, {},
function (response) {
if (response.values) {
self.table.clear().draw();
self.table.rows.add(response.values).draw();
}
},
@ -1104,6 +1222,86 @@ class ServiciosManipulado {
showBreadCrumbSaveButton(true);
}
addSolapas() {
const self = this;
new Ajax('/serviciosmanipulados/serviciosolapas', {}, {},
function (response) {
if (response.service) {
const tarifa_id = response.service;
var rows = self.table.rows().data().toArray();
var found = rows.some(row => row.tarifa_id === tarifa_id);
if (!found)
self.getPresupuestoManipulado(tarifa_id);
}
},
function (error) {
console.error(error);
}
).get();
}
removeSolapas() {
const self = this;
new Ajax('/serviciosmanipulados/serviciosolapas', {}, {},
function (response) {
if (response.service) {
const tarifa_id = response.service;
var rows = self.table.rows().data().toArray();
for (let i = 0; i < rows.length; i++) {
if (rows[i]['tarifa_id'] == tarifa_id) {
self.table.row(i).remove().draw();
break;
}
}
}
},
function (error) {
console.error(error);
}
).get();
}
updateServicios() {
const self = this;
const id = window.location.href.split('/').pop();
const tarifa_ids = this.table.rows().data().toArray().map(row => row.tarifa_id);
let tirada = 0;
if (parseInt($('#tirada').val()) > 0) {
tirada = parseInt($('#tirada').val())
}
if (tarifa_ids.length > 0) {
const data = {
datos: tarifa_ids,
solapas: $('#solapas').is(':checked') ? 1 : 0,
tirada: tirada
};
new Ajax('/serviciosmanipulados/update/' + id, data, {},
function (response) {
if (response.lineas) {
self.table.clear().draw();
self.table.rows.add(response.lineas).draw();
}
},
function (error) {
console.error(error);
}
).post();
}
}
getPresupuestoManipulado(tarifa_id = -1) {
const self = this;
@ -1238,6 +1436,12 @@ class ServiciosExtra {
drawCallback: function (settings) {
self.check_serv_extra_error();
/* TO-DO
updatePresupuesto({
update_resumen: true,
update_tiradas_alternativas: true})
*/
}

View File

@ -677,6 +677,8 @@ class PresupuestoCliente {
},
}
this.datos.guardas = this.disenioCubierta.getGuardas();
if (calcularSolapas) {
return;
}
@ -700,7 +702,7 @@ class PresupuestoCliente {
carasImpresion: this.disenioCubierta.carasCubierta.val(),
};
this.datos.guardas = this.disenioCubierta.getGuardas();
this.datos.sobrecubierta = this.disenioCubierta.getSobrecubierta();
this.datos.faja = this.disenioCubierta.getFaja();