resultactioncode.blade.php 11.7 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");

if(isset($_GET['logdateto']))$logdateto=strtotime($_GET['logdateto']." 00:00:00");
else $logdateto=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",$logdateto+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();
	
	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();
$users = DB::table('users as u1')->
    leftjoin('users AS u2', 'u2.username', '=', 'u1.supervisor')->
    select('u1.id','u1.fullname AS telecaller', 'u2.fullname AS sepervisor')->
    get();
foreach($users as $tuser)
{
    $userarr[$tuser->id] = $tuser;
}    

$i=1;
$reporthead=array("#","Telecaller","Supervisor","Customers","Total");
$reportarray=array();
foreach($alist as $aline)
{
    $tuser=$userarr[$aline->user_id];
	
	if(!isset($reportarray[$aline->user_id]))$reportarray[$aline->user_id]=array("#"=>$i++,"Telecaller"=>$tuser->telecaller,"Supervisor"=>$tuser->sepervisor,"Customers"=>0,"Total"=>0,"Customer_lists"=>array());
	
    if($aline->crm_id != 0) {
        $reportarray[$aline->user_id]["Customer_lists"][] = $aline->crm_id;
    }
    else {
        $reportarray[$aline->user_id]["Customer_lists"][] = $aline->number;    
    }
    $reportarray[$aline->user_id]["Customers"] = count(array_unique($reportarray[$aline->user_id]["Customer_lists"]));
	$reportarray[$aline->user_id]["Total"]++;
	
	//$ststr=$aline->userstatus."-".$aline->usersubstatus;
    $ststr=$aline->resultCode;
	if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
	
	$reportarray[$aline->user_id][$ststr]++;
}

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('ResultActionCodeReport');
    $objPHPExcel->setActiveSheetIndex(0);
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="ResultActionCode.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++){
	if($reporthead[$head] == '#') {
        $mode_str = "<a onclick='displayMode(".'"summation"'.");return false;' href='#'><i class='fa fa-plus-square-o'></i></a> / <a onclick='displayMode(".'"percent"'.");return false;' href='#'>%</a>";
        $outhead.="<td>".$mode_str."</td>";
    }
    else {
        $outhead.="<td>".$reporthead[$head]."</td>";
    }
}
$outhead.="</tr>";
$utotalarr = array("Telecaller"=>'Total');
foreach($reportarray as $uid=>$uarr)
{
	$outstr.="<tr>";
	for ($head = 0; $head < $highestColumn; $head++){
        if($head < 3) {
            $data_str = $uarr[$reporthead[$head]];
        }
        elseif($head < 4) {
            $data_str = $uarr[$reporthead[$head]];
            $utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];          
        }
        else {
            $data_str = '<span class="summation" style="display:block;">'.$uarr[$reporthead[$head]].'</span>';
            $data_str .= '<span class="percent" style="display:none;">'.number_format(@($uarr[$reporthead[$head]]/$uarr['Total']) * 100, 2 ).'%</span>';  
            $utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];          
        }
        $outstr.="<td>".$data_str."</td>";
	}
	$outstr.="</tr>";
}

$outstr.="<tr>";
for ($head = 0; $head < $highestColumn; $head++)
{
    if($head < 4) {
        $data_str = $utotalarr[$reporthead[$head]];
    }
    else {
        $data_str = '<span class="summation" style="display:block;">'.$utotalarr[$reporthead[$head]].'</span>';
        $data_str .= '<span class="percent" style="display:none;">'.number_format(@($utotalarr[$reporthead[$head]]/$utotalarr['Total']) * 100, 2 ).'%</span>';  
    }
    $outstr.="<td>".$data_str."</td>";
}
$outstr.="</tr>";

//charts
$cat1=array();
$cat1arr=array();
foreach($reportarray as $uid=>$uarr)
{
	$cat1[]="'$uarr[Telecaller]'";
	
	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); ?>'});
  $('#modto').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
});
</script>

<h4>Productivity Report</h4>
<hr style="margin-bottom: 10px;">
<div style="float:left;width:50%">

Search <input id=filter name="filter" type="text" style="border:1px solid #efefef; padding: 2px 10px;"> 
Date : From<input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' onchange='statusLogReloadFun("");' /> To <input size=10 id='modto' name='modto' type='text' value='<?php echo date("Y-m-d",$logdateto); ?>' onchange='statusLogReloadFun("");' />

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


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

</div>
<div style="clear:both"></div>
<hr style="margin:5px;">

<div class=col-md-6 style='border:1px solid #BBB;'>


<div id=userlogschart1 style='min-height:250px;width:100%'></div>
<script>
$(function () {
    $('#userlogschart1').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Userwise result count',
            style: {
                fontSize: '14px'
            }
        },
        xAxis: {
            labels:{
                enabled:true//default is true
            },
            categories: [<?php echo implode(",",$cat1); ?>]
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            },
            stackLabels: {
                enabled: false,
            }
        },
        tooltip: {
            headerFormat: '<b>{point.x}</b><br/>',
            pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
        },
        plotOptions: {
            column: {
                stacking: 'normal',
                dataLabels: {
                    enabled: false,
                }
            }
        },
        series: [<?php echo $cat1arrstr; ?>]
    });
});

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

</div>

<div class=col-md-6 style='border:1px solid #BBB;'>


<div id=userlogschart2 style='min-height:250px;width:100%'></div>
<script>
$(function () {
    $('#userlogschart2').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Resultwise count',
            style: {
                fontSize: '14px'
            }
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [<?php echo implode(",",array_keys($cat2)); ?>],
            crosshair: true,
            labels:{
                enabled:true//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}</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: 'Count',
            data: [<?php echo implode(",",array_values($cat2)); ?>]

        },]
    });
});


function displayMode(mode) {
    if(mode == 'percent') {
        $(".summation").hide();
        $(".percent").show();
    }
    else {
        $(".percent").hide();
        $(".summation").show();
    }
}
</script>

</div>



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

<div style="overflow: auto; margin-top: 10px;">
<table id=logtable class='footable table table-striped table-bordered table-white table-primary footable-loaded' style='font-size:12px; margin:0; border:1px solid #BBB;'>
<thead>
	<?php echo $outhead; ?>
</thead>
<?php echo $outstr; ?>
</table>
</div>

<div id=dialoglog></div>

                
                
                
                
            </div>