@extends('layouts.admin_master')
@section('page-title') 
    Admin | Dashboard
@endsection
@section('page-content')
<div class="row">
    <div class="col-lg-12 text-center welcome-message">
        <h2>Welcome to Airtime Sales Admin Dashboard</h2>
        <!-- <p>
            Special <strong>Admin Theme</strong> for medium and large web applications with very clean and
            aesthetic style and feel.
        </p> -->
    </div>
</div>
<div class="row">
            <div class="col-lg-3">
                <div class="hpanel">
                    <div class="panel-body text-center h-200">
                        <i class="pe-7s-graph1 fa-4x"></i>

                        <h1 class="m-xs">MK {{ number_format($current_year_transactions_sum) }}</h1>

                        <h3 class="font-extra-bold no-margins text-success">
                           Sales({{ date('Y') }})
                        </h3>
                        <small>Sales from Merchants to customers</small>
                    </div>
                    <div class="panel-footer">
                    Sales from Merchants to end users
                    </div>
                </div>
            </div>
            <div class="col-lg-3">
                <div class="hpanel stats">
                    <div class="panel-body h-200">
                        <div class="stats-title pull-left">
                            <h4>Merchants</h4>
                        </div>
                        <div class="stats-icon pull-right">
                            <i class="pe-7s-share fa-4x"></i>
                        </div>
                        <div class="m-t-xl">
                            <h3 class="m-b-xs text-danger">{{ number_format($merchant_count) }}</h3>
                    <span class="font-bold no-margins">
                        Merchants
                    </span>

                            <!-- <div class="progress m-t-xs full progress-small">
                                <div style="width: 55%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="55"
                                     role="progressbar" class=" progress-bar progress-bar-success">
                                    <span class="sr-only">35% Complete (success)</span>
                                </div>
                            </div> -->

                            <!-- <div class="row">
                                <div class="col-xs-6">
                                    <small class="stats-label">Pages / Visit</small>
                                    <h4>7.80</h4>
                                </div>

                                <div class="col-xs-6">
                                    <small class="stats-label">% New Visits</small>
                                    <h4>76.43%</h4>
                                </div>
                            </div> -->
                        </div>
                    </div>
                    <div class="panel-footer">
                        Registered Merchants
                    </div>
                </div>
            </div>
            <div class="col-lg-3">
                <div class="hpanel stats">
                    <div class="panel-body h-200">
                        <div class="stats-title pull-left">
                            <h4>Dealers</h4>
                        </div>
                        <div class="stats-icon pull-right">
                            <i class="pe-7s-monitor fa-4x"></i>
                        </div>
                        <div class="m-t-xl">
                            <h1 class="text-success">{{ number_format($dealer_count) }}</h1>
                    <span class="font-bold no-margins">
                        <!-- Social users -->
                    </span>
                            <br/>
                            <!-- <small>
                                Lorem Ipsum is simply dummy text of the printing and <strong>typesetting
                                industry</strong>. Lorem Ipsum has been.
                            </small> -->
                        </div>
                    </div>
                    <div class="panel-footer">
                        Registered Dealers
                    </div>
                </div>
            </div>
            <div class="col-lg-3">
                <div class="hpanel stats">
                    <div class="panel-body h-200">
                        <div class="stats-title pull-left">
                            <h4>Sales (Today)</h4>
                        </div>
                        <div class="stats-icon pull-right">
                            <i class="pe-7s-cash fa-4x"></i>
                        </div>
                        <div class="clearfix"></div>
                        <div class="flot-chart">
                            <div class="flot-chart-content" id="flot-income-chart"></div>
                        </div>
                        <div class="m-t-xs">

                            <div class="row">
                                <div class="col-xs-5">
                                    <small class="stat-label">Today</small>
                                    <h4>{{ number_format($current_day_transactions) }} </h4>
                                </div>
                                <div class="col-xs-7">
                                    <small class="stat-label">Last week</small>
                                    <h4>{{ number_format($last_weeek_transactions) }} <i class="fa fa-level-up text-success"></i></h4>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer">
                        Merchant Sales to end users
                    </div>
                </div>
            </div>
        </div>
<div class="row">
            <div class="col-lg-3">
                <div class="hpanel stats">
                    <div class="panel-heading">
                        <div class="panel-tools">
                            <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                            <a class="closebox"><i class="fa fa-times"></i></a>
                        </div>
                        Top Merchants
                    </div>
                    <div class="panel-body list">
                        <div class="stats-title pull-left">
                            <h4>Activity</h4>
                        </div>
                        <div class="stats-icon pull-right">
                            <i class="pe-7s-science fa-4x"></i>
                        </div>
                        <div class="m-t-xl">
                            <span class="font-bold no-margins">
                                Top Merchants by Sales
                            </span>
                            <br/>
                            <!-- <small>
                                Lorem Ipsum is simply dummy text of the printing simply all dummy text. Lorem Ipsum is
                                simply dummy text of the printing and typesetting industry. Lorem Ipsum has been.
                            </small> -->
                        </div>
                        <div class="row m-t-md">
                            <div class="col-lg-6">
                                <h3 class="no-margins font-extra-bold text-success">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ number_format($top_merchants[0]->total_amount) }}
                                    @else
                                        {{ 'N/A' }}
                                    @endif
                                </h3>

                                <div class="font-bold">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ $top_merchants[0]->fullname }}
                                    @else
                                        {{ 'N/A' }}
                                    @endif
                                </div>
                            </div>
                            @if($top_merchants->count() > 1)
                            <div class="col-lg-6">
                                <h3 class="no-margins font-extra-bold text-success">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ number_format($top_merchants[1]->total_amount) }}
                                    @else
                                        {{ 'N/A' }}
                                    @endif
                                </h3>

                                <div class="font-bold">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ $top_merchants[1]->fullname }}
                                    @else
                                        {{ 'N/A' }}
                                    @endif
                                </div>
                            </div>
                             @endif
                        </div>
                        @if($top_merchants->count() > 2)
                        <div class="row m-t-md">
                            <div class="col-lg-6">
                                <h3 class="no-margins font-extra-bold text-warning ">
                                    
                                    @if($top_merchants->isEmpty() == false)
                                        {{ number_format($top_merchants[2]->total_amount) }}
                                    @else
                                        {{ '0.00' }}
                                    @endif
                                </h3>

                                <div class="font-bold">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ $top_merchants[2]->fullname }} 
                                    @else
                                        {{ '0.00' }}
                                    @endif
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <h3 class="no-margins font-extra-bold text-warning">
                                    
                                    @if($top_merchants->isEmpty() == false)
                                        {{ number_format($top_merchants[3]->total_amount) }}
                                    @else
                                        {{ '0.00' }}
                                    @endif
                                </h3>

                                <div class="font-bold">
                                    @if($top_merchants->isEmpty() == false)
                                        {{ $top_merchants[3]->fullname }} 
                                    @else
                                        {{ 'N/A' }}
                                    @endif
                                </div>
                            </div>

                        </div>
                        @endif
                    </div>
                    <div class="panel-footer">
                        <!-- This is standard panel footer -->
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="hpanel">
                    <div class="panel-heading">
                        <div class="panel-tools">
                            <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                            <a class="closebox"><i class="fa fa-times"></i></a>
                        </div>
                        Recent Dealer Sales to Merchants 
                    </div>
                    <div class="panel-body list">
                        <div class="table-responsive project-list">
                            <table class="table table-striped">
                                <thead>
                                <tr>
                                    <th>Merchant</th>
                                    <th>Amount (MK)</th>
                                    <th>Status</th>
                                    <th>Dealer Name</th>
                                    <th>Date</th>
                                </tr>
                                </thead>
                                <tbody>
                                @forelse ($merchant_topups as $row)
                                <tr>
                                    <td>{{ $row->merchantInfo->fullname }}</td>
                                    <td>{{ number_format($row->amount) }}</td>
                                    <td class="<?php echo ($row->status == 'Success') ? "text-success" : "text-warning"; ?>">{{ $row->status }}</td>
                                    <td>{{ ucfirst($row->orgUserInfo->name) }}</td>
                                    <td>{{ Carbon\Carbon::parse($row->created_at)->format('F d, Y') }}</td>
                                </tr>
                                @empty
                                    <tr>                      
                                        <td colspan="5">No Data</td>
                                    </tr>
                                @endforelse                                
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-3">
                <div class="hpanel">
                    <div class="panel-heading">
                        <div class="panel-tools">
                            <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                            <a class="closebox"><i class="fa fa-times"></i></a>
                        </div>
                        Admin Activity
                    </div>
                    <div class="panel-body list">

                        <div class="pull-right">
                            <!-- <a href="" class="btn btn-xs btn-default">Today</a> -->
                            <!-- <a href="" class="btn btn-xs btn-default">Month</a> -->
                        </div>
                        <div class="panel-title">Recent Sales</div>
                        <small class="fo">Sale from Admin to Dealers</small>
                        <div class="list-item-container">
                            @forelse ($dealer_topups as $row)
                                <div class="list-item">
                                    <h3 class="no-margins font-extra-bold text-success">MK{{ number_format($row->amount) }}</h3>
                                    <small>Dealer : {{ $row->orgInfo->name }}</small>
                                    <div class="pull-right font-bold"> 
                                        &nbsp;
                                        {{ $row->created_at }} 
                                        <!-- <i class="fa fa-date text-success"></i> -->
                                    </div>
                                </div>
                            @empty
                                <tr>                      
                                    <td colspan="5">No Data</td>
                                </tr>
                            @endforelse
                            
                            
                        </div>

                    </div>
                </div>
            </div>
        </div>
@endsection

@section('page-js')

<!-- third party js -->
<!-- <script src="{{ url('public/assets/js/vendor/apexcharts.min.js')}}"></script> -->
<!-- <script src="{{ url('public/assets/js/vendor/jquery-jvectormap-1.2.2.min.js')}}"></script> -->
<!-- <script src="{{ url('public/assets/js/vendor/jquery-jvectormap-world-mill-en.js')}}"></script> -->
<!-- third party js ends -->

<!-- demo app -->
<!-- <script src="{{ url('public/assets/js/pages/demo.dashboard.js')}}"></script> -->
<!-- end demo js-->

@endsection
