<?php
    $monthName = fn ($m) => $m >= 1 && $m <= 12 ? date('M', mktime(0, 0, 0, $m, 10)) : '';
    $branch = $student->branch;
    $logo = $branch?->logo ? asset('storage/'.ltrim($branch->logo, '/')) : '';
    $sname = $student->name;
    $parentName = $student->family?->primary_contact_name ?? '-';
    $studentRoll = $student->roll_number ?: ($student->admission_number ?: '-');
    $classSec = trim(($student->schoolClass?->name ?? '-').' / '.($student->section?->name ?? ''), ' /');
    $campusName = $branch?->name ?? '-';
    $afterDue = $subtotal; // fines are already folded into each challan balance
    $barcodeUrl = 'https://barcode.tec-it.com/barcode.ashx?data='.urlencode($voucherNo).'&code=Code128&dpi=96&imagetype=Gif&height=42&modulewidth=2&showtext=false';
    $qrUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=90x90&qzone=1&data='.urlencode('Voucher:'.$voucherNo.' | '.$sname.' | Roll:'.$studentRoll.' | Rs '.number_format($subtotal));
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fee Card — <?php echo e($sname); ?></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
  *{box-sizing:border-box}
  html,body{margin:0;padding:0;background:#e9edf1;font-family:Arial,Helvetica,sans-serif;color:#222}
  .sheet-wrap{max-width:1180px;margin:14px auto;background:#fff;padding:14px;box-shadow:0 2px 12px rgba(0,0,0,.12)}
  .fc-toolbar{display:flex;gap:8px;justify-content:space-between;align-items:center;flex-wrap:wrap;margin-bottom:12px}
  .fc-toolbar a,.fc-toolbar button,.fc-toolbar select{font:inherit;font-size:13px;padding:6px 12px;border-radius:5px;border:1px solid #cbd3dc;background:#fff;cursor:pointer;text-decoration:none;color:#222}
  .fc-toolbar .btn-print{background:#222;color:#fff;border-color:#222}
  .fc-toolbar .btn-pay{background:#0d6efd;color:#fff;border-color:#0d6efd}
  .fc-toolbar .btn-back{color:#555}
  /* voucher */
  #voucherSheet{display:flex;gap:10px;justify-content:space-between;align-items:stretch}
  .vc{position:relative;width:33%;border:1px solid #111;background:#fff;overflow:hidden}
  .vc + .vc{border-left:1px dashed #777}
  .vc-inner{position:relative;z-index:2;padding:10px 12px}
  .wm{position:absolute;inset:0;z-index:1;background-repeat:no-repeat;background-position:center 46%;background-size:70% auto;opacity:.11;-webkit-print-color-adjust:exact;print-color-adjust:exact}
  .copy-label{text-align:center;font-size:10px;font-weight:700;letter-spacing:2px;text-transform:uppercase;color:#333;border-bottom:2px solid #7a1f1f;padding-bottom:6px;margin-bottom:8px}
  .vhead{display:flex;align-items:center;justify-content:center;gap:10px}
  .vlogo{height:42px;width:auto;object-fit:contain}
  .vschool{font-family:Georgia,'Times New Roman',serif;font-size:20px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;color:#111}
  .vaddr{text-align:center;font-size:11px;color:#333;border-bottom:1px dashed #999;padding:6px 0;margin-bottom:6px}
  .vinfo{width:100%;border-collapse:collapse;font-size:11.5px;margin-bottom:8px}
  .vinfo th{text-align:left;text-transform:uppercase;font-size:10px;color:#222;width:1%;white-space:nowrap;border:1px solid #cfcfcf;padding:3px 5px;background:#fafafa}
  .vinfo td{border:1px solid #cfcfcf;padding:3px 6px}
  .vbar{margin:4px 0;text-align:center}
  .vbar img{max-width:100%;height:40px}
  .vbank{text-align:center;font-size:10.5px;font-weight:600;color:#333;margin:2px 0 8px}
  .vfee{width:100%;border-collapse:collapse;font-size:11.5px}
  .vfee th{background:#eaeaea;border:1px solid #bbb;padding:5px 6px;text-transform:uppercase;font-size:10px}
  .vfee td{border:1px solid #bbb;padding:5px 6px}
  .vfee .l{text-align:left}.vfee .r{text-align:right}
  .vfee .sub td{background:#f3f3f3;font-weight:700}
  .vtot{width:100%;border-collapse:collapse;font-size:11.5px;margin-top:6px}
  .vtot td{border:1px solid #bbb;padding:5px 6px}
  .vtot .l{font-weight:700;background:#f3f3f3;width:60%}.vtot .r{text-align:right;font-weight:700;background:#f3f3f3}
  .vtot .vdates{font-size:11px}
  .vhist-title{text-align:center;font-weight:700;font-size:11px;margin:10px 0 4px;text-transform:uppercase}
  .vhist{width:100%;border-collapse:collapse;font-size:9px;text-align:center}
  .vhist th,.vhist td{border:1px solid #bbb;padding:2px}
  .vhist th{background:#f0f0f0}
  .vnotice{display:flex;justify-content:space-between;align-items:flex-start;gap:8px;margin-top:10px}
  .vn-text{font-size:10px;color:#333}
  .vqr img{width:74px;height:74px}
  .vsign{display:flex;justify-content:space-between;font-size:10px;font-style:italic;border-top:1px solid #999;margin-top:34px;padding-top:4px}
  .vpower{text-align:center;font-size:9px;color:#777;margin-top:6px}

  /* ---- A4 print: fit all 3 copies on ONE landscape page ---- */
  @media print {
    @page{ size:A4 landscape; margin:5mm; }
    html,body{ background:#fff !important; margin:0; padding:0; -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; }
    .no-print{ display:none !important; }
    .sheet-wrap{ max-width:none; width:100%; margin:0; padding:0; box-shadow:none; }
    #voucherSheet{ gap:0; width:100%; page-break-inside:avoid; }
    .vc{ width:33.33%; page-break-inside:avoid; }
    .vc-inner{ padding:5px 7px; }
    .vschool{ font-size:15px; }
    .vaddr{ font-size:9.5px; padding:4px 0; }
    .vinfo{ font-size:9px; } .vinfo th{ font-size:8.5px; padding:2px 4px; } .vinfo td{ padding:2px 4px; }
    .vbar img{ height:32px; }
    .vfee{ font-size:9px; } .vfee th,.vfee td{ padding:3px 5px; }
    .vtot{ font-size:9px; } .vtot td{ padding:3px 5px; }
    .vhist{ font-size:7.5px; }
    .vqr img{ width:60px;height:60px; }
    .vsign{ margin-top:18px; }
  }
</style>
</head>
<body>
<div class="sheet-wrap">
  <div class="fc-toolbar no-print">
    <form method="get" action="<?php echo e(route('students.fee-card', $student)); ?>" style="display:flex;align-items:center;gap:6px;margin:0">
      <label style="margin:0">Year</label>
      <select name="year" onchange="this.form.submit()">
        <?php $__currentLoopData = $years; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $y): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <option value="<?php echo e($y); ?>" <?php echo e($year == $y ? 'selected' : ''); ?>><?php echo e($y); ?></option>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </select>
    </form>
    <div style="display:flex;gap:6px">
      <a class="btn-back" href="<?php echo e(route('students.show', $student)); ?>">&larr; Back</a>
      <a class="btn-pay" href="<?php echo e(route('students.show', $student)); ?>#fees">Receive Payment</a>
      <button class="btn-print" type="button" onclick="window.print()">&#128424; Print Voucher</button>
    </div>
  </div>

  <div id="voucherSheet">
    <?php $__currentLoopData = ['Bank Copy', 'School Copy', 'Parent Copy']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $copyLabel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
      <div class="vc">
        <?php if($logo): ?><div class="wm" style="background-image:url('<?php echo e($logo); ?>')"></div><?php endif; ?>
        <div class="vc-inner">
          <div class="copy-label"><?php echo e($copyLabel); ?></div>

          <div class="vhead">
            <?php if($logo): ?><img class="vlogo" src="<?php echo e($logo); ?>" onerror="this.style.display='none'"><?php endif; ?>
            <div class="vschool"><?php echo e($branch?->name ?? 'School Name'); ?></div>
          </div>
          <div class="vaddr">
            <?php echo e(trim(($branch?->address ?? '').(($branch?->address && $branch?->city) ? ', ' : '').($branch?->city ?? ''))); ?>

            <?php if($branch?->phone): ?><br>Contact: <?php echo e($branch->phone); ?><?php endif; ?>
          </div>

          <table class="vinfo">
            <tr><th>Name:</th><td><?php echo e($sname); ?></td><th>Parent:</th><td><?php echo e($parentName); ?></td></tr>
            <tr><th>Class/Sec:</th><td><?php echo e($classSec); ?></td><th>Roll No:</th><td><?php echo e($studentRoll); ?></td></tr>
            <tr><th>Campus:</th><td><?php echo e($campusName); ?></td><th>Voucher:</th><td><?php echo e($voucherNo); ?></td></tr>
          </table>

          <div class="vbar"><img src="<?php echo e($barcodeUrl); ?>" onerror="this.parentNode.style.display='none'"></div>
          <?php if($student->family?->family_code): ?>
            <div class="vbank">Family A/C: <?php echo e($student->family->family_code); ?> &nbsp; • &nbsp; Payable at <?php echo e($branch?->name ?? 'School'); ?> Office</div>
          <?php endif; ?>

          <table class="vfee">
            <tr><th class="l">Fee Description</th><th class="r">Amount</th></tr>
            <?php $__empty_1 = true; $__currentLoopData = $lines; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fl): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
              <tr><td class="l"><?php echo e($fl['desc']); ?></td><td class="r"><?php echo e(number_format($fl['amount'])); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
              <tr><td class="l">No outstanding dues</td><td class="r">0</td></tr>
            <?php endif; ?>
            <tr class="sub"><td class="l">Subtotal</td><td class="r"><?php echo e(number_format($subtotal)); ?></td></tr>
          </table>

          <table class="vtot">
            <tr><td class="l">Total Payable:</td><td class="r"><?php echo e(number_format($subtotal)); ?></td></tr>
            <tr><td class="l">After Due Date:</td><td class="r"><?php echo e(number_format($afterDue)); ?></td></tr>
            <tr><td colspan="2" class="vdates">Voucher Validity: <b><?php echo e($validDate->format('d/m/Y')); ?></b> &nbsp; Due Date: <b><?php echo e($dueDate->format('d/m/Y')); ?></b></td></tr>
          </table>

          <div class="vhist-title">Fee History (Family Account)</div>
          <table class="vhist">
            <tr><th>Year</th><th colspan="12"><?php echo e($year); ?></th></tr>
            <tr><th>Month</th><?php for($m=1;$m<=12;$m++): ?><td><?php echo e($monthName($m)); ?></td><?php endfor; ?></tr>
            <tr><th>Billed</th><?php for($m=1;$m<=12;$m++): ?><td><?php echo e($billed[$m] ? number_format($billed[$m]) : 0); ?></td><?php endfor; ?></tr>
            <tr><th>Paid</th><?php for($m=1;$m<=12;$m++): ?><td><?php echo e($paid[$m] ? number_format($paid[$m]) : 0); ?></td><?php endfor; ?></tr>
          </table>

          <div class="vnotice">
            <div class="vn-text"><b>NOTICE:</b><br>* This is a computer generated fee voucher. No manual corrections will be acceptable.</div>
            <div class="vqr"><img src="<?php echo e($qrUrl); ?>" onerror="this.style.display='none'"></div>
          </div>

          <div class="vsign">
            <span>Authorized Signature</span>
            <span>Bank / School Stamp</span>
          </div>
          <div class="vpower"><?php echo e(config('app.name')); ?></div>
        </div>
      </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
  </div>
</div>
</body>
</html>
<?php /**PATH /home/u385418287/domains/itartificer.com/public_html/sms-erp/resources/views/fees/card.blade.php ENDPATH**/ ?>