<div id="paymenthistory" class="mt-10">
    <div class="table-responsive">
        <table class="table table-bordered " id="tableDownload">
            <tr>
                <th>#id</th>
                <th>Date</th>
                <th>Type</th>
                <th>C Name</th>
                <th>username</th>
                <th>Expire Date</th>
                <th>POP</th>
                <th>MR ID</th>
                <th>Entry BY</th>
                <th>Col By</th>
                <th>Package</th>
                <th style="max-width: 150px">Description</th>
                <th>Amount</th>
                <th>Discount</th>
            </tr>
            @php($totalDue = 0)
            @foreach ($list as $p)
                <tr>
                    {{-- <td>{{ $p->id }}</td> --}}
                    <td>
                        <a class="underline text-blue-300"
                            href="{{ route('getPaymentHistory', $p->clients->id) }}">@php(printf('CID%04d', $p->clients->id))</a>

                        {{-- <a href="{{ route('invoice', $p->clients->id) }}" class="btn btn-info btn-xs">Invoice</a> --}}
                        <a href="{{ route('printPaymentInvoice', $p->id) }}" target="_blank" class="btn btn-info btn-xs">Invoice</a>
                    </td>
                    <td class="text-center">{{ date('d-M-Y h:i:s A', strtotime($p->created_at)) }}</td>
                    <td>{{ $p->income->head->name ?? '' }}</td>
                    <td>{{ $p->clientsinfo->clients_name ?? '' }}</td>
                    <td>{{ $p->clients->userid ?? '' }}</td>
                    <td>{{ \Carbon\Carbon::parse($p->clients->expire_date)->format('d-M-Y') }}</td>
                    <td>{{ $p->clients->pop->popname ?? '' }}</td>
                    <td>{{ $p->money_receipt_number }}</td>
                    <td>{{ $p->user->name ?? '' }}</td>
                    <td class="text-center">{{ $p->employee->name ?? '' }}</td>
                    <td> {{ $p->clients->packages->package_name ?? '' }}</td>
                    <td style="max-width: 150px">{{ $p->description ?? '' }}</td>
                    <td class="text-right"> {{ $p->paid_amount }}</td>
                    <td class="text-right"> {{ $p->discount_amount }}</td>
                </tr>
            @endforeach

            <tr class="hidden">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td class="text-right"><b>Total:</b> </td>
                <td class="text-right"><b>{{ $list->sum('paid_amount') }} TK</b></td>
                <td class="text-right"><b>{{ $list->sum('discount_amount') }} TK</b></td>
            </tr>
        </table>
    </div>
</div>
