-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcliente.ejs
141 lines (134 loc) · 7 KB
/
cliente.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
<!DOCTYPE html>
<html lang="es">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css" rel="stylesheet">
<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! | Perfil cliente'}); %>
</head>
<body id="body">
<div class="container h-100" style="margin-top: 20px;">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-lg-12 col-xl-10">
<div class="card text-black" style="border-radius: 25px;">
<div class="card-body p-md-4">
<div class="row justify-content-center">
<p class="text-center h1 fw-bold mb-4 mx-1 mx-md-4 mt-3"><i class="bi bi-person-fill"></i> Detalle de cliente</p>
<div class="alert alert-info" role="alert">Se esta visualizando a: <strong><%= usuario.name %></strong></div>
<div>Correo: <%= usuario.mail %></div>
<div>Nombre completo: <%= usuario.name %></div>
<div>Telefono: <%= usuario.tel %></div>
<div>DNI: <%= usuario.DNI %></div>
<div>Rol: <%= usuario.rol %></div>
<div style="margin-top: 10px; margin-bottom: 20px;">
<a class="btn btn-outline-primary float-left" href="/historial/<%= usuario.id %>"><i class="bi bi-house-add"></i> Historial de visitas</a>
<a class="btn btn-outline-primary float-right" href="/ver_cliente/cupones/<%= usuario.id %>"><i class="bi bi-piggy-bank"></i> Ver beneficios actuales</a>
</div>
<div class="text-center">Mascotas</div>
<div>
<table class="table" id="tabla1">
<thead>
<tr>
<th scope="col">Nombre</th>
<th scope="col">Raza</th>
<th scope="col">Edad</th>
<th scope="col">Acciones</th>
</tr>
</thead>
<tbody>
<% mascotas.forEach(mascota => { %>
<tr class="paginate">
<td><%= mascota.nombre %></td>
<td><%= mascota.raza %></td>
<% var meses = calcularEdadMasco(mascota.fecha_nacimiento); %>
<td>
<% if (meses < 12) { %>
<% if (meses === 1) { %>
<%= meses %> (mes)
<% } else { %>
<%= meses %> (meses)
<% } %>
<% } else { %>
<% if (Math.floor(meses / 12) === 1) { %>
<%= Math.floor(meses / 12) %> (año)
<% } else { %>
<%= Math.floor(meses / 12) %> (años)
<% } %>
<% } %>
</td>
<td>
<button type="button" onclick="location.href='<%= `/ver_mascota/${mascota.id}` %>'" class="btn btn-outline-primary d-inline mr-2">
<i class="bi bi-eye-fill"></i> Ver
</button>
<% if (session.usuario.rol === 'admin') { %>
<form method="POST" action="/eliminar_mascota/<%= mascota.id %>" class="d-inline" id="eliminarForm-<%= mascota.id %>">
<button type="button" class="btn btn-outline-danger" onclick="confirmarEliminar(<%= mascota.id %>)">
<i class="bi bi-trash3-fill"></i> Eliminar
</button>
</form>
<% } %>
</td>
<% }); %>
</tbody>
</table>
</div>
<div class="text-center"><a class="small" href="#" onclick="history.back(); return false;">Volver</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
<script>
function confirmarEliminar(mascotaId) {
Swal.fire({
title: '¿Estás seguro?',
text: 'Al eliminar ya no se podrán ver los turnos relacionados con esa mascota, aunque figurara en los reportes',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonText: 'Cancelar',
confirmButtonText: 'Eliminar',
}).then((result) => {
if (result.isConfirmed) {
// Si el usuario confirma, envía el formulario manualmente
const formId = `eliminarForm-${mascotaId}`;
const formElement = document.getElementById(formId);
formElement.submit();
}
});
}
</script>
<script>
$(document).ready(function () {
const tableRows = $('#tabla1 tbody tr').length;
const pagingEnable = tableRows > 50;
$('#tabla1').DataTable({
paging: pagingEnable,
ordering: false,
info: false,
lengthMenu: [
[5, 15, 50, -1],
[5, 15, 50, 'Todos'],
],
pageLength: 50, // Establecer como la opción por defecto
searching: false, // deshabilita la función de búsqueda
language: {
paginate: { previous: 'Anterior', next: 'Siguiente', },
zeroRecords: 'La persona no posee mascotas',
info: 'Mostrando pagina _PAGE_ de _PAGES_',
infoEmpty: 'La persona no posee mascotas',
lengthMenu: 'Mostrar _MENU_ entradas'
},
});
});
</script>
</body>
</html>