<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Advance Management</h1>
<?php  include('includes/fun-php.php')?>
<?php 
$rurl="&modid=".$modid."&frmid=".$frmid."";
$target="index.php?route=HRModule/advance_management".$rurl;

if($_REQUEST['Save'])
{
 	$data['advance_date'] = FormatDateForSQL($_REQUEST['advance_date']);
	$data['emp_id'] = $_REQUEST['emp_code'];	
	$data['advance_type'] = $_REQUEST['advance_type'];
	$data['advance_amount'] = $_REQUEST['advance_amount'];
	$data['deducation_month']=$_REQUEST['deducation_month'];
	$data['deduction_year']=$_REQUEST['deduction_year'];
 	  
 	if($_REQUEST['action']!='Edit')
	$insert=$s->RecordInsert('advance_management', $data);
	else {
		$cond="id='".$_REQUEST['id']."'";
		$insert=$s->RecordEdit('advance_management', $data, $cond);
	}
	if($insert)
	{
		  echo "<center>Record Updated Successfully</center>";
		  $s->pageLocation( $target.'&action=view');
	}	
}
?>

<?php
  if($_REQUEST['action']!='Addnew' && $_REQUEST['action']!='Edit' )
     {?>
<form action="" method="post">
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr class="row1">
	 <?php if($_SESSION['frmcreate']=='0'){
    $titel="No Permission"; 
	?>
	 <td width="18%"><a href="#" title="<?php echo $titel; ?>" class="search">Apply Advance</a></td>
	<?php } else { 
$titel='Apply Advance';
?>
  <td width="20%"><a href="<?php echo $target;?>&action=Addnew"  title="<?php echo $titel; ?>">
  <input type="button" class="search" value="Apply Advance" /></a></td>
  <td width="21%" align="right">Employee Code</td>
  <td width="35%"><select name="empcode" id="empcode">
    <option value="0">Select</option>
    <?php
		  $sql_emp=DB_query("SELECT * FROM empmaster where CompanyId='".$_SESSION['ACGCompanyId']."'  order by emp_code ASC ",$db);
		  while($sql_emp_row=DB_fetch_array($sql_emp))
		  {	
		  $ss='';
		  if($_REQUEST['empcode']==$sql_emp_row['id'])
		  $ss="selected";	  
		   ?>
    <option value="<?php echo $sql_emp_row['id']; ?>" <?php echo $ss; ?>><?php echo $sql_emp_row['emp_name']."&nbsp;&nbsp;"."[".$sql_emp_row['emp_code']."]" ?></option>
    <?php } ?>
  </select></td>
<td><input type="submit" name="Search" value="Search" class="search" /></td>
<?php } ?>
	</tr>
	</table>
</form>
<?php }  
  if($_REQUEST['action']=='Addnew'|| $_REQUEST['action']=='Edit' )
  {
  		//echo $_REQUEST['empcode'];	  
	   
	  if($_REQUEST['action']=='Edit'){
	   $GetAdvanceRecord = "Select * from advance_management where id='".$_REQUEST['id']."'  ";
		$ResultAdvanceData = DB_query($GetAdvanceRecord,$db);	   
   	     $RowAdvanceData = DB_fetch_array($ResultAdvanceData);
		 $advance_date = ConvertSQLDate($RowAdvanceData['advance_date']);
		 $emp_id = $RowAdvanceData['emp_id'];
		// $emp_name =$s->getField('empmaster','id',$emp_id,'emp_name');
		// $emp_code =$s->getField('empmaster','id',$emp_id,'emp_code');
		 
		 $advance_type = $RowAdvanceData['advance_type'];
		 $advance_amount = $RowAdvanceData['advance_amount'];
         $deducation_month=$RowAdvanceData['deducation_month'];	 
      }	  
?>

	<h3>Employee Advance Detail</h3>
   
      <form action="" method="post">
      	<!--<input type="text" name="emp_id" value="<?php //echo $emp_id; ?>">-->
      <table width="100%" border="0" cellpadding="3" cellspacing="0">
	  <tr class="row1">
    <td width="13%" style="text-align:right;">Deduction Month</td>
    <td width="20%"><select name="deducation_month" id="deducation_month" >
	<?php
	$arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
				foreach ($arr as $key => $value) {
 				$p='';
 				if( $key==$deducation_month)
				$p='selected';?>
			<option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 		<?php } ?>
	</select>
	</td>
    <td width="13%" style="text-align:right;">Deduction Year</td>
    <td width="20%"><select name="deduction_year" id="deduction_year" >
		 <option value="<?php echo date('Y'); ?>"><?php echo date("Y"); ?></option>
		 <option value="<?php echo date('Y')+1; ?>"><?php echo date("Y")+1; ?></option>
		</td>
    <td width="13%" style="text-align:right;">Date</td>
    <td><input name="advance_date" type="text" class='datepicker' value="<?php  echo $advance_date?>"  /></td>
  </tr>
  <tr class="row1">
    <td style="text-align:right;">Emp. Code</td>
    <td><select name="emp_code" id="emp_code" >
	     <option value="0">Select</option>
		  <?php
		  $sql_emp1=DB_query("SELECT * FROM empmaster where CompanyId='".$_SESSION['ACGCompanyId']."'  order by emp_code ASC ",$db);
		  while($sql_emp_row1=DB_fetch_array($sql_emp1))
		  {	
		  $ss1='';
		  if($emp_id==$sql_emp_row1['id'])
		  $ss1="selected";	  
		   ?>
		   <option value="<?php echo $sql_emp_row1['id']; ?>" <?php echo $ss1; ?>>
		   <?php echo $sql_emp_row1['emp_name']."&nbsp;&nbsp;"."[".$sql_emp_row1['emp_code']."]" ?></option>
	<?php } ?>
	</select>	
	</td>
    <td style="text-align:right;">Advance Type</td>
     <td>
     <?php  $arr_advancetype=array('personal','official');
	 ?>
     <select name="advance_type" >
     <option value="000">--Select Advance Type--</option>
     <?php 
	    for($i=0;$i<count($arr_advancetype);$i++)
		{
			 $p='';
			  if($advance_type==$arr_advancetype[$i])
			  $p='selected';
	 ?>
      <option value="<?php echo $arr_advancetype[$i]?>" <?php echo $p; ?>><?php echo $arr_advancetype[$i]?></option>
    <?php } ?>
     </select></td>
    <td style="text-align:right;">Advance Amount</td>
    <td><input name="advance_amount" id='advance_amount'  type="text" value="<?php  echo $advance_amount;?>"  /></td>
  </tr>   
  <tr class="row1">
    <td colspan="6" align="center"><input type="submit" name="Save" id="Save" value="Save" class="search"></td>  
  </tr>
      </table>

      </form>

      <?php } else if($_REQUEST['action']!='Addnew'&& $_REQUEST['action']!=='Edit' ) 
      {?>

<br>
 <table cellpadding="3" cellspacing="0" border="0" width="100%" class="thborder">
	<tr>
	    <th width="12%">Emp. Code</th>
		<th>Emp. Name</th>
		<th width="8%">Advance Date</th>		 
		<th width="12%" class="text-right">Amount</th>
		<th width="6%" class="text-center">Status</th>
		<th width="6%" class="text-center">View</th>		
	</tr>
	<?php
	if(isset($_POST['Search']))
	$GetProcess = "Select * from advance_management where emp_id='".$_REQUEST['empcode']."' ";
	else	
	$GetProcess = "Select * from advance_management  ";	
	//echo $GetProcess;	 	   
       $ResultProcess_SalData = DB_query($GetProcess,$db);
	   //echo DB_num_rows($ResultData);
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
	<tr bgcolor="#fff">
		<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 style="text-align:right;"><?php echo $RowData['advance_amount']?></td>
		<td style="text-align:center;"><?php echo $RowData['status']?></td>
		<td style="text-align:center;"><?php if($_SESSION['frmEdit']=='1') {?>
		<a href="<?php echo $target.'&id='.$RowData['id'].'&emp_id='.$RowData['emp_id'].'&action=Edit' ; ?>"><img src="images/search.gif" width="15" title="search" /></a>
		<?php  } else { ?><img src="images/search.gif" width="15" title="Not Allowed" style="opacity:0.6;" /><?php } ?>		
		</td>		
	</tr>
	<?php }?>
</table>
	  <?php } ?>
</div>
</div>
	  