<?php
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

redirectIfNotLoggedIn();


$payments = $database->select("payments", ['familyid', 'paymentid (id)', 'amount', 'amountpaid', 'date', 'type']);
?>

<div class="btn-group">
    <a href="app.php?page=editpayment" class="btn btn-success"><i class="fas fa-plus"></i> <?php $Strings->get("Manual Entry"); ?></a>
</div>
<table id="paytable" class="table table-bordered table-hover table-sm">
    <thead>
        <tr>
            <th data-priority="0"></th>
            <th data-priority="1"><?php $Strings->get('Actions'); ?></th>
            <th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Last Name'); ?></th>
            <th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Total'); ?></th>
            <th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Paid'); ?></th>
            <th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
            <th data-priority="3"><i class="fas fa-bars hidden-sm"></i> <?php $Strings->get('Type'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($payments as $p) {
            ?>
            <tr>
                <td></td>
                <td>
                    <a class="btn btn-primary btn-sm" href="app.php?page=editpayment&id=<?php echo $p['id']; ?>"><i class="fas fa-edit"></i> <?php $Strings->get("Edit"); ?></a>
                </td>
                <td>
                    <?php
                    $familynames = $database->select('people', 'lastname', ['familyid' => $p['familyid']]);
                    echo htmlentities(implode(", ", $familynames));
                    ?>
                </td>
                <td>$<?php echo number_format($p['amount'], 2); ?></td>
                <td>$<?php echo number_format($p['amountpaid'], 2); ?></td>
                <td><?php echo date("Y-m-d H:i:s", strtotime($p['date'])); ?></td>
                <td><?php $Strings->get($p["type"]); ?></td>
            </tr>
            <?php
        }
        ?>
    </tbody>
    <tfoot>
        <tr>
            <th data-priority="0"></th>
            <th data-priority="1"><?php $Strings->get('Actions'); ?></th>
            <th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Last Name'); ?></th>
            <th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Total'); ?></th>
            <th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Paid'); ?></th>
            <th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
            <th data-priority="3"><i class="fas fa-bars hidden-sm"></i> <?php $Strings->get('Type'); ?></th>
        </tr>
    </tfoot>
</table>