<?php $this->start('body');
    $rows = $this->data['rows'] ?? [];
?>
<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="mb-0" style="font-weight:600;"><i class="fas fa-clipboard-list me-1 text-muted"></i>
            Contract BOQs · <?= count($rows); ?> project<?= count($rows) === 1 ? '' : 's'; ?>
        </h5>
        <div class="text-muted" style="font-size:.72rem;">Snapshotted from approved tender pricing at project provisioning.</div>
    </div>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-body p-0">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light">
                <tr>
                    <th>Project</th>
                    <th>Customer</th>
                    <th class="text-end">Contract value</th>
                    <th class="text-end">Variations</th>
                    <th style="width:100px;" class="text-end">Items</th>
                    <th style="width:80px;" class="text-end">Open</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $r): ?>
                    <tr>
                        <td>
                            <strong><?= htmlspecialchars($r['project_no']); ?></strong>
                            <div class="text-muted small"><?= htmlspecialchars($r['project_name']); ?></div>
                        </td>
                        <td class="text-muted small"><?= htmlspecialchars($r['project_customer']); ?></td>
                        <td class="text-end"><?= number_format((float)$r['contract_value']); ?></td>
                        <td class="text-end text-muted small"><?= number_format((float)$r['variation_value']); ?></td>
                        <td class="text-end"><?= (int)$r['item_count']; ?></td>
                        <td class="text-end"><a href="<?= PROOT; ?>WorksBoq/view/<?= (int)$r['c0d']; ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-right"></i></a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($rows)): ?>
                    <tr><td colspan="6" class="text-center text-muted py-4">No works projects with a BOQ yet.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $this->end(); ?>
