<?php ob_start();
$PageSecurity = 5;
include('includes/SQL_CommonFunctions.inc');
$title = _('Quotation Register');
$PageName ='Quotation Register';	
if($_REQUEST['Cancel']!='')
{
	unset($_REQUEST);
}
?>
<h2 align="center"><strong>Quotation Register</strong></h2>
<form action="" method="post">
<table width="40%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <th><strong>Branch</strong></th>
    <td><select name="site">
        <option value="">Select</option>
        <?php 
        if($_SESSION['AssignedSites']!='0')
	  {
	  	 $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in (".$_SESSION['AssignedSites'].")",$db);
	   	 
	  	 
	  }
		else {
			
		
        
	  $site_sql=DB_query("Select loccode,locationname from locations",$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>
    <th><strong>Vendor</strong></th>
    <td>
      <select name="vendor">
	  <option value="">Select</option>
	  <?php 
	  $v_sql=DB_query("Select * from suppliers",$db);
	  while($v_row=DB_fetch_array($v_sql)) {
	  ?>
	  <option value="<?php echo $v_row['id'];?>"<?php echo ($_REQUEST['vendor']==$v_row['id']?'selected':'')?>><?php echo $v_row['vendor_name'];?></option>
	  <?php } ?>
      </select>    </td>
  </tr>
  <tr>
    <th><strong>From</strong></th>
    <td><strong>
	<?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</strong> 
      <input name="toDate" type="text" size="12" class="datepicker" value="<?php echo $toDate;?>"/></td>
  </tr>
  <tr>
    <th><strong>Item Code </strong></th>
    <td>
	<select name="itemCode">
	<option value="">Select</option>
	<?php 
	$item_sql=DB_query("Select id,item_name from item_master",$db);
	while($item_row=DB_fetch_array($item_sql)){
	?>
	<option value="<?php echo $item_row['id'];?>"<?php echo ($_REQUEST['itemCode']==$item_row['id']?'selected':'')?>><?php echo $item_row['StockID'];?></option>
	<?php } ?>
    </select>	</td>
  </tr>
 
</table>
<p align="center"><input type="submit" name="View" value="View" /><input type="submit" name="Cancel" value="Cancel" /></p>
</form>
<br />
<p align="right"><a href="Print_QuotationRegister.php?site=<?php echo $_REQUEST['site'];?>&itemCode=<? echo $_REQUEST['itemCode'];?>&itemName=<?php echo $_REQUEST['itemName'];?>&todate=<?php echo $_REQUEST['toDate'];?>&fromdate=<?php echo $_REQUEST['fromDate'];?>&vendor_code=<?php echo $_REQUEST['vendor'];?>&view=<?php echo $_REQUEST['view'];?>">Print</a>&nbsp;&nbsp;&nbsp;<a href="tcpdf/Pdf_QuotationRegister.php?site=<?php echo $_REQUEST['site'];?>&itemCode=<? echo $_REQUEST['itemCode'];?>&itemName=<?php echo $_REQUEST['itemName'];?>&todate=<?php echo $_REQUEST['toDate'];?>&fromdate=<?php echo $_REQUEST['fromDate'];?>&vendor_code=<?php echo $_REQUEST['vendor'];?>">PDF</a>
<a href="Export_QuotationRegister.php?site=<?php echo $_REQUEST['site'];?>&itemCode=<? echo $_REQUEST['itemCode'];?>&itemName=<?php echo $_REQUEST['itemName'];?>&todate=<?php echo $_REQUEST['toDate'];?>&fromdate=<?php echo $_REQUEST['fromDate'];?>&vendor_code=<?php echo $_REQUEST['vendor'];?>">Export</a>
</p>	
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <th>S. No. </th>
	<th>Date. </th>
    <th>Quotation No.</th>
	<th>Vendor</th>
	<th>Requisition No. </th>
    <th>Branch</th>
   	<th>Item Name</th>
	<th>Total Quotation Quantity</th>
    </tr>
	<?php 
	if($_REQUEST['View']!='')
	{
		//print_r($_REQUEST);
		$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']!='')
		$filter[]="venderquotations.sitecode='".$_REQUEST['site']."'";
		
		if($_REQUEST['vendor']!='')
		$filter[]="venderquotations.mst_supplierno='".$_REQUEST['vendor']."'";
		
		if($_REQUEST['itemCode']!='')
		$filter[]="vendorquotationdetails.mst_productid ='".$_REQUEST['itemCode']."'";
		
		if($_REQUEST['itemName']!='')
		$filter[]="vendorquotationdetails.prod_dec='".$_REQUEST['itemName']."'";
		
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="venderquotations.date1 between '".$From."' and '".$To."'";
		
		if($filter != '')
		{
		$filter1 = implode(" and ",$filter);
		}	
	$sql="SELECT venderquotations.*, vendorquotationdetails.* from venderquotations INNER JOIN vendorquotationdetails on(venderquotations.id = vendorquotationdetails.quotation_no) where $filter1";
		//echo $sql;
		$_SESSION['quat_reg1']=$sql;
		
		$result=DB_query($sql,$db);
		$i=1;
		if(DB_num_rows($result)>0)
		{
			while($myrow=DB_fetch_array($result))
			{
		?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo $i;?></td>
	 <td><?php echo ConvertSQLDate($myrow['date1']);?></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 $sitename1=$s->getField('item_master','id',$myrow['mst_productid'],'item_name');
    echo $sitename1; ?></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"><strong>No Record Found</strong></font></td></tr>
		<?php 	
		}
  }
	?>
</table>
