astatusreport.blade.php 10.2 KB
<?php
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;



$selectedvals=explode(":",Input::get("selectedvals",":::::"));
$hdfcnodes=array();
$offline=array();
$arr=Config::get("app.hdfcnodes");
foreach($arr as $server=>$arrline)
{
	$tvals=explode(":",$arrline);
	
	if($selectedvals[0]=="")$hdfcnodes[]=$server;
	else if($selectedvals[0]==$tvals[0])
	{
		if($selectedvals[1]=="")$hdfcnodes[]=$server;
		else if($selectedvals[1]==$tvals[1])
		{
			if($selectedvals[2]=="")$hdfcnodes[]=$server;
			else if($selectedvals[2]==$tvals[2])
			{
				if($selectedvals[3]=="")$hdfcnodes[]=$server;
				else if($selectedvals[3]==$tvals[3])
				{
					if($selectedvals[4]=="")$hdfcnodes[]=$server;
					else if($selectedvals[4]==$tvals[4])
					{
						$hdfcnodes[]=$server;
					}
				}
			}
		}
	}
}



$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");



$i=1;
$reporthead=array("#","UserId","UserName","Count","Total");
$reportarray=array();


foreach($hdfcnodes as $ci=>$server)
{
	$conn = array(
			'driver'    => 'mysql',
			'host'      => $server,
			'database'  => env('DB_DATABASE', 'kstych_flexydial'),
			'username'  => env('DB_USERNAME', 'root'),
			'password'  => env('DB_PASSWORD', ''),
			'charset'   => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix'    => '',
			'options'   => array(
				PDO::ATTR_TIMEOUT => 5,
		),
	);
	Config::set("database.connections.conn$ci", $conn);

	try
	{
		DB::connection("conn$ci")->getDatabaseName();
		
$alist=CRMCall::on("conn$ci")->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));
$alist=$alist->get();
$userarr=array();
foreach($alist as $aline)
{
	if(!isset($userarr[$aline->user_id."conn$ci"]))$userarr[$aline->user_id."conn$ci"]=User::on("conn$ci")->find($aline->user_id."conn$ci");
	$tuser=$userarr[$aline->user_id."conn$ci"];
	
	if(!isset($reportarray[$aline->user_id."conn$ci"]))$reportarray[$aline->user_id."conn$ci"]=array("#"=>$i++,"UserId"=>$tuser->id,"UserName"=>$tuser->username,"Count"=>0,"Total"=>0,"Wait"=>0,"Call"=>0,"Talk"=>0,"Dispo"=>0);
	
	$talktime=$aline->talkSec+$aline->recstartSec+$aline->recendSec;
	
	$reportarray[$aline->user_id."conn$ci"]["Count"]++;
	$reportarray[$aline->user_id."conn$ci"]["Total"]+=round(($aline->waitSec+$aline->callSec+$talktime+$aline->dispoSec)/1000,2);
	
	$ststr=$aline->userstatus."-".$aline->usersubstatus;
	if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
	
	$reportarray[$aline->user_id."conn$ci"][$ststr]++;
}


	}catch(Exception $e)
	{
		$offline[]=$server;
	}
}



if(Input::has("dllogxls"))
{
	include_once(app_path().'/lib/newphpexcel/Classes/PHPExcel.php');
    $objPHPExcel = new PHPExcel();
	$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]]);
			}
	}


	$objPHPExcel->getActiveSheet()->setTitle('StatusLogReport');
    $objPHPExcel->setActiveSheetIndex(0);
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="StatusLog.xlsx"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
    exit;
	
	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]],1);
		if(empty($cat1arr[$reporthead[$head]][$uarr["#"]]))$cat1arr[$reporthead[$head]][$uarr["#"]]=0;
	}
}

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


$cat2=array();
foreach($reportarray as $uid=>$uarr)
{
	for ($head = 5; $head < $highestColumn; $head++){
		$cat2["'".$reporthead[$head]."'"]+=round($uarr[$reporthead[$head]],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='statusLogReloadFun("");' /> 

</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 statusLogReloadFun(sortby)
{
	var sortstr='';if(sortby!="")sortstr="&sort="+sortby
	
	doAjax('dialer/astatusreport?logdate='+$("#modfrom").val()+sortstr+'&selectedvals='+getarvalval(),'','rightmainreportdiv','ajax_dialer_reports','singlethis','GET');
}
function dlAgentlogXls()
{
	window.open('dialer/astatusreport?dllogxls=1&logdate='+$("#modfrom").val()+'&selectedvals='+getarvalval());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,
                    labels:{
                        enabled:false//default is 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: 'Count',
            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>