<?php
if($_REQUEST['save'])
{
	//print_r($_REQUEST); exit;
	if($_REQUEST['sub_rabill_opening']['contractor']!='')
	
	{	
			$opening_date=FormatDateForSQL($_REQUEST['sub_rabill_opening']['opening_date']);
			$_REQUEST['sub_rabill_opening']['opening_date']=$opening_date;
			extract($_REQUEST['sub_rabill_opening']);
			
		if($s->RecordInsert('sub_rabill_opening',$_REQUEST['sub_rabill_opening']))
		{
		
		}
				unset($_REQUEST['sub_rabill_opening']);	
				//print_r($_REQUEST); exit;
				$_SESSION['success_msg']="Saved Successfully";	
				echo "<script>location.href='index.php?route=SubContractors/RaBill/ra_bill_opening_entry_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";

	}
	else
	{
		echo "<script>alert('Try Again');</script>";
	}

}


	if($_REQUEST['action']=='edit' && !empty($_REQUEST['opn']))
	{	
		$recEdit=DB_fetch_array($s->GetRecordById('sub_rabill_opening','id='.$_REQUEST['opn']));
		extract($recEdit);
		
	}

if(isset($_REQUEST['update']))
{
	$opening_date=FormatDateForSQL($_REQUEST['sub_rabill_opening']['opening_date']);
			$_REQUEST['sub_rabill_opening']['opening_date']=$opening_date;	
	 $s->RecordEdit('sub_rabill_opening',$_REQUEST['sub_rabill_opening'],"id=".$_REQUEST['opn']);
		$_SESSION['success_msg']="Update Successfully";
		
		echo "<script>location.href='index.php?route=SubContractors/RaBill/ra_bill_opening_entry_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}



?>
<h3>RA Bill Posting</h3>
<form action="" method="post">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td width="22%" class="label"><strong>Project</strong></td>
        <td width="27%"><select name="sub_rabill_opening[project]" id="project">
          <option value="">Select Project</option>
        </select></td>
        <td width="21%" class="label"><strong>Block</strong></td>
        <td width="30%"><select name="sub_rabill_opening[block]" id="block">
          <option value="">Select Block</option>
        </select></td>
      </tr>
      <tr>
        <td class="label"><strong>Contractor</strong></td>
        <td><select name="sub_rabill_opening[contractor]" id="contractor">
          <option value="">Select Contractor </option>
          <?php
		$sqlcategory=DB_query("select * from sub_contractor_definition",$db);
		while($category_row=DB_fetch_array($sqlcategory))
		{
				$s='';
				if($contractor==$category_row['id'])
				$s="selected";
		?>
          <option value="<?php echo $category_row['id'];?>" <?php echo $s;?>><?php echo $category_row['contractor_name'];?></option>
          <?php } ?>
        </select></td>
        <td class="label"><strong>Work Order No.</strong></td>
        <td><select name="sub_rabill_opening[work_order_no]" id="work_order_no">
          <option value="">Select Work Order No</option>
        </select></td>
      </tr>
      <tr>
        <td class="label"><strong>Opening Date</strong></td>
        <td><input type="text" name="sub_rabill_opening[opening_date]" id="opening_date" value="<?php echo ConvertSQLDate($opening_date); ?>" class="datepicker" /></td>
        <td class="label"><strong>Ending Bill No.</strong></td>
        <td><input type="text" name="sub_rabill_opening[ending_bill_no]" id="ending_bill_no" value="<?php echo $ending_bill_no; ?>"/></td>
      </tr>
     <tr>
    <td class="label"><strong>Remarks</strong></td>
    <td colspan="6"><textarea name="sub_rabill_opening[remarks]" style="width:700; height:80;"><?php echo $remarks;?></textarea></td>
  </tr>
    </table>
	<br />
	<table width="100%" border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td width="10%"><input type="button" name="activity_details" value="Activity Details"/></td>
        <td width="11%"><input type="button" name="work_order_tax" value="Work Order Tax"/></td>
        <td width="12%"><input type="button" name="bill_summary" value="Bill Summary"/></td>
        <td width="67%">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<p align="center"> <input type="submit" value="Save" name="<?php if($_REQUEST['action']=='edit') echo 'update'; else echo 'save'; ?>"><input type="reset" name="cancel" value="Reset" /><a href="index.php?route=SubContractors/RaBill/ra_bill_opening_entry_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="back" value="Cancel" /></a></p>
</form>