@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">
                    EMIs
                </h3>
            </div>

        </div>
    </div>
<?php setlocale(LC_MONETARY, 'en_IN.UTF-8'); ?>
<!-- END: Subheader -->
    <div class="m-content">
        @if(Session::has('success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('success') }}
            </div>
        @endif
        @if(Session::has('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('error') }}
            </div>
        @endif
        <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">
                            EMIs
                        </h3>
                    </div>
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <div class="col-md-12">
                            <form id="merchant_offer" class="form-horizontal" method="POST">
                                <input name="_token" value="{{ csrf_token() }}" type="hidden">
                                <input name="search" value="search" type="hidden">
                                <input name="source" value="source" type="hidden">
                                <div class="row" style="padding-bottom: 10px;margin-left: -32px;padding-top: 10px;">
                                    <div class="col-md-3">
                                        <input type="text" name="from_date" id="fl_from_date" class="form-control" placeholder="From Date" value="{{Request::old('from_date', $from_date)}}" autocomplete="off"/>
                                    </div>
                                    <div class="col-md-3">
                                        <select class="form-control" name="merchant_id" id="merchant_id">
                                            <option value="">Select Merchant</option>
                                            @foreach($merchants as $index=>$merchant)
                                                <option data-index="{!! $index !!}" value="{!! $merchant->id !!}" @if(isset($merchant_id) && $merchant_id == $merchant->id) selected="selected" @endif>{!! $merchant->merchant_name !!}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-3">
                                        <select class="form-control" name="category_id" id="category_id">
                                            <option value="">Select Category</option>
                                        </select>
                                    </div>
                                    <div class="col-md-3">
                                        <select class="form-control" name="lender_id" id="lender_id">
                                            <option value="">Select Lender</option>
                                            @foreach($lenders as $lender)
                                                <option data-index="{!! $index !!}" value="{!! $lender->id !!}" @if(isset($lender_id) && $lender_id == $lender->id) selected="selected" @endif>{!! $lender->name !!}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-3">
                                        <input type="text" name="keyword" value="" class="form-control" id="keyword" placeholder="Search By Name, Email, Phone"/>
                                    </div>

                                    <div class="col-md-3 calculate-for-emi">
                                        <input type="submit" class="btn btn-accent" value="Get EMIs"  style="margin-right: 20px;"/>
                                        <div class="btn btn-primary" onclick="return window.location = '/admin/emis';">Clear Filter</div>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <div class="emi-dues-summary m-section__content">
                            @if(isset($emis) && count($emis) > 0)
                                <div style="margin-bottom: 11px;font-size: 15px;font-weight: 800;">Total EMIs: <?php echo $applications->total() ?? count($emis); ?> <a href="?export=true&<?php echo http_build_query($_POST);?>" style="color: white;text-decoration: none;"><span class="pull-right col-md-1 form-control btn btn-primary">Export</span></a><a href="?paymentfile=true&<?php echo http_build_query($_POST);?>" style="color: white;text-decoration: none;"><span class="pull-right col-md-1 form-control btn btn-primary">Payment File</span></a><a href="?ovderdue=true&<?php echo http_build_query($_POST);?>" style="color: white;text-decoration: none;"><span class="pull-right col-md-1 form-control btn btn-primary">Over Due File</span></a></div>
                                <table class="table">
                                    <thead style="background-color: #999999;color: white">
                                    <th>#</th>
                                    <th>Name</th>
                                    <th>Merchant</th>
                                    <th>Lender</th>
                                    <th style="display: none;">Email</th>
                                    <th style="display: none;">Phone</th>
                                    <th style="display: none;">Amount</th>
                                    <th style="display: none;">Nach Status</th>
                                    <th>Application</th>
                                    </thead>
                                    <tbody>
                                    <?php $total_amount = 0;
                                    $i= 1?>
                                    @foreach($emis as $emi)
                                        <tr>
                                            <td>{!! $i !!}</td>
                                            <td>
                                                @if($emi['is_error'])
                                                    <i class="fa fa-exclamation-triangle" aria-hidden="true" style="margin-right: 6px;color: red;" title="@if($emi['is_error'] == 1) Bank Details Missing @elseif($emi['is_error']) ProForma Missing @endif"></i>
                                                @endif
                                                {!! $emi['name'] !!}</td>
                                            <td>{!! $emi['merchant_name'] !!}</td>
                                            <td>{!! $emi['lender_name'] !!}</td>
                                            <td style="display: none"><?php echo $emi['email'] ?? ''; ?></td>
                                            <td style="display: none"><?php echo $emi['phone'] ?? ''; ?></td>
                                            <td style="display: none">&#8377;<?php echo isset($emi['emi_amount']) ? str_replace('.00','',money_format('%!i', $emi['emi_amount'])) : '0'; ?></td>
                                            <td style="display: none"><?php echo $emi['nach_status'] ?? ''; ?></td>
                                            <td><a class="btn btn-primary" href="/admin/consumer-applications/edit/{!! $emi['id'] !!}" target="_blank">Go To Application</a></td>
                                        </tr>
                                        <?php $total_amount += $emi['emi_amount'] ?? 0;
                                        $i++;?>
                                    @endforeach
                                    <tr style="display: none;background-color: #999999;color: white">
                                        <td colspan="7" style="text-align: center"><strong>Total EMI Amount</strong></td>
                                        <td><strong>&#8377;{!! str_replace('.00','',money_format('%!i',$total_amount)) !!}</strong></td>
                                    </tr>
                                    </tbody>
                                </table>
                            @else
                                <b><center>No Data Found</center></b>
                            @endif
                        </div>
                        <div>
                            {!!$applications->appends(\Request::except('page', '_token'))->render()!!}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@include("admin.layouts.footer")
