raicingcustomerreport.blade.php 10.8 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();
$sup_status="";
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="";

if(isset($_GET['sup_status'])) $sup_status=$_GET['sup_status'];
else $sup_status="";


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

$userarr=array();$i=1;
$reportarray=array();
$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","supervisor_update","Submit");

if($agents=="" && $sup_status=="")
{

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

}else if($agents!="" && $sup_status==""){
   
  $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))->where('pb_code','=',$agents)->get();

}else if($agents=="" && $sup_status!="")
{
  
 /* $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).'"')->where('supervisor_statu','=','"'.$sup_status.'"')->get();*/

  $reportarray = DB::select(DB::raw("SELECT * FROM potentialcustomer_details where date >='".date("Y-m-d H:i:s",$logdate)."' and date <= '".date("Y-m-d H:i:s",$logtodate)."' and supervisor_status='".$sup_status."' "));

  
}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))->where('pb_code','=',$agents)->where('supervisor_status','=','"'.$sup_status.'"')->get();*/

  $reportarray = DB::select(DB::raw("SELECT * FROM potentialcustomer_details where date >='".date("Y-m-d H:i:s",$logdate)."' and date <= '".date("Y-m-d H:i:s",$logtodate)."' and pb_code = '".$agents."' and supervisor_status='".$sup_status."' "));
}

//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);
$supervisorstatus="";
//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"){
             $supervisorstatus=$uarr->$reporthead[$head];
            	$outstr.="<td><select id='".$id."_action_taken'><option value=".$supervisorstatus.">".$supervisorstatus."</option><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   style="width: 20%;" >
    <?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='$agents'>$agents</option> <option value='$tcompany[mkey]' $seltxt>$tcompany[mkey]</option>";
      }
    ?>
                           
    </select>
     Supervisor Status:<select class=select2multi id='sup_status' style="width: 20%;">
     <option value=''></option>
      <option value='Pending'>Pending</option>
      <option value='Action Taken'>Action Taken</option>
      <option value='Rejected'>Rejected</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()
{
  var agents=$('#usrname').val();
  var sup_status=$('#sup_status').val();
  if(agents=="" && sup_status=="" ){
    window.open('dialer/raicingcustomerreport?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val());return false;
  }else if(sup_status=="" && agents!=""){
    window.open('dialer/raicingcustomerreport?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&agents='+agents);return false;
  }else if(sup_status!="" && agents==""){
    window.open('dialer/raicingcustomerreport?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&sup_status='+sup_status);return false;
  }else{
    window.open('dialer/raicingcustomerreport?dllogxls=1&logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&agents='+agents+'&sup_status='+sup_status);return false;
  }
	
}
function dataString()
{
  
  var agents=$('#usrname').val();
  var sup_status=$('#sup_status').val();
    
  if(agents=="" && sup_status=="" )
  {
    return 'logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()
  }
  else if(sup_status=="" && agents!="")
  {
    return 'logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&agents='+agents;
  }else if(sup_status!="" && agents==""){
      return 'logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&sup_status='+sup_status;
  }
  else
  {
    return 'logdate='+$("#modfrom").val()+'&logtodate='+$("#modto").val()+'&agents='+agents+'&sup_status='+sup_status;
  }
    
}
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>