reporthead.blade.php 2.98 KB
<?php
use App\Models\CRMCall;
use App\Models\CRMCallArchive;
use App\Models\User;
use App\Jobs\KHRMSLib;

$wakka = new KHRMSLib();
$dashboarduser=Auth::user();
$timeoffset = $dashboarduser->timezone; //-330; //$dashboarduser->timezone;\
//$timeoffset = $timeoffset*60;
$timeoffset = 0;

$logtime    =(isset($_GET['logtime']))  ? $_GET['logtime']  :9;
$logtimeto  =(isset($_GET['logtimeto']))? $_GET['logtimeto']:20;
$logdate    =(isset($_GET['logdate']))  ? strtotime($_GET['logdate']." ".$logtime.":00:00")
                                        : strtotime(date("Y-m-d")." 09:00:00");
$logdateto  =(isset($_GET['logdateto']))? strtotime($_GET['logdateto']." ".$logtimeto.":00:00")
                                        : strtotime(date("Y-m-d")." 20:00:00");
$campaign   =explode('||', (isset($_GET['campaign']))  ? $_GET['campaign']  : "All");
$state      =explode('||', (isset($_GET['state']))    ? $_GET['state']    : "All");
$product    =explode('||', (isset($_GET['product']))  ? $_GET['product']  : "All");
$bucket     =explode('||', (isset($_GET['bucket']))   ? $_GET['bucket']   : "All");

$clientlist =$wakka->clientsReadAccess(); $clientlist; $clientlist[0] = 'All';

$alist=DB::table('crmcalls_archive AS c')->leftJoin('records', 'c.crm_id', '=', 'records.id')->where('c.user_id','!=',0);
$alist=$alist   ->where('c.created_at','>=',date("Y-m-d H:i:s",$logdate))
                ->where('c.created_at','<=',date("Y-m-d H:i:s",$logdateto));

$displayAdv = 'none';
if(!in_array('All', $campaign)) {
    $displayAdv = 'block';
    $alist =$alist->whereIn('c.client',$campaign);
}

$userarr=array();
$allusers = DB::table('users as u1')->leftjoin('users AS u2', 'u2.username', '=', 'u1.supervisor')
    ->select('u1.id','u1.username','u1.fullname AS telecaller', 'u2.fullname AS sepervisor');

if($dashboarduser->usertype != 'Admin')
{
    $uidlist=array($dashboarduser->id);
    $allusers=$allusers->where(function ($query)  use($dashboarduser) {
        $query->where('u1.supervisor','=',$dashboarduser->username)
        ->orWhere('u1.lteam2','=',$dashboarduser->username)
        ->orWhere('u1.lteam','=',$dashboarduser->username);
    })->get();
    
    foreach($allusers as $tuser)
    { 
        $uidlist[]=$tuser->id;
        $userarr[$tuser->id] = $tuser;
    }
    $alist=$alist->whereIn('c.user_id',$uidlist);
        
    /*$roclientstr=array();$didlinesstr=array();
    if($dashboarduser->exten!="")$didlinesstr[]=$dashboarduser->exten;

    if(!empty($clientlist))foreach($clientlist as $tclnt)if($tclnt!="")
    {
        $roclientstr[]="$tclnt";
        
        $mastersdata=$wakka->getCompanyMaster($tclnt);
        if(!empty($mastersdata["DialerDID"]))$didlinesstr[]=$mastersdata["DialerDID"];
    }

    $alist=$alist->where(function ($query) use($roclientstr,$uidlist,$didlinesstr){
        $query->orWhereIn('c.client',$roclientstr)
        ->orWhereIn('c.did',$didlinesstr);
    });*/
}
else {
    $allusers=$allusers->get();
    foreach($allusers as $tuser)
    {
        $userarr[$tuser->id] = $tuser;
    }
}