seatCount.blade.php 2.8 KB
<?php
if(Input::has("dllogxls"))
{
	if(isset($_GET['logdate']))$logdate=strtotime($_GET['logdate']." 00:00:00");
	else $logdate=strtotime(date('Y-m-d')." 00:00:00");

	if(isset($_GET['logtodate']))$logtodate=strtotime($_GET['logtodate']." 23:59:59");
	else $logtodate=strtotime(date('Y-m-d')." 23:59:59");
	
	$ulists=DB::select(DB::raw("SELECT MONTH(crmcalls_archive.created_at) AS month, users.username, users.usertype, users.status, COUNT(DISTINCT EXTRACT(DAY FROM crmcalls_archive.created_at)) AS Number_of_Days, COUNT(DISTINCT crmcalls_archive.created_at) AS Number_of_calls FROM `users` INNER JOIN crmcalls_archive on users.id=crmcalls_archive.user_id WHERE crmcalls_archive.created_at >= '".date("Y-m-d H:i:s",$logdate)."' AND crmcalls_archive.created_at < '".date("Y-m-d H:i:s",$logtodate)."'  GROUP BY users.id, MONTH(crmcalls_archive.created_at) ORDER BY MONTH(crmcalls_archive.created_at) DESC"));

	$reportArr = array();

	foreach($ulists as $ulist)
	{
		$reportArr[] = (array)$ulist;
	}

	header('Content-Type: application/csv');
	header('Content-Disposition: attachment; filename="seatcount.csv";');
	header('Cache-Control: max-age=0');

	$headers = ['month','username','usertype','status','Number_of_Days','Number_of_calls'];

	$f = fopen('php://output','w');

	fputcsv($f, $headers);

	foreach($reportArr as $arr)
	{
		fputcsv($f, $arr);
	}
	return ;
}
else
{
?>

<div class="row">
	<div class="col-md-12">
		<div class=innerAll>

			<fieldset style='margin-bottom:2%'>
				<label>From:</label>
				<input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d"); ?>' onchange='callLogReloadFun("");' /> 
				<label>To:</label>
				<input size=10 id='modto' name='modto' type='text' value='<?php echo date("Y-m-d"); ?>' onchange='callLogReloadFun("");' /> 
			</fieldset>

			<fieldset style='margin-bottom:2%'>
				<span style="color: #fb6e52;">To Download seat count click on following button.</span><br><br>
				<input type=button class='btn btn-green' onclick="sendReq();" value="Download">
				<div style='clear:both;height: 10px;'></div>
			</fieldset>
		</div>
	</div>
	<div style='clear:both;'></div>
</div>

<script>
	$('#modfrom').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});

	$('#modto').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});

	function sendReq()
	{
		// var postdata="dwnld=download";
		// doAjax("record?action=seatcount",postdata,"employeeresult","esajaxMutex","esvarajax");
		window.open('setting/seatcount?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val());return false;
		// window.open('record/seatcount?dwnld=download');
		// return false;
	}
</script>
<?php
}