<?php
/**
 * (c) ININOUT & PYXIS. All Rights Reserved.
 * Wszelkie modyfikacje tego pliku wymagaja zgloszenia oraz zgody autorow.
 * Any modifications to this file require notification and consent of the authors.
 */
/**
 * i-BOK 5 - Historia płatności klienta
 */

$client_id = $_SESSION['client_id'];
$oplaty = vbk_read_oplaty($client_id);

// Sortuj od najnowszych
usort($oplaty, function($a, $b) {
    return strcmp($b['data_ksieg'], $a['data_ksieg']);
});
?>

<div class="fade-in">
    <h4 class="mb-4">
        <i class="bi bi-credit-card me-2"></i> <?= __('payments.title') ?>
        <span class="badge bg-secondary ms-2"><?= count($oplaty) ?></span>
    </h4>

    <?= ibok_help_section('platnosci', __('help.show_help'), __('help.platnosci_section_content')) ?>

    <div class="card">
        <div class="card-body">
            <?php if (empty($oplaty)): ?>
                <p class="text-muted text-center py-4"><?= __('payments.no_payments') ?></p>
            <?php else: ?>
                <div class="table-responsive">
                    <table class="table table-hover ibok-table" id="tblPlatnosci">
                        <thead>
                            <tr>
                                <th><?= __('payments.booking_date') ?></th>
                                <th><?= __('payments.payment_number') ?></th>
                                <th><?= __('payments.payment_method') ?><?= ibok_tooltip(__('help.tooltip_payment_type')) ?></th>
                                <th><?= __('payments.amount') ?><?= ibok_tooltip(__('help.tooltip_payment_amount')) ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($oplaty as $o): ?>
                            <tr>
                                <td data-order="<?= e($o['data_ksieg']) ?>"><?= format_date($o['data_ksieg']) ?></td>
                                <td><?= e($o['nr_wplaty']) ?></td>
                                <td><?= e($o['forma_platn']) ?></td>
                                <td class="fw-bold"><?= e($o['kwota']) ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>
