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

$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");

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

$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","question","primary_question","primary_response","primary_text","followup1_question","followup1_response","followup1_text","followup2_question","followup2_response","followup2_text","followup3_question","followup3_response","followup3_text","followup4_question","followup4_response","followup4_text","followup5_question","followup5_response","followup5_text","followup6_question","followup6_response","followup6_text","followup7_question","followup7_response","followup7_text");
//$reportarray=DB::table('questionaire_details')->select('*')->get();

$reportarray=DB::table('questionaire_details')->select('*')->where('updated_at','>=',date("Y-m-d H:i:s",$logdate))->where('updated_at','<=',date("Y-m-d H:i:s",$logtodate))->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++){

				if($reporthead[$head]=="created_at")
					$uarr->$reporthead[$head]=date("Y-m-d H:i:s",strtotime($uarr->$reporthead[$head])+330*60);

				if($reporthead[$head]=="updated_at")
                        $uarr->$reporthead[$head]=date("Y-m-d H:i:s",strtotime($uarr->$reporthead[$head])+330*60);

                if($reporthead[$head]=="question_time")
					$uarr->$reporthead[$head]=date("Y-m-d H:i:s",strtotime($uarr->$reporthead[$head])+330*60);

				$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%">

From : <input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' />
&nbsp;&nbsp;To : <input size=10 id='modto' name='modto' type='text' value='<?php echo date("Y-m-d",$logtodate); ?>' />
 
</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;

	window.open('dialer/questionnaire?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").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>