-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcargar_historial.ejs
260 lines (216 loc) · 10.2 KB
/
cargar_historial.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%- include ('header', {tituloweb: '¡Oh my dog! | Registrar visita'}); %>
</head>
<body id="body">
<div class="container h-100 mt-4">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-lg-12 col-xl-8">
<div class="card text-black" style="border-radius: 25px;">
<div class="card-body p-md-5 p-lg-5">
<div class="row justify-content-center">
<p class="text-center h1 fw-bold mb-5 mx-1 mx-md-4 ">Registrar visita</p>
<% if (usuario && usuario.name) { %>
<div class="alert alert-info" role="alert">Se registra una visita a: <strong><%= usuario.name %></strong></div>
<% } %>
<div class="col-md-10 col-lg-5 col-xl-6 order-2 order-lg-1">
<form id="miForm" action="/registrarVisita/cliente/<%= usuario.id %>?mascota=<%= turno.MascotumId %>&practica=<%= turno.practica %>&turno_id=<%= turno.id %>" method="POST">
<div class="row mb-3">
<label for="mascota">Mascota</label>
<div class="mb-3">
<input type="text" class="form-control form-control-user" id="mascota"
name="mascota" readonly value="<%= nombreMascota %>"
style="background-color: #f2f2f2; opacity: 0.7; pointer-events: none;">
</div>
<label for="practica">Práctica</label>
<div class="mb-3">
<input type="text" class="form-control form-control-user" id="practica"
name="practica" readonly value="<%= practica %>"
style="background-color: #f2f2f2; opacity: 0.7; pointer-events: none;">
</div>
<label for="observacion">Observaciones </label>
<div class="mb-3">
<textarea class="form-control form-control-user" name="observacion" id="observacion"
placeholder="Observacion General " rows="5" cols="30"></textarea>
</div>
<label for="monto">Monto (*)</label>
<div class="mb-3">
<input class="form-control form-control-user" name="monto" type="number" id="monto"
placeholder="Monto que abono" min="0.01" step="0.01" required>
</div>
<div class="mb-3">
<% if (beneficios.length > 0) { %>
<select id="monto_b" class="form-select" name="monto_b" required="">
<option value="" disabled selected>Monto Beneficio (*)</option>
<option value="ninguno">Ninguno</option>
<% beneficios.forEach(function(beneficio) { %>
<% if (!beneficio.usado) { %>
<option value="<%= beneficio.monto_beneficio %>">
<%= beneficio.monto_beneficio %>
</option>
<% } %>
<% }); %>
</select>
<% } else { %>
<select id="monto_b" class="form-select" name="monto_b" required="" style="background-color: #f2f2f2; opacity: 0.7; pointer-events: none;">
<option value="ninguno" selected>Ninguno</option>
</select>
<% } %>
</div>
<div class="text-center mb-2" style="font-size: smaller;">Los campos con (*) son obligatorios</div>
<div id="mensaje"></div>
</div>
<button id="registrar" class="btn btn-primary d-block btn-user w-100" name="registrar" type="submit">Registrar</button>
</form>
</div>
<div class="col-md-10 col-lg-6 col-xl-6 d-flex align-items-center order-1 order-lg-2 justify-content-center">
<img src="/img/perritu.png" width="300px">
</div>
</div>
<style>
@media only screen and (max-width: 900px) {
img {
display: none;
}
div {
display: block;
}
}
</style>
</div>
<hr>
<div class="text-center"><a class="small" href="/turnos_dia">Volver</a></div>
</div>
</div>
</div>
</div>
<br>
<!-- Modal de confirmación monto < monto_b-->
<div class="modal fade" id="modalWarning" tabindex="-1" aria-labelledby="modalWarningLabel" aria-hidden="true" style="text-align: center;">
<div class="modal-dialog modal-dialog-centered" >
<div class="modal-content">
<div class="modal-header" style="text-align: center;">
<h5 class="modal-title text-center" id="modalWarningLabel">Advertencia</h5>
<button type="button"class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body " style="text-align: center;">
<p>¿El monto beneficio es mayor al de consulta, seguro quiere utilizarlo?</p>
<p><strong>El cliente va a perder lo que resta del beneficio</strong></p>
<p>Monto consulta: <span id="montoConsulta"></span></p>
<p>Monto beneficio: <span id="montoBeneficio"></span></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button type="button" class="btn btn-primary" id="btnConfirmar" onclick="confirmarUtilizacion()">Confirmar</button>
</div>
</div>
</div>
</div>
<!-- Modal de confirmación de envio-->
<div class="modal fade" id="modalConfirmacion" tabindex="-1" aria-labelledby="modalConfirmacionLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="text-align: center;">
<h5 class="modal-title text-center" id="modalConfirmacionLabel">Confirmacion de registro</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="text-align: center;">
<p>¿Desea registrar esta visita?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button type="button" class="btn btn-primary" id="btnConfirmar" onclick="confirmarUtilizacion()">Confirmar</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> -->
<script>
const btnEnviar = document.getElementById("registrar");
function montosVacios() {
const monto = document.getElementById('monto').value;
const monto_b = document.getElementById('monto_b').value;
// Verificar si los campos están vacíos
if (!monto || !monto_b) {
const mensajeElemento = document.getElementById('mensaje');
mensajeElemento.style.color = 'red';
mensajeElemento.textContent = 'Por favor complete todos los campos solicitados.';
setTimeout(function() {
mensajeElemento.textContent = '';
}, 5000);
return true;
}
// Verificar si el monto es menor o igual a 0
if (parseFloat(monto) <= 0) {
const mensajeElemento = document.getElementById('mensaje');
mensajeElemento.style.color = 'red';
mensajeElemento.textContent = 'El monto de consulta debe ser mayor a 0.';
setTimeout(function() {
mensajeElemento.textContent = '';
}, 5000);
return true;
}
if (!/^\d+(\.\d{1,2})?$/.test(monto)) {
const mensajeElemento = document.getElementById('mensaje');
mensajeElemento.style.color = 'red';
mensajeElemento.textContent = 'El monto de consulta solo admite 2 decimales';
setTimeout(function() {
mensajeElemento.textContent = '';
}, 5000);
return true;
}
return false;
}
function compararMontos() {
let monto = document.getElementById('monto').value;
let monto_b_select = document.getElementById('monto_b');
let monto_b = monto_b_select.options[monto_b_select.selectedIndex].value;
// Convertir los valores a números
monto = Number(monto);
monto_b = parseFloat(monto_b);
console.log("monto:", monto);
console.log("monto_b:", monto_b);
// Comparar los montos
if (monto_b > monto) {
console.log("El monto beneficio es mayor que monto");
// Obtener los elementos <span> para los montos
const montoConsultaSpan = document.getElementById('montoConsulta');
const montoBeneficioSpan = document.getElementById('montoBeneficio');
// Asignar los valores de los montos a los <span>
montoConsultaSpan.textContent = monto;
montoBeneficioSpan.textContent = monto_b;
// Mostrar el modal de warning
$('#modalWarning').modal('show');
return true; // Monto menor que el monto beneficio
}
return false; // Monto válido, retorna false
}
function confirmarUtilizacion() {
// Cerrar el modal
$('#modalWarning').modal('hide');
$('#modalConfirmacion').modal('hide');
// Enviar el formulario
document.getElementById('miForm').submit();
}
function confirmarRegistro(){
$('#modalConfirmacion').modal('show');
}
btnEnviar.onclick = function (event) {
// Si los montos están vacíos o se debe mostrar el modal de warning, se cancela el envío del formulario
event.preventDefault();
if (montosVacios() || compararMontos() ) {
return false;
}else {
confirmarRegistro();
}
};
</script>
<%- include ('sweet-alert') %>
</body>
</html>