questairereport.blade.php 5.14 KB
<?php
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;
use DB;

$wakka = new KHRMSLib();
$dashboarduser=Auth::user();

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

$alist=CRMCall::where('created_at','>=',date("Y-m-d H:i:s",$logdate))->where('created_at','<=',date("Y-m-d H:i:s",$logdate+24*60*60));

//if(!$dashboarduser->moduleACL("Dialer",false,false,true))
if($dashboarduser->usertype != 'Admin')
{
	$uidlist=array($dashboarduser->id);
	$allusers=User::where(function ($query)  use($dashboarduser) {
			$query->where('supervisor','=',$dashboarduser->username)
			->orWhere('lteam2','=',$dashboarduser->username)
			->orWhere('lteam','=',$dashboarduser->username);
	})->get();
// 	->where(function ($query) {
// 			$query->where('status', '=', 'Active');
// 	})->get();
	
	foreach($allusers as $tuser)$uidlist[]=$tuser->id;


	$roclientstr=array();$didlinesstr=array();
	if($dashboarduser->exten!="")$didlinesstr[]=$dashboarduser->exten;
	$oclientlst=$wakka->clientsReadAccess();
	if(!empty($oclientlst))foreach($oclientlst as $tclnt)if($tclnt!="")
	{
		$roclientstr[]="$tclnt";
		
		$mastersdata=$wakka->getCompanyMaster($tclnt);
		if(!empty($mastersdata["DialerDID"]))$didlinesstr[]=$mastersdata["DialerDID"];
	}
	
	$alist=$alist->where(function ($query) use($roclientstr,$uidlist,$didlinesstr){
		$query->orWhereIn('client',$roclientstr)
		->orWhereIn('user_id',$uidlist)
		->orWhereIn('did',$didlinesstr);
	});
	
}

$alist=$alist->get();

$userarr=array();$i=1;
$reporthead=array("id","created_at","updated_at","user_id","cust_id","call_id","name","number","question_time","auth_question_1","auth_opt_1","auth_question_2","auth_opt_2","auth_question_3","auth_opt_3","auth_question_4","auth_opt_4","auth_question_5","auth_opt_5","question","primary_question","primary_response","primary_text","followup_question","followup_response","followup_text","secondary_question","secondary_response","secondary_text");
$reportarray=DB::table('questionaire_details')->select('*')->get();

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;
			
			if($urr->auth_question!='')
			{
			$urr->auth_question = (array)json_decode($urr->auth_question);
			}
			
			for ($head = 0; $head < $highestColumn; $head++){
				$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
				$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $uarr->$reporthead[$head]);
			}
	}


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

  $('#modto').datepicker({dateFormat: 'yy-mm-dd',inline: true,changeYear: true,selectOtherMonths: true,yearRange: '<?php echo (date('Y')-70).":".(date('Y')+5); ?>'});
});
</script>
<div style="float:left;width:50%">
 

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


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

</div>
<div style="clear:both"></div>
<hr>

<div class=col-md-12>


<div id=userlogschart1 style='min-height:300px;width:100%'></div>
</div>

<script>
function dlAgentlogXls()
{
	window.open('dialer/questionnaire?dllogxls=1&logdate='+$("#modfrom").val());return false;
}
</script>

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

<div class=col-md-12>


<div id=userlogschart2 style='min-height:300px;width:100%'></div>

</div>



<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>
	<?php /*echo $outhead;*/ ?>
</thead>
<?php /*echo $outstr;*/ ?>
</table>
</div>

<div id=dialoglog></div>

                
                
                
                
            </div>