uo
This commit is contained in:
@@ -147,13 +147,41 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
|
||||
|
||||
/* ── Consentimientos ── */
|
||||
.consent-item {
|
||||
display: flex; align-items: center; gap: .6rem;
|
||||
padding: .4rem .6rem; border-radius: 8px;
|
||||
font-size: .85rem; margin-bottom: .3rem;
|
||||
display: flex; align-items: center; gap: .5rem;
|
||||
padding: .5rem .7rem; border-radius: 10px;
|
||||
font-size: .84rem; margin-bottom: .4rem;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.consent-item.firmado { background: #f0fdf4; color: #166534; }
|
||||
.consent-item.pendiente{ background: #fffbeb; color: #92400e; }
|
||||
.consent-item.enviado { background: #eff6ff; color: #1e40af; }
|
||||
.consent-item.firmado { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
|
||||
.consent-item.pendiente { background: #fffbeb; color: #92400e; border-color: #fde68a; }
|
||||
.consent-item.enviado { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
|
||||
.consent-item.visto { background: #faf5ff; color: #6b21a8; border-color: #ddd6fe; }
|
||||
.consent-item.rechazado { background: #f8fafc; color: #64748b; border-color: #e2e8f0; }
|
||||
.consent-item .c-nom { flex: 1; font-weight: 500; }
|
||||
.consent-item .c-badge { font-size: .7rem; font-weight: 700; padding: 1px 8px;
|
||||
border-radius: 99px; border: 1px solid currentColor; opacity: .85; }
|
||||
.consent-acciones { display: flex; gap: .3rem; flex-shrink: 0; }
|
||||
.consent-acciones .btn { font-size: .72rem; padding: 2px 8px; border-radius: 7px; }
|
||||
|
||||
/* ── Modal firma presencial ── */
|
||||
.modal-firma-backdrop {
|
||||
display: none; position: fixed; inset: 0;
|
||||
background: rgba(15,23,42,.65); z-index: 1050;
|
||||
align-items: center; justify-content: center;
|
||||
}
|
||||
.modal-firma-backdrop.open { display: flex; }
|
||||
.modal-firma-box {
|
||||
background: #fff; border-radius: 16px;
|
||||
width: min(94vw, 860px); height: min(88vh, 720px);
|
||||
display: flex; flex-direction: column; overflow: hidden;
|
||||
box-shadow: 0 8px 40px rgba(0,0,0,.35);
|
||||
}
|
||||
.modal-firma-hdr {
|
||||
padding: 12px 18px; border-bottom: 1px solid #e2e8f0;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
font-size: .95rem; font-weight: 600; flex-shrink: 0;
|
||||
}
|
||||
.modal-firma-box iframe { flex: 1; border: 0; }
|
||||
|
||||
/* ── Barra de acciones ── */
|
||||
.ficha-acciones {
|
||||
@@ -344,12 +372,15 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
||||
|
||||
<!-- ── Sección 5: Consentimientos ── -->
|
||||
<div class="ficha-section" id="sec-consentimientos" style="display:none!important">
|
||||
<h6><i class="fas fa-file-signature me-1"></i>Consentimientos</h6>
|
||||
<div class="d-flex align-items-center justify-content-between mb-2">
|
||||
<h6 class="mb-0"><i class="fas fa-file-signature me-1"></i>Consentimientos informados</h6>
|
||||
<button class="btn btn-sm btn-outline-primary py-0 px-2"
|
||||
id="btn-reenviar-consent" onclick="enviarConsentimientosTodos()"
|
||||
title="Enviar todos por WhatsApp">
|
||||
<i class="fas fa-paper-plane me-1"></i>Enviar todos
|
||||
</button>
|
||||
</div>
|
||||
<div id="lista-consentimientos"></div>
|
||||
<button class="btn btn-outline-primary btn-sm mt-2"
|
||||
id="btn-reenviar-consent" onclick="enviarConsentimientos()">
|
||||
<i class="fas fa-paper-plane me-1"></i>Enviar / Reenviar por WhatsApp
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ── Acciones ── -->
|
||||
@@ -373,6 +404,19 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
||||
</div><!-- /rec-layout -->
|
||||
</main>
|
||||
|
||||
<!-- ══ Modal firma presencial ═════════════════════════════════ -->
|
||||
<div class="modal-firma-backdrop" id="modal-firma-rec">
|
||||
<div class="modal-firma-box">
|
||||
<div class="modal-firma-hdr">
|
||||
<span><i class="fas fa-signature me-2 text-primary"></i><span id="modal-firma-titulo-rec">Firmar consentimiento</span></span>
|
||||
<button class="btn btn-sm btn-outline-secondary" onclick="cerrarModalFirmaRec()">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<iframe id="firma-iframe-rec" src="" title="Formulario de consentimiento"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ── Estado ────────────────────────────────────────────────────
|
||||
let turnoActivo = null;
|
||||
@@ -650,26 +694,93 @@ async function guardarSolicitud() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Labels / iconos para estados ─────────────────────────────
|
||||
const CONSENT_META = {
|
||||
firmado : { cls:'firmado', ico:'fa-check-circle', lbl:'Firmado' },
|
||||
enviado : { cls:'enviado', ico:'fa-envelope', lbl:'Enviado' },
|
||||
visto : { cls:'visto', ico:'fa-eye', lbl:'Visto' },
|
||||
rechazado : { cls:'rechazado', ico:'fa-ban', lbl:'Rechazado' },
|
||||
pendiente : { cls:'pendiente', ico:'fa-clock', lbl:'Pendiente' },
|
||||
};
|
||||
|
||||
function renderConsentimientos(lista) {
|
||||
document.getElementById('lista-consentimientos').innerHTML = lista.map(c => {
|
||||
const cls = c.estado === 'firmado' ? 'firmado'
|
||||
: c.estado === 'enviado' ? 'enviado'
|
||||
: 'pendiente';
|
||||
const ico = c.estado === 'firmado' ? 'fa-check-circle'
|
||||
: c.estado === 'enviado' ? 'fa-envelope'
|
||||
: 'fa-clock';
|
||||
return `<div class="consent-item ${cls}">
|
||||
<i class="fas ${ico}"></i>
|
||||
<span class="flex-1">${escHtml(c.formulario_nombre || 'Consentimiento')}</span>
|
||||
<span class="badge">${escHtml(c.estado)}</span>
|
||||
const el = document.getElementById('lista-consentimientos');
|
||||
if (!lista.length) {
|
||||
el.innerHTML = '<div class="text-muted small"><i class="fas fa-check-circle text-success me-1"></i>Sin consentimientos requeridos</div>';
|
||||
return;
|
||||
}
|
||||
el.innerHTML = lista.map(c => {
|
||||
const m = CONSENT_META[c.estado] || CONSENT_META.pendiente;
|
||||
const ya = ['firmado','rechazado'].includes(c.estado);
|
||||
const token = escHtml(c.token || '');
|
||||
const nom = escHtml(c.formulario_nombre || 'Consentimiento');
|
||||
const nomJs = JSON.stringify(c.formulario_nombre || 'Consentimiento');
|
||||
|
||||
// Botón de firma (solo si no está firmado/rechazado)
|
||||
const btnFirmar = (!ya && c.token)
|
||||
? `<button class="btn btn-outline-primary" onclick="abrirFirmaPresencialRec('${token}', ${nomJs})"
|
||||
title="Firmar aquí en pantalla">
|
||||
<i class="fas fa-signature"></i> Firmar
|
||||
</button>` : '';
|
||||
|
||||
// Botón enviar/reenviar WhatsApp
|
||||
const btnWa = ya
|
||||
? (c.token ? `<button class="btn btn-outline-secondary" onclick="verFirmado('${token}')" title="Ver formulario firmado">
|
||||
<i class="fas fa-eye"></i> Ver
|
||||
</button>` : '')
|
||||
: `<button class="btn btn-outline-success" onclick="enviarConsentimientoUno(${c.turno_id || turnoActivo?.id})"
|
||||
title="Enviar enlace de firma por WhatsApp">
|
||||
<i class="fab fa-whatsapp"></i> WhatsApp
|
||||
</button>`;
|
||||
|
||||
return `<div class="consent-item ${m.cls}">
|
||||
<i class="fas ${m.ico}"></i>
|
||||
<span class="c-nom">${nom}</span>
|
||||
<span class="c-badge">${m.lbl}</span>
|
||||
<div class="consent-acciones">${btnFirmar}${btnWa}</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// ── Enviar consentimientos ────────────────────────────────────
|
||||
async function enviarConsentimientos() {
|
||||
// ── Firmar presencialmente (modal iframe) ─────────────────────
|
||||
function abrirFirmaPresencialRec(token, nombreForm) {
|
||||
const url = BASE_WA + 'ver_formulario_enviado.php?token=' + encodeURIComponent(token);
|
||||
document.getElementById('modal-firma-titulo-rec').textContent = 'Firmar: ' + nombreForm;
|
||||
document.getElementById('firma-iframe-rec').src = url;
|
||||
document.getElementById('modal-firma-rec').classList.add('open');
|
||||
}
|
||||
function cerrarModalFirmaRec() {
|
||||
document.getElementById('modal-firma-rec').classList.remove('open');
|
||||
document.getElementById('firma-iframe-rec').src = '';
|
||||
// Refrescar consentimientos al cerrar
|
||||
if (turnoActivo) refrescarConsentimientos(turnoActivo.id);
|
||||
}
|
||||
function verFirmado(token) {
|
||||
window.open(BASE_WA + 'ver_formulario_enviado.php?token=' + encodeURIComponent(token), '_blank');
|
||||
}
|
||||
// Cerrar modal al clic fuera
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('modal-firma-rec').addEventListener('click', function(e) {
|
||||
if (e.target === this) cerrarModalFirmaRec();
|
||||
});
|
||||
});
|
||||
|
||||
// ── Refrescar estado de consentimientos ───────────────────────
|
||||
async function refrescarConsentimientos(turnoId) {
|
||||
try {
|
||||
const res = await fetch(`${API}get_consentimientos.php?turno_id=${turnoId}`);
|
||||
const json = await res.json();
|
||||
if (json.ok) {
|
||||
consentimientos = json.consentimientos || [];
|
||||
renderConsentimientos(consentimientos);
|
||||
}
|
||||
} catch(_) {}
|
||||
}
|
||||
|
||||
// ── Enviar consentimientos (todos) ───────────────────────────
|
||||
async function enviarConsentimientosTodos() {
|
||||
if (!turnoActivo || !solicitudActiva) return;
|
||||
const btn = document.getElementById('btn-enviar-consent');
|
||||
const btn = document.getElementById('btn-reenviar-consent');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Enviando…';
|
||||
try {
|
||||
@@ -680,18 +791,39 @@ async function enviarConsentimientos() {
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.ok) { mostrarError(json.error); return; }
|
||||
|
||||
consentimientos = json.consentimientos ?? json.data?.consentimientos ?? consentimientos;
|
||||
consentimientos = json.consentimientos ?? consentimientos;
|
||||
renderConsentimientos(consentimientos);
|
||||
btn.innerHTML = '<i class="fas fa-check me-1"></i>Enviado';
|
||||
setTimeout(() => { btn.innerHTML = '<i class="fas fa-paper-plane me-1"></i>Enviar todos'; }, 3000);
|
||||
} catch (err) {
|
||||
mostrarError(err.message);
|
||||
btn.innerHTML = '<i class="fas fa-paper-plane me-1"></i>Enviar consentimientos';
|
||||
btn.innerHTML = '<i class="fas fa-paper-plane me-1"></i>Enviar todos';
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Enviar consentimiento individual ─────────────────────────
|
||||
async function enviarConsentimientoUno(turnoId) {
|
||||
if (!turnoId) return;
|
||||
try {
|
||||
const res = await fetch(API + 'send_consentimiento.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ turno_id: turnoId }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.ok) { mostrarError(json.error); return; }
|
||||
consentimientos = json.consentimientos ?? consentimientos;
|
||||
renderConsentimientos(consentimientos);
|
||||
} catch (err) {
|
||||
mostrarError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Enviar consentimientos (legacy — usado por btn-enviar-consent) ──
|
||||
async function enviarConsentimientos() { return enviarConsentimientosTodos(); }
|
||||
|
||||
// ── Pasar a lugar ─────────────────────────────────────────────
|
||||
async function pasarALugar() {
|
||||
if (!turnoActivo || !solicitudActiva) return;
|
||||
|
||||
Reference in New Issue
Block a user