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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
057439e140
commit
1a08d9dba7
@@ -41,13 +41,17 @@ $diagPpal = !empty($datos['diag_ppal']) ? trim((string)$datos['diag_ppa
|
|||||||
$itemsPrecio = isset($datos['items_precio']) && is_array($datos['items_precio'])
|
$itemsPrecio = isset($datos['items_precio']) && is_array($datos['items_precio'])
|
||||||
? json_encode($datos['items_precio']) : null;
|
? json_encode($datos['items_precio']) : null;
|
||||||
$pagosDetalle = null;
|
$pagosDetalle = null;
|
||||||
|
$combRefs = [];
|
||||||
if ($metodoPago === 'combinado' && isset($datos['pagos_detalle']) && is_array($datos['pagos_detalle'])) {
|
if ($metodoPago === 'combinado' && isset($datos['pagos_detalle']) && is_array($datos['pagos_detalle'])) {
|
||||||
$pd = $datos['pagos_detalle'];
|
$pd = $datos['pagos_detalle'];
|
||||||
$pagosDetalle = json_encode([
|
$pagosDetalle = json_encode([
|
||||||
'efectivo' => max(0, (float)($pd['efectivo'] ?? 0)),
|
'efectivo' => max(0, (float)($pd['efectivo'] ?? 0)),
|
||||||
'transferencia' => max(0, (float)($pd['transferencia'] ?? 0)),
|
'transferencia' => max(0, (float)($pd['transferencia'] ?? 0)),
|
||||||
'tarjeta' => max(0, (float)($pd['tarjeta'] ?? 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;
|
if ($numOrden === '') $numOrden = null;
|
||||||
|
|
||||||
@@ -321,16 +325,17 @@ try {
|
|||||||
$pagoId = (int)$pdo->lastInsertId();
|
$pagoId = (int)$pdo->lastInsertId();
|
||||||
|
|
||||||
$stD = $pdo->prepare(
|
$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) {
|
if ($metodoPago === 'combinado' && $pagosDetalle) {
|
||||||
foreach (json_decode($pagosDetalle, true) ?? [] as $tipo => $val) {
|
foreach (json_decode($pagosDetalle, true) ?? [] as $tipo => $val) {
|
||||||
if ((float)$val > 0) {
|
if ((float)$val > 0) {
|
||||||
$stD->execute([$pagoId, $tipo, (float)$val]);
|
$ref = $combRefs[$tipo] ?? null;
|
||||||
|
$stD->execute([$pagoId, $tipo, (float)$val, $ref]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$stD->execute([$pagoId, $metodoPago, $valorTotal]);
|
$stD->execute([$pagoId, $metodoPago, $valorTotal, $numeroRecibo]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $eRec) {
|
} catch (\Throwable $eRec) {
|
||||||
@@ -386,15 +391,11 @@ try {
|
|||||||
];
|
];
|
||||||
$datos = array_map(fn($cod) => ['cod_examen' => $cod] + $meta, $codRips);
|
$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(
|
$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]);
|
)->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) {
|
} catch (\Throwable $eRips) {
|
||||||
error_log('[create_solicitud] rips_examenes_pendientes: ' . $eRips->getMessage());
|
error_log('[create_solicitud] rips_examenes_pendientes: ' . $eRips->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user