f0a9d37f1ac6cc1e93c4792bbaafa62150f73a6e.php 7.59 KB
<?php
$reportTitle = 'TC Productivity MIS';
$returnblade = 'productivity_mis';

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

$alist=$alist->select(DB::raw("c.user_id, count(DISTINCT case when c.lan IS NOT NULL then c.lan end) customer, count(*) count, sum(case when c.userstatus = 'Contacted' then 1 else 0 end) contacted, sum(case when (c.userstatus = 'Contacted' && c.resultCode = 'PTP') then 1 else 0 end) ptp, sum(case when (c.userstatus = 'Contacted' && c.resultCode = 'BP') then 1 else 0 end) bp"))->groupBy('c.user_id');

if(Input::has("spcode"))
{   
    if(!$joined) $alist=$alist->leftjoin('records AS r', 'r.id', '=', 'c.crm_id');
    
    $alist=$alist->addSelect(DB::raw(" r.state, r.specialCode"));
    $alist=$alist->groupBy('r.state');
    $alist=$alist->groupBy('r.SpecialCode');
}
$alist=$alist->get();

$i=1;
$reporthead=array("#","Telecaller","TelecallerID","Supervisor","Account","Attempt","AI","Contact","CI","Contact(%)","PTP","PTP(%)","BP","BP(%)");
$reportarray=array();
$totalarray =array();
if(count($alist))
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);
	}

    $reportarray[$aline->user_id]["Account"]    = $aline->customer;
    $reportarray[$aline->user_id]["Attempt"]    = $aline->count;
    $reportarray[$aline->user_id]["AI"]         = number_format( ($aline->customer) ? ($aline->count/$aline->customer) : 0, 2 );
    $reportarray[$aline->user_id]["Contact"]    = $aline->contacted;
    $reportarray[$aline->user_id]["CI"]         = number_format( ($aline->customer) ? ($aline->contacted/$aline->customer) : 0, 2 );
    $reportarray[$aline->user_id]["Contact(%)"] = number_format( ($aline->count) ? ($aline->contacted/$aline->count) * 100 : 0, 2 ) . '%';
    $reportarray[$aline->user_id]["PTP"]        = $aline->ptp;
    $reportarray[$aline->user_id]["PTP(%)"]     = number_format( ($aline->contacted) ? ($aline->ptp/$aline->contacted) * 100 : 0, 2 ) . '%';
    $reportarray[$aline->user_id]["BP"]         = $aline->bp;
    $reportarray[$aline->user_id]["BP(%)"]      = number_format( ($aline->ptp) ? ($aline->bp/$aline->ptp) * 100 : 0, 2 ) . '%';

    if(Input::has("spcode"))    {
        $reportarray[$aline->user_id]["State"]      = $aline->state;
        $reportarray[$aline->user_id]["SpecialCode"]= $aline->specialCode;
        $specialarray[$aline->user_id . $aline->state . $aline->specialCode] = $reportarray[$aline->user_id];
    }

    $totalarray["Account"]  += $aline->customer;
    $totalarray["Attempt"]  += $aline->count;
    $totalarray["AI"]        = number_format(@($totalarray["Attempt"]/$totalarray["Account"]), 2 );
    $totalarray["Contact"]  += $aline->contacted;
    $totalarray["CI"]        = number_format(@($totalarray["Contact"]/$totalarray["Account"]), 2 );
    $totalarray["Contact(%)"]= number_format(@($totalarray["Contact"]/$totalarray["Attempt"]) * 100, 2 ) . '%';
    $totalarray["PTP"]      += $aline->ptp;
    $totalarray["PTP(%)"]    = number_format(@($totalarray["PTP"]/$totalarray["Contact"]) * 100, 2 ) . '%';
    $totalarray["BP"]       += $aline->bp;
    $totalarray["BP(%)"]     = number_format(@($totalarray["BP"]/$totalarray["PTP"]) * 100, 2 ) . '%';
}

if(Input::has("spcode"))
{
    $reporthead=array("TelecallerID","Telecaller","State","SpecialCode","Account","Attempt","AI","Contact","CI","Contact(%)","PTP","PTP(%)");
    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){
        $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
        $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $headval);
        $index_count++;
    }

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

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

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

$reportarray["Total"] = array_merge(array("Telecaller"=>"Total"),$totalarray);

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;

    $index_count = 0;
    foreach ($reporthead as $head => $headval){
        $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
        $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $headval);
        $index_count++;
    }

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

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

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

    return ;
}

$highestColumn = sizeof($reporthead);
if(count($reportarray) > 1) {
    $outhead="<tr>";$outstr="";$outsubhead="<tr>";
    foreach ($reporthead as $head => $headval){
        $outhead.="<td align='center'>".$headval."</td>";
    }
    $outsubhead.="</tr>";
    $outhead.="</tr>".$outsubhead;
    $utotalarr = array("Telecaller"=>'Total');
    if(count($reportarray))
    foreach($reportarray as $uid=>$uarr)
    {
    	$outstr.="<tr>";
    	for ($head = 0; $head < $highestColumn; $head++){
            if($head < 3) {
                $outstr.="<td>".$uarr[$reporthead[$head]]."</td>";
            }
            else {
                $outstr.="<td align='right'>".$uarr[$reporthead[$head]]."</td>";
            }

    	}
    	$outstr.="</tr>";
    }
}
else {
    $outhead.="<tr><td>No Records Found.</td></tr>";
}
?>

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

<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 dlSpecialCodeXls()
{
    var searchStr = dataString();
    window.open('dialer/<?php echo e($returnblade); ?>?spcode=1&'+searchStr);
    return false;
}

$("#download_btn").append("<button class='pull-right btn btn-sm btn-default' onclick='dlSpecialCodeXls();return false;' title='Download' style='margin-right: 5px;'><i class='fa fa-download'></i> Special Code</button>");
</script>