<?php

namespace App\Http\Controllers\FCControllers;

use Illuminate\Http\Request;
use Auth;
Use EloquentBuilder;
use App\Models\fcmodels\Wallet;
use App\Models\fcmodels\IvrRequest;
use App\Models\fcmodels\Ivr;
use App\Models\fcmodels\Bulksms;
use App\Models\fcmodels\Shop;
use App\Models\fcmodels\ApiTopup;
use App\Models\fcmodels\Currency_Expenditure;
use App\Models\fcmodels\Organization;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    // public function __construct()
    // {
    //     $this->middleware('auth');
    // }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        // if(Auth::guard('organization')->check())
        // {
        //     $id = Auth::guard('organization')->user()->organization_id;
        //     $api_account = Auth::guard('organization')->user()->api_account;
        //     $name = Auth::guard('organization')->user()->name;
        // }
        // else if(Auth::guard('web')->check())
        // {
            $id = Auth::guard('web')->user()->organization_id;
            $api_account = Auth::guard('web')->user()->api_account;
            $name = Auth::guard('web')->user()->name;
        // }
             //fetch all trans
             $sms='SMS';
            
             //return $sms;
        $account=Shop::where('ShopID',$api_account)->pluck('mpesa_account_name');
        
        $query =Currency_Expenditure::where('shopid',$api_account)->where('description','like',"%". $sms ."%")->where('sms','!=',"")->take(10);
        $trans=EloquentBuilder::to($query,request()->all())->get();
         //IVR count  today
         $ivrcountnow = Ivr::where('organization_id',$id)->whereDate('created_at',now())->count();
         //sms count today
        $smscount = Currency_Expenditure::whereDate('date_time',now())->where('shopid',$api_account)->count();
        
        $wallet = Wallet::where('shopid',$api_account)->pluck('amount');
        return view('fcviews.home',compact('wallet','trans','ivrcountnow','smscount'));
    }
}

