ebpldashboard.blade.php 17.9 KB
<?php
$reportTitle = 'Dashboard';
$returnblade = 'ebpldashboard';

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

$alist1=$alist;

$alist=$alist->whereIn('userstatus',array('Interested', 'Reprised', 'No contact', 'Not Interested', 'Not Eligible', 'FollowUp'));
$alist = $alist->select(array('c.*', 'records.peopledata'));
$alist=$alist->get();

//$alist1=$alist1->whereIn('c.userstatus',array('Not Interested', 'Not Eligible'));
$alist1 = $alist1->select(array('c.*', 'records.peopledata'));
$alist1=$alist1->groupBy('c.userstatus', 'c.id');
$alist1=$alist1->get();

$i=1;
$reporthead=array("#","Campaign", "Normal", "Preferred", "Total Base");
//"Data Received","Callable Data","Data Utilised","Attempts","Intensity","Contacts","Not Interested","Not Eligible","FollowUp","Reprised","No contact","Lead Count","Lead Value","Contacts%","Not Interested%","Not Eligible%"
$reporthead1=array("Campaign Name", "Normal", "Preferred", "Grand Total");
$reportarray=$reportarray1=array();
$Preferred_head = 'Normal';
$t=0;$a=0;$b=0;
$lead_value_array = array();
if(count($alist))
	foreach($alist as $aline)
	{		
		$peopledata= ($aline->peopledata != '') ? unserialize($aline->peopledata) : array();
		//echo '<pre>'; print_r($peopledata);
		/* if(array_key_exists('Preferred_Tag', $peopledata))
		{ */
			//echo '<pre>'; print_r($peopledata);die;
			$Preferred = (is_array($peopledata) && array_key_exists('Preferred_Tag', $peopledata)) ? $peopledata['Preferred_Tag'] : '';	
			$Occupation = (is_array($peopledata) && array_key_exists('occupation', $peopledata)) ? $peopledata['occupation'] : '';
			$lead_value = $peopledata['Eligible_TopUp_Amount'];
			
			if($Preferred == '' && $Occupation != 'Salaried'){				
				$Preferred_head = 'Normal';
				if($aline->userstatus == 'Interested')
				{ 
					$lead_value_array[$Preferred_head][$aline->lan]=$lead_value; 
					$t = array_sum($lead_value_array[$Preferred_head]);
				}
			} else {
				$Preferred_head = 'Preferred';
				if($aline->userstatus == 'Interested')
				{ 
					$lead_value_array[$Preferred_head][$aline->lan]=$lead_value;
					$t = array_sum($lead_value_array[$Preferred_head]);
				}
			}
			
			$ststr = $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());
						
			$arrayheadkey = "Attempts";
			if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			$reportarray[$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 = "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->userstatus;		
			//if(!isset($reportarray[$arraykey]))$reportarray[$arraykey]=array("#"=>$i++,"Campaign"=>$arraykey,"Customer_lists"=>array());
			
			/* $ststr= $aline->userstatus;
			$reportarray[$arraykey][$ststr]++;			
	
			$reportarray[$arraykey][$aline->userstatus]++;
	
			if($aline->userstatus == 'Interested') {
				$reportarray[$arraykey]['Lead Count']++;
			} */
			
			$ststr= $Preferred_head;
			if(!is_null($aline->lan)) {
			 $reportarray["Data Utilised"]["Customer_lists"][$ststr][] = $aline->lan;
			 if($aline->userstatus != 'No contact') { $reportarray["Contactable"]["Customer_lists"][$ststr][] = $aline->lan; }
			 if($aline->userstatus == 'Interested') { $reportarray["Interested"]["Customer_lists"][$ststr][] = $aline->lan; }
			 if($aline->userstatus == 'Not Interested') { $reportarray["Not Interested"]["Customer_lists"][$ststr][] = $aline->lan; }
			 if($aline->userstatus == 'Not Eligible') { $reportarray["Not Eligible"]["Customer_lists"][$ststr][] = $aline->lan; }
			 if($aline->userstatus == 'FollowUp') { $reportarray["FollowUp"]["Customer_lists"][$ststr][] = $aline->lan; }			 
			}			
	
			
			if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
			//$reportarray[$arraykey][$ststr]++;
			
			$ststr = $Preferred_head;
			$reportarray["Data Utilised"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Data Utilised"]) && is_array($reportarray["Data Utilised"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Data Utilised"]["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());
			$ststr = $Preferred_head;
			$reportarray[$arrayheadkey][$ststr]=$t;
			
			$arrayheadkey = "%Contactable";
			if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
			$ststr = $Preferred_head;
			$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());
			$ststr = $Preferred_head;
			$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());
			$ststr = $Preferred_head;
			$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) . '%' : '';
		/* } */
	}


$highestColumn = sizeof($reporthead);
if(count($reportarray)) { //echo '<pre>';
	$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');
	
	foreach($reportarray as $uid=>$uarr)
	{
		$outstr.="<tr>";
		for ($head = 0; $head < $highestColumn; $head++){
			if($head < 2) {
				$data_str = $uarr[$reporthead[$head]];
			}
			else if($head == 4) {
				if($uid == '%Contactable') {
					$data_str = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Interested') {
					$data_str = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Eligible') {
					$data_str = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 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>";
}



$i=1;
//$reporthead1=array("Campaign Name", "Grand Total");
$reporthead1=array("Campaign Name");
$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)) ? $peopledata['occupation'] : '';
		$lead_value = $peopledata['Eligible_TopUp_Amount'];
			
		if($Preferred == '' && $Occupation != 'Salaried'){
			$Preferred_head = 'Normal';
			/* if($aline->userstatus == 'Interested')
			{
				$lead_value_array[$Preferred_head][$aline->lan]=$lead_value;
				$t = array_sum($lead_value_array[$Preferred_head]);
			} */
		} else {
			$Preferred_head = 'Preferred';
			/* if($aline->userstatus == 'Interested')
			{
				$lead_value_array[$Preferred_head][$aline->lan]=$lead_value;
				$t = array_sum($lead_value_array[$Preferred_head]);
			} */
		}
			
		$ststr = $Preferred_head;
		
		/* if(array_key_exists('Preferred_Tag', $peopledata))
		{ */
			//echo $aline->id . ' ' . $aline->lan . ' ' .$aline->crm_id . ' ' . $aline->userstatus . '<br/>';
			$arrayheadkey = $aline->userstatus . ' Reason';
			
			if(!is_null($aline->lan)) {
				$reportarray[$arrayheadkey]["Customer_lists"][$ststr][] = $aline->lan;
			}
			$reportarray[$arrayheadkey][$ststr] = (array_key_exists("Customer_lists", $reportarray[$arrayheadkey]) && is_array($reportarray[$arrayheadkey]["Customer_lists"][$ststr])) ? count(array_unique($reportarray[$arrayheadkey]["Customer_lists"][$ststr])) : '';
			
			/* if(!is_null($aline->crm_id)) {
				$reportarray[$arrayheadkey]["Customer_lists"][] = $aline->crm_id;
			} */
			
			if(!isset($reportarray1[$arrayheadkey]))$reportarray1[$arrayheadkey]=array("Campaign Name"=>$arrayheadkey,"Grand Total"=>0);
			$ststr = $Preferred_head; 
			//$reportarray1[$arrayheadkey][$ststr]++; 
			$reportarray1[$arrayheadkey]["Grand Total"]++;
			$reportarray1[$arrayheadkey][$ststr] = (array_key_exists($arrayheadkey, $reportarray) && is_array($reportarray[$arrayheadkey]["Customer_lists"])) ? count(array_unique($reportarray[$arrayheadkey]["Customer_lists"])) : '';
			
			$tuser=$userarr[$aline->user_id];
			//$arraykey = ($aline->userstatus == 'Not Interested') ? 'NI-' . $aline->usersubstatus : 'NE-' . $aline->usersubstatus;
			$arraykey = $aline->userstatus . '-' . $aline->usersubstatus; //($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->usersubstatus; $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>";
	//$utotalarr = array("Campaign Name"=>'Not Interested Reason');
	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>";
}
$outhead1 = $outstr1 = '';

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++){
			$printval = ($head != 6) ? $uarr[$reporthead[$head]] : number_format(@($uarr[$reporthead[5]]/$uarr[$reporthead[4]]) * 100, 2 ) . '%';
			if($head == 4) {
				
				if($uid == '%Contactable') {
					$printval = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Interested') {
					$printval = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else if($uid == '%Not Eligible') {
					$printval = number_format(@(($uarr[$reporthead[2]]+$uarr[$reporthead[3]])/2), 2 ) . '%';
				}
				else {
					$printval = $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>