This commit is contained in:
Lizandro Guarnizo
2026-06-13 13:19:02 -05:00
parent 0e51165108
commit f34d19b3df
4 changed files with 43 additions and 4 deletions
+1 -2
View File
@@ -183,10 +183,9 @@ function siguienteNumeroPorPrioridad(int $sesionId, int $prioridadId): int
'SELECT COALESCE(MAX(numero), 0) + 1 AS siguiente
FROM turnero_turnos
WHERE sesion_id = ?
AND prioridad_id = ?
FOR UPDATE'
);
$stmt->execute([$sesionId, $prioridadId]);
$stmt->execute([$sesionId]);
return (int) $stmt->fetchColumn();
}
+14
View File
@@ -105,6 +105,20 @@ try {
// ── Enviar notificación WhatsApp con la plantilla configurada ──
if ($pacienteTel) {
try {
$stmtCfg = $pdo->prepare(
"SELECT clave, valor FROM lab_config WHERE clave IN ('turnero_wa_template','turnero_wa_lang','turnero_wa_kiosko_enabled')"
);
$stmtCfg->execute();
$cfgWA = $stmtCfg->fetchAll(PDO::FETCH_KEY_PAIR);
$waKioskoEnabled = ($cfgWA['turnero_wa_kiosko_enabled'] ?? '0') === '1';
} catch (\Throwable $e) {
$waKioskoEnabled = true;
}
}
if ($pacienteTel && $waKioskoEnabled) {
try {
$cfgWA = [];
$stmtCfg = $pdo->prepare(
"SELECT clave, valor FROM lab_config WHERE clave IN ('turnero_wa_template','turnero_wa_lang')"
);
+4
View File
@@ -82,6 +82,8 @@ if ($accion === 'reabrir') {
if ($accion === 'config_wa') {
$template = trim($input['template'] ?? '');
$lang = trim($input['lang'] ?? 'es_CO');
$waKiosko = (int)($input['wa_kiosko'] ?? 0);
$waConsent = (int)($input['wa_consent'] ?? 0);
if ($template === '') jsonError('El nombre de plantilla es requerido');
if (!preg_match('/^[a-z0-9_]{1,64}$/i', $template)) {
@@ -98,6 +100,8 @@ if ($accion === 'config_wa') {
);
$upsert->execute(['turnero_wa_template', $template]);
$upsert->execute(['turnero_wa_lang', $lang]);
$upsert->execute(['turnero_wa_kiosko_enabled', (string)$waKiosko]);
$upsert->execute(['turnero_wa_consent_enabled', (string)$waConsent]);
jsonOk([], 'Configuración WhatsApp guardada');
}
+24 -2
View File
@@ -713,7 +713,27 @@ $tab = $_GET['tab'] ?? 'lugares';
<!-- Config WhatsApp turnero -->
<div>
<p class="section-title"><i class="fab fa-whatsapp me-1" style="color:#25d366"></i>Plantilla de consentimiento WhatsApp</p>
<p class="section-title"><i class="fab fa-whatsapp me-1" style="color:#25d366"></i>Notificaciones WhatsApp</p>
<div class="mb-3 p-3" style="background:#fffbeb;border:1px solid #fde68a;border-radius:10px">
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" id="chk-wa-kiosko"
<?= !empty($cfg['turnero_wa_kiosko_enabled']) ? 'checked' : '' ?>>
<label class="form-check-label" for="chk-wa-kiosko">
<strong>Enviar notificación de turno desde el kiosko</strong>
<small class="d-block text-muted">Cuando un paciente toma turno en el kiosko, se le envía un WhatsApp con la plantilla configurada.</small>
</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="chk-wa-consent"
<?= !empty($cfg['turnero_wa_consent_enabled']) ? 'checked' : '' ?>>
<label class="form-check-label" for="chk-wa-consent">
<strong>Enviar consentimientos por WhatsApp</strong>
<small class="d-block text-muted">Permite enviar consentimientos informados desde recepción por WhatsApp.</small>
</label>
</div>
</div>
<div class="row g-2">
<div class="col-md-6">
<label class="form-label small fw-semibold">Nombre de plantilla Meta aprobada</label>
@@ -1126,12 +1146,14 @@ async function borrarTvVideo() {
async function guardarWhatsApp() {
const template = document.getElementById('wa-template')?.value.trim();
const lang = document.getElementById('wa-lang')?.value.trim();
const waKiosko = document.getElementById('chk-wa-kiosko')?.checked ? 1 : 0;
const waConsent = document.getElementById('chk-wa-consent')?.checked ? 1 : 0;
if (!template) { toast('El nombre de plantilla es requerido', 'error'); return; }
try {
const res = await fetch(API + 'sesion_turno.php', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ accion: 'config_wa', template, lang })
body: JSON.stringify({ accion: 'config_wa', template, lang, wa_kiosko: waKiosko, wa_consent: waConsent })
});
const json = await res.json();
if (!json.ok) { toast(json.error || 'Error', 'error'); return; }