trabajando en direcciones

This commit is contained in:
jaimejimenezortega
2024-05-06 21:53:02 +02:00
parent 3453306123
commit 282f2274ca
10 changed files with 22068 additions and 403 deletions

View File

@ -0,0 +1,33 @@
<div class="col-12 pb-2">
<div id="containerTiradasEnvios" class="row mb-3">
</div>
<div class="row mb-3">
<div class="col-sm-4 mb-3">
<label for="direcciones" class="form-label">Mis direcciones</label>
<select id="direcciones" name="direcciones" class="form-control select2bs2" style="width: 100%;"></select>
</div>
<div class="col-sm-2 mb-3">
<label for="unidadesEnvio" class="form-label">
Unidades
</label>
<input type="number" class="form-control" id="unidadesEnvio" name="unidadesEnvio" maxLength="8" step="1" class="form-control">
</div><!--//.mb-3 -->
<div class="col-sm-2 mb-3 mt-auto mb-0">
<button id="insertarDireccion" type="button" class="btn btn-secondary waves-effect waves-light">Insertar</button>
</div>
<div id="errorDirecciones" class="fv-plugins-message-container invalid-feedback" style="display: none;">
</div>
</div>
<div id="divDirecciones" class="col-12 pb-2">
</div>
</div>

View File

@ -0,0 +1,144 @@
function initTiradasDirecciones() {
const _this = this
$('#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 html = '';
html += '<div class="col-sm-3">';
html += '<div class="form-check custom-option custom-option-basic custom-option-tiradasDirecciones' + (i==1?' checked':'')+ ' ">';
html += '<label class="form-check-label custom-option-content" for="tiradaEnvios' + i + '">';
html += '<input name="' + id + '" class="form-check-input" type="radio" value="" id="' + id + '">';
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);
$('#' + id).hide();
}
}
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 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')
})
}
el.closest('.custom-option-tiradasDirecciones').classList.add('checked')
} else {
el.closest('.custom-option-tiradasDirecciones').classList.remove('checked')
}
}
$('#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());
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($('#prototipo').is(':checked')) {
tirada += 1;
}
if(total + unidades <= tirada) {
let html = '';
html += '<div 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">Jaime Jiménez Ortega</h6>';
html += '<span class="badge bg-label-primary">' + unidades + ' unidades</span>';
html += '</span>';
html += '<span class="custom-option-body">';
html += '<small>Circunvalacion La Encina, 20, 5A</small><br>';
html += '<small>18200</small><br>';
html += '<small>Granada, España</small><br>';
html += '<small>600620238</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();
}
else{
$('#errorDirecciones').text('El número de unidades supera la tirada seleccionada.');
$('#errorDirecciones').show();
}
//}
return false;
})
$(".eliminar-direccion").on('click', function() {
$(this).closest('.row.mb-3').remove();
return false;
})

View File

@ -594,6 +594,10 @@ function comprobarTiradasPOD(){
return false;
}
$('#clienteId').on('select2:change', function () {
calcularPresupuesto();
});
async function calcularPresupuesto() {
@ -714,10 +718,8 @@ async function calcularPresupuesto() {
console.log(response);
$('#loader').hide();
if(error){
$('#tiradaPrecio1').hide();
$('#tiradaPrecio2').hide();
$('#tiradaPrecio3').hide();
$('#tiradaPrecio4').hide();
$('#divTiradasPrecio').empty();
}
else{
$('#precios').show();
@ -726,24 +728,28 @@ async function calcularPresupuesto() {
const total = (parseFloat(response.precio_u[i]) * parseInt(response.tiradas[i])).toFixed(2) ;
const label = "tiradaPrecio" + parseInt(i+1);
$('#ud_' + label).text(response.tiradas[i] + ' ud.');
$('#tot_' + label).text('Total: ' + total + '€');
$('#pu_' + label).text(response.precio_u[i] + '€/ud');
$('#' + label).show();
}
for (i = response.tiradas.length; i < 4; i++) {
const label = "tiradaPrecio" + parseInt(i+1);
$('#' + label).hide();
}
let html = '';
html += '<div id="' + label + '" 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);
}
}
},
error: function (error) {
$('#loader').hide();
$('#tiradaPrecio1').hide();
$('#tiradaPrecio2').hide();
$('#tiradaPrecio3').hide();
$('#tiradaPrecio4').hide();
$('#divTiradasPrecio').empty();
}
});
}

View File

@ -208,6 +208,7 @@
}
}).on('core.form.valid', function () {
validationStepper.next();
initTiradasDirecciones();
});
const tirada = $('#tirada');
@ -218,7 +219,7 @@
FormValidation2.revalidateField('gramajeSobrecubierta');
});
// Deal Usage
// Direcciones
const FormValidation4 = FormValidation.formValidation(clientePresupuestoWizardFormStep4, {
fields: {
@ -296,6 +297,12 @@
break;
case 3:
for (let i = 0; i < 4; i++) {
let id = "tiradaPrecio" + i;
if ($('#' + id).length > 0) {
$('#' + id).show();
}
}
validationStepper.previous();
break;

View File

@ -68,52 +68,9 @@
administrador.</p>
</div>
<div id="tiradaPrecio1" class="list-group" style="display: none;">
<a class="list-group-item list-group-item-action d-flex justify-content-between" style="display: none;">
<div class="li-wrapper d-flex justify-content-start align-items-center" >
<div class="list-content">
<h7 id="ud_tiradaPrecio1" class="mb-1">100 unidades</h7>
<h6 id="tot_tiradaPrecio1" class="mb-1">Total 387.54€</h6>
<h7 id="pu_tiradaPrecio1" class="mb-1">3.8754€/ud</h7>
</div>
</div>
</a>
</div>
<div id="tiradaPrecio2" class="list-group" style="display: none;">
<a class="list-group-item list-group-item-action d-flex justify-content-between" style="display: none;">
<div class="li-wrapper d-flex justify-content-start align-items-center" >
<div class="list-content">
<h7 id="ud_tiradaPrecio2" class="mb-1">100 unidades</h7>
<h6 id="tot_tiradaPrecio2" class="mb-1">Total 387.54€</h6>
<h7 id="pu_tiradaPrecio2" class="mb-1">3.8754€/ud</h7>
</div>
</div>
</a>
</div>
<div id="tiradaPrecio3" class="list-group" style="display: none;">
<a class="list-group-item list-group-item-action d-flex justify-content-between" style="display: none;">
<div class="li-wrapper d-flex justify-content-start align-items-center" >
<div class="list-content">
<h7 id="ud_tiradaPrecio3" class="mb-1">100 unidades</h7>
<h6 id="tot_tiradaPrecio3" class="mb-1">Total 387.54€</h6>
<h7 id="pu_tiradaPrecio3" class="mb-1">3.8754€/ud</h7>
</div>
</div>
</a>
</div>
<div id="tiradaPrecio4" class="list-group" style="display: none;">
<a class="list-group-item list-group-item-action d-flex justify-content-between" style="display: none;">
<div class="li-wrapper d-flex justify-content-start align-items-center" >
<div class="list-content">
<h7 id="ud_tiradaPrecio4" class="mb-1">100 unidades</h7>
<h6 id="tot_tiradaPrecio4" class="mb-1">Total 387.54€</h6>
<h7 id="pu_tiradaPrecio4" class="mb-1">3.8754€/ud</h7>
</div>
</div>
</a>
</div>
<div id='divTiradasPrecio'>
</div>
</div>
@ -125,9 +82,10 @@
<div id="tipo-libro" class="content active dstepper-block fv-plugins-bootstrap5 fv-plugins-framework">
<div class="row g-3">
<?= view("themes/backend/vuexy/form/presupuestos/cliente/_tipoLibroItems") ?>
<?= view("themes/backend/vuexy/form/presupuestos/cliente/_tipoLibroItems") ?>
<?php /*
<?= view("themes/backend/vuexy/form/presupuestos/cliente/_direccionesItems") ?>
*/?>
<div class="col-12 d-flex justify-content-between mt-4">
<button class="btn btn-label-secondary btn-prev waves-effect">
<i class="ti ti-arrow-left ti-xs me-sm-1 me-0"></i>
@ -160,11 +118,11 @@
</div>
</div>
<!-- Deal Usage -->
<!-- Direcciones -->
<div id="direcciones-libro" class="content fv-plugins-bootstrap5 fv-plugins-framework">
<div class="row g-3">
<?= view("themes/backend/vuexy/form/presupuestos/cliente/_direccionesItems") ?>
<div class="col-12 d-flex justify-content-between mt-4">
<button class="btn btn-label-secondary btn-prev waves-effect">
@ -275,4 +233,5 @@ initDisenioLibro();
<script src="<?= site_url('js_loader/presupuestoCliente_js') ?>"></script>
<script src="<?= site_url('js_loader/presupuestoClienteTipoLibro_js') ?>"></script>
<script src="<?= site_url('js_loader/presupuestoClienteDisenioLibro_js') ?>"></script>
<script src="<?= site_url('js_loader/presupuestoClienteDirecciones_js') ?>"></script>
<?= $this->endSection() ?>

View File

@ -1268,34 +1268,34 @@ function get_tarifas_preimpresion(tarifa_id = -1){
function servicioPrototipo(){
if($('#prototipo').prop('checked')){
$('#add_servicio_preimpresion_list').val(serviciosAutomaticos.prototipo)
$('#insertar_serv_preimpresion').click()
$('#add_servicio_extra_list').val(serviciosAutomaticos.prototipo)
$('#insertar_serv_extra').click()
}
else{
var row_indexes = tableServiciosPreimpresion.rows().eq( 0 ).filter( function (rowIdx) {
return tableServiciosPreimpresion.cell( rowIdx, 0 ).data() == serviciosAutomaticos.prototipo ? true : false;
var row_indexes = tableServiciosExtra.rows().eq( 0 ).filter( function (rowIdx) {
return tableServiciosExtra.cell( rowIdx, 0 ).data() == serviciosAutomaticos.prototipo ? true : false;
} );
if(row_indexes.length > 0){
tableServiciosPreimpresion.row(row_indexes[0]).remove().draw()
tableServiciosExtra.row(row_indexes[0]).remove().draw()
check_serv_preimpresion_error()
}
}
}
function servicioFerro(){
var row_indexes = tableServiciosPreimpresion.rows().eq( 0 ).filter( function (rowIdx) {
return tableServiciosPreimpresion.cell( rowIdx, 0 ).data() == serviciosAutomaticos.ferro ? true : false;
var row_indexes = tableServiciosExtra.rows().eq( 0 ).filter( function (rowIdx) {
return tableServiciosExtra.cell( rowIdx, 0 ).data() == serviciosAutomaticos.ferro ? true : false;
} );
if($('#ferro').prop('checked')){
if(row_indexes.length == 0){
$('#add_servicio_preimpresion_list').val(serviciosAutomaticos.ferro)
$('#insertar_serv_preimpresion').click()
$('#add_servicio_extra_list').val(serviciosAutomaticos.ferro)
$('#insertar_serv_extra').click()
}
}
else{
if(row_indexes.length > 0){
tableServiciosPreimpresion.row(row_indexes[0]).remove().draw()
check_serv_preimpresion_error()
tableServiciosExtra.row(row_indexes[0]).remove().draw()
check_serv_extra_error()
}
}
}