<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 5;
include('includes/SQL_CommonFunctions.inc');
$title = _('Quotation Register');
$PageName ='Quotation Register';	
if($_REQUEST['Cancel']!='')
{
	unset($_REQUEST);
}
?>

<div class="body_contain">
<div class="tab_div">


<h1>Quotation Register</h>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="row1">
    <td class="tabledata1">Branch</td>
  
    <td><select name="site">
        <option value="0">Select</option>
        <?php 
	  $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  while($site_row=DB_fetch_array($site_sql)) {
	  ?>
        <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
        <?php } ?>
      </select>
    </td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Vendor</td>
    
    <td>
      <select name="vendor">
	  <option value="0">Select</option>
	  <?php 
	  $v_sql=DB_query("Select vendor_code,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	  
	  while($v_row=DB_fetch_array($v_sql)) {
	  ?>
	  <option value="<?php echo $v_row['vendor_code'];?>"<?php echo ($_REQUEST['vendor']==$v_row['vendor_code']?'selected':'')?>><?php echo $v_row['vendor_name'];?></option>
	  <?php } ?>
      </select>    </td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">From</td>
    <td>
	<?php 
	if($_REQUEST['fromDate']!=''){$fromDate=$_REQUEST['fromDate'];}
	if($_REQUEST['toDate']!=''){$toDate=$_REQUEST['toDate'];}
	?>
      <input name="fromDate" type="text" size="12" class="datepicker" value="<?php echo $fromDate;?>"/>
      To 
      <input name="toDate" type="text" size="12" class="datepicker" value="<?php echo $toDate;?>"/></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Item Code </td>
    <td>
    	
	<select name="itemCode">
	<option value="0">Select</option>
	<?php 
	$item_sql=DB_query("Select StockID from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($item_row=DB_fetch_array($item_sql)){
	?>
	<option value="<?php echo $item_row['StockID'];?>"<?php echo ($_REQUEST['itemCode']==$item_row['StockID']?'selected':'')?>><?php echo $item_row['StockID'];?></option>
	<?php } ?>
    </select>	</td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Item Name </td>
    <td>
	<select name="itemName">
	<option value="0">Select</option>
	<?php 
	$name_sql=DB_query("Select distinct item_name from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($name_row=DB_fetch_array($name_sql)) {
	?>
	<option value="<?php echo $name_row['item_name'];?>"<?php echo ($_REQUEST['itemName']==$name_row['item_name']?'selected':'')?>><?php echo $name_row['item_name'];?></option>
	<?php } ?>
    </select>	</td>
  </tr>
</table>
<p align="left" style="padding-left:10px;"><input type="submit" name="View" value="View" /><input type="submit" name="Cancel" value="Cancel" /></p>
</form>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <td class="tabledata">S. No. </td>
    <td class="tabledata">Vendor Quotation No.</td>
	<td class="tabledata">Vendor</td>
	<td class="tabledata">Requisition No. </td>
    <td class="tabledata">Branch</td>
    <td class="tabledata">Date</td>
	<td class="tabledata">Total Quotation Quantity</td>
    </tr>
	<?php 
	if($_REQUEST['View']!='')
	{
		$filter=array();
		
		$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;
		
		if($_REQUEST['site']!='0')
		$filter[]="A.sitecode='".$_REQUEST['site']."'";
		if($_REQUEST['vendor']!='0')
		$filter[]="A.vendercode='".$_REQUEST['vendor']."'";
		if($_REQUEST['itemCode']!='0')
		$filter[]="B.prod_id='".$_REQUEST['itemCode']."'";
		if($_REQUEST['itemName']!='0')
		$filter[]="B.prod_dec='".$_REQUEST['itemName']."'";
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="A.date1 between '".$From."' and '".$To."'";
		
		if($filter!='')
		{
			if($_REQUEST['site']!='0'){$filter2=implode(" and ",$filter)." group by B.quotation_no";}
			else
			$filter2=implode(" and ",$filter);
		}
		
		if($_REQUEST['site']!='0')
		{
			$sql="Select A.*, B.*, sum(quantity) from venderquotations A, vendorquotationdetails B where B.quotation_no=A.id and $filter2";
		}
		else{
		$sql="Select A.*, B.* from venderquotations A, vendorquotationdetails B where B.quotation_no=A.id and $filter2"; }
		//echo $sql;
		
		
		$result=DB_query($sql,$db);
		$i=1;
		if(DB_num_rows($result)>0)
		{
			while($myrow=DB_fetch_array($result))
			{
		?>
<tr bgcolor="#c1c1c1">
    <td><?php echo $i;?></td>
	 <td><?php echo $myrow['vernder_quotation']; //echo "===".$myrow['id'];?></td>
	  <td><?php echo $myrow['vendername'];?></td>
    <td><?php 
	$ReqCode=$s->getField('materialrequisitions','requisitionno',$myrow['pr_no'],'Reqno');
	echo $ReqCode;?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['sitecode'],'locationname');
	echo $sitename;?></td>
    <td><?php echo ConvertSQLDate($myrow['date1']);?></td>
	<td><?php if($_REQUEST['site']!='0'){echo $myrow['sum(quantity)'];}
	if($_REQUEST['itemCode']!='0' || $_REQUEST['itemName']!='0'){echo $myrow['quantity'];}
	?></td>
  </tr>
  <?php $i++;}
  		}
		else
		{?>
		<tr><td colspan="4"><font color="#FF0000">No Record Found</font></td></tr>
		<?php 	
		}
  }
	?>
</table>
</div></div>
