<script>
    $(document).ready(function (){
        $('#req-payment-details').DataTable( {
            dom: 'lBfrtip',
            buttons: [
                { extend: 'excel', className: 'download-buttons'},
                { extend: 'pdf', className: 'download-buttons'},
            ]
        } );
    });
    var c = document.getElementsByClassName("cr");
    for (var i = 0; i < c.length; i++) {
        c[i].innerHTML = (i+1)+".";
    }
</script>
<style>
    #req-payment-details th, td {
        text-align: left;
        padding: 5px;
    }
    #req-payment-details tr:hover {background-color: #999ebe;}
</style>
<div class="error" style="text-align: center;">On this Window, you can view How a Bill was Paid</div>
<div class="guestDetails_inputDivider"></div>
<table style="width: 50%; border-collapse: collapse; padding: 5px">
    <tr>
        <th>Bill Invoice Number:</th>
        <td><b class="error">{!! strtoupper($bill->ref) !!}</b></td>
    </tr>
    <tr>
        <th>Bill Narration:</th>
        <td><b class="error">{!! strtoupper($bill->narration) !!}</b></td>
    </tr>
    <tr>
        <th>Date Created:</th>
        <td><b>{{date('d-m-Y', strtotime($bill->created_at))}}</b></td>
    </tr>
    <tr>
        <td>
            <button type="button" class="navButtons" style="background-color: #d9ffff;color: black; margin-bottom: 0;font-weight: bold; min-width: 200px ;font-size: 14px">Bill Bal:
                <b class="error" style="margin-left: 10px">
                    {{number_format($bill->amount - abs($bill->billPaidAmount($bill->id)),2)}}
                </b>
            </button>
        </td>
    </tr>
</table>
<div class="guestDetails_inputDivider"></div>
<table id="req-payment-details" style="width: 100%; border-collapse: collapse; ">
    <thead>
    <tr style="background-color: #a1b5d3">
        <th>No</th>
        <th>PV No.</th>
        <th>PV Type</th>
        <th>Paid From</th>
        <th>GL Account</th>
        <th>Paid To</th>
        <th>Mode</th>
        <th>REF</th>
        <th>Narration</th>
        <th>Amount Paid</th>
        <th>Date Paid</th>
        <th>Date of Payment</th>
        <th>User</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    @foreach($paidReqs as $row)
        @if($row->payment)
            <tr>
                <td class="cr"></td>
                <td><a href="{{url('payment/'.$row->payment->stamp.'/finance?type=summary')}}" class="inner"><b class="error">PV{{$row->payment->pv_id}}</b></a></td>
                <td>{{$row->payment->type}}</td>
                <td>
                    <b>
                        @if($row->payment->account != null)
                            {!! strtoupper($row->payment->account->acc_name) !!}
                        @endif
                    </b>
                </td>
                <td>
                    <b>
                        @if($row->payment->glAccount != null)
                            {!! strtoupper($row->payment->glAccount->acc_name) !!}
                        @endif
                    </b>
                </td>
                <td>
                    @if($row->payment->type == 'refund-premium')
                        @if($row->payment->client != null)
                            {!! strtoupper($row->payment->client->nms) !!}
                        @endif
                    @elseif($row->payment->type == 'remit-premium')
                        @if($row->payment->insurer != null)
                            {!! strtoupper($row->payment->insurer->nm) !!}
                        @endif
                    @else
                        -
                    @endif
                </td>

                <td>
                    @if($row->payment->modeOfPayment != null)
                        {!! $row->payment->modeOfPayment->name !!}
                        @if($row->payment->subModeOfPayment != null)
                            - {!! $row->payment->subModeOfPayment->name !!}
                        @endif
                    @endif
                </td>
                <td>{!! $row->payment->ref !!}</td>
                <td>{!! $row->payment->nar !!}</td>
                <td><b>{!! number_format($row->payment->amount,2) !!}</b></td>
                <td>{{date('d/m/Y', strtotime($row->payment->pv_date))}}</td>
                <td>{{date('d/m/Y', strtotime($row->payment->created_at))}}</td>
                <td>
                    @if($row->payment->user != null)
                        {!! $row->payment->user->firstName[0].". ".$row->payment->user->lastName !!}
                    @endif
                </td>
                <td><a href="{{url('payment-pdf/'.$row->payment->stamp.'/AddWatermark')}}" class="inner" target="_blank"><i class="fa fa-print error" style="font-size: 16px"></i></a></td>
            </tr>
        @endif

    @endforeach
    </tbody>
    <tfoot>
    <tr style="background-color: #a1b5d3">
        <th>No</th>
        <th>PV No.</th>
        <th>PV Type</th>
        <th>Paid From</th>
        <th>GL Account</th>
        <th>Paid To</th>
        <th>Mode</th>
        <th>REF</th>
        <th>Narration</th>
        <th>Amount Paid</th>
        <th>Date Paid</th>
        <th>Date of Payment</th>
        <th>User</th>
        <th></th>
    </tr>
    </tfoot>
</table>
