ebpl.blade.php 16.1 KB
<?php
$reportTitle = 'Dashboard';
$returnblade = 'ebpl';

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

$reporthead=array("#","Campaign", "Normal", "Preferred", "Total Base");
$reporthead1=array("Campaign Name", "Normal", "Preferred", "Grand Total");

$alist1=$alist;
$alist=$alist->get();

//$alist1=$alist1->whereIn('c.dialer_status',array('Not Interested', 'Not Eligible'));
$alist1=$alist1->groupBy('dialer_status', 'id');
$alist1=$alist1->get();

$i=1;$reportarray=$reportarray1=array();$Preferred_head = 'Normal';$t=0;$lead_value_array = $calls_attempts = array();

if(count($alist))
	foreach($alist as $aline)
	{
		$peopledata = ($aline->peopledata != '') ? unserialize($aline->peopledata) : array();		
		$Preferred 	= (is_array($peopledata) && array_key_exists('Preferred_Tag', $peopledata)) ? $peopledata['Preferred_Tag'] : '';
		$Occupation = (is_array($peopledata) && array_key_exists('occupation', $peopledata)) ? trim($peopledata['occupation']) : '';
		
		$lead_value = $peopledata['Eligible_TopUp_Amount'];

		$Preferred_head = ($Preferred != '' && $Occupation == "Salaried") ? 'Preferred' : 'Normal';
		
		$ststr = $Preferred_head;
		
		if($aline->dialer_status == 'Interested') {
			$lead_value_array[$Preferred_head][]=$lead_value;$t = array_sum($lead_value_array[$Preferred_head]);
		}
			
		$arrayheadkey = "Data Uploaded";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr] = '';$reportarray[$arrayheadkey]["Total Base"]='';
			
		$arrayheadkey = "Data Utilised";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray["Data Utilised"][$ststr]++;
		
		$arrayheadkey = "Attempts";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$calls_attempts[$arrayheadkey][$ststr][]=$aline->calls->count();
		$reportarray[$arrayheadkey][$ststr] = array_sum($calls_attempts[$arrayheadkey][$ststr]);
			
		$arrayheadkey = "Intensity";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Data Utilised"][$ststr] != 0) ? number_format($reportarray["Attempts"][$ststr]/$reportarray["Data Utilised"][$ststr], 2) : '';
			
		$arrayheadkey = "No contact";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		
		$arrayheadkey = "Contactable";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			
		$arrayheadkey = "Not Interested";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			
		$arrayheadkey = "Not Eligible";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());

		$arrayheadkey = "FollowUp";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			
		$arrayheadkey = "Interested";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			
		$arraykey = $aline->dialer_status;		
			
		$ststr= $Preferred_head;
		$reportarray["Data Utilised"]["Customer_lists"][$ststr][] = $aline->lan;
		if($aline->dialer_status == 'No contact') { $reportarray["No contact"]["Customer_lists"][$ststr][] = $aline->lan; }
		if($aline->dialer_status != 'No contact') { $reportarray["Contactable"]["Customer_lists"][$ststr][] = $aline->lan; }
		if($aline->dialer_status == 'Interested') { $reportarray["Interested"]["Customer_lists"][$ststr][] = $aline->lan; }
		if($aline->dialer_status == 'Not Interested') { $reportarray["Not Interested"]["Customer_lists"][$ststr][] = $aline->lan; }
		if($aline->dialer_status == 'Not Eligible') { $reportarray["Not Eligible"]["Customer_lists"][$ststr][] = $aline->lan; }
		if($aline->dialer_status == 'FollowUp') { $reportarray["FollowUp"]["Customer_lists"][$ststr][] = $aline->lan; }
								
		$ststr = $Preferred_head;
		$reportarray["No contact"][$ststr] = (array_key_exists("Customer_lists", $reportarray["No contact"]) && is_array($reportarray["No contact"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["No contact"]["Customer_lists"][$ststr])) : '';
		$reportarray["Contactable"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Contactable"]) && is_array($reportarray["Contactable"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Contactable"]["Customer_lists"][$ststr])) : '';
		$reportarray["Interested"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Interested"]) && is_array($reportarray["Interested"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Interested"]["Customer_lists"][$ststr])) : '';
		$reportarray["Not Interested"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Not Interested"]) && is_array($reportarray["Not Interested"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Not Interested"]["Customer_lists"][$ststr])) : '';
		$reportarray["Not Eligible"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Not Eligible"]) && is_array($reportarray["Not Eligible"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Not Eligible"]["Customer_lists"][$ststr])) : '';
		$reportarray["FollowUp"][$ststr] = (array_key_exists("Customer_lists", $reportarray["FollowUp"]) && is_array($reportarray["FollowUp"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["FollowUp"]["Customer_lists"][$ststr])) : '';

		$arrayheadkey = "Lead Value";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]=$t;
			
		$arrayheadkey = "%Contactable";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Data Utilised"][$ststr] != 0) ? number_format(@($reportarray["Contactable"][$ststr]/$reportarray["Data Utilised"][$ststr]) * 100, 2) . '%' : '';
			
		$arrayheadkey = "%Not Interested";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Not Interested"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
			
		$arrayheadkey = "%Not Eligible";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Not Eligible"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
			
		$ststr = "Total Base";
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Data Utilised"][$ststr] != 0) ? number_format(@($reportarray["Contactable"][$ststr]/$reportarray["Data Utilised"][$ststr]) * 100, 2) . '%' : '';
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Not Interested"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Not Eligible"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
		
		if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
	}

$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("Campaign"=>'Total');
	//echo '<pre>';print_r($reportarray['Contactable']['Customer_lists']);
	foreach($reportarray as $uid=>$uarr)
	{
		$outstr.="<tr>";
		for ($head = 0; $head < $highestColumn; $head++){
			
			$u = $reportarray['Data Utilised'][$reporthead[2]]+$reportarray['Data Utilised'][$reporthead[3]];
			$c = $reportarray['Contactable'][$reporthead[2]]+$reportarray['Contactable'][$reporthead[3]];
			$ni = $reportarray['Not Interested'][$reporthead[2]]+$reportarray['Not Interested'][$reporthead[3]];
			$ne = $reportarray['Not Eligible'][$reporthead[2]]+$reportarray['Not Eligible'][$reporthead[3]];
			
			if($head < 2) {
				$data_str = $uarr[$reporthead[$head]];
			}
			else if($head == 4) {
				if($uid == '%Contactable') {					
					$data_str = number_format(@($c/$u) * 100, 2 ) . '%';//number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Interested') {
					$data_str = number_format(@($ni/$c) * 100, 2 ) . '%';
				}
				else if($uid == '%Not Eligible') {
					$data_str = number_format(@($ne/$c) * 100, 2 ) . '%';
				}
				else {
					$data_str = $uarr[$reporthead[2]]+$uarr[$reporthead[3]];
				}
			}
			elseif($head < 50) {
				$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['Attempts']) * 100, 2 ).'%</span>';
				$utotalarr[$reporthead[$head]] += $uarr[$reporthead[$head]];
			}
			$outstr.="<td>".$data_str."</td>";
		}
		$outstr.="</tr>";
	}
}
else {
	$outhead.="<tr><td>No Records Found.</td></tr>";
}

$reporthead1=array("Campaign Name", "Grand Total");
$i=1;$reportarray1=array();

if(count($alist1))
	foreach($alist1 as $aline)
	{
		$peopledata= ($aline->peopledata != '') ? unserialize($aline->peopledata) : array();

		$Preferred = (is_array($peopledata) && array_key_exists('Preferred_Tag', $peopledata)) ? $peopledata['Preferred_Tag'] : '';
		$Occupation = (is_array($peopledata) && array_key_exists('occupation', $peopledata)) ? trim($peopledata['occupation']) : '';
		
		$Preferred_head = ($Preferred != '' && $Occupation == "Salaried") ? 'Preferred' : 'Normal';
		
		$ststr = $Preferred_head;
		
		$arrayheadkey = $aline->dialer_status;
			
		if(!isset($reportarray1[$arrayheadkey]))$reportarray1[$arrayheadkey]=array("Campaign Name"=> '<b>'.$arrayheadkey.'</b>',"Grand Total"=>0);
		$reportarray1[$arrayheadkey][$ststr]++;$reportarray1[$arrayheadkey]["Grand Total"]++;
		
		//$arraykey = ($aline->userstatus == 'Not Interested') ? 'NI-' . $aline->usersubstatus : 'NE-' . $aline->usersubstatus;
		$arraykey = $aline->dialer_status . '-' . $aline->dialer_substatus; //($aline->userstatus == 'Not Interested') ? 'NI-' . $aline->usersubstatus : 'NE-' . $aline->usersubstatus;
		
		if(!isset($reportarray1[$arraykey]))$reportarray1[$arraykey]=array("Campaign Name"=>$arraykey,"Grand Total"=>0);
		$ststr = $aline->dialer_substatus; $reportarray1[$arraykey][$ststr]++; $reportarray1[$arraykey]["Grand Total"]++;

		$ststr=$Preferred_head;
		if(!in_array($ststr,$reporthead1))$reporthead1[]=$ststr;
		$reportarray1[$arraykey][$ststr]++;
	}

$highestColumn1 = sizeof($reporthead1);
if(count($reportarray1)) {
	$outhead1="<tr>";$outstr1="";
	for ($head = 0; $head < $highestColumn1; $head++){
		if($reporthead1[$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>";
			$outhead1.="<td>".$mode_str."</td>";
		}
		else {
			$outhead1.="<td>".$reporthead1[$head]."</td>";
		}
	}
	$outhead1.="</tr>";
	foreach($reportarray1 as $uid=>$uarr)
	{
		$outstr.="<tr>";
		for ($head = 0; $head < $highestColumn1; $head++){
			if($head < 1) {
				$data_str = $uarr[$reporthead1[$head]];
			}
			elseif($head < 50) {
				$data_str = $uarr[$reporthead1[$head]];
				$utotalarr[$reporthead1[$head]] += $uarr[$reporthead1[$head]];
			}
			else {
				$data_str = '<span class="summation" style="display:block;">'.$uarr[$reporthead1[$head]].'</span>';
				$data_str .= '<span class="percent" style="display:none;">'.number_format(@($uarr[$reporthead1[$head]]/$uarr['Total']) * 100, 2 ).'%</span>';
				$utotalarr[$reporthead1[$head]] += $uarr[$reporthead1[$head]];
			}
			$outstr1.="<td>".$data_str."</td>";
		}
		$outstr1.="</tr>";
	}

	$outstr1.="<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;
		
		$u = $reportarray['Data Utilised'][$reporthead[2]]+$reportarray['Data Utilised'][$reporthead[3]];
		$c = $reportarray['Contactable'][$reporthead[2]]+$reportarray['Contactable'][$reporthead[3]];
		$ni = $reportarray['Not Interested'][$reporthead[2]]+$reportarray['Not Interested'][$reporthead[3]];
		$ne = $reportarray['Not Eligible'][$reporthead[2]]+$reportarray['Not Eligible'][$reporthead[3]];

		for ($head = 0; $head < $highestColumn; $head++){
			$printval = ($head != 6) ? $uarr[$reporthead[$head]] : number_format(@($uarr[$reporthead[5]]/$uarr[$reporthead[4]]) * 100, 2 ) . '%';
			if($head == 4) {
				if($uid == '%Contactable') {
					$data_str = number_format(@($c/$u) * 100, 2 ) . '%';//number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Interested') {
					$data_str = number_format(@($ni/$c) * 100, 2 ) . '%';
				}
				else if($uid == '%Not Eligible') {
					$data_str = number_format(@($ne/$c) * 100, 2 ) . '%';
				}
				else {
					$data_str = $uarr[$reporthead[2]]+$uarr[$reporthead[3]];
				}
			}
			$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
			$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $printval);
		}
	}

	$baseRow = $row+3;

	$highestColumn1 = sizeof($reporthead1);
	for ($head = 0; $head < $highestColumn1; $head++){
		$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
		$objPHPExcel->getActiveSheet()->setCellValue($colstr.$baseRow, $reporthead1[$head]);
	}
	$baseRow++;
	foreach($reportarray1 as $uid=>$uarr)
	{
		$row = $baseRow++;
		$col = 0;

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

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

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

	return ;
}
?>

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

<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 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 $outhead1; ?></thead>
        <?php echo $outstr1; ?>
    </table>
</div>
</div>