<link rel="stylesheet" href="css/new_mxerp.css">
<?php
	$PageSecurity = 5;
	$title = _('Comparative Vendor Quotation');
	include('includes/SQL_CommonFunctions.inc');
	$PageName ='Comprative' ;	
	$Prefix_SQL = "Select prefix_id,prefix_code,prefix_name from prefix_tbl Where prefix_name ='".$PageName."'";
	$Prefix_Result = DB_query($Prefix_SQL,$db);
	$Prefix_Row = DB_fetch_array($Prefix_Result);
	$Prefix_code = $Prefix_Row['prefix_code'];
	   $Prefix_date = date("y");
	   $Prefix_date++;
	   $CurrentFinancialYear = date("y")."-".$Prefix_date; 
?>
<!--<style>
.bod {
	border: 1px double #666666;
	}
.style2 {font-weight: bold}
.style3 {font-weight: bold}
.style4 {font-weight: bold}
.style5 {font-weight: bold}
.style6 {font-weight: bold}
</style>-->
<?php
    $id = $_REQUEST['id'];
   $RequisitionNo = $_REQUEST['RequisitionNo'];
 $lsqlvend="SELECT * FROM venderquotations WHERE pr_no='".$RequisitionNo."' and CompanyId='".$_SESSION['ACGCompanyId']."'";

	$lresultvand=DB_query($lsqlvend,$db);
	$lvendorid=DB_fetch_array($lresultvand);
	$vander_code = $lvendorid['vendercode'];
	$vander_id = $lvendorid['id'];
			
	  //$sql='select comprative_id, comprative_no from comprative_detail order by comprative_id desc limit 0,1';
	  $sql="select * from comprative_detail where sitecode='".$lvendorid['sitecode']."'";
	 // print_r($sql);exit;
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	 
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			
			 if($lvendorid['sitecode']!='')
			 {
				$val= substr($myrow['comprative_no'],0,19);
				$strChar1 = substr($myrow['comprative_no'],0,7);
				//print_r($strChar1);exit;
				$strChar = $strChar1."/".$lvendorid['sitecode']."/".$CurrentFinancialYear."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		  

		}
		else
		{
		 	$strChar = $Prefix_code."/".$lvendorid['sitecode']."/".$CurrentFinancialYear."/";
		}
	  }
	  	else
		{
	  	    $strChar = $Prefix_code."/".$lvendorid['sitecode']."/".$CurrentFinancialYear."/";
		}
	$strFinal = $maxval+1;
	$strBothFinal = $strChar.str_pad($strFinal,4,"0",STR_PAD_LEFT);
	
	$REQ_SQL="Select * from materialrequisitions where requisitionno='".$RequisitionNo."'";
	$REQ_Result=DB_query($REQ_SQL,$db);
	$REQ_Result_Row=DB_fetch_array($REQ_Result);
	$month_year = $REQ_Result_Row['month_year'];
	$ReqFarmCode = $REQ_Result_Row['Reqno'];
	$prdate = $REQ_Result_Row['prdate'];
 ?>

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


 <form action="index.php?route=PO_Header&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>" method="post" name="finalqt">
 
<!-- table1 insert here -->
<div style="border:#6699CC solid 1px; padding:5px; margin-top:3px; background-color:#dddddd">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td >Comparative No.</td>
                   <td ><input type="text" name="comprativeno" size="30" readonly=""  value="<?php echo $strBothFinal; ?>"/></td>
                   <td>Date</td>
                   <td><?php echo date("d/m/Y"); ?><input type="hidden" name="comprative_date" size="30" value="<?php echo date("d/m/Y"); ?>"/></td>
                 </tr>
             </table>

</div><!-- table1 insert here -->
 <!-- table2 inser here --><div style="padding-top:3px;">
 <table width="100%" border="0" cellpadding="0" cellspacing="0" >
               <tr class="row1">
                 <td class="tabledata1"><strong>Site Code</strong></td>
                 <td class="tabledata1"><strong>Site Name</strong></td>
                 <td class="tabledata1"><strong>Requisition No.</strong></td>
				 <td class="tabledata1"><strong>Requisition Date</strong></td>
				</tr>
				<tr class="row1">
                 <td class="tabledata1"><?php echo $lvendorid['sitecode']; ?></td>
                 <td class="tabledata1"><?php echo $lvendorid['site']; ?>
                       <input type="hidden" name="sitecode" id="sitecode" value="<?php echo $lvendorid['sitecode']; ?>" />
                       <input type="hidden" name="sitename" id="sitename" value="<?php echo $lvendorid['site']; ?>" />
                 </td>
                 <td class="tabledata1"><?php echo $ReqFarmCode; ?><input type="hidden" name="reqno" id="reqno"  value="<?php echo $RequisitionNo; ?>" /></td>
                 <td class="tabledata1"><?php echo ConvertSQLDate($prdate); ?>
                       <input type="hidden" name="reqno_date" id="reqno_date"  value="<?php echo ConvertSQLDate($prdate); ?>" />
                 </td>
               </tr>
             </table>
 
 </div> <!-- table2 close here -->

  <!-- table3 inser here --><div style="padding-top:3px; background-color:#999999;">
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <?php 
	         $suppsqlvend="SELECT venderquotations.*,
				  suppliers.vendor_name, 
				  suppliers.vendor_code  
				  FROM  venderquotations
				  INNER JOIN suppliers ON suppliers.vendor_code=venderquotations.vendercode 
				  INNER JOIN vendorquotationdetails ON vendorquotationdetails.quotation_no=venderquotations.id 
				  WHERE venderquotations.pr_no=".$RequisitionNo." group by id";	
				  $suppresultvand=DB_query($suppsqlvend,$db);
$i=1;

if(DB_num_rows($suppresultvand)>0){
while($suppvendorid=DB_fetch_array($suppresultvand))
{
$payment_Sql = "SELECT termsindicator, terms  FROM paymentterms Where termsindicator='".$suppvendorid['payment_term']."'";
$payment_result = DB_query($payment_Sql,$db);
$payment_myrow=DB_fetch_array($payment_result);
$paymentother_Sql = "Select paymentid, paymentname, paymenttype, receipttype from paymentmethods Where paymentid='".$suppvendorid['payment_term']."'";
$paymentother_result = DB_query($paymentother_Sql,$db);
$paymentother_myrow=DB_fetch_array($paymentother_result);
$event_Sql = "select * from events Where event_id='".$suppvendorid['event']."'";
$event_result = DB_query($event_Sql,$db);
$event_myrow=DB_fetch_array($event_result);
?>

<tr class="row1">
<td>&nbsp;</td>
<td><strong>Vendor Quot. No</strong></td>
<td><strong>Quot. Date</strong></td>
<td><strong>Vendor Code</strong></td>
<td><strong>Vendor Name </strong></td>
<td><strong>Quot. Catagory </strong></td>
<td><strong>Basis</strong></td>
<td><strong>Payment Tearm</strong></td>
<td><strong>Payment Mode</strong></td>
<td><strong>Event</strong></td>
</tr>
<tr class="row1">
<td><input name="final_Quot" id="final_Quot[]" type="radio" value="<?php echo $suppvendorid['id']; ?>" onclick="FinalQuotation(this.value)"/></td>
<td><?php echo $suppvendorid['vernder_quotation']; ?>
<input type="hidden" name="Vendorqtnid" id="Vendorqtnid" value="<?php echo $suppvendorid['id']; ?>" /></td>
<td><?php echo ConvertSQLDate($suppvendorid['date1']); ?></td>
<td><?php echo $suppvendorid['vendor_code']; ?>
<input type="hidden" name="vendername" id="vendername" value="<?php echo $suppvendorid['vendor_name']; ?>" />
<input type="hidden" name="vendercode" id="vendercode" value="<?php echo $suppvendorid['vendor_code']; ?>">
</td>
<td><?php echo $suppvendorid['vendername']; ?></td>
<td><?php echo $suppvendorid['quotationcategory']; ?></td>
<td><?php echo $suppvendorid['basis']; ?></td>
<td><?php echo $payment_myrow['terms']; ?></td>
<td><?php echo $paymentother_myrow['paymentname']; ?></td>
<td><?php echo $event_myrow['event_desc'];?></td>
</tr>
<tr>
<td colspan="10">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%"border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#666666">
<td><strong><font color="#FFFFFF">Product Code</font></strong></td>
<td colspan="2"><strong><font color="#FFFFFF">Product Name</font></strong></td>
<td><strong><font color="#FFFFFF">Make</font></strong></td>
<td><strong><font color="#FFFFFF">Grade</font></strong></td>
<td><strong><font color="#FFFFFF">Color</font></strong></td>
<td><strong><font color="#FFFFFF">Quantity</font></strong></td>
<td><strong><font color="#FFFFFF">Rate</font></strong></td>
<td><strong><font color="#FFFFFF">Discount<br />Type</font></strong></td>
<td><strong><font color="#FFFFFF">Discount</font></strong></td>
<td><strong><font color="#FFFFFF">Discount<br />Amount</font></strong></td>
<td><strong><font color="#FFFFFF">Sub Total </font></strong></td>
<!--<td><strong><font color="#FFFFFF">Tax Name</font></strong></td>
<td><strong><font color="#FFFFFF">Tax Rate </font></strong></td>
<td><strong><font color="#FFFFFF">Tax Amount</font></strong></td>
<td colspan="2"><strong><font color="#FFFFFF">Amount With<br /> Taxes</font></strong></td>-->
</tr>
<?php 
$sql='SELECT venderquotations.*, 
suppliers.vendor_name, 
suppliers.vendor_code, 
vendorquotationdetails.* 
FROM  venderquotations
INNER JOIN suppliers ON suppliers.vendor_code=venderquotations.vendercode 
INNER JOIN vendorquotationdetails ON vendorquotationdetails.quotation_no=venderquotations.id 
WHERE venderquotations.pr_no='.$RequisitionNo. ' and venderquotations.id='.$suppvendorid['id']; 
$result=DB_query($sql,$db);
$j = 1;
$k=0; //row colour counter
while($myrow=DB_fetch_array($result))
{	

if ($k==1){ /*alternate bgcolour of row for highlighting */
echo '<tr class="OddTableRows">';
$k=0;
} else {
echo '<tr class="EvenTableRows">';
$k++;
}
?>
<tr>
<td><?php echo $myrow['prod_id']; ?></td>
<td colspan="2"><?php echo $myrow['prod_dec']; ?>
<input type="hidden" name="prod_id"  value="<?php echo $myrow['prod_id']; ?>" /></td>
<td><?php 
$makename=$s->getField('product_manufacture','id',$myrow['make'],'manufacturer');
echo $makename; ?></td>
<td><?php 
$gradename=$s->getField('product_grade','id',$myrow['grade'],'grade');
echo $gradename; ?></td>
<td><?php 
$colorname=$s->getField('product_color','id',$myrow['color'],'color');
echo $colorname; ?></td>
<td><?php echo $myrow['quantity']; ?></td>
<td><?php echo $myrow['rate']; ?></td>
<td><?php 
if($myrow['discount']=='0')
echo "N/A";
else
echo $myrow['discount_type']; ?></td>
<td><?php echo $myrow['discount']; ?></td>
<td><?php echo $myrow['discount_amount']; ?></td>
<td><?php echo $myrow['sub_total']; ?></td>
<!--<td><?php 
//$tax_sql=DB_query("Select tax_code from sales_tax_master where salestax_id='".$myrow['taxnameid']."'",$db);
//$tax_row=DB_fetch_array($tax_sql);
//echo $tax_row['tax_code']; ?></td>  
<td><?php //echo $myrow['taxvalue']; ?></td>
<td><?php //echo $myrow['taxamount']; ?></td>
<td colspan="2"><?php //echo $myrow['totalamountwithtax']; ?></td>-->
</tr>
<?php }  ?>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Total Basic Amount:</font></strong></td>
  <td><strong><?php echo $suppvendorid['basic_amt']; ?></strong>
      <input type="hidden" name="Total_Amount" value="<?php echo $suppvendorid['basic_amt']; ?>" />  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Excise Duty :</font></strong></td>
  <td><strong><?php echo $suppvendorid['Excise_Duty']; ?></strong>
      <input type="hidden" name="Total_Amount" value="<?php echo $suppvendorid['Excise_Duty']; ?>" /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Edu Cess:</font></strong></td>
  <td><strong><?php echo $suppvendorid['Edu_Cess']; ?></strong>
      <input type="hidden" name="Total_Amount" value="<?php echo $suppvendorid['Edu_Cess']; ?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>

<td colspan="2"><strong><font color="#666666">SHE Cess:</font></strong></td>
<td><strong><?php echo $suppvendorid['SHE_Cess']; ?></strong>
      <input type="hidden" name="Total_Amount" value="<?php echo $suppvendorid['SHE_Cess']; ?>" /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Taxable Amount:</font></strong></td>
  <td><span class="style3">
    <?php
echo $suppvendorid['taxable_amt']; ?>
  </span>
      <input type="hidden" name="Total_Tax2" value="<?php echo $suppvendorid['taxable_amt']; ?>" /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Tax Name :</font></strong></td>
  <td><span class="style4">
    <?php
  	$tax_sql=DB_query("Select tax_code from sales_tax_master where salestax_id='".$suppvendorid['taxname']."'",$db);
	$tax_row=DB_fetch_array($tax_sql);
	echo $tax_row['tax_code'];
   ?>
  </span>
      <input type="hidden" name="Total_Tax2" value="<?php echo $suppvendorid['taxname']; ?>" /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><strong><font color="#666666">Tax Rate :</font></strong></td>
  <td><strong>
    <?php
echo $suppvendorid['taxvalue']; ?> 
    </strong> 
      <input type="hidden" name="Total_Tax2" value="<?php echo $suppvendorid['taxvalue']; ?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"><strong><font color="#666666">Total Tax Amount </font><font color="#666666"> :</font></strong></td>
<td><span class="style5">
  <?php
echo $suppvendorid['tot_tax_amount']; ?>
</span>
  <input type="hidden" name="Total_Tax2" value="<?php echo $suppvendorid['tot_tax_amount']; ?>" /></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"><strong><font color="#666666">Surcharge : </font></strong></td>
<td><strong>
  <?php
echo $suppvendorid['sur_oct_perc']; ?>
  %</strong>
    <input type="hidden" name="sur_oct_perc" value="<?php echo $suppvendorid['sur_oct_perc']; ?>" /></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"><strong><font color="#666666">Surcharge Amount </font></strong></td>
<td>
  <span class="style6">
  <?php
echo $suppvendorid['sur_oct_amt']; ?>
  </span>
  <input type="hidden" name="sur_oct_amt" value="<?php echo $suppvendorid['sur_oct_amt']; ?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td  colspan="2"><strong><font color="#666666">Total Charges:</font></strong></td>
<td><strong><?php echo $suppvendorid['totalcharge']; ?></strong>
  <input type="hidden" name="Total_Charge" value="<?php echo $suppvendorid['totalcharge']; ?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2"><strong><font color="#666666">Grand Total:</font></strong></td>
<td><strong><?php echo $suppvendorid['grand_total']; ?></strong>
  <input type="hidden" name="Grand_Total" value="<?php echo $suppvendorid['grand_total']; ?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?php $i++;} }
else
{?>
<tr>
<td colspan="8"><strong>NO VENDOR QUOTATION HAS BEEN MADE AGAINST THIS REQUISITION</strong></h2></td>
</tr>
<?php 
}
?>

</table>
</div> 
 



</form>


</div>
</div>



<script type="text/javascript">
function FinalQuotation(str)
	{ 
	  //alert(str);
	  
	  xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
				alert ("Your browser does not support AJAX!");
				return;
			  } 
		var url="FinalQuot.php";
		url=url+"?FinalQuot="+str;
		//alert(url);
		xmlHttp.onreadystatechange=NumberChanged1;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
  function NumberChanged1() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
		   document.getElementById("FinalQuot").innerHTML=xmlHttp.responseText;
		}
	}    
  function GetXmlHttpObject()
  {
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
  }  
</script>   