<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<?php //error_reporting(0);
include('includes/fun-php.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="index.php?route=master_payslip&action=View&modid=".$modid."&frmid=".$frmid.""; 
?>
<form action="" method="post">
<table border="0" cellpadding="3" cellspacing="0" width="100%" align="center">
<tr class="row1">
	<td width="13%" align="right"><strong>Branch</strong></td>
	<td width="32%"><select name="site" id="site" onchange="showemp(this.value)" style="width:98%;">
    <option value="0">Select</option>
    <?php
    $sql_site=DB_query("select * from locations",$db);
    while($row=DB_fetch_array($sql_site))
    {
    ?>
    <option value="<?php echo $row['loccode']; ?>" <?php if($_REQUEST['site']==$row['loccode']) { ?> selected <?php }?> ><?php echo $row['locationname']; ?></option>
    <?php } ?>
    </select>
	</td>
	<td width="13%" align="right"><strong>Employee</strong></td>
	<td><select name="empcode" id="empcode" style="width:98%;">
		<option value="0">Select</option>
      <?php
     $sql_emp=DB_query("select * from empmaster where emp_site='".$_REQUEST['site']."'",$db);
     while($row1=DB_fetch_array($sql_emp))
     {
     ?>
     <option value="<?php echo $row1['id'] ?>" <?php if($_REQUEST['empcode']==$row1['id']) { ?> selected <?php }?>  ><?php echo $row1['emp_name'] ?></option>
     <?php } ?>
     </select>
		</td>
</tr>
<tr class="row1">
 <td align="right"><strong>Month</strong></td>
 <td><select name="paymonth" style="width:98%;">
 <?php
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 foreach ($arr as $key => $value) {
 	$p='';
 	if( $key==$_REQUEST['paymonth'])
	$p='selected';
   ?><option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 <?php } ?></select>
	  </td>   
   <td align="right"><strong>Year</strong></td>
 <td><select name="payyear" style="width:98%;">
 <?php
 
 for($i=date('Y');$i>2000;$i--)
 {
 	$p='';
 	if( $i==$_REQUEST['payyear'])
	$p='selected';
 ?><option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 <?php 
 }
 ?></select>
	  </td>       
  </tr>
  <tr class="row1">
  <td colspan="4" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search"/></td>
  </tr>
  </table>	
</form>	

<?php 
  if($_REQUEST['Search'] )
  {
  	$filter=array();

	if($_REQUEST['payyer']!='')
	$filter[]="year(B.advance_date)='".$_REQUEST['payyer']."'";	
    if($_REQUEST['paymonth']!='')
   	$filter[]="month(B.advance_date)='".$_REQUEST['paymonth']."'";
    if($_REQUEST['empcode']!='0')
    $filter[]="B.emp_id ='".$_REQUEST['empcode']."'";	
    if($_REQUEST['site']!='0')
    $filter[]="A.emp_site='".$_REQUEST['site']."'";	
    if(!empty($filter))
	$filter1=implode(" and ",$filter);
	  
	 
?>
<p align="right"><a href="advance_report_print.php" target="_blank"><input type="button" class="Search" value="Print" /></a></p> 
 <table cellpadding="3" cellspacing="0" border="1" width="100%" style="border:#808080 1px solid; border-collapse:collapse;">
	<tr>
		<th width="16%"><strong>Emp Code</strong></th>
		<th><strong>Emp Name</strong></th>
		<th width="10%"><strong>Advance Date</strong></th>	
		<th width="14%"><strong>Amount</strong></th>			
		<th width="8%"><strong>Status</strong></th>
	</tr>
	<?php
	    $GetProcess = "Select B.* from advance_management B inner join empmaster A on A.id=B.emp_id where ".$filter1." ";	
	    $_SESSION['advance_query']=$GetProcess;	 	   
        $ResultProcess_SalData = DB_query($GetProcess,$db);	 
        if(DB_num_rows($ResultProcess_SalData)>0)
        {
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
	<tr bgcolor="#FFFFFF">
		<td><?php  echo $s->getField('empmaster','id',$RowData['emp_id'],'emp_code')?></td>
		<td><?php 	echo $s->getField('empmaster','id',$RowData['emp_id'],'emp_name');	?></td>
		<td><?php  echo ConvertSQLDate($RowData['advance_date'])?></td>		 
		<td><?php  echo $RowData['advance_amount']?></td>
		<td><?php  echo $RowData['status']?></td>
	</tr>
	<?php } } else { ?>
<tr bgcolor="#fff"><td colspan="5" align="center">No Records Found</td></tr>
	<?php } ?>
</table>
<?php } ?>
</div>
</div>
<script type="text/javascript">
function showemp(str)
{
var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else 
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{	
		//alert(xmlhttp.responseText)
	 	document.getElementById("empcode").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","ajax_site_wise_emp.php?site="+str,true);
	xmlhttp.send();
}
</script>