@extends('admin.layouts.app')
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
    .small-box p {
        font-size: 12px !important;
    }

    :root {
        --bg-black: #121213;
    }

    .skin-blue .content-header {
        background: var(--bg-black) !important;
    }

    .content {
        background: var(--bg-black) !important;
        color: #8a99b5 !important;
    }

    .bg-red, .callout.callout-danger, .alert-danger, .alert-error, .label-danger, .modal-danger .modal-body {
        background: var(--bg-black) !important;
    }

    .small-box {
        border-radius: 10px !important
    }

    .bg-black {
        background: #222222 !important
    }

    /* custom style end */
    #bar-chart * {
        font-family: open sans;
    }

    #chart-title {
        width: 100%;
        text-align: center;
        font-size: 18px;
        font-family: open sans;
    }

    #bar-chart {
        width: 1200px;
        height: 350px;
        margin: auto;
    }

    .inner {
        color: #ffcc00 !important;
    }

    .small-box > .small-box-footer {
        background: #3c8dbc !important;

    }

</style>
@section('content')
    <section class="content">
        @if(\Auth::user()->details->is_production != 1 || \Auth::user()->hasRole('admin') || \Auth::user()->hasRole('super-admin') )
            <div class="row">
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => $all_tot_leads,
                        "title" => "Total Leads this month",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.leads.index')
                    ])
                </div>
                <!-- ./col -->
                @if(\Auth::user()->hasRole('admin') || \Auth::user()->hasRole('super-admin'))
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_unpaid_pay,
                            "title" => "In Pending $",
                            "icon" => 'fa fa-',
                            "route" => route('admin.payments.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6 pak">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_paid_pay,
                            "title" => "Target Achieved $",
                            "icon" => 'fa fa-',
                            "route" => route('admin.invoices.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => app(\App\Repositories\Admin\TeamRepository::class)->where('id','!=',\App\Models\Team::POOL)->sum('target'),
                            "title" => "Total Teams Target $",
                            "icon" => 'fa fa- ',
                            "route" => url('admin/teams')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_charge_back,
                            "title" => "Total Charge Back $",
                            "icon" => 'fa fa- ',
                            "route" => url('admin/payments?month='.\Carbon\Carbon::now()->month)
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_refund,
                            "title" => "Total Refund $",
                            "icon" => 'fa fa- ',
                            "route" => url('admin/payments?month='.\Carbon\Carbon::now()->month)
                        ])
                    </div>
                @else
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_paid_inv.'|'.$tot_unpaid_inv,
                            "title" => "No.Paid|Unpaid payments",
                            "icon" => 'fa fa-',
                            "route" => route('admin.payments.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6 pak">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_paid_pay.'|'.$tot_unpaid_pay,
                            "title" => "This Month Paid|Unpaid Amount($)",
                            "icon" => 'fa fa-',
                            "route" => route('admin.invoices.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_lead,
                            "title" => "My Total Leads this month",
                            "icon" => 'fa fa-shopping- ',
                            "route" => url('admin/leads?user_id='.\Auth::id().'&month='.\Carbon\Carbon::now()->month)
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_charge_back,
                            "title" => "Total Charge Back $",
                            "icon" => 'fa fa- ',
                            "route" => url('admin/payments?month='.\Carbon\Carbon::now()->month)
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_refund,
                            "title" => "Total Refund $",
                            "icon" => 'fa fa- ',
                            "route" => url('admin/payments?month='.\Carbon\Carbon::now()->month)
                        ])
                    </div>
                @endif


            </div>
            <div class="row">
                @if(\Auth::user()->hasRole('admin') || \Auth::user()->hasRole('super-admin'))

                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => app(\App\Repositories\Admin\LeadRepository::class)->whereDate('created_at', \Carbon\Carbon::today())->where('user_id','!=',null)->count('id'),
                            "title" => "All Today Lead(s)(all teams)",
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads?user_id='.\Auth::id())
                        ])
                    </div>
                    <?php

                    $team_ids = App\Models\Team::where('id', '!=', App\Models\Team::POOL)->get();

                    for ($z = 0; $z < count($team_ids); $z++) {
                    $all_tot_leads = app(App\Repositories\Admin\LeadRepository::class)->whereNotNull('user_id')->whereRaw('MONTHNAME(created_at) = MONTHNAME(NOW()) AND YEAR(created_at) = YEAR(NOW())')->where('team_id', $team_ids[$z]->id)->count('id');
                    ?>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $all_tot_leads,
                            "title" => "This Month Lead(s)".$team_ids[$z]->name,
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads')
                        ])
                    </div>
                    <?php
                    }
                    ?>
                @else
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $today,
                            "title" => "My Today Lead(s)",
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads?user_id='.\Auth::id())
                        ])
                    </div>
                    <!-- ./col -->
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_lead_paid,
                            "title" => "My Today Paid/Won Lead(s)",
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads?user_id='.\Auth::id().'&status_id=3')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_lead_won,
                            "title" => "My Today Stripe Paid Lead(s)",
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads?user_id='.\Auth::id().'&status_id=3')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "black",
                            "counter" => $tot_lead_owned,
                            "title" => "My Today Owned Lead(s)",
                            "icon" => 'fa fa-',
                            "route" => url('admin/leads?user_id='.\Auth::id().'&status_id=3')
                        ])
                    </div>
                    @if(\Auth::user()->details->team_lead == 1)
                        <div class="col-lg-3 col-xs-6">
                            @include("admin.counter_widget", [
                                "bgColor" => "black",
                                "counter" => $tot_team_paid_pay,
                                "title" => "Your Team Standing $",
                                "icon" => 'fa fa-',
                                "route" => url('admin/payments')
                            ])
                        </div>
                    @endif
                @endif
            </div>
        @else
            <div class="row">
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => \App\Models\Order::count('id'),
                        "title" => "Total Orders this month",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.orders.index')
                    ])
                </div>
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => \App\Models\Order::where('production_user_id',\Auth::id())->count('id'),
                        "title" => "My Total Orders",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.orders.index')
                    ])
                </div>
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => \App\Models\Order::where('production_user_id',\Auth::id())->where('status_id',\App\Models\Order::COMPLETED)->count('id'),
                        "title" => "My Orders Completed",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.orders.index')
                    ])
                </div>
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => \App\Models\Order::where('production_user_id',\Auth::id())->where('status_id',\App\Models\Order::ONHOLD)->count('id'),
                        "title" => "My Orders On-Hold",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.orders.index')
                    ])
                </div>
                <div class="col-lg-3 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "rgb(65, 88, 146)",
                        "counter" => \App\Models\Order::where('production_user_id',\Auth::id())->where('status_id',\App\Models\Order::PROCESS)->count('id'),
                        "title" => "My Orders In-Progress",
                        "icon" => 'fa fa-shopping- ',
                        "route" => route('admin.orders.index')
                    ])
                </div>
                @if(\Auth::user()->details->is_production == 1 && \Auth::user()->details->is_production_team_lead == 1 )
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "rgb(65, 88, 146)",
                            "counter" => \App\Models\Order::where('production_team_id',\Auth::user()->details->production_team_id)->count('id'),
                            "title" => "Total Team Orders this month",
                            "icon" => 'fa fa-shopping- ',
                            "route" => route('admin.orders.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "rgb(65, 88, 146)",
                            "counter" => \App\Models\Order::where('production_team_id',\Auth::user()->details->production_team_id)->where('status_id',\App\Models\Order::COMPLETED)->count('id'),
                            "title" => "Total Team Orders Completed",
                            "icon" => 'fa fa-shopping- ',
                            "route" => route('admin.orders.index')
                        ])
                    </div>
                    <div class="col-lg-3 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "rgb(65, 88, 146)",
                            "counter" => \App\Models\Order::where('production_team_id',\Auth::user()->details->production_team_id)->where('status_id',\App\Models\Order::PROCESS)->count('id'),
                            "title" => "Total Team Orders In-Progress",
                            "icon" => 'fa fa-shopping- ',
                            "route" => route('admin.orders.index')
                        ])
                    </div>
                @endif
            </div>
        @endif

    </section>

    <section id="extraData">


    </section>

    <section class="content" style="background: #121213">

        <div class="row" style="">
            <div class="col-lg-6">
                <div class="box box-success" style="border-top-color: #ffcc00;">
                    <div class="box-header with-border">`
                        <h3 class="box-title">Leads Reports </h3>
                    </div>
                    <div class="box-body chart-responsive">
                        <canvas id="myChart" style="height: 300px;"></canvas>
                    </div>
                    <!-- /.box-body -->
                </div>

            </div>

            <div class="col-lg-6">
                <div class="box box-success" style="border-top-color: #ffcc00;">
                    <div class="box-header with-border">`
                        <h3 class="box-title">Earnings Reports </h3>
                    </div>
                    <div class="box-body chart-responsive">
                        <canvas id="myChart2" style="height: 300px;"></canvas>
                    </div>
                    <!-- /.box-body -->
                </div>

            </div>

        </div>


    </section>

@endsection
@push("scripts")
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
    <script>

        var ctx = document.getElementById("myChart").getContext('2d');
        var labels =
                {!! json_encode($months) !!}
        var data =
                {!! json_encode($counts_orders) !!}

        var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels,
                    datasets: [{
                        label: 'Number of leads owned/won per month',
                        data,
                        backgroundColor: "#000"
                    }]
                }
            });


        var ctx = document.getElementById("myChart2").getContext('2d');
        var labels =
                {!! json_encode($invmonths) !!}
        var data =
                {!! json_encode($tot_amount) !!}

        var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels,
                    datasets: [{
                        label: 'Earnings Per Month',
                        data,
                        backgroundColor: "#000"
                    }]
                }
            });
    </script>
    <script>
        $(window).on('load', function () {

            setTimeout(function () {

                $('#extraData').load('{{route('admin.extraIndex')}}');

            }, 500);
        });

    </script>
@endpush