mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
1946 lines
69 KiB
JavaScript
1946 lines
69 KiB
JavaScript
import Ajax from "../../../components/ajax.js";
|
|
import { getToken } from "../../../common/common.js";
|
|
import ClassSelect from "../../../components/select2.js";
|
|
|
|
class Servicios {
|
|
|
|
constructor() {
|
|
|
|
this.csrf_token = getToken();
|
|
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
|
|
|
|
this.serviciosAcabado = new ServiciosAcabado(this.csrf_token, this.csrf_hash);
|
|
this.serviciosPreimpresion = new ServiciosPreimpresion(this.csrf_token, this.csrf_hash);
|
|
this.ServiciosEncuadernacion = new ServiciosEncuadernacion(this.csrf_token, this.csrf_hash);
|
|
this.ServiciosManipulado = new ServiciosManipulado(this.csrf_token, this.csrf_hash);
|
|
this.serviciosExtra = new ServiciosExtra(this.csrf_token, this.csrf_hash);
|
|
|
|
//this.serviciosDefecto = $('#serv_default');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.serviciosAcabado.init();
|
|
this.serviciosPreimpresion.init();
|
|
this.ServiciosEncuadernacion.init();
|
|
this.ServiciosManipulado.init();
|
|
this.serviciosExtra.init();
|
|
|
|
/*
|
|
this.serviciosDefecto.on('click', function () {
|
|
|
|
$('#loader').modal('show');
|
|
try {
|
|
self.ServiciosEncuadernacion.getServiciosDefecto().then(function (response) {
|
|
//self.ServiciosManipulado.getServiciosDefecto().then(function (response) {
|
|
$('#loader').modal('hide');
|
|
//});
|
|
});
|
|
}
|
|
catch (error) {
|
|
console.log(error);
|
|
$('#loader').modal('hide');
|
|
}
|
|
});*/
|
|
|
|
$('.nav-servicios button').on('shown.bs.tab', function () {
|
|
$("#tableOfServiciosAcabado").DataTable().columns.adjust();
|
|
$("#tableOfServiciosPreimpresion").DataTable().columns.adjust();
|
|
$("#tableOfServiciosEncuadernacion").DataTable().columns.adjust();
|
|
$("#tableOfServiciosManipulado").DataTable().columns.adjust();
|
|
$("#tableOfServiciosExtra").DataTable().columns.adjust();
|
|
})
|
|
|
|
$(document).on('add-servicio-lineas', this.addServicio.bind(this));
|
|
$(document).on('remove-servicio-lineas', this.removeServicio.bind(this));
|
|
|
|
|
|
|
|
$(document).on('change', '.update-totales-servicios', function () {
|
|
|
|
const row = $(this).closest('tr');
|
|
const table = $(this).closest('table').DataTable();
|
|
|
|
if (!row.length || !table) return;
|
|
|
|
const data = table.row(row).data();
|
|
data.precio_total = parseFloat($(this).val().replace(',', '.'));
|
|
table.row(row).data(data).draw();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
$(document).on('update-servicios', async function () {
|
|
await self.updateServicios()
|
|
|
|
$(document).trigger('update-servicios-completed');
|
|
});
|
|
}
|
|
|
|
cargar(datos) {
|
|
|
|
if (datos.serviciosAcabado.length > 0)
|
|
this.serviciosAcabado.cargarServiciosAcabado(datos.serviciosAcabado);
|
|
if (datos.serviciosPreimpresion.length > 0)
|
|
this.serviciosPreimpresion.cargarServiciosPreimpresion(datos.serviciosPreimpresion);
|
|
if (datos.serviciosEncuadernacion.length > 0)
|
|
this.ServiciosEncuadernacion.cargarServiciosEncuadernacion(datos.serviciosEncuadernacion);
|
|
if (datos.serviciosManipulado.length > 0)
|
|
this.ServiciosManipulado.cargarServiciosManipulado(datos.serviciosManipulado);
|
|
if (datos.serviciosExtra.length > 0)
|
|
this.serviciosExtra.cargarServiciosExtra(datos.serviciosExtra);
|
|
|
|
}
|
|
|
|
async guardar() {
|
|
await this.serviciosAcabado.guardarServiciosAcabado();
|
|
await this.serviciosPreimpresion.guardarServiciosPreimpresion();
|
|
await this.ServiciosEncuadernacion.guardarServiciosEncuadernacion();
|
|
await this.ServiciosManipulado.guardarServiciosManipulado();
|
|
await this.serviciosExtra.guardarServiciosExtra();
|
|
}
|
|
|
|
|
|
addServicio(event, servicio) {
|
|
|
|
if (servicio == 'acabadoCubierta') {
|
|
this.serviciosAcabado.updateAcabadosExteriores(1, 0, 0);
|
|
}
|
|
else if (servicio == 'acabadoSobrecubierta') {
|
|
this.serviciosAcabado.updateAcabadosExteriores(0, 1, 0);
|
|
}
|
|
else if (servicio == 'acabadoFaja') {
|
|
this.serviciosAcabado.updateAcabadosExteriores(0, 0, 1);
|
|
}
|
|
else if (servicio == 'ferro') {
|
|
const id = $('#ferro').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosExtra.table, id))
|
|
this.serviciosExtra.getPresupuestoExtra(id);
|
|
}
|
|
else if (servicio == 'ferro_2') {
|
|
const id = $('#ferro_2').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosExtra.table, id))
|
|
this.serviciosExtra.getPresupuestoExtra(id);
|
|
}
|
|
else if (servicio == 'ferroDigital') {
|
|
const id = $('#ferroDigital').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosExtra.table, id))
|
|
this.serviciosExtra.getPresupuestoExtra(id);
|
|
}
|
|
else if (servicio == 'prototipo') {
|
|
const id = $('#prototipo').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosExtra.table, id))
|
|
this.serviciosExtra.getPresupuestoExtra(id);
|
|
}
|
|
else if (servicio == 'prototipo_2') {
|
|
const id = $('#prototipo_2').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosExtra.table, id))
|
|
this.serviciosExtra.getPresupuestoExtra(id);
|
|
}
|
|
else if (servicio == 'retractilado') {
|
|
const id = $('#retractilado').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosAcabado.table, id))
|
|
this.serviciosAcabado.getPresupuestoAcabado(id, null, null, true);
|
|
}
|
|
else if (servicio == 'retractilado5') {
|
|
const id = $('#retractilado5').attr('service-id');
|
|
if (!this.checkServiceInTable(this.serviciosAcabado.table, id))
|
|
this.serviciosAcabado.getPresupuestoAcabado(id, null, null, true);
|
|
}
|
|
else if (servicio == 'solapas_cubierta') {
|
|
const id = $('#serv_solapas_cubierta').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'solapas_sobrecubierta') {
|
|
const id = $('#serv_solapas_sobrecubierta').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'solapas_faja') {
|
|
const id = $('#solapas_faja').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'solapas_grandes_cubierta') {
|
|
const id = $('#solapas_grandes_cubierta').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'solapas_grandes_sobrecubierta') {
|
|
const id = $('#solapas_grandes_sobrecubierta').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'solapas_grandes_faja') {
|
|
const id = $('#solapas_grandes_faja').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
else if (servicio == 'lomo_redondo') {
|
|
const id = $('#compLomoRedondo').attr('service-id');
|
|
if (!this.checkServiceInTable(this.ServiciosManipulado.table, id))
|
|
this.ServiciosManipulado.getPresupuestoManipulado(id);
|
|
}
|
|
}
|
|
|
|
checkServiceInTable(table, id) {
|
|
for (let i = 0; i < table.rows().count(); i++) {
|
|
let data = table.row(i).data();
|
|
if (data && data.tarifa_id == id) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
removeServicio(event, servicio) {
|
|
|
|
const self = this;
|
|
|
|
if (servicio == 'ferro') {
|
|
const id = $('#ferro').attr('service-id');
|
|
this.serviciosExtra.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data.tarifa_id == id) {
|
|
this.remove();
|
|
self.serviciosExtra.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'ferro_2') {
|
|
const id = $('#ferro_2').attr('service-id');
|
|
this.serviciosExtra.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data.tarifa_id == id) {
|
|
this.remove();
|
|
self.serviciosExtra.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'ferroDigital') {
|
|
const id = $('#ferroDigital').attr('service-id');
|
|
this.serviciosExtra.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data.tarifa_id == id) {
|
|
this.remove();
|
|
self.serviciosExtra.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
else if (servicio == 'prototipo') {
|
|
const id = $('#prototipo').attr('service-id');
|
|
this.serviciosExtra.table.rows().every(function () {
|
|
var data = this.data();
|
|
if (data.tarifa_id == id) {
|
|
this.remove();
|
|
self.serviciosExtra.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'prototipo_2') {
|
|
const id = $('#prototipo_2').attr('service-id');
|
|
this.serviciosExtra.table.rows().every(function () {
|
|
var data = this.data();
|
|
if (data.tarifa_id == id) {
|
|
this.remove();
|
|
self.serviciosExtra.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'retractilado') {
|
|
const id = $('#retractilado').attr('service-id');
|
|
for (let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) {
|
|
let data = this.serviciosAcabado.table.row(i).data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.serviciosAcabado.table.row(i).remove();
|
|
this.serviciosAcabado.table.draw();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else if (servicio == 'retractilado5') {
|
|
const id = $('#retractilado5').attr('service-id');
|
|
for (let i = this.serviciosAcabado.table.rows().count(); i >= 0; i--) {
|
|
let data = this.serviciosAcabado.table.row(i).data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.serviciosAcabado.table.row(i).remove();
|
|
this.serviciosAcabado.table.draw();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else if (servicio == 'solapas_cubierta') {
|
|
const id = $('#serv_solapas_cubierta').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data && parseInt(data.tarifa_id) == id) {
|
|
this.remove();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'solapas_sobrecubierta') {
|
|
const id = $('#serv_solapas_sobrecubierta').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.remove();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'solapas_faja') {
|
|
const id = $('#solapas_faja').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.remove().draw();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'solapas_grandes_cubierta') {
|
|
const id = $('#solapas_grandes_cubierta').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
let data = this.data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.remove();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'solapas_grandes_sobrecubierta') {
|
|
const id = $('#solapas_grandes_sobrecubierta').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
var data = this.data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.remove();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'solapas_grandes_faja') {
|
|
const id = $('#solapas_grandes_faja').attr('service-id');
|
|
this.ServiciosManipulado.table.rows().every(function () {
|
|
var data = this.data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.remove();
|
|
this.ServiciosManipulado.table.draw();
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
else if (servicio == 'acabadoCubierta') {
|
|
for (let i = 0; i < this.serviciosAcabado.table.rows().count(); i++) {
|
|
let data = this.serviciosAcabado.table.row(i).data();
|
|
if (data.cubierta == 1) {
|
|
this.serviciosAcabado.table.row(i).remove();
|
|
}
|
|
};
|
|
this.serviciosAcabado.table.draw();
|
|
}
|
|
else if (servicio == 'acabadoSobrecubierta') {
|
|
for (let i = 0; i < this.serviciosAcabado.table.rows().count(); i++) {
|
|
let data = this.serviciosAcabado.table.row(i).data();
|
|
if (data.sobrecubierta == 1) {
|
|
this.serviciosAcabado.table.row(i).remove();
|
|
}
|
|
};
|
|
this.serviciosAcabado.table.draw();
|
|
}
|
|
else if (servicio == 'acabadoFaja') {
|
|
for (let i = 0; i < this.serviciosAcabado.table.rows().count(); i++) {
|
|
let data = this.serviciosAcabado.table.row(i).data();
|
|
if (data.faja == 1) {
|
|
this.serviciosAcabado.table.row(i).remove();
|
|
}
|
|
};
|
|
this.serviciosAcabado.table.draw();
|
|
}
|
|
else if (servicio == 'lomo_redondo') {
|
|
const id = $('#compLomoRedondo').attr('service-id');
|
|
for (let i = this.ServiciosManipulado.table.rows().count(); i >= 0; i--) {
|
|
var data = this.ServiciosManipulado.table.row(i).data();
|
|
if (data && data.tarifa_id == id) {
|
|
this.ServiciosManipulado.table.row(i).remove();
|
|
}
|
|
};
|
|
this.ServiciosManipulado.table.draw();
|
|
}
|
|
}
|
|
|
|
async updateServicios() {
|
|
|
|
this.serviciosAcabado.updateServicios();
|
|
this.ServiciosEncuadernacion.updateServicios();
|
|
this.ServiciosManipulado.updateServicios();
|
|
}
|
|
}
|
|
|
|
class ServiciosAcabado {
|
|
|
|
constructor(token, hash) {
|
|
|
|
this.csrf_token = token;
|
|
this.csrf_hash = hash;
|
|
|
|
this.table = null;
|
|
|
|
this.selectorServicios = new ClassSelect($('#add_servicio_acabado_list'), '/tarifas/acabados/gettarifas', window.language.Presupuestos.servicioAcabadoList, false, {});
|
|
this.addServicio = $('#insertar_serv_acabado');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectorServicios.init();
|
|
|
|
this.table = new DataTable('#tableOfServiciosAcabado', {
|
|
scrollX: true,
|
|
searching: false,
|
|
paging: false,
|
|
info: false,
|
|
ordering: false,
|
|
responsive: true,
|
|
select: false,
|
|
language: {
|
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
},
|
|
columns: [
|
|
{ data: 'tarifa_id' },
|
|
{
|
|
data: 'nombre', render: function (data, type, row) {
|
|
if (row.cubierta == 1) {
|
|
return row.nombre + ' (' + window.language.Presupuestos.cubierta + ')';
|
|
}
|
|
else if (row.sobrecubierta == 1) {
|
|
return row.nombre + ' (' + window.language.Presupuestos.sobrecubierta + ')';
|
|
}
|
|
else if (row.faja == 1) {
|
|
return row.nombre + ' (' + window.language.Presupuestos.faja + ')';
|
|
}
|
|
else {
|
|
return row.nombre;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
data: 'proveedor', render: function (data, type, row) {
|
|
return `
|
|
<select id="proveedor_acabado_${row.tarifa_id}" class="form-control select2bs proveedor_acabado proveedor-servicios" style="width: 100%;">
|
|
<option selected value="${row.proveedor_id}">${row.proveedor}</option>
|
|
</select>
|
|
`;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio_unidad', render: function (data, type, row) {
|
|
let precio_unidad_coste = (row.precio_unidad / (1 + row.margen / 100)).toFixed(2);
|
|
precio_unidad_coste = parseFloat(precio_unidad_coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
const precio_unidad = parseFloat(row.precio_unidad).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return precio_unidad_coste + '/' + precio_unidad;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio_total', render: function (data, type, row) {
|
|
let total = 0;
|
|
if (data !== undefined)
|
|
total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return `
|
|
<input class="update-totales-servicios form-control" id="precio_acabado_${row.tarifa_id}" value="${total}"></input>`;
|
|
}
|
|
},
|
|
{ data: 'margen' },
|
|
{ data: 'cubierta', visible: false },
|
|
{ data: 'sobrecubierta', visible: false },
|
|
{ data: 'faja', visible: false },
|
|
{
|
|
data: function (row) {
|
|
return `
|
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-servacabados mx-2" data-id="${row.id}"></i></a>
|
|
`;
|
|
}
|
|
}
|
|
],
|
|
|
|
drawCallback: function (settings) {
|
|
|
|
$('.proveedor_acabado').select2({
|
|
allowClear: false,
|
|
minimumResultsForSearch: -1,
|
|
ajax: {
|
|
url: '/serviciosacabados/menuitems',
|
|
type: 'post',
|
|
dataType: 'json',
|
|
|
|
data: function (params) {
|
|
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
var tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
else {
|
|
var tirada = 0
|
|
}
|
|
|
|
var row = self.table.row($(this).closest('tr')).data();
|
|
var return_data = {
|
|
tarifa_id: row.tarifa_id,
|
|
tirada: tirada,
|
|
};
|
|
return_data = Object.assign(return_data, window.token_ajax);
|
|
|
|
return return_data;
|
|
},
|
|
delay: 60,
|
|
processResults: function (response) {
|
|
yeniden(response[window.csrf_token]);
|
|
return {
|
|
results: response.menu
|
|
};
|
|
},
|
|
cache: true
|
|
}
|
|
});
|
|
|
|
$('.proveedor_acabado').on('select2:close', function () {
|
|
self.getPresupuestoAcabado(null, null, $(this));
|
|
})
|
|
|
|
self.check_serv_acabado_error();
|
|
|
|
$(document).trigger('update-presupuesto', {
|
|
update_lineas: false,
|
|
update_servicios: false,
|
|
update_envios: false,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
$(document).on('click', '.btn-delete-servacabados', function () {
|
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
|
self.table.row(rowId).remove().draw();
|
|
});
|
|
|
|
|
|
|
|
this.addServicio.on('click', this.addServicioAcabado.bind(this));
|
|
}
|
|
|
|
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);
|
|
const fajas = this.table.rows().data().toArray().map(row => row.fajas);
|
|
// 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], faja: fajas[i] });
|
|
}
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
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, faja) {
|
|
|
|
let tarifa_id = 0;
|
|
let uso = 'cubierta';
|
|
if (cubierta == 1) {
|
|
tarifa_id = $('#acabado_cubierta_id').val();
|
|
}
|
|
else if (sobrecubierta == 1) {
|
|
tarifa_id = $('#acabado_sobrecubierta_id').val();
|
|
uso = 'sobrecubierta';
|
|
}
|
|
else if (faja == 1) {
|
|
tarifa_id = $('#acabado_faja_id').val();
|
|
uso = 'faja';
|
|
}
|
|
this.getPresupuestoAcabado(tarifa_id, uso, null);
|
|
}
|
|
|
|
getPresupuestoAcabado(tarifa_id = -1, uso = null, updateSelect = null, isTarifa = false) {
|
|
|
|
const self = this;
|
|
|
|
let tirada = 0
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
let datos = {
|
|
tirada: tirada,
|
|
isTarifa: isTarifa ? 1 : 0
|
|
};
|
|
|
|
if (updateSelect != null) {
|
|
datos.tarifa_acabado_id = self.table.row(updateSelect.closest('tr')).data().tarifa_id;
|
|
datos.proveedor_id = parseInt(updateSelect.val())
|
|
}
|
|
else {
|
|
datos.tarifa_acabado_id = tarifa_id;
|
|
}
|
|
|
|
if (datos.tarifa_acabado_id > 0) {
|
|
new Ajax('/serviciosacabados/getvalues', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
if (uso == 'cubierta') {
|
|
for (let i = self.table.rows().count() - 1; i >= 0; i--) {
|
|
let data = self.table.row(i).data();
|
|
if (data && (data.cubierta == 1)) {
|
|
self.table.row(i).remove().draw(false);
|
|
}
|
|
}
|
|
}
|
|
else if (uso == 'sobrecubierta') {
|
|
for (let i = self.table.rows().count() - 1; i >= 0; i--) {
|
|
let data = self.table.row(i).data();
|
|
if (data && (data.sobrecubierta == 1)) {
|
|
self.table.row(i).remove().draw(false);
|
|
}
|
|
}
|
|
}
|
|
else if (uso == 'faja') {
|
|
for (let i = self.table.rows().count() - 1; i >= 0; i--) {
|
|
let data = self.table.row(i).data();
|
|
if (data && (data.faja == 1)) {
|
|
self.table.row(i).remove().draw(false);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
self.table.draw();
|
|
|
|
for (let i = 0; i < response.values.length; i++) {
|
|
response.values[i].cubierta = 0;
|
|
response.values[i].sobrecubierta = 0;
|
|
response.values[i].faja = 0;
|
|
if (uso == 'cubierta') {
|
|
response.values[i].cubierta = 1;
|
|
}
|
|
else if (uso == 'sobrecubierta') {
|
|
response.values[i].sobrecubierta = 1;
|
|
}
|
|
else if (uso == 'faja') {
|
|
response.values[i].faja = 1;
|
|
}
|
|
}
|
|
|
|
if (updateSelect != null) {
|
|
self.table.row(updateSelect.closest('tr')).data(response.values[0]).draw();
|
|
}
|
|
else {
|
|
self.table.rows.add(response.values).draw(false);
|
|
}
|
|
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
}
|
|
}
|
|
|
|
addServicioAcabado() {
|
|
|
|
const tarifa_text = this.selectorServicios.getText();
|
|
|
|
if (tarifa_text.length > 0) {
|
|
|
|
var rows = this.table.rows().data().toArray();
|
|
var found = rows.some(row => {
|
|
const renderedText = row.nombre;
|
|
if (row.cubierta == 1) {
|
|
return renderedText === tarifa_text + ' (' + window.language.Presupuestos.cubierta + ')';
|
|
} else if (row.sobrecubierta == 1) {
|
|
return renderedText === tarifa_text + ' (' + window.language.Presupuestos.sobrecubierta + ')';
|
|
} else {
|
|
return renderedText === tarifa_text;
|
|
}
|
|
});
|
|
|
|
if (!found)
|
|
this.getPresupuestoAcabado(this.selectorServicios.getVal(), null, null, true);
|
|
else
|
|
popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-acabado-alert');
|
|
}
|
|
|
|
this.check_serv_acabado_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
|
|
}
|
|
|
|
|
|
cargarServiciosAcabado(datos) {
|
|
|
|
this.table.rows.add(datos).draw();
|
|
}
|
|
|
|
|
|
async guardarServiciosAcabado() {
|
|
|
|
let datos = [];
|
|
this.table.rows().every(function () {
|
|
datos.push(this.data());
|
|
});
|
|
const domain = window.location.origin;
|
|
const id = window.location.href.split('/').pop();
|
|
await fetch(domain + "/presupuestos/presupuestoacabados/edit/" + id, {
|
|
method: "POST",
|
|
body: JSON.stringify({ datos: datos }),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
check_serv_acabado_error() {
|
|
|
|
var htmlString = '';
|
|
var error = false;
|
|
|
|
const rows = this.table.rows().data().toArray();
|
|
for (let i = 0; i < rows.length; i++) {
|
|
if (rows[i]['precio_total'] == 0) {
|
|
error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (error) {
|
|
htmlString = `
|
|
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-ban ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.error_servicios_anadidos +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
$('#serv-acabado-error').html(htmlString)
|
|
}
|
|
}
|
|
|
|
class ServiciosPreimpresion {
|
|
|
|
constructor(token, hash) {
|
|
|
|
this.csrf_token = token;
|
|
this.csrf_hash = hash;
|
|
|
|
this.table = null;
|
|
|
|
this.selectorServicios = new ClassSelect($('#add_servicio_preimpresion_list'),
|
|
'/tarifapreimpresion/gettarifas', window.language.Presupuestos.servicioPreimpresionList, false, {});
|
|
this.addServicio = $('#insertar_serv_preimpresion');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectorServicios.init();
|
|
|
|
this.table = new DataTable('#tableOfServiciosPreimpresion', {
|
|
scrollX: true,
|
|
searching: false,
|
|
paging: false,
|
|
info: false,
|
|
ordering: false,
|
|
responsive: true,
|
|
select: false,
|
|
language: {
|
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
},
|
|
columns: [
|
|
{ data: 'tarifa_id' },
|
|
{ data: 'nombre' },
|
|
|
|
{
|
|
data: 'coste', render: function (data, type, row) {
|
|
let coste = (row.precio / (1 + row.margen / 100)).toFixed(2);
|
|
coste = parseFloat(coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return coste;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio', render: function (data, type, row) {
|
|
|
|
let total = 0;
|
|
if (data !== undefined)
|
|
total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return `
|
|
<input class="update-totales-servicios totales-preimpresion form-control" id="precio_preimpresion_${row.tarifa_id}" value="${total}"></input>`;
|
|
|
|
}
|
|
},
|
|
{ data: 'margen' },
|
|
{
|
|
data: function (row) {
|
|
return `
|
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-servpreimpresion mx-2" data-id="${row.id}"></i></a>
|
|
`;
|
|
}
|
|
}
|
|
],
|
|
drawCallback: function (settings) {
|
|
|
|
self.check_serv_preimpresion_error();
|
|
|
|
$(document).trigger('update-presupuesto', {
|
|
update_lineas: false,
|
|
update_servicios: false,
|
|
update_envios: false,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
});
|
|
}
|
|
|
|
|
|
});
|
|
|
|
$('#tableOfServiciosPreimpresion tbody').on('change', '.totales-preimpresion', function () {
|
|
|
|
let input = $(this);
|
|
let tarifa_id = input.attr('id').replace('precio_preimpresion_', '');
|
|
let newValue = parseFloat(input.val().replace(/\./g, '').replace(',', '.')) || 0;
|
|
|
|
let table = $('#tableOfServiciosPreimpresion').DataTable();
|
|
let row = table.rows().data().toArray().find(r => r.tarifa_id == tarifa_id);
|
|
|
|
if (row) {
|
|
row.precio = newValue;
|
|
table.row($(this).closest('tr')).data(row).draw(false);
|
|
self.check_serv_preimpresion_error();
|
|
}
|
|
});
|
|
|
|
|
|
$(document).on('click', '.btn-delete-servpreimpresion', function () {
|
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
|
self.table.row(rowId).remove().draw();
|
|
});
|
|
|
|
|
|
|
|
this.addServicio.on('click', this.addServicioPreimpresion.bind(this));
|
|
}
|
|
|
|
getPresupuestoPreimpresion(tarifa_id = -1) {
|
|
|
|
const self = this;
|
|
|
|
let datos = {
|
|
tarifa_preimpresion_id: tarifa_id
|
|
};
|
|
|
|
if (datos.tarifa_preimpresion_id > 0) {
|
|
new Ajax('/serviciospreimpresiones/getvalues', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
|
|
self.table.rows.add([response.values[0]]).draw();
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
}
|
|
}
|
|
|
|
addServicioPreimpresion() {
|
|
|
|
const tarifa_text = this.selectorServicios.getText();
|
|
const tarifa_id = this.selectorServicios.getVal();
|
|
|
|
if (tarifa_text.length > 0) {
|
|
|
|
var rows = this.table.rows().data().toArray();
|
|
var found = rows.some(row => row.tarifa_id === tarifa_id);
|
|
|
|
if (!found)
|
|
this.getPresupuestoPreimpresion(this.selectorServicios.getVal());
|
|
else
|
|
popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-preimpresion-alert');
|
|
}
|
|
|
|
this.check_serv_preimpresion_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
}
|
|
|
|
cargarServiciosPreimpresion(datos) {
|
|
|
|
this.table.rows.add(datos).draw();
|
|
}
|
|
|
|
|
|
check_serv_preimpresion_error() {
|
|
|
|
var htmlString = '';
|
|
var error = false;
|
|
|
|
const rows = this.table.rows().data().toArray();
|
|
for (let i = 0; i < rows.length; i++) {
|
|
if (rows[i]['precio'] == 0) {
|
|
error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (error) {
|
|
htmlString = `
|
|
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-ban ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.error_servicios_anadidos +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
$('#serv-preimpresion-error').html(htmlString)
|
|
}
|
|
|
|
async guardarServiciosPreimpresion() {
|
|
|
|
let datos = [];
|
|
this.table.rows().every(function () {
|
|
datos.push(this.data());
|
|
});
|
|
const domain = window.location.origin;
|
|
const id = window.location.href.split('/').pop();
|
|
await fetch(domain + "/presupuestos/presupuestopreimpresiones/edit/" + id, {
|
|
method: "POST",
|
|
body: JSON.stringify({ datos: datos }),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
class ServiciosEncuadernacion {
|
|
|
|
constructor(token, hash) {
|
|
|
|
this.csrf_token = token;
|
|
this.csrf_hash = hash;
|
|
|
|
this.table = null;
|
|
|
|
this.selectorServicios = new ClassSelect($('#add_servicio_enc_list'),
|
|
'/tarifasencuadernacion/gettarifas', window.language.Presupuestos.servicioEncuadernacionList, false, {});
|
|
this.addServicio = $('#insertar_serv_enc');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectorServicios.init();
|
|
|
|
this.table = new DataTable('#tableOfServiciosEncuadernacion', {
|
|
scrollX: true,
|
|
searching: false,
|
|
paging: false,
|
|
info: false,
|
|
ordering: false,
|
|
responsive: true,
|
|
select: false,
|
|
language: {
|
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
},
|
|
columns: [
|
|
{ data: 'tarifa_id' },
|
|
{ data: 'nombre' },
|
|
{
|
|
data: 'proveedor', render: function (data, type, row) {
|
|
return `
|
|
<select id="proveedor_encuadernacion_${row.tarifa_id}" class="form-control select2bs proveedor_encuadernacion proveedor-servicios" style="width: 100%;">
|
|
<option selected value="${row.proveedor_id}">${row.proveedor}</option>
|
|
</select>
|
|
`;
|
|
}
|
|
},
|
|
{
|
|
data: 'paginas_por_cuadernillo', render: function (data, type, row) {
|
|
if (data == null) return '';
|
|
else {
|
|
const value_list = [32, 28, 24, 20, 16];
|
|
var string =
|
|
'<select id="cuadernillos_' + row.tarifa_id + '" class="cuadernillo_enc paginas-cuadernillo select2bs2" style="width: 50%;">';
|
|
for (let i = 0; i < value_list.length; i++) {
|
|
string +=
|
|
'<option value="' + value_list[i] + '" ' + (value_list[i] == data ? 'selected' : '') + '>' +
|
|
value_list[i] +
|
|
'</option>';
|
|
}
|
|
string += '</select>';
|
|
return string;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
data: 'tiempo', render: function (data, type, row) {
|
|
return self.convertirTiempo(data);
|
|
}
|
|
},
|
|
{
|
|
data: 'precio_unidad', render: function (data, type, row) {
|
|
const precio_total_sin_fijo = (row.precio_unidad*parseInt($('#tirada').val()))-parseFloat(row.importe_fijo);
|
|
let precio_unidad_coste = ((precio_total_sin_fijo / parseInt($('#tirada').val())) / (1 + row.margen / 100)).toFixed(2);
|
|
precio_unidad_coste = parseFloat(precio_unidad_coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
const precio_unidad = parseFloat(row.precio_unidad).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return precio_unidad_coste + '/' + precio_unidad;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio_total', render: function (data, type, row) {
|
|
let total = 0;
|
|
if (data !== undefined)
|
|
total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return `
|
|
<input class="update-totales-servicios form-control" id="precio_enc_${row.tarifa_id}" value="${total}"></input>`;
|
|
}
|
|
},
|
|
{ data: 'margen' },
|
|
{
|
|
data: function (row) {
|
|
return `
|
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-servencuadernacion mx-2" data-id="${row.id}"></i></a>
|
|
`;
|
|
}
|
|
},
|
|
{data: 'importe_fijo', visible: false},
|
|
],
|
|
|
|
drawCallback: function (settings) {
|
|
|
|
$('.cuadernillo_enc').select2({
|
|
allowClear: false,
|
|
minimumResultsForSearch: -1,
|
|
});
|
|
|
|
$('.proveedor_encuadernacion').select2({
|
|
|
|
allowClear: false,
|
|
minimumResultsForSearch: -1,
|
|
ajax: {
|
|
url: '/serviciosencuadernaciones/menuitems',
|
|
type: 'post',
|
|
dataType: 'json',
|
|
|
|
data: function (params) {
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val());
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
|
|
let paginas = 0;
|
|
if (parseInt($('#paginas').val()) > 0) {
|
|
paginas = parseInt($('#paginas').val())
|
|
}
|
|
|
|
const row = self.table.row($(this).closest('tr')).data();
|
|
const tamanio = self.getDimensionLibro();
|
|
|
|
let return_data = {
|
|
tarifa_id: row.tarifa_id,
|
|
tirada: tirada,
|
|
paginas: paginas,
|
|
ancho: tamanio.ancho,
|
|
alto: tamanio.alto,
|
|
};
|
|
|
|
if (row.paginas_por_cuadernillo) {
|
|
return_data.paginas_por_cuadernillo = row.paginas_por_cuadernillo;
|
|
}
|
|
|
|
return return_data;
|
|
},
|
|
delay: 60,
|
|
processResults: function (response) {
|
|
yeniden(response[window.csrf_token]);
|
|
return {
|
|
results: response.menu
|
|
};
|
|
},
|
|
cache: true
|
|
}
|
|
});
|
|
|
|
$('.proveedor_encuadernacion').on('select2:close', function () {
|
|
|
|
const row = $(this).closest('tr');
|
|
const table = $(this).closest('table').DataTable();
|
|
|
|
if (!row.length || !table || $(this).select2('data') <= 0) return;
|
|
|
|
const data = table.row(row).data();
|
|
|
|
data.proveedor_id = parseInt($(this).select2('data')[0].id);
|
|
data.proveedor_nombre = $(this).select2('data')[0].text;
|
|
//table.row(row).data(data).draw();
|
|
|
|
self.getPresupuestoEncuadernacion(null, $(this));
|
|
})
|
|
|
|
$('.cuadernillo_enc').on('select2:close', function () {
|
|
|
|
const row = $(this).closest('tr');
|
|
const table = $(this).closest('table').DataTable();
|
|
|
|
if (!row.length || !table || $(this).select2('data') <= 0) return;
|
|
|
|
const data = table.row(row).data();
|
|
data.paginas_por_cuadernillo = parseInt($(this).select2('data')[0].text);
|
|
self.getPresupuestoEncuadernacion(null, $(this));
|
|
})
|
|
|
|
self.check_serv_enc_error();
|
|
|
|
$(document).trigger('update-presupuesto', {
|
|
update_lineas: false,
|
|
update_servicios: false,
|
|
update_envios: false,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
});
|
|
}
|
|
});
|
|
|
|
$(document).on('click', '.btn-delete-servencuadernacion', function () {
|
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
|
self.table.row(rowId).remove().draw();
|
|
});
|
|
|
|
this.addServicio.on('click', this.addServicioEncuadernacion.bind(this));
|
|
}
|
|
|
|
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: null, paginas_por_cuadernillo: cuadernillos[i] });
|
|
}
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
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();
|
|
}
|
|
|
|
async getServiciosDefecto() {
|
|
|
|
const self = this;
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
let paginas = 0;
|
|
if (parseInt($('#paginas').val()) > 0) {
|
|
paginas = parseInt($('#paginas').val())
|
|
}
|
|
|
|
const tamanio = self.getDimensionLibro();
|
|
let datos = {
|
|
tirada: tirada,
|
|
paginas: paginas,
|
|
ancho: tamanio.ancho,
|
|
alto: tamanio.alto,
|
|
solapas: $('#solapas').is(':checked') ? 1 : 0,
|
|
tipo_impresion_id: $('#tipo_impresion_id').val(),
|
|
tipo: 'default'
|
|
};
|
|
|
|
new Ajax('/serviciosencuadernaciones/datatable', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
self.table.clear().draw();
|
|
self.table.rows.add(response.values).draw();
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
|
|
this.check_serv_enc_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
}
|
|
|
|
|
|
getPresupuestoEncuadernacion(tarifa_id = -1, updateSelect = null) {
|
|
|
|
const self = this;
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
let paginas = 0;
|
|
if (parseInt($('#paginas').val()) > 0) {
|
|
paginas = parseInt($('#paginas').val())
|
|
}
|
|
|
|
const tamanio = self.getDimensionLibro();
|
|
let datos = {
|
|
tirada: tirada,
|
|
paginas: paginas,
|
|
ancho: tamanio.ancho,
|
|
alto: tamanio.alto,
|
|
};
|
|
|
|
if (updateSelect != null) {
|
|
const row = updateSelect.closest('tr');
|
|
const data = self.table.row(row).data();
|
|
datos.tarifa_enc_id = data.tarifa_id;
|
|
datos.proveedor_id = data.proveedor_id;
|
|
if (data.paginas_por_cuadernillo) {
|
|
datos.paginas_por_cuadernillo = data.paginas_por_cuadernillo;
|
|
}
|
|
}
|
|
else {
|
|
datos.tarifa_enc_id = tarifa_id;
|
|
}
|
|
|
|
if (datos.tarifa_enc_id > 0) {
|
|
new Ajax('/serviciosencuadernaciones/getvalues', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
if (updateSelect != null) {
|
|
|
|
self.table.row(updateSelect.closest('tr')).data(response.values[0]).draw();
|
|
}
|
|
else {
|
|
self.table.rows.add([response.values[0]]).draw();
|
|
}
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
}
|
|
}
|
|
|
|
addServicioEncuadernacion() {
|
|
|
|
const tarifa_text = this.selectorServicios.getText();
|
|
const tarifa_id = this.selectorServicios.getVal();
|
|
|
|
if (tarifa_text.length > 0) {
|
|
|
|
var rows = this.table.rows().data().toArray();
|
|
var found = rows.some(row => row.tarifa_id === tarifa_id);
|
|
|
|
if (!found)
|
|
this.getPresupuestoEncuadernacion(tarifa_id);
|
|
else
|
|
popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-enc-alert');
|
|
}
|
|
|
|
this.check_serv_enc_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
|
|
}
|
|
|
|
async guardarServiciosEncuadernacion() {
|
|
|
|
let datos = [];
|
|
this.table.rows().every(function () {
|
|
datos.push(this.data());
|
|
});
|
|
const domain = window.location.origin;
|
|
const id = window.location.href.split('/').pop();
|
|
await fetch(domain + "/presupuestos/presupuestoencuadernaciones/edit/" + id, {
|
|
method: "POST",
|
|
body: JSON.stringify({ datos: datos }),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
check_serv_enc_error() {
|
|
|
|
var htmlString = '';
|
|
var error = false;
|
|
|
|
const rows = this.table.rows().data().toArray();
|
|
for (let i = 0; i < rows.length; i++) {
|
|
if (rows[i]['precio_total'] == 0) {
|
|
error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (error) {
|
|
htmlString = `
|
|
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-ban ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.error_servicios_anadidos +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
$('#serv-enc-error').html(htmlString)
|
|
}
|
|
|
|
|
|
convertirTiempo(horas) {
|
|
|
|
if (horas != null) {
|
|
|
|
if (parseFloat(horas) > 0) {
|
|
|
|
const seconds = parseFloat(horas) * 3600;
|
|
// se convierte a formato hh:mm:ss
|
|
const h = Math.floor(seconds / 3600);
|
|
const minutos = Math.floor((seconds % 3600) / 60);
|
|
const segundos = Math.round(seconds % 60, 0);
|
|
return h + ':' + minutos + ':' + segundos;
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
getDimensionLibro() {
|
|
|
|
var ancho = 0;
|
|
var alto = 0;
|
|
|
|
|
|
if ($('#papelFormatoPersonalizado').is(':checked')) {
|
|
ancho = parseFloat($('#papelFormatoAncho').val());
|
|
alto = parseFloat($('#papelFormatoAlto').val());
|
|
}
|
|
else {
|
|
const selectedText = $('#papelFormatoId').find('option:selected').text();
|
|
if (selectedText.length > 0) {
|
|
ancho = parseFloat(selectedText.trim().split(" x ")[0]);
|
|
alto = parseFloat(selectedText.trim().split(" x ")[1]);
|
|
}
|
|
}
|
|
|
|
return {
|
|
ancho: ancho,
|
|
alto: alto
|
|
}
|
|
}
|
|
}
|
|
|
|
class ServiciosManipulado {
|
|
|
|
constructor(token, hash) {
|
|
|
|
this.csrf_token = token;
|
|
this.csrf_hash = hash;
|
|
|
|
this.table = null;
|
|
|
|
this.selectorServicios = new ClassSelect($('#add_servicio_manipulado_list'),
|
|
'/tarifasmanipulado/gettarifas', window.language.Presupuestos.servicioManipuladoList, false, {});
|
|
this.addServicio = $('#insertar_serv_manipulado');
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectorServicios.init();
|
|
|
|
this.table = new DataTable('#tableOfServiciosManipulado', {
|
|
scrollX: true,
|
|
searching: false,
|
|
paging: false,
|
|
info: false,
|
|
ordering: false,
|
|
responsive: true,
|
|
select: false,
|
|
language: {
|
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
},
|
|
columns: [
|
|
{ data: 'tarifa_id' },
|
|
{ data: 'nombre' },
|
|
{
|
|
data: 'precio_unidad', render: function (data, type, row) {
|
|
let precio_unidad_coste = (row.precio_unidad / (1 + row.margen / 100)).toFixed(2);
|
|
precio_unidad_coste = parseFloat(precio_unidad_coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
const precio_unidad = parseFloat(row.precio_unidad).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return precio_unidad_coste + '/' + precio_unidad;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio_total', render: function (data, type, row) {
|
|
let total = 0;
|
|
if (data !== undefined)
|
|
total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
else
|
|
data = 0;
|
|
return `
|
|
<input class="update-totales-servicios totales-manipulado form-control" id="precio_manipulado_${row.tarifa_id}" value="${total}"></input>`;
|
|
}
|
|
},
|
|
{ data: 'margen' },
|
|
{
|
|
data: function (row) {
|
|
return `
|
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-servmanipulado mx-2" data-id="${row.id}"></i></a>
|
|
`;
|
|
}
|
|
}
|
|
],
|
|
drawCallback: function (settings) {
|
|
|
|
self.check_serv_manipulado_error();
|
|
|
|
$(document).trigger('update-presupuesto', {
|
|
update_lineas: false,
|
|
update_servicios: false,
|
|
update_envios: false,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
});
|
|
}
|
|
});
|
|
|
|
$('#tableOfServiciosManipulado tbody').on('change', '.totales-manipulado', function () {
|
|
let input = $(this);
|
|
let tarifa_id = input.attr('id').replace('precio_manipulado_', '');
|
|
let newValue = parseFloat(input.val().replace(/\./g, '').replace(',', '.')) || 0;
|
|
|
|
let table = $('#tableOfServiciosManipulado').DataTable();
|
|
let row = table.rows().data().toArray().find(r => r.tarifa_id == tarifa_id);
|
|
|
|
if (row) {
|
|
row.precio_total = newValue;
|
|
table.row($(this).closest('tr')).data(row).draw(false);
|
|
self.check_serv_manipulado_error();
|
|
}
|
|
});
|
|
|
|
this.addServicio.on('click', this.addServicioManipulado.bind(this));
|
|
|
|
$(document).on('click', '.btn-delete-servmanipulado', function () {
|
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
|
self.table.row(rowId).remove().draw();
|
|
});
|
|
}
|
|
|
|
|
|
addServicioManipulado() {
|
|
|
|
const tarifa_text = this.selectorServicios.getText();
|
|
const tarifa_id = this.selectorServicios.getVal();
|
|
|
|
if (tarifa_text.length > 0) {
|
|
|
|
var rows = this.table.rows().data().toArray();
|
|
var found = rows.some(row => row.tarifa_id === tarifa_id);
|
|
|
|
if (!found)
|
|
this.getPresupuestoManipulado(tarifa_id);
|
|
else
|
|
popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-manipulado-alert');
|
|
}
|
|
}
|
|
|
|
async getServiciosDefecto() {
|
|
|
|
const self = this;
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
|
|
let datos = {
|
|
tirada: tirada,
|
|
solapas: $('#solapas').is(':checked') ? 1 : 0,
|
|
tipo_impresion_id: $('#tipo_impresion_id').val(),
|
|
tipo: 'default'
|
|
};
|
|
|
|
new Ajax('/serviciosmanipulados/datatable', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
self.table.clear().draw();
|
|
self.table.rows.add(response.values).draw();
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
|
|
this.check_serv_manipulado_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
}
|
|
|
|
|
|
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())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
|
|
if (tarifa_ids.length > 0) {
|
|
const data = {
|
|
datos: tarifa_ids,
|
|
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;
|
|
|
|
let tirada = 0;
|
|
if (parseInt($('#tirada').val()) > 0) {
|
|
tirada = parseInt($('#tirada').val())
|
|
/*var merma = parseInt($('#merma').val())
|
|
if (merma && merma > 0) {
|
|
tirada = tirada + merma;
|
|
}*/
|
|
}
|
|
|
|
let datos = {
|
|
tirada: tirada,
|
|
tarifa_manipulado_id: tarifa_id
|
|
};
|
|
|
|
if (datos.tarifa_manipulado_id > 0) {
|
|
new Ajax('/serviciosmanipulados/getvalues', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
self.table.rows.add([response.values[0]]).draw();
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
}
|
|
}
|
|
|
|
cargarServiciosManipulado(datos) {
|
|
|
|
this.table.rows.add(datos).draw();
|
|
}
|
|
|
|
async guardarServiciosManipulado() {
|
|
|
|
let datos = [];
|
|
this.table.rows().every(function () {
|
|
datos.push(this.data());
|
|
});
|
|
const domain = window.location.origin;
|
|
const id = window.location.href.split('/').pop();
|
|
await fetch(domain + "/presupuestos/presupuestomanipulados/edit/" + id, {
|
|
method: "POST",
|
|
body: JSON.stringify({ datos: datos }),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
}
|
|
|
|
check_serv_manipulado_error() {
|
|
|
|
var htmlString = '';
|
|
var error = false;
|
|
|
|
// get all rows of the table
|
|
const rows = this.table.rows().data().toArray();
|
|
for (let i = 0; i < rows.length; i++) {
|
|
if (rows[i]['precio_total'] == 0) {
|
|
error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (error) {
|
|
htmlString = `
|
|
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-ban ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.error_servicios_anadidos +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
$('#serv-manipulado-error').html(htmlString)
|
|
}
|
|
}
|
|
|
|
class ServiciosExtra {
|
|
|
|
constructor(token, hash) {
|
|
|
|
this.csrf_token = token;
|
|
this.csrf_hash = hash;
|
|
|
|
this.table = null;
|
|
|
|
this.selectorServicios = new ClassSelect($('#add_servicio_extra_list'),
|
|
'/tarifaextra/gettarifas', window.language.Presupuestos.servicioExtraList, false, {});
|
|
this.addServicio = $('#insertar_serv_extra');
|
|
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.selectorServicios.init();
|
|
|
|
this.table = new DataTable('#tableOfServiciosExtra', {
|
|
scrollX: true,
|
|
searching: false,
|
|
paging: false,
|
|
info: false,
|
|
ordering: false,
|
|
responsive: true,
|
|
select: false,
|
|
language: {
|
|
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
|
},
|
|
columns: [
|
|
{ data: 'tarifa_id' },
|
|
{ data: 'nombre' },
|
|
|
|
{
|
|
data: 'coste', render: function (data, type, row) {
|
|
let coste = (row.precio / (1 + row.margen / 100)).toFixed(2);
|
|
coste = parseFloat(coste).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return coste;
|
|
}
|
|
},
|
|
{
|
|
data: 'precio', render: function (data, type, row) {
|
|
|
|
let total = 0;
|
|
if (data !== undefined)
|
|
total = parseFloat(data).toLocaleString('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
return `
|
|
<input class="update-totales-servicios totales-extra form-control" id="precio_extra_${row.tarifa_id}" value="${total}"></input>`;
|
|
|
|
}
|
|
},
|
|
{ data: 'margen' },
|
|
{
|
|
data: function (row) {
|
|
return `
|
|
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete-servextra mx-2" data-id="${row.id}"></i></a>
|
|
`;
|
|
}
|
|
}
|
|
],
|
|
drawCallback: function (settings) {
|
|
|
|
self.check_serv_extra_error();
|
|
|
|
$(document).trigger('update-presupuesto', {
|
|
update_lineas: false,
|
|
update_servicios: false,
|
|
update_envios: false,
|
|
update_resumen: true,
|
|
update_tiradas_alternativas: true
|
|
});
|
|
}
|
|
});
|
|
|
|
$('#tableOfServiciosExtra tbody').on('change', '.totales-extra', function () {
|
|
|
|
let input = $(this);
|
|
let tarifa_id = input.attr('id').replace('precio_extra_', '');
|
|
let newValue = parseFloat(input.val().replace(/\./g, '').replace(',', '.')) || 0;
|
|
|
|
let table = $('#tableOfServiciosExtra').DataTable();
|
|
let row = table.rows().data().toArray().find(r => r.tarifa_id == tarifa_id);
|
|
|
|
if (row) {
|
|
row.precio = newValue;
|
|
table.row($(this).closest('tr')).data(row).draw(false);
|
|
self.check_serv_extra_error();
|
|
}
|
|
});
|
|
|
|
$(document).on('click', '.btn-delete-servextra', function () {
|
|
const rowId = $(this).closest('td').parent()[0].sectionRowIndex;
|
|
self.table.row(rowId).remove().draw();
|
|
});
|
|
|
|
this.addServicio.on('click', this.addServicioExtra.bind(this));
|
|
}
|
|
|
|
addServicioExtra() {
|
|
|
|
const tarifa_text = this.selectorServicios.getText();
|
|
const tarifa_id = this.selectorServicios.getVal();
|
|
|
|
if (tarifa_text.length > 0) {
|
|
|
|
var rows = this.table.rows().data().toArray();
|
|
var found = rows.some(row => row.tarifa_id === tarifa_id);
|
|
|
|
if (!found)
|
|
this.getPresupuestoExtra(this.selectorServicios.getVal());
|
|
else
|
|
popErrorAlert(window.language.Presupuestos.errores.error_servicios_duplicados, 'serv-extra-alert');
|
|
}
|
|
|
|
this.check_serv_extra_error();
|
|
|
|
showBreadCrumbSaveButton(true);
|
|
|
|
}
|
|
|
|
cargarServiciosExtra(datos) {
|
|
|
|
this.table.rows.add(datos).draw();
|
|
}
|
|
|
|
async guardarServiciosExtra() {
|
|
|
|
let datos = [];
|
|
this.table.rows().every(function () {
|
|
datos.push(this.data());
|
|
});
|
|
const domain = window.location.origin;
|
|
const id = window.location.href.split('/').pop();
|
|
await fetch(domain + "/presupuestos/presupuestoserviciosextra/edit/" + id, {
|
|
method: "POST",
|
|
body: JSON.stringify({ datos: datos }),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
}
|
|
|
|
getPresupuestoExtra(tarifa_id = -1) {
|
|
|
|
const self = this;
|
|
|
|
let datos = {
|
|
tarifa_extra_id: tarifa_id
|
|
};
|
|
|
|
if (datos.tarifa_extra_id > 0) {
|
|
new Ajax('/serviciosextra/getvalues', datos, {},
|
|
function (response) {
|
|
if (response.values) {
|
|
self.table.rows.add([response.values[0]]).draw();
|
|
}
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
}
|
|
).post();
|
|
}
|
|
}
|
|
|
|
check_serv_extra_error() {
|
|
|
|
var htmlString = '';
|
|
var error = false;
|
|
|
|
const rows = this.table.rows().data().toArray();
|
|
for (let i = 0; i < rows.length; i++) {
|
|
if (rows[i]['precio'] == 0) {
|
|
error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (error) {
|
|
htmlString = `
|
|
<div class="alert alert-danger d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon
|
|
alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-ban ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.error_servicios_anadidos +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
|
|
$('#serv-extra-error').html(htmlString)
|
|
}
|
|
}
|
|
|
|
export default Servicios; |