diff --git a/modules/turnero/api/_helpers.php b/modules/turnero/api/_helpers.php index 4c06d88..d509852 100644 --- a/modules/turnero/api/_helpers.php +++ b/modules/turnero/api/_helpers.php @@ -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(); } diff --git a/modules/turnero/api/create_turno.php b/modules/turnero/api/create_turno.php index 5ca8526..4a582f5 100644 --- a/modules/turnero/api/create_turno.php +++ b/modules/turnero/api/create_turno.php @@ -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')" ); diff --git a/modules/turnero/api/sesion_turno.php b/modules/turnero/api/sesion_turno.php index 688a6b4..71a1319 100644 --- a/modules/turnero/api/sesion_turno.php +++ b/modules/turnero/api/sesion_turno.php @@ -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'); } diff --git a/modules/turnero/views/configuracion.php b/modules/turnero/views/configuracion.php index 0b3ae1f..b87fbb1 100644 --- a/modules/turnero/views/configuracion.php +++ b/modules/turnero/views/configuracion.php @@ -713,7 +713,27 @@ $tab = $_GET['tab'] ?? 'lugares';
Plantilla de consentimiento WhatsApp
+Notificaciones WhatsApp
+ +