onlinechannel.blade.php 10.5 KB
<?php
$reportTitle = 'Online Channel';
$returnblade = 'onlinechannel';

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

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

$i=1;
$reporthead=array("#","Campaign");
$reportarray=array();

if(count($alist))
	foreach($alist as $aline)
	{
		$peopledata= ($aline->peopledata != '') ? unserialize($aline->peopledata) : array();
		$mass_channel = (is_array($peopledata) && array_key_exists('Mass Channel', $peopledata)) ? $peopledata['Mass Channel'] : '';
			
		$ststr = $mass_channel;
		
		$arrayheadkey = "Data Received";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr] = '';$reportarray[$arrayheadkey]["Total Base"]='';
		
		$arrayheadkey = "Uploaded";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr] = '';$reportarray[$arrayheadkey]["Total Base"]='';
			
		$arrayheadkey = "Dialed";
		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 = "Attempt Intensity";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Dialed"][$ststr] != 0) ? number_format($reportarray["Attempts"][$ststr]/$reportarray["Dialed"][$ststr], 2) : '';
		
		$arrayheadkey = "Yet TO Call";
		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->userstatus;
		
		$ststr= $mass_channel;
		if(!is_null($aline->crm_id)) {
			$reportarray["Dialed"]["Customer_lists"][$ststr][] = $aline->crm_id;
			if($aline->userstatus != 'No contact') { $reportarray["Contactable"]["Customer_lists"][$ststr][] = $aline->crm_id; }
			if($aline->userstatus == 'Interested') { $reportarray["Interested"]["Customer_lists"][$ststr][] = $aline->crm_id; }
			if($aline->userstatus == 'Not Interested') { $reportarray["Not Interested"]["Customer_lists"][$ststr][] = $aline->crm_id; }
			if($aline->userstatus == 'Not Eligible') { $reportarray["Not Eligible"]["Customer_lists"][$ststr][] = $aline->crm_id; }
			if($aline->userstatus == 'FollowUp') { $reportarray["FollowUp"]["Customer_lists"][$ststr][] = $aline->crm_id; }
		}
			
		if(!in_array($ststr,$reporthead))$reporthead[]=$ststr;
			
		$ststr = $mass_channel;
		$reportarray["Dialed"][$ststr] = (array_key_exists("Customer_lists", $reportarray["Dialed"]) && is_array($reportarray["Dialed"]["Customer_lists"][$ststr])) ? count(array_unique($reportarray["Dialed"]["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 = "%RPC/dialed";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$ststr = $mass_channel;
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Dialed"][$ststr] != 0) ? number_format(@($reportarray["Contactable"][$ststr]/$reportarray["Dialed"][$ststr]) * 100, 2) . '%' : '';
			
		$arrayheadkey = "%Lead/RPC";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$ststr = $mass_channel;
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Interested"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
			
		$arrayheadkey = "%Lead/Dialed";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$ststr = $mass_channel;
		$reportarray[$arrayheadkey][$ststr]= ($reportarray["Contactable"][$ststr] != 0) ? number_format(@($reportarray["Interested"][$ststr]/$reportarray["Contactable"][$ststr]) * 100, 2) . '%' : '';
		
		$arrayheadkey = "Logged-in count";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]='';
		
		$arrayheadkey = "Logged-in Value";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]='';
		
		$arrayheadkey = "Booked count";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$ststr]='';
		
		$arrayheadkey = "Booked Cases_Value";
		if(!isset($reportarray[$arrayheadkey]))$reportarray[$arrayheadkey]=array("#"=>$i++,"Campaign"=>$arrayheadkey,"Customer_lists"=>array());
		$reportarray[$arrayheadkey][$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 < 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>";
}


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 ) . '%';
			$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
			$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $printval);
		}
	}

	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="OnlineChannel.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>