<div class="invoice-modern">
<div class="row">
    <div class="col-sm-3">
        <?= isset($invoice_sidebar_html) ? $invoice_sidebar_html : '' ?>
    </div>
    <section class="col-sm-9">
        <?= message_box('error') ?>
        <!-- Start create invoice -->
        <?php
        if (!empty($all_payments_history)) {
            $reference = ": <a href='" . base_url('admin/invoice/manage_invoice/invoice_details/' . $invoice_info->invoices_id) . "' >" . $invoice_info->reference_no . "</a>";
            $invoice_due = $this->invoice_model->calculate_to('invoice_due', $invoice_info->invoices_id);
            $payment_page = !empty($payment_history_page) ? (int) $payment_history_page : 1;
            $payment_pages = !empty($payment_history_pages) ? (int) $payment_history_pages : 1;
            $payment_query = $this->input->get();
            unset($payment_query['payment_page']);
        ?>
        <section class="panel panel-custom ">
            <header class="panel-heading pb-sm"><?= lang('payment_history_for_this_invoice', $reference) ?>
                <?php if ($invoice_due != 0) { ?>
                <div class="pull-right">
                    <a class="btn btn-xs btn-danger" data-toggle="tooltip" data-placement="top"
                        href="<?= base_url('admin/invoice/manage_invoice/payment/' . $invoice_info->invoices_id) ?>"
                        title="<?= lang('add_payment') ?>"><i data-lucide="credit-card"></i> <?= lang('pay_invoice') ?>
                    </a>
                </div>
                <?php } ?>
            </header>
            <div class="panel-body table-responsive">
                <table class="table table-striped" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th><?= lang('trans_id') ?></th>
                            <th><?= lang('payment_date') ?></th>
                            <th><?= lang('paid_amount') ?></th>
                            <th><?= lang('payment_method') ?></th>
                            <th><?= lang('account') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            foreach ($all_payments_history as $v_payment_history) {
                                $currency = $this->invoice_model->client_currency_symbol($invoice_info->client_id);
                                if (empty($currency)) {
                                    $currency = $this->invoice_model->check_by(array('code' => config_item('default_currency')), 'tbl_currencies');
                                }
                                $payment_method_name = !empty($v_payment_history->payment_method_name) ? $v_payment_history->payment_method_name : $v_payment_history->payment_method;
                                $account = !empty($v_payment_history->account_name) ? $v_payment_history->account_name : '-';
                            ?>
                        <tr>
                            <td>
                                <a
                                    href="<?= base_url() ?>admin/invoice/manage_invoice/payments_details/<?= $v_payment_history->payments_id ?>">
                                    <?= $v_payment_history->trans_id ?></a>
                            </td>
                            <td>
                                <?= display_date($v_payment_history->payment_date) ?>
                            </td>
                            <td>
                                <span><?= display_money($v_payment_history->amount, $currency->symbol); ?></span>
                            </td>
                            <td>
                                <span><?= !empty($payment_method_name) ? html_escape($payment_method_name) : '-'; ?></span>
                            </td>
                            <td>
                                <span><?= html_escape($account) ?></span>
                            </td>
                        </tr>
                        <?php } ?>
                    </tbody>
                </table>
                <?php if ($payment_pages > 1) { ?>
                <div class="mt-4 flex items-center justify-between gap-3">
                    <?php if ($payment_page > 1) { ?>
                        <a href="<?= base_url('admin/invoice/manage_invoice/payment_history/' . $invoice_info->invoices_id) . '?' . http_build_query(array_merge($payment_query, array('payment_page' => $payment_page - 1))) ?>" class="btn btn-default btn-sm">Prev</a>
                    <?php } else { ?>
                        <span class="btn btn-default btn-sm disabled">Prev</span>
                    <?php } ?>
                    <span class="text-muted"><?= $payment_page ?> of <?= $payment_pages ?></span>
                    <?php if ($payment_page < $payment_pages) { ?>
                        <a href="<?= base_url('admin/invoice/manage_invoice/payment_history/' . $invoice_info->invoices_id) . '?' . http_build_query(array_merge($payment_query, array('payment_page' => $payment_page + 1))) ?>" class="btn btn-default btn-sm">Next</a>
                    <?php } else { ?>
                        <span class="btn btn-default btn-sm disabled">Next</span>
                    <?php } ?>
                </div>
                <?php } ?>
            </div>
            <footer class="panel-footer no-padder">
                <div class="row text-center no-gutter">
                    <div class="col-xs-4 b-r b-light">
                        <span
                            class="h4 font-bold m-t block"><?= display_money($this->invoice_model->calculate_to('total', $invoice_info->invoices_id), $currency->symbol) ?></span>
                        <small class="text-muted m-b block"><?= lang('total') . ' ' . lang('invoice_amount') ?></small>
                    </div>
                    <div class="col-xs-4 b-r b-light">
                        <span
                            class="h4 font-bold m-t block"><?= display_money($this->invoice_model->calculate_to('paid_amount', $invoice_info->invoices_id), $currency->symbol) ?></span>
                        <small class="text-muted m-b block"><?= lang('total') . ' ' . lang('paid_amount') ?></small>
                    </div>
                    <div class="col-xs-4">
                        <span
                            class="h4 font-bold m-t block"><?= display_money($invoice_due, $currency->symbol) ?></span>
                        <small class="text-muted m-b block"><?= lang('total') . ' ' . lang('due_amount') ?></small>

                    </div>
                </div>
            </footer>
        </section>

        <?php } ?>
    </section>
</div>

<!-- end -->
</div>
