<?php $this->start('body'); ?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <h5 class="mb-0" style="font-weight:600;"><i class="fas fa-truck me-2 text-muted"></i>Customer Delivery Notes</h5>
    <a href="<?= PROOT; ?>GoodsClientPos" class="btn btn-sm btn-outline-secondary"><i class="fas fa-file-contract me-1"></i> Find PO to deliver</a>
</div>

<div class="card border-0 shadow-sm">
    <div class="table-responsive">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light">
                <tr>
                    <th>DN #</th><th>Date</th><th>Client PO</th><th>Customer</th><th>Delivered to</th>
                    <th class="text-end">Lines</th><th class="text-end">Qty delivered</th>
                    <th>Condition</th><th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($this->data['rows'] as $r): ?>
                    <tr>
                        <td><a href="<?= PROOT; ?>GoodsCustomerDeliveries/view/<?= (int)$r['c0d']; ?>" class="text-decoration-none"><strong><?= htmlspecialchars($r['dn_no']); ?></strong></a></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['delivery_date']); ?></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['client_po_no']); ?></td>
                        <td><?= htmlspecialchars($r['customer_name']); ?></td>
                        <td><?= htmlspecialchars($r['delivered_to'] ?: '—'); ?></td>
                        <td class="text-end text-muted"><?= (int)$r['line_count']; ?></td>
                        <td class="text-end"><?= number_format((float)$r['qty_delivered_total'], 0); ?></td>
                        <td>
                            <?php if ((int)$r['condition_ok'] === 1): ?>
                                <span class="badge bg-success"><i class="fas fa-check me-1"></i>OK</span>
                            <?php else: ?>
                                <span class="badge bg-warning text-dark"><i class="fas fa-exclamation-triangle me-1"></i>Issues</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-end"><a href="<?= PROOT; ?>GoodsCustomerDeliveries/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($this->data['rows'])): ?>
                    <tr><td colspan="9" class="text-center text-muted py-4">No customer deliveries yet. Open a Client PO with received stock and click "Record Delivery".</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php $this->end(); ?>
