From 1a08d9dba79abe7637cb00b9f8bc03675a72be7a Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:18:11 -0500 Subject: [PATCH] fix(pagos): agregar bono al ENUM, guardar refs en lab_pagos_det, consumir cache rips al crear solicitud Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/api/create_solicitud.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/turnero/api/create_solicitud.php b/modules/turnero/api/create_solicitud.php index c5daddd..30e3ef9 100644 --- a/modules/turnero/api/create_solicitud.php +++ b/modules/turnero/api/create_solicitud.php @@ -41,13 +41,17 @@ $diagPpal = !empty($datos['diag_ppal']) ? trim((string)$datos['diag_ppa $itemsPrecio = isset($datos['items_precio']) && is_array($datos['items_precio']) ? json_encode($datos['items_precio']) : null; $pagosDetalle = null; +$combRefs = []; if ($metodoPago === 'combinado' && isset($datos['pagos_detalle']) && is_array($datos['pagos_detalle'])) { $pd = $datos['pagos_detalle']; $pagosDetalle = json_encode([ 'efectivo' => max(0, (float)($pd['efectivo'] ?? 0)), 'transferencia' => max(0, (float)($pd['transferencia'] ?? 0)), 'tarjeta' => max(0, (float)($pd['tarjeta'] ?? 0)), + 'bono' => max(0, (float)($pd['bono'] ?? 0)), ]); + if (!empty($pd['ref_transferencia'])) $combRefs['transferencia'] = trim((string)$pd['ref_transferencia']); + if (!empty($pd['ref_tarjeta'])) $combRefs['tarjeta'] = trim((string)$pd['ref_tarjeta']); } if ($numOrden === '') $numOrden = null; @@ -321,16 +325,17 @@ try { $pagoId = (int)$pdo->lastInsertId(); $stD = $pdo->prepare( - "INSERT INTO lab_pagos_det (pago_id, tipo_pago, valor) VALUES (?, ?, ?)" + "INSERT INTO lab_pagos_det (pago_id, tipo_pago, valor, num_doc) VALUES (?, ?, ?, ?)" ); if ($metodoPago === 'combinado' && $pagosDetalle) { foreach (json_decode($pagosDetalle, true) ?? [] as $tipo => $val) { if ((float)$val > 0) { - $stD->execute([$pagoId, $tipo, (float)$val]); + $ref = $combRefs[$tipo] ?? null; + $stD->execute([$pagoId, $tipo, (float)$val, $ref]); } } } else { - $stD->execute([$pagoId, $metodoPago, $valorTotal]); + $stD->execute([$pagoId, $metodoPago, $valorTotal, $numeroRecibo]); } } } catch (\Throwable $eRec) { @@ -386,15 +391,11 @@ try { ]; $datos = array_map(fn($cod) => ['cod_examen' => $cod] + $meta, $codRips); + // Consumir el cache: solo eliminar, no reinsertar, para que no recargue en una segunda visita $pdo->prepare( - "DELETE FROM rips_examenes_pendientes WHERE numero_documento = ? AND DATE(created_at) = CURDATE()" + "DELETE FROM rips_examenes_pendientes WHERE numero_documento = ?" )->execute([$numDoc]); - $pdo->prepare( - "INSERT INTO rips_examenes_pendientes (numero_documento, datos, recepcion_id, hora_recepcion) - VALUES (?, ?, ?, CURTIME())" - )->execute([$numDoc, json_encode($datos, JSON_UNESCAPED_UNICODE), $recepcionId]); - } catch (\Throwable $eRips) { error_log('[create_solicitud] rips_examenes_pendientes: ' . $eRips->getMessage()); }