<?php require_once __DIR__ . '/../includes/bootstrap.php'; require_login(); $id = (int)($_GET['id'] ?? 0); $sql = "SELECT pi.*, p.year, p.month, p.start_date, p.end_date, p.status AS period_status, e.full_name, e.document_number, e.hire_date, d.name AS department_name, po.name AS position_name, (SELECT COALESCE(SUM(sa.amount),0) FROM salary_advances sa WHERE sa.employee_id = e.id AND YEAR(sa.advance_date)=p.year AND MONTH(sa.advance_date)=p.month AND sa.status='Activo') advance_total FROM payroll_items pi JOIN payroll_periods p ON p.id = pi.period_id JOIN employees e ON e.id = pi.employee_id LEFT JOIN departments d ON d.id = e.department_id LEFT JOIN positions po ON po.id = e.position_id WHERE pi.id = ?"; $stmt = db()->prepare($sql); $stmt->execute([$id]); $item = $stmt->fetch(); if (!$item) { die('Recibo no encontrado.'); } ?>
<!doctype html><html lang="es"><head><meta charset="utf-8"><title>Recibo de salario</title><meta name="viewport" content="width=device-width, initial-scale=1"><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"><link href="<?= e(base_url('assets/css/app.css')) ?>" rel="stylesheet"></head><body><div class="container py-4 payslip"><div class="table-wrap"><div class="d-flex justify-content-between align-items-center no-print mb-3"><a href="<?= e(base_url('payroll/view.php?id=' . $item['period_id'])) ?>" class="btn btn-outline-secondary">Volver</a><button onclick="window.print()" class="btn btn-primary">Imprimir</button></div><div class="d-flex justify-content-between align-items-center mb-4"><div><img src="<?= e(public_logo_url()) ?>" alt="<?= e(company_name()) ?>" style="max-height:72px;"><div class="mt-2 fw-bold"><?= e(company_name()) ?></div><div class="text-muted small">Recibo de salario</div></div><div class="text-end"><div><strong>Período:</strong> <?= e(month_name_es($item['month'])) ?>/<?= e($item['year']) ?></div><div><strong>Estado:</strong> <?= e($item['period_status']) ?></div><div><strong>Desde:</strong> <?= e($item['start_date']) ?></div><div><strong>Hasta:</strong> <?= e($item['end_date']) ?></div></div></div><div class="row g-4"><div class="col-md-6"><div class="section-title">Datos del colaborador</div><div class="line"><span>Nombre</span><strong><?= e($item['full_name']) ?></strong></div><div class="line"><span>Cédula</span><strong><?= e($item['document_number']) ?></strong></div><div class="line"><span>Ingreso</span><strong><?= e($item['hire_date']) ?></strong></div><div class="line"><span>Departamento</span><strong><?= e($item['department_name'] ?: '-') ?></strong></div><div class="line"><span>Cargo</span><strong><?= e($item['position_name'] ?: '-') ?></strong></div></div><div class="col-md-6"><div class="section-title">Liquidación</div><div class="line"><span>Salario base</span><strong><?= money_gs($item['base_salary']) ?></strong></div><div class="line"><span>Adelantos del mes</span><strong><?= money_gs($item['advance_total']) ?></strong></div><div class="line"><span>Extras</span><strong><?= money_gs($item['extras']) ?></strong></div><div class="line"><span>Descuentos aplicados</span><strong><?= money_gs($item['discounts']) ?></strong></div><div class="line"><span>Neto a cobrar</span><strong><?= money_gs($item['net_pay']) ?></strong></div></div></div><div class="mt-4 row"><div class="col-md-6"><div class="section-title">Observación</div><p class="text-muted mb-0">El descuento por adelantos se consolida según los movimientos activos del mes correspondiente.</p></div><div class="col-md-6 text-end pt-4"><div class="mt-5">____________________________________</div><div class="small text-muted">Firma del colaborador</div></div></div></div></div></body></html>
