<script>
    $(document).ready(function (){
        $('#req-payment-details').DataTable( {
            dom: 'lBfrtip',
            buttons: [
                { extend: 'excel', className: 'download-buttons'},
                { extend: 'pdf', className: 'download-buttons'},
            ]
        } );
    });
    var a = document.getElementsByClassName("ar");
    for (var i = 0; i < a.length; i++) {
        a[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 a List of all Partially Declared Premiums on a Particular Certificate</div>
<div class="guestDetails_inputDivider"></div>
<table id="req-payment-details" class="table-overflow" style="width: 100%; border-collapse: collapse; ">
    <thead>
    <tr style="background-color: #a1b5d3">
        <th>No</th>
        <th>Type</th>
        <th>Insurer</th>
        <th>Cert No.</th>
        <th>DN No.</th>
        <th>Insured Name</th>
        <th>KRA PIN</th>
        <th>Certificate Type</th>
        <th>Reg Number</th>
        <th>Chassis</th>
        <th>Policy Number</th>
        <th>Date Issued</th>
        <th>Period From</th>
        <th>Period To</th>
        <th>Allocated Amount</th>
        <th>Date Paid</th>
        <th>Mode of Payment</th>
        <th>Declaration Ref No.</th>
        <th>Certificate Status</th>
        <th>Notes</th>
    </tr>
    </thead>
    <tbody>
    @if($cert->partialPayments != null)
        @foreach($cert->partialPayments as $partial)
            @if($partial->payment != null) {{--Here, we are Just sure that there exists a payment on this Partial Payment--}}
            @if($cert->debit != null)
                <tr style="padding: 4px; border-bottom: 2px solid black; border-top: 2px solid black">
                    <td class="ar"></td>
                    <td>
                        <b>{!! strtoupper($cert->debit->type) !!}</b>
                    </td>
                    <td>
                        @if($cert->debit->policy != null)
                            @if($cert->debit->policy->insurer != null)
                                {{$cert->debit->policy->insurer->nm}}
                            @endif
                        @endif
                    </td>
                    <td>
                        <b class="error">{!! $cert->cert_no !!}</b>
                    </td>
                    <td>
                        <a href="{{url('policy/'.$cert->debit->pl_cd.'?type=summary')}}" class="inner" ><b class="error">DN{{$cert->debit->pl_cd}}</b></a>
                    </td>
                    <td >
                        @if($cert->policyMotor != null)
                            @if($cert->policyMotor->policy != null)
                                @if($cert->policyMotor->policy->client != null)
                                    {!! strtoupper($cert->policyMotor->policy->client->nms) !!}
                                @endif
                            @endif
                        @endif

                    </td>
                    <td>
                        @if($cert->policyMotor != null)
                            @if($cert->policyMotor->policy != null)
                                @if($cert->policyMotor->policy->client != null)
                                    {!! strtoupper($cert->policyMotor->policy->client->pin) !!}
                                @endif
                            @endif
                        @endif
                    </td>
                    <td >
                        @if($cert->policyMotor != null)
                            @if($cert->policyMotor->policy != null)
                                @if($cert->policyMotor->policy->productCategory != null)
                                    {!! $cert->policyMotor->policy->productCategory->name !!} @if($cert->policyMotor->policy->productSubCategory != null) {!! $cert->policyMotor->policy->productSubCategory->name !!} @endif @if($cert->policyMotor->policy->productMiniSubCategory != null)- {!! $cert->policyMotor->policy->productMiniSubCategory->name !!} @endif
                                @endif
                            @endif
                        @endif

                    </td>
                    @if($cert->policyMotor != null)
                        @if($cert->policyMotor->motorDetails != null)
                            <td ><b class="error">{!! $cert->policyMotor->motorDetails->reg_no_ntsa !!}</b></td>
                            <td>{!! $cert->policyMotor->motorDetails->chassis !!}</td>
                        @else
                            <td><b>--Not Found--</b></td>
                            <td>-</td>
                        @endif
                    @endif
                    <td>
                        @if($cert->debit->policy != null)
                            {{$cert->debit->policy->plcy_no}}
                        @endif
                    </td>
                    <td >{{date('d M Y H:s:i a', strtotime($cert->created_at))}}</td>
                    <td >{{date('d M Y', strtotime($cert->st))}}</td>
                    <td >{{date('d M Y', strtotime($cert->ed))}}</td>
                    <td><b>{{number_format($partial->payment->amount,2)}}</b></td>
                    <td>{!! date('d/m/Y', strtotime($partial->payment->pv_date)) !!}</td>
                    <td>
                        @if($partial->payment->modeOfPayment != null)
                            <b class="error" > {{$partial->payment->modeOfPayment->name}}  @if($partial->payment->subModeOfPayment != null) - {{ $partial->payment->subModeOfPayment->name}} @endif </b>
                        @endif
                    </td>
                    <td>{!! $partial->payment->ref !!}</td>
                    <td>
                        @if($cert->cert_status == 'cancelled')
                            <b class="error">CANCELLED</b>
                        @else
                            <b class="success">Active</b>
                        @endif
                    </td>
                    <td>
                        {!! $cert->cert_notes." " !!} @if($cert->debit->policy != null) {!! $cert->debit->policy->end_cover_summary !!}@endif
                    </td>
                </tr>
            @endif
            @endif
        @endforeach
    @endif
    </tbody>
    <tfoot>
    <tr style="background-color: #a1b5d3">
        <th>No</th>
        <th>Type</th>
        <th>Insurer</th>
        <th>Cert No.</th>
        <th>DN No.</th>
        <th>Insured Name</th>
        <th>KRA PIN</th>
        <th>Certificate Type</th>
        <th>Reg Number</th>
        <th>Chassis</th>
        <th>Policy Number</th>
        <th>Date Issued</th>
        <th>Period From</th>
        <th>Period To</th>
        <th>Allocated Amount</th>
        <th>Date Paid</th>
        <th>Mode of Payment</th>
        <th>Declaration Ref No.</th>
        <th>Certificate Status</th>
        <th>Notes</th>
    </tr>
    </tfoot>
</table>
