<?php

namespace App\Providers;
use App\CoiUsers;
use App\HelpDesk;
use App\PreLoginHelpDesk;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer('layout.adminapp', function ($view) {
        $conflict = CoiUsers::query()->where('conflict','1')->where('momoconflict',false)->count();

        $current_year = Carbon::now()->year;
        $countpendingcoi = count(DB::select("SELECT email FROM `coi_users` WHERE dept IS NOT NULL AND deleted_at IS NULL AND coi_status IS NULL AND status IS NULL AND YEAR(created_at) = $current_year"));

        $countstartedscoi = count(DB::select("SELECT email FROM `coi_users` where  dept IS NOT NULL AND deleted_at IS NULL AND YEAR(created_at) = $current_year AND (coi_status = 'Agree' AND status = 'Pending') OR (coi_status IS NULL AND status = 'Pending')"));

        // $noconclict = CoiUsers::query()->where('conflict','0')->count();

        $noconclict =count(DB::select("SELECT email FROM `coi_users` WHERE dept IS NOT NULL AND deleted_at IS NULL AND coi_status = 'Agree' AND status IN ('Completed', 'Updated', 'UpdatedFromLastYear') AND conflict = 0"));

        $noneconclict = $countpendingcoi + $countstartedscoi;
        $momoconflict = CoiUsers::query()->where('momoconflict',true)->count();
        $help = HelpDesk::query()->whereNull('adminid')->count();
        $access = PreLoginHelpDesk::query()->whereNull('adminname')->count();
$sumhelp = $help + $access;
        $view->with([

               // 'comp'=> $countqa,
               'conflict'=> $conflict+$momoconflict,
               'gendec'=> $conflict,
               'noconclict'=> $noconclict,
               'noneconclict'=>$noneconclict,
               'help'=>$help,
               'access'=>$access,
               'sumhelp'=>$sumhelp,
               'momoconflict'=>$momoconflict,
               // 'rej'=> $totalrejected,
//                     'app'=>$totalcp


            ]);
          });
    }
}
