<?php
//*************************DELETE THE DATA***********************START HERE******************************************/


if($_REQUEST['action']=='delete' && !empty($_REQUEST['opn']))
{
	if($s->DeleteRecord('sub_ra_bill_preparation',"id=".$_REQUEST['opn']))
	{
	$_SESSION['success_msg']="Delete Successfully";	
	$s->pageLocation("index.php?route=SubContractors/RaBill/ra_bill_preparation_index".$rurl);
	}
}

//*************************DELETE THE DATA***********************END HERE******************************************/



//*************************SEARCHING***************************START HERE******************************************/

if($_REQUEST['search']!='')
{	
	$filter = array();
	if(isset($_REQUEST['contractor']) && $_REQUEST['contractor'] != '')
	$filter[]="contractor='".$_REQUEST['contractor']."'";
	if(isset($_REQUEST['project']) && $_REQUEST['project'] != '')
	$filter[]="project='".$_POST['project']."'";
	$filter1 = implode("and ",$filter); 
	if($filter1!='')
	{
	$sql="select * from sub_ra_bill_preparation where $filter1";
	}
	else
	{
	$sql = "SELECT * FROM sub_ra_bill_preparation";
	}
}
else
{
	$sql = "SELECT * FROM sub_ra_bill_preparation";
}


//*************************SEARCHING***************************END HERE******************************************/

?>
<link rel="stylesheet" type="text/css" href="SubContractors/css/paginate.css" />
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<div class="tender_main_page">
<h3>RA Bill Preparation</h3>
<a href="index.php?route=SubContractors/RaBill/ra_bill_preparation&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a>
<form action="" method="post">
<table width="75%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td class="tabledata">Contractor </strong></td>
    <td><select name="contractor">
		<option value="">Select CategoryName</option>
		<?php
		$sqlcategory=DB_query("select * from sub_contractor_definition",$db);
		while($category_row=DB_fetch_array($sqlcategory))
		{
				$s='';
				if($_REQUEST['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">Project</strong></td>
    <td><input type="text" name="project"/></td>
    <td><input type="submit" name="search" value="Search" /><input type="reset" value="Reset" name="reset" /></td>
  </tr>
</table>
</form>
<p>&nbsp;</p>
<div><br></div>

<div id="tableContainer" class="tableContainer">
<table class="scrollTable" width="100%" border="0" cellpadding="0" cellspacing="0">

	<tr>
		<td class="tabledata">Project</strong></td>
		<td class="tabledata">Block</strong></td>
		<td class="tabledata">Contractor</strong></a></td>
		<td class="tabledata">Work Order</strong></td>
		<td class="tabledata">Bill No.</strong></td>
		<td class="tabledata">Bill Ref No</strong></td>
		<td class="tabledata">Delete</td>
	</tr>
	
	<?php 
			$rpp = 10; // results per page
			$adjacents = 5;
			$page = intval($_GET["page"]);
			if($page<=0) $page = 1;
			$reload ="index.php?route=SubContractors/RaBill/ra_bill_preparation_index".$rurl;
			// select appropriate results from DB:
			//$sql = "SELECT * FROM sub_rabill_opening";
			$result =DB_query($sql,$db);
			// count total number of appropriate listings:
			$tcount = DB_num_rows($result);
			// count number of pages:
			$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
			$count = 0;
			$i = ($page-1)*$rpp;
			while(($count<$rpp) && ($i<$tcount)) {
				DB_data_seek($result,$i);
				$query = DB_fetch_array($result);
				extract($query);
				$loc=DB_query("select locationname from locations where loccode='".$project."'",$db);
				$locationname=DB_fetch_array($loc);
	?>
	<tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';" >
		<td><a href="index.php?route=SubContractors/RaBill/ra_bill_preparation<?php echo $rurl;?>&amp;action=edit&opn=<?php echo $id; ?>" style="color:#000000"><?php echo $locationname['locationname']; ?></a></td>
		<td><?php $s=new db_query();
		 echo  $s->GetFieldValue('sub_block_master',"id='".$block."'",'block_name');  ?></td>
		<td > 
		<?php 
		 echo  $s->GetFieldValue('sub_contractor_definition',"id='".$contractor."'",'contractor_name'); ?></td>
		<td><?php echo $s->GetFieldValue('sub_preparation',"id='".$work_order_no."'",'work_order_no'); ?></td>
		<td ><?php echo $bill_no; ?></td>
		<td><?php echo $bill_ref_no; ?></td>	
		<td ><a href="index.php?route=SubContractors/RaBill/ra_bill_preparation_index<?php echo $rurl;?>&amp;action=delete&opn=<?php echo $id; ?>" onclick="return confirm('Are you sure you want to delete?')"> <img src="images/Icon_Delete.png" /></a></td>
	</tr>	
	<?php  $i++;  $count++; }
	// call pagination function:
echo paginate_two($reload, $page, $tpages, $adjacents);
 ?>
</table>
 <font color="#FF0000"><?php echo $masg; ?></font>
</div>
<div><br></div>
</div>
<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
unset($_SESSION['success_msg']);
}

?>



