<?php
// Variables: $rows, $totals, $as_of, $buckets
?>

<div class="meta-grid">
  <div class="meta-item">
    <div class="label">تاريخ التقرير</div>
    <div class="value"><?= e($as_of) ?></div>
  </div>
  <div class="meta-item">
    <div class="label">عدد الموردين</div>
    <div class="value"><?= e((string)count($rows)) ?></div>
  </div>
</div>

<table class="table">
  <thead>
    <tr>
      <th style="width:60px">#</th>
      <th>المورد</th>
      <th style="width:140px">إجمالي</th>
      <th style="width:140px"><?= e($buckets[0]['label']) ?></th>
      <th style="width:140px"><?= e($buckets[1]['label']) ?></th>
      <th style="width:140px"><?= e($buckets[2]['label']) ?></th>
      <th style="width:140px"><?= e($buckets[3]['label']) ?></th>
    </tr>
  </thead>
  <tbody>
    <?php $i=1; foreach ($rows as $r): ?>
      <tr>
        <td><?= e((string)$i++) ?></td>
        <td><?= e($r['supplier_name']) ?> <span class="muted">(<?= e($r['supplier_code']) ?>)</span></td>
        <td class="num"><?= e(format_money($r['total'])) ?></td>
        <td class="num"><?= e(format_money($r['b1'])) ?></td>
        <td class="num"><?= e(format_money($r['b2'])) ?></td>
        <td class="num"><?= e(format_money($r['b3'])) ?></td>
        <td class="num"><?= e(format_money($r['b4'])) ?></td>
      </tr>
    <?php endforeach; ?>
  </tbody>
  <tfoot>
    <tr>
      <th colspan="2">الإجمالي</th>
      <th class="num"><?= e(format_money($totals['total'])) ?></th>
      <th class="num"><?= e(format_money($totals['b1'])) ?></th>
      <th class="num"><?= e(format_money($totals['b2'])) ?></th>
      <th class="num"><?= e(format_money($totals['b3'])) ?></th>
      <th class="num"><?= e(format_money($totals['b4'])) ?></th>
    </tr>
  </tfoot>
</table>

<p class="muted">* يعتمد التقرير على فواتير الشراء المرحّلة بعد خصم المرتجعات والمدفوعات الموزعة.</p>
