<?php ob_start();
$PageSecurity = 5;
include('includes/SQL_CommonFunctions.inc');
$title = _('Quotation Ammendment Register');
$PageName ='Quotation Ammendment Register';	
if($_REQUEST['Cancel']!='')
{
	unset($_REQUEST);
}
?>
<h2 align="center"><strong>Quotation Ammendment Register</strong></h2>
<form action="" method="post">
<table width="100%" align="center">
  <tr>
    <td>Branch</td>
    <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']."'",$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>
    <td>Vendor</td>
    <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 str_replace(array("M/s ","M/S"),'',$v_row['vendor_name']);?></option>
	  <?php } ?>
      </select>    </td>
    <td>From</td>
    <td>
	<?php 
	if($_REQUEST['fromDate']!=''){$fromDate=$_REQUEST['fromDate'];}
	if($_REQUEST['toDate']!=''){$toDate=$_REQUEST['toDate'];}
?>
      <input name="fromDate" type="text"  class="datepicker"
	    value="<?php echo $fromDate;?>"/> </td>
   <td>To</td>
    <td><input name="toDate" type="text"  class="datepicker" value="<?php echo $toDate;?>"/></td>
    <td>Code </td>
    <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['item_name'];?></option>
	<?php } ?>
    </select>	</td>
    <td><input type="submit" name="View" value="View" /></td>
  </tr>
 
</table>

</form>
<br />
<?php
if($_REQUEST['View']!='')
	{
?>
<p align="right"><a href="Print_QuotationAmmendmentRegister.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'];?>" target="_blank">Print</a>&nbsp;&nbsp;&nbsp;<?php /*?><a href="tcpdf/Pdf_QuotationAmmendmentRegister.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_QuotationAmmendmentRegister.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><?php */?>
</p>	

	<?php 
	
		$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[]="vendor_quotes_ammendment.sitecode='".$_REQUEST['site']."'";
		
		if($_REQUEST['vendor']!='')
		$filter[]="vendor_quotes_ammendment.mst_supplierno='".$_REQUEST['vendor']."'";
		
		if($_REQUEST['itemCode']!='')
		$filter[]="vendor_quotes_ammendment_details.item_id ='".$_REQUEST['itemCode']."'";
		
		if($_REQUEST['itemName']!='')
		$filter[]="vendor_quotes_ammendment_details.item_name='".$_REQUEST['itemName']."'";
		
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="vendor_quotes_ammendment.quotation_date between '".$From."' and '".$To."'";
		$sitename=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
		
		$sitename1=$s->getField('suppliers','id',$_REQUEST['vendor'],'vendor_name');
		
	if($_REQUEST['site']!='' && $_REQUEST['vendor']!=''  && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
	{
	$message="Showing Records of Branch ".$sitename."  and vender '".$sitename1."'  From  ".$From." to ".$To."";
	}
	else if($_REQUEST['site']!='' && $_REQUEST['vendor']=='' && $_REQUEST['fromDate']=='' && $_REQUEST['toDate']=='')
	{
	$message="Showing Records of Branch ".$sitename." ";
	
	}
	else if($_REQUEST['site']=='' && $_REQUEST['vendor']=='' && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
	{
	$message="Showing Records   From  ".$From." to ".$To."";
	
	}
	else if($_REQUEST['site']=='' && $_REQUEST['vendor']!='' && $_REQUEST['fromDate']=='' && $_REQUEST['toDate']=='')
	{
	$message="Showing Records  of vender   ".$sitename1." ";
	
	}
	else if($_REQUEST['site']!='' && $_REQUEST['vendor']!='' && $_REQUEST['fromDate']=='' && $_REQUEST['toDate']=='')
	{
	$message="Showing Records  of Branch ".$sitename."  and vender '".$sitename1."'";
	
	}
	else if($_REQUEST['site']=='' && $_REQUEST['vendor']!='' && $_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
	{
	$message="Showing Records  of  vender '".$sitename1."' From  ".$From." to ".$To."";
	
	}
		
		
		if($filter != '')
		{
		$filter1 = implode(" and ",$filter);
		}	
		if($filter1!='')
		{
	$sql="SELECT vendor_quotes_ammendment.* from vendor_quotes_ammendment INNER JOIN vendor_quotes_ammendment_details
	 on(vendor_quotes_ammendment.id = vendor_quotes_ammendment_details.vendor_quotes_ammendment_id) where $filter1
	 group by vendor_quotes_ammendment.id";
	}
	else
	{
	   if($_SESSION['AssignedSites']!='0')
	  { 
	
	$sql="SELECT vendor_quotes_ammendment.* from vendor_quotes_ammendment INNER JOIN 
	vendor_quotes_ammendment_details on(vendor_quotes_ammendment.id = vendor_quotes_ammendment_details.vendor_quotes_ammendment_id)
	 where   sitecode in (".$_SESSION['AssignedSites'].")	group by vendor_quotes_ammendment.id";
	}
	else
	{
	$sql="SELECT vendor_quotes_ammendment.* from vendor_quotes_ammendment INNER JOIN 
	vendor_quotes_ammendment_details on(vendor_quotes_ammendment.id = vendor_quotes_ammendment_details.vendor_quotes_ammendment_id)  	group by vendor_quotes_ammendment.id";
	}
	}
		//echo $sql;
		$_SESSION['mess']=$message;
		$_SESSION['quat_reg1']=$sql;
		
		
		?>
   <div style="width:auto; height:400px; overflow:auto; margin-left:auto; margin-right:auto;">

	 
	 <div align="center"><strong><?php echo $message; ?></strong> </div>
	 <br />
<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:solid 1px #666666;">
  <tr style="background-color:#CCCCCC; height: 30px">
    <td style="white-space:nowrap;">S. No.</td>
    <td style="white-space:nowrap;">Date</td>
    <td style="white-space:nowrap;">Ammendment No. </td>
	<td>Rev. No. </td>
	<td style="white-space:nowrap;">Vendor </td>
	<td style="white-space:nowrap;">Against Quatation No. </td>
    <td style="width:100px;white-space:nowrap;"><strong>Item Name</strong></td>
	<td style="width:45px"><strong>UOM</strong></td>
	<td style="width:40px"><strong>Qty</strong></td>
    <td><strong>Actual Rate</strong></td>
	<td><strong>Ammend Rate</strong></td>
	<td><strong>Total Amt.</strong></td>
    
  </tr>
  <?php
  $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['quotation_date']);?></td>
    <td><?php echo $myrow['vernder_quotation']; ?></td>
	<td><?php echo $myrow['revision_no']; ?></td>
    <td><?php echo $vender_name=$s->getField('suppliers','id',$myrow['mst_supplierno'],'vendor_name'); ?></td>
	<td><?php echo $quat_no=$s->getField('venderquotations','id',$myrow['old_quotetion_no'],'vernder_quotation'); ?></td>
    <td colspan="6" bgcolor="#99CCCC" ><table width="100%" border="0" bgcolor="#99CCCC">
      <?php 
	  
	 $details_sql="Select * from vendor_quotes_ammendment_details where vendor_quotes_ammendment_id=".$myrow['id']."";
	
	$details_res=DB_query($details_sql,$db);	
	if(DB_num_rows($details_res)>0){
	$tot_received='';
	while($details_row=DB_fetch_array($details_res)){
		
	?>
      <tr bgcolor="#99CCCC" >
        <td class="jjrs_tabledata1" style="width:100px;"><?php echo $details_row['item_name'];?></td>
		<td class="jjrs_tabledata1" style="width:40px;"><span class="jjrs_tabledata1" style="width:51px;"><?php        
		  $sitename1=$s->getField('item_master','id',$details_row['item_id'],'unit');
		$sitename2=$s->getField('unitsofmeasure','unitid',$sitename1,'unitname');
	echo $sitename2;?></span></td>
	<td class="jjrs_tabledata1" style="width:37px;"><?php echo $details_row['quantity'];?></td>
	<?php $details_sql1="Select rate from vendorquotationdetails where mst_productid=".$details_row['item_id']." and quotation_no=".$myrow['old_quotetion_no']."";
	$details_res1=DB_query($details_sql1,$db);
	$details_row1=DB_fetch_array($details_res1);
	?>
        <td class="jjrs_tabledata1" style="width:90px;"><?php echo $details_row1['rate'];  ?></td>
		<td class="jjrs_tabledata1" style="width:98px;"><?php echo $details_row['rate']; ?></td>
        <td   class="jjrs_tabledata1" style="text-align:right"><?php echo $tot_amt=($details_row['quantity']*$details_row['rate']); $tot_received[]=$tot_amt;?></td>
        </tr>
      <?php } ?>
      <tr bgcolor="#FFFFFF" style="height: 25px">
	  <td class="jjrs_tabledata1" style=" white-space:nowrap;"><strong></strong></td>
	  <td class="jjrs_tabledata1" style=" white-space:nowrap;"><strong></strong></td>
	  <td class="jjrs_tabledata1" style=" white-space:nowrap;"><strong></strong></td>
	  <td class="jjrs_tabledata1" style=" white-space:nowrap;"><strong></strong></td>
        <td class="jjrs_tabledata1" style=" white-space:nowrap;"><strong>Total</strong></td>
     <td class="jjrs_tabledata1" style="text-align:right"><strong><?php echo $a[]=array_sum($tot_received);?></strong></td>
        </tr>
      <?php } ?>
      
    </table></td>
  </tr>
  <?php $i++;}
  		}
		else
		{?>
  <tr>
    <td colspan="4"><font color="#FF0000"><strong>No Record Found</strong></font></td>
  </tr>
  <?php 	
		}
  }
	?>
	
</table>
<?php if(!empty($a)) { ?>

<!--<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border:solid 1px #666666;">
  <tr style="background-color:#CCCCCC; height: 30px">

	<td style="width:635px;"></td>
     <td class="jjrs_tabledata1" style=" width:84px;"><strong>Grand Total</strong></td>
     <td class="jjrs_tabledata1" style=""><span class="jjrs_tabledata1" style=" white-space:nowrap;"><?php  //echo array_sum($a); ?></span></td>
        
  </tr>
</table> -->

<?php } ?>
</div>
