<?php
if($_REQUEST['DeleteId'] && $_REQUEST['flag']!='')
{
if($_REQUEST['flag']=='APO'){
/****************************DELETE FROM PURCHASEORDER Ammendment TABLE ******************/
	$slq_del=DB_query("delete from purchorderdetails_ammd where orderno='".$_REQUEST['DeleteId']."'",$db);
	$sql_del1=DB_query("delete from purchorders_ammd where orderno='".$_REQUEST['DeleteId']."'",$db);
}
elseif($_REQUEST['flag']=='PO'){
/****************************DELETE FROM PURCHASEORDER  TABLE ******************/
	$slq_del=DB_query("delete from purchorderdetails where orderno='".$_REQUEST['DeleteId']."'",$db);
	$sql_del1=DB_query("delete from purchorders where orderno='".$_REQUEST['DeleteId']."'",$db);
}
}


if($_REQUEST['CencelId'] && $_REQUEST['flag']!='')
{
if($_REQUEST['flag']=='PO'){
/****************************UPDATE STATUS IN PURCHASEORDER  TABLE ******************/
	$cencl=DB_query("update purchorders set po_ammendment_status='0', Po_recive_status='Cancel' where orderno='".$_REQUEST['CencelId']."'",$db); }
elseif($_REQUEST['flag']=='APO'){
	/****************************UPDATE STATUS IN PURCHASEORDER_AMMD  TABLE ******************/
	$cencl=DB_query("update purchorders_ammd set  Po_recive_status='Cancel' where orderno='".$_REQUEST['CencelId']."'",$db); }
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Order Ammendment</h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1"><strong>Site Name </strong></td>
    <td colspan="4"><select name="sitecode"  style="width:150px;">
		<option value="">----Select----</option>
		<?php
		
		//$sqlsite=DB_query("select * from locations where company='".$_SESSION['ACGCompanyId']."' and  and loccode in (".$_SESSION['AssignedSites'].")",$db);
		if($_SESSION['AssignedBranch']!='')
	  {	  	
		$sqlsite=DB_query("select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'  and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
		}
else
 {
	$sqlsite=DB_query("select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
}
		
		
		while($site_row=DB_fetch_array($sqlsite))
		{
				$p='';
				if($_REQUEST['sitecode']==$site_row['loccode'])
				$p="selected";
		?>
		 <option value="<?php echo $site_row['loccode'];?>" <?php echo $p;?>><?php echo $site_row['locationname'];?></option>
		<?php } ?>
	</select>
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1"><strong>Vendor</strong></td>
    <td><select name="suppliers" style="width:150px;">
		<option value="">----Select----</option>
		<?php
		$sqlsuppliers=DB_query("Select * from suppliers",$db);
		while($suppliers_row=DB_fetch_array($sqlsuppliers))
		{
				$p='';
				if($_REQUEST['suppliers']==$suppliers_row['id'])
				$p="selected";
		?>
		 <option value="<?php echo $suppliers_row['id'];?>" <?php echo $p;?>><?php echo  str_replace(array("M/s ","M/S"),'',$suppliers_row['vendor_name']);?></option>
		<?php } ?>
	</select></td>
	<td class="tabledata1"><strong>Order No.</strong></td>
	<td><input type="text" name="po_order" style="width:150px;" value="<?php echo $_REQUEST['po_order'];?>" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>From</strong></td>
	<td><input type="text" name="fromDate" style="width:150px;"  value="<?php  echo $_REQUEST['fromDate'];?>" class="datepicker"/></td>
	<td class="tabledata1"><strong>To</strong></th>
	<td> <input type="text" name="toDate" style="width:150px;" value="<?php  echo $_REQUEST['toDate'];?>" class="datepicker"/></td>
</tr>
<tr class="row1">
	<td style="text-align:center;" colspan="4">
	<input type="submit" name="search" class="search" value="Search" />
	<input type="reset" value="Reset" class="search" name="reset" />
	</td>
</tr>
</table>
</form>

<br />
<!-- For this div of pagination -->
<div class="new_tab">

<div class="inside_tab">

	<ul>
		<li><a href="index.php?route=POModule/POorder_Ammendment_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&tab=2&type=POModule/PO">Purchase Orders</a></li>
		<li><a href="index.php?route=POModule/POorder_Ammendment_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&tab=2&type=POModule/APO">Ammended Purchase Orders</a></li>
<div style="clear:both;"></div>

	</ul>
</div>
</div>
<div style="height:3px;"></div>

<div style="width:100%; ">

	<?php for($i=1; $i<3; $i++)
	{
		if($i==$_REQUEST['tab']){
	?>

			<?php
			if($_REQUEST['route']!=''&& $_REQUEST['type']!='')
			{
				include($_REQUEST['type'].".php");
			} ?>

	<?php }} 
	
	if($_REQUEST['tab']=='')
	{
	include("PO.php");
	}
	?>
</div>





<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
