<?php
//**********************************INSERT FRESH DATA****************START HERE*************************************

if(isset($_POST['Save']))
{
	$data['project']=$_REQUEST['project'];
	$data['block']=$_REQUEST['block'];
	$data['contractor']=$_REQUEST['contractor'];
	$data['mbook_no']=$_REQUEST['mbook_no'];
	$data['work_order_no']=$_REQUEST['work_order_no'];
	$data['rabill_no']=$_REQUEST['rabill_no'];
	$data['mbook_date']=FormatDateForSQL($_REQUEST['mbook_date']);
	$data['mbook_sub_date']=FormatDateForSQL($_REQUEST['mbook_sub_date']);
	$data['total_amt']=$_REQUEST['total_mbook_amt'];
	$data['ra_bill_status']='Pending';
	$s->RecordInsert('sub_mbook_submission',$data);
	$lastId=DB_Last_Insert_ID($db,'sub_mbook_submission','id');
	for($i=0;$i<$_REQUEST['counter'];$i++)
	{
	$data1['parantid']=$lastId;
	$data1['group_id']=$_REQUEST['group_id'][$i];
	$data1['activity_id']=$_REQUEST['activity_id'][$i];
	$data1['unit']=$_REQUEST['unit'][$i];
	$data1['wo_qty']=$_REQUEST['work_order_qty'][$i];
	$data1['wo_rate']=$_REQUEST['work_order_rate'][$i];
	$data1['curr_qty']=$_REQUEST['current_qty'][$i];
	$data1['amt']=$_REQUEST['ammount'][$i];
	$data1['balance_qty']=$_REQUEST['balance_qty'][$i];
	$data1['net_amt']=$_REQUEST['net_amount'][$i];
	$s->RecordInsert('sub_mbook_submission_chield',$data1);
	}
	$datarray['status']='Approved';
	$cond="id='".$_REQUEST['mbook_no']."'";
	$s->RecordEdit('subcontractor_mbook_preparation', $datarray, $cond);
	$_SESSION['success_msg']="Saved Successfully";
	$s->pageLocation("index.php?route=SubContractors/materialBook/mbook_submission_index".$rurl);
}


//**********************************INSERT FRESH DATA****************END HERE*************************************



if($_REQUEST['action']=='edit' and $_REQUEST['pre']!='')
{
	//$sql=DB_query("select * from sub_mbook_submission where id='".$_REQUEST['pre']."'",$db);
	//$query=DB_fetch_array($sql);	
	extract($query);	
}
if(isset($_POST['Update']))
{
	extract($_REQUEST['sub_mbook_submission']);
	//$s->RecordEdit('sub_mbook_submission',$_REQUEST['sub_mbook_submission'],"id=".$_REQUEST['pre']);
	$_SESSION['success_msg']="Update Successfully";
	echo "<script>location.href='index.php?route=SubContractors/materialBook/mbook_submission_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}



?>



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




<script type="text/javascript" language="javascript">
function getblock_conractor(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","contractor_block_mbooksbmission.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)
	{
	document.getElementById("MBOOKNO").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_Mbook_submission_no.php?str="+str,true);
	xmlhttp.send();
}



function showdata(str)
{  
	//alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no").innerHTML="";
	return;
	}
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("WORK_ORDER_NO").innerHTML=data[0];
	document.getElementById("RA_BILL_NO").innerHTML=data[1];
	document.getElementById("MBOOK_DATE").innerHTML=data[2];
	document.getElementById("MBOOK_DATA").innerHTML=data[3];	
	}
	}
	xmlhttp.open("GET","get_Mbook_Submision_data.php?mbookno="+str,true);
	xmlhttp.send();
}
</script>


</script>


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


<style>
.label{
background-color: #B7B7B7;
    color: #000000;
    font-size: 10.5px;
    font-weight: bold !important;
    padding: 5px 10px;
    text-align: left;
}
</style>
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<div class="tender_main_page">
<form action="" method="post">
<h3>MBook Submission</h3>
<table  width="100%" border="1" cellpadding="3">
	<tr>
		<td class="tabledata">Project</td>
		<td><select name="project"  id="project" style="width: 150px" onchange="getblock_conractor(this.value)">
		<option value="0">Select</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.</td>
		<td id="BId"><select name="block" id="block" style="width: 150px">
		<option value="0">Select</option>	
		<?php
		$proj=DB_query("select * from locations",$db);
		while($locdata=DB_fetch_array($proj))
		{
		$d='';	
		if($block==$locdata['loccode'])
		{
		$d="selected";	
		}    	    
		?>	
		<option value="<?php echo $locdata['loccode']; ?>"<?php echo $d; ?>><?php echo $locdata['locationname']; ?></option>	
		<?php } ?>	
		</select></td>
	</tr>
	<tr>
		<td class="tabledata">Contractor</td>
		<td id="contra"><select name="contractor" id="contractor" style="width: 150px">
		<option value="0">Select</option>	
		<?php
		$cont=DB_query("select * from sub_contractor_definition",$db);
		while($contdata=DB_fetch_array($cont))
		{
		$e='';
		if($contdata['id']==$contractor)
		{
		$e="selected";	
		}	    
		?>	
		<option value="<?php echo $contdata['id']; ?>"<?php echo $e; ?>><?php echo $contdata['contractor_name']; ?></option>	
		<?php } ?>	
		</select></td>
		<td class="tabledata">Mbook No. </td>
		<td id="MBOOKNO"><select name="mbook_no" id="mbook_no" style="width: 150px">
		<option value="0">Select</option>	
		</select></td>
	</tr>
	<tr>
		<td class="tabledata">Work Order No</td>
		<td id="WORK_ORDER_NO"><input type="text"  name="work_order_no" id="work_order_no" style="width: 150px"  /></td>
		<td class="tabledata">RA Bill No.</td>
		<td id="RA_BILL_NO"><input type="text"  name="rabill_no" id="rabill_no" style="width: 150px"  /></td>
	</tr>
	<tr>
		<td class="tabledata">MBook Date</td>
		<td id="MBOOK_DATE"><input type="text"  name="mbook_date" id="mbook_date" style="width: 150px"  /></td>
		<td class="tabledata">MBook Submmision Date.</td>
		<td><input type="text"  name="mbook_sub_date" id="mbook_sub_date" class="datepicker" style="width: 150px"  /></td>
	</tr>
    </table>
	<br /><br />
	<div style="width:810px; margin-left:auto; margin-right:auto; overflow:auto;">
<table width="100%" border="1" cellpadding="3" id="MBOOK_DATA">
	<tr>
		<td class="tabledata">Select</td>
		<td class="tabledata">PBSName</td>
		<td class="tabledata">Activity</td>
		<td class="tabledata">Unit</td>
		<td class="tabledata">WO Qty</td>
		<td class="tabledata">WO Rate</td>
		<td class="tabledata">Quantity</td>
		<td class="tabledata">Amount</td>
		<td class="tabledata">Balance Qty</td>
		<td class="tabledata">Total Qty</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	  </table> 
	  </div>
<p align="center">   
	<input type="submit" name="<?php if($_REQUEST['action']=='edit') echo "Update"; else echo "Save"; ?>" value="<?php if($_REQUEST['action']=='edit') echo "Update"; else echo "Submit"; ?>"><input type="submit" name="Close" value="Close">
</p>
</form>
</div>