@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;

    }




    .skin-blue .main-header .navbar {
        background: linear-gradient(289.37deg, #26AFBF 1.81%, #239EB3 22.86%, #1E7295 104.01%, #152C65 125.48%, #14225F 133.38%);

    }

    .small-box {
        background: #fff !important;
        border-radius: 5px !important;
        padding: 30px 20px;
        text-align: center;
        height: 200px;
    }

    .small-box h3,.small-box p {
        color: #269DAB;
    }


    .small-box .d-flex {
        display: flex;
        justify-content: center;
        margin-bottom: 20px;
    }

    .small-box .d-flex .inner{
        text-align: left;
        width:60%
    }

    .small-box .icon{
        position: unset !important;
        font-size: 60px !important;
        color: #26AFBF !important;
        width:40%
    }
    .small-box>.small-box-footer {
        width: auto;
        background: transparent !important;
        border: 1px solid #26AFBF;
        color: #26AFBF !important;
        border-radius: 20px;
        display: unset !important;
        padding: 8px 25px !important;
        position: absolute !important;
        bottom: 25px;
        left: 50%;
        transform: translate(-50%, 0);
    }

    .small-box:hover {
        background: linear-gradient(127deg, #26AFBF, #152C65) !important;
    }

    .small-box:hover a.small-box-footer {
        color: #fff !important;
        border-color: #fff;
    }

    .small-box:hover .d-flex .icon {
        color: #fff !important;
    }
    .small-box:hover .inner h3,.small-box:hover .inner p {
        color: #fff !important;
    }
    section.content {
        background: #dfdfdf !important;
        padding-top: 60px;
    }
    section.content-header.clearfix {
        position: absolute;
        width: 100%;
        background: transparent !important;
        left: 0;
    }



    .breadcrumb>.active{
        color: #00b2c1;
        font-size: 16px;
    }
    .card.card-widget.widget-user-2 .card-footer a.nav-link:hover {
        background: #ffffff33;
        border-radius: 20px;
    }
    .small-box h3 {
        font-size: 50px;
    }


</style>
@section('content')
    @php

        use Carbon\Carbon;
    $filterMonth = ($month > 0) ? $month : \Carbon\Carbon::now()->month;
    @endphp
    @if(\Auth::user()->details->is_production != 1 && \Auth::user()->id !=2 && \Auth::user()->id !=1  )
        {{--        for leads and all sales user indivisual stats--}}
        <section class="content">
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" =>number_format(app(\App\Repositories\Admin\UserDetailRepository::class)
                    ->where('user_id', Auth::id())
                    ->value('target'),2),
                    "title" => "$ Total Target",
                    "icon" => 'fa fa-dollar',
                    "route" =>route('admin.payments.index')
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('user_id', Auth::id())
        ->where('status', 1)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->sum('price'),2),
                   "title" => "$ Target Achieved",
                    "icon" => 'fa fa-dollar',
                    "route" => url('admin/payments?user_id='.Auth::id().'&status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('user_id', Auth::id())
        ->where('status', 0)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->sum('price'),
                     "title" => "$ Target Pending",
                    "icon" => 'fa fa-dollar',
                    "route" => url('admin/payments?user_id='.Auth::id().'&status=0&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            {{--        leads--}}
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\LeadRepository::class)
        ->where('user_id', Auth::id())
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total Leads",
                    "icon" => 'fa fa-filter',
                    "route" => url('admin/leads?user_id='.Auth::id().'&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" =>app(\App\Repositories\Admin\LeadRepository::class)
        ->where('user_id', Auth::id())
         ->where('status_id', 4)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Owned Leads",
                    "icon" => 'fa fa-filter',
                    "route" => url('admin/leads?user_id='.Auth::id().'&lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\LeadRepository::class)
        ->where('user_id', Auth::id())
         ->where('status_id', 3)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Paid Leads",
                    "icon" => 'fa fa-filter',
                    "route" =>  url('admin/leads?user_id='.Auth::id().'&lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            {{--//payments--}}
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('user_id', Auth::id())
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total No. of Payments",
                    "icon" => 'fa fa-money',
                    "route" => url('admin/payments?user_id='.Auth::id().'&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('user_id', Auth::id())
         ->where('status', 1)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total No. of Paid Payments",
                    "icon" => 'fa fa-money',
                     "route" => url('admin/payments?user_id='.Auth::id().'&status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>

            @if(\Auth::user()->details->team_lead == 1 )
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\UserDetailRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->whereNull('deleted_at')
            ->sum('target').'|'.app(\App\Repositories\Admin\PaymentRepository::class)
                    ->where('team_id', \Auth::user()->details->team_id)
                    ->where('status', 1)
                    ->whereNull('deleted_at')
                    ->whereYear('created_at', Carbon::now()->year)
                    ->whereMonth('created_at', $filterMonth)
                    ->sum('price'),
                        "title" => "Team Target",
                        "icon" => 'fa fa-money',
                       "route" => route('admin.payments.index')
                    ])
                </div>
            @endif
        </section>

        @if(\Auth::user()->details->team_lead == 1 )
            <div class="col-md-12">
                <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Team Leads Stats</h4>
            </div>

            <section class="content">
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" =>app(\App\Repositories\Admin\UserDetailRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->whereNull('deleted_at')
            ->sum('target'),
                        "title" => "$ Team Target",
                        "icon" => 'fa fa-dollar',
                        "route" =>route('admin.teams.index')
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\LeadRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
             ->where('status_id', 4)
              ->where('lead_status', 'Ppc')
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', $filterMonth)
            ->count('id'),
                       "title" => "$ Total PPC Leads",
                        "icon" => 'fa fa-google',
                        "route" => url('admin/leads?platform=Ppc&lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\LeadRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
             ->where('status_id', 4)
             ->where('lead_status', 'Social Media')
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', $filterMonth)
            ->count('id'),
                         "title" => "$ Total SMM Leads",
                        "icon" => 'fa fa-facebook',
                        "route" => url('admin/payments?platform=Social%20Media&lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                {{--        leads--}}
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
             ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', $filterMonth)
            ->sum('price'),
                        "title" => "Team Target Achieved",
                        "icon" => 'fa fa-filter',
                        "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <?php
                $tot_leads_paid_ppc = app(\App\Repositories\Admin\LeadRepository::class)
                    ->where('team_id', \Auth::user()->details->team_id)
                    ->where('status_id', 3)
                    ->where('lead_status', 'ppc')
                    ->whereNull('deleted_at')
                    ->whereYear('created_at', Carbon::now()->year)
                    ->whereMonth('created_at', $filterMonth)
                    ->pluck('id');

                $tot_leads_paid_smm =  app(\App\Repositories\Admin\LeadRepository::class)
                    ->where('team_id', \Auth::user()->details->team_id)
                    ->where('status_id', 3)
                    ->where('lead_status', 'Social Media')
                    ->whereNull('deleted_at')
                    ->whereYear('created_at', Carbon::now()->year)
                    ->whereMonth('created_at', $filterMonth)
                    ->pluck('id');

                ?>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" =>count($tot_leads_paid_ppc),
                        "title" => "PPC Paid Leads",
                        "icon" => 'fa fa-google',
                        "route" => url('admin/leads?platform=Ppc&lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" =>count($tot_leads_paid_smm),
                        "title" => "SMM Paid Leads",
                        "icon" => 'fa fa-facebook',
                        "route" =>  url('admin/leads?platform=Social%20Media&lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                {{--//payments--}}
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" =>app(\App\Repositories\Admin\TeamRepository::class)
                        ->where('id', \Auth::user()->details->team_id)
                        ->value('target')-app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
             ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', $filterMonth)
            ->sum('price'),
                        "title" => "Target Remaining",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
                        ->whereIn('lead_id', $tot_leads_paid_ppc)
            ->where('team_id',\Auth::user()->details->team_id)
            ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', $filterMonth)
            ->sum('price'),
                        "title" => "Paid Amount PPC",
                        "icon" => 'fa fa-money',
                         "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
                        ->whereIn('lead_id', $tot_leads_paid_smm)
            ->where('team_id',\Auth::user()->details->team_id)
            ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at',$filterMonth)
            ->sum('price'),
                        "title" => "Paid Amount SMM",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>


                <div class="col-md-12">
                    <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Current Day Team Stats</h4>
                </div>


                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereDate('created_at', Carbon::today())
            ->sum('price'),
                        "title" => "Today Achieved",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>

                <?php
                $tot_leads_paid_ppc_today = app(\App\Repositories\Admin\LeadRepository::class)
                    ->where('team_id', \Auth::user()->details->team_id)
                    ->where('status_id', 3)
                    ->where('lead_status', 'ppc')
                    ->whereNull('deleted_at')
                    ->whereDate('created_at', Carbon::today())
                    ->pluck('id');

                $tot_leads_paid_smm_today =  app(\App\Repositories\Admin\LeadRepository::class)
                    ->where('team_id', \Auth::user()->details->team_id)
                    ->where('status_id', 3)
                    ->where('lead_status', 'Social Media')
                    ->whereNull('deleted_at')
                    ->whereDate('created_at', Carbon::today())
                    ->pluck('id');

                ?>


                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => count($tot_leads_paid_ppc_today) .'|'. app(\App\Repositories\Admin\PaymentRepository::class)
                        ->whereIn('lead_id', $tot_leads_paid_ppc_today)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereDate('created_at', Carbon::today())
            ->sum('price'),
                        "title" => "PPC Leads | Amount",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>


                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => count($tot_leads_paid_smm_today) .'|'.  app(\App\Repositories\Admin\PaymentRepository::class)
                        ->whereIn('lead_id', $tot_leads_paid_smm_today)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)
            ->whereNull('deleted_at')
            ->whereDate('created_at', Carbon::today())
            ->sum('price'),
                        "title" => "SMM Leads | Amount",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>


                <div class="col-md-12">
                    <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Team Payment Stats Break Down</h4>
                </div>


                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)->where('type', 4)
            ->whereNull('deleted_at')
           ->whereMonth('created_at',$filterMonth)
            ->sum('price'),
                        "title" => "Fresh Payments",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>
                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)->where('type', 5)
            ->whereNull('deleted_at')
           ->whereMonth('created_at',$filterMonth)
            ->sum('price'),
                        "title" => "UpSell Payments",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>


                <div class="col-lg-4 col-xs-6">
                    @include("admin.counter_widget", [
                        "bgColor" => "",
                        "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
            ->where('team_id', \Auth::user()->details->team_id)
            ->where('status', 1)->where('type', 6)
            ->whereNull('deleted_at')
           ->whereMonth('created_at',$filterMonth)
            ->sum('price'),
                        "title" => "Existing Payments",
                        "icon" => 'fa fa-money',
                       "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                    ])
                </div>


            </section>
        @endif


    @elseif( \Auth::user()->hasRole('admin') || \Auth::user()->hasRole('super-admin'))
        {{--        //admin here--}}
        <section class="content">
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" =>app(\App\Repositories\Admin\TeamRepository::class)
                    ->sum('target'),
                    "title" => "$ Total Target",
                    "icon" => 'fa fa-dollar',
                    "route" =>route('admin.payments.index')
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('status', 1)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->sum('price'),2),
                   "title" => "$ Target Achieved",
                    "icon" => 'fa fa-dollar',
                    "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)
        ->where('status', 0)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->sum('price'),2),
                     "title" => "$ Target Pending",
                    "icon" => 'fa fa-dollar',
                    "route" => url('admin/payments?status=0&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            {{--        leads--}}
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\LeadRepository::class)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total Leads",
                    "icon" => 'fa fa-filter',
                    "route" => url('admin/leads?month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" =>app(\App\Repositories\Admin\LeadRepository::class)
         ->where('status_id', 4)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Owned Leads",
                    "icon" => 'fa fa-filter',
                    "route" => url('admin/leads?lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\LeadRepository::class)
         ->where('status_id', 3)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Paid Leads",
                    "icon" => 'fa fa-filter',
                    "route" =>  url('admin/leads?lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            {{--//payments--}}
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total No. of Payments",
                    "icon" => 'fa fa-money',
                    "route" => url('admin/payments?month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => app(\App\Repositories\Admin\PaymentRepository::class)
         ->where('status', 1)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->count('id'),
                    "title" => "Total No. of Paid Payments",
                    "icon" => 'fa fa-money',
                     "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                ])
            </div>
            <div class="col-lg-4 col-xs-6">
                @include("admin.counter_widget", [
                    "bgColor" => "",
                    "counter" => number_format(app(\App\Repositories\Admin\TeamRepository::class)
        ->whereNull('deleted_at')
        ->sum('target'),2).'|'.number_format(app(\App\Repositories\Admin\PaymentRepository::class)
         ->where('status', 1)
        ->whereNull('deleted_at')
        ->whereYear('created_at', Carbon::now()->year)
        ->whereMonth('created_at', $filterMonth)
        ->sum('price'),2),
                    "title" => "Team Target",
                    "icon" => 'fa fa-money',
                   "route" => route('admin.payments.index'),
                   "style" => "font-size: 10px;"
                ])
            </div>
                <div class="col-md-12">
                    <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Team Leads Stats</h4>
                </div>

                <section class="content">
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" =>app(\App\Repositories\Admin\UserDetailRepository::class)
                ->whereNull('deleted_at')
                ->sum('target'),
                            "title" => "$ Team Target",
                            "icon" => 'fa fa-dollar',
                            "route" =>route('admin.teams.index')
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => app(\App\Repositories\Admin\LeadRepository::class)

                 ->where('status_id', 4)
                  ->where('lead_status', 'Ppc')
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at', $filterMonth)
                ->count('id'),
                           "title" => "$ Total PPC Leads",
                            "icon" => 'fa fa-google',
                            "route" => url('admin/leads?platform=Ppc&lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => app(\App\Repositories\Admin\LeadRepository::class)

                 ->where('status_id', 4)
                 ->where('lead_status', 'Social Media')
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at', $filterMonth)
                ->count('id'),
                             "title" => "$ Total SMM Leads",
                            "icon" => 'fa fa-facebook',
                            "route" => url('admin/payments?platform=Social%20Media&lead_status_id=4&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    {{--        leads--}}
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)

                 ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at', $filterMonth)
                ->sum('price'),2),
                            "title" => "Team Target Achieved",
                            "icon" => 'fa fa-filter',
                            "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <?php
                    $tot_leads_paid_ppc = app(\App\Repositories\Admin\LeadRepository::class)
                        ->where('status_id', 3)
                        ->where('lead_status', 'ppc')
                        ->whereNull('deleted_at')
                        ->whereYear('created_at', Carbon::now()->year)
                        ->whereMonth('created_at', $filterMonth)
                        ->pluck('id');

                    $tot_leads_paid_smm =  app(\App\Repositories\Admin\LeadRepository::class)
                        ->where('status_id', 3)
                        ->where('lead_status', 'Social Media')
                        ->whereNull('deleted_at')
                        ->whereYear('created_at', Carbon::now()->year)
                        ->whereMonth('created_at', $filterMonth)
                        ->pluck('id');

                    ?>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" =>count($tot_leads_paid_ppc),
                            "title" => "PPC Paid Leads",
                            "icon" => 'fa fa-google',
                            "route" => url('admin/leads?platform=Ppc&lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" =>count($tot_leads_paid_smm),
                            "title" => "SMM Paid Leads",
                            "icon" => 'fa fa-facebook',
                            "route" =>  url('admin/leads?platform=Social%20Media&lead_status_id=3&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    {{--//payments--}}
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" =>number_format(app(\App\Repositories\Admin\TeamRepository::class)

                            ->value('target')-app(\App\Repositories\Admin\PaymentRepository::class)

                 ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at', $filterMonth)
                ->sum('price'),2),
                            "title" => "Target Remaining",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)
                            ->whereIn('lead_id', $tot_leads_paid_ppc)

                ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at', $filterMonth)
                ->sum('price'),2),
                            "title" => "Paid Amount PPC",
                            "icon" => 'fa fa-money',
                             "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)
                            ->whereIn('lead_id', $tot_leads_paid_smm)

                ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereYear('created_at', Carbon::now()->year)
                ->whereMonth('created_at',$filterMonth)
                ->sum('price'),2),
                            "title" => "Paid Amount SMM",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>


                    <div class="col-md-12">
                        <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Current Day Team Stats</h4>
                    </div>


                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)

                ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereDate('created_at', Carbon::today())
                ->sum('price'),2),
                            "title" => "Today Achieved",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>

                    <?php
                    $tot_leads_paid_ppc_today = app(\App\Repositories\Admin\LeadRepository::class)

                        ->where('status_id', 3)
                        ->where('lead_status', 'ppc')
                        ->whereNull('deleted_at')
                        ->whereDate('created_at', Carbon::today())
                        ->pluck('id');

                    $tot_leads_paid_smm_today =  app(\App\Repositories\Admin\LeadRepository::class)

                        ->where('status_id', 3)
                        ->where('lead_status', 'Social Media')
                        ->whereNull('deleted_at')
                        ->whereDate('created_at', Carbon::today())
                        ->pluck('id');

                    ?>


                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => count($tot_leads_paid_ppc_today) .'|'. number_format(app(\App\Repositories\Admin\PaymentRepository::class)
                            ->whereIn('lead_id', $tot_leads_paid_ppc_today)

                ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereDate('created_at', Carbon::today())
                ->sum('price'),2),
                            "title" => "PPC Leads | Amount",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>


                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => count($tot_leads_paid_smm_today) .'|'.  number_format(app(\App\Repositories\Admin\PaymentRepository::class)
                            ->whereIn('lead_id', $tot_leads_paid_smm_today)

                ->where('status', 1)
                ->whereNull('deleted_at')
                ->whereDate('created_at', Carbon::today())
                ->sum('price'),2),
                            "title" => "SMM Leads | Amount",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>




                    <div class="col-md-12">
                        <h4 class="team_head_name" style="text-align: center; padding: 20px; color: #28b8da; border-radius: 10px">Team Payment Stats Break Down</h4>
                    </div>


                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)

                ->where('status', 1)->where('type', 4)
                ->whereNull('deleted_at')
               ->whereMonth('created_at',$filterMonth)
                ->sum('price'),2),
                            "title" => "Fresh Payments",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>
                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)

                ->where('status', 1)->where('type', 5)
                ->whereNull('deleted_at')
               ->whereMonth('created_at',$filterMonth)
                ->sum('price'),2),
                            "title" => "UpSell Payments",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>


                    <div class="col-lg-4 col-xs-6">
                        @include("admin.counter_widget", [
                            "bgColor" => "",
                            "counter" => number_format(app(\App\Repositories\Admin\PaymentRepository::class)

                ->where('status', 1)->where('type', 6)
                ->whereNull('deleted_at')
               ->whereMonth('created_at',$filterMonth)
                ->sum('price'),2),
                            "title" => "Existing Payments",
                            "icon" => 'fa fa-money',
                           "route" => url('admin/payments?status=1&month='.$filterMonth.'&year='.\Carbon\Carbon::now()->year)
                        ])
                    </div>

                </section>

        </section>
    @elseif(\Auth::user()->details->is_production == 1)
        {{--        //production here--}}
    @endif
    <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>--}}
    <script>
        $(window).on('load', function () {
            var month = {!! json_encode($month) !!} // Embedding the $month variable from Blade into JavaScript

            setTimeout(function () {
                var url = '{{ route('admin.extraIndex') }}';
                if (month > 0) {
                    url += '?month=' + month;
                }
                $('#extraData').load(url);
            }, 500);
        });
    </script>
@endpush