
@include('admin.layouts.header')
@include('admin.layouts.sidebar')
<style>
    .hidden{
        display: none;
    }
    .font-weight{
        font-weight: 600;
    }
    table{
        width: 100%;
        font-family: Arial;
    }
    .emi-form > thead > tr > th{
        font-weight: 600 !important;
    }
    .payable-amt{
        border-top-style: solid;
        border-bottom-style: solid;
    }
    .interest_rate{
        text-transform: capitalize;
    }
    .datepicker tbody tr > td[class='day']{
        border-color: #34b9c3;
        color: black;
        border-style: dashed;
        border-width: 1px;
    }
    .panel-group{
        padding-top: 18px;
    }
    .panel-default{
        padding-bottom: 4px;
    }
    .panel-collapse{
        background-color: #ffffff;
        padding: 10px;
        border: 1px solid #dedada;
    }
    h4.panel-title > a{
        font-size: 14px;
        color: #5f5a5a !important;
    }
    .panel-heading {
        background-color: #f1f1f1;
        border: 1px solid #e0dfe0;
        padding-left: 10px;
        padding-top: 6px;
        cursor: pointer;
    }
</style>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
    <!-- BEGIN: Subheader -->
    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    Loan Schedule -  {!! $customer_name !!}
                </h3>
            </div>

        </div>
    </div>
<?php setlocale(LC_MONETARY, 'en_IN.UTF-8'); ?>
    <!-- END: Subheader -->
    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-calendar"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            Loan Schedule -  {!! $customer_name !!}
                        </h3>
                    </div>
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <table style="margin-bottom: 30px;">
                        <tr>
                            <td>Loan Amount</td><td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($summary['loan_amount'],0)))) !!}</td>
                            <td>Merchant</td><td>{!! $summary['merchant_name'] !!}</td>
                        </tr>
                        <tr>
                            <td>Total EMIs</td><td>{!! $summary['tenure'] !!}</td>
                            <td>Advance EMIs</td><td>{!! $summary['tenure']-$summary['remaining_emi'] !!}</td>
                        </tr>
                        <tr>
                            <td>Quoted rate</td><td>{!! $summary['quoted_interest'] !!}%</td>
                            <td>Interest Rate</td><td>{!! round($summary['interest'],2) !!}%</td>
                        </tr>
                        <tr>
                            <td>Subvention</td><td>{!! $summary['subvention'] !!}%</td>
                            <td>Processing Fee</td><td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($summary['processing_fee'],0)))) !!}</td>
                        </tr>
                        <tr>
                            <td>EMI</td><td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($summary['emi'],0)))) !!}</td>
                            <td>Advance Due</td><td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($summary['advance_due'],0)))) !!}</td>
                        </tr>
                    </table>

                    @if(isset($summary['moratoriums']) && count($summary['moratoriums']))
                        <div class="panel-group" style="margin-bottom: 16px;">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <h4 class="panel-title">
                                        <a data-toggle="collapse" href="#moratorium_details">Moratorium Details</a>
                                        <div style="float: right;margin-right: 14px;"><i class="fa fa-angle-down" style="font-size: 24px;"></i></div>
                                    </h4>
                                </div>
                                <div id="moratorium_details" class="panel-collapse collapse">
                                    <div class="panel-body">
                                        <table class="table">
                                            <thead>
                                            <tr>
                                                <th>Moratorium Period</th>
                                                <th>Moratorium Interest Rate</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($summary['moratoriums'] as $moratoriumItem)
                                                <tr>
                                                    <td>{!! $moratoriumItem->emi_date !!}</td>
                                                    <td>{!! $moratoriumItem->interest_rate !!}%</td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endif

                    @if(isset($schedule_new) && isset($schedule_new[0]) && $schedule_new[0]['bpi_interest'] > 0)
                        <div class="panel-group" style="margin-bottom: 16px;">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                        Pre-EMI Details
                                </div>
                                <div id="pre_emi_details" class="panel-collapse">
                                    <div class="panel-body">
                                        <table class="table">
                                            <tr>
                                                <th>Date</th>
                                                <th>Amount</th>
                                            </tr>
                                            <tr>
                                                <td>{!! $schedule_new[0]['emi_date'] !!}</td>
                                                <td>{!! $schedule_new[0]['bpi_interest'] !!}</td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endif


                    @if(isset($schedule) && count($schedule) > 0)
                        <table class="table">
                            <thead style="background-color: #999999;color: white">
                            <th>#</th>
                            <th>EMI Date</th>
                            <th>EMIs Amount</th>
                            {{--@if(\Auth::user()->user_type != 'admin')--}}
                            <th>Principal Outstanding</th>
                            <th>Interest Due</th>
                            <th>Principal Due</th>
                            {{--@endif--}}
                            <th>Bounce Charges</th>
                            <th>Penalty Charges</th>
                            <th>Moratorium Amount</th>
                            <th>Charges Waived off</th>
                            {{--@if(\Auth::user()->user_type == 'admin')--}}
                            {{--<th>Subvention Recognised</th>--}}
                            {{--<th>Total revenue</th>--}}
                            {{--@endif--}}
                            <th>Payment Details<br>(Amount - Payment Date - Mode)</th>
                            <th>Total Amount Due</th>
                            <th>Total Amount Paid</th>
                            <th>Payment Status</th>
                            <th>Foreclosure Amount</th>
                            </thead>
                            <tbody>
                            <?php $x = 1;?>
                            @foreach($schedule as $emis)
                                <?php  $total_paid = 0; ?>
                                <tr>
                                    <td>
                                        {!! $x !!}</td>
                                    <td>{!! $emis['emi_date'] !!}</td>
                                    <?php $emi_amount = $emis['amount'];
                                        if($emis['moratorium_amount']){
                                            $emi_amount -= $emis['moratorium_amount'];
                                        }
                                    ?>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emi_amount,2)))) !!}</td>
                                    {{--@if(\Auth::user()->user_type != 'admin')--}}
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['principal_outstanding'],2)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['interest'],2)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['principal'],2)))) !!}</td>
                                    {{--@endif--}}
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['bounce_charges'],2)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['delay_penalty'],2)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['moratorium_amount'],2)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['charges_waived'],2)))) !!}</td>
                                    {{--@if(\Auth::user()->user_type == 'admin')--}}
                                    {{--<td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['subvention'],2)))) !!}</td>--}}
                                    {{--<td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['irr'],2)))) !!}</td>--}}
                                    {{--@endif--}}
                                    {{--<td>&#8377;10,000 - 18 Jan 2019 - Cash<br>&#8377;5,000 - 19 Jan 2019 - Cash</td>--}}
                                    <td>
                                        @if(isset($emis['transaction']))
                                            @foreach($emis['transaction'] as $transaction)
                                                <?php $total_paid = $total_paid + $transaction['amount']; ?>
                                                &#8377;{!! trim(str_replace('.00','',money_format('%!i',round($transaction['amount'],2)))) !!} - {!! date('Y-m-d',strtotime($transaction['payment_date'])) !!} - {!! $transaction['status'] !!} <br>
                                            @endforeach
                                        @else
                                        Not Paid
                                        @endif
                                    </td>
                                    <?php $amountdue = ($emis['amount'] + $emis['bounce_charges'] + $emis['delay_penalty']) - $emis['charges_waived'] ?>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($amountdue,0)))) !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($total_paid,0)))) !!}</td>
                                    <td>{!! $emis['payment_status'] !!}</td>
                                    <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['fore_closure_amount'],0)))) !!}</td>

                                </tr>
                                <?php $x++; ?>
                            @endforeach
                            </tbody>
                        </table>
                    @elseif(isset($schedule_new) && count($schedule_new) > 0)
                        <table class="table">
                            <thead style="background-color: #999999;color: white">
                            <th>#</th>
                            <th>EMI Date</th>
                            <th>Pre-EMI Amount</th>
                            <th>EMIs Amount</th>
                            {{--@if(\Auth::user()->user_type != 'admin')--}}
                            <th>Principal Outstanding</th>
                            <th>Interest Due</th>
                            <th>Principal Due</th>
                            {{--@endif--}}
                            <th>Bounce Charges</th>
                            <th>Penalty Charges</th>
{{--                            <th>Moratorium Amount</th>--}}
                            <th>Charges Waived off</th>
                            {{--@if(\Auth::user()->user_type == 'admin')--}}
                            {{--<th>Subvention Recognised</th>--}}
                            {{--<th>Total revenue</th>--}}
                            {{--@endif--}}
                            <th>Payment Details<br>(Amount - Payment Date - Mode)</th>
                            <th>Total Amount Due</th>
                            <th>Total Amount Paid</th>
                            <th>Payment Status</th>
                            <th>Foreclosure Amount</th>
                            </thead>
                            <tbody>
                            <?php $x = 1;?>
                            @foreach($schedule_new as $emis)
{{--                                @if($emis['emi_amount'] > 0)--}}
                                    <?php  $total_paid = 0; ?>
                                    <tr>
                                        <td>
                                            {!! $x !!}</td>
                                        <td>{!! $emis['emi_date'] !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['bpi_interest'],2)))) !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['emi_amount'],2)))) !!}</td>
                                        {{--@if(\Auth::user()->user_type != 'admin')--}}
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['principal_outstanding'],2)))) !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['interest_comp'],2)))) !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['principal_comp'],2)))) !!}</td>
                                        {{--@endif--}}
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['bounce_charges'] ?? 0, 2)))) !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['delay_penalty'] ?? 0, 2)))) !!}</td>
{{--                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['moratorium_amount'] ?? 0, 2)))) !!}</td>--}}
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['charges_waived'] ?? 0, 2)))) !!}</td>
                                        {{--@if(\Auth::user()->user_type == 'admin')--}}
                                        {{--<td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['subvention'],2)))) !!}</td>--}}
                                        {{--<td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($emis['irr'],2)))) !!}</td>--}}
                                        {{--@endif--}}
                                        {{--<td>&#8377;10,000 - 18 Jan 2019 - Cash<br>&#8377;5,000 - 19 Jan 2019 - Cash</td>--}}
                                        <td>
                                            @if(isset($emis['transaction']))
                                                @foreach($emis['transaction'] as $transaction)
                                                    <?php $total_paid = $total_paid + $transaction['amount']; ?>
                                                    &#8377;{!! trim(str_replace('.00','',money_format('%!i',round($transaction['amount'],2)))) !!} - {!! date('Y-m-d',strtotime($transaction['payment_date'])) !!} - {!! $transaction['status'] !!} <br>
                                                @endforeach
                                            @else
                                                Not Paid
                                            @endif
                                        </td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($amountdue ?? 0, 0)))) !!}</td>
                                        <td>&#8377;{!! trim(str_replace('.00','',money_format('%!i',round($total_paid ?? 0, 0)))) !!}</td>
                                        <td>{!! $emis['payment_status'] or 'pending' !!}</td>
                                        <td>&#8377; <?php echo trim(str_replace('.00','',money_format('%!i',round($emis['foreclosure_amount'])))) ?></td>

                                    </tr>
                                    <?php $x++; ?>
{{--                                @endif--}}
                            @endforeach
                            </tbody>
                        </table>
                    @else
                        <b><center>No Data Found</center></b>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@include("admin.layouts.footer")
