<?php /* payroll/payslip.php */ include APP_PATH.'/views/partials/report_header.php'; ?>
<div class="no-print d-flex justify-content-between align-items-center mb-3">
  <h5 class="fw-bold mb-0"><i class="bi bi-file-earmark-person me-2 text-primary"></i>Pay Slip</h5>
  <div class="d-flex gap-2">
    <a href="<?=APP_URL?>/payroll/process/<?=$record['period_id']?>" class="btn btn-sm btn-outline-secondary">← Period</a>
    <button onclick="window.print()" class="btn btn-sm btn-primary"><i class="bi bi-printer me-1"></i>Print</button>
  </div>
</div>
<div class="card" style="max-width:700px;margin:0 auto">
  <!-- Header -->
  <div style="background:linear-gradient(135deg,#0f2557,#1e40af);color:#fff;padding:20px 24px;border-radius:10px 10px 0 0">
    <div class="d-flex justify-content-between align-items-start">
      <div>
        <div style="font-size:1.2rem;font-weight:800"><?=e(setting('shop_name','MJPOS'))?></div>
        <div style="opacity:.8;font-size:.8rem;margin-top:4px"><?=e(setting('shop_address',''))?></div>
        <div style="opacity:.8;font-size:.8rem"><?=e(setting('shop_phone',''))?></div>
      </div>
      <div class="text-end">
        <div style="font-size:1.1rem;font-weight:700;text-transform:uppercase;letter-spacing:.1em">PAY SLIP</div>
        <div style="opacity:.8;font-size:.8rem;margin-top:4px"><?=e($record['period_name'])?></div>
        <div style="opacity:.7;font-size:.75rem"><?=fDate($record['start_date'])?> – <?=fDate($record['end_date'])?></div>
      </div>
    </div>
  </div>
  <div class="card-body">
    <!-- Employee info -->
    <div class="row g-3 mb-3 pb-3 border-bottom">
      <div class="col-6">
        <div class="text-muted small">Employee Name</div>
        <div class="fw-bold"><?=e($record['full_name'])?></div>
        <div class="text-muted small mt-1">Employee Code: <strong><?=e($record['emp_code'])?></strong></div>
      </div>
      <div class="col-3">
        <div class="text-muted small">Designation</div>
        <div class="fw-semibold small"><?=e($record['designation']??'—')?></div>
        <div class="text-muted small mt-1">Dept: <?=e($record['department']??'—')?></div>
      </div>
      <div class="col-3">
        <div class="text-muted small">Branch</div>
        <div class="fw-semibold small"><?=e($record['branch_name']??'Main')?></div>
        <div class="text-muted small mt-1">Days: <?=$record['present_days']?>/<?=$record['working_days']?></div>
      </div>
    </div>

    <!-- Earnings & Deductions -->
    <div class="row g-3">
      <div class="col-6">
        <div class="fw-bold small mb-2 text-success">
          <i class="bi bi-plus-circle me-1"></i>EARNINGS
        </div>
        <table class="table table-sm table-borderless mb-0">
          <tr><td class="text-muted small ps-0">Basic Salary</td><td class="text-end fw-semibold"><?=currency($record['basic_salary'])?></td></tr>
          <?php foreach($components as $c): if($c['type']!=='allowance') continue;?>
          <tr><td class="text-muted small ps-0"><?=e($c['name'])?></td><td class="text-end text-success"><?=currency($c['amount'])?></td></tr>
          <?php endforeach;?>
          <?php if($record['overtime_amount']>0):?>
          <tr><td class="text-muted small ps-0">Overtime (<?=$record['overtime_hours']?>h)</td><td class="text-end text-success"><?=currency($record['overtime_amount'])?></td></tr>
          <?php endif;?>
          <tr style="border-top:2px solid #e2e8f0"><td class="fw-bold small ps-0">Gross Salary</td><td class="text-end fw-bold text-success"><?=currency($record['gross_salary'])?></td></tr>
        </table>
      </div>
      <div class="col-6">
        <div class="fw-bold small mb-2 text-danger">
          <i class="bi bi-dash-circle me-1"></i>DEDUCTIONS
        </div>
        <table class="table table-sm table-borderless mb-0">
          <?php foreach($components as $c): if($c['type']!=='deduction') continue;?>
          <tr><td class="text-muted small ps-0"><?=e($c['name'])?></td><td class="text-end text-danger">(<?=currency($c['amount'])?>)</td></tr>
          <?php endforeach;?>
          <?php if($record['epf_employee']>0):?>
          <tr><td class="text-muted small ps-0">EPF (Employee 8%)</td><td class="text-end text-danger">(<?=currency($record['epf_employee'])?>)</td></tr>
          <?php endif;?>
          <tr style="border-top:2px solid #e2e8f0"><td class="fw-bold small ps-0">Total Deductions</td><td class="text-end fw-bold text-danger">(<?=currency($record['total_deductions']+$record['epf_employee'])?>)</td></tr>
        </table>
      </div>
    </div>

    <!-- Net salary -->
    <div class="mt-3 p-3 rounded" style="background:linear-gradient(135deg,#0f2557,#1e40af);color:#fff">
      <div class="d-flex justify-content-between align-items-center">
        <span style="font-size:.9rem;font-weight:700;opacity:.9">NET SALARY PAYABLE</span>
        <span style="font-size:1.5rem;font-weight:900"><?=currency($record['net_salary'])?></span>
      </div>
    </div>

    <!-- EPF/ETF Summary -->
    <div class="row g-2 mt-2">
      <div class="col-4">
        <div class="text-center p-2 rounded" style="background:#f0fdf4;border:1px solid #bbf7d0">
          <div class="small text-muted">EPF Employee</div>
          <div class="fw-bold text-success"><?=currency($record['epf_employee'])?></div>
        </div>
      </div>
      <div class="col-4">
        <div class="text-center p-2 rounded" style="background:#eff6ff;border:1px solid #bfdbfe">
          <div class="small text-muted">EPF Employer</div>
          <div class="fw-bold text-primary"><?=currency($record['epf_employer'])?></div>
        </div>
      </div>
      <div class="col-4">
        <div class="text-center p-2 rounded" style="background:#fefce8;border:1px solid #fde68a">
          <div class="small text-muted">ETF Employer</div>
          <div class="fw-bold text-warning"><?=currency($record['etf'])?></div>
        </div>
      </div>
    </div>

    <!-- Bank & Payment -->
    <div class="mt-3 pt-3 border-top d-flex justify-content-between align-items-center">
      <div class="small text-muted">
        <i class="bi bi-bank me-1"></i>
        <?=e($record['bank_name']??'—')?> · <?=e($record['bank_account']??'—')?>
        &nbsp;·&nbsp; <?=ucfirst(str_replace('_',' ',$record['payment_method']))?>
      </div>
      <span class="badge <?=$record['payment_status']==='paid'?'bg-success':'bg-warning text-dark'?> px-3 py-2">
        <?=ucfirst($record['payment_status'])?>
      </span>
    </div>

    <!-- Signature -->
    <div class="row g-3 mt-4">
      <div class="col-6 text-center">
        <div style="border-top:1px solid #000;margin-top:40px;padding-top:4px;font-size:.75rem">Employee Signature</div>
      </div>
      <div class="col-6 text-center">
        <div style="border-top:1px solid #000;margin-top:40px;padding-top:4px;font-size:.75rem">Authorized Signature</div>
      </div>
    </div>
  </div>
</div>