<h2>Advance Management</h2>
<?php  include('includes/fun-php.php')?>
<?php 
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

$rurl="index.php?route=advance_management&modid=".$modid."&frmid=".$frmid."";

if($_REQUEST['Save'])
{
 	$data['advance_date'] = FormatDateForSQL($_REQUEST['advance_date']);
	$data['emp_id'] = $_REQUEST['emp_id'];
	$data['emp_code'] = $_REQUEST['emp_code'];
	$data['emp_name'] = $_REQUEST['emp_name'];
	$data['advance_type'] = $_REQUEST['advance_type'];
	$data['advance_amount'] = $_REQUEST['advance_amount'];
 	  
 	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( $rurl.'&action=view');
	}	
}

?>
 
 



<?php
  if($_REQUEST['action']=='Addnew')
     {?>
<form action="" method="post">
	<table border="1" cellpadding="0" cellspacing="0"  width="50%%">
	<tr><td>Employee Code: <input type="text" name="empcode" value="<?php echo $_REQUEST['empcode']; ?>"> </td>
	<td>	<input type="submit" name="Search"   value="Search"/> </td></tr></table>
</form>
<?php }  




  if(($_REQUEST['action']=='Addnew'|| $_REQUEST['action']=='Edit' )|| $_REQUEST['Search']  )
  {
  		//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'];
	 
      }
	  else{
	  	   $emp_id =$s->getField('empmaster','emp_code',$_REQUEST['empcode'],'id');
	  	 $emp_name =$s->getField('empmaster','id',$emp_id,'emp_name');
		 $emp_code =$s->getField('empmaster','id',$emp_id,'emp_code');
	  }
?>




<fieldset>

	  <legend> <strong>Employee Advance Detail</strong></legend>
   
      <form action="" method="post">
      	<input type=hidden name="emp_id" value="<?php echo $emp_id; ?>">
      <table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td width="25%">Date</td>
    <td width="75%"><input name="advance_date" type="text" class='datepicker' value="<?php  echo $advance_date?>"></td>
  </tr>
  <tr>
    <td>Emp Code</td>
    <td><input name="emp_code" type="text" value="<?php  echo $emp_code?>"></td>
  </tr>
  <tr>
    <td>Emp Name</td>
    <td><input name="emp_name" type="text" value="<?php  echo $emp_name?>"></td>
  </tr>
  <tr>
    <td>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>
  </tr>
  <tr>
    <td>Advance Amount</td>
      <td><input name="advance_amount" id='advance_amount'  type="text" value="<?php  echo $advance_amount;?>"></td>
  </tr>
   
   
 
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Save"  id="Save" value="Save"></td>
  </tr>
      </table>

      </form>
</fieldset>
      <?php } else if($_REQUEST['action']!='Addnew'&& $_REQUEST['action']!=='Edit' ) 
      {?>
<div><a href="<?php echo $rurl;?>&action=Addnew">Apply Advance</a></div>

      <table cellpadding="0" cellspacing="0" border="1" width="100%">
	<tr><td><strong>EmpCode</strong></td>
		<td><strong>EmpName</strong></td>
		<td><strong>Advance Date</strong></td>
		 
		<td><strong>Amount</strong></td>
		<td><strong>Status</strong></td>
		<td><strong>View</strong></td>		
	</tr>
	<?php
	$GetProcess = "Select * from advance_management  ";		 	   
       $ResultProcess_SalData = DB_query($GetProcess,$db);
	  // echo DB_num_rows($ResultData);
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
		<tr>
		<td><?php  echo $RowData['emp_code']?>&nbsp;</td>
		<td><?php  //echo $RowData['emp_id'];
		echo $s->getField('empmaster','id',$RowData['emp_id'],'emp_name');
			?>&nbsp;</td>
		 <td>&nbsp;<?php  echo ConvertSQLDate($RowData['advance_date'])?></td>
		 
		<td><?php  echo $RowData['advance_amount']?></td>
		<td><?php  echo $RowData['status']?></td>
		<td><a href="<?php echo $rurl.'&id='.$RowData['id'].'&emp_id='.$RowData['emp_id'].'&action=Edit' ; ?>">Edit</a></td>		
	 </tr>
	<?php }?>
</table>

	  <?php } ?>