campreport.blade.php 9.75 KB
<?php
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;

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

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

$alist=CRMCall::where('created_at','>=',date("Y-m-d H:i:s",$logdate))->where('created_at','<=',date("Y-m-d H:i:s",$logdate+24*60*60));

//if(!$dashboarduser->moduleACL("Dialer",false,false,true))
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);
	});
	
}

$alist=$alist->get();

$userarr=array();$i=1;
$reporthead=array("#","UserId","User","Name","Count","Total","Wait","Call","Talk","Dispo");
$reportarray=array();
foreach($alist as $aline)
{
	if(!isset($userarr[$aline->user_id]))$userarr[$aline->user_id]=User::find($aline->user_id);
	$tuser=$userarr[$aline->user_id];
	
	if(!isset($reportarray[$aline->user_id]))$reportarray[$aline->user_id]=array("#"=>$i++,"UserId"=>$tuser->id,"User"=>$tuser->username,"Name"=>$tuser->fullname,"Count"=>0,"Total"=>0,"Wait"=>0,"Call"=>0,"Talk"=>0,"Dispo"=>0);
	
	$talktime=$aline->talkSec+$aline->recstartSec+$aline->recendSec;
	
	$reportarray[$aline->user_id]["Count"]++;
	$reportarray[$aline->user_id]["Total"]+=round(($aline->waitSec+$aline->callSec+$talktime+$aline->dispoSec)/1000,2);
	$reportarray[$aline->user_id]["Wait"]+=round($aline->waitSec/1000,2);
	$reportarray[$aline->user_id]["Call"]+=round($aline->callSec/1000,2);
	$reportarray[$aline->user_id]["Talk"]+=round($talktime/1000,2);
	$reportarray[$aline->user_id]["Dispo"]+=round($aline->dispoSec/1000,2);
}

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


	$highestColumn = sizeof($reporthead);
	for ($head = 0; $head < $highestColumn; $head++){
		$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
		$objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $reporthead[$head]);
	}

	foreach($reportarray as $uid=>$uarr)
	{
			$row = $baseRow++;
			$col = 0;
			
			for ($head = 0; $head < $highestColumn; $head++){
				$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
				$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $uarr[$reporthead[$head]]);
			}
	}


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

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



$highestColumn = sizeof($reporthead);
$outhead="<tr>";$outstr="";
for ($head = 0; $head < $highestColumn; $head++){
	$outhead.="<td>".$reporthead[$head]."</td>";
}
$outhead.="</tr>";
foreach($reportarray as $uid=>$uarr)
{
	$outstr.="<tr>";
	for ($head = 0; $head < $highestColumn; $head++){
		$outstr.="<td>".$uarr[$reporthead[$head]]."</td>";
	}
	$outstr.="</tr>";
}




//charts
$cat1=array();
$cat1arr=array();
foreach($reportarray as $uid=>$uarr)
{
	$cat1[]="'$uarr[UserName]'";
	
	for ($head = 5; $head < $highestColumn; $head++){
		if(!isset($cat1arr[$reporthead[$head]]))$cat1arr[$reporthead[$head]]=array();
		
		$cat1arr[$reporthead[$head]][$uarr["#"]]=round($uarr[$reporthead[$head]]/60,1);
		if(empty($cat1arr[$reporthead[$head]][$uarr["#"]]))$cat1arr[$reporthead[$head]][$uarr["#"]]=0;
	}
}

$cat1arrstr="";
foreach($cat1arr as $name=>$data)
{
	$cat1arrstr.="{ name: '$name',\ndata : [";
	$cat1arrstr.=implode(",",$data);
	$cat1arrstr.="] },\n";
}


$cat2=array();
foreach($reportarray as $uid=>$uarr)
{
	for ($head = 5; $head < $highestColumn; $head++){
		$cat2["'".$reporthead[$head]."'"]+=round($uarr[$reporthead[$head]]/60,1);
	}
}
?>


            <div class=innerAll>


<style>#logtable.td{vertical-align:top;}#logtable.tr{height:28px;overflow-y:hidden;}</style>
<script>
$(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); ?>'});
});
</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='campLogReloadFun("");' /> 

</div>
<div style="float:left;width:50%">


	<button class="pull-right btn btn-sm btn-default" onclick='dlAgentlogXls();return false;' title='Download' style='margin-top:-8px'><i class='fa fa-download'></i> Download</button>

</div>
<div style="clear:both"></div>
<hr>

<div class=col-md-12>


<div id=userlogschart1 style='min-height:300px;width:100%'></div>
<script>
$(function () {
    $('#userlogschart1').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        xAxis: {
                    labels:{
                        enabled:false//default is true
                    },
            categories: [<?php echo implode(",",$cat1); ?>]
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            },
            stackLabels: {
                enabled: false,
//                 style: {
//                     fontWeight: '',
//                     color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
//                 }
            }
        },
//         legend: {
//             align: 'right',
//             x: -30,
//             verticalAlign: 'top',
//             y: 25,
//             floating: true,
//             backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
//             borderColor: '#CCC',
//             borderWidth: 1,
//             shadow: false
//         },
        tooltip: {
            headerFormat: '<b>{point.x}</b><br/>',
            pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
        },
        plotOptions: {
            column: {
                stacking: 'normal',
                dataLabels: {
                    enabled: false,
//                     color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
//                     style: {
//                         textShadow: '0 0 3px black'
//                     }
                }
            }
        },
        series: [<?php echo $cat1arrstr; ?>]
    });
});




function campLogReloadFun(sortby)
{
	var sortstr='';if(sortby!="")sortstr="&sort="+sortby
	
	doAjax('dialer/campreport?logdate='+$("#modfrom").val()+sortstr,'','rightmainreportdiv','ajax_dialer_reports','singlethis','GET');
}
function dlAgentlogXls()
{
	window.open('dialer/campreport?dllogxls=1&logdate='+$("#modfrom").val());return false;
}
</script>

</div>

<div style='clear:both'></div>

<div class=col-md-12>


<div id=userlogschart2 style='min-height:300px;width:100%'></div>
<script>
$(function () {
    $('#userlogschart2').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [<?php echo implode(",",array_keys($cat2)); ?>],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        legend : {
            floating: true,
            align: 'right',
            x: -30,
            verticalAlign: 'top',
        },
        series: [{
            name: 'Mins',
            data: [<?php echo implode(",",array_values($cat2)); ?>]

        },]
    });
});

</script>

</div>



<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>
	<?php echo $outhead; ?>
</thead>
<?php echo $outstr; ?>
</table>
</div>

<div id=dialoglog></div>

                
                
                
                
            </div>