<?php
if (!isset($reportData)) {
    $reportData = [];
}
$laybuyTableTotal = 0;
foreach (($paymentData ?? []) as $payments) {
    $laybuyTableTotal += (float)($payments['body_amount'] ?? 0);
}
?>

<table class="table table-striped">
    <thead>
        <tr>
            <th>Date</th>
            <th>Item Name</th>
            <th>Amount</th>
            <th>Status</th>
            <th>Assigned Code(s)</th>
        </tr>
		</thead>
        <tbody>
                <?php if (!empty($paymentData)): ?>
                    <?php foreach ($paymentData  as $payments): ?>
                        <tr>
                            <td><?php echo htmlspecialchars($payments['payment_date'] ?? ''); ?></td>
                            <td><?php echo htmlspecialchars($payments['notes'] ?? ''); ?></td>
                            <td><?php echo htmlspecialchars($payments['body_amount'] ?? ''); ?></td>
                            <td><?php echo htmlspecialchars($payments['verified']?? ''); ?></td>
                            <td><?php echo !empty($payments['assigned_codes']) ? htmlspecialchars($payments['assigned_codes']) : '<span class="text-muted">—</span>'; ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr>
                        <td colspan="5" class="text-center">No Payment data found.</td>
                    </tr>
                <?php endif; ?>
            </tbody>
            <?php if (!empty($paymentData)): ?>
            <tfoot>
                <tr>
                    <td colspan="2" class="text-end"><strong>Total Laybuy Payments</strong></td>
                    <td><strong>MWK <?php echo number_format($laybuyTableTotal, 2); ?></strong></td>
                    <td colspan="2"></td>
                </tr>
            </tfoot>
            <?php endif; ?>

</table>