@if(isset($consumer_applications) && count($consumer_applications) > 0)
    @if(isset($total_applications))
        <div><span class="badge">Total Applications: {!! $total_applications or 0 !!}</span></div>
    @endif
    <table class="table m-table table-hover">
        <thead>
        <tr>
            <th>#</th>
            <th>Application Date</th>
            <th>Customer Name</th>
            <th>Email</th>
            <th>Mobile</th>
            <th>Loan Amount</th>
            <th>Approved Amount</th>
            <th>Advisor</th>
            <th>Status</th>
            @if(\Auth::user()->user_type != 'merchant')
                <th>Actions</th>
            @else
                <th>Disbursed Date</th>
            @endif
        </tr>
        </thead>
        <tbody>
        <?php setlocale(LC_MONETARY, 'en_IN.UTF-8'); ?>
        @foreach($consumer_applications as $key => $consumer_application)
            <tr>
                <th scope="row">{{ $key+1 }}</th>
                <td>
                    {!! date('F d, Y',strtotime($consumer_application->created_at)) !!}
                </td>
                <td>
                    {{ ucwords(strtolower($consumer_application->name)) }}
                </td>
                <td>
                    {{ strtolower($consumer_application->email) }}
                </td>
                <td>
                    {{ $consumer_application->mobile_number }}
                </td>
                <td>
                    &#8377;{!! str_replace('.00','',money_format('%!i',$consumer_application->loan_amount)) !!}
                </td>
                <td>
                    @if($consumer_application->approved_amount == 0 || in_array($consumer_application->state,['rejected', 'aborted']))
                        @if(in_array($consumer_application->state,['rejected', 'aborted'])) -
                        @else Application is in process
                        @endif
                    @else &#8377;{!! str_replace('.00','',money_format('%!i',$consumer_application->approved_amount)) !!}
                    @endif
                </td>
                <td>
                    @if(isset($consumer_application->advisor->name)){{ucwords($consumer_application->advisor->name)}} @endif
                </td>
                <td>
                    {{ ucwords($consumer_application->state) }}
                </td>
                @if(\Auth::user()->user_type == 1)
                    @if(\Auth::user()->user_type == 1 && ($consumer_application->state == 'disbursed' || $consumer_application->state == 'nach registered'))
                        <td>
                            <a href="{{ asset('application/payment_history/'.$consumer_application->hashed_id) }}" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill"
                            title="View">
                                View
                            </a>
                        </td>
                    @else
                        <td>
                            <a href="{{ asset('application/'.$consumer_application->hashed_id) }}" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill"
                               title="View">
                                Edit
                            </a>
                        </td>
                    @endif
                @else
                    <td>
                        @if($consumer_application->state == 'disbursed')
                            @if(isset($consumer_application->status_created_at))
                                {!! date('F d, Y',strtotime($consumer_application->status_created_at)) !!}
                            @endif
                        @endif
                    </td>
                @endif
            </tr>
        @endforeach
        </tbody>
    </table>
    <div class="text-center">
        {!!$consumer_applications->appends(\Request::except('page', '_token'))->render()!!}
    </div>
@else
    <b><center>No applications under {!! $status !!} status </center></b>
@endif