<?php 
$url_cancel= "index.php?route=ToolPlants/maintenance/asset_maintenance_bill_entry_index".$rurl;
$url_add= "index.php?route=ToolPlants/maintenance/asset_maintenance_bill_entry".$rurl;

//echo $rurl;
?>

<?php
if(isset($_REQUEST['save']))
{	
	
	//print_r($_REQUEST); exit;
		$date=FormatDateForSQL($_REQUEST['tpl_asset_maintenace_bill']['bill_date']);
		
			$_REQUEST['tpl_asset_maintenace_bill']['bill_date']=$date;
			
		extract($_REQUEST['tpl_asset_maintenace_bill']);
		if($s->RecordInsert('tpl_asset_maintenace_bill',$_REQUEST['tpl_asset_maintenace_bill']))
		{	
			
				//print_r($_REQUEST); exit;
				$_SESSION['success_msg']="Saved Successfully";
				echo "<script>location.href='$url_cancel'</script>";			

		 }
	
}
if(isset($_REQUEST['action']) && isset($_REQUEST['amid']))
{
	if($_REQUEST['action']=='edit' && !empty($_REQUEST['amid']))
	{	
		$recEdit=DB_fetch_array($s->GetRecordById('tpl_asset_maintenace_bill','id='.$_REQUEST['amid']));
		extract($recEdit);
		
	}
}
if(isset($_REQUEST['update']))
{
			$date=FormatDateForSQL($_REQUEST['tpl_asset_maintenace_bill']['bill_date']);
		
			$_REQUEST['tpl_asset_maintenace_bill']['bill_date']=$date;
		extract($_REQUEST['tpl_asset_maintenace_bill']);
		
		if($s->RecordEdit('tpl_asset_maintenace_bill',$_REQUEST['tpl_asset_maintenace_bill'],"id=".$_REQUEST['tpl_asset_maintenace_bill']['id']))
		{
		
		//print_r($_REQUEST);exit;
			unset($_REQUEST['tpl_asset_maintenace_bill']);
			$_SESSION['success_msg']="Saved Successfully";
			echo "<script>location.href='$url_cancel'</script>";
	}
	
}

?><head>

</head>

<form name="" id="" method="POST">
<div align="center">
<fieldset style="width:800px"><legend><strong>Asset Maitenance Bill Entry</strong></legend>	
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td style="padding:5px"><!-- General details -->
      <table width="100%" cellspacing="4" cellpadding="4" border="0" style="color:#ffffff>
        <tr>
          <td style="padding:5px; text-align:center;" colspan="4" align="right"></td>
        </tr>
        <tr>
          <td style="text-align:center;" colspan="4"><b></b></td>
        </tr>
          <input type="hidden" value="<?php if($_REQUEST['action']=='edit') echo $id; ?>" name="tpl_asset_maintenace_bill[id]">
          <tr style="height:25px">
          <th> Project </th>
          <td width="30%" align="left" >
          	<select name="tpl_asset_maintenace_bill[project]" id="project" style="width:100%;">
			<option value="">Select</option>
			 <?php
		    $query4=DB_query("Select * from locations ",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($project==$row4['loccode'])
					$s="selected";
					?>
					<option value=<?php echo $row4['loccode'];?> <?php echo $s;?>><?php echo $row4['locationname'];?></option>
				<?php }
		  ?>
			</select>
          </td>
         
          <th>Bill No.</th>
          <td width="30%" align="left"  >
          	<input type="text"  value="<?php echo $bill_no;?>" style="width:98%;"   name="tpl_asset_maintenace_bill[bill_no]" id="bill_no">
       	 </td>
        </tr>
         <tr style="height:25px">
          <th> Vendor </th>
          <td width="30%" align="left" >
          	<select name="tpl_asset_maintenace_bill[vendor]" id="vendor" style="width:100%;">
			<option value="">Select</option>
			 <?php
		    $query4=DB_query("SELECT * FROM suppliers",$db);
			while($row4=DB_fetch_array($query4))
				{
					$s='';
					if($vendor==$row4['id'])
					$s="selected";
					?>
					<option value=<?php echo $row4['id'];?> <?php echo $s;?>><?php echo $row4['vendor_name'];?></option>
				<?php }
		  ?>
		  </select>
         </td>
         
          <th>Bill Date</th>
          <td width="30%" align="left"  >
          	<input type="text" value="<?php if($bill_date!='') echo ConvertSqlDate($bill_date);?>"  style="width:98%;"   name="tpl_asset_maintenace_bill[bill_date]" id="bill_date" class="datepicker">
    	  </td>
       </tr>
       <tr style="height:25px">
          <th> Maintenance Type </th>
          <td>
          	<table width="100%" border="0" cellspacing="1" cellpadding="0">
                           <tr>
                             <td style="text-align:center;">Preventive</td>
                             <td align="center" style="text-align:center;"><input type="radio" name="tpl_asset_maintenace_bill[maintenance_type]"  value="Y" <?php if($maintenance_type=='P') { echo "checked=checked"; }?>/></td> 
                         
                              <td style="text-align:center;">Accidental</td>
                             <td align="center" style="text-align:center;"><input type="radio" name="tpl_asset_maintenace_bill[maintenance_type]"  value="N" <?php if($maintenance_type=='A') { echo "checked=checked"; }?>/></td>
                           </tr>
                         </table></td>
         
          <th>Bill Ref. No.</th>
          <td width="30%" align="left">
          	<input type="text" value="<?php echo $bill_refno;?>" style="width:98%;"   name="tpl_asset_maintenace_bill[bill_refno]" id="bill_refno">
    	  </td>
       </tr>
       <tr style="height:25px">
       <th>Remarks</th>
          <td width="30%" colspan="2">
          <textarea name="tpl_asset_maintenace_bill[remarks]" style="width:450px"><?php echo $remarks;?></textarea>
          
    	  </td>
       </tr>
        <tr>
		<input type="hidden" name="tpl_asset_maintenace_bill[created]" value="<?php echo date('Y-m-d')?>">
		   <input type="hidden" name="tpl_asset_maintenace_bill[created_by]" value="<?php echo $_SESSION['UserID']?>">

          <td style="padding:5px; text-align:center;" colspan="4" align="right">
		  <input type="submit" value="Save" name="<?php if($_REQUEST['action']=='edit') echo 'update'; else echo 'save'; ?>" class="add">    <a href="<?php echo $url_cancel;?>"><input type="button" value="Cancel" name="button" class="add"></a>
</td>
        </tr>
      </table></td>
  
  </tr>
</table></fieldset>
</div></form>

<div align="center">
<div style="overflow:auto; width:800px; height:150px">
<table width="100%" border="0" align="center">
<tr>
<td bgcolor="#c6c6c6" ><table width="100%" border="0" cellspacing="1" cellpadding="5" align="center">
  <tr>
  	<th><strong>Select</strong></th>
  	<th><strong>Asset Name</strong></th>
    <th><strong>Asset Code</strong></th>
    <th><strong>Amount</strong></th>
   	<th><strong>Addition Amount</strong></th>
   	<th><strong>Deduction Amount</strong></th>
   	<th><strong>Spare Parts Cost</strong></th>
   	<th><strong>Service Charge</strong></th>
   
  </tr>
<tr bgcolor="#ffffff">
 </tr>
 </table>
</td>
</tr>
</table>
</div>
</div>
