mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en añadir tiradas alternativas
This commit is contained in:
@ -8,6 +8,7 @@ class tarjetaDireccion {
|
||||
this.card = this.#generateHTML(id, direccion);
|
||||
this.deleteBtn = this.card.find('.direccion-eliminar');
|
||||
this.editBtn = this.card.find('.direccion-editar');
|
||||
this.direccion = direccion;
|
||||
}
|
||||
|
||||
|
||||
@ -89,13 +90,21 @@ class tarjetaDireccion {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
getPaisId() {
|
||||
return this.direccion.pais_id;
|
||||
}
|
||||
|
||||
getDireccion() {
|
||||
return this.direccion;
|
||||
}
|
||||
|
||||
getDireccionId() {
|
||||
return this.direccionId;
|
||||
}
|
||||
|
||||
getFormData() {
|
||||
return {
|
||||
id: this.direccionId,
|
||||
direccion: this.direccion,
|
||||
unidades: this.getUnidades(),
|
||||
entregaPalets: this.getEntregaPalets()
|
||||
};
|
||||
|
||||
@ -8,6 +8,7 @@ import LineasPresupuesto from './sections/lineasPresupuesto.js';
|
||||
import PreviewFormasAdmin from './sections/previewFormasAdmin.js';
|
||||
import Servicios from './sections/servicios.js';
|
||||
import Envios from './sections/envios.js';
|
||||
import TiradasAlernativas from './sections/tiradasAlternativas.js';
|
||||
|
||||
class PresupuestoAdminEdit {
|
||||
|
||||
@ -40,6 +41,9 @@ class PresupuestoAdminEdit {
|
||||
this.previewFormasAdmin = null;
|
||||
this.servicios = new Servicios();
|
||||
this.envios = new Envios();
|
||||
this.tiradasAlternativas = new TiradasAlernativas({
|
||||
getDimensionLibro: this.getDimensionLibro,
|
||||
});
|
||||
this.calcularPresupuesto = false;
|
||||
}
|
||||
|
||||
@ -69,7 +73,6 @@ class PresupuestoAdminEdit {
|
||||
this.datosLibro.init();
|
||||
this.comparador.init();
|
||||
this.lineasPresupuesto.init();
|
||||
this.envios.init();
|
||||
|
||||
this.previewFormasAdmin = new PreviewFormasAdmin(tipoLibro, this.tipoTapa,
|
||||
{
|
||||
@ -84,6 +87,8 @@ class PresupuestoAdminEdit {
|
||||
);
|
||||
this.previewFormasAdmin.init();
|
||||
this.servicios.init();
|
||||
this.envios.init();
|
||||
this.tiradasAlternativas.init();
|
||||
|
||||
if (window.location.href.includes("edit")) {
|
||||
|
||||
@ -128,6 +133,14 @@ class PresupuestoAdminEdit {
|
||||
|
||||
self.servicios.cargar(response.data.servicios);
|
||||
self.envios.cargar(response.data.direcciones);
|
||||
|
||||
$('#comentariosCliente').val(response.data.comentarios_cliente);
|
||||
$('#comentariosSafekat').val(response.data.comentarios_safekat);
|
||||
$('#comentariosPdf').val(response.data.comentarios_presupuesto);
|
||||
$('#comentariosProduccion').val(response.data.comentarios_produccion);
|
||||
|
||||
self.tiradasAlternativas.cargar(response.data.tiradasAlternativas);
|
||||
|
||||
/*self.direcciones.handleChangeCliente();
|
||||
|
||||
self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);
|
||||
|
||||
@ -0,0 +1,338 @@
|
||||
import { getToken } from "../../../common/common.js";
|
||||
|
||||
class TiradasAlernativas {
|
||||
|
||||
constructor(functions = {}) {
|
||||
|
||||
this.getDimensionLibro = functions.getDimensionLibro;
|
||||
|
||||
this.csrf_token = getToken();
|
||||
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
|
||||
|
||||
this.addTirada = $('#add_tirada_alt');
|
||||
this.tirada = $('#tirada_alt');
|
||||
|
||||
this.table = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
this.addTirada.on('click', this.addTiradaAlt.bind(this));
|
||||
|
||||
this.table = $('#tableTiradas').DataTable({
|
||||
|
||||
"language": {
|
||||
"url": "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
},
|
||||
"paging": false,
|
||||
"info": false,
|
||||
"searching": false,
|
||||
"ordering": true,
|
||||
"autoWidth": false,
|
||||
"responsive": true,
|
||||
"columnDefs": [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [$('#tableTiradas').find("tr:first th").length - 1]
|
||||
},
|
||||
],
|
||||
"columns": [
|
||||
{ data: "tirada" },
|
||||
{ data: 'coste_impresion' },
|
||||
{
|
||||
data: 'coste_envio',
|
||||
render: function (data, type, row) {
|
||||
return parseFloat(data).toFixed(2);
|
||||
},
|
||||
},
|
||||
{
|
||||
data: 'margen',
|
||||
render: function (data, type, row) {
|
||||
return data + '%';
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'total_pedido',
|
||||
render: function (data, type, row) {
|
||||
return parseFloat(data).toFixed(2);
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'precio_unidad',
|
||||
render: function (data, type, row) {
|
||||
return parseFloat(data).toFixed(4);
|
||||
}
|
||||
},
|
||||
{
|
||||
data: function (row, type, set, meta) {
|
||||
return `
|
||||
<a href="javascript:void(0);"><i class="ti ti-check ti-sm comfirm-tirada-alt mx-2" ></i></a>
|
||||
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-tirada mx-2" F></i></a>
|
||||
`;
|
||||
},
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
order: [[0, 'asc']]
|
||||
});
|
||||
|
||||
// Evento de borrado de una fila de la tabla de tiradas
|
||||
$(document).on('click', '.btn-delete-tirada', function (e) {
|
||||
|
||||
const row = $(this).closest('tr');
|
||||
self.table.row(row)
|
||||
.remove()
|
||||
.draw();
|
||||
showBreadCrumbSaveButton(true);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
cargar(datos) {
|
||||
|
||||
this.table.clear().draw();
|
||||
this.table.rows.add(datos).draw();
|
||||
}
|
||||
|
||||
|
||||
addTiradaAlt() {
|
||||
|
||||
const self = this;
|
||||
const id = window.location.href.split('/').pop();
|
||||
|
||||
const tirada = parseInt(this.tirada.val());
|
||||
const tirada_ejemplo = parseInt($('#tirada').val());
|
||||
const POD = parseInt($('#POD').val());
|
||||
|
||||
if ((tirada_ejemplo > POD && tirada <= POD) ||
|
||||
(tirada_ejemplo <= POD && tirada > POD)) {
|
||||
popErrorAlert('No se pueden mezclar tiradas POD y no POD', 'alert-tiradas_alt');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.table.rows().count() > 0) {
|
||||
let tiradas = this.table.rows().data().toArray();
|
||||
if (tiradas.find(t => parseInt(t.tirada) == tirada)) {
|
||||
popErrorAlert('La tirada ya existe', 'alert-tiradas_alt');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const dimension = this.getDimensionLibro();
|
||||
|
||||
const envios = JSON.stringify($('#tableOfDireccionesEnvio').DataTable().rows().data().toArray());
|
||||
|
||||
let datos = {
|
||||
id: id,
|
||||
tirada: this.tirada.val(),
|
||||
peso_libro: this.get_peso_libro(),
|
||||
tirada_base: $('#tirada').val(),
|
||||
paginas: $('#paginas').val(),
|
||||
merma: this.getMerma(tirada),
|
||||
tipo_impresion_id: $('#tipo_impresion_id').val(),
|
||||
json_tiradas: this.generate_json_lp(),
|
||||
json_acabados: this.generate_json_servicios('acabados'),
|
||||
json_encuadernaciones: this.generate_json_servicios('encuadernaciones'),
|
||||
json_manipulado: this.generate_json_servicios('manipulado'),
|
||||
json_envios: envios,
|
||||
ancho: dimension.ancho,
|
||||
alto: dimension.alto,
|
||||
cliente_id: $('#clienteId').find(":selected").val(),
|
||||
solapas_cubierta: $('#solapas').is(':checked') ? 1 : 0,
|
||||
solapas_cubierta_ancho: $('#solapas').is(':checked') ? parseInt($('#solapas_ancho').val()) : 0,
|
||||
solapas_sobrecubierta: $('#solapas_sobrecubierta').is(':checked') ? 1 : 0,
|
||||
solapas_sobrecubierta_ancho: $('#solapas_sobrecubierta').is(':checked') ? parseInt($('#solapas_ancho_sobrecubierta').val()) : 0,
|
||||
lomo: $('#lomo_cubierta').val(),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/presupuestotiradasalternativas/datatable_2',
|
||||
data: datos,
|
||||
success: async function (data) {
|
||||
|
||||
var coste_total = 0.0;
|
||||
var margen_total = 0.0;
|
||||
|
||||
var costes_servicios = 0.0;
|
||||
var margen_servicios = 0.0;
|
||||
|
||||
var coste_envio = 0.0;
|
||||
var margen_envio = 0.0;
|
||||
|
||||
if (data.lineas.length > 0) {
|
||||
// Se cogen los valores de la linea con los datos correspondientes
|
||||
data.lineas.forEach(function (value) {
|
||||
coste_total += value.total_coste;
|
||||
margen_total += value.total_margen;
|
||||
});
|
||||
|
||||
if (data.servicios) {
|
||||
costes_servicios += data.servicios.coste;
|
||||
margen_servicios += data.servicios.margen;
|
||||
|
||||
}
|
||||
|
||||
$('#tableOfServiciosPreimpresion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
costes_servicios += parseFloat(rowData.coste);
|
||||
margen_servicios += parseFloat(rowData.precio) - parseFloat(rowData.coste);
|
||||
});
|
||||
|
||||
$('#tableOfServiciosExtra').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
costes_servicios += parseFloat(rowData.coste);
|
||||
margen_servicios += parseFloat(rowData.precio) - parseFloat(rowData.coste);
|
||||
});
|
||||
|
||||
if (data.envios) {
|
||||
coste_envio += data.envios.coste;
|
||||
margen_envio += data.envios.margen;
|
||||
|
||||
}
|
||||
|
||||
// Se añade la fila a la tabla de tiradas
|
||||
self.table.row.add({
|
||||
tirada: datos.tirada,
|
||||
coste_impresion: coste_total.toFixed(2),
|
||||
coste_envio: coste_envio.toFixed(2),
|
||||
margen: ((margen_total + margen_servicios + margen_envio) / (coste_total + coste_envio) * 100.0).toFixed(2),
|
||||
total_pedido: (coste_total + costes_servicios + coste_envio).toFixed(2),
|
||||
precio_unidad: ((coste_total + costes_servicios + coste_envio) / datos.tirada).toFixed(4),
|
||||
|
||||
}).draw(false);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
error: function (e) { }
|
||||
});
|
||||
}
|
||||
|
||||
generate_json_lp() {
|
||||
|
||||
const data = $('#tableLineasPresupuesto').DataTable().data().toArray();
|
||||
|
||||
let json = this.filterData(data,
|
||||
['paginas',
|
||||
'numPagColor',
|
||||
'paginas_impresion',
|
||||
'papel', // papel generico
|
||||
'papel_impresion_id',
|
||||
'gramaje',
|
||||
'maquina_id',
|
||||
'aFavorFibra',
|
||||
'row_id',
|
||||
'check_papel_total',
|
||||
'check_impresion_total',
|
||||
'cobAmarillo', // tipologia de papel
|
||||
'cobCyan',
|
||||
'cobMagenta',
|
||||
'cobNegro',
|
||||
'cobCG',
|
||||
'gotaColor',
|
||||
'gotaNegro']);
|
||||
|
||||
json.forEach(element => {
|
||||
element['check_papel_total'] = $('#' + element['row_id'] + '_checkPapel').is(':checked') ? 1 : 0;
|
||||
element['check_impresion_total'] = $('#' + element['row_id'] + '_checkClicks').is(':checked') ? 1 : 0;
|
||||
});
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
|
||||
generate_json_servicios(servicios) {
|
||||
|
||||
let json = [];
|
||||
switch (servicios) {
|
||||
case 'acabados':
|
||||
$('#tableOfServiciosAcabado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
json.push(rowData);
|
||||
});
|
||||
break;
|
||||
case 'encuadernaciones':
|
||||
$('#tableOfServiciosEncuadernacion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
json.push(rowData);
|
||||
});
|
||||
break;
|
||||
case 'presimpresion':
|
||||
$('#tableOfServiciosPreimpresion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
json.push(rowData);
|
||||
});
|
||||
break;
|
||||
case 'manipulado':
|
||||
$('#tableOfServiciosManipulado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
json.push(rowData);
|
||||
});
|
||||
break;
|
||||
case 'extra':
|
||||
$('#tableOfServiciosExtra').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
json.push(rowData);
|
||||
});
|
||||
break;
|
||||
}
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
|
||||
get_peso_libro() {
|
||||
|
||||
var peso_total_libro = 0.0
|
||||
$('#tableLineasPresupuesto').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var rowData = this.data();
|
||||
peso_total_libro += parseFloat(rowData.peso)
|
||||
})
|
||||
return peso_total_libro;
|
||||
}
|
||||
|
||||
getMerma(tirada) {
|
||||
|
||||
let merma = 0;
|
||||
|
||||
if (tirada > parseInt($('#POD').val())) {
|
||||
|
||||
merma = tirada * 0.1 <= 30 ? tirada * 0.1 : 30
|
||||
}
|
||||
else {
|
||||
let merma_lineas = []
|
||||
$('#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 = $('#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
|
||||
merma = 0
|
||||
}
|
||||
return merma;
|
||||
}
|
||||
|
||||
filterData(data, keys) {
|
||||
|
||||
return data.map(obj => {
|
||||
|
||||
const newObj = {};
|
||||
keys.forEach(key => {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
});
|
||||
return newObj;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default TiradasAlernativas;
|
||||
@ -104,7 +104,7 @@ class Direcciones {
|
||||
for (let i = 0; i < datos.length; i++) {
|
||||
|
||||
let id = datos[i].id;
|
||||
let unidades = datos[i].unidades;
|
||||
let unidades = datos[i].cantidad;
|
||||
let entregaPalets = datos[i].palets;
|
||||
|
||||
|
||||
@ -113,7 +113,22 @@ class Direcciones {
|
||||
if (unidades == null || unidades <= 0 || unidades == undefined)
|
||||
return;
|
||||
|
||||
let peticion = new Ajax('/misdirecciones/getDireccionPresupuesto/' + id, {}, {},
|
||||
let divId = "dirEnvio-1";
|
||||
let direccionesActuales = this.divDirecciones.find('.direccion-cliente');
|
||||
if (direccionesActuales.length > 0) {
|
||||
// the the lass item
|
||||
let last = direccionesActuales[direccionesActuales.length - 1];
|
||||
divId = "dirEnvio-" + (parseInt(last.id.split('-')[1]) + 1);
|
||||
}
|
||||
let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, datos[i]);
|
||||
tarjeta.setUnidades(unidades);
|
||||
tarjeta.setEntregaPalets(entregaPalets);
|
||||
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self));
|
||||
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self));
|
||||
this.divDirecciones.append(tarjeta.card);
|
||||
this.direcciones.push(tarjeta);
|
||||
|
||||
/*let peticion = new Ajax('/misdirecciones/getDireccionPresupuesto/' + id, {}, {},
|
||||
(response) => {
|
||||
let divId = "dirEnvio-1";
|
||||
let direccionesActuales = this.divDirecciones.find('.direccion-cliente');
|
||||
@ -134,7 +149,7 @@ class Direcciones {
|
||||
console.error('Error getting address');
|
||||
});
|
||||
|
||||
peticion.get();
|
||||
peticion.get();*/
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@ -226,7 +241,7 @@ class Direcciones {
|
||||
let direcciones = [];
|
||||
this.direcciones.forEach(direccion => {
|
||||
let dir = {
|
||||
id: direccion.getId(),
|
||||
direccion: direccion.getDireccion(),
|
||||
unidades: direccion.getUnidades(),
|
||||
entregaPalets: direccion.getEntregaPalets()
|
||||
};
|
||||
@ -306,12 +321,23 @@ class Direcciones {
|
||||
total_unidades += parseInt(this.direcciones[i].getUnidades());
|
||||
}
|
||||
|
||||
|
||||
if (this.getSelectedTirada() == null) {
|
||||
popErrorAlert("Tiene que seleccionar una tirada para insertar una dirección");
|
||||
return;
|
||||
}
|
||||
|
||||
if (total_unidades + parseInt(unidades) > this.getSelectedTirada()) {
|
||||
popErrorAlert("El total de unidades enviadas tiene que ser menor que " + this.getSelectedTirada());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.getSelectedTirada() == null) {
|
||||
popErrorAlert("Tiene que seleccionar una tirada para insertar una dirección");
|
||||
return;
|
||||
}
|
||||
|
||||
if (unidades > this.getSelectedTirada()) {
|
||||
popErrorAlert("El total de unidades enviadas tiene que ser menor que " + this.getSelectedTirada());
|
||||
return;
|
||||
|
||||
@ -569,6 +569,9 @@ class PresupuestoCliente {
|
||||
popAlert2Hide();
|
||||
|
||||
for (let i = 0; i < response.tiradas.length; i++) {
|
||||
if(i==0){
|
||||
$('#eb').val(response.eb[i]);
|
||||
}
|
||||
new tarjetaTiradasPrecio(
|
||||
this.divTiradasPrecios,
|
||||
('precio-tiradas-' + response.tiradas[i]),
|
||||
@ -677,6 +680,10 @@ class PresupuestoCliente {
|
||||
},
|
||||
}
|
||||
|
||||
if(this.direcciones.getSelectedTirada() != null && this.direcciones.getSelectedTirada() != undefined && this.direcciones.getSelectedTirada() > 0){
|
||||
this.datos.selectedTirada = this.direcciones.getSelectedTirada();
|
||||
}
|
||||
|
||||
this.datos.guardas = this.disenioCubierta.getGuardas();
|
||||
|
||||
if (calcularSolapas) {
|
||||
@ -692,6 +699,7 @@ class PresupuestoCliente {
|
||||
this.datos.retractilado = this.datosGenerales.retractilado.is(':checked') ? 1 : 0;
|
||||
this.datos.retractilado5 = this.datosGenerales.retractilado5.is(':checked') ? 1 : 0;
|
||||
|
||||
this.datos.eb = $('#eb').val();
|
||||
|
||||
this.datos.cubierta = {
|
||||
tipoCubierta: this.disenioCubierta.disenioCubierta.filter('.selected').attr('id'),
|
||||
@ -758,6 +766,7 @@ class PresupuestoCliente {
|
||||
referenciaCliente: this.datosGenerales.referenciaCliente.val(),
|
||||
}
|
||||
this.datos.selectedTirada = this.direcciones.getSelectedTirada();
|
||||
this.datos
|
||||
}
|
||||
|
||||
if (window.location.href.includes("edit")) {
|
||||
|
||||
Reference in New Issue
Block a user