mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
solucionado guardado de servicios acabado cubierta y sobrecubierta
This commit is contained in:
@ -22,6 +22,7 @@ use App\Services\PresupuestoClienteService;
|
||||
use App\Services\PresupuestoService;
|
||||
use Exception;
|
||||
|
||||
use stdClass;
|
||||
use function PHPUnit\Framework\containsOnly;
|
||||
|
||||
|
||||
@ -718,6 +719,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$POD = model('App\Models\Configuracion\ConfiguracionSistemaModel')->getPOD();
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
$id = intval($id);
|
||||
|
||||
@ -932,23 +935,24 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
if ($id != 0) {
|
||||
$borrar_antes = true;
|
||||
}
|
||||
|
||||
$sobrecubierta_acabado_id = [];
|
||||
if ($datos_presupuesto['sobrecubierta']) {
|
||||
$acabado_id = $this->obtenerTarifasAcabado(['plastificado' => $datos_presupuesto['sobrecubierta']['acabados']]);
|
||||
if (count($acabado_id) > 0) {
|
||||
$datos_presupuesto['sobrecubierta']['acabados'] = $acabado_id[0];
|
||||
$sobrecubierta_acabado_id = $this->obtenerTarifasAcabado(['plastificado' => $datos_presupuesto['sobrecubierta']['acabados']]);
|
||||
if (count($sobrecubierta_acabado_id) > 0) {
|
||||
// la sobrecubierta sólo tiene plastificado
|
||||
$datos_presupuesto['sobrecubierta']['acabados'] = $sobrecubierta_acabado_id['plastificado'];
|
||||
}
|
||||
}
|
||||
$acabado_id = $this->obtenerTarifasAcabado($datos_presupuesto['cubierta']['acabadosCubierta']);
|
||||
if (count($acabado_id) > 0) {
|
||||
if (array_key_exists('plastificado', $acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['plastificado'] = $acabado_id['plastificado'];
|
||||
$cubierta_acabado_id = $this->obtenerTarifasAcabado($datos_presupuesto['cubierta']['acabadosCubierta']);
|
||||
if (count($cubierta_acabado_id) > 0) {
|
||||
if (array_key_exists('plastificado', $cubierta_acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['plastificado'] = $cubierta_acabado_id['plastificado'];
|
||||
}
|
||||
if (array_key_exists('barniz', $acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['barniz'] = $acabado_id['barniz'];
|
||||
if (array_key_exists('barniz', $cubierta_acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['barniz'] = $cubierta_acabado_id['barniz'];
|
||||
}
|
||||
if (array_key_exists('estampado', $acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['estampado'] = $acabado_id['estampado'];
|
||||
if (array_key_exists('estampado', $cubierta_acabado_id)) {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['estampado'] = $cubierta_acabado_id['estampado'];
|
||||
}
|
||||
} else {
|
||||
$datos_presupuesto['cubierta']['acabadosCubierta']['id'] = 0;
|
||||
@ -991,6 +995,27 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$this->guardarLineaPresupuesto($id, $resultado_presupuesto['info']['guardas']);
|
||||
|
||||
// Servicios
|
||||
foreach ($sobrecubierta_acabado_id as $acabado) {
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$servicio = $model->getPrecioTarifa($acabado, intval($selected_tirada), -1, $POD);
|
||||
|
||||
if (count($servicio) > 0) {
|
||||
if ($servicio[0]->total > 0) {
|
||||
$this->guardarServicio($id, $servicio[0], 'acabado', false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($cubierta_acabado_id as $acabado) {
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$servicio = $model->getPrecioTarifa($acabado, intval($selected_tirada), -1, $POD);
|
||||
|
||||
if (count($servicio) > 0) {
|
||||
if ($servicio[0]->total > 0) {
|
||||
$this->guardarServicio($id, $servicio[0], 'acabado', true, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($resultado_presupuesto['info']['serviciosDefecto'] as $servicio) {
|
||||
$this->guardarServicio($id, $servicio, 'encuadernacion');
|
||||
}
|
||||
@ -1311,7 +1336,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
|
||||
|
||||
protected function guardarServicio($presupuestoId, $servicio, $tipo)
|
||||
protected function guardarServicio($presupuestoId, $servicio, $tipo, $cubierta = false, $sobrecubierta = false)
|
||||
{
|
||||
|
||||
if ($tipo == 'encuadernacion') {
|
||||
@ -1349,9 +1374,12 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$data = [
|
||||
'presupuesto_id' => $presupuestoId,
|
||||
'tarifa_acabado_id' => $servicio->tarifa_id,
|
||||
'precio_total' => $servicio->total,
|
||||
'precio_unidad' => $servicio->precio_unidad,
|
||||
'precio_total' => round($servicio->total, 2),
|
||||
'precio_unidad' => round($servicio->precio_unidad, 2),
|
||||
'margen' => $servicio->margen,
|
||||
'proveedor_id' => $servicio->proveedor_id,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $sobrecubierta,
|
||||
];
|
||||
$model->insert($data);
|
||||
} else if ($tipo == 'manipulado') {
|
||||
@ -1790,7 +1818,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
foreach ($tarifaAcabadoSobrecubierta as $tarifa) {
|
||||
|
||||
// NONE
|
||||
if ($tarifaAcabadoSobrecubierta[0] == 0)
|
||||
if ($tarifa == 0)
|
||||
continue;
|
||||
$model = model('App\Models\Presupuestos\PresupuestoAcabadosModel');
|
||||
$acabadoSobrecubierta = $model->getPrecioTarifa($tarifa, $datosPedido->tirada, -1, $POD);
|
||||
@ -2590,10 +2618,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
if ($value != 'NONE') {
|
||||
$data = $model->where('code', $value)->first();
|
||||
$data = $data->id;
|
||||
array_push($tarifas, [$acabado => $data]);
|
||||
} else {
|
||||
array_push($tarifas, 0);
|
||||
$tarifas[$acabado] = $data->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,387 +0,0 @@
|
||||
function initDirecciones() {
|
||||
data = {
|
||||
id: $('#clienteId').val()
|
||||
},
|
||||
data = Object.assign(data, window.token_ajax);
|
||||
$('#errorDirecciones').hide();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.direcciones,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
$("#direcciones").empty();
|
||||
$.each(response.menu, function(index, value) {
|
||||
$("#direcciones").append('<option value="' + value.id + '">' + value.text + '</option>');
|
||||
});
|
||||
$("#direcciones").val('');
|
||||
},
|
||||
error: function() {
|
||||
$("#direcciones").empty();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function initTiradasDirecciones() {
|
||||
const _this = this
|
||||
let sel_index = 1;
|
||||
|
||||
$('#containerTiradasEnvios').empty();
|
||||
|
||||
for (i = 1; i <= 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
|
||||
let tirada_id = "ud_tiradaPrecio" + i;
|
||||
let total_id = "tot_tiradaPrecio" + i;
|
||||
let precio_u_id = "pu_tiradaPrecio" + i;
|
||||
let peso = $('#' + id).attr('peso');
|
||||
|
||||
let html = '';
|
||||
html += '<div class="col-sm-3">';
|
||||
html += '<div id=div-env_' + id + ' class="form-check custom-option custom-option-basic custom-option-tiradasDirecciones">';
|
||||
html += '<label class="form-check-label custom-option-content" for="tiradaEnvios' + i + '">';
|
||||
html += '<input name=env_"' + id + '" peso="' + peso + '" class="form-check-input" type="radio" value="" id="env_' + id + '"></input>';
|
||||
html += '<span class="custom-option-header">';
|
||||
html += '<span id="tiradaDireccionesValue' + i + '" class="h6 mb-0">' + $('#' + tirada_id).text().split(' ')[0] + '</span>';
|
||||
html += '<span class="text-muted">' + $('#' + total_id).text() + '</span>';
|
||||
html += '</span>';
|
||||
html += '<span class="custom-option-body">';
|
||||
html += '<small>' + $('#' + precio_u_id).text() + '</small>';
|
||||
html += '</span>';
|
||||
html += '</label>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
$('#containerTiradasEnvios').append(html);
|
||||
|
||||
if(parseInt($('#' + tirada_id).text().split(' ')[0]) == window.direcciones_sel_tirada){
|
||||
sel_index = i;
|
||||
}
|
||||
|
||||
$('#' + id).hide();
|
||||
}
|
||||
}
|
||||
$(('#env_tiradaPrecio' + sel_index)).trigger('click');
|
||||
|
||||
cargarDirecciones();
|
||||
|
||||
const tiradasDireccionesList = [].slice.call(document.querySelectorAll('.custom-option-tiradasDirecciones .form-check-input'))
|
||||
tiradasDireccionesList.map(function (customOptionEL) {
|
||||
// Update custom options check on page load
|
||||
_this.updateTiradasDireccionesCheck(customOptionEL)
|
||||
|
||||
// Update custom options check on click
|
||||
customOptionEL.addEventListener('click', e => {
|
||||
_this.updateTiradasDireccionesCheck(customOptionEL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function cargarDirecciones(){
|
||||
$('#loader').show();
|
||||
$('#divDirecciones').empty();
|
||||
|
||||
if(window.direcciones == null){
|
||||
$('#loader').hide();
|
||||
return;
|
||||
}
|
||||
for(let i=0; i<window.direcciones.length; i++){
|
||||
const tipo = window.direcciones[i].entregaPieCalle == 1?'palets':'cajas';
|
||||
let html = '';
|
||||
html += '<div id="envioId' + window.direcciones[i].direccion_id + '" t="' + tipo + '" p= ' +window.direcciones[i].precio + ' class="row mb-3">';
|
||||
html += '<div class="col-sm-5 form-check custom-option custom-option-basic checked">';
|
||||
html += '<label class="form-check-label custom-option-content" for="customRadioAddress1">';
|
||||
html += '<span class="custom-option-header mb-2">';
|
||||
html += '<h6 class="fw-semibold mb-0">' + window.direcciones[i].att + '</h6>';
|
||||
html += '<span class="badge bg-label-primary">' + window.direcciones[i].cantidad + ' unidades</span>';
|
||||
html += '</span>';
|
||||
html += '<span class="custom-option-body">';
|
||||
html += '<small>' + window.direcciones[i].direccion + '</small><br>';
|
||||
html += '<small>' + window.direcciones[i].cp + '</small><br>';
|
||||
html += '<small>' + window.direcciones[i].municipio +', ' + window.direcciones[i].pais + '</small><br>';
|
||||
html += '<small>' + window.direcciones[i].telefono + '</small><br>';
|
||||
html += '<small>' + window.direcciones[i].email + '</small><br>';
|
||||
if(tipo == 'palets'){
|
||||
html += '<small><i>Envío en palets</i></small><br>';
|
||||
}
|
||||
html += '<hr class="my-2">';
|
||||
html += '<span class="d-flex">';
|
||||
html += '<a class="eliminar-direccion" href="javascript:void(0)">Eliminar</a>';
|
||||
html += '</span>';
|
||||
html += '</span>';
|
||||
html += '</label>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
$('#divDirecciones').append(html);
|
||||
$('#errorDirecciones').hide();
|
||||
$('#loader').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function updateTiradasDireccionesCheck(el) {
|
||||
if (el.checked) {
|
||||
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
||||
if (el.type === 'radio') {
|
||||
const customRadioOptionList = [].slice.call(el.closest('.row').querySelectorAll('.custom-option-tiradasDirecciones'))
|
||||
customRadioOptionList.map(function (customRadioOptionEL) {
|
||||
customRadioOptionEL.closest('.custom-option-tiradasDirecciones').classList.remove('checked')
|
||||
let id_temp = customRadioOptionEL.id.split('-')[1];
|
||||
$('#' + id_temp).prop('checked', false);
|
||||
})
|
||||
}
|
||||
const element = el.closest('.custom-option-tiradasDirecciones');
|
||||
element.classList.add('checked');
|
||||
|
||||
let id = element.id.split('-')[1];
|
||||
$('#' + id).prop('checked', true);
|
||||
|
||||
} else {
|
||||
el.closest('.custom-option-tiradasDirecciones').classList.remove('checked')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function obtenerUnidadesEnvio(){
|
||||
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
let total = 0;
|
||||
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let unidades_direcciones = parseInt($(elements[index]).find('div label span span').text().split(' ')[0]);
|
||||
total += unidades_direcciones;
|
||||
};
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
$('#insertarDireccion').on('click', function() {
|
||||
|
||||
if( $('#direcciones').val() > 0 ) {
|
||||
|
||||
let unidades = $('#unidadesEnvio').val();
|
||||
if(unidades == '' || isNaN(unidades) || parseInt(unidades) <= 0){
|
||||
return false;
|
||||
}
|
||||
unidades = parseInt(unidades);
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
let total = obtenerUnidadesEnvio();
|
||||
|
||||
if($('#prototipo').is(':checked')) {
|
||||
tirada += 1;
|
||||
}
|
||||
|
||||
if(total + unidades <= tirada) {
|
||||
|
||||
data = {
|
||||
id: $('#direcciones').val(),
|
||||
peso: $('#env_tiradaPrecio' + number[0]).attr('peso'),
|
||||
unidades: unidades,
|
||||
entregaPieCalle: $('#entregaPieCalle').is(':checked')?1:0,
|
||||
},
|
||||
data = Object.assign(data, window.token_ajax)
|
||||
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.getDatos,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
if(response.data.length > 0) {
|
||||
let html = '';
|
||||
html += '<div id="envioId' + response.data[0].id + '" t="' +response.data[0].tipo + '" p= ' +response.data[0].coste + ' class="row mb-3">';
|
||||
html += '<div class="col-sm-5 form-check custom-option custom-option-basic checked">';
|
||||
html += '<label class="form-check-label custom-option-content" for="customRadioAddress1">';
|
||||
html += '<span class="custom-option-header mb-2">';
|
||||
html += '<h6 class="fw-semibold mb-0">' + response.data[0].att + '</h6>';
|
||||
html += '<span class="badge bg-label-primary">' + unidades + ' unidades</span>';
|
||||
html += '</span>';
|
||||
html += '<span class="custom-option-body">';
|
||||
html += '<small>' + response.data[0].direccion + '</small><br>';
|
||||
html += '<small>' + response.data[0].cp + '</small><br>';
|
||||
html += '<small>' + response.data[0].municipio +', ' + response.data[0].pais + '</small><br>';
|
||||
html += '<small>' + response.data[0].telefono + '</small><br>';
|
||||
html += '<small>' + response.data[0].email + '</small><br>';
|
||||
if(response.data[0].tipo == 'palets'){
|
||||
html += '<small><i>Envío en palets</i></small><br>';
|
||||
}
|
||||
html += '<hr class="my-2">';
|
||||
html += '<span class="d-flex">';
|
||||
html += '<a class="eliminar-direccion" href="javascript:void(0)">Eliminar</a>';
|
||||
html += '</span>';
|
||||
html += '</span>';
|
||||
html += '</label>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
|
||||
$('#divDirecciones').append(html);
|
||||
$('#errorDirecciones').hide();
|
||||
$('#loader').hide();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$("#direcciones").empty();
|
||||
$('#loader').hide();
|
||||
},
|
||||
});
|
||||
}
|
||||
else{
|
||||
$('#errorDirecciones').text('El número de unidades supera la tirada seleccionada.');
|
||||
$('#errorDirecciones').show();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
|
||||
|
||||
$(document).on('click', '.eliminar-direccion', function(e) {
|
||||
|
||||
$(this).closest('.row.mb-3').remove();
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
|
||||
let total = 0;
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let unidades_direcciones = parseInt($(elements[index]).find('div label span span').text().split(' ')[0]);
|
||||
total += unidades_direcciones;
|
||||
};
|
||||
}
|
||||
|
||||
if(total <= tirada) {
|
||||
$('#errorDirecciones').hide();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('#direcciones').on('change', function() {
|
||||
if( $('#direcciones').val() == 0 ) {
|
||||
$("#addressForm").attr('action','create')
|
||||
|
||||
var $newAddDialog = $("#addressForm")
|
||||
$newAddDialog.modal('show')
|
||||
|
||||
$newAddDialog.on('hidden.bs.modal', function (e) {
|
||||
$('#direcciones').val('');
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function saveAdd_callback(){
|
||||
if($('#addressForm').attr('action')=='create'){
|
||||
let data = {
|
||||
cliente_id: $('#clienteId').val(),
|
||||
alias: $('#add_alias').val(),
|
||||
att: $('#add_att').val(),
|
||||
email: $('#add_email').val(),
|
||||
direccion: $('#add_direccion').val(),
|
||||
pais_id: $("#add_pais_id option:selected").val(),
|
||||
municipio: $('#add_municipio').val(),
|
||||
provincia: $('#add_provincia').val(),
|
||||
cp: $('#add_cp').val(),
|
||||
telefono: $('#add_telefono').val(),
|
||||
}
|
||||
data = Object.assign(data, window.token_ajax)
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_direcciones.nuevaDireccion,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
success: function(response) {
|
||||
$("#direcciones").empty();
|
||||
$.each(response.data, function(index, value) {
|
||||
$("#direcciones").append('<option value="' + value.id + '">' + value.text + '</option>');
|
||||
});
|
||||
$("#direcciones").val('');
|
||||
$('#addressForm').modal('hide');
|
||||
},
|
||||
error: function() {
|
||||
$('#addressForm').modal('hide');
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function validarEnvio(){
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
if(seleccion.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length == 0) {
|
||||
return false;
|
||||
}
|
||||
let tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
|
||||
let total = obtenerUnidadesEnvio();
|
||||
|
||||
if($('#prototipo').is(':checked')) {
|
||||
tirada += 1;
|
||||
}
|
||||
|
||||
if(total != tirada){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDireccionesEnvio(){
|
||||
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
|
||||
let direcciones = [];
|
||||
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
const unidades = parseInt($(elements[index]).find('div label span span').text().split(' ')[0]);
|
||||
const id = $(elements[index]).attr('id').replace('envioId', '');
|
||||
const tipo = $(elements[index]).attr('t');
|
||||
|
||||
direcciones.push({
|
||||
unidades: unidades,
|
||||
id: id,
|
||||
tipo: tipo,
|
||||
})
|
||||
};
|
||||
}
|
||||
return direcciones;
|
||||
}
|
||||
@ -1,789 +0,0 @@
|
||||
$('#papelFormatoPersonalizado').on('change', function () {
|
||||
if ($(this).is(":checked")) {
|
||||
$('#tamanioLibroDiv').hide();
|
||||
$('#anchoLibroDiv').show();
|
||||
$('#altoLibroDiv').show();
|
||||
$('#papelFormatoId').val('').trigger('change');
|
||||
} else {
|
||||
$('#tamanioLibroDiv').show();
|
||||
$('#anchoLibroDiv').hide();
|
||||
$('#altoLibroDiv').hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Init custom option check
|
||||
function initTapaCheck() {
|
||||
const _this = this
|
||||
|
||||
const tapaOptionList = [].slice.call(document.querySelectorAll('.custom-option-tapa .form-check-input'))
|
||||
tapaOptionList.map(function (customOptionEL) {
|
||||
// Update custom options check on page load
|
||||
_this.updateTapaCheck(customOptionEL)
|
||||
|
||||
// Update custom options check on click
|
||||
customOptionEL.addEventListener('click', e => {
|
||||
_this.updateTapaCheck(customOptionEL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function updateTapaCheck(el) {
|
||||
if (el.checked) {
|
||||
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
||||
if (el.type === 'radio') {
|
||||
const customRadioOptionList = [].slice.call(el.closest('.row').querySelectorAll('.custom-option-tapa'))
|
||||
customRadioOptionList.map(function (customRadioOptionEL) {
|
||||
customRadioOptionEL.closest('.custom-option-tapa').classList.remove('checked')
|
||||
})
|
||||
}
|
||||
el.closest('.custom-option-tapa').classList.add('checked')
|
||||
if (el.closest('.custom-option-tapa').id == 'tapaBlandaInnerDiv') {
|
||||
$('#tapaBlanda').prop('checked', true);
|
||||
$('#tapaDura').prop('checked', false);
|
||||
}
|
||||
else {
|
||||
$('#tapaBlanda').prop('checked', false);
|
||||
$('#tapaDura').prop('checked', true);
|
||||
}
|
||||
} else {
|
||||
el.closest('.custom-option-tapa').classList.remove('checked')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initColorCheck() {
|
||||
const _this = this
|
||||
|
||||
const custopOptionList = [].slice.call(document.querySelectorAll('.custom-option-color .form-check-input'))
|
||||
custopOptionList.map(function (customOptionEL) {
|
||||
// Update custom options check on page load
|
||||
_this.updateColorCheck(customOptionEL)
|
||||
|
||||
// Update custom options check on click
|
||||
customOptionEL.addEventListener('click', e => {
|
||||
_this.updateColorCheck(customOptionEL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function updateColorCheck(el) {
|
||||
if (el.checked) {
|
||||
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
||||
if (el.type === 'radio') {
|
||||
const customRadioOptionList = [].slice.call(el.closest('.row-color').querySelectorAll('.custom-option-color'))
|
||||
customRadioOptionList.map(function (customRadioOptionEL) {
|
||||
customRadioOptionEL.closest('.custom-option-color').classList.remove('checked')
|
||||
})
|
||||
}
|
||||
el.closest('.custom-option-color').classList.add('checked')
|
||||
if (el.closest('.custom-option-color').id == 'colorNegroDiv') {
|
||||
$('#colorNegro').prop('checked', true);
|
||||
$('#colorNegroHq').prop('checked', false);
|
||||
$('#colorColor').prop('checked', false);
|
||||
$('#colorColorHq').prop('checked', false);
|
||||
}
|
||||
else if (el.closest('.custom-option-color').id == 'colorNegroHqDiv') {
|
||||
$('#colorNegro').prop('checked', false);
|
||||
$('#colorNegroHq').prop('checked', true);
|
||||
$('#colorColor').prop('checked', false);
|
||||
$('#colorColorHq').prop('checked', false);
|
||||
}
|
||||
else if (el.closest('.custom-option-color').id == 'colorColorDiv') {
|
||||
$('#colorNegro').prop('checked', false);
|
||||
$('#colorNegroHq').prop('checked', false);
|
||||
$('#colorColor').prop('checked', true);
|
||||
$('#colorColorHq').prop('checked', false);
|
||||
}
|
||||
else {
|
||||
$('#colorNegro').prop('checked', false);
|
||||
$('#colorNegroHq').prop('checked', false);
|
||||
$('#colorColor').prop('checked', false);
|
||||
$('#colorColorHq').prop('checked', true);
|
||||
}
|
||||
|
||||
} else {
|
||||
el.closest('.custom-option-color').classList.remove('checked')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$('#enableSobrecubierta').on('change', function () {
|
||||
if ($(this).is(":checked")) {
|
||||
$('.enable-sobrecubierta').show();
|
||||
} else {
|
||||
$('#gramajeSobrecubierta').val('').trigger('change');
|
||||
$('#paperSobrecubierta').val('').trigger('change');
|
||||
$('#acabadosSobrecubierta').val('').trigger('change');
|
||||
$('#tamanioSolapasSobrecubierta').val();
|
||||
$('.enable-sobrecubierta').hide();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function initDisenioLibro() {
|
||||
initTapaCheck();
|
||||
initColorCheck();
|
||||
|
||||
$('.elementos-libro').trigger('change');
|
||||
$('.change-tipo-impresion').trigger('change');
|
||||
|
||||
$('#papelInterior').trigger('change');
|
||||
$('#papelInterior').val(window.datosDisenioLibro.papel_interior);
|
||||
$('#gramajeInterior').append($('<option>', {
|
||||
value: window.datosDisenioLibro.gramaje_interior,
|
||||
text: window.datosDisenioLibro.gramaje_interior
|
||||
}));
|
||||
$('#gramajeInterior').val(window.datosDisenioLibro.gramaje_interior);
|
||||
$('#papelCubierta').val('').trigger('change');
|
||||
$('#papelCubierta').val(window.datosDisenioLibro.papel_cubierta);
|
||||
$('#gramajeCubierta').append($('<option>', {
|
||||
value: window.datosDisenioLibro.gramaje_cubierta,
|
||||
text: window.datosDisenioLibro.gramaje_cubierta
|
||||
}));
|
||||
$('#gramajeCubierta').val(window.datosDisenioLibro.gramaje_cubierta);
|
||||
|
||||
$('#papelSobrecubierta').val('').trigger('change');
|
||||
$('#papelSobrecubierta').val(window.datosDisenioLibro.papel_sobrecubierta);
|
||||
$('#gramajeSobrecubierta').append($('<option>', {
|
||||
value: window.datosDisenioLibro.gramaje_sobrecubierta,
|
||||
text: window.datosDisenioLibro.gramaje_sobrecubierta
|
||||
}));
|
||||
$('#gramajeSobrecubierta').val(window.datosDisenioLibro.gramaje_sobrecubierta);
|
||||
|
||||
$('#enableSobrecubierta').trigger('change');
|
||||
}
|
||||
|
||||
$('.change-tipo-impresion').on('change', function () {
|
||||
|
||||
let isColor = false;
|
||||
if($('#colorColorDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isColor = true;
|
||||
let isHq = false;
|
||||
if($('#colorNegroDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isHq = true;
|
||||
|
||||
//si es color hay que mostrar el numero de paginas a color
|
||||
if (isColor) {
|
||||
$('#pagColorDiv').show();
|
||||
if($('#paginasColor').val() == '')
|
||||
$('#paginasColor').val('0');
|
||||
}
|
||||
else {
|
||||
$('#pagColorDiv').hide();
|
||||
$('#paginasColor').val('0');
|
||||
}
|
||||
|
||||
var data = [];
|
||||
|
||||
if (!isColor && !isHq) {
|
||||
data = window.datosPresupuesto.papelInteriorNegro;
|
||||
}
|
||||
else if (!isColor && isHq) {
|
||||
data = window.datosPresupuesto.papelInteriorNegroHq;
|
||||
}
|
||||
else if (isColor && !isHq) {
|
||||
data = window.datosPresupuesto.papelInteriorColor;
|
||||
}
|
||||
else if (isColor && isHq) {
|
||||
data = window.datosPresupuesto.papelInteriorColorHq;
|
||||
}
|
||||
|
||||
var dropdown = $("#papelInterior");
|
||||
dropdown.empty();
|
||||
$.each(data, function () {
|
||||
dropdown.append($("<option />").val(this.id).text(this.nombre));
|
||||
});
|
||||
//Se quita la seleccion del dropdown
|
||||
dropdown.val('').trigger('change');
|
||||
$('#gramajeInterior').val('').trigger('change');
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('#tirada').on('change', function () {
|
||||
|
||||
const valInterior = $('#gramajeInterior option:selected').val();
|
||||
const valCubierta = $('#gramajeCubierta option:selected').val();
|
||||
const valSobrecubierta = $('#gramajeSobrecubierta option:selected').val();
|
||||
|
||||
|
||||
$('#papelInterior').trigger('change');
|
||||
$('#papelCubierta').trigger('change');
|
||||
$('#papelSobrecubierta').trigger('change');
|
||||
});
|
||||
|
||||
|
||||
$('#papelInterior').on('change', function () {
|
||||
|
||||
let isColor = false;
|
||||
if($('#colorColorDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isColor = true;
|
||||
let isHq = false;
|
||||
if($('#colorNegroDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isHq = true;
|
||||
|
||||
if ($('#papelInterior option:selected').val() != undefined) {
|
||||
var uso = 'bn';
|
||||
|
||||
if (!isColor && !isHq) {
|
||||
uso = 'bn';
|
||||
}
|
||||
else if (!isColor && isHq) {
|
||||
uso = 'bnhq';
|
||||
}
|
||||
else if (isColor && !isHq) {
|
||||
uso = 'color';
|
||||
}
|
||||
else if (isColor && isHq) {
|
||||
uso = 'colorhq';
|
||||
}
|
||||
datos = {
|
||||
tirada: $('#tirada').val(),
|
||||
merma: 0,
|
||||
uso: uso,
|
||||
papel: $('#papelInterior option:selected').text()
|
||||
};
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
const valInterior = $('#gramajeInterior option:selected').val();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_disenio_libro.obtenerGramaje,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function (response) {
|
||||
|
||||
if(response.menu){
|
||||
|
||||
$('#gramajeInterior').empty();
|
||||
$(response.menu).each(function (index, element) {
|
||||
$('#gramajeInterior').append($("<option />").val(element.id).text(element.text));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (valInterior != undefined && valInterior != '')
|
||||
$('#gramajeInterior option[value=' + valInterior + ']').prop('selected', true).trigger('change');
|
||||
else
|
||||
$('#gramajeInterior').val('').trigger('change');
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#papelCubierta').on('change', function () {
|
||||
let isColor = true;
|
||||
let isHq = true;
|
||||
|
||||
if ($('#papelCubierta option:selected').val() != undefined) {
|
||||
var uso = 'cubierta';
|
||||
|
||||
datos = {
|
||||
tirada: $('#tirada').val(),
|
||||
merma: 0,
|
||||
uso: uso,
|
||||
papel: $('#papelCubierta option:selected').text().trim()
|
||||
};
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
const valCubierta = $('#gramajeCubierta option:selected').val();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_disenio_libro.obtenerGramaje,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function (response) {
|
||||
|
||||
$('#gramajeCubierta').empty();
|
||||
$(response.menu).each(function (index, element) {
|
||||
$('#gramajeCubierta').append($("<option />").val(element.id).text(element.text));
|
||||
});
|
||||
|
||||
if (valCubierta != undefined && valCubierta != '')
|
||||
$('#gramajeCubierta option[value=' + valCubierta + ']').prop('selected', true).trigger('change');
|
||||
else
|
||||
$('#gramajeCubierta').val('').trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#papelSobrecubierta').on('change', function () {
|
||||
let isColor = true;
|
||||
let isHq = true;
|
||||
|
||||
if ($('#papelSobrecubierta option:selected').val() != undefined) {
|
||||
var uso = 'sobrecubierta';
|
||||
|
||||
datos = {
|
||||
tirada: $('#tirada').val(),
|
||||
merma: 0,
|
||||
uso: uso,
|
||||
papel: $('#papelSobrecubierta option:selected').text().trim()
|
||||
};
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
const valSobrecubierta = $('#gramajeSobrecubierta option:selected').val();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_disenio_libro.obtenerGramaje,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function (response) {
|
||||
|
||||
$('#gramajeSobrecubierta').empty();
|
||||
$(response.menu).each(function (index, element) {
|
||||
$('#gramajeSobrecubierta').append($("<option />").val(element.id).text(element.text));
|
||||
});
|
||||
|
||||
if (valSobrecubierta != undefined)
|
||||
$('#gramajeSobrecubierta option[value=' + valSobrecubierta + ']').prop('selected', true).trigger('change');
|
||||
else
|
||||
$('#gramajeSobrecubierta').val('').trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#solapasCubierta').on('change', function () {
|
||||
if ($(this).is(":checked")) {
|
||||
$('#tamanioSolapasCubierta').show();
|
||||
} else {
|
||||
$('#tamanioSolapasCubierta').hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Funcion que comprueba que están rellenos todos los datos necesarios para calcular el presupuesto
|
||||
function checkValues() {
|
||||
|
||||
const tirada = $('#tirada').val();
|
||||
const paginas = $('#paginas').val();
|
||||
const papelInterior = $('#papelInterior option:selected').val();
|
||||
const gramajeInterior = $('#gramajeInterior option:selected').text();
|
||||
const papelCubierta = $('#papelCubierta option:selected').val();
|
||||
const gramajeCubierta = $('#gramajeCubierta option:selected').text();
|
||||
const papelFormatoAlto = $('#papelFormatoAlto').val();
|
||||
const papelFormatoAncho = $('#papelFormatoAncho').val();
|
||||
const clienteId = $('#clienteId').val();
|
||||
|
||||
if (paginas == '' || isNaN(paginas) || parseInt(paginas) <= 0) {
|
||||
return false;
|
||||
}
|
||||
if(parseInt(paginas)%2!=0){
|
||||
$('#paginas').val(parseInt(paginas)+1).trigger('change');
|
||||
return false;
|
||||
}
|
||||
|
||||
if(clienteId == '' || isNaN(clienteId) || parseInt(clienteId) <= 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tirada == '' || isNaN(tirada) || parseInt(tirada) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (papelInterior == '' || gramajeInterior == '') {
|
||||
return false;
|
||||
}
|
||||
if (papelCubierta == '' || gramajeCubierta == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($('#papelFormatoId').val() == null && !$('#papelFormatoPersonalizado').is(':checked')){
|
||||
return false;
|
||||
}
|
||||
if($('#papelFormatoPersonalizado').is(':checked')){
|
||||
if(papelFormatoAncho == '' || parseInt(papelFormatoAncho) <= 0 ||
|
||||
papelFormatoAlto == '' || parseInt(papelFormatoAlto) <= 0){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function getTiradas() {
|
||||
let tiradas = [];
|
||||
tiradas.push(parseInt($('#tirada').val()));
|
||||
if ($('#tirada2').val().length > 0 && parseInt($('#tirada2').val()) > 0)
|
||||
tiradas.push(parseInt($('#tirada2').val()));
|
||||
if ($('#tirada3').val().length > 0 && parseInt($('#tirada3').val()) > 0)
|
||||
tiradas.push(parseInt($('#tirada3').val()));
|
||||
if ($('#tirada4').val().length > 0 && parseInt($('#tirada4').val()) > 0)
|
||||
tiradas.push(parseInt($('#tirada4').val()));
|
||||
return tiradas;
|
||||
}
|
||||
|
||||
|
||||
function getDimensionLibro() {
|
||||
|
||||
var ancho = 0;
|
||||
var alto = 0;
|
||||
|
||||
if ($('#papelFormatoId option:selected').length > 0) {
|
||||
var selectedText = $('#papelFormatoId option:selected').text();
|
||||
if (selectedText.length > 0) {
|
||||
ancho = parseFloat(selectedText.trim().split(" x ")[0]);
|
||||
alto = parseFloat(selectedText.trim().split(" x ")[1]);
|
||||
}
|
||||
else if (document.getElementById('papelFormatoPersonalizado').checked) {
|
||||
ancho = parseFloat(document.getElementById('papelFormatoAncho').value);
|
||||
alto = parseFloat(document.getElementById('papelFormatoAlto').value);
|
||||
}
|
||||
}
|
||||
|
||||
else if (document.getElementById('papelFormatoPersonalizado').checked) {
|
||||
ancho = parseFloat(document.getElementById('papelFormatoAncho').value);
|
||||
alto = parseFloat(document.getElementById('papelFormatoAlto').value);
|
||||
}
|
||||
return {
|
||||
ancho: ancho,
|
||||
alto: alto
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$('#retractilado').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
if ($('#retractilado5').is(':checked'))
|
||||
$('#retractilado5').prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#retractilado5').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
if ($('#retractilado').is(':checked'))
|
||||
$('#retractilado').prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
$('.elementos-libro').on('change', function () {
|
||||
// Libro cosido
|
||||
if ($('#cosidoDiv').hasClass('checked')) {
|
||||
$('#tituloDisenioLibro').text("Rústica cosido");
|
||||
if ($('#tapaBlandaInnerDiv').hasClass('checked')) {
|
||||
// Cosido tapa blanda
|
||||
$('.guardas').hide();
|
||||
$('.solapas-cubierta').show();
|
||||
$('.sobrecubierta').show();
|
||||
$('#enableSobrecubierta').trigger('change');
|
||||
}
|
||||
else {
|
||||
// Cosido tapa dura
|
||||
$('.guardas').show();
|
||||
numCarasGuardas(2);
|
||||
$('.solapas-cubierta').hide();
|
||||
$('.sobrecubierta').show();
|
||||
$('#enableSobrecubierta').trigger('change');
|
||||
}
|
||||
}
|
||||
// Libro fresado
|
||||
else if ($('#fresadoDiv').hasClass('checked')) {
|
||||
$('#tituloDisenioLibro').text("Rústica fresado");
|
||||
if ($('#tapaBlandaInnerDiv').hasClass('checked')) {
|
||||
// fresado tapa blanda
|
||||
$('.guardas').hide();
|
||||
$('.solapas-cubierta').show();
|
||||
$('.sobrecubierta').show();
|
||||
$('#enableSobrecubierta').trigger('change');
|
||||
}
|
||||
else {
|
||||
// fresado tapa dura
|
||||
$('.guardas').show();
|
||||
numCarasGuardas(2);
|
||||
$('.solapas-cubierta').hide();
|
||||
$('.sobrecubierta').show();
|
||||
$('#enableSobrecubierta').trigger('change');
|
||||
}
|
||||
}
|
||||
// Libro grapado
|
||||
else if ($('#grapadoDiv').hasClass('checked')) {
|
||||
$('#tituloDisenioLibro').text("Cosido con grapas");
|
||||
if ($('#tapaBlandaInnerDiv').hasClass('checked')) {
|
||||
// grapado tapa blanda
|
||||
$('.guardas').hide();
|
||||
$('.solapas-cubierta').show();
|
||||
$('.sobrecubierta').hide();
|
||||
$('#enableSobrecubierta').prop('checked', false);
|
||||
}
|
||||
}
|
||||
// Libro wire-o
|
||||
else if ($('#wireoDiv').hasClass('checked')) {
|
||||
$('#tituloDisenioLibro').text("Wire-O");
|
||||
if ($('#tapaBlandaInnerDiv').hasClass('checked')) {
|
||||
// wire-o tapa blanda
|
||||
$('.guardas').hide();
|
||||
$('.solapas-cubierta').show();
|
||||
$('.sobrecubierta').hide();
|
||||
$('#enableSobrecubierta').prop('checked', false);
|
||||
}
|
||||
else {
|
||||
// wire-o tapa dura
|
||||
$('.guardas').show();
|
||||
numCarasGuardas(1);
|
||||
$('.solapas-cubierta').hide();
|
||||
$('.sobrecubierta').hide();
|
||||
$('#enableSobrecubierta').prop('checked', false);
|
||||
}
|
||||
}
|
||||
// Libro espiral
|
||||
else if ($('#espiralDiv').hasClass('checked')) {
|
||||
$('#tituloDisenioLibro').text("Espiral");
|
||||
if ($('#tapaBlandaInnerDiv').hasClass('checked')) {
|
||||
// espiral tapa blanda
|
||||
$('.guardas').hide();
|
||||
$('.solapas-cubierta').show();
|
||||
$('.sobrecubierta').hide();
|
||||
$('#enableSobrecubierta').prop('checked', false);
|
||||
}
|
||||
else {
|
||||
// espiral tapa dura
|
||||
$('.espiral').show();
|
||||
numCarasGuardas(1);
|
||||
$('.solapas-cubierta').hide();
|
||||
$('.sobrecubierta').hide();
|
||||
$('#enableSobrecubierta').prop('checked', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function numCarasGuardas(numCaras) {
|
||||
if (numCaras == 1) {
|
||||
$("#impresionGuardas option[value='8']").remove();
|
||||
}
|
||||
else {
|
||||
if ($("#impresionGuardas option[value='8']").length == 0)
|
||||
$("#impresionGuardas").append('<option value="8">' + window.Presupuestos.dosCaras + '</option>');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$('.calcular-presupuesto').on('change', function () {
|
||||
|
||||
// se obtiene el id del elemento que ha disparado el evento
|
||||
if($(this).hasClass('input-sobrecubierta')){
|
||||
if($('#papelSobrecubierta option:selected').val() == '' || $('#gramajeSobrecubierta option:selected').val() == ''){
|
||||
return;
|
||||
}
|
||||
}
|
||||
calcularPresupuesto();
|
||||
});
|
||||
|
||||
function comprobarTiradasPOD(){
|
||||
const tiradas = getTiradas();
|
||||
|
||||
//Comprobar que todos los elementos del array tiradas estan por encima de 30 o por debajo
|
||||
const tiradasPOD = tiradas.every(tirada => tirada <= 30);
|
||||
const tiradasNoPOD = tiradas.every(tirada => tirada > 30);
|
||||
if (tiradasPOD == !tiradasNoPOD) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#clienteId').on('select2:change', function () {
|
||||
calcularPresupuesto();
|
||||
});
|
||||
|
||||
|
||||
async function calcularPresupuesto() {
|
||||
|
||||
let isColor = false;
|
||||
if($('#colorColorDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isColor = true;
|
||||
let isHq = false;
|
||||
if($('#colorNegroHqDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isHq = true;
|
||||
|
||||
if(!comprobarTiradasPOD()){
|
||||
$('#errorTiradas').show();
|
||||
return;
|
||||
}
|
||||
$('#errorTiradas').hide();
|
||||
|
||||
// se obtiene la propiedad serv_id de los checkboxes seleccionados de la clase .servicio-extra
|
||||
if (!checkValues()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let servicios = [];
|
||||
$('.servicio-extra:checked').each(function () {
|
||||
servicios.push($(this).attr('serv_id'));
|
||||
})
|
||||
|
||||
let datos = {
|
||||
tamanio: getDimensionLibro(),
|
||||
tirada: getTiradas(),
|
||||
paginas: $('#paginas').val(),
|
||||
paginasColor: $('#paginasColor').val(),
|
||||
tipo: $('.custom-option-tipo.checked').attr('id').replace('Div', ''),
|
||||
tapa: $('#tapaDura').is(':checked') ? 'dura' : 'blanda',
|
||||
isColor: isColor ? 1 : 0,
|
||||
isHq: isHq ? 1 : 0,
|
||||
papelInterior: $('#papelInterior option:selected').val(),
|
||||
papelInteriorNombre: $('#papelInterior option:selected').text().trim(),
|
||||
gramajeInterior: $('#gramajeInterior option:selected').text(),
|
||||
excluirRotativa: $('#excluirRotativa').is(':checked')? 1 : 0,
|
||||
papelCubierta: $('#papelCubierta option:selected').val(),
|
||||
papelCubiertaNombre: $('#papelCubierta option:selected').text().trim(),
|
||||
gramajeCubierta: $('#gramajeCubierta option:selected').text(),
|
||||
carasCubierta: $('#carasCubierta').val(),
|
||||
acabadoCubierta: $('#acabadosCubierta').val(),
|
||||
clienteId: $('#clienteId').val(),
|
||||
servicios: servicios,
|
||||
}
|
||||
|
||||
// Si es cosido, se añade el número de páginas del cuadernillo
|
||||
if ($('#cosidoDiv').hasClass('checked')) {
|
||||
datos.paginasCuadernillo = $('#paginasCuadernillo').val();
|
||||
}
|
||||
// Si hay solapas de cubierta
|
||||
if ($('#solapasCubierta').is(':checked')) {
|
||||
datos.solapasCubierta = $('#anchoSolapasCubierta').val()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Si hay sobrecubierta
|
||||
if ($('#enableSobrecubierta').is(':checked')) {
|
||||
if($('#papelSobrecubierta option:selected').val()>0 && $('#gramajeSobrecubierta option:selected').val()>0){
|
||||
|
||||
datos.sobrecubierta = {
|
||||
papel: $('#papelSobrecubierta option:selected').val(),
|
||||
papel_nombre: $('#papelSobrecubierta option:selected').text().trim(),
|
||||
gramaje: $('#gramajeSobrecubierta option:selected').text(),
|
||||
acabado: $('#acabadosSobrecubierta').val()
|
||||
}
|
||||
|
||||
datos.sobrecubierta.solapas = $('#anchoSolapasSobrecubierta').val()
|
||||
}
|
||||
}
|
||||
|
||||
if ($('#divGuardas').is(':visible')) {
|
||||
datos.guardas = {
|
||||
papel: $('#papelGuardas option:selected').val(),
|
||||
papel_nombre: $('#papelGuardas option:selected').text().trim(),
|
||||
gramaje: 170,
|
||||
caras: $('#impresionGuardas option:selected').val()
|
||||
}
|
||||
}
|
||||
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
$('.divTiradasPrecio').empty();
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_disenio_libro.presupuestoCliente,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function (response) {
|
||||
error = false;
|
||||
$('#errorGeneral').hide();
|
||||
try{
|
||||
|
||||
|
||||
if(response.errors.interior.length > 0){
|
||||
$('#errorInterior').show();
|
||||
error = true;
|
||||
}
|
||||
else
|
||||
$('#errorInterior').hide();
|
||||
if(response.errors.cubierta.length > 0){
|
||||
$('#errorCubierta').show();
|
||||
error = true;
|
||||
}
|
||||
else
|
||||
$('#errorCubierta').hide();
|
||||
|
||||
if(response.errors.sobrecubierta.length > 0){
|
||||
$('#errorSobrecubierta').show();
|
||||
error = true;
|
||||
}
|
||||
else
|
||||
$('#errorSobrecubierta').hide();
|
||||
|
||||
|
||||
if(response.errors.guardas.length > 0){
|
||||
$('#errorGuardas').show();
|
||||
error = true;
|
||||
}
|
||||
else
|
||||
$('#errorGuardas').hide();
|
||||
|
||||
if(response.errors.servicios.length > 0 || response.errors.serviciosDefecto.length > 0){
|
||||
error = true;
|
||||
$('#errorGeneral').show();
|
||||
}
|
||||
else{
|
||||
$('#errorGeneral').hide();
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
}
|
||||
|
||||
//For debug only
|
||||
//console.log(response);
|
||||
|
||||
$('#loader').hide();
|
||||
|
||||
$('.divTiradasPrecio').empty();
|
||||
|
||||
if(!error){
|
||||
|
||||
$('#lomo_cubierta').val(response.info.lomo_cubierta);
|
||||
|
||||
$('#precios').show();
|
||||
|
||||
if(response.tiradas){
|
||||
for (i = 0; i < response.tiradas.length; i++) {
|
||||
const total = (parseFloat(response.precio_u[i]) * parseInt(response.tiradas[i])).toFixed(2) ;
|
||||
const label = "tiradaPrecio" + parseInt(i+1);
|
||||
|
||||
let html = '';
|
||||
|
||||
html += '<div id="' + label + '" peso="' +response.peso[i]+ '" class="list-group" >';
|
||||
html += '<a href="javascript:void(0);" class="list-group-item list-group-item-action">';
|
||||
html += '<div class="li-wrapper d-flex justify-content-start align-items-center" >';
|
||||
html += '<div class="list-content">';
|
||||
html += '<h7 id="ud_' + label + '" class="mb-1">' + (response.tiradas[i] + ' ud.') + '</h7>';
|
||||
html += '<h6 id="tot_' + label + '" class="mb-1">' + ('Total: ' + total + '€') + '</h6>';
|
||||
html += '<h7 id="pu_' + label + '" class="mb-1">' + (response.precio_u[i] + '€/ud') + '</h7>';
|
||||
html += '</div>';
|
||||
html += '</div>'
|
||||
html += '</a>';
|
||||
html += '</div>';
|
||||
|
||||
$('.divTiradasPrecio').append(html);
|
||||
}
|
||||
}
|
||||
|
||||
if($('#resumen-libro').hasClass('active')) {
|
||||
initDirecciones();
|
||||
initTiradasDirecciones();
|
||||
generarResumen();
|
||||
previewEsquemaCubierta(true);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
$('#loader').hide();
|
||||
$('.divTiradasPrecio').empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,356 +0,0 @@
|
||||
/**
|
||||
* Cliente presupuesto Wizard
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
// Init custom option check
|
||||
//window.Helpers.initCustomOptionCheck();
|
||||
// Vertical Wizard
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
const clientePresupuestoWizard = document.querySelector('#wizard-presupuesto-cliente');
|
||||
if (typeof clientePresupuestoWizard !== undefined && clientePresupuestoWizard !== null ) {
|
||||
// Wizard form
|
||||
const clientePresupuestoWizardForm = clientePresupuestoWizard.querySelector('#presupuesto-cliente-form');
|
||||
// Wizard steps
|
||||
const clientePresupuestoWizardFormStep2 = clientePresupuestoWizardForm.querySelector('#tipo-libro');
|
||||
const clientePresupuestoWizardFormStep3 = clientePresupuestoWizardForm.querySelector('#disenio-libro');
|
||||
const clientePresupuestoWizardFormStep4 = clientePresupuestoWizardForm.querySelector('#direcciones-libro');
|
||||
const clientePresupuestoWizardFormStep5 = clientePresupuestoWizardForm.querySelector('#resumen-libro');
|
||||
// Wizard next prev button
|
||||
const clientePresupuestoWizardNext = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-next'));
|
||||
const clientePresupuestoWizardPrev = [].slice.call(clientePresupuestoWizardForm.querySelectorAll('.btn-prev'));
|
||||
|
||||
let FormValidation2;
|
||||
let FormValidation3;
|
||||
let FormValidation4;
|
||||
let FormValidation5;
|
||||
|
||||
let validationStepper = new Stepper(clientePresupuestoWizard, {
|
||||
linear: true
|
||||
});
|
||||
|
||||
if(clientePresupuestoWizardFormStep2 != null) {
|
||||
// select2 (clienteId)
|
||||
const clienteId = $('#clienteId');
|
||||
|
||||
clienteId.on('change.select2', function () {
|
||||
// Revalidate the clienteId field when an option is chosen
|
||||
FormValidation2.revalidateField('clienteId');
|
||||
});
|
||||
|
||||
// Deal Details
|
||||
FormValidation2 = FormValidation.formValidation(clientePresupuestoWizardFormStep2, {
|
||||
fields: {
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({
|
||||
// Use this for enabling/changing valid/invalid class
|
||||
// eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
rowSelector: '.col-sm-3'
|
||||
}),
|
||||
autoFocus: new FormValidation.plugins.AutoFocus(),
|
||||
submitButton: new FormValidation.plugins.SubmitButton()
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
// Jump to the next step when all fields in the current step are valid
|
||||
validationStepper.next();
|
||||
});
|
||||
|
||||
|
||||
// Deal Usage
|
||||
FormValidation3 = FormValidation.formValidation(clientePresupuestoWizardFormStep3, {
|
||||
fields: {
|
||||
titulo: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: window.Presupuestos.validation.requerido_short
|
||||
},
|
||||
}
|
||||
},
|
||||
clienteId: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.cliente,
|
||||
callback: function (input) {
|
||||
// Get the selected options
|
||||
const options = $("#clienteId").select2('data');
|
||||
const hasValidOption = options.some(option => parseInt(option.id) > 0);
|
||||
return options !== null && options.length > 0 && hasValidOption;
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
tirada: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.integer_greatherThan_0,
|
||||
callback: function (input) {
|
||||
const value = $("#tirada").val();
|
||||
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
paginas: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.integer_greatherThan_0,
|
||||
callback: function (input) {
|
||||
const value = $("#paginas").val();
|
||||
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
paginasColor: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.integer_greatherThan_0,
|
||||
callback: function (input) {
|
||||
if ($('#pagColorDiv').is(':hidden'))
|
||||
return true;
|
||||
else {
|
||||
const value = $("#paginasColor").val();
|
||||
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
gramajeInterior: {
|
||||
validators: {
|
||||
callback: {
|
||||
callback: function (input) {
|
||||
const value = $("#tirada").val();
|
||||
if ($('#gramajeInterior option:selected').text().length == 0) {
|
||||
if(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0){
|
||||
return {
|
||||
valid: false,
|
||||
message: window.Presupuestos.validation.sin_gramaje,
|
||||
}
|
||||
}
|
||||
return {
|
||||
valid: value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0,
|
||||
message: window.Presupuestos.validation.tirada_no_valida,
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
gramajeCubierta: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.tirada_no_valida,
|
||||
callback: function (input) {
|
||||
const value = $("#tirada").val();
|
||||
if ($('#gramajeCubierta option:selected').text().length == 0) {
|
||||
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.sin_gramaje,
|
||||
callback: function (input) {
|
||||
if ($('#gramajeCubierta option:selected').text().length == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
gramajeSobrecubierta: {
|
||||
validators: {
|
||||
callback: {
|
||||
message: window.Presupuestos.validation.tirada_no_valida,
|
||||
callback: function (input) {
|
||||
const value = $("#tirada").val();
|
||||
if ($('#gramajeSobrecubierta option:selected').text().length == 0) {
|
||||
return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({
|
||||
// Use this for enabling/changing valid/invalid class
|
||||
// eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
rowSelector: function (field, ele) {
|
||||
// field is the field name
|
||||
// ele is the field element
|
||||
switch (field) {
|
||||
case 'gramajeInterior':
|
||||
case 'gramajeCubierta':
|
||||
case 'gramajeSobrecubierta':
|
||||
return '.col-sm-2';
|
||||
|
||||
case 'titulo':
|
||||
return '.col-sm-12';
|
||||
|
||||
case 'clienteId':
|
||||
return '.col-sm-6';
|
||||
|
||||
default:
|
||||
return '.col-sm-3';
|
||||
}
|
||||
}
|
||||
}),
|
||||
autoFocus: new FormValidation.plugins.AutoFocus(),
|
||||
submitButton: new FormValidation.plugins.SubmitButton()
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
if($('#tiradaPrecio1').length > 0) {
|
||||
validationStepper.next();
|
||||
initDirecciones();
|
||||
initTiradasDirecciones();
|
||||
}
|
||||
});
|
||||
|
||||
const tirada = $('#tirada');
|
||||
tirada.on('change', function () {
|
||||
// Revalidate the clienteId field when an option is chosen
|
||||
FormValidation2.revalidateField('gramajeInterior');
|
||||
FormValidation2.revalidateField('gramajeCubierta');
|
||||
FormValidation2.revalidateField('gramajeSobrecubierta');
|
||||
});
|
||||
|
||||
// Direcciones
|
||||
FormValidation4 = FormValidation.formValidation(clientePresupuestoWizardFormStep4, {
|
||||
fields: {
|
||||
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({
|
||||
// Use this for enabling/changing valid/invalid class
|
||||
// eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
rowSelector: '.col-md-12'
|
||||
}),
|
||||
autoFocus: new FormValidation.plugins.AutoFocus(),
|
||||
submitButton: new FormValidation.plugins.SubmitButton()
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
if(validarEnvio()){
|
||||
generarResumen();
|
||||
validationStepper.next();
|
||||
}
|
||||
else{
|
||||
let text = "El número de unidades enviadas no coincie con la tirada seleccionada.";
|
||||
if($('#prototipo').is(':checked')) {
|
||||
text += "<br>(Tenga en cuenta que se ha seleccionado la opción de prototipo)";
|
||||
}
|
||||
$('#errorDirecciones').text(text);
|
||||
$('#errorDirecciones').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
// Deal Usage
|
||||
FormValidation5 = FormValidation.formValidation(clientePresupuestoWizardFormStep5, {
|
||||
fields: {
|
||||
// * Validate the fields here based on your requirements
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap5: new FormValidation.plugins.Bootstrap5({
|
||||
// Use this for enabling/changing valid/invalid class
|
||||
// eleInvalidClass: '',
|
||||
eleValidClass: '',
|
||||
rowSelector: '.col-md-12'
|
||||
}),
|
||||
autoFocus: new FormValidation.plugins.AutoFocus(),
|
||||
submitButton: new FormValidation.plugins.SubmitButton()
|
||||
}
|
||||
}).on('core.form.valid', function () {
|
||||
// You can submit the form
|
||||
// clientePresupuestoWizardForm.submit()
|
||||
// or send the form data to server via an Ajax request
|
||||
// To make the demo simple, I just placed an alert
|
||||
//alert('Submitted..!!');
|
||||
});
|
||||
|
||||
clientePresupuestoWizardNext.forEach(item => {
|
||||
item.addEventListener('click', event => {
|
||||
// When click the Next button, we will validate the current step
|
||||
switch (validationStepper._currentIndex) {
|
||||
case 0:
|
||||
FormValidation2.validate();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
FormValidation3.validate();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
FormValidation4.validate();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
FormValidation5.validate();
|
||||
break;
|
||||
|
||||
default:
|
||||
validationStepper.next();
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
clientePresupuestoWizardPrev.forEach(item => {
|
||||
item.addEventListener('click', event => {
|
||||
switch (validationStepper._currentIndex) {
|
||||
case 4:
|
||||
validationStepper.previous();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
validationStepper.previous();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
$('#' + id).show();
|
||||
}
|
||||
}
|
||||
validationStepper.previous();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
validationStepper.previous();
|
||||
break;
|
||||
|
||||
case 0:
|
||||
window.location.href = document.location.origin + '/presupuestocliente/list';
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var url = $(location).attr('href'); // Obtener URL actual
|
||||
if (url.includes('/edit/')) { // Comprobar si la URL contiene 'edit'
|
||||
validationStepper.to(4);
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
@ -1,311 +0,0 @@
|
||||
function generarResumen(){
|
||||
$('#tipoLibro').text($('#tituloDisenioLibro').text() + ' tapa ' + (($('#tapaBlandaInnerDiv').hasClass('checked'))?'blanda':'dura'));
|
||||
$('#resumenTamanio').text('Dimensiones: ' + getDimensionLibro().ancho + 'x' + getDimensionLibro().alto + 'mm');
|
||||
$('#resumenPaginas').text('Páginas: '+ $('#paginas').val() + ' páginas');
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
let tirada = 0;
|
||||
if(seleccion.length != 0) {
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length != 0) {
|
||||
tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
}
|
||||
}
|
||||
$('#resumenTirada').text('Tirada: '+ tirada + ' unidades');
|
||||
|
||||
$('#resumenPrototipo').text('Prototipo: ' + (($('#prototipo').is(':checked'))?'Sí':'No'));
|
||||
$('#resumenFerro').text('Ferro: ' + (($('#ferro').is(':checked'))?'Sí':'No'));
|
||||
|
||||
$('#tipoImpresion').text('Impresión: ' +
|
||||
($('#colorNegroDiv').hasClass('checked')?'Negro estándar':
|
||||
$('#colorNegroHqDiv').hasClass('checked')?'Negro premium':
|
||||
$('#colorColorDiv').hasClass('checked')?'Color estándar':'Color premium'));
|
||||
|
||||
if($('#colorNegroDiv').hasClass('checked') || $('#colorNegroHqDiv').hasClass('checked')){
|
||||
$('#pResumenPaginasColor').hide();
|
||||
}
|
||||
else{
|
||||
$('#pResumenPaginasColor').show();
|
||||
$('#resumenPaginasColor').text($('#paginasColor').val());
|
||||
}
|
||||
$('#resumenPapelInterior').text($('#papelInterior option:selected').text().trim() + ' ' +
|
||||
$('#gramajeInterior option:selected').text() + 'gr/m²');
|
||||
|
||||
let papelCubierta = $('#papelCubierta option:selected').text().trim() + ' ' +
|
||||
$('#gramajeCubierta option:selected').text();
|
||||
papelCubierta += 'gr/m²';
|
||||
$('#resumenPapelCubierta').text(papelCubierta);
|
||||
$('#resumenCarasCubierta').text('Impresión: ' + $('#carasCubierta option:selected').text())
|
||||
$('#resumenAcabadoCubierta').text('Acabado: ' + $('#acabadosCubierta option:selected').text())
|
||||
if ($('#solapasCubierta').is(':checked')) {
|
||||
$('#resumenSolapasCubierta').text('Solapas: ' + $('#anchoSolapasCubierta').val())
|
||||
}
|
||||
else{
|
||||
$('#resumenSolapasCubierta').text('Solapas: No')
|
||||
}
|
||||
|
||||
if ($('#enableSobrecubierta').is(':checked')) {
|
||||
$(".resumen-sobrecubierta").show();
|
||||
$('#resumenPapelCubierta').text($('#papelSobrecubierta option:selected').text().trim() + ' ' +
|
||||
$('#gramajeSobrecubierta option:selected').text() + 'gr/m²');
|
||||
$('#resumenAcabadoSobrecubierta').text('Acabado: ' + $('#acabadosSobrecubierta option:selected').text())
|
||||
$('#resumenSolapasSobrecubierta').text('Solapas: ' + $('#anchoSolapasSobrecubierta').val())
|
||||
|
||||
}
|
||||
else{
|
||||
$(".resumen-sobrecubierta").hide();
|
||||
}
|
||||
|
||||
if ($('#divGuardas').css('display') != 'none') {
|
||||
|
||||
$(".resumen-guardas").show();
|
||||
$('#resumenGuardasPapel').text($('#papelGuardas option:selected').text().trim() + ' ' + '170gr/m²');
|
||||
$('#resumenGuardasCaras').text('Impresión: ' + $('#impresionGuardas option:selected').text())
|
||||
}
|
||||
else{
|
||||
$(".resumen-guardas").hide();
|
||||
}
|
||||
|
||||
|
||||
if($('#retractilado').is(':checked') || $('#retractilado5').is(':checked') || $('#fajaColor').is(':checked')){
|
||||
|
||||
$('.resumen-extras').show();
|
||||
$('#retractilado').is(':checked')?$('#resumenRetractilado1').show():$('#resumenRetractilado1').hide();
|
||||
$('#retractilado5').is(':checked')?$('#resumenRetractilado5').show():$('#resumenRetractilado5').hide();
|
||||
$('#fajaColor').is(':checked')?$('#resumenFajaColor').show():$('#resumenFajaColor').hide();
|
||||
}
|
||||
else{
|
||||
$('.resumen-extras').hide();
|
||||
}
|
||||
|
||||
for (i = 1; i <= 4; i++) {
|
||||
let id = "tiradaPrecio" + i;
|
||||
if ($('#' + id).length > 0) {
|
||||
|
||||
const envio = getTotalEnvio();
|
||||
|
||||
let tirada_id = "ud_tiradaPrecio" + i;
|
||||
if(parseInt($('#' + tirada_id).text().replace(' ud.', '')) != tirada){
|
||||
continue;
|
||||
}
|
||||
|
||||
let total_id = "tot_tiradaPrecio" + i;
|
||||
|
||||
let total = parseFloat($('#' + total_id).text().replace('€', '').replace('Total: ', '')) + envio;
|
||||
let total_iva = 0.0;
|
||||
if($('#ivaReducido').val() == '1'){
|
||||
total_iva = total * 1.04;
|
||||
}
|
||||
else{
|
||||
total_iva = total * 1.21;
|
||||
}
|
||||
const precio_u = total_iva/tirada;
|
||||
$('#resumenTotalIVA').text('Total (I.V.A. ' + (($('#ivaReducido').val() == '1')?'4':'21') + '%): ' + total_iva.toFixed(2) + '€');
|
||||
$('#resumenPrecioU').text(precio_u.toFixed(4) + '€/ud');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getTotalEnvio(){
|
||||
const elements = $('#divDirecciones').find('.row.mb-3');
|
||||
let total = 0.0;
|
||||
|
||||
if(elements.length > 0) {
|
||||
for (let index=0; index<elements.length; index++){
|
||||
let precio_envio = parseFloat($(elements[index]).attr('p'));
|
||||
total += precio_envio;
|
||||
};
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
$('#btnSave').on('click', function() {
|
||||
|
||||
finalizarPresupuesto(false);
|
||||
|
||||
});
|
||||
|
||||
$('#btnConfirm').on('click', function() {
|
||||
|
||||
finalizarPresupuesto(true);
|
||||
|
||||
});
|
||||
|
||||
$('#btnDuplicar').on('click', function() {
|
||||
|
||||
const paths = window.location.pathname.split("/").filter(path => path !== "");
|
||||
let id=0;
|
||||
if(paths.length > 0 && paths[paths.length - 2] == 'edit'){
|
||||
id=paths[paths.length - 1];
|
||||
}
|
||||
datos = {
|
||||
id: id,
|
||||
}
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_resumen.duplicarPresupuesto,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function(response) {
|
||||
|
||||
if(Object.keys(response).length > 0) {
|
||||
if(response.success){
|
||||
$('#loader').hide();
|
||||
window.location.href = document.location.origin + '/presupuestos/presupuestocliente/edit/' + response.id;
|
||||
}
|
||||
}
|
||||
$('#loader').hide();
|
||||
|
||||
},
|
||||
error: function() {
|
||||
$('#loader').hide();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('#btnBack').on('click', function() {
|
||||
window.location.href = document.location.origin + '/presupuestocliente/list';
|
||||
});
|
||||
|
||||
function finalizarPresupuesto(confirmar){
|
||||
|
||||
let isColor = false;
|
||||
if($('#colorColorDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isColor = true;
|
||||
let isHq = false;
|
||||
if($('#colorNegroDiv').hasClass('checked') || $('#colorColorHqDiv').hasClass('checked'))
|
||||
isHq = true;
|
||||
|
||||
const paths = window.location.pathname.split("/").filter(path => path !== "");
|
||||
let id=0;
|
||||
if(paths.length > 0 && paths[paths.length - 2] == 'edit'){
|
||||
id=paths[paths.length - 1];
|
||||
}
|
||||
|
||||
let servicios = [];
|
||||
$('.servicio-extra:checked').each(function () {
|
||||
servicios.push($(this).attr('serv_id'));
|
||||
})
|
||||
|
||||
let datos_libro = {
|
||||
tamanio: getDimensionLibro(),
|
||||
tirada: getTiradas(),
|
||||
paginas: $('#paginas').val(),
|
||||
paginasColor: $('#paginasColor').val(),
|
||||
tipo: $('.custom-option-tipo.checked').attr('id').replace('Div', ''),
|
||||
tapa: $('#tapaDura').is(':checked') ? 'dura' : 'blanda',
|
||||
isColor: isColor,
|
||||
isHq: isHq,
|
||||
papelInterior: $('#papelInterior option:selected').val(),
|
||||
papelInteriorNombre: $('#papelInterior option:selected').text().trim(),
|
||||
gramajeInterior: $('#gramajeInterior option:selected').text(),
|
||||
excluirRotativa: $('#excluirRotativa').is(':checked')? 1 : 0,
|
||||
papelCubierta: $('#papelCubierta option:selected').val(),
|
||||
papelCubiertaNombre: $('#papelCubierta option:selected').text().trim(),
|
||||
gramajeCubierta: $('#gramajeCubierta option:selected').text(),
|
||||
carasCubierta: $('#carasCubierta').val(),
|
||||
acabadoCubierta: $('#acabadosCubierta').val(),
|
||||
clienteId: $('#clienteId').val(),
|
||||
servicios: servicios,
|
||||
};
|
||||
|
||||
// Si es cosido, se añade el número de páginas del cuadernillo
|
||||
if ($('#cosidoDiv').hasClass('checked')) {
|
||||
datos_libro.paginasCuadernillo = $('#paginasCuadernillo').val();
|
||||
}
|
||||
|
||||
// Si hay solapas de cubierta
|
||||
if ($('#solapasCubierta').is(':checked')) {
|
||||
datos_libro.solapasCubierta = $('#anchoSolapasCubierta').val()
|
||||
}
|
||||
|
||||
// Si hay sobrecubierta
|
||||
if ($('#enableSobrecubierta').is(':checked')) {
|
||||
if($('#papelSobrecubierta option:selected').val()>0 && $('#gramajeSobrecubierta option:selected').val()>0){
|
||||
|
||||
datos_libro.sobrecubierta = {
|
||||
papel: $('#papelSobrecubierta option:selected').val(),
|
||||
papel_nombre: $('#papelSobrecubierta option:selected').text().trim(),
|
||||
gramaje: $('#gramajeSobrecubierta option:selected').text(),
|
||||
acabado: $('#acabadosSobrecubierta').val()
|
||||
}
|
||||
|
||||
datos_libro.sobrecubierta.solapas = $('#anchoSolapasSobrecubierta').val()
|
||||
}
|
||||
}
|
||||
|
||||
if ($('#divGuardas').css('display') != 'none') {
|
||||
datos_libro.guardas = {
|
||||
papel: $('#papelGuardas option:selected').val(),
|
||||
papel_nombre: $('#papelGuardas option:selected').text().trim(),
|
||||
gramaje: 170,
|
||||
caras: $('#impresionGuardas option:selected').val()
|
||||
}
|
||||
}
|
||||
|
||||
let datos_cabecera = {
|
||||
titulo: $('#titulo').val(),
|
||||
referenciaCliente: $('#referenciaCliente').val(),
|
||||
}
|
||||
|
||||
const seleccion = $('.custom-option-tiradasDirecciones.checked');
|
||||
let tirada = 0;
|
||||
let peso_libro = 0;
|
||||
if(seleccion.length != 0) {
|
||||
|
||||
const element_tirada =($(seleccion[0]).find('label input')[0]);
|
||||
const number = element_tirada.id.match(/\d+$/);
|
||||
if (number.length != 0) {
|
||||
tirada = parseInt($('#tiradaDireccionesValue' + number[0]).text());
|
||||
peso_libro = ($(seleccion[0])).find('label input').attr('peso');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let direcciones = getDireccionesEnvio();
|
||||
datos = {
|
||||
id: id,
|
||||
datos_libro : datos_libro,
|
||||
datos_cabecera: datos_cabecera,
|
||||
direcciones: direcciones,
|
||||
tirada: tirada,
|
||||
peso: peso_libro,
|
||||
iva_reducido: $('#ivaReducido').val()==1?1:0,
|
||||
confirmar: confirmar?1:0,
|
||||
},
|
||||
|
||||
datos = Object.assign(datos, window.token_ajax)
|
||||
|
||||
$('#loader').show();
|
||||
|
||||
$.ajax({
|
||||
url: window.routes_resumen.guardarPresupuesto,
|
||||
type: 'POST',
|
||||
data: datos,
|
||||
success: function(response) {
|
||||
|
||||
if(Object.keys(response).length > 0) {
|
||||
if(response.status > 0){
|
||||
if(confirmar || window.location.href.includes("add"))
|
||||
window.location.href = response.url + '/' + response.status;
|
||||
}
|
||||
|
||||
}
|
||||
$('#loader').hide();
|
||||
|
||||
},
|
||||
error: function() {
|
||||
$('#loader').hide();
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
// Init custom option check
|
||||
function initTipoLibroCheck()
|
||||
{
|
||||
const _this = this
|
||||
|
||||
const custopOptionList = [].slice.call(document.querySelectorAll('.custom-option-tipo .form-check-input'))
|
||||
custopOptionList.map(function (customOptionEL) {
|
||||
// Update custom options check on page load
|
||||
_this.updateTipoLibroCheck(customOptionEL)
|
||||
|
||||
// Update custom options check on click
|
||||
customOptionEL.addEventListener('click', e => {
|
||||
_this.updateTipoLibroCheck(customOptionEL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function updateTipoLibroCheck(el)
|
||||
{
|
||||
if (el.checked) {
|
||||
// If custom option element is radio, remove checked from the siblings (closest `.row`)
|
||||
if (el.type === 'radio') {
|
||||
const customRadioOptionList = [].slice.call(el.closest('.tipo_libro').querySelectorAll('.custom-option-tipo'))
|
||||
customRadioOptionList.map(function (customRadioOptionEL) {
|
||||
customRadioOptionEL.closest('.custom-option-tipo').classList.remove('checked')
|
||||
})
|
||||
}
|
||||
el.closest('.custom-option-tipo').classList.add('checked')
|
||||
if(el.closest('.custom-option-tipo').id == 'grapadoDiv') {
|
||||
$('#tapaDuraDiv').hide();
|
||||
$('#tapaBlanda').prop('checked', true);
|
||||
}
|
||||
else {
|
||||
$('#tapaDuraDiv').show();
|
||||
}
|
||||
if(el.closest('.custom-option-tipo').id == 'cosidoDiv') {
|
||||
$('#div_pagCuadernillo').show();
|
||||
}
|
||||
else {
|
||||
$('#div_pagCuadernillo').hide();
|
||||
}
|
||||
} else {
|
||||
el.closest('.custom-option-tipo').classList.remove('checked')
|
||||
}
|
||||
}
|
||||
|
||||
initTipoLibroCheck();
|
||||
|
||||
|
||||
function getUpdatePapelInterior() {
|
||||
var impresionInterior = $('input[name="impresionInterior"]:checked').val();
|
||||
if(impresionInterior == 'color') {
|
||||
$('#colorInteriorDiv').show();
|
||||
}
|
||||
else {
|
||||
$('#colorInteriorDiv').hide();
|
||||
}
|
||||
}
|
||||
@ -523,16 +523,12 @@ class DisenioCubierta {
|
||||
acabados += ", Barniz UVI " + this.domItem.find("#barniz").children("option:selected").text();
|
||||
if (this.domItem.find("#estampado").children("option:selected").val() != 'NONE')
|
||||
acabados += ", Estampado " + this.domItem.find("#estampado").children("option:selected").text();
|
||||
if (this.domItem.find("#retractilado").hasClass('selected')) {
|
||||
acabados += ", Retractilado ";
|
||||
}
|
||||
return acabados;
|
||||
}
|
||||
else {
|
||||
acabados.plastificado = this.domItem.find("#plastificado ").children("option:selected").val();
|
||||
acabados.barniz = this.domItem.find("#barniz").children("option:selected").val();
|
||||
acabados.estampado = this.domItem.find("#estampado").children("option:selected").val();
|
||||
acabados.retractilado = this.domItem.find("#retractilado").hasClass('selected') ? 'RETR' : 'NONE';
|
||||
}
|
||||
return acabados;
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user