diff --git a/Practicas/Practicas JS/DOM Alquiler Coche V2/Ejercicio_práctica_alquila_coche2.txt b/Practicas/Practicas JS/DOM Alquiler Coche V2/Ejercicio_práctica_alquila_coche2.txt new file mode 100644 index 0000000..89ab104 --- /dev/null +++ b/Practicas/Practicas JS/DOM Alquiler Coche V2/Ejercicio_práctica_alquila_coche2.txt @@ -0,0 +1,20 @@ +Debemos adaptar el ejercicio anterior. + +- Para el periodo de alquiler solicitamos dos fechas inicio y fin del alquiler.(No el número de días). +- Ahora tendra un botón para calcular el coste y sacar la información, otro para realizar el envío del formulario y otro más para limpiar los datos del formulario. + +- Coste de anulación será el 30% del total con IVA incluido y solo se puede anular al menos 5 días antes del inicio del alquiler. + + + +Mensaje en textarea: + +Faltan 2 días para tu alquiler ! +Tu fecha de de entrega del vehículo es el 27/1/2024 ! +Puedes anular tu reserva hasta el día 21/1/2024 ! +El coste de la anulación será de 155.73 euros ! +Tus extras son los siguientes: +Silla Infantil +Gps +Has contratado seguro a todo riesgo ! +Tienes recargo por ser menor de 30 años ! \ No newline at end of file diff --git a/Practicas/Practicas JS/DOM Alquiler Coche V2/index.html b/Practicas/Practicas JS/DOM Alquiler Coche V2/index.html new file mode 100644 index 0000000..dae0827 --- /dev/null +++ b/Practicas/Practicas JS/DOM Alquiler Coche V2/index.html @@ -0,0 +1,75 @@ + + + + + + + + Alquiler de coche + + + +
+
+
+
+ +
+
+ +
+
+
+ + +
+ +

Elementos Opcionales

+ +
+ + +
+ +
+ + +
+ +

Seguro

+

*** El seguro a terceros es obligatorio y tiene un coste de 10 €/dia sin IVA

+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + + +
+
+
+ + + + + + + \ No newline at end of file diff --git a/Practicas/Practicas JS/DOM Alquiler Coche V2/js/main.js b/Practicas/Practicas JS/DOM Alquiler Coche V2/js/main.js new file mode 100644 index 0000000..104bdc4 --- /dev/null +++ b/Practicas/Practicas JS/DOM Alquiler Coche V2/js/main.js @@ -0,0 +1,76 @@ +const diaInicio=document.getElementById("fechaInicio"); +const diaFin=document.getElementById("fechaFin"); +const gamaSeleccionada=document.getElementById("tipoVehiculo"); +const sillaInfantil=document.getElementById("sillainfantil"); +const gps=document.getElementById("gps"); +const seguroTr=document.getElementById("segurotr"); +const menor30=document.getElementById("menor30"); +const total=document.getElementById("total"); +const txtResumen= document.getElementById("resumen"); + + +const GAMAVEHICULOS=['basico','gama_media','lujo']; +const PVPALQUILERXDIA=[45,65,85]; +const PVPSEGUROTR=[15,25,35]; + +const IVA=1.21; + + +function calculaAlquiler() { + let diasAlquiler=difFechasDias(diaInicio.value,diaFin.value) + let pvpAlquilerXGama = parseInt(valorXopcion(gamaSeleccionada.value,GAMAVEHICULOS,PVPALQUILERXDIA,0)*diasAlquiler) + let opcSillaInfantil = parseInt(totalXOpcion(sillaInfantil.checked,15,0)* diasAlquiler); + let opcGps = parseInt(totalXOpcion(gps.checked,5,0)* diasAlquiler); + let seguro = parseInt(totalXOpcion(seguroTr.checked,valorXopcion(gamaSeleccionada.value,GAMAVEHICULOS,PVPSEGUROTR,0),10)*diasAlquiler); + let pvpSinIva = diasAlquiler+pvpAlquilerXGama+opcSillaInfantil+opcGps+seguro; + let pvpConIva = parseFloat(pvpSinIva*IVA).toFixed(2); + if (menor30.checked){pvpConIva=(pvpConIva*1.30).toFixed(2)} + total.value=pvpConIva + + + + + diasEntrega= difFechasDias(new Date(),diaInicio.value) + generaResumen(diasEntrega, diaFin.value) + + + + +} + + +function generaResumen(diasEntrega, fechaEntrega, fechaAnulacion, costeAnulacion, extras){ + let mensaje=`Faltan ${diasEntrega} días para tu alquiler\nTu fecha de entrega del vehiculo es: ${fechaEntrega}` + txtResumen.value=mensaje +} + + + + +// ******************** // +// Funciones de Fechas // +// ******************** // +/** + * Devuelve la diferencia en dias entre fechas + * @param {Date} fechaIni - Fecha inicial + * @param {Date} fechaFin - Fecha final + */ +function difFechasDias(fechaIni, fechaFin) { + let dias = Math.ceil((new Date(fechaFin) - new Date(fechaIni)) / (1000 * 60 * 60 * 24)); + return dias; +} + + +function valorXopcion(opc,opciones,valores,valorDefecto){ + const index = opciones.indexOf(opc); + return index !== -1 ? valores[index] : valorDefecto; +} + +function totalXOpcion(checked,valorChecked,valorUnchecked){ + return checked ? valorChecked : valorUnchecked; +} + + +function limpiarForm(){ + document.getElementById("formAlquiler").reset(); +} \ No newline at end of file