@extends('layout.main')

@section('title', config('app.name') . ' | Welcome Dashboard')

@section('content')

<!-- main content start-->
<div id="page-wrapper">

    <div class="main-page">

        <div class="widget-shadow">

            @include('partials.errors')
            @include('partials.success')

        </div>


        <!-- ========================================================= -->
        <!-- DASHBOARD STATISTICS -->
        <!-- ========================================================= -->

        <div class="row-one">

            <!-- TODAY DOCUMENTS -->
            <div class="col-md-4 widget">

                <div class="stats-left">

                    <h5>Today</h5>
                    <h4>Documents</h4>

                </div>

                <div class="stats-right">

                    @if(isset($tot_today))
                        <label>{{ $tot_today }}</label>
                    @else
                        <label>0</label>
                    @endif

                </div>

                <div class="clearfix"></div>

            </div>


            <!-- TOTAL DOCUMENTS -->
            <div class="col-md-4 widget states-mdl">

                <div class="stats-left">

                    <h5>Total</h5>
                    <h4>Documents</h4>

                </div>

                <div class="stats-right">

                    @if(isset($totel_docs))
                        <label>{{ $totel_docs }}</label>
                    @else
                        <label>0</label>
                    @endif

                </div>

                <div class="clearfix"></div>

            </div>


            <!-- TOTAL CUSTOMERS -->
            <div class="col-md-4 widget states-last">

                <div class="stats-left">

                    <h5>Total</h5>
                    <h4>Customers</h4>

                </div>

                <div class="stats-right">

                    @if(isset($tot_customer))
                        <label>{{ $tot_customer }}</label>
                    @else
                        <label>0</label>
                    @endif

                </div>

                <div class="clearfix"></div>

            </div>

            <div class="clearfix"></div>

        </div>


        <!-- ========================================================= -->
        <!-- PREVIOUS MONTHS + LATEST DOCUMENTS -->
        <!-- ========================================================= -->

        <div class="row">


            <!-- ===================================================== -->
            <!-- PREVIOUS MONTHS -->
            <!-- ===================================================== -->

            <div class="col-md-4 stats-info widget">

                <div class="stats-title">

                    <h4 class="title">
                        Previous Months
                    </h4>

                </div>


                <div class="stats-body">

                    <ul class="list-unstyled">


                        @if(isset($get_documents_months) && $get_documents_months->count() > 0)

                            @php
                                $month_count = 0;
                            @endphp


                            @foreach($get_documents_months as $month => $documents)

                                @php
                                    $month_count++;

                                    $month_date = \Carbon\Carbon::createFromFormat(
                                        'Y-m',
                                        $month
                                    );
                                @endphp


                                <li
                                    @if($month_count == $get_documents_months->count())
                                        class="last"
                                    @endif
                                >

                                    {{ $month_date->format('F Y') }}

                                    <span class="pull-right">

                                        {{ $documents->count() }}

                                        {{ $documents->count() == 1 ? 'Document' : 'Documents' }}

                                    </span>

                                </li>


                            @endforeach


                        @else

                            <li class="last">

                                No Previous Documents

                                <span class="pull-right">
                                    0 Documents
                                </span>

                            </li>

                        @endif


                    </ul>

                </div>

            </div>


            <!-- ===================================================== -->
            <!-- LATEST DOCUMENTS -->
            <!-- ===================================================== -->

            <div class="col-md-8 stats-info stats-last widget-shadow">


                <table class="table stats-table">


                    <thead>

                    <tr>

                        <th>Serial No</th>

                        <th>Customer Id</th>

                        <th>Customer Name</th>

                        <th>Doc-id</th>

                        <th>Status</th>

                    </tr>

                    </thead>


                    <tbody>


                    @if(isset($get_documents))


                        @forelse($get_documents as $get_document)

                            <tr>

                                <th scope="row">
                                    {{ $loop->iteration }}
                                </th>


                                <td>
                                    {{ $get_document->customer_id }}
                                </td>


                                <td>
                                    {{ $get_document->customer_name }}
                                </td>


                                <td>
                                    {{ $get_document->document_id }}
                                </td>


                                <td>

                                    <a
                                        href="/document-view/{{ $get_document->id }}"
                                        class="badge badge-success"
                                    >
                                        View
                                    </a>

                                </td>

                            </tr>


                        @empty


                            <tr>

                                <td colspan="5" class="text-center">

                                    No Record Found!

                                </td>

                            </tr>


                        @endforelse


                    @else


                        <tr>

                            <td colspan="5" class="text-center">

                                No Record Found!

                            </td>

                        </tr>


                    @endif


                    </tbody>

                </table>


            </div>


            <div class="clearfix"></div>

        </div>


        <div class="clearfix"></div>

    </div>

</div>

<!-- footer -->

@endsection