productivity.blade.php 8.88 KB
<?php
$reportTitle = 'Productivity Report';
$returnblade = 'productivity';

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

$alist=$alist->get();

$i=1;
$reporthead=array("#","Telecaller","TelecallerID","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,"TelecallerID"=>$tuser->username,"Supervisor"=>$tuser->sepervisor,"Customers"=>0,"Total"=>0,"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->userstatus."-".$aline->usersubstatus;
    $ststr=$aline->resultCode;
    if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
    
    $reportarray[$aline->user_id][$ststr]++;

    if($aline->userstatus == 'Contacted' && trim($ststr) != '') {
        $reportarray[$aline->user_id]['Contacted']++;    
    }
}

$highestColumn = sizeof($reporthead);
if(count($reportarray)) {
    $outhead="<tr>";$outstr="";
    for ($head = 0; $head < $highestColumn; $head++){
        if($reporthead[$head] == '#' && false) {
            $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 < 4) {
                $data_str = $uarr[$reporthead[$head]];
            }
            elseif($head < 5) {
                $data_str = $uarr[$reporthead[$head]];
                $utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];          
            }
            else {
                $total_val = ($reporthead[$head] != 'PTP') ? $uarr['Total'] : $uarr['Contacted'];

                $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]]/$total_val) * 100).'%</span>';  
                $data_str = '<a href="#" onclick="breakupXls(\'productivity\',\''.$uid.'\',\''.$reporthead[$head].'\')">' . $data_str . '</a>';
                $utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];          
            }
            $outstr.="<td>".$data_str."</td>";
        }
        $outstr.="</tr>";
    }

    $outstr.="<tr>";
    for ($head = 0; $head < $highestColumn; $head++)
    {
        if($head < 5) {
            $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).'%</span>'; 
            $data_str = '<a href="#" onclick="breakupXls(\'productivity\',\'All\',\''.$reporthead[$head].'\')">' . $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;


    $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]]);
            }
    }

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

    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="Productivity.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]'";
    
    for ($head = 6; $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 = 6; $head < $highestColumn; $head++){
        $cat2["'".$reporthead[$head]."'"]+=round($uarr[$reporthead[$head]],1);
    }
}
?>

@include('layout.module.dialer.searchform')

<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: 'Userwise result count',
            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: '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)); ?>]

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