7df249d0f3679d976e13dcce47a7bc134de3ae3d.php 12.7 KB
<?php
$reportTitle = 'Contactability Report';
$returnblade = 'contactability';

$userstatus_array = array("Contacted", "Not Contacted", "FORCEDCLOSE");
foreach($userstatus_array AS $userstatus) {
    $userstatus_array1[$userstatus] = array($userstatus);
    $userstatus_array2[$userstatus] = array();
}

$view_path = Config::get('view.paths'); 
include_once($view_path[0].'/layout/module/dialer/reporthead.blade.php');

$alist=$alist->whereIn('userstatus', array_merge($userstatus_array, array("REDIAL")) );
$alist=$alist->get();   

$i=1;
$reporthead=array("#","Telecaller","TelecallerID","Supervisor","Customers","Total");
$reporthead=array_merge($reporthead, $userstatus_array,$userstatus_array1);
$reportarray=array();
foreach($alist as $aline)
{
    $tuser=$userarr[$aline->user_id];
    $aline->userstatus = ($aline->userstatus != 'REDIAL') ? $aline->userstatus : 'Not Contacted';
	
	if(!isset($reportarray[$aline->user_id])) {
        $reportarray[$aline->user_id]=array_merge( array("#"=>$i++,"Telecaller"=>$tuser->telecaller,"TelecallerID"=>$tuser->username,"Supervisor"=>$tuser->sepervisor,"Customers"=>0,"Total"=>0),$userstatus_array2,array("Customer_lists"=>array()));
	}

    if(!is_null($aline->lan)) {
        $reportarray[$aline->user_id]["Customer_lists"][] = $aline->lan;
    }
    $reportarray[$aline->user_id]["Customers"] = count(array_unique($reportarray[$aline->user_id]["Customer_lists"]));
	$reportarray[$aline->user_id]["Total"]++;
	
    $ststr=$aline->action_code;
	if(!in_array($ststr,$reporthead[$aline->userstatus]))$reporthead[$aline->userstatus][]=$ststr;
    $reportarray[$aline->user_id][$aline->userstatus][$aline->userstatus]++;
	$reportarray[$aline->user_id][$aline->userstatus][$aline->action_code]++;
}

$highestColumn = sizeof($reporthead);
if(count($reportarray)) {
    $outhead="<tr>";$outstr="";$outsubhead="<tr>";
    foreach ($reporthead as $head => $headval){
    	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 rowspan=2>".$mode_str."</td>";
        }
        else {
            if(!is_array($headval)) {
                if(array_key_exists($headval, $reporthead)) {
                    $outhead.="<td colspan=".count($reporthead[$headval]).">".$headval."</td>";
                    foreach ($reporthead[$headval] as $subhead) {
                        $outsubhead.="<td>".$subhead."</td>";
                    }
                }
                else {
                    $outhead.="<td rowspan=2>".$headval."</td>";
                }
            }
        }
    }
    $outsubhead.="</tr>";
    $outhead.="</tr>".$outsubhead;
    $utotalarr = array("Telecaller"=>'Total');
    foreach($reportarray as $uid=>$uarr)
    {
    	$outstr.="<tr>";
    	for ($head = 0; $head < $highestColumn; $head++){
            if($head < 4) {
                $data_str = $uarr[$reporthead[$head]];
                $outstr.="<td>".$data_str."</td>";
            }
            elseif($head < 5) {
                $data_str = $uarr[$reporthead[$head]];
                $utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];          
                $outstr.="<td>".$data_str."</td>";
            }
            elseif($head < 6) {
                $data_str1 = $uarr[$reporthead[$head]];
                $utotalarr[$reporthead[$head]] += $data_str1;          
                $data_str = '<span class="summation" style="display:block;">'.$data_str1.'</span>';
                $data_str .= '<span class="percent" style="display:none;">'.number_format(@($data_str1/$uarr['Total']) * 100, 2 ).'%</span>';  
                $data_str = '<a href="#" onclick="breakupXls(\'contactability\',\''.$uid.'\',\''.$reporthead[$head].'\')">' . $data_str . '</a>';
                $outstr.="<td>".$data_str."</td>";
            }
            else {
                if(is_array($uarr[$reporthead[$head]])) {
                    foreach($reporthead[$reporthead[$head]] AS $subval) {
                        $data_str1 = $uarr[$reporthead[$head]][$subval];                    
                        $utotalarr[$subval] += $data_str1;          
                        $data_str = '<span class="summation" style="display:block;">'.$data_str1.'</span>';
                        $data_str .= '<span class="percent" style="display:none;">'.number_format(@($data_str1/$uarr['Total']) * 100, 2 ).'%</span>';  
                        $data_str = '<a href="#" onclick="breakupXls(\'contactability\',\''. $uid.'\',\''.$reporthead[$head] .'||'.$subval.'\')">' . $data_str . '</a>';
                        $outstr.="<td>".$data_str."</td>";
                    }
                }
            }
    	}
    	$outstr.="</tr>";
    }

    $outstr.="<tr>";
    foreach ($reporthead as $head => $headval){
        if(is_int($head) && $head < 5) {
            @($data_str = $utotalarr[$headval]);
            $outstr.="<td>".$data_str."</td>";
        }
        elseif(is_int($head) && $head < 6) {
            $data_str = '<span class="summation" style="display:block;">'.$utotalarr[$headval].'</span>';
            $data_str .= '<span class="percent" style="display:none;">'.number_format(@($utotalarr[$headval]/$utotalarr['Total']) * 100, 2 ).'%</span>';  
            $data_str = '<a href="#" onclick="breakupXls(\'contactability\',\'All\',\''.$headval.'\')">' . $data_str . '</a>';
            $outstr.="<td>".$data_str."</td>";
        }
        else {
            if(!is_array($headval)) {
                if(array_key_exists($headval, $reporthead)) {
                    foreach ($reporthead[$headval] as $subhead) {
                        $data_str = '<span class="summation" style="display:block;">'.$utotalarr[$subhead].'</span>';
                        $data_str .= '<span class="percent" style="display:none;">'.number_format(@($utotalarr[$subhead]/$utotalarr['Total']) * 100, 2 ).'%</span>';  
                        $data_str = '<a href="#" onclick="breakupXls(\'contactability\',\'All\',\''.$headval.'||'.$subhead.'\')">' . $data_str . '</a>';
                        $outstr.="<td>".$data_str."</td>";
                    }
                }
            }
        }
    }
    $outstr.="</tr>";
}
else {
    $outhead.="<tr><td>No Records Found.</td></tr>";
}

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 = 2;

    $index_count = 0;
    foreach ($reporthead as $head => $headval){
        if(!is_array($headval)) {
            if(array_key_exists($headval, $reporthead)) {
                foreach ($reporthead[$headval] as $subhead) {
                    $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                    $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $subhead);
                    $index_count++;
                }
            }
            else {
                $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $headval);
                $index_count++;
            }
        }
    }

    foreach($reportarray as $uid=>$uarr)
    {
        $row = $baseRow++;
        $index_count = 0;
        foreach ($reporthead as $head => $headval){
            if(!is_array($headval)) {
                if(array_key_exists($headval, $reporthead)) {
                    foreach ($reporthead[$headval] as $subhead) {
                        $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                        $objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $uarr[$headval][$subhead]);
                        $index_count++;
                    }
                }
                else {
                    $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                    $objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $uarr[$headval]);
                    $index_count++;
                }
            }
        }

    }

    $row++; $index_count = 0;
    foreach ($reporthead as $head => $headval){
        if(!is_array($headval)) {
            if(array_key_exists($headval, $reporthead)) {
                foreach ($reporthead[$headval] as $subhead) {
                    $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                    $objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $utotalarr[$subhead]);
                    $index_count++;
                }
            }
            else {
                $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
                $objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $utotalarr[$headval]);
                $index_count++;
            }
        }
    }

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

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

//charts
$cat1=array();
$cat1arr=array();
foreach($reportarray as $uid=>$uarr)
{
	$cat1[]="'$uarr[Telecaller]'";
	
    foreach ($userstatus_array as $value) {
        $cat1arr[$value][$uarr["#"]]=round($uarr[$value][$value],1);
        if(empty($cat1arr[$value][$uarr["#"]]))$cat1arr[$value][$uarr["#"]]=0; 
    }		
}

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

$cat2=array();
foreach($reportarray as $uid=>$uarr)
{
	foreach ($userstatus_array as $value) {
		$cat2["'".$value."'"]+=round($uarr[$value][$value],1);
	}
}
?>

<?php echo $__env->make('layout.module.dialer.searchform', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

<div class=col-md-6 style='border:1px solid #BBB;'>
    <div id=userlogschart1 style='min-height:250px;width:100%'></div>
</div>
<div class=col-md-6 style='border:1px solid #BBB;'>
    <div id=userlogschart2 style='min-height:250px;width:100%'></div>
</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>

<script>
$(function () {
    $('#userlogschart1').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'User Contactability Status',
            style: {
                fontSize: '14px'
            }
        },
        xAxis: {
            labels:{
                rotation: -45,
                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 () {
    $('#userlogschart2').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Contactability Status',
            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)); ?>]

        },]
    });
});
</script>