raicingcustomerreport.blade.php 8.29 KB
<?php
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;
use App\Models\SupervisonComments;

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

$agents=array();
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");



if(isset($_GET['agents']))
{
  $agents[]=$_GET['agents'];
  
  
}
else $agents="";




 /*$pb_code=implode(",",$agents);
 echo "-----".$$pb_code;*/

$userarr=array();$i=1;
$reporthead=array("id","date","pb_name","pb_code","pb_code","pb_landline_contact_no","supervisor_mail_id","group_id","group_id_name","cust_id","cust_name","relationship_with_group_id","cust_id_next","cust_name_next","relationship_with_group_id_next","new_group_addition_to_group","racing_from","supervisor_status","Submit");

if(isset($_GET['agents'])){
   print_r($agents);
    $reportarray=DB::table('potentialcustomer_details')->select('*')->where('date','>=',date("Y-m-d H:i:s",$logdate))->where('date','<=',date("Y-m-d H:i:s",$logtodate))->whereIn('pb_code',$agents)->get();

}else{

$reportarray=DB::table('potentialcustomer_details')->select('*')->where('date','>=',date("Y-m-d H:i:s",$logdate))->where('date','<=',date("Y-m-d H:i:s",$logtodate))->get();

}

//echo $reportarray;die();
/* $allusers=User::where(function ($query)  use($dashboarduser) {
            $query->where('supervisor','=',$dashboarduser->username)
            ->orWhere('lteam2','=',$dashboarduser->username)
            ->orWhere('lteam','=',$dashboarduser->username);
            })->get();
 
 foreach($allusers as $alluser){
        $usrData = json_decode($alluser->data);

        $usrHRMSData = unserialize($usrData->hrmsdata);

        if($usrHRMSData['clientsownerlist']&&$usrHRMSData['clientsownerlist']!='null')
          $client[] = $usrHRMSData['clientsownerlist'];

          $username[] = $alluser->username;
          //print_r($username);
        }*/

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++){
				if($reporthead[$head]=="date")
					$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="PotentialCustomers.xls"');
	header('Cache-Control: max-age=0');

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
	$objWriter->save('php://output');
	
	return ;
}
//echo "<pre><br>".print_r($reportarray)."</pre>";
$highestColumn = sizeof($reporthead);
//echo $highestColumn;
if(count($reportarray)) {
    $outhead="<tr>";$outstr="";$id="";
    for ($head = 0; $head < $highestColumn; $head++){

        $outhead.="<td>".$reporthead[$head]."</td>";
    }
    $outhead.="</tr>";
    
    foreach($reportarray as $uid=>$uarr)
    {

        $outstr.="<tr>";
        for ($head = 0; $head < $highestColumn; $head++){
        	if($reporthead[$head]=="date"){
        	$uarr->$reporthead[$head]=date("Y-m-d H:i:s",strtotime($uarr->$reporthead[$head])+330*60);
        	}
        	if($reporthead[$head]=="id"){
        		$id=$uarr->$reporthead[$head];
        	}
			if($reporthead[$head]=="supervisor_status"){
            	$outstr.="<td><select id='".$id."_action_taken'><option value='Pending'>Pending</option><option value='Action Taken'>Action Taken</option><option value='Rejected'>Rejected</option></select></td>";
            }else if($reporthead[$head]=="Submit"){
            	$outstr.="<td><input type='button' id='".$id."_save' value='Save' onclick='updatesupervisorfeedback($id);'></td>";
            }else {
                $outstr.="<td>".$uarr->$reporthead[$head]."</td>";
            }		
        }

        $outstr.="</tr>";
    }
}
else {
    $outhead.="<tr><td>No Records Found.</td></tr>";
}

?>

<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 class=innerAll>
<h4 style="float:left;width:50%;margin:10px 0;">Racing Customer</h4>
<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 style="margin-bottom: 5px;">
<div>

Date:From <input size=10 id='modfrom' name='modfrom' type='text' value='<?php echo date("Y-m-d",$logdate); ?>' onchange='statusLogReloadFun("");'/>
&nbsp;&nbsp;To<input size=10 id='modto' name='modto' type='text' value='<?php echo date("Y-m-d",$logtodate); ?>' onchange='statusLogReloadFun("");'/>&nbsp;&nbsp;
 <!--PB Code:
     <select id='usrname' class=select2multi  multiple="" style="width: 30%;" > -->
    <?php
      /*$companyarr=$wakka->LoadAll("select * from hrms_masters where mtype='company'");
      foreach($companyarr as $tcompany)
      {
        $seltxt='';
        if(strstr(",".$clientslist.",",",$tcompany[mkey],"))$seltxt='selected="selected"';
        echo "<option value='$tcompany[mkey]' $seltxt>$tcompany[mkey]</option>";
      }*/
    ?>
                           
    <!--  </select>  
 
       <button class="pull-right btn btn-sm btn-default" onclick='statusLogReloadFun("");return false;' title='Search' style='margin-top:-1px'><i class='fa fa-search'></i>Search</button>  --> 

</div>

<div id=createtaskdiv></div>
<hr style="margin:5px;">
<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 id=dialoglog></div>
</div>
<script>
function dlAgentlogXls()
{
	window.open('dialer/raicingcustomerreport?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val());return false;
}
function dataString()
{
    /*var agents=$('#usrname').val();
    var agentsval=[];
    
    if(agents=="" || agents==null){
        
    }else
    {
      for(i=0;i<agents.length;i++)
      {
        agentsval[i] = "'" + String(agents[i]) + "'";
      }
       agentsval=agentsval.join(",");
       
      return 'logdate='+$("#modfrom").val()+'&logdateto='+$("#modto").val()+'&agents='+agentsval;
    }*/
    return 'logdate='+$("#modfrom").val()+'&logdateto='+$("#modto").val();
}
function statusLogReloadFun(sortby)
{
    var sortstr='';if(sortby!="")sortstr="&sort="+sortby
    var searchStr = dataString();
    doAjax('dialer/raicingcustomerreport?'+searchStr+sortstr,'','rightmainreportdiv','ajax_dialer_reports','singlethis','GET');
}
function updatesupervisorfeedback(id)
{
  var supervisorstatus=$('#'+id+'_action_taken').val();
  var postdata='id='+id;
  postdata+='&supervisorstatus='+supervisorstatus;
  doAjax('racingcustupdate',postdata,'createtaskdiv','ajaxMutex_recSaveData','singlethis','POST');
}
</script>