head.blade.php 2.29 KB
<?php
use App\Models\CRMCall;
use App\Models\CRMCallArchive;
use App\Models\User;
use App\Jobs\KHRMSLib;
use App\Models\Record;

$wakka = new KHRMSLib();
$dashboarduser=Auth::user();
$timeoffset = $dashboarduser->timezone;
$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=Record::whereHas('calls', function ($query) use ($logdate, $logdateto) {
	$query->where('created_at','>=',date("Y-m-d H:i:s",$logdate))
          ->where('created_at','<=',date("Y-m-d H:i:s",$logdateto));
	})->where('usr_id','!=',0);
	
$alist=$alist->where('modified','>=',date("Y-m-d H:i:s",$logdate))
	->where('modified','<=',date("Y-m-d H:i:s",$logdateto));

$displayAdv = 'none';
if(!in_array('All', $campaign)) {
	$displayAdv = 'block';
	$alist =$alist->whereIn('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('usr_id',$uidlist);
}
else {
	$allusers=$allusers->get();
	foreach($allusers as $tuser)
	{
		$userarr[$tuser->id] = $tuser;
	}
}