<?php
error_reporting(0);
    $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 = substr($Prefix_Row['prefix_code'],6,9);
$year = $_SESSION['financialYearStart'];
$year_after=$_SESSION['financialYearEnd'];
$CurrentFinancialYear = $year.$year_after; 
?>
<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

if($_REQUEST['FinalQuot'])
{
$arr4=array();

 foreach ($_REQUEST['final_Quot'] as $key => $value)
	  {	  	
		
	  	$venid=  $s->GetFieldValue('venderquotations',"id='".$value."'" ,'mst_supplierno');
  		$supplier=  $s->GetFieldValue('suppliers',"id='".$venid."'" ,'vendor_name');
		//$qutotationid[]= $s->GetFieldValue('vendorquotationdetails',"quotation_no='".$value."'" ,'quotation_id');
		//print_r($qutotationid);
		$data_cmp['comprative_no']= $_REQUEST['comprativeno'];
 		$data_cmp['vendor_id']=$venid;
		$data_cmp['vendor_name']=$supplier;
		$data_cmp['sitecode']=$_REQUEST['sitecode'];
		$data_cmp['Quotations_type']=$_REQUEST['quotation_type'][$key];
		$arr3='';
		$arr5='';
		$arr6='';
	   for($i=1;$i<=count($_REQUEST['ACGProductOrder'][$value]);$i++)
		{
		
		  $da[]=$_REQUEST['ACGProductOrder'][$value][$i];
		  $da1[]=$_REQUEST['ACGProductOrder'][$value][$i];
		 $arr3[]= $_REQUEST['assign_qty'][$_REQUEST['ACGProductOrder'][$value][$i]][$value];
		 $arr4[][$_REQUEST['ACGProductOrder'][$value][$i]]= $_REQUEST['assign_qty'][$_REQUEST['ACGProductOrder'][$value][$i]][$value];
		 $arr5[]=$_REQUEST['vender_detail_id'][$_REQUEST['ACGProductOrder'][$value][$i]][$value];	
		 $arr6[]=$_REQUEST['venderqty'][$_REQUEST['ACGProductOrder'][$value][$i]][$value];	
		}
			
			
		$da1[]=array_unique($da);
		$da5[$value]=array_unique($da);
		
		if(count($_REQUEST['ACGProductOrder'])>0)
		{
		  $arr=implode(',',$arr3);;	
	
         $arr1=implode(',',$arr5);
	
	     $arr2=implode(',',$arr6);	
		
		$data_cmp['mst_product_list']=implode(',',$da5[$value]);
		}
		else
		$data_cmp['mst_product_list']=$_REQUEST['ACGProductOrder'][$value][$i];
		$data_cmp['Vendor_Quot_No']= $value;
		$data_cmp['RequisitionNo']= $_REQUEST['RequisitionNo'];
	    $data_cmp['comprative_date']= date('Y-m-d');
		
		if(count($arr)>0)
		{			
		$data_cmp['assign_qty']=$arr;
		}
		else
		{				 
		$data_cmp['assign_qty']=$arr;	
		}
		
		if(count($arr1)>0)
		{	
		$data_cmp['quotation_id']=$arr1;
		}
		else 
		$data_cmp['quotation_id']=$arr1;
			
		if($data_cmp['mst_product_list']!=''){
		$insert=$s->RecordInsert('comprative_detail', $data_cmp);
 		$last=DB_Last_Insert_ID($db,'comprative_detail', 'id');
		}
		
		}
	
	 }
	 
	 $sum=array();
	 $i=0;
	foreach($arr4 as  $key1 => $value1)
	{	
    foreach ($value1 as $key2=> $value2) 
	{
	
	if(!in_array($key2,$sum))
	{
	$sum[$key2]=$sum[$key2]+$value2;
	}
	}
	
	}
	    if(count($sum)>0)
		{
	 	//$productid=$_REQUEST['ACGProductOrder'][$value][$i];		
		$quantity='';
	    for($l=0;$l<count($sum);$l++)
	    {
	      $itemid=$da1[$l];
		  //echo $arr2[$value][$i];	
		 // echo "select App_quantity1 from requisitionorderdetails where mst_itemid='".$itemid."' 
		//and requsitionno='".$_REQUEST['RequisitionNo']."'";
		  
		$sqldcheck=DB_query("select App_quantity1 from requisitionorderdetails where mst_itemid='".$itemid."' 
		and requsitionno='".$_REQUEST['RequisitionNo']."'",$db);  
		$sqlcheck=DB_fetch_array($sqldcheck);
		//echo $sqlcheck['App_quantity1'];
		if($sqlcheck['App_quantity1']=='') 
		{ 	
		 $quantity=$sum[$itemid];
		}
		else
		 $quantity=$sqlcheck['App_quantity1']-$sum[$itemid];		
		
		//echo "update  requisitionorderdetails set  App_quantity1='".$quantity."' where mst_itemid='".$itemid."'
	  // and requsitionno='".$_REQUEST['RequisitionNo']."'"; 	
	   $data1=DB_query("update  requisitionorderdetails set  App_quantity1='".$quantity."' where mst_itemid='".$itemid."'
	  and requsitionno='".$_REQUEST['RequisitionNo']."'",$db);
		}
	 //print_r($sum);
	 

echo "<script>location.href='index.php?route=POModule/Comp-Groupwiselist&CPID=".$last.'&RequisitionNo='.$_REQUEST['RequisitionNo'].$rurl."'</script>";
 

//$s->pageLocation("index.php?route=POModule/Comp-Groupwiselist&CPID=".$last.'&RequisitionNo='.$_REQUEST['RequisitionNo'].$rurl);
 }

    $id = $_REQUEST['id'];
    $RequisitionNo = $_REQUEST['RequisitionNo'];
  	$lsqlvend="SELECT * FROM venderquotations WHERE indent_prno='".$RequisitionNo."'";
	$lresultvand=DB_query($lsqlvend,$db);
	$lvendorid=DB_fetch_array($lresultvand);
	$vander_code = $lvendorid['vendercode'];
	$vander_id = $lvendorid['id'];
	
  	$sql='select * from comprative_detail where sitecode = "'.$lvendorid['sitecode'].'"  ORDER BY comprative_id DESC LIMIT 0,1';
 	$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);
			 $last_number=substr($myrow['comprative_no'],-4);
			 $strchar = $strChar1."/".$lvendorid['sitecode']."/".$CurrentFinancialYear."/";
							  
			//$val1= substr($myrow['MRNNo'],0,18);
			//$strChar1 = substr($myrow['MRNNo'],0,7);
			//$strChar = $strChar1."/".$_POST['sitecode']."/".$CurrentFinancialYear."/";
			
			if($numrows>0)
			{ 
				$maxval = $last_number;
			}
			else
			{
				$maxval=0;
			}
			$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'];
 ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Comparative</h1>
<form action="" method="post" name="finalqt">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
	<td height="30" bgcolor="#666666"  style="color:#FFFFFF"><strong>Comparative No.</strong></td>
	<td bgcolor="#666666"  style="color:#FFFFFF">
	<!--<input type="text" name="comprativeno" size="30" readonly=""  value="<?php echo $strBothFinal; ?>"/>-->
	<input type="text" name="comprativeno" size="30" readonly=""  value="Auto Generated"/></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong>Date</strong></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong><?php echo date("d/m/Y"); ?></strong>
	<input type="hidden" name="comprative_date" size="30" value="<?php echo date("d/m/Y"); ?>"/></td>
</tr>
<tr>
	<td height="30" bgcolor="#666666"  style="color:#FFFFFF"><strong>Site Name:</strong></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong><?php echo $lvendorid['Site']; ?></strong>
	<input type="hidden" name="sitecode" id="sitecode" value="<?php echo $lvendorid['Site']; ?>" /></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong>Requisition No.:</strong></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong><?php echo $ReqFarmCode; ?></strong>
	<input type="hidden" name="reqno" id="reqno"  value="<?php echo $RequisitionNo; ?>" /></td>
	<td bgcolor="#666666"  style="color:#FFFFFF"><strong>Requisition Date:</strong></td>
	<td bgcolor="#666666"  style="color:#FFFFFF">  <strong><?php echo ConvertSQLDate($prdate); ?></strong>
	<input type="hidden" name="reqno_date" id="reqno_date"  value="<?php echo ConvertSQLDate($prdate); ?>" /></td>
</tr>
<?php 
$data2=''; 
$rowdata=DB_query("select Vendor_Quot_No from comprative_detail where RequisitionNo='".$REQ_Result_Row['requisitionno']."' ",$db);
while($rowdata1=DB_fetch_array($rowdata))
{
	$data2[]=$rowdata1['Vendor_Quot_No'];		
}
if(!empty($data2))
{
	$comma_separated = implode("','",$data2);
}   
else 
{
	$comma_separated = 'Test';
}        
if($comma_separated=='Test')
{ 
	$suppsqlvend="SELECT venderquotations.*,
	suppliers.vendor_name, 
	suppliers.vendor_code,
	suppliers.id  as venderid 
	FROM  venderquotations
	INNER JOIN suppliers ON suppliers.id=venderquotations.mst_supplierno 
	INNER JOIN vendorquotationdetails ON vendorquotationdetails.parant_id=venderquotations.id 
	WHERE venderquotations.indent_prno=".$RequisitionNo."  group by id";
}
else
{       
	$suppsqlvend="SELECT venderquotations.*,
	suppliers.vendor_name, 
	suppliers.vendor_code,  
	suppliers.id  as venderid
	FROM  venderquotations
	INNER JOIN suppliers ON suppliers.id=venderquotations.mst_supplierno  
	INNER JOIN vendorquotationdetails ON vendorquotationdetails.quotation_no=venderquotations.id 
	WHERE venderquotations.mst_requisition_no=".$RequisitionNo." and venderquotations.id NOT IN('".$comma_separated."') group by id";
}
$suppresultvand=DB_query($suppsqlvend,$db);
$i=1;
$vid=0;
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>
<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 colspan="11">
 	<table width="100%" border="0" cellpadding="0" cellspacing="0" >
	<tr style="height:40px;color:#FFFFFF;" bgcolor="#666666">
	<td>&nbsp;</td>
	<td style="border-top:1px #FFFFFF solid;"><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>Basis</strong></td>
</tr>
<tr>
<td><div align="center">
<input name="final_Quot[<?php echo $vid?>]" id="final_Quot_<?php echo $vid; ?>" type="checkbox" value="<?php echo $suppvendorid['id']; ?>" onclick="checkItems('<?php echo $vid; ?>')"  />
</div></td>
<td><?php echo $suppvendorid['quotation_no']; ?>
<input type="hidden" name="Vendorqtnid" id="Vendorqtnid" value="<?php echo $suppvendorid['id']; ?>" /></td>
<td><div align="left"><?php echo ConvertSQLDate($suppvendorid['Quotation_Date']); ?></div></td>
<td><div align="left"><?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']; ?>">
</div></td>
<td><div align="left"><?php echo $suppvendorid['vendor_name']; ?></div></td>
<td><div align="left"><?php echo $suppvendorid['basis']; ?></div></td>
</tr>
<tr>
  <td colspan="6" width="100%">
  <table width="100%"border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
 <tr bgcolor="#999999">
<td><strong>Product Code</strong></td>
<td><strong>Product Name</strong></td>
<td><strong>Quantity</strong></td>
<td><strong>Assign Qty</strong></td>
<td><strong>Rate</strong></td>
<td><strong>Discount<br />Amount</strong></td>
<td><strong> Sub Total </strong></td>
<td><strong>Special <br />Discount<br />Amount</strong></td>
<td><strong> Basic Amt </strong></td>
<td><strong> Taxable Amt </strong></td>
<td><strong> Total </strong></td>
</tr>
<?php 
//echo "select * from vendor_quotes_ammendment where requisition_id='".$_REQUEST['RequisitionNo']."' and mst_supplierno='".$suppvendorid['mst_supplierno']."'  order by vendor_quotes_ammendment.revision_no DESC limit 1";
$sqlcheck=DB_query("select * from vendor_quotes_ammendment where requisition_id='".$_REQUEST['RequisitionNo']."' and mst_supplierno='".$suppvendorid['mst_supplierno']."'  order by vendor_quotes_ammendment.revision_no DESC limit 1",$db);
$numrowcheck=DB_num_rows($sqlcheck);
$row5=DB_fetch_array($sqlcheck);
if($numrowcheck>0)
{
$sql='SELECT vendor_quotes_ammendment.*, vendor_quotes_ammendment_details.* 
FROM  vendor_quotes_ammendment INNER JOIN vendor_quotes_ammendment_details ON vendor_quotes_ammendment.id=vendor_quotes_ammendment_details.vendor_quotes_ammendment_id 
WHERE vendor_quotes_ammendment.requisition_id='.$RequisitionNo. ' and vendor_quotes_ammendment.old_quotetion_no='.$suppvendorid['id'].' and  vendor_quotes_ammendment.revision_no='.$row5['revision_no'].'' ;	
$result=DB_query($sql,$db);
$numdata=DB_num_rows($result);
 $j=1;
$k=0; //row colour counter
while($myrow=DB_fetch_array($result))
{	
$app=DB_query("select * from requisitionorderdetails where requsitionno='".$RequisitionNo."' and mst_itemid='".$myrow['item_id']."'",$db);
$app1=DB_fetch_array($app);
if($app1['App_quantity1']!='0.000')
{
if ($k==1){ /*alternate bgcolour of row for highlighting */
echo '<tr class="OddTableRows">';
$k=0;
} else {
echo '<tr class="EvenTableRows">';
$k++;
}
?>
<tr>
<td>
<input name="ACGProductOrder[<?php echo $suppvendorid['id']; ?>][<?php echo $j; ?>]" id="ACGProductOrder_<?php  echo $vid; ?><?php echo $j; ?>" type="checkbox" value="<?php echo $myrow['item_id'];  ?>"  onclick="FinalQuotation(this.value,'<?php echo $vid.$j;?>')"  disabled="disabled"/>
<input type="hidden" id="items_<?php echo $vid; ?>-<?php echo $myrow['item_id'] ; ?>" value="<?php echo  $myrow['item_id'];  ?>" />
 <?php echo $myrow['item_code']; ?></td>
<td  ><?php echo $myrow['item_name']; ?>
<input type="hidden" name="prod_id"  value="<?php echo $myrow['item_code']; ?>" />
<input type="hidden" name="vender_detail_id[<?php echo $myrow['item_id'];?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['id'];  ?>"></td>
<td>
<?php if($app1['App_quantity1']!='') {
	echo $app1['App_quantity1'];
	?>
<input type="hidden"  name="venderqty[<?php echo $myrow['item_id'];?>][<?php echo $suppvendorid['id']; ?>]" id="venderqty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php echo $app1['App_quantity1'] ; ?>" /> 
<?php } else {
	echo $myrow['quantity'];
	 ?>
<input type="hidden" name="venderqty[<?php echo $myrow['item_id'];?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['quantity']; ?>"  id="venderqty_<?php  echo $vid; ?><?php echo $j; ?>"/>
<?php } ?>
</td>
<td><?php if($app1['App_quantity1']!='') {?>	
	<input type="text" name="assign_qty[<?php echo $myrow['item_id'];?>][<?php echo $suppvendorid['id']; ?>]" size="10px" onchange="check(<?php echo $vid; ?>,<?php echo $j; ?>)" id="assign_qty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php echo $app1['App_quantity1'] ; ?>" disabled="disabled" >
	<?php } else { ?>
	<input type="text" name="assign_qty[<?php echo $myrow['item_id'];?>][<?php echo $suppvendorid['id']; ?>]" size="10px" onchange="check(<?php echo $vid; ?>,<?php echo $j; ?>)" id="assign_qty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php echo $myrow['quantity']; ?>"  disabled="disabled">
		
	<?php } ?>	
	
	
	</td>
<td><?php echo $myrow['rate']; ?></td> 
<td><?php echo $myrow['discount_amount']; ?></td>
<td><?php echo $myrow['sub_total']; ?>
<td><?php echo $myrow['special_discount_amount']; ?>
<td><?php echo $myrow['basic_amount']; ?></td>
<td><?php if($myrow['tax_type']=='NonExcisable')
			{
				 echo $myrow['taxvalue'];  
			}
			else
			{
				 if($myrow['tax_type']=='Excisable')
				 {
				 	echo $myrow['taxable_amt'] + $myrow['taxvalue'];
				 }
				 else{
				 	echo "IncludeTax";
				 }					
			}
			?></td>
<td><?php echo $myrow['total_amount']; ?></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 $j++; } 
else { ?>
<tr><td colspan="11"> No Records</td></tr>	
	
<?php }
} 
?>
<input type="hidden" name="count1" id="count1_<?php echo $vid; ?>" value="<?php echo $j; ?>" />
<input type="hidden" name="quotation_type[]" value="AMD" />
<?php } 
else 
{	
//echo "<br>";
  echo $sql='SELECT venderquotations.*, vendorquotationdetails.* 
FROM  venderquotations INNER JOIN vendorquotationdetails ON vendorquotationdetails.parant_id=venderquotations.id 
WHERE venderquotations.indent_prno='.$RequisitionNo. ' and venderquotations.id='.$suppvendorid['id'] ;
$result=DB_query($sql,$db);
$j = 1;
$k=0; //row colour counter
while($myrow=DB_fetch_array($result))
{	
$app=DB_query("select * from requisitionorderdetails where requsitionno='".$RequisitionNo."' and mst_itemid='".$myrow['mst_productid']."'",$db);
$app1=DB_fetch_array($app);
if($app1['App_quantity1']!='0.000')
{
if ($k==1){ /*alternate bgcolour of row for highlighting */
echo '<tr class="OddTableRows">';
$k=0;
} else {
echo '<tr class="EvenTableRows">';
$k++;
}
?>
<tr>
<td><input name="ACGProductOrder[<?php echo $suppvendorid['id']; ?>][<?php echo $j; ?>]" id="ACGProductOrder_<?php  echo $vid; ?><?php echo $j; ?>" type="checkbox" value="<?php echo $myrow['mst_productid'];  ?>" onclick="FinalQuotation(this.value,'<?php echo $vid.$j;?>')" disabled="disabled"/>
<input type="hidden" id="items_<?php echo $vid; ?>-<?php echo $myrow['mst_productid'] ; ?>" value="<?php echo $myrow['mst_productid'];  ?>" />
  <?php echo $myrow['mst_itemid']; ?></td>
<td><?php echo $myrow['mst_itemid']; ?>
<input type="hidden" name="prod_id"  value="<?php echo $myrow['mst_itemid']; ?>" />
<input type="hidden" name="vender_detail_id[<?php echo $myrow['mst_itemid'];?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['quotation_id'];  ?>"></td>
<td>
<?php if($app1['App_quantity1']!='') {
	echo $app1['App_quantity1'];
	?>
<input type="hidden"  name="venderqty[<?php echo $myrow['mst_itemid'];?>][<?php echo $suppvendorid['id']; ?>]" id="venderqty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php echo $app1['App_quantity1'] ; ?>" /> 
<?php } else {
	echo $myrow['quantity'];
	 ?>
<input type="hidden" name="venderqty[<?php echo $myrow['mst_itemid'];?>][<?php echo $suppvendorid['id']; ?>]" value="<?php echo $myrow['quantity']; ?>"  id="venderqty_<?php  echo $vid; ?><?php echo $j; ?>"/>
<?php } ?>
</td>
<td><?php if($app1['App_quantity1']!='') {?>	
	<input type="text" name="assign_qty[<?php echo $myrow['mst_itemid'];?>][<?php echo $suppvendorid['id']; ?>]" size="10px" onchange="check(<?php echo $vid; ?>,<?php echo $j; ?>)" id="assign_qty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php //echo $app1['App_quantity1'] ; ?>" disabled="disabled"  >
	<?php } else { ?>
	<input type="text" name="assign_qty[<?php echo $myrow['mst_itemid'];?>][<?php echo $suppvendorid['id']; ?>]" size="10px" onchange="check(<?php echo $vid; ?>,<?php echo $j; ?>)" id="assign_qty_<?php  echo $vid; ?><?php echo $j; ?>" value="<?php //echo $myrow['quantity']; ?>" disabled="disabled"  >
		
	<?php } ?>
	
	<td><?php echo $myrow['rate']; ?></td>
<td><?php echo $myrow['discount_amount']; ?></td>
<td><?php echo $myrow['sub_total']; ?>
<td><?php echo $myrow['specialdiscount_amount']; ?>
<td><?php echo $myrow['basic_amt']; ?></td>
<td><?php if($myrow['tax_type']=='NonExcisable')
			{
				 echo $myrow['taxvalue'];  
			}
			else
			{
				 if($myrow['tax_type']=='Excisable')
				 {
				 	echo $myrow['taxable_amt'] + $myrow['taxvalue'];
				 }
				 else{
				 	echo "IncludeTax";
				 }					
			}
			?></td>
<td><?php echo $myrow['total_amount']; ?></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 $j++; } }
?>
<input type="hidden" name="count1" id="count1_<?php echo $vid; ?>"   value="<?php echo $j; ?>" />
<input type="hidden" name="quotation_type[]" value="WithoutAmd" />

<?php  } ?>
 </table>
  </td>
</tr>
</table>

</td>
 
</tr>
<tr>
<td colspan="10" valign="top" align="center">
 </td>
</tr>
<?php $i++;
$vid++;

}?>
<input type="hidden" name="viddata" value="<?php echo $vid; ?>" id="viddata"  />
<?php }
else
{?>
<tr>
<td colspan="10"><h3 align="center"><strong>NO VENDOR QUOTATION HAS BEEN MADE AGAINST THIS REQUISITION</strong></h3></td>
</tr>
<?php 
} 
?>
<tr>
<td colspan="10"><div id="FinalQuot"></div></td>
</tr>
<tr>
<td colspan="10">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</form>
<script type="text/javascript">
function checkItems(id)
{
	var count_items=document.getElementById("count1_"+id).value;
	
	if(document.getElementById("final_Quot_"+id).checked==true){
	for(var k=1;k<count_items;k++)
	{
		document.getElementById("ACGProductOrder_"+id+""+k).disabled=false;
		document.getElementById("assign_qty_"+id+""+k).disabled=false;
	}}
	else
	{
		for(var k=1;k<count_items;k++)
		{
			document.getElementById("ACGProductOrder_"+id+""+k).disabled=true;
			document.getElementById("ACGProductOrder_"+id+""+k).checked=false;
			document.getElementById("assign_qty_"+id+""+k).value='';
			document.getElementById("assign_qty_"+id+""+k).disabled=true;
		}
	}
}

function FinalQuotation(str,id)
	{ 
	  //alert(id);	
	  if(document.getElementById("ACGProductOrder_"+id).checked==true){ 
	  	
	  document.getElementById("assign_qty_"+id).value=document.getElementById("venderqty_"+id).value;
	  var data=check1(id);
	  
	  
	  }
	  else if(document.getElementById("ACGProductOrder_"+id).checked==false)
	  {document.getElementById("assign_qty_"+id).value='';}
	  
	  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;
  }  
  
function check(i,t)
{
	
var vid=document.getElementById("viddata").value;

//var k=parseFloat(document.getElementById("assign_qty_"+i+t).value);
//var j=parseFloat(document.getElementById("venderqty_"+i+t).value);
//if(k>j)
//{
//alert("Assign Qty Cannot Greater Then Actual Qty");
//document.getElementById("assign_qty_"+i+t).value='';
//document.getElementById("assign_qty_"+i+t).focus;
//}
var k=0;
 var j;

for(var m=0;m<vid;m++)
{
	
if(document.getElementById("ACGProductOrder_"+m+""+t).checked==true && (document.getElementById("ACGProductOrder_"+i+""+t).value==document.getElementById("ACGProductOrder_"+m+""+t).value))
{
	
if(i==m)
{	
				
  var k=k+parseFloat(document.getElementById("assign_qty_"+i+""+t).value);
  var j=parseFloat(document.getElementById("venderqty_"+i+""+t).value);
  break;	
}
else
{		
var k=k+parseFloat(document.getElementById("assign_qty_"+m+""+t).value);

var j=parseFloat(document.getElementById("venderqty_"+m+""+t).value);	
	}
}

 }

if(k>j)
{
alert("Assign Qty Cannot Greater Then Actual Qty");
document.getElementById("assign_qty_"+i+""+t).value='';
document.getElementById("assign_qty_"+i+""+t).focus;

}
}


function check1(id)
{
	
	var t=id.substr(1,1);
	var i=id.substr(0,1);
var vid=document.getElementById("viddata").value;

//var k=parseFloat(document.getElementById("assign_qty_"+i+t).value);
//var j=parseFloat(document.getElementById("venderqty_"+i+t).value);
//if(k>j)
//{
//alert("Assign Qty Cannot Greater Then Actual Qty");
//document.getElementById("assign_qty_"+i+t).value='';
//document.getElementById("assign_qty_"+i+t).focus;
//}
var k=0;
 var j;

for(var m=0;m<vid;m++)
{
	
if(document.getElementById("ACGProductOrder_"+m+""+t).checked==true && (document.getElementById("ACGProductOrder_"+i+""+t).value==document.getElementById("ACGProductOrder_"+m+""+t).value))
{
	
if(i==m)
{	
				
  var k=k+parseFloat(document.getElementById("assign_qty_"+i+""+t).value);
  var j=parseFloat(document.getElementById("venderqty_"+i+""+t).value);
  break;	
}
else
{		
var k=k+parseFloat(document.getElementById("assign_qty_"+m+""+t).value);

var j=parseFloat(document.getElementById("venderqty_"+m+""+t).value);	
	}
}

 }

if(k>j)
{
alert("Assign Qty Cannot Greater Then Actual Qty");
document.getElementById("assign_qty_"+i+""+t).value='';
document.getElementById("assign_qty_"+i+""+t).focus;
}
}


function checkdata1()
{
var t=0;
var k=0;
var vid=document.getElementById("viddata").value;
for(var m=0;m<vid;m++)
{	
	    if(document.getElementById("final_Quot_"+m).checked==true)
	    {		
		var counter=document.getElementById("count1_"+m).value;
		for(var j=1;j<counter;j++)
		{			
		if(document.getElementById("ACGProductOrder_"+m+""+j).checked==true)
		{			
		var value=document.getElementById("ACGProductOrder_"+m+""+j).value;
		var items=(document.getElementById("items_"+m+"-"+value).value).split('-');
		var t=parseFloat(document.getElementById("venderqty_"+m+""+j).value);	
		if(items[0]==document.getElementById("ACGProductOrder_"+(m+1)+""+j).value)
		{
		var k=k+parseFloat(document.getElementById("assign_qty_"+m+""+j).value);
		}
				
		} 
		}
				
	}	

}
alert(k);
alert(t);
if(k>t)
{
alert("Assign Qty Cannot Greater Then Actual Qty");
return false;
}
return false;
}



  
</script>   