diff --git a/migrations/20260703_pago_combinado.sql b/migrations/20260703_pago_combinado.sql new file mode 100644 index 0000000..e2e6566 --- /dev/null +++ b/migrations/20260703_pago_combinado.sql @@ -0,0 +1,7 @@ +ALTER TABLE turnero_solicitudes + MODIFY COLUMN metodo_pago ENUM( + 'efectivo','transferencia','tarjeta','eps','cortesia','combinado' + ) DEFAULT NULL, + ADD COLUMN pagos_detalle JSON DEFAULT NULL + COMMENT 'Desglose de pago combinado {efectivo, transferencia, tarjeta}' + AFTER metodo_pago; diff --git a/modules/turnero/api/create_solicitud.php b/modules/turnero/api/create_solicitud.php index 3bba1dd..906414b 100644 --- a/modules/turnero/api/create_solicitud.php +++ b/modules/turnero/api/create_solicitud.php @@ -27,10 +27,19 @@ $examIds = isset($datos['exam_tipo_ids']) && is_array($datos['exam_tipo_ids' ? array_filter(array_map('intval', $datos['exam_tipo_ids'])) : []; $total = isset($datos['total_cobrado']) && $datos['total_cobrado'] !== null ? (float) $datos['total_cobrado'] : null; -$metodoPago = isset($datos['metodo_pago']) ? trim((string) $datos['metodo_pago']) : null; -$obs = isset($datos['observaciones']) ? trim((string) $datos['observaciones']) : null; -$numOrden = isset($datos['numero_orden']) ? trim((string) $datos['numero_orden']) : null; -$embarazada = !empty($datos['embarazada']) ? 1 : 0; +$metodoPago = isset($datos['metodo_pago']) ? trim((string) $datos['metodo_pago']) : null; +$obs = isset($datos['observaciones']) ? trim((string) $datos['observaciones']) : null; +$numOrden = isset($datos['numero_orden']) ? trim((string) $datos['numero_orden']) : null; +$embarazada = !empty($datos['embarazada']) ? 1 : 0; +$pagosDetalle = null; +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)), + ]); +} if ($numOrden === '') $numOrden = null; // ── Validaciones ────────────────────────────────────────────── @@ -39,7 +48,7 @@ if ($pacienteId <= 0) jsonError('paciente_id inválido.'); if ($lugarId <= 0) jsonError('lugar_id inválido.'); if (empty($examIds)) jsonError('Debe seleccionar al menos un examen.'); -$metodosValidos = ['efectivo', 'transferencia', 'tarjeta', 'eps', 'cortesia', '']; +$metodosValidos = ['efectivo', 'transferencia', 'tarjeta', 'eps', 'cortesia', 'combinado', '']; if ($metodoPago && !in_array($metodoPago, $metodosValidos, true)) { jsonError('metodo_pago inválido.'); } @@ -104,12 +113,12 @@ try { $stmt = $pdo->prepare( "INSERT INTO turnero_solicitudes - (turno_id, paciente_id, lugar_id, numero_orden, total_cobrado, metodo_pago, observaciones, embarazada, creado_por) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" + (turno_id, paciente_id, lugar_id, numero_orden, total_cobrado, metodo_pago, pagos_detalle, observaciones, embarazada, creado_por) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); $stmt->execute([ $turnoId, $pacienteId, $lugarId, $numOrden, - $total, $metodoPago ?: null, $obs ?: null, $embarazada, adminId(), + $total, $metodoPago ?: null, $pagosDetalle, $obs ?: null, $embarazada, adminId(), ]); $solicitudId = (int) $pdo->lastInsertId(); diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index 53807ee..3c0b026 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -501,16 +501,32 @@ document.addEventListener('DOMContentLoaded', function() { placeholder="Total $" step="100" min="0">
- +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1120,6 +1136,27 @@ function seleccionarPaciente(pac) { _historialPacienteId = pac.id; } +function togglePagoCombinado() { + const combinado = document.getElementById('sel-pago').value === 'combinado'; + document.getElementById('panel-combinado').classList.toggle('d-none', !combinado); + const inp = document.getElementById('inp-total'); + inp.readOnly = combinado; + inp.style.background = combinado ? '#e9ecef' : ''; + if (combinado) sumarCombinado(); +} +function sumarCombinado() { + const v = id => parseFloat(document.getElementById(id).value) || 0; + const total = v('comb-efectivo') + v('comb-transferencia') + v('comb-tarjeta'); + document.getElementById('inp-total').value = total || ''; +} +function resetPagoCombinado() { + ['comb-efectivo','comb-transferencia','comb-tarjeta'].forEach(id => document.getElementById(id).value = ''); + document.getElementById('panel-combinado').classList.add('d-none'); + const inp = document.getElementById('inp-total'); + inp.readOnly = false; + inp.style.background = ''; +} + function desvincularPaciente() { pacienteActivo = null; _historialPacienteId = null; @@ -1264,8 +1301,13 @@ async function guardarSolicitud() { lugar_id: lugarId, exam_tipo_ids: examIds, numero_orden: document.getElementById('inp-consecutivo').value.trim() || null, - total_cobrado: parseFloat(document.getElementById('inp-total').value) || null, - metodo_pago: document.getElementById('sel-pago').value || null, + total_cobrado: parseFloat(document.getElementById('inp-total').value) || null, + metodo_pago: document.getElementById('sel-pago').value || null, + pagos_detalle: document.getElementById('sel-pago').value === 'combinado' ? { + efectivo: parseFloat(document.getElementById('comb-efectivo').value) || 0, + transferencia: parseFloat(document.getElementById('comb-transferencia').value) || 0, + tarjeta: parseFloat(document.getElementById('comb-tarjeta').value) || 0, + } : null, observaciones: document.getElementById('inp-obs').value.trim() || null, embarazada: document.getElementById('chk-embarazada').checked ? 1 : 0, }), @@ -1612,6 +1654,10 @@ async function soltarTurno() { // ── Helpers ─────────────────────────────────────────────────── function resetCheckboxes() { document.querySelectorAll('.exam-chk').forEach(c => c.checked = false); + document.getElementById('sel-pago').value = ''; + document.getElementById('inp-total').value = ''; + document.getElementById('inp-obs').value = ''; + resetPagoCombinado(); } function toggleTodosExamenes(val) { document.querySelectorAll('.exam-chk').forEach(c => c.checked = val);