smslog.blade.php 6.86 KB
<?php
use App\Models\CRMCallArchive;
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;

$wakka = new KHRMSLib();
$dashboarduser=Auth::user();
$userdialmode=$dashboarduser->dialmode_assign;
$userdialmode=explode(",",$userdialmode);
$timeoffset=$dashboarduser->timezone*60;

$locationserverip=DB::select(DB::raw("SELECT location from server_details group by location"));

if(isset($_GET['logdate']))$logdate=strtotime($_GET['logdate']." 00:00:00");
else $logdate=strtotime(date('Y-m-d')." 00:00:00");

$location   =(isset($_GET['location']))  ? $_GET['location']  : "Select Location";
$i=1;
$locations=explode(",",$location);
//print_r($locations);
foreach ($locations as $location) {
	$serverid=DB::select(DB::raw("SELECT server_ip,id,location from server_details where location='$location' ORDER BY id ASC"));

	//echo "All";
//print_r($serverid);
	
//$serverip->get();
	foreach ($serverid as $server_id) {
		//$serverids=$server_id->id<10?"0".$server_id->id:$server_id->id;
		$serverids=$server_id->id;
	//print_r($server_id->server_ip);
		
			$alist=DB::select(DB::raw("SELECT * from sms_report where created_at>='".date("Y-m-d H:i:s",$logdate+$timeoffset)."' and created_at <= '".date("Y-m-d H:i:s",$logdate+24*60*60)."' and server=$serverids ORDER BY id DESC "));
		
		//print_r($alist);
		foreach ($alist as $aline) {
			$outstr.="<tr><td>".$i."</td>
			<td>".$server_id->server_ip."</td>
			<td>".$server_id->location."</td>
			<td>".$aline->message_time."</td>
			<td>".$aline->agent_name."</td>
			<td>".$aline->subdispo."</td>
			<td>".$aline->number."</td>
			<td>".$aline->message."</td>
			<td>".$aline->response."</td>
			</tr>";
			$i++;
		}
	}
}

		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;

			$tcol=0;$fieldsarr=array();$extrahdrarr=array();
			$fieldsarr[$tcol++]='#';
			$fieldsarr[$tcol++]='server_ip';
			$fieldsarr[$tcol++]='location';
			$fieldsarr[$tcol++]='message_time';
			$fieldsarr[$tcol++]='agent_name';
			$fieldsarr[$tcol++]='SubDispo';
			$fieldsarr[$tcol++]='Number';
			$fieldsarr[$tcol++]='Message';
			$fieldsarr[$tcol++]='response';

			$highestColumn = sizeof($fieldsarr);
			for ($head = 0; $head < $highestColumn; $head++){
				$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
				$objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $fieldsarr[$head]);
			}

			$ii=1;
			foreach($alist as $aline)
			{
				$row = $baseRow++;
				$col = 0;



				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($ii++);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($server_id->server_ip);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($server_id->location);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->message_time);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->agent_name);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->subdispo);
				
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->number);

				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->message);
				$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit($aline->response);
				
				
			}
			


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

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

			return ;
		}

?>

<div class=innerAll>




	<style>#logtable.td{vertical-align:top;}#logtable.tr{height:28px;overflow-y:hidden;}</style>
	<script>
		function showExtraPost(varstr)
		{
			doAjax("hr?action=LiveUsers","getpostdata="+varstr,"dialoglog");

			$('#dialoglog').dialog('open');
			return false;
		}

		$(document).ready(function()
		{
			if(!$('#dialoglog').hasClass('ui-dialog-content'))
			{
				$('#dialoglog').dialog({
					autoOpen: false,
					width: '70%',
					buttons: {
						"Ok": function() { 
							$(this).dialog("close"); 
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});
			}

			waitKeyUpRun("filter",function() { filter2(document.getElementById('filter'), 'logtable') },"2000");
			$('#modfrom').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
		});
	</script>
	<div>


		Date : <input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' /> 

			Location:<select id="location" style="border:1px solid #efefef;">
		        <option value='Select Location' disabled selected>Select Location</option>   
		        <option value='All'>All</option>
		         <?php foreach($locationserverip as $c){$s="";if($c->location==$location)$s='selected';echo "<option value='$c->location' $s>$c->location</option>";} ?>
			</select>

		<button id="load" onclick='callLogReloadFun("");return false;' value='Submit'>Submit</button>&nbsp;&nbsp;

	</div>
	<div style="float:right;width:30%">


		<button class="pull-right btn btn-sm btn-default" onclick='dlCalllogXls();return false;' title='Download' style='margin-top:-8px'><i class='fa fa-download'></i> Download</button>

	</div>

	<script>
		function dataString()
		{
			return 'logdate='+$("#modfrom").val()+'&location='+$("#location").val();
		}

		function callLogReloadFun(sortby)
		{
			var sortstr='';if(sortby!="")sortstr="&sort="+sortby
			var searchStr = dataString();
			doAjax('dialer/smslog?'+searchStr+sortstr,'','rightmainreportdiv','ajax_dialer_reports','singlethis','GET');
		}
		function dlCalllogXls()
		{
			var searchStr = dataString();
			window.open('dialer/smslog?dllogxls=1&'+searchStr);
			return false;
			
		}

	</script>

	<div style='clear:both'></div>

	<div style='overflow:auto'>
		<table id=logtable class='footable table table-striped table-bordered table-white table-primary footable-loaded' style='font-size:12px'>
			<thead>
				<tr>
					<th>#</th>
					<th>ServerIp</th>
					<th>Location</th>
					<th>Message Time</th>
					<th>RM Name</th>    
					
					<th>SubDispo</th>
					<th style='width:120px'>Number</th>
					<th>Message</th>
					<th>Response</th>
					
					
				</tr>
			</thead>
			<?php echo $outstr; ?>
		</table>
	</div>
	<?php
	function convert($size)
	{
		$unit=array('b','kb','mb','gb','tb','pb');
		return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
	}

echo "<br>".convert(memory_get_peak_usage(true)); // 123 kb


?>
<div id=dialoglog></div>





</div>