<?php 
if($_REQUEST['search']!='')
{
	//print_r($_REQUEST);
	
		$fromDate=$_REQUEST['fromDate'];
		$fromDateBrk=explode("/",$fromDate);
		$fromDate=$fromDateBrk[0];
		$fromMonth=$fromDateBrk[1];
		$fromYear=$fromDateBrk[2];
		$From=$fromYear."-".$fromMonth."-".$fromDate;
		
		$toDate=$_REQUEST['toDate'];
		$toDateBrk=explode("/",$toDate);
		$toDate=$toDateBrk[0];
		$toMonth=$toDateBrk[1];
		$toYear=$toDateBrk[2];
		$To=$toYear."-".$toMonth."-".$toDate;
	$filter = '';
	
	if(isset($_REQUEST['sitecode']) && $_REQUEST['sitecode'] != '')			
	$filter[]="sitecode='".$_REQUEST['sitecode']."'";
	
	if(isset($_REQUEST['suppliers']) && $_REQUEST['suppliers'] != '')			
	$filter[]="vendor_id='".$_POST['suppliers']."'";
	
	if(isset($_REQUEST['po_order']) && $_REQUEST['po_order'] != '')			
	$filter[]="ammndmnt_no LIKE '%".$_POST['po_order']."%'";
	
	if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
	$filter[]="orddate between '".$From."' and '".$To."'";
	
	$filter1 = implode(" and ",$filter); 
	if($filter1!='')
			{
				  $sql1="SELECT * FROM purchorders_ammd where $filter1 order by orddate desc";
			}
			else
			{
			 if($_SESSION['AssignedBranch']!='')
              {
			
				$sql1 = "SELECT * FROM purchorders_ammd where sitecode in('".$_SESSION['AssignedBranch']."') order by orddate desc";
			 }
			 else
			 {
			 $sql1 = "SELECT * FROM purchorders_ammd  order by orddate desc";
			
			 }	
			}
	
}
else
{
   if($_SESSION['AssignedBranch']!='')
    {
	 $sql1 = "SELECT * FROM purchorders_ammd where sitecode in('".$_SESSION['AssignedBranch']."')  order by orddate desc";

    }
	else
	{
	 $sql1 = "SELECT * FROM purchorders_ammd   order by orddate desc";

	}
}

if($_REQUEST['reset']!='')
{
   if($_SESSION['AssignedBranch']!='')
    {
	 $sql1 = "SELECT * FROM purchorders_ammd where sitecode in('".$_SESSION['AssignedBranch']."') order by orddate desc";
    }
	else
	{
	$sql1 = "SELECT * FROM purchorders_ammd  order by orddate desc";
 
	}
}

//echo $sql1;
?>
	<div>
<?php 
/*$rpp = 10; // results per page
$adjacents = 8;
$page = intval($_GET["page"]);
if($page<=0) $page = 1;
$reload ="index.php?route=POModule/POorder_Ammendment_index".$rurl."&tab=2&type=POModule/APO";
// select appropriate results from DB:
$result1 =DB_query($sql1,$db);
// count total number of appropriate listings:
$tcount = DB_num_rows($result1);
// count number of pages:
$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
$count = 0;
$i = ($page-1)*$rpp;

echo $tcount; echo "<br />"; echo $tpages; echo "<br />"; echo $count; echo "<br />"; echo $i; exit;	

if($tcount>0){
echo paginate_two($reload, $page, $tpages, $adjacents);}

if($tcount=='0'){echo "No Record"; exit;} */

 ?></div>

<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="6%"><strong>Sl.No.</strong></td>
    <td width="8%"><strong>Ammendment Date</strong></td>
    <td width="17%"><strong>Ammendment No. </strong></td>
	<td width="5%"><strong>Revision No.</strong></td>
	<td width="15%"><strong>Against PO</strong></td>
    <td width="11%"><strong>Vendor Code </strong></td>
    <td width="14%"><strong>Vendor Name </strong></td>
    <td width="12%"><strong>Site Name/Code </strong></td>
	<td width="7%"><strong>View</strong></td>
	<td width="7%"><strong>Cancel</strong></td>
	<td width="7%"><strong>Delete</strong></td>
	<td width="7%"><strong>Print</strong></td>
  </tr>
  <?php 
			$result1 =DB_query($sql1,$db);
			//while(($count<$rpp) && ($i<$tcount)) 
			$x=0;
			while($query = DB_fetch_array($result1)) 
			{
				//DB_data_seek($result1,$i);
				//$query = DB_fetch_array($result1);
				extract($query);
				 $vendor_detail = "Select vendor_code,vendor_name  from suppliers where id='".$vendor_id."'";
				$result_vendor=DB_query($vendor_detail,$db);
				$myrow_vendor=DB_fetch_array($result_vendor);
				$site=$s->getField('locations','loccode',$sitecode,'locationname')
	?>
	
  <tr class="row1">
    <td><?php echo $x+1; ?></td>
    <td><?php echo ConvertSQLDate($orddate); ?></td>
    <td><?php echo $ammndmnt_no; ?></td>
	<td><?php echo $revision_no; ?></td>
	<td><?php echo $s->getField('purchorders','orderno',$against_po_id,'PO_Orderno'); ?></td>
    <td><?php echo $myrow_vendor['vendor_code']; ?></td>
    <td><?php echo $myrow_vendor['vendor_name'];?></td>
    <td><?php echo $site;?></td>
	<td> 
	<?php if($_SESSION['frmView']==1) {?>
	<a href="index.php?route=POModule/POrderdetailaview&AMDPOID=<?php echo $orderno?>&CPID=<?php echo $mst_comperitive.$rurl;;?>" ><center><img src="images/search.gif" width="15" height="15"></center></a> 
	<?php }else{ ?>
	<?php echo 'No Permission'; ?>
	<?php }?>
	</td>
   <!--
    <td><a href="index.php?route=POModule/POorder_Ammendment_add&POAMDId=<?php //echo $orderno.$rurl;?>&idfy_quotes=<?php //echo $identify; ?>" ><img src="images/icon-edit.png"width="15" height="15"></a></td>-->
	<td>
	<?php if($_SESSION['frmDelete']==1) {?>
	<a href="index.php?route=POModule/POorder_Ammendment_index&flag=APO&CencelId=<?php echo $orderno.$rurl;?>" onclick="return confirm('Are you sure you want to cancel this PO?')">Cancel</a>
	
	<?php }else{ ?>
	<?php echo 'No Permission'; ?>
	<?php }?>
	</td>
	<td>
	<?php if($_SESSION['frmDelete']==1) {?>
	<a href="index.php?route=POModule/POorder_Ammendment_index&flag=APO&DeleteId=<?php echo $orderno.$rurl;?>" onclick="return confirm('Are you sure you want to delete?')"> <img src="images/Icon_Delete.png" /></a>
	
	<?php }else{ ?>
	<?php echo 'No Permission'; ?>
	<?php }?>
	
	</td>
	<td>
	<?php if($_SESSION['frmView']==1) {?>
	<a href="purchase_ammd_print.php?id=<?php echo $orderno;?>&CPID=<?php echo $mst_comperitive; ?>" target=_blank>Print</a>
	
	<?php }else{ ?>
	<?php echo 'No Permission'; ?>
	<?php }?>
	</td>
  </tr>
	<?php  $x++; // $count++; 
	}
 ?>
</table>