282cd93ed611f5df61deb36e577cc59cea183669.php 12.3 KB
<?php
use App\Models\CRMCallArchive;
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;

$wakka = new KHRMSLib();
$dashboarduser=Auth::user();

if(Input::get("getCallRec")=="1")
{
	$calllog=CRMCallArchive::find(Input::get("calllog"));
	$tdata=json_decode($calllog->data,true);
	if(Auth::user()->usertype == "Telecaller")
        {	
		echo '<audio controls src="dialer/playrecfile?calllog='.$calllog->id.'" controlsList="nodownload"/>';
	}
	else
	{
		 echo '<audio controls src="dialer/playrecfile?calllog='.$calllog->id.'" />';
	}
	return;
}

if(isset($_GET['logdate']))$logdate=strtotime($_GET['logdate']." 00:00:00");
else $logdate=strtotime(date('Y-m-d')." 00:00:00");

if(isset($_GET['logtodate']))$logtodate=strtotime($_GET['logtodate']." 20:00:00");
else $logtodate=strtotime(date('Y-m-d')." 20:00:00");

$alist=CRMCallArchive::where('created_at','>=',date("Y-m-d H:i:s",$logdate))->where('created_at','<=',date("Y-m-d H:i:s",$logtodate));

if($dashboarduser->usertype != 'Admin')
{
	$uidlist=array($dashboarduser->id);
	$allusers=User::where(function ($query)  use($dashboarduser) {
		$query->where('supervisor','=',$dashboarduser->username)
		->orWhere('lteam2','=',$dashboarduser->username)
		->orWhere('lteam','=',$dashboarduser->username);
	})->get();
// 	->where(function ($query) {
// 			$query->where('status', '=', 'Active');
// 	})->get();
	
	foreach($allusers as $tuser)$uidlist[]=$tuser->id;

	$roclientstr=array();$didlinesstr=array();
	if($dashboarduser->exten!="")$didlinesstr[]=$dashboarduser->exten;
	$oclientlst=$wakka->clientsReadAccess();
	if(!empty($oclientlst))foreach($oclientlst 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('client',$roclientstr)
		->orWhereIn('user_id',$uidlist)
		->orWhereIn('did',$didlinesstr);
	});
	
}

if(Input::get('sort')=='cpu')$alist=$alist->orderBy("callSec","DESC");
else $alist=$alist->orderBy("id","DESC");
$alist=$alist->get();

$userarr=array();
$i=sizeof($alist);if(!empty($_GET['sort']))$i=1;
$totaltime=0;$ttlovr10=0;$ttlovr5=0;$ttlovr1=0;$ttlovr0=0;$outstr="";$usrcnt=0;
$totaltimeIn=0;$ttlovr10In=0;$ttlovr5In=0;$ttlovr1In=0;$ttlovr0In=0;$usrcntIn=0;
$actionarr=array();$actionarrIn=array();

if(Input::has("dllogxls"))
{
	include_once(app_path().'/lib/phpexcel/PHPExcel.php');
	
	$inputFileType = "CSV";
	$objReader = PHPExcel_IOFactory::createReader($inputFileType);
	$objPHPExcel = $objReader->load("assets/extras/blank.csv");
	$baseRow = 3;

	$tcol=0;$fieldsarr=array();$extrahdrarr=array();
	$fieldsarr[$tcol++]='#';
	$fieldsarr[$tcol++]='LAN';
	$fieldsarr[$tcol++]='Start';
	$fieldsarr[$tcol++]='Length';
	$fieldsarr[$tcol++]='User';
	$fieldsarr[$tcol++]='Name';
	$fieldsarr[$tcol++]='Number';
	$fieldsarr[$tcol++]='Data';
	$fieldsarr[$tcol++]='Type';
	$fieldsarr[$tcol++]='Dialline';
	$fieldsarr[$tcol++]='Statuscode';
	$fieldsarr[$tcol++]='Status';
	$fieldsarr[$tcol++]='Substatus';
	$fieldsarr[$tcol++]='Resultcode';
	$fieldsarr[$tcol++]='WaitSec';
	$fieldsarr[$tcol++]='CallSec';
	$fieldsarr[$tcol++]='TalkSec';
	$fieldsarr[$tcol++]='DispoSec';
	
	$highestColumn = sizeof($fieldsarr);
	for ($head = 0; $head < $highestColumn; $head++){
		$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
		$objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $fieldsarr[$head]);
	}

	$ii=1;
	foreach($alist as $aline)
	{
		$row = $baseRow++; $col = 0;

		$fulldate=date("Y-m-d H:i:s",strtotime($aline->created_at)-($dashboarduser->timezone*60));
		$talktime=$aline->talkSec+$aline->recstartSec+$aline->recendSec;
		$length=round(($aline->waitSec+$aline->callSec+$talktime+$aline->dispoSec)/1000,2);

		if(!isset($userarr[$aline->user_id])&&$aline->user_id>0)$userarr[$aline->user_id]=User::find($aline->user_id);
		$dispname="";if(isset($userarr[$aline->user_id]))$dispname=$userarr[$aline->user_id]->dispname();
		$username="";if(isset($userarr[$aline->user_id]))$username=$userarr[$aline->user_id]->username;

		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($ii++);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->lan);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($fulldate);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($length);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($username);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($dispname);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->number);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->client);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->type);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->dialline_id);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->statuscode);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->status);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->substatus);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->resultCode);
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit(round($aline->waitSec/1000,2));
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit(round($aline->callSec/1000,2));
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit(round($talktime/1000,2));
		$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit(round($aline->dispoSec/1000,2));
	}

	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="CallLog.csv"');
	header('Cache-Control: max-age=0');

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
	$objWriter->save('php://output');

	return ;
}

$exit = 1;

foreach($alist as $aline)
{
	$clientcode="";
	if($aline->crm_id>0)
	{
		$user=$wakka->getPerson($aline->crm_id);
		$clientcode=$user["peopledata"]["clientcode"];
	}
	$tpostdata=json_decode($aline->data,true);
	$fulldate=date("Y-m-d H:i:s",strtotime($aline->created_at)-($dashboarduser->timezone*60));
	$talktime=$aline->talkSec+$aline->recstartSec+$aline->recendSec;
	$length=round(($aline->waitSec+$aline->callSec+$talktime+$aline->dispoSec)/1000,2);

	if(!isset($userarr[$aline->user_id])&&$aline->user_id>0)$userarr[$aline->user_id]=User::find($aline->user_id);
	$dispname="";if(isset($userarr[$aline->user_id]))$dispname=$userarr[$aline->user_id]->dispname();
	$username="";if(isset($userarr[$aline->user_id]))$username=$userarr[$aline->user_id]->username;

	$recstr='';
	if($dashboarduser->moduleACL("Dialer",false,false,true))
	{
		if(Auth::user()->usertype == "Telecaller")
		{
		if(isset($tpostdata['recFolder']))$recstr.="<a href=# onclick='getCallRec(".$aline->id.");return false;' title='Size : ".round($aline->recsize/1024,0)." KB'><i class='fa fa-play-circle'></i> &nbsp;</a><span id='recspan_".$aline->id."'</span>"; 
	}
	else
	{
		if(isset($tpostdata['recFolder']))
		{
		$recstr.="<a href=# onclick='getCallRec(".$aline->id.");return false;' title='Size : ".round($aline->recsize/1024,0)." KB'><i class='fa fa-play-circle'></i> &nbsp;</a>";
                $recstr.="<a href='dialer/playrecfile?calllog=$aline->id&out=wav' title='' target='_blank'><i class='fa fa-download'></i> &nbsp;</a><span id='recspan_".$aline->id."'</span>";
		}
	}
	}

	$outstr.="<tr><td>".$i."</td>
	<td>".$aline->lan."</td>
	<td title='$fulldate'>".explode(" ",$fulldate)[1]."</td>
	<td>$length</td>
	<td>".$username."</td>
	<td>".$dispname."</td>
	<td>".$aline->number."</td>
	<td>".$aline->client."</td>
	<td>".$aline->type."</td>
	<td>".$aline->dialline_id."</td>
	 <td>".$aline->statuscode."</td>
	 <td>".$aline->status."</td>
	 <td>".$aline->substatus."</td>
	 <td>".$aline->resultCode."</td>
	<td>".round($aline->waitSec/1000,2)."</td>
	<td>".round($aline->callSec/1000,2)."</td>
	<td>".round($talktime/1000,2)."</td>
	<td>".round($aline->dispoSec/1000,2)."</td>
	<td>$recstr</td>
</tr>";

if(!empty($_GET['sort']))$i++;else $i--;

if($exit=="1000")break;
$exit++;
}
?>

<div class=innerAll>
	<style>#logtable.td{vertical-align:top;}#logtable.tr{height:28px;overflow-y:hidden;}</style>
	<script>
		function showExtraPost(varstr)
		{
			doAjax("hr?action=LiveUsers","getpostdata="+varstr,"dialoglog");

			$('#dialoglog').dialog('open');
			return false;
		}

		$(document).ready(function()
		{
			if(!$('#dialoglog').hasClass('ui-dialog-content'))
			{
				$('#dialoglog').dialog({
					autoOpen: false,
					width: '70%',
					buttons: {
						"Ok": function() { 
							$(this).dialog("close"); 
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});
			}

			waitKeyUpRun("filter",function() { filter2(document.getElementById('filter'), 'logtable') },"2000");
			$('#modfrom').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
			$('#modto').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
		});
	</script>
	<div style="float:left;width:50%">

		Search <input id=filter name="filter" type="text"> 
		Date : <input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' onchange='callLogReloadFun("");' /> 
		To <input size=10 id='modto' name='modto' type='text' value='<?php echo date("Y-m-d",$logtodate); ?>' onchange='callLogReloadFun("");' /> 

	</div>
	<div style="float:left;width:50%">
		<button class="pull-right btn btn-sm btn-default" onclick='dlCalllogXls();return false;' title='Download' style='margin-top:-8px'><i class='fa fa-download'></i> Download</button>
	</div>
	<div style="clear:both"></div>
	<hr>

	<?php 
	$categories=array();$avgarr=array();$cntarr=array();
	foreach($actionarr as $act=>$actarr)
	{
		if($actarr['cnt']>sizeof($alist)/150)
		{
			$categories[]="'$act'";
			$avgarr[]=-round($actarr['time']/$actarr['cnt'],2);
			$cntarr[]=$actarr['cnt'];
		}
	}

	array_multisort($cntarr,$avgarr,$categories);

	$categoriesIn=array();$avgarrIn=array();$cntarrIn=array();
	foreach($actionarrIn as $act=>$actarr)
	{
		if($actarr['cnt']>sizeof($alist)/150)
		{
			$categoriesIn[]="'$act'";
			$avgarrIn[]=-round($actarr['time']/$actarr['cnt'],2);
			$cntarrIn[]=$actarr['cnt'];
		}
	}

	array_multisort($cntarrIn,$avgarrIn,$categoriesIn);
	?>
<script>
	function callLogReloadFun(sortby)
	{
		var sortstr='';if(sortby!="")sortstr="&sort="+sortby

		doAjax('dialer/calllog?logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+sortstr,'','rightmainreportdiv','ajax_dialer_reports','singlethis','GET');
	}
	function getCallRec(id)
	{
		doAjax("dialer/calllog","getCallRec=1&calllog="+id,'recspan_'+id,'rec_ajax','singlefail','GET');
	}
	function dlCalllogXls()
	{
		window.open('dialer/calllog?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val());return false;
	}
</script>
<br/>
<div style='clear:both'></div>
	<div style='overflow:auto'>
		<table id=logtable class='footable table table-striped table-bordered table-white table-primary footable-loaded' style='font-size:12px'>
			<thead>
				<tr>
					<th>#</th>
					<th>LAN</th>
					<th>Start</th>
					<th onclick='callLogReloadFun("");return false;'>Length</th>
					<th>User</th>    
					<th>Name</th>
					<th style='width:120px'>Number</th>
					<th>Campaign</th>
					<th>Type</th>
					<th>Dialline</th>
					<th>Statuscode</th>
                    <th>Status</th>
                    <th>Substatus</th>
                    <th>Result Code</th>
					<th>WaitSec</th>
					<th>CallSec</th>
					<th>TalkSec</th>
					<th>DispoSec</th>
					<th>Recording</th>
				</tr>
			</thead>
			<?php echo $outstr; ?>
		</table>
	</div>
	<?php
	function convert($size)
	{
		$unit=array('b','kb','mb','gb','tb','pb');
		return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
	}
	echo "<br>".convert(memory_get_peak_usage(true)); // 123 kb
	?>
	<div id=dialoglog></div>
</div>