Dia38
This commit is contained in:
parent
4cb6127f80
commit
a6dd79e9c8
|
|
@ -0,0 +1,179 @@
|
||||||
|
<!Doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Coste viaje JAVASCRIPT</title>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
|
||||||
|
// Función obtener() que realizará la captación de datos,los cálculos y la escritura del mensaje de info
|
||||||
|
function obtener() {
|
||||||
|
// Declaro y obtengo las variables de número de días y tipo de vehículo
|
||||||
|
|
||||||
|
//Calcular periodo de alquiler (días)
|
||||||
|
let inicio=document.getElementById("fecha").valueAsNumber;
|
||||||
|
let fin=document.getElementById("fechaF").valueAsNumber;
|
||||||
|
let dif=fin - inicio;
|
||||||
|
let dias=Math.ceil(dif/(1000*60*60*24));
|
||||||
|
|
||||||
|
//Tipo de vehículo
|
||||||
|
let tipo=document.getElementById("tipo").value;
|
||||||
|
|
||||||
|
// Declaro las variables tipoP y riesgo que se reasignarán en los condicionales
|
||||||
|
let tipoP;
|
||||||
|
let riesgo;
|
||||||
|
|
||||||
|
if (tipo == "basico") {
|
||||||
|
tipoP=45;
|
||||||
|
riesgo=15;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tipo == "gamamedia") {
|
||||||
|
tipoP=65;
|
||||||
|
riesgo=25;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tipo == "lujo") {
|
||||||
|
tipoP=85;
|
||||||
|
riesgo=35;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculo el precio por día con tipo de vehículo y seguro
|
||||||
|
let vehiculo;
|
||||||
|
if (document.getElementById("riesgo").checked) {
|
||||||
|
vehiculo=dias*(tipoP+riesgo);
|
||||||
|
} else {vehiculo=dias*(tipoP+10)}
|
||||||
|
|
||||||
|
|
||||||
|
//Extra silla
|
||||||
|
let silla;
|
||||||
|
if (document.getElementById("silla").checked) {
|
||||||
|
silla=15;
|
||||||
|
} else { silla=0}
|
||||||
|
|
||||||
|
//Extra gps
|
||||||
|
let gps;
|
||||||
|
if (document.getElementById("gps").checked) {
|
||||||
|
gps=5;
|
||||||
|
} else { gps=0}
|
||||||
|
|
||||||
|
// Calculo el incremento de precio con extras
|
||||||
|
let extras=(silla+gps)*dias;
|
||||||
|
|
||||||
|
// Calculo el precio de vehículo + extras con IVA
|
||||||
|
let total=vehiculo+extras;
|
||||||
|
let totalI=(total*1.21);
|
||||||
|
|
||||||
|
// Aplico el incremento si es menor de 30 años
|
||||||
|
let precioMenor;
|
||||||
|
if (document.getElementById("menor").checked) {
|
||||||
|
precioMenor=totalI*0.3;
|
||||||
|
} else { precioMenor=0 }
|
||||||
|
|
||||||
|
// Calculo el precio total y los gastos de anulación
|
||||||
|
let totalF=(totalI+precioMenor).toFixed(2);
|
||||||
|
document.getElementById("total").value=totalF;
|
||||||
|
let precioAnulacion=totalF*0.3;
|
||||||
|
let precioAnulacionF=precioAnulacion.toFixed(2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Cáculo de fechas
|
||||||
|
|
||||||
|
//Fecha del momento de la reserva
|
||||||
|
let hoy=new Date().getTime();
|
||||||
|
// Calculo los días que faltan
|
||||||
|
let dif2=inicio-hoy;
|
||||||
|
let diasF=dif2/(1000*60*60*24);
|
||||||
|
// Fecha de entrega
|
||||||
|
let entregaF=new Date(fin);
|
||||||
|
// Obtengo la fecha de entrega en formato local dd-mm-xxxx
|
||||||
|
let entregaP=entregaF.toLocaleDateString();//.toLocaleDateString()
|
||||||
|
// Obtengo la fecha límite para la anulación
|
||||||
|
let limiteAnulacion=inicio-(5*24*60*60*1000);
|
||||||
|
// Obtengo la fecha de anulación en formato local
|
||||||
|
let anulacionF=new Date(limiteAnulacion);
|
||||||
|
let anulacionP=anulacionF.toLocaleDateString();
|
||||||
|
|
||||||
|
/////////////////////
|
||||||
|
// Inicializar variables de mensaje extras
|
||||||
|
let mensajeSilla = "No has escogido silla infantil" ;
|
||||||
|
let mensajeGps = "No has escogido Gps";
|
||||||
|
let mensajeRiesgo = "No has escogido seguro a todoriesgo";
|
||||||
|
let mensajeMenor = "No tienes recargo por ser menor de 30 ";
|
||||||
|
|
||||||
|
// Resaignar valor mensaje extra si esta checked
|
||||||
|
if(document.getElementById('silla').checked){
|
||||||
|
mensajeSilla = "Has escogido silla infantil";}
|
||||||
|
|
||||||
|
if(document.getElementById('gps').checked){
|
||||||
|
mensajeGps = "Has escogido Gps";}
|
||||||
|
|
||||||
|
if(document.getElementById('riesgo').checked){
|
||||||
|
mensajeRiesgo = "Has escogido seguro a todo riesgo";}
|
||||||
|
|
||||||
|
if(document.getElementById('menor').checked){
|
||||||
|
mensajeMenor = "Tienes recargo por ser menor de 30 ";}
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
|
// Creo las variables del mensaje
|
||||||
|
let extrasT="Tus extras son los siguientes: " + "\n";
|
||||||
|
|
||||||
|
// Añado los extras al mensaje
|
||||||
|
extrasT += mensajeSilla +"\n"+ mensajeGps +"\n"+ mensajeRiesgo +"\n"+ mensajeMenor
|
||||||
|
|
||||||
|
// Creo el mensaje llamando a las variables
|
||||||
|
let frase="Faltan "+(Math.ceil(diasF))+ " días "+"para tu alquiler"+"\n"
|
||||||
|
+"Tu fecha de de entrega del vehículo es el "+entregaP+"\n"
|
||||||
|
+"Puedes anular tu reserva hasta el día "+anulacionP+"\n"
|
||||||
|
+"El coste de la anulación será de " +precioAnulacionF+ " euros"+"\n"
|
||||||
|
+ extrasT;
|
||||||
|
document.getElementById("info").value=frase;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container">
|
||||||
|
<form action="gracias.html" method="get">
|
||||||
|
<h1>Alquiler de vehículo</h1>
|
||||||
|
|
||||||
|
<p>Elige la fecha de inicio del alquiler<input type="date" id="fecha"></p>
|
||||||
|
<p>Elige la fecha de fin del alquiler<input type="date" id="fechaF"></p>
|
||||||
|
<br>
|
||||||
|
<p>Seleccione el tipo de vehículo
|
||||||
|
<!-- Lista de selección -->
|
||||||
|
<select name="tipo" id="tipo">
|
||||||
|
<option value="basico">Básico 45 Euros/día</option>
|
||||||
|
<option value="gamamedia">Gama media 65 Euros/día</option>
|
||||||
|
<option value="lujo">Lujo 85 Euros/día</option>
|
||||||
|
</select></p>
|
||||||
|
<h2>Elementos opcionales</h2>
|
||||||
|
<p>Silla Infantil * 15 Euros por día de alquiler<input type="checkbox" name="silla" id="silla" value="Silla Infantil"></p>
|
||||||
|
<p>GPS * 5 Euros por día de alquiler <input type="checkbox" name="gps" id="gps" value="Gps"></p>
|
||||||
|
<h2>Seguro</h2>
|
||||||
|
<p>** El seguro a terceros es obligatorio y tiene un coste de 10 Euros/día sin IVA</p>
|
||||||
|
<p>Seguro a todo riesgo <input type="checkbox" name="riesgo" id="riesgo" value="Seguro a todo riesgo"></p>
|
||||||
|
<p>Conductor menor de 30 años <input type="checkbox" name="menor" id="menor" value="Menor de 30"></p>
|
||||||
|
<p>Coste total <input type="text" name="total" id="total" ></p>
|
||||||
|
|
||||||
|
<input type="button" value="Calcular coste total" onclick="obtener();">
|
||||||
|
<input type="reset" value="Limpiar">
|
||||||
|
<input type="submit" value="Enviar"><br><br>
|
||||||
|
|
||||||
|
<input type="hidden" name="" id="inputAnulacion" value="" />
|
||||||
|
<textarea rows="8" cols="60" name="info" id="info"></textarea>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -217,9 +217,13 @@
|
||||||
const index = opciones.indexOf(opc);
|
const index = opciones.indexOf(opc);
|
||||||
return index !== -1 ? valores[index] : valorDefecto;
|
return index !== -1 ? valores[index] : valorDefecto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function totalXOpcion(checked, valorChecked, valorUnchecked) {
|
function totalXOpcion(checked, valorChecked, valorUnchecked) {
|
||||||
return checked ? valorChecked : valorUnchecked;
|
return checked ? valorChecked : valorUnchecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function submitForm() {
|
function submitForm() {
|
||||||
document.getElementById("formAlquiler").submit();
|
document.getElementById("formAlquiler").submit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user