<?php
//*************************INSERT THE DATA IN THE TABLE*******************START HERE****************************/

if(isset($_POST['Continue']))
{
	$adhoc_total_adv=$_REQUEST['adhoc_total_adv'];
	$adhoc_total_adv_recoverd=$_REQUEST['adhoc_total_adv_recoverd'];
	$sub=$adhoc_total_adv-$adhoc_total_adv_recoverd;
	$data['project']=$_REQUEST['project'];
	$data['block']=$_REQUEST['block'];
	$data['contractor']=$_REQUEST['contractor'];
	$data['work_order_no']=$_REQUEST['work_order_no'];
	$data['bill_no']=$_REQUEST['bill_no'];
	$data['mbookno']=$_REQUEST['mbook_no'];
	$data['bill_date']=FormatDateForSQL($_REQUEST['bill_date']);
	$data['bill_ref_no']=$_REQUEST['bill_ref_no'];
	$data['retention_perc']=$_REQUEST['retention_perc'];
	$data['retention_release_date']=$_REQUEST['retention_release_date'];
	$data['wo_start_date']=FormatDateForSQL($_REQUEST['wo_start_date']);
	$data['wo_comp_date']=FormatDateForSQL($_REQUEST['wo_comp_date']);
	$data['remarks']=$_REQUEST['remarks'];
	$data['adhoc_total_adv']=$_REQUEST['adhoc_total_adv'];
	$data['adhoc_bal_adv']=$sub;
	$data['adhoc_total_adv_recoverd']=$_REQUEST['adhoc_total_adv_recoverd'];
	$data['adhoc_adv_for_this_bill']=$_REQUEST['adhoc_adv_for_this_bill'];
	//$data['mobillisation_total_adv']=$_REQUEST['mobillisation_total_adv'];
//	$data['mobillisation_bal_adv']=$_REQUEST['mobillisation_bal_adv'];
//	$data['mobillisation_total_adv_recoverd']=$_REQUEST['mobillisation_total_adv_recoverd'];
//	$data['mobillisation_adv_for_this_bill']=$_REQUEST['mobillisation_adv_for_this_bill'];
//	
//	$data['discount_total_dis']=$_REQUEST['discount_total_dis'];
//	$data['discount_bal_dis']=$_REQUEST['discount_bal_dis'];
//	$data['discount_total_dis_recovered']=$_REQUEST['discount_total_dis_recovered'];
//	$data['discount_current_discount']=$_REQUEST['discount_current_discount'];
//	$data['final_bill']=$_REQUEST['final_bill'];
	$data['bill_amt']=$_REQUEST['bill_amt'];
	$data['material_value']=$_REQUEST['material_value'];
	$data['tax_addition']=$_REQUEST['tax_addition'];
	$data['tax_deduction']=$_REQUEST['tax_deduction'];
	$data['total_addition']=$_REQUEST['total_addition'];
	$data['total_deduction']=$_REQUEST['total_deduction'];
	$data['retention_amt']=$_REQUEST['retention_amt'];
	$data['rounded_amt']=$_REQUEST['rounded_amt'];
	$data['hold_amt']=$_REQUEST['hold_amt'];
	$data['net_amt']=$_REQUEST['net_amt'];
	$data['certified_amt']=$_REQUEST['certified_amt'];
	$s->RecordInsert('sub_ra_bill_preparation',$data);//INSERT THE DATA
	$dataupdate['ra_bill_status']='Created';
 	$cond="mbook_no='".$_REQUEST['mbook_no']."' and rabill_no='".$_REQUEST['bill_no']."'";
	$s->RecordEdit('sub_mbook_submission', $dataupdate, $cond);//UPDATE THE STATUS IN PREVIOUS TABLE
	
	$_SESSION['success_msg']="Saved Successfully";
	$s->pageLocation("index.php?route=SubContractors/RaBill/ra_bill_preparation_index".$rurl);
}

//*************************INSERT THE DATA IN THE TABLE*******************END HERE****************************/


if($_REQUEST['action']=='edit' and $_REQUEST['opn']!='')
{
$sql=DB_query("select * from sub_ra_bill_preparation where id='".$_REQUEST['opn']."'",$db);
$query=DB_fetch_array($sql);	
extract($query);	
}
if(isset($_POST['Update']))
{
	$start_date=FormatDateForSQL($_REQUEST['sub_ra_bill_preparation']['bill_date']);
	$start_date1=FormatDateForSQL($_REQUEST['sub_ra_bill_preparation']['retention_release_date']);
	$start_date2=FormatDateForSQL($_REQUEST['sub_ra_bill_preparation']['from_date']);    
	$start_date3=FormatDateForSQL($_REQUEST['sub_ra_bill_preparation']['to_date']);   
	$_REQUEST['sub_ra_bill_preparation']['bill_date']=$start_date;
	$_REQUEST['sub_ra_bill_preparation']['retention_release_date']=$start_date1;
	$_REQUEST['sub_ra_bill_preparation']['from_date']=$start_date2;
	$_REQUEST['sub_ra_bill_preparation']['to_date']=$start_date3;
	extract($_REQUEST['sub_ra_bill_preparation']);
	$s->RecordEdit('sub_ra_bill_preparation',$_REQUEST['sub_ra_bill_preparation'],"id=".$_REQUEST['opn']);
	$_SESSION['success_msg']="Update Successfully";
	echo "<script>location.href='index.php?route=SubContractors/RaBill/ra_bill_preparation_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>

<!-------------------------------AJAX FILES-------------------------START HERE------------------------------------->



<script language="javascript" type="text/javascript">
function getblock_conractor_for_rabill(str)
{
	//alert(str);
	var xmlhttp;
	if(str=='')
	{
	document.getElementById("project").innerHTML='';
	return false;
	}
	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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("BId").innerHTML=data[0];
	document.getElementById("contra").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","Get_block_conractor_for_rabill.php?q="+str,true);
	xmlhttp.send();
}
function showMbookno(str)
{
	//alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no").innerHTML="";
	return;
	}
	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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("workorderno").innerHTML=data[0];
	document.getElementById("RABILLNO").innerHTML=data[1];
	document.getElementById("MBOOKNO").innerHTML=data[2];
	document.getElementById("BILL_AMT").innerHTML=data[3];
	}
	}
	xmlhttp.open("GET","get_Mbook_submission_no_for_rabill.php?str="+str,true);
	xmlhttp.send();
}


function showdata(str)
{
//alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no").innerHTML="";
	return;
	}
	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)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("TOTAL_ADV_AMT").innerHTML=data[0];
	document.getElementById("BAL_ADV_AMT").innerHTML=data[1];
	document.getElementById("Total_adv_rec").innerHTML=data[2];
	document.getElementById("Adv_for_this_bill").innerHTML=data[3];
	document.getElementById("WO_START_DATE").innerHTML=data[4];
	document.getElementById("WO_COMP_DATE").innerHTML=data[5];
	}
	}
	xmlhttp.open("GET","get_data_for_advance_posting.php?str="+str,true);
	xmlhttp.send();
}


<!-------------------------------AJAX FILES-------------------------END HERE------------------------------------->



<!-------------------------------JS FILES-------------------------START HERE------------------------------------->


function getcal()
{
var b=parseFloat(document.getElementById("adhoc_total_adv_recoverd1").value);
var a=parseFloat(document.getElementById("adhoc_adv_for_this_bill").value);

var c=b+a;
document.getElementById("adhoc_total_adv_recoverd").value=c;
}


function tax_add()
{
var a=parseFloat(document.getElementById("bill_amt").value);
var b=parseFloat(document.getElementById("tax_rate").value);
var c=(a*b)/100;
document.getElementById("tax_addition").value=c;
}

function tatal_add()
{
	var a=parseFloat(document.getElementById("bill_amt").value);
	var b=parseFloat(document.getElementById("tax_addition").value);
	var c=a+b;
	document.getElementById("total_addition").value=c;
}

function netAmmout()
{
	var a=parseFloat(document.getElementById("total_addition").value);
	document.getElementById("net_amt").value=a;
}


<!-------------------------------AJAX FILES-------------------------END HERE------------------------------------->

</script>
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<div class="tender_main_page">
<h3> RA BILL Preparation</h3>
<form action="" method="post">
<table width="100%" border="1"  cellpadding="3">
  <tr>
    <td class="tabledata">Project</strong></td>
    <td><select name="project" id="project" onchange="getblock_conractor_for_rabill(this.value)">
		<option value="">Select Project</option>
		<?php
		$proj=DB_query("select * from locations",$db);
		while($locdata=DB_fetch_array($proj))
		{
		$c='';	
		if($project==$locdata['loccode'])
		{
		$c="selected";	
		}    
		?>	
		<option value="<?php echo $locdata['loccode']; ?>"<?php echo $c; ?>><?php echo $locdata['locationname']; ?></option>	
		<?php } ?>
	</select></td>
    <td class="tabledata">Block</strong></td>
    <td id="BId"><select name="block" id="block" >
		<option value="">Block</option>
	</select></td>
  </tr>
  <tr>
    <td class="tabledata">Contractor</strong></td>
    <td id="contra"><select name="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="tabledata">Work Order No.</strong></td>
    <td id="workorderno"><select name="work_order" id="work_order">
		<option value="">Select Contractor </option>
		<?php
		$sqlcategory1=DB_query("select * from sub_preparation",$db);
		while($category_row1=DB_fetch_array($sqlcategory1))
		{
				$s='';
				if($work_order==$category_row1['id'])
				$s="selected";
		?>
		 <option value="<?php echo $category_row1['id'];?>" <?php echo $s;?>><?php echo $category_row1['work_order_no'];?></option>
		<?php } ?>
		</select></td>
  </tr>
  <tr>
    <td class="tabledata">Bill No</strong></td>
    <td id="RABILLNO"><input type="text" name="bill_no" value="<?php echo $bill_no; ?>" id="bill_no" style="width: 150px;"  /></td>
    <td class="tabledata">Mbook No </td>
    <td id="MBOOKNO"><input type="text" name="mbook_no" value="<?php echo $bill_ref_no; ?>" id="mbook_no" style="width: 150px;"/></td>
  </tr>
 	<tr><td class="tabledata">Bill Date</td>
 	<td><input type="text" name="bill_date" value="<?php echo date('d/m/Y'); ?>" id="bill_date" style="width: 150px;" class="datepicker"/></td>	
 	
 		<td class="tabledata">Bill Ref No</strong></td>
    <td><input type="text" name="bill_ref_no" value="<?php echo $bill_ref_no; ?>" id="bill_ref_no" style="width: 150px;"/></td>
 	</tr>
 	</tr>
 	<tr><td class="tabledata">Retention Percentage</td>
 	<td><input type="text" name="retention_perc" value="<?php echo $retention_perc; ?>" id="retention_perc" style="width: 150px;"/></td>	
 	<td class="tabledata">Retention Release Date</td>
 	<td><input type="text" name="retention_release_date" value="<?php echo date('d/m/Y'); ?>" id="retention_release_date"  class="datepicker" style="width: 150px;"/></td>	
 	</tr>
 	</tr>
 	<tr><td class="tabledata">Work Order Start Date</td>
 	<td id="WO_START_DATE"><input type="text" name="wo_start_date" value="<?php echo date('d/m/Y'); ?>" id="from_date" style="width: 150px;" class="datepicker"/></td>	
 	<td class="tabledata">Work Order Completion Date</td>
 	<td id="WO_COMP_DATE"><input type="text" name="wo_comp_date" value="<?php echo date('d/m/Y'); ?>" id="to_date"  class="datepicker" style="width: 150px;"/></td>	
 	</tr>
  <tr>
  <td class="tabledata">Remarks</td>
    <td colspan="3"><textarea name="remarks"  style="width: 537px;"><?php echo $remarks; ?></textarea></td>
  </tr>
</table>
<table width="100%" border="1"  cellpadding="3">
	 <tr><td colspan="4">&nbsp;</td></tr>
  <tr><td colspan="4" class="tabledata"><strong>Adhoc Advance</strong></td>
  </tr>
  <tr><td colspan="4">&nbsp;</td></tr>
  <tr>
    <td class="tabledata">Total Advance</strong></td>
    <td id="TOTAL_ADV_AMT"><input type="text" name="adhoc_total_adv" value="<?php echo $adhoc_total_adv; ?>" id="adhoc_total_adv" style="width: 150px;" /></td>
    <td class="tabledata">Balance Advance</strong></td>
    <td id="BAL_ADV_AMT"><input type="text" name="adhoc_bal_adv" value="<?php echo $adhoc_bal_adv; ?>" id="adhoc_bal_adv" style="width: 150px;"/></td>
  </tr>
 	<tr><td class="tabledata">Total Adv. Recovered</td>
 	<td id="Total_adv_rec"><input type="text" name="adhoc_total_adv_recoverd" value="<?php echo $adhoc_total_adv_recoverd; ?>" id="adhoc_total_adv_recoverd" style="width: 150px;"/></td>	
 	<td class="tabledata">Recover Adv.For this Bill</td>
 	<td id="Adv_for_this_bill"><input type="text" name="adhoc_adv_for_this_bill" value="<?php echo $adhoc_adv_for_this_bill; ?>" id="adhoc_adv_for_this_bill" style="width: 150px;"/></td>	
 	 <tr><td colspan="4">&nbsp;</td></tr>
  <!--<tr><td colspan="4" class="tabledata"><strong>Mobillisation Advance</strong></td>
  </tr>
   <tr><td colspan="4">&nbsp;</td></tr>
 	 <tr>
   <td class="tabledata">Total Advance</strong></td>
    <td><input type="text" name="mobillisation_total_adv" value="<?php echo $mobillisation_total_adv; ?>" id="mobillisation_total_adv" style="width: 150px;" /></td>
    <td class="tabledata">Balance Advance</strong></td>
    <td><input type="text" name="mobillisation_bal_adv" value="<?php echo $mobillisation_bal_adv; ?>" id="mobillisation_bal_adv" style="width: 150px;"/></td>
  </tr>
 	<tr><td class="tabledata">Total Adv. Recovered</td>
 	<td><input type="text" name="mobillisation_total_adv_recoverd" value="<?php echo $mobillisation_total_adv_recoverd; ?>" id="mobillisation_total_adv_recoverd" style="width: 150px;"/></td>	
 	<td class="tabledata">Recover Adv.For this Bill</td>
 	<td><input type="text" name="mobillisation_adv_for_this_bill" value="<?php echo $mobillisation_adv_for_this_bill; ?>" id="mobillisation_adv_for_this_bill" style="width: 150px;"/></td>
 	</tr>
 	 <tr><td colspan="4">&nbsp;</td></tr>
  <tr><td colspan="4" class="tabledata"><strong>Discount Details</strong></strong></td>
  </tr>
   <tr><td colspan="4">&nbsp;</td></tr>
 	 <tr>
    <td class="tabledata">Total Discount</strong></td>
    <td><input type="text" name="discount_total_dis" value="<?php echo $discount_total_dis; ?>" id="discount_total_dis" style="width: 150px;" /></td>
   <td class="tabledata">Balance Discount</strong></td>
    <td><input type="text" name="discount_bal_dis" value="<?php echo $discount_bal_dis; ?>" id="discount_bal_dis" style="width: 150px;"/></td>
  </tr>
 	<tr><td class="tabledata">Total Dis. Recovered</td>
 	<td><input type="text" name="discount_total_dis_recovered" value="<?php echo $discount_total_dis_recovered; ?>" id="discount_total_dis_recovered" style="width: 150px;"/></td>	
 	<td class="tabledata">Current Discount</td>
 	<td><input type="text" name="discount_current_discount" value="<?php echo $discount_current_discount; ?>" id="discount_current_discount" style="width: 150px;"/></td>
 	</tr>
 	<tr><td>&nbsp;</td><td><input type="checkbox" name="final_bill" />Final Bill</td><td>&nbsp;</td>
 		<td>&nbsp;</td></tr>-->
 	<tr><td colspan="4" class="tabledata"><strong>Bill</strong></td></tr>
 	 <tr><td colspan="4">&nbsp;</td></tr>
 	 <tr>
    <td class="tabledata">Bill Amount</strong></td>
    <td id="BILL_AMT"><input type="text" name="bill_amt" value="<?php echo $bill_amt; ?>" id="bill_amt" style="width: 150px;" /></td>
    <td class="tabledata">Material Value</strong></td>
    <td><input type="text" name="material_value" value="<?php echo $material_value; ?>" id="material_value" style="width: 150px;"/></td>
  </tr>
 	<tr><td class="tabledata">Tax Addition</td>
 	<td>
	<input type="text" name="tax_rate" id="tax_rate" size="5" />
	<input type="text" name="tax_addition" value="<?php echo $tax_addition; ?>" id="tax_addition" style="width: 100px;" onfocus="tax_add()"/></td>	
 	<td class="tabledata">Tax Deduction</td>
 	<td>
	<input type="text" name="tax_deduction" id="tax_deduction" size="5" />
	<input type="text" name="tax_deduction" value="<?php echo $tax_deduction; ?>" id="tax_deduction" style="width: 100px;"/></td>
 	</tr>	
 	<tr><td class="tabledata">Total Addition</td>
 	<td><input type="text" name="total_addition" value="<?php echo $total_addition; ?>" id="total_addition" style="width: 150px;" onfocus="tatal_add()"/></td>	
 	<td class="tabledata">Total  Deduction</td>
 	<td><input type="text" name="total_deduction" value="<?php echo $total_deduction; ?>" id="total_deduction" style="width: 150px;"/></td>
 	</tr>	
 	<tr><td class="tabledata">Retention Amount</td>
 	<td><input type="text" name="retention_amt" value="<?php echo $retention_amt; ?>" id="retention_amt" style="width: 150px;"/></td>	
 	<td class="tabledata">Rounded Amount</td>
 	<td><input type="text" name="rounded_amt" value="<?php echo $rounded_amt; ?>" id="rounded_amt" style="width: 150px;"/></td>
 	</tr>
 	<tr><td class="tabledata">Hold Amount</td>
 	<td><input type="text" name="hold_amt" value="<?php echo $hold_amt; ?>" id="hold_amt" style="width: 150px;"/></td>	
 	<td class="tabledata">Net Amount</td>
 	<td><input type="text" name="net_amt" value="<?php echo $net_amt; ?>" id="net_amt" onfocus="netAmmout()" style="width: 150px;"/></td>
 	</tr>
  <tr><td class="tabledata">Certified Amount</td>
 	<td><input type="text" name="certified_amt" value="<?php echo $certified_amt; ?>" id="certified_amt" style="width: 150px;"/></td>	
 	</tr>
</table>
<p align="center"><input type="submit" name="<?php if($_REQUEST['action']=='edit') echo "Update"; else echo "Continue"; ?>" value="<?php if($_REQUEST['action']=='edit') echo "Update"; else echo "Continue"; ?>" /><input type="submit" name="Close" value="Close" /></p>
</form>
</div>