campaignreport.blade.php 11 KB
<?php
$reportTitle = 'Campaign Wise Report';
$returnblade = 'campaignreport';

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

$alist1=$alist;

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

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

$i=1;
$reporthead=array("#","Campaign","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", "Grand Total");
$reportarray=$reportarray1=array();
if(count($alist))
	foreach($alist as $aline)
	{
		$arraykey = $aline->client;

		if(!isset($reportarray[$arraykey]))$reportarray[$arraykey]=array("#"=>$i++,"Campaign"=>$aline->client,"Data Received"=>0,"Callable Data"=>0,"Data Utilised"=>0,"Attempts"=>0,"Intensity"=>0,"Contacts"=>0,"Not Interested"=>0,"Not Eligible"=>0,"FollowUp"=>0,"Lead Count"=>0,"Lead Value"=>0,"Contacts%"=>0,"Not Interested%"=>0,"Not Eligible%"=>0,"Customer_lists"=>array());

		if(!is_null($aline->lan)) {
			$reportarray[$arraykey]["Customer_lists"][] = $aline->lan;
		}
		$reportarray[$arraykey]["Callable Data"] = count(array_unique($reportarray[$arraykey]["Customer_lists"]));
		$reportarray[$arraykey]["Data Utilised"] = count(array_unique($reportarray[$arraykey]["Customer_lists"]));
		$reportarray[$arraykey]["Attempts"]++;

		if($aline->userstatus != 'No contact')$reportarray[$arraykey]["Contacts"]++;
		
		$reportarray[$arraykey][$aline->userstatus]++;
		
		if($aline->userstatus == 'Interested') {
			//$ststr=str_replace('Top up ', '', $aline->usersubstatus);
			//$reportarray[$arraykey][$aline->usersubstatus]++;
			$reportarray[$arraykey]['Lead Count']++;
		}

		$ststr= $aline->client;
		$reportarray[$arraykey][$ststr]++;

		/* if($aline->userstatus == 'Interested') {
			$ststr=str_replace('Top up ', '', $aline->usersubstatus);
			$reportarray[$arraykey][$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');
	foreach($reportarray as $uid=>$uarr)
	{
		$outstr.="<tr>";
		for ($head = 0; $head < $highestColumn; $head++){
			if($head < 2) {
				$data_str = $uarr[$reporthead[$head]];
			}
			elseif($head == 6) {
				$data_str = number_format(@($uarr[$reporthead[5]]/$uarr[$reporthead[4]]) * 100, 2 ) . '%';
			}
			elseif($head == 15) {
				$data_str = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[4]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			elseif($head == 16) {
				$data_str = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[8]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			elseif($head == 17) {
				$data_str = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[9]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			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>";
	}

	$outstr.="<tr>";
	for ($head = 0; $head < $highestColumn; $head++)
	{
		if($head == 6) {
			$data_str = number_format(@($utotalarr[$reporthead[5]]/$utotalarr[$reporthead[4]]) * 100, 2 ) . '%';
		}
		elseif($head == 15) {
			$data_str = number_format(@($utotalarr[$reporthead[4]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%';
		}
		elseif($head == 16) {
			$data_str = number_format(@($utotalarr[$reporthead[8]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%';
		}
		elseif($head == 17) {
			$data_str = number_format(@($utotalarr[$reporthead[9]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%';
		}
		elseif($head < 50) {
			$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['Attempts']) * 100, 2 ).'%</span>';
		}
		$outstr.="<td>".$data_str."</td>";
	}
	$outstr.="</tr>";
}
else {
	$outhead.="<tr><td>No Records Found.</td></tr>";
}



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

	foreach($alist1 as $aline)
	{
		$arrayheadkey = $aline->userstatus . ' Reason';
		if(!isset($reportarray1[$arrayheadkey]))$reportarray1[$arrayheadkey]=array("Campaign Name"=>$arrayheadkey,"Grand Total"=>0);
		$ststr = $aline->client; $reportarray1[$arrayheadkey][$ststr]++; $reportarray1[$arrayheadkey]["Grand Total"]++;

		$tuser=$userarr[$aline->user_id];
		$arraykey = ($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=$aline->client;
		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>";
}
/* else {
	$outhead1.="<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++){
			$printval = ($head != 6) ? $uarr[$reporthead[$head]] : number_format(@($uarr[$reporthead[5]]/$uarr[$reporthead[4]]) * 100, 2 ) . '%';
			if($head == 15) {
				$printval = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[4]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			if($head == 16) {
				$printval = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[8]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			if($head == 17) {
				$printval = ($uarr[$reporthead[7]] != 0) ? number_format(@($uarr[$reporthead[9]]/$uarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
			}
			$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
			$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $printval);
		}
	}

	$row++;
	for ($head = 0; $head < $highestColumn; $head++){
		$printval = ($head != 6) ? $utotalarr[$reporthead[$head]] : number_format(@($utotalarr[$reporthead[5]]/$utotalarr[$reporthead[4]]) * 100, 2 ) . '%';
		if($head == 15) {
			$printval = ($utotalarr[$reporthead[7]] != 0) ? number_format(@($utotalarr[$reporthead[4]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
		}
		if($head == 16) {
			$printval = ($utotalarr[$reporthead[7]] != 0) ? number_format(@($utotalarr[$reporthead[8]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
		}
		if($head == 17) {
			$printval = ($utotalarr[$reporthead[7]] != 0) ? number_format(@($utotalarr[$reporthead[9]]/$utotalarr[$reporthead[7]]) * 100, 2 ) . '%' : '';
		}
		$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="Campaignreport.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>