<?php
//echo $sql2="select * from vendorquotationdetails where quotation_no='".$_GET['qtid']."' ";
    error_reporting("E_ALL");
	$PageSecurity = 5;
	$PageName ='Quotation';	
	//include('includes/session.inc');
	$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; 
$RequisitionNo=$_REQUEST['RequisitionNo'];
$_SESSION['frmid']=$_REQUEST['frmid'];
///get form permissions///
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'], $_SESSION['ACGRoleId']);
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
$formId=$px->GetFormId('MR_SelectOSMaterialRequi.php');

?>
<link rel="stylesheet" href="css/jquery.ui.all.css" />
<script src="js/jquery-1.5.1.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>



<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>
<script language="javascript" type="text/javascript">
function open_items()
{
	window.open("VenderQutation_TermCondition.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&RequisitionNo=<?php  echo $_REQUEST['RequisitionNo'];?>&vendorresult=1","item_popup_window","height=500,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function generate_reqno(str)
{
	if (str.length==0)
  {
  document.getElementById("reqno").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("reqno").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_reqno.php?site="+str,true);
xmlhttp.send();
}
function check_approveqty(str,j)
{
	var req_qty=document.getElementById("req_qty_"+j).value;
	if(str>req_qty)
	{
		alert("Quantity to approve cannot be greater than requsition quantity");
		document.getElementById("app_qty_"+j).value='';
		document.getElementById("app_qty_"+j).focus();
		}
}

</script>
<?php
	$title = _('Vendor Quotation');
	//include('includes/header.inc');
	include('includes/SQL_CommonFunctions.inc');
	//include('includes/function_lib.php');
	
	$val=$_GET[RequisitionNo];
	$type="paging";
	$rowsPerPage = 10;
	$pageNum = 1;
	if(isset($_GET['page']))
	{
		$pageNum = $_GET['page'];
	}
	$offset = ($pageNum - 1) * $rowsPerPage;

	if(isset($_GET['qtid']) and $_GET['qtid']!="" and $_GET['readonly']==1)
	  { 
     echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
	 echo "<br/>";
	  echo "<br/>";
     $sql="select * from venderquotations INNER JOIN vendorquotationdetails 
			ON(venderquotations.id=vendorquotationdetails.quotation_no)
			WHERE venderquotations.id='".$_GET['qtid']."'";
	 $result=DB_query($sql, $db);
	 $myrow=DB_fetch_array($result);
	 
	 $requisition=$myrow['pr_no'];
	 $deliveryterms = $myrow['deliveryterms'];
	 $totalcharge = $myrow['totalcharge'];
	 $grand_total = $myrow['grand_total'];
	 $total_amt = $myrow['total_amt'];
	 $sql2 = "Select * from materialrequisitions where requisitionno = '".$requisition."' ";
	 $result2=DB_query($sql2, $db);
	 $myrow2=DB_fetch_array($result2);
	 $Reqno = $myrow2['Reqno'];
	 $reqdate = $myrow2['prdate'];
	?><table width="100%" border="0" cellpadding="5" align="center">
  <tr>
     <th><strong>SITE CODE </strong></th>
	 <td><?php echo $myrow['sitecode']; ?></td>
	 <th><strong>SITE NAME </strong></th>
	 <td><?php echo $myrow['site']; ?></td>

	 <th><strong>QUOTATION NUMBER </strong></th>
	 <td><?php echo $myrow['vernder_quotation']; ?></td>
	 <th><strong>QUOTATION DATE </strong></th>
	 <td><?php echo ConvertSQLDate($myrow['date1']); ?></td>
  	 
  </tr>
  <tr>
	 <th><strong>VENDOR CODE </strong></th>
	 <td><?php echo $myrow['vendercode']; ?></td>
	<th><strong>VENDOR NAME </strong></th>
	<td><?php echo $myrow['vendername']; ?></td>
	<th><strong>REQUISITION NUMBER </strong></th>
	<td><?php echo $Reqno; ?></td>
	<th><strong>REQUISITION DATE </strong></th>
	<td><?php echo ConvertSQLDate($reqdate); ?></td>
  </tr> 
  <tr>
	<th height="28"><strong>CATEGORY</strong></th>
	<td><?php echo $myrow['quotationcategory']; ?></td>
  
	<th><strong>BASIS</strong></th>
	<td><?php echo $myrow['basis'];?></td>
	<th><strong>VALID DATE </strong></th>
	<td><?php echo ConvertSQLDate($myrow['validtill']); ?></td>
	<th><strong>WARANTY DETAILS </strong></th>
	<td><?php echo $myrow['basis']; ?></td>
  </tr>
   <tr>
<?php 	
	 $Paymentsql = "Select termsindicator, terms from paymentterms where termsindicator = '".$myrow['payment_term']."' ";
	 $paymentresult=DB_query($Paymentsql, $db);
	 $Paymentmyrow=DB_fetch_array($paymentresult);
	 $payment_term = $Paymentmyrow['terms'];
	 
	 $Paymentmodsql = "Select paymentid, paymentname  from paymentmethods where paymentid = '".$myrow['payment_mode']."' ";
	 $paymentmodresult=DB_query($Paymentmodsql, $db);
	 $Paymentmymodrow=DB_fetch_array($paymentmodresult);
	 $payment_mod = $Paymentmymodrow['paymentname'];
	 
	 $Eventsql = "Select  event_id, event_desc  from events where event_id = '".$myrow['event']."' ";
	 $Eventresult=DB_query($Eventsql, $db);
	 $Eventrow=DB_fetch_array($Eventresult);
	 $Event_name = $Eventrow['event_desc'];
?>	 
   <th><strong>PAYMENT TERMS </strong></th>
   <td><?php echo $payment_term;?></td>
	 	  <th><strong>PAYMENT MODE </strong></th>
		  <td><?php echo $payment_mod; ?></td>
		  <th><strong>DELIVERY TERMS </strong></th>
		  <td><?php echo $deliveryterms; ?></td>
		  <th><strong>EVENT</strong></th>
		  <td><?php echo $Event_name; ?></td>
  </tr>
        
		  <tr>
		  <th><strong>REMARKS</strong></th>
		  <td colspan="7"><?php echo $myrow['remarks']; ?></td>

  </tr>
</table>
  <br />
<div style="overflow:auto; width:800; height:150px">
  <table width="100%" border="0">
   <tr>
    <th><strong>ITEM CODE</strong></th>
	<th><strong>ITEM Name</strong></th>
    <th><strong>ITEM DESCRIPTION </strong></th>
    <th><strong>ITEM NO.</strong></th>
	<th><strong>FLEXO/OFFSET</strong></th>
    <th><strong>OD</strong></th>
	<th><strong>MAKE</strong></th>
	<th><strong>GRADE</strong></th>
	<th><strong>COLOR</strong></th>
	<th><strong>SIZE</strong></th>
	<th><strong>GSM</strong></th>
	<th><strong>UNIT</strong></th>
    <th><strong>WIDTH</strong></th>
    <th><strong>LENGTH</strong></th>
    <th><strong>SERIAL NO. </strong></th>
    <th><strong>ORIGINAL/LOCAL</strong></th>
    <th><strong>TYPE</strong></th>
    <th><strong>SHADE</strong></th>
    <th><strong>RUNNING METER/ROLL</strong></th>
    <th><strong>VOLUME</strong></th>
    <th><strong>TEETH</strong></th>
    <th><strong>BCM</strong></th>
    <th><strong>UPS</strong></th>
    <th><strong>QUALITY</strong></th>
	<th><strong>QUANTITY</strong></th>
    <th><strong>RATE</strong></th>
	<th><strong>DISCOUNT TYPE</strong></th>
	<th><strong>DISCOUNT</strong></th>
	<th><strong>DISCOUNT AMOUNT</strong></th>
    <th><strong>SUB TOTAL </strong></th>
	 <th><strong>SPECIAL DISCOUNT </strong></th>
	<th><strong>SPECIAL DISCOUNT AMOUNT </strong></th>
	<th><strong>TOTAL AMOUNT</strong></th>
 

  </tr>
<?php 
 $sql2="select * from vendorquotationdetails where quotation_no='".$_GET['qtid']."' ";
  
  $result2=DB_query($sql2,$db);
  $i=1;
  while($myrow2=DB_fetch_array($result2))
     {
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
		
		$item_sql=DB_query("Select * from item_master where StockID='".$myrow2['prod_id']."'",$db);
		$item_row=DB_fetch_array($item_sql);
		
	 ?>
	  <tr  bgcolor="<?php echo $bg;?>"><td><?php echo $myrow2['prod_id']; ?>
	  
	  
	  
	  </td>
	  <td ><?php echo $item_row['item_name']; ?></td>
  	  <td><?php echo $item_row['item_desc']; ?></td>
  	  <td><?php echo $item_row['item_no']; ?></td>
   	  <td><?php echo $item_row['flexo_offset']; ?></td>
   	  <td><?php echo $item_row['od']; ?></td>
	   <td><?php 
	   $makename=$s->getField('product_manufacture','id',$myrow2['make'],'manufacturer');
	   echo $makename; ?></td>
	   <td><?php 
	   $gradename=$s->getField('product_grade','id',$myrow2['grade'],'grade');
	   echo $gradename; ?></td>
	   <td><?php 
	   $colorname=$s->getField('product_color','id',$myrow2['color'],'color');
	   echo $colorname; ?></td>
	   <td><?php 
	   $sizename=$s->getField('size_master','id',$myrow2['size'],'name');
	   echo $sizename;?></td>
	   <td><?php 
	   $gsmname=$s->getField('gsm','id',$myrow2['gsm'],'gsm');
	   echo $gsmname;?></td>
	   <td><?php echo $myrow2['uom']?></td>
   	  <td><?php echo $item_row['width']; ?></td>
   	  <td><?php echo $item_row['length']; ?></td>
   	  <td><?php echo $item_row['serial_no']; ?></td>
   	  <td><?php echo $item_row['orig_local']; ?></td>
   	  <td><?php echo $item_row['type_name']; ?></td>
   	  <td><?php echo $item_row['shade']; ?></td>
   	  <td><?php echo $item_row['running_roll']; ?></td>
   	  <td><?php echo $item_row['volume']; ?></td>
   	  <td><?php echo $item_row['teeth']; ?></td>
   	  <td><?php echo $item_row['bcm']; ?></td>
   	  <td><?php echo $item_row['ups']; ?></td>
   	  <td><?php echo $item_row['quality']; ?></td>
	   <td><input type="text" value="<?php echo $myrow2['quantity']; ?>" size="15" readonly /></td>
	   <td><input type="text" value="<?php echo $myrow2['rate']; ?>" size="15" readonly /></td>
	   <td><input type="text" value="<?php echo $myrow2['discount_type']; ?>" size="15" readonly /></td>
	   <td>
	   <?php
	   if($myrow2['discount_type']=="PercentAmt")
	     {$d= $myrow2['discount']."%";}
	   else {$d =$myrow2['discount'];}?>
	   <input type="text" value="<?php echo $d; ?>" size="15" readonly />
	   </td>	
	   <td><input type="text" value="<?php echo $myrow2['discount_amount']; ?>" size="15" readonly /></td> 
	   <td><input type="text" value="<?php echo $myrow2['sub_total']; ?>" size="15" readonly /></td>
    </tr>
	   <tr></tr>
	<?php $i++; } ?>
</table>
  <?php 
$SQL = "Select Inclusive, As_Per_Actual, charges_name, charges, charges_percentage FROM quotation_charge WHERE requisition_no='".$requisition."'  AND quatition_id
='".$_GET['qtid']."' ";
$charges_result = DB_query($SQL, $db);
?>
</div>
<table width="80%">
<tr><td valign="top">	
<table width="70%" border="0">
<tr><td colspan="5"><h2><strong>Charges Details</strong></h2></td></tr>
<tr>
<th><strong>DESCRIPTION</strong></th>
<th><strong>AS PER ACTUAL </strong></th>
<th><strong>AMOUNT</strong></th>
</tr>
<?php
			while($charges_result_row = DB_fetch_array($charges_result))
			{?>
				
						  <tr>
						  <th><strong><?php echo $charges_result_row['charges_name']; ?></strong></th>
						  <td><?php echo $charges_result_row['As_Per_Actual']; ?></td>
						  <td><?php echo $charges_result_row['charges']; ?></td>
						  </tr>
<?php 			
			}
			?>
</table>
</td>
<td valign="top">
<table width="100%" cellpadding="3">
			<tr>
			<th><strong>Basic Amount</strong></th>
			<td><?php echo $myrow['basic_amt'];?></td>
			</tr>
			<?php 
			$excise_sql="Select * from excise_tax where form_type='Purchase'";
			$excise_res=DB_query($excise_sql,$db);
			$m=1;
			while($excise_row=DB_fetch_array($excise_res))
			{
			$excise_tax_sql="Select ".$excise_row['label']." as value, ".$excise_row['label']."_perc as percentage from venderquotations where id='".$_GET['qtid']."'";
			$excise_tax_res=DB_query($excise_tax_sql,$db);
			$excise=DB_fetch_array($excise_tax_res);
			?>
			<tr>
			<th><strong><?php echo $excise_row['caption'];?></strong>
			<input type="hidden" name="caption_name[<?php echo $m;?>]" value="<?php echo $excise_row['caption'];?>" id="caption_name_<?php echo $m;?>" />
			<input type="hidden" name="label_name[<?php echo $m;?>]" value="<?php echo $excise_row['label'];?>" id="label_name_<?php echo $m;?>" /></th>
	        <td><input name="rate[<?php echo $m;?>]" type="text" id="rate[<?php echo $m;?>]" value="<?php echo $excise['percentage'];?>" size="3" readonly="TRUE"/>
	        % = 
	        <?php echo $excise['value'];?></td>
			</tr>
			<?php $m++;}?><input type="hidden" name="count_tax" id="count_tax" value="<?php echo $m;?>" />
			<tr>
			<th><strong>Taxable Amount </strong></th>
			<td><?php echo $myrow['taxable_amt'];?></td>
			</tr>
			<tr>
              <th><strong>Tax Name </strong></th>
			  <?php
				$Taxsql='select salestax_id,tax_code from sales_tax_master where salestax_id= "'.$myrow['taxname'].'"';
				$Taxresult=DB_query($Taxsql,$db);
				$TAX=DB_fetch_array($Taxresult);
     	?>
              <td><?php echo $TAX['tax_code'];?></td>
	    </tr>
			<tr>
			  <th><strong>Total Tax Amount </strong></th>
              <td><?php echo $myrow['tot_tax_amount'];?></td>
			</tr>
			<tr>
		  <th><strong>Surcharge</strong>
		    <input type="hidden" name="hidden_suroct" id="hidden_suroct" value="SUR" /></th>
			<td><?php echo $myrow['sur_oct_perc'];?> % </td>
			</tr>
			<tr>
			<th><strong>Surcharge Amount </strong></th>
			<td><?php echo $myrow['sur_oct_amt'];?></td>
			</tr>
			<tr>   
		<th><strong>Total Charges</strong></th>
		<td><?php echo $myrow['totalcharge'];?></td>
			</tr>
		<tr><th><strong>Grand Total</strong></th>
		<td><?php echo $myrow['grand_total'];?></td>
		</tr>
	  </table>  
</td>
</tr>
</table>
<br />
<br />
<?php 	
exit; 
  }
  /*
if(isset($_GET['qtid']) and $_GET['qtid']!="" and $_GET['update']==1 and !isset($_GET['delete']))  
{
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
	 if(isset($_POST['UpdateVendorQt']))
	   {
		  for($str=1;$str<$_REQUEST['count_tax'];$str++)
			{	
			$caption_val[$str] = $_REQUEST['caption_value'][$str];
			$percentage[$str] = $_REQUEST['rate'][$str];
			}
		  					
		echo   $sql = "UPDATE venderquotations SET 
									quotationcategory	='" . $_POST['QuotationCategory'] . "',
									basis				='" . $_POST['Basis'] . "',
									warramtydetails		='" . $_POST['WarrantyDetails'] . "',
									validtill			='" .  FormatDateForSQL($_POST['ValidTill']) . "',
									deliveryterms		='" . $_POST['DeliveryTerms'] . "',
									remarks				='" . $_POST['Remarks'] . "',
									payment_term		='" . $_POST['PaymentTerm'] . "',
									payment_mode		='" . $_POST['PayMode'] . "',
									party_no		='" . $_POST['party_no'] . "',
									party_date			='" .  FormatDateForSQL($_POST['party_date']) . "',
									event				='" . $_POST['Event'] . "',
									billingType			='" . $_POST['billingType'] . "',
									basic_amt			='" . $_POST['basic'] . "',
									Excise_Duty 		='" . $_POST['exciseDuty'] . "',
									ExcisePercentage	='" . $_POST['ExcisePercentage']."',
									Excise_Duty_value	='" . $_POST['exciseValue'] . "',
									Edu_Cess_perc		='" . $_POST['ECessPercentage'] . "',
									Edu_Cess			='" . $_POST['ECessValue'] . "',  
									SHE_Cess_perc		='" . $_POST['SAHCessPercentage'] . "',
									SHE_Cess			='" . $_POST['SAHCessValue'] . "',  
									taxable_amt			='" . $_POST['taxable_amt'] . "', 
									taxname				='" . $_POST['taxname'] . "',  
									taxvalue			='" . $_POST['taxvalue'] . "',  
									sur_oct				='" . $_POST['hidden_suroct'] . "',  
									sur_oct_perc		='" . $_POST['sur_oct_perc'] . "',  
									sur_oct_amt			='" . $_POST['sur_oct_amt'] . "',
									total_amt			='" . $_POST['Total'] . "',
									totalcharge			='" . $_POST['TotalCharge'] . "',
									pkg_charges			='" . $_POST['pkg_charges'] . "',  
								 	add_charges			='" . $_POST['add_charges'] . "',
								 	roundOff			='" . $_POST['roundOff'] . "',
									grand_total			='" . $_POST['GrandTotal'] . "',
									VenderQutation_TermCondition='" .$_SESSION['VenderQutation_TermCondition'] . "',									
									 WHERE id = '".$_GET['qtid']."'"; 
								//echo "<pre>";
								//print_r($sql); exit;

			$ErrMsg = _('The Vendor Quotation could not be updated because');
			$DbgMsg = _('The SQL that was used to update the supplier but failed was');
			$result = DB_query($sql, $db, $ErrMsg, $DbgMsg);
			
		   	for($i=1;$i<$_REQUEST['countcharges'];$i++)
			   {
				 $sql1="UPDATE quotation_charge SET 
								charges =  '".$_REQUEST['actual'][$i]."'
								WHERE quatition_id = '".$_REQUEST['qtid']."' and charges_name='".$_REQUEST['chargename'][$i]."'";
			$result1 =DB_query($sql1,$db);
			  //echo "<pre>";
			  //print_r($sql1);
			   }
			   //exit;
			 for($row=1; $row<$_REQUEST['count']; $row++)
			   {    //make='".$_POST['Make'][$row]."',
					 $sql2 = "UPDATE vendorquotationdetails SET 
					 						rate='".$_POST['Rate'][$row]."',
											discount_type='".$_POST['PerAmo'][$row] . "',
											discount='" . $_POST['Discount'][$row] . "',
											discount_amount='" . $_POST['perc'][$row] . "',
											
										
											specialdiscount='".$_POST['SpecialDiscount'][$row] . "',
											specialdiscount_amount='" . $_POST['Specialperc'][$row] . "',
											totalamount='" . $_POST['TotalSpecial'][$row] . "',							 	
												sub_total='" . $_POST['NetRate'][$row] . "'
										    WHERE quotation_no = '".$_GET['qtid']."'
											and prod_id='".$_REQUEST['ProductID'][$row]."' and make='".$_REQUEST['make'][$row]."'
											and color='".$_REQUEST['color'][$row]."' and grade='".$_REQUEST['grade'][$row]."' ";
					$result2 = DB_query($sql2,$db);	
											//echo "<pre>";
											//print_r($sql2);					
				}	
				//exit;
			unset($_POST['QutationEntryNo']);	
			unset($_POST['Date1']);
			unset($_POST['QuotationCategory']);
			unset($_POST['Basis']);
			unset($_POST['WarrantyDetails']);
			unset($_POST['ValidTill']);
			unset($_POST['DeliveryTerms']);
			unset($_POST['Remarks']);
			unset($_POST['PaymentTerm']);
			unset($_POST['PayMode']);
			unset($_POST['Event']);
			unset($_POST['Total']);
			unset($_POST['TWT']);
			unset($_POST['TotalCharge']);
			unset($_POST['GrandTotal']);
			unset($_GET['qtid']);
		   prnMsg(_('The Vendor Quotation record for') . ' ' . $_GET['qtid'] . ' ' . _('has been updated'),'success');
		  
		   exit;						
	       }
    echo "<br/>";
	 
	 $sql="SELECT venderquotations.*, 
	 			  suppliers.Vendor_name, 
				  paymentterms.terms, 
				  events.event_desc 
				  FROM venderquotations INNER JOIN suppliers ON(venderquotations.vendercode=suppliers.vendor_code) 
	 			  INNER JOIN paymentterms ON(venderquotations.payment_term=paymentterms.termsindicator)
	 			  INNER JOIN events ON(venderquotations.event=events.event_id) WHERE venderquotations.id='".$_GET['qtid']."'";
	 
	 $result=DB_query($sql,$db);
	 $myrow=DB_fetch_array($result);
	 $updatevendor=$myrow['vendercode'];
	 //echo "<pre>";
	 //print_r($myrow);
	// echo "<br>***********************updating vendor quotation********************<br>";
	 echo '<form name="VendorResult" action="' . $_SERVER['PHP_SELF'] . '?qtid='.$_GET[qtid].'&update=1' . SID . '" method=post>';
     ?>
<table width="100%" border="0">
<tr>
<td>
<table width="100%" border="0">
      <tr>
        <td><strong>Site Code:</strong></td>
        <td><?php echo $myrow['sitecode'];?>
        <input type="hidden" name="SiteCode" value="<?php echo $myrow['sitecode'];?>" /></td>
        <td><strong>Site Name:</strong></td>
        <td><?php echo $myrow['site'];?>
        <input type="hidden" name="SiteCode" value="<?php echo $myrow['sitecode'];?>" /></td>
        <td><strong>Quotation Date:</strong></td>
        <td><?php echo ConvertSQLDate($myrow['date1']);?></td>
      </tr>
      <tr>
        <td><strong>Vendor Code:</strong></td>
        <td><?php echo $myrow['vendercode'];?></td>
        <td><strong>Vendor Name:</strong></td>
        <td><?php echo $myrow['Vendor_name']?></td>
        <td><strong>Requisiton Date: </strong></td>
        <td><?php echo ConvertSQLDate($myrow['date2']);?></td>
      </tr>
      <tr>
        <td><strong>Quotation Category:</strong></td>
        <td><select name="QuotationCategory">
<option value="H.O. PURCHASE"<?php echo ($myrow['quotationcategory']=='H.O. PURCHASE'?'selected':'');?>>Head Office Purchase</option>
<option value="SERVEY BY H.O."<?php echo ($myrow['quotationcategory']=='SERVEY BY H.O.'?'selected':'');?>>Survey By Head Office</option>
<option value="SERVEY BY SITE" <?php echo ($myrow['quotationcategory']=='SERVEY BY SITE'?'selected':'');?>>Survey By site</option>
<option value="SITE PURCHASE" <?php echo ($myrow['quotationcategory']=='SITE PURCHASE'?'selected':'');?>>Site Purchase</option>
        </select></td>
        <td><strong>Basis:</strong></td>
        <td><select name="Basis">
          <option value="CREDIT" <?php echo($myrow['basis']=='CREDIT'?'selected':'')?>>CREDIT</option>
          <option value="CASH" <?php echo($myrow['basis']=='CASH'?'selected':'')?>>CASH</option>
        </select>        </td>
        <td><strong>Valid Till:</strong></td>
        <td><input type="text" name="ValidTill" size="12" value="<?php echo ConvertSQLDate($myrow['validtill']);?>" class="datepicker"/></td>
      </tr>
      <tr>
        <td><strong>Warranty Details:</strong></td>
        <td><input type="text" name="WarrantyDetails" size="30" value="<?php echo $myrow['warramtydetails'];?>" /></td>
        <td><strong>Pay Terms:</strong></td>
        <td><select name="PaymentTerm">
          <?php 
$sql1="SELECT paymentterms.terms,paymentterms.termsindicator FROM paymentterms WHERE termsindicator='".$myrow['payment_term']."'";
			$result1=DB_query($sql1, $db);
		    while($myrow1 = DB_fetch_array($result1))
		        { 
					$p='';
					if($_POST['PaymentTerm']==$myrow1['termsindicator'])
					$p="selected";
				?>
          <option value="<?php echo $myrow1['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow1['terms'];?></option>
          <?php } ?>
        </select></td>
        <td><strong>Payment Mode:</strong></td>
        <td><select name="PayMode">
          <?php 
		    $sql2="SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods";
			$result2=DB_query($sql2, $db);
		    while($myrow2 = DB_fetch_array($result2))
		        {?>
          <option value="<?php echo $myrow2['paymentid'];?>"<?php echo ($myrow['payment_mode']==$myrow2['paymentid']?'selected':'');?>><?php echo $myrow2['paymentname'];?></option>
          <?php 	} ?>
        </select></td>
      </tr>
      <tr>
        <td><strong>Delivery Terms:</strong></td>
        <td><input type="text" name="DeliveryTerms" size="30" value="<?php echo $myrow['deliveryterms'];?>" /></td>
        <td><strong>Remarks:</strong></td>
        <td><input type="text" name="Remarks" size="30"  value="<?php echo $myrow['remarks'];?>" /></td>
        <td><strong>Events:</strong></td>
        <td><select name="Event">
          <?php
				$result3=DB_query("SELECT event_id, event_desc FROM events",$db);
				while($myrow3 = DB_fetch_array($result3))
					{?>
          <option value="<?php echo $myrow3['event_id'];?>"<?php echo($myrow['event_desc']==$myrow3['event_id']?'selected':'')?>><?php echo $myrow3['event_desc'];?></option>
          <?php }?>
        </select></td>
      </tr>
    </table>
<p>&nbsp;</p>
 <fieldset><legend><h3><strong>Item Details</strong></h3></legend>
<div style="overflow:auto; width:800; height:150px">
<table border="0" width="100%" cellpadding="5">
          <tr>
            <th><strong>ITEM CODE </strong></th>
            <th><strong>ITEM NAME </strong></th>
            <th><strong>MAKE</strong></th>
            <th><strong>COLOR</strong></th>
            <th><strong>GRADE</strong></th>
			<th><strong>SIZE</strong></th>
			<th><strong>GSM</strong></th>
            <th><strong>UOM</strong></th>
			
			
	 <th><strong>ITEM DESCRIPTION </strong></th>
     <th><strong>ITEM NO.</strong></th>
	  <th><strong>FLEXO/OFFSET</strong></th>
      <th><strong>OD</strong></th>
      <th><strong>SERIAL NO. </strong></th>
      <th><strong>ORIGINAL/LOCAL</strong></th>
      <th><strong>TYPE </strong></th>
      <th><strong>SHADE</strong></th>
      <th><strong>RUNNING METER/ROLL</strong></th>
      <th><strong>VOLUME</strong></th>
      <th><strong>TEETH</strong></th>
      <th><strong>BCM</strong></th>
      <th><strong>UPS</strong></th>
      <th><strong>QUALITY</strong></th>
			
            <th><strong>QTY</strong></th>
            <th><strong>RATE</strong></th>
            <th><strong>DISCOUNT TYPE</strong></th>
            <th><strong>DISCOUNT</strong></th>
			<th><strong>DISCOUNT AMOUNT</strong></th>
            <th><strong>SUB TOTAL</strong></th>
         	 <th><strong>SPECIAL DISCOUNT </strong></th>
			<th><strong>SPECIAL DISCOUNT AMOUNT </strong></th>
			<th><strong>TOTAL AMOUNT</strong></th>


          </tr>
          <?php
	echo $sql4_mrq="SELECT * FROM vendorquotationdetails WHERE quotation_no='".$_GET[qtid]."'";
		  $ErrMsg="Requisition Details D'nt Exit";
		  $result4_req =DB_query($sql4_mrq,$db,$ErrMsg);
		  $i=1;
		  while($myrow4_req = DB_fetch_array($result4_req))
		  {
			if($i%2==0)
			{$bg="#CCCCCC";}
			else
			$bg="#C8BECB";	    
					$proid=$myrow4_req['prod_id'];
					$mst_productid=$myrow4_req['mst_productid'];
					$proname=$myrow4_req['prod_dec'];
					$make=$myrow4_req['make'];
					$color=$myrow4_req['color'];
					$grade=$myrow4_req['grade'];
					$uom=$myrow4_req['uom'];
					$quantity=$myrow4_req['quantity'];
					$rate=$myrow4_req['rate'];
					$dtype=$myrow4_req['discount_type'];
					$damount=$myrow4_req['discount'];
					$subtotal=$myrow4_req['sub_total'];
					$taxnameid=$myrow4_req['taxnameid'];
					$_REQUEST['taxvalue']=$myrow4_req['taxvalue'];
					$taxamount=$myrow4_req['taxamount'];
					$totalamountwithtax=$myrow4_req['totalamountwithtax'];
					$leadtime=$myrow4_req['lead_time'];
					$predelins=$myrow4_req['predel_ins'];
					$speci=$myrow4_req['specification'];
					$quantum=$myrow4_req['quantum'];
				
			$item_sql="Select * from item_master where StockID='".$proid."'";
			$item_result=DB_query($item_sql,$db);	
			$item_row=DB_fetch_array($item_result);
				?>
          <tr bgcolor="<?php echo $bg;?>">
            <td><?php echo $proid;?>
			
			   <input type="text" name="mst_productid[<?php echo $i;?>]"  value="<?php echo $item_row['id'];?>"   />
                <input type="hidden" name="ProductID[<?php echo $i;?>]" size="10" value="<?php echo $proid;?>" readonly /></td>
            <td><?php echo $proname;?>
                <input type="hidden" name="ProductDes[<?php echo $i;?>]" size="20" value="<?php echo $proname;?>" readonly /></td>
            <td><?php 
			$makename=$s->getField('product_manufacture','id',$myrow4_req['make'],'manufacturer');
			echo $makename; ?>
                <input type="hidden" name="make[<?php echo $i;?>]" value="<?php echo $myrow4_req['make'];?>" /></td>
            <td><?php 
			$colorname=$s->getField('product_color','id',$myrow4_req['color'],'color');
			echo $colorname;?>
                <input name="color[<?php echo $i;?>]" type="hidden" value="<?php echo $myrow4_req['color'];?>" /></td>
            <td><?php 
			$gradename=$s->getField('product_grade','id',$myrow4_req['grade'],'grade');
			echo $gradename;?>
                <input name="grade[<?php echo $i;?>]" type="hidden" value="<?php echo $myrow4_req['grade'];?>" /></td>
				<td><?php 
				$sizeename=$s->getField('size_master','id',$myrow4_req['size'],'name');
				echo $sizeename;?></td>
				<td><?php 
				$gsmname=$s->getField('gsm','id',$myrow4_req['gsm'],'gsm');
				echo $gsmname;?></td>
            <td><?php 
			$unitname=$s->getField('unitsofmeasure','unitid',$uom,'unitname');
			echo $unitname;?>
                <input type="hidden" name="uom[<?php  echo $i;?>]" size="5" value="<?php echo $uom;?>" readonly="readonly" /></td>
			<td><?php echo $item_row['item_desc'];?></td>
			<td><?php echo $item_row['item_no'];?></td>
			<td><?php echo $item_row['flexo_offset'];?></td>
			<td><?php echo $item_row['od'];?></td>
			<td><?php echo $item_row['serial_no'];?></td>
			<td><?php echo $item_row['orig_local'];?></td>
			<td><?php echo $item_row['type_name'];?></td>
			<td><?php echo $item_row['shade'];?></td>
			<td><?php echo $item_row['running_roll'];?></td>
			<td><?php echo $item_row['volume'];?></td>
			<td><?php echo $item_row['teeth'];?></td>
			<td><?php echo $item_row['bcm'];?></td>
			<td><?php echo $item_row['ups'];?></td>
			<td><?php echo $item_row['quality'];?></td>
			<td><?php echo $quantity;?><input type="hidden" name="Quantity[<?php echo$i;?>]" size="5" value="<?php echo $quantity;?>" id="Quantity_<?php echo $i;?>" />
            </td>
      <td><input type="text" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>" value="<?php echo $rate;?>" size="10" /></td>
            
			<td><select name="PerAmo[<?php echo $i;?>]" id="PerAmo_<?php echo $i;?>">
                <option value="Amount"<?php echo ($dtype=='Amount'?'selected':'')?>>Amount</option>
                <option value="PercentAmt"<?php echo ($dtype=='PercentAmt'?'selected':'')?>>Percent Amt</option>
              </select>            </td>
            <td><?php echo '<input type="text" name="Discount['.$i.']" id="Discount_'.$i.'" size="10" onblur="DiscountAmount(this.value,'.$i.')" value="'.$myrow4_req['discount'].'" />'; ?></td>
            <td><?php echo '<input type="text" name="perc['.$i.']" id="perc_'.$i.'" size="15" readonly="true" value="'.$myrow4_req['discount_amount'].'" />';?></td>
            <td><input type="text" id="NetRate_<?php echo $i;?>" name="NetRate[<?php echo $i;?>]" value="<?php echo $subtotal;?>" size="15" readonly/></td>
            <?php
				$Taxsql='select salestax_id,tax_code from sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
          </tr>
          <?php 
		$i++;
	     }?>
	  </table>
</div>
</fieldset>
<input type="hidden" name="count" id="count" value="<?php echo $i;?>" size="10" /></td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td valign="top">
<table border="0" width="60%">
<tr><td colspan="3"><h2><strong>Charges Details</strong></h2></td>
</tr>
      <tr>
        <th width="20%"><strong>DESCRIPTION</strong></th>
        <th><strong>AS PER</strong></th>
		<th><strong>AMOUNT</strong></th>
      </tr>
      <?php 
$ChargeSql="SELECT  As_Per_Actual,charges, charges_name,charges_percentage FROM quotation_charge WHERE quatition_id='".$_GET[qtid]."'";
			  $ChargeResult=DB_query($ChargeSql,$db);
		   $j=1;
		    while($ChargeMy=DB_fetch_array($ChargeResult))
		  {
		  ?>
      <tr>
 <th><strong><?php echo $ChargeMy['charges_name'];?><input type="hidden" name="chargename[<?php echo $j;?>]" value="<?php echo $ChargeMy['charges_name'];?>" /></strong></th>
        <td>
		<select name="AsPerActual[<?php echo $j;?>]" id="AsPerActual_<?php echo $j;?>" style="width:90px">
          <option value="Amount" <?php echo ($ChargeMy['As_Per_Actual']=='Amount'?'selected':'')?>>Amount</option>
        </select></td>
	<td><input name="actual[<?php echo $j;?>]" id="actual_<?php echo $j;?>" type="text" value="<?php echo $ChargeMy['charges'];?>" size="8"  >
	</td>
      </tr>
      <?php 	$j++;}	?>
    </table><input type="hidden" name="countcharges" id="countcharges" value="<?php echo $j;?>" />
</td>
<td>
<table width="80%" cellpadding="3" align="left">
			<tr>
			<th><strong>Basic Amount</strong></th>
			<td><input type="text" name="basic" id="basic" size="15" readonly onfocus="calc_basicamt()" value="<?php echo $myrow['basic_amt']?>"></td>
			</tr>
			<?php 
			$excise_sql="Select * from excise_tax where form_type='Purchase'";
			$excise_res=DB_query($excise_sql,$db);
			$m=1;
			while($excise_row=DB_fetch_array($excise_res))
			{
			$excise_tax_sql="Select ".$excise_row['label']." as value, ".$excise_row['label']."_perc as percentage from venderquotations where id='".$_GET['qtid']."'";
			$excise_tax_res=DB_query($excise_tax_sql,$db);
			$excise=DB_fetch_array($excise_tax_res);
			
			?>
			<tr>
			<th><strong><?php echo $excise_row['caption'];?></strong>
			<input type="hidden" name="caption_name[<?php echo $m;?>]" value="<?php echo $excise_row['caption'];?>" id="caption_name_<?php echo $m;?>" />
			<input type="hidden" name="label_name[<?php echo $m;?>]" value="<?php echo $excise_row['label'];?>" id="label_name_<?php echo $m;?>" /></th>
	<td><input name="rate[<?php echo $m;?>]" type="text" id="rate_<?php echo $m;?>" value="<?php echo $excise['percentage'];?>" size="3" />
%=  
  <input type="text" name="caption_value[<?php echo $m;?>]" id="caption_value_<?php echo $m;?>" value="<?php echo $excise['value']?>" size="15" onfocus="cal_<?php echo $excise_row['label'];?>(<?php echo $m;?>)" readonly/></td>
			</tr>
			<?php $m++;}?><input type="hidden" name="count_tax" id="count_tax" value="<?php echo $m;?>" />
			<tr>
			<th><strong>Taxable Amount </strong></th>
			<td><input type="text" name="taxable_amt" id="taxable_amt" value="<?php echo $myrow['taxable_amt'];?>" size="15" onfocus="calc_taxable_amount()" readonly/></td>
			</tr>
			<tr>
              <th><strong>Tax Name </strong></th>
			  <?php
				$Taxsql='select salestax_id,tax_code from sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td>
	<select id="taxname" name="taxname" onchange="tax_rate(this.value)" style="width:90px">
	<option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($myrow['taxname']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']; ?></option>
                  <?php } ?>
              </select></td>
			  </tr>
			<tr>
              <th><strong>Tax Rate </strong></th>
			  <?php
				$Taxsql='select salestax_id,tax_code from sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" onblur="AmountWithtax(this.value)" size="15" value="<?php echo $myrow['taxvalue'];?>" />
              </div></td>
			  </tr>
			<tr>
			  <th><strong>Total Tax Amount </strong></th>
    <td><input type="text" name="tot_tax_amount" id="tot_tax_amount" value="<?php echo $myrow['tot_tax_amount'];?>" size="15" onfocus="calc_tax_amount()" readonly/></td>
			</tr>
			<tr>
		  <th><strong>Surcharge</strong>
		    <input type="hidden" name="hidden_suroct" id="hidden_suroct" value="SUR" /></th>
			<td><input name="sur_oct_perc" type="text" id="sur_oct_perc" value="<?php echo $myrow['sur_oct_perc'];?>" size="15" onblur="cal_suroct(this.value)"/></td>
			 </tr>
			<tr>  
			<th><strong>Surcharge Amount </strong></th>
			<td><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $myrow['sur_oct_amt'];?>" size="15" readonly="true"/></td>
			</tr>
			<tr>
		<th>
		<input type="button" name="chargebutton" value="Total Charges" onclick="cal_totalcharge()"/></th>
		<td><input type="text" name="TotalCharge" id="TotalCharge" size="15" readonly="readonly" value="<?php echo $myrow['totalcharge'];?>"/></td>
		</tr>
		<tr><th>
		<input type="button" name="grandbutton" value="Grand Total" onclick="cal_grandtotal()"/> </th>
		<td><input type="text" name="GrandTotal" id="GrandTotal" size="15" readonly="readonly" value="<?php echo $myrow['grand_total'];?>"/>		</td>
		</tr>
			</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--onblur="FinalGrandTotal(this.value)"-->

<p><div class='centre'><input type='Submit' name='UpdateVendorQt' VALUE="Update Vendor Quotation" onclick="return checkcalc()"/>
	<?php 
	echo '<a href="'. $rootpath . '/index.php?' . SID . '">'. _('<input type="Submit" name="Cancel" VALUE="' . _('Cancel') . '">'). '</a><br>'; ?>
</div></form>
<?php 
  }
else if(isset($_GET['qtid']) and $_GET['qtid']!="" and $_GET['delete']==1 and !isset($_GET['update'])) 
  {
 
  
        $sql1='DELETE FROM venderquotations WHERE id='."'".$_GET['qtid']."'";
		$ErrMsg =  _('The Quotation could not be deleted because');
		$DbgMsg = _('The SQL statement used to delete the vendor Quotation header record, that failed was');
		$result1 = DB_query($sql1,$db,$ErrMsg,$DbgMsg);
		$sql2='DELETE FROM vendorquotationdetails WHERE quotation_no='."'".$_GET['qtid']."'";
		$ErrMsg =  _('The Requisition could not be deleted because');
		$DbgMsg = _('The SQL statement used to delete the Vendor Quotation header record, that failed was');
		$result2 = DB_query($sql2,$db,$ErrMsg,$DbgMsg);
		$sql3='DELETE FROM quotation_charge WHERE quatition_id='."'".$_GET['qtid']."'";
		$ErrMsg =  _('The Requisition could not be deleted because');
		$DbgMsg = _('The SQL statement used to delete the Vendor Quotation header record, that failed was');
		$result3 = DB_query($sql3,$db,$ErrMsg,$DbgMsg);
		prnMsg( _(' Quotation No '.$_GET['qtid'].' Code Has Deleted!'),'success');
		
		//echo '<a href="'. $rootpath . '/VenderQutations.php?' . SID . '">'. _('Back to Quotation List'). '</a><br>';
		header("Location:index.php?route=VenderQutations&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");
  }
 

function getTaxInformation($supplierid){
global $db;

	$sql="select taxauthorities.taxid, taxauthorities.description, taxgrouptaxes.*,suppliers.supplierid from suppliers
INNER JOIN taxgroups on taxgroups.taxgroupid = suppliers.taxgroupid
INNER JOIN taxgrouptaxes on taxgrouptaxes.taxgroupid = taxgroups.taxgroupid
INNER JOIN taxauthorities on taxauthorities.taxid = taxgrouptaxes.taxauthid
where suppliers.supplierid='$supplierid' ";
	  $result =DB_query($sql,$db);
	  $i=0;
	
	while($myrow = DB_fetch_row($result))
	{
	   $TaxID[$i] = $myrow[0];
		$TaxDesc[$i] = $myrow[1];
		$TaxGroupId[$i] = $myrow[2];
		$CalculationOrder[$i] = $myrow[4];
		echo '<tr><td align="right" style="text-align:right;" width="38%" >'.$TaxDesc[$i].'</td><td>
		<input type="text" name="tax_qty['.$i.']" id="'.$TaxDesc[$i].'" size="6" onblur="TaxAmount(this.value,\''.$TaxDesc[$i].'\')">
		<input type="hidden" name="taxDescName_['.$i.']" value="'.$TaxID[$i].'"> %=
		 
		 <input type="text" name="tax_percentage_['.$i.']" size="5" value="" id="tax_'.$TaxDesc[$i].'" readonly>
		 <input type="hidden" name="counttax" size="5" value="'.$i.'" >';
		echo '</td></tr>';
		$i++;
	}
	return $suplierData;
}

function getTaxInformationUpdate($supplierid,$quotationid){
global $db;

	 $sql="select taxauthorities.taxid, taxauthorities.description, taxgrouptaxes.*,suppliers.supplierid from suppliers
INNER JOIN taxgroups on taxgroups.taxgroupid = suppliers.taxgroupid
INNER JOIN taxgrouptaxes on taxgrouptaxes.taxgroupid = taxgroups.taxgroupid
INNER JOIN taxauthorities on taxauthorities.taxid = taxgrouptaxes.taxauthid
where suppliers.supplierid='$supplierid' ";
	  $result =DB_query($sql,$db);
	  $i=0;
	
	while($myrow = DB_fetch_row($result))
	{
	    $TaxID[$i] = $myrow[0];
		$TaxDesc[$i] = $myrow[1];
		$TaxGroupId[$i] = $myrow[2];
		$CalculationOrder[$i] = $myrow[4];
	    $AmtSql="SELECT Tax_percentage, Tax_amount FROM quotationtaxwithcost WHERE quatition_id='".$quotationid."' and vendor_id='".$supplierid."' and Tax_name='".$TaxID[$i]."'";
		$AmtResult=DB_query($AmtSql,$db);
		$AmtMyrow=DB_fetch_array($AmtResult);
		echo '<tr><td align="right" style="text-align:right;" width="38%" >'.$TaxDesc[$i].'</td><td>
		<input type="text" name="tax_qty['.$i.']" id="'.$TaxDesc[$i].'" size="6" onblur="TaxAmount(this.value,\''.$TaxDesc[$i].'\')" value="'.$AmtMyrow['Tax_percentage'].'">
		<input type="hidden" name="taxDescName_['.$i.']" value="'.$TaxID[$i].'"> %=
		 
		 <input type="text" name="tax_percentage_['.$i.']" size="5" value="'.$AmtMyrow['Tax_amount'].'" id="tax_'.$TaxDesc[$i].'" readonly>
		 <input type="hidden" name="counttax" size="5" value="'.$i.'" >';
		echo '</td></tr>';
		$i++;
	}
	return $suplierData;
}
 */
if(isset($_POST['submit']))
{

$status=true;	
$msgerr='';
if($_REQUEST['QuotationCategory'] == '000')	
{
	$msgerr[]='Please Select Quotation Category';
   $status=false;	
} 
if($_REQUEST['Basis']=='000')	
{
	$msgerr[]='Please Select Basis';
   $status=false;	
} 

if(empty($_REQUEST['WarrantyDetails']))	
{
	$msgerr[]='Please Enter Warranty Details';
   $status=false;	
} 
if($_REQUEST['PaymentTerm']=='000')	
{
	$msgerr[]='Please Select Payment Terms';
   $status=false;	
} 
if($_REQUEST['PayMode']=='000')	
{
	$msgerr[]='Please Select Payment Mode';
   $status=false;	
} 

if(empty($_REQUEST['DeliveryTerms']))	
{
	$msgerr[]='Please Enter Delivery Terms';
   $status=false;	
} 

if(empty($_REQUEST['Remarks']))	
{
	$msgerr[]='Please Select Remarks   ';
   $status=false;	
} 
if($_REQUEST['Event']=='000')	
{
	$msgerr[]='Please Select Event';
   $status=false;	
} 
	
	//echo "manvi";
	
	  $siteCode = $_POST['SiteCode'];
      $sql="select * from venderquotations where sitecode = '".$siteCode."'";
      
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
		 if($siteCode!='')
				$val1= substr($myrow['vernder_quotation'],0,18);
				$strChar1 = substr($myrow['vernder_quotation'],0,7);
				$strChar = $strChar1."/".$siteCode."/".$CurrentFinancialYear."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			$strChar = $Prefix_code."/".$siteCode."/".$CurrentFinancialYear."/";
		}
	  }
	  else
	  {
	  	$strChar = $Prefix_code."/".$siteCode."/".$CurrentFinancialYear."/";
	  }
	  
	 $strFinal = $maxval+1;
	 $strBothFinal = $strChar.str_pad($strFinal,4,"0",STR_PAD_LEFT);  
   
	   $sql="INSERT INTO venderquotations(mst_requisition_no,
	                           sitecode,
	                           site, 
	                          date1
	                          ,mst_supplierno,
	                           vendername, 
	                          vendercode
	                          ,date2,
	                           quotationcategory,
	                           basis,
	                           warramtydetails,
	                           validtill,
	                           deliveryterms,
	                            remarks, 
	                            payment_term,
	                            payment_mode,
	                            party_no,
	                            party_date,
	                            event,
	                            billingType
	                            ,total_amt,
								 sur_oct_amt,								
								 totalcharge,
								 pkg_charges,  
								 add_charges,
	                             grand_total,
								 delivery_by,
								 pr_no,
								 roundOff,
								 vernder_quotation,
								 VenderQutation_TermCondition,
								 delivery_date)
						VALUES('".$RequisitionNo."','".$_POST['SiteCode']."',
						       '".$_POST['Site']."',
							   '".FormatDateForSQL($_POST['Date1'])."',
							    '".$_POST['mst_supplierno']."',
							   '".$_POST['VenderName']."',
							   '".$_POST['VenderCode']."',
							   '".FormatDateForSQL($_POST['Date2'])."',
							   '".$_POST['QuotationCategory']."',
							   '".$_POST['Basis']."',
							   '".$_POST['WarrantyDetails']."',
							   '".FormatDateForSQL($_POST['ValidTill'])."',
							   '".$_POST['DeliveryTerms']."',
							   '".$_POST['Remarks']."',
							   '".$_POST['PaymentTerm']."',
							   '".$_POST['PayMode']."',
							   '" . $_POST['party_no'] . "',
							   '" .  FormatDateForSQL($_POST['party_date']) . "',
							   '".$_POST['Event']."', '".$_POST['billingType']."','".$_POST['total_item_amount']."', 
							   '".$_POST['sur_oct_amt']."',
							   '".$_POST['TotalCharge']."',
							   '".$_POST['pkg_charges']."',
							   '".$_POST['add_charges']."',
							   '".$_POST['GrandTotal']."',
							   '".$_SESSION[UserID]."',
							   '".$val."',
							   '".$_REQUEST['round_off']."',
							   '". $strBothFinal ."','".$_SESSION['VenderQutation_TermCondition']."','".FormatDateForSQL($_REQUEST['delivery_date'])."')"; 
    // echo "<pre>";

	  //print_r($sql);exit;
		  $ErrMsg = _('vendor Quotation Details is not Created');
		  $result =DB_query($sql,$db,$ErrMsg);			  					   
		 $lastquatationid=DB_Last_Insert_ID($db,'venderquotations','id');
		  if($lastquatationid!=" ") 
			{
				  $sql="select count(requsitionno) from requisitionorderdetails where requsitionno='".$val."'";
				  $result =DB_query($sql,$db);
				  $myrow = DB_fetch_row($result); 
				  $rows=$myrow[0];
				  for( $i=1; $i<=$rows; $i++){
				  
				  
				  if($_POST['Rate'][$i]!=''){
				 $sql="INSERT INTO vendorquotationdetails(quotation_no,
										 requisition_no,
										 prod_id,mst_productid,
										 prod_dec,
										 quantity,
										 rate,
										 discount_type,
										 discount,
										 discount_amount,
										 sub_total,
										 specialdiscount,
										 specialdiscount_amount,
										 totalamount,
										 lead_time,
										 predel_ins,
										 specification,
										 quantum,
										 make,
										 color,
										 grade,
										 size,
										 gsm,
										 uom,
										 basic_amt, 
										 tax_type,
	                                     Excise_Duty,
								         ExcisePercentage,
								         Excise_Duty_value,
								         Edu_Cess_perc,
								         Edu_Cess, 
								         SHE_Cess_perc, 
								         SHE_Cess,  
								         taxable_amt, 
								         taxname,  
								         taxvalue,								        
								  		 total_amount)
								VALUES('".$lastquatationid."',
									   '".$val."',
									   '".$_POST['ProductID'][$i]."', 
									   '".$_POST['mst_productid'][$i]."',
									   '".$_POST['ProductDes'][$i]."',
									   '".$_POST['Quantity'][$i]."',
									   '".$_POST['Rate'][$i]."',
									   '".$_POST['PerAmo'][$i]."',
									   '".$_POST['Discount'][$i]."',
									   '".$_POST['perc'][$i]."',
									   '".$_POST['NetRate'][$i]."',
									   '".$_POST['SpecialDiscount'][$i]."',
									   '".$_POST['Specialperc'][$i]."',
									   '".$_POST['TotalSpecial'][$i]."',
									   '".$_POST['LeadTime'][$i]."',
									   '".$_POST['PreIns'][$i]."',
									   '".$_POST['Specification'][$i]."',
									   '".$_POST['Quantum'][$i]."',
									   '".$_POST['Make'][$i]."',
									   '".$_POST['Color'][$i]."',
									   '".$_POST['Grade'][$i]."',
									   '".$_POST['size'][$i]."',
									   '".$_POST['gsm'][$i]."',
									   '".$_POST['UOM'][$i]."',
									    '".$_POST['basic'][$i]."',
									   '".$_POST['hid_billing_type'][$i]."',
							           '".$_POST['exciseDuty'][$i]."',
							           '".$_POST['ExcisePercentage'][$i]."',
							           '".$_POST['exciseValue'][$i]."',
							           '".$_POST['ECessPercentage'][$i]."',
							           '".$_POST['ECessValue'][$i]."',
							           '".$_POST['SAHCessPercentage'][$i]."',
							           '".$_POST['SAHCessValue'][$i]."',
							           '".$_POST['taxable_amt'][$i]."',
							           '".$_POST['taxname'][$i]."',
							           '".$_POST['taxvalue'][$i]."',
							           
							           '".$_POST['TotalSpecial'][$i]."')";
									  // echo "<pre>";
									   //print_r($sql); 
					 $ErrMsg = _('vendor Quotation Order Details is not Created');
					$result =DB_query($sql,$db,$ErrMsg);	
					}
			}
		  $countcharge = $_POST['countcharges'];
		 
		   for($P=1;$P<$countcharge;$P++)
		 {
		     $sql="INSERT INTO quotation_charge(vendor_id, 
														 As_Per_Actual, 
														 charges_name, 
														 charges,
														 requisition_no,
														 quatition_id)
														 VALUES('".$_POST['VenderCode']."',
														'".$_POST['AsPerActual_'.$P.'']."', 
														'".$_POST['desc_'.$P.'']."',
														'".$_POST['actual_'.$P.'']."',											 
														'".$val."',
														'".$lastquatationid."')"; 
					 $ErrMsg = _('vendor Quotation Order Details is not Created');
					$result =DB_query($sql,$db,$ErrMsg);	
		 }
		 
	 }
	 unset($_SESSION['VenderQutation_TermCondition']);
 $SuccessMsg = _('The Vendor Quotation Details have been successfully Inserted.') . ' ' . $lastquatationid;
echo "<script>location.href='index.php?route=MR_SelectOSMaterialRequi&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

/*if($_SESSION['UserStockLocation'])
{*/
if($_GET[RequisitionNo]!='' && $_GET['vendorsearch']==1)
   {if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
   		
   	
   
		echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;	
		 
			if(isset($_POST['SearchOrders']))
			  {
			     
					
			      if(isset($_POST['VendorCodeSearch']) && $_POST['VendorNameSearch']=='' )
				    {
					    $sql="SELECT vendor_code,  vendor_name FROM suppliers WHERE vendor_code = '".$_POST['VendorCodeSearch']."'";
					}
					//echo $_POST['VendorNameSearch'];exit;
				 else  if($_POST['VendorNameSearch']!='' && $_POST['VendorCodeSearch']=='' )	
				    {
					//echo $_POST['VendorNameSearch'];exit;
					   $sql="SELECT vendor_code,  vendor_name FROM suppliers WHERE vendor_name like '".$_POST['VendorNameSearch']."%'";
					
}
           else  if($_POST['VendorNameSearch']!='' && $_POST['VendorCodeSearch']!='' )	
				    {
					//echo $_POST['VendorNameSearch'];exit;
					   $sql="SELECT vendor_code,  vendor_name FROM suppliers WHERE vendor_name = '".$_POST['VendorNameSearch']."' or vendor_code = '".$_POST['VendorCodeSearch']."'";
					
                    }
				   else  
				    {
					     $sql="SELECT vendor_code,  vendor_name FROM suppliers";
					}	
								 	 
				// echo $sql;
				  //// search table after searching for vendor////
				  echo '<form name="VendorResult" action="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo='.$_GET[RequisitionNo].'&vendorresult=1' . SID . '" method=post>';
				  echo '<table cellpadding=2 colspan=7 BORDER=2>';
				  $TableHeader = 	'<tr><th>' . _('Vendor Code') . '</th>
						<th>' . _('Vendor Name') . '</th>
						</tr>';
				  echo $TableHeader;
				  $j = 1;
				  $k=0; //row colour counter
				  $i = 1;
				   $result=DB_query($sql,$db);
				  while ($myrow=DB_fetch_array($result))
				  {
				 
				    if ($k==1){
						echo '<tr class="EvenTableRows">';
						$k=0;
					} else {
						echo '<tr class="OddTableRows">';
						$k=1;
					}
				    echo '<td><input type="submit" name="VendorCode" value="'.$myrow['vendor_code'].'" onclick="fillUpValueFromVendor(this.value);">
					</td>
					<td>'.$myrow['vendor_name'].'</td></tr>';
					$i++;
				  }
				echo '</table>';	
				echo '</form>';
				exit;
			  }
			
			
			echo '<form name="VendorSearch" action="index.php?route=VenderQutations&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'&RequisitionNo='.$_GET[RequisitionNo].'&vendorsearch=1' . SID . '" method=post>';
			
			echo '<div class="centre"><strong>'._('Vendor Code') . ': </strong><input type=text id="VendorCodeSearch" name="VendorCodeSearch" MAXLENGTH =10 size=11/><input type="button" name="popup" value="+" id="popup" onclick="openPopUp(this.id)" />';
			echo '&nbsp;&nbsp; <strong>' 
			. _('Vendor Name') . ':</strong><input name="VendorNameSearch" id="VendorNameSearch" type="text" MAXLENGTH =10 size=30 >
			 <br> <br> <input type=submit name="SearchOrders" VALUE="' . _('Search Vendor') . '" onclick="return valid()"></div>';
			echo '</form>';
				
			$SQL='SELECT categoryid, categorydescription FROM stockcategory ORDER BY categorydescription';
			$result1 = DB_query($SQL,$db);
     }
else if(isset($_POST['VendorCode'])) //echo "Data will display After compare";
{
   
     
      
		   $VendorCode = $_POST['VendorCode'];
		  $sql="SELECT id,vendor_code , vendor_name FROM suppliers WHERE vendor_code='".$VendorCode."'";
		  $result=DB_query($sql,$db);
		  $vendor=DB_fetch_array($result);
		  $VendorName = $vendor['vendor_name'];
		  $mst_supplierno= $vendor['id'];
		  $check=DB_query("SELECT * FROM venderquotations WHERE mst_requisition_no='".$_REQUEST['RequisitionNo']."' and mst_supplierno='".$mst_supplierno."'",$db);
		  $numcheck=DB_num_rows($check);
		   $sql1 = "SELECT materialrequisitions.Reqno,materialrequisitions.prdate FROM materialrequisitions WHERE requisitionno='".$_REQUEST['RequisitionNo']."' and status='1'";
		  $ReqResult= DB_query($sql1,$db);
		  $result1 = DB_fetch_array($ReqResult);
		 
		  $Reqno = $result1['Reqno'];
		  $ReqDate = $result1['prdate'];
	  
	  
	   if($_GET[RequisitionNo]!='')
		   { 
			echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
			echo "<br/>";
			 $reqno=$_GET['RequisitionNo'];
			
			 echo "<form name='VenderQuotation' action='' method='post' >";
			 
			 
if(isset($msgerr ) && count($msgerr)>0)
 {
 echo '<div class="error"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr>';

  for($kp=0,$j=0;$kp<count($msgerr);$kp++)
  {
     if($j%4==0){
	   echo " </tr><tr><td>";
	   $j=0;
	 }
	
	echo '<td>'.$msgerr[$kp].'</td>';
	 $j++;
  }
  echo '</table></div>';
}
			?>
			 <table border="0" width="100%" cellpadding="2">
			 <tr>
			 <td><table width="100%" border="0" cellpadding="1" cellspacing="2" style="background-color: #FFFFFF; border: solid 1px #CCC">
			 <tr> <?php 
				 $sql="SELECT sitecode, requisition_site, prdate FROM materialrequisitions WHERE requisitionno='".$reqno."' and status='1'";
				  $result=DB_query($sql,$db);
				  $myrow = DB_fetch_array($result);
				  ?>
		<th width="15%"><strong>Site Code</strong></th>
		<td width="22%"><input type="text" name="SiteCode" value="<?php echo $myrow['sitecode'];?>" style="width: 100%"; readonly></td>
		<th width="14%"><strong>Site Name</strong></th>
		<td width="19%"><?php 
		$site_sql=DB_query("Select locationname from locations where loccode='".$myrow['sitecode']."'",$db);
		$site_row=DB_fetch_array($site_sql);
		?>
		  <input type="text" name="Site" value="<?php echo $site_row['locationname'];?>" style="width: 100%"; readonly></td>
		<th width="14%" nowrap="nowrap"><strong>Quotation Date / No.</strong></th>
		<td width="16%">
		  <input type="text" name="Date1" value="<?php echo date('d/m/Y');?>" style="width: 40%"; readonly>
		   <input type="text" name="vernder_quotation" value="Auto Generate" style="width: 55%"; readonly>
		  </td>
			</tr>
			 <tr>
			<th><strong>Vendor Code</strong></th>
			<td> 
			
			<input name="mst_supplierno" type="hidden" value="<?php  echo $mst_supplierno?>" />
			<input type="text" name="VenderCode" size="10" value="<?php echo $VendorCode;?>" style="width: 100%"; readonly></td>
			<th><strong>Vendor Name</strong></th>
			<td><input type="text" name="VenderName" size="10" value="<?php echo $VendorName;?>" style="width: 100%"; readonly></td>
			<th><strong>Basis</strong></th>
			<td><select name="Basis" id="Basis" onchange="getdata(this.value);">
			  <option value="000">---Select Basis---</option>
			  <option value="CREDIT"<?php echo ($_POST['Basis']=='CREDIT'?'selected':'');?>>CREDIT</option>
			  <option value="CASH"<?php echo ($_POST['Basis']=='CASH'?'selected':'');?>>CASH</option>
			  </select></td>
			 <tr>
				<th nowrap="nowrap"><strong>Requisition Number</strong></th>
				<td><input type="text" name="" size="10" value="<?php echo $Reqno;?>" style="width: 100%"; readonly></td>
			<th nowrap="nowrap"><strong>Requisition Date</strong></th>
<td><input type="text" name="Date2" size="10" value="<?php echo ConvertSQLDate($ReqDate);?>" style="width: 100%"; readonly>
	
</td>
<th>Delivery Date</th>
<td><input type="text" name="delivery_date" id="delivery_date"  style="width:100%;" class="datepicker"></td>
 </tr>
			  <tr>
			    <th ><strong>Pay Terms</strong></th>
			    <td><select name="PaymentTerm" id="PaymentTerm">
			      <option value="000">---Select Payment Terms---</option>
			      <?php 
			// $sql='SELECT suppliers.payterms, paymentterms.terms FROM suppliers 
//INNER JOIN paymentterms ON suppliers.payterms=paymentterms.termsindicator WHERE suppliers.supplierid="'.$VendorCode.'"';
				 	$sql="select * from paymentterms";
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($_POST['PaymentTerm']==$myrow['termsindicator'])
							$p="selected";
						?>
			      <option value="<?php echo $myrow['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow['terms'];?></option>
			      <?php } ?>
			      </select></td>
			    <th><strong>Payment Mode</strong></th>
			    <td><select name="PayMode" id="PayMode">
			      <option value="000">---Select Payment Mode---</option>
			      <?php 
					$sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($_POST['PayMode'] == $myrow['paymentid'])
							$p="selected";
						?>
			      <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
			      <?php 	} ?>
			      </select></td>
			      <th><strong>Remarks</strong></th>
<td><input type="text" name="Remarks" id="Remarks" size="25" value="<?php echo $_POST['Remarks'];?>" style="width: 100%";/></td>
            
			      <tr>
				<th nowrap="nowrap"><strong>Party Quotation Number</strong></th>
				<td><input type="text" name="party_no" size="10" value="<?php echo $party_no;?>" style="width: 100%"; ></td>
			<th nowrap="nowrap"><strong>Party Quotation Date</strong></th>
            <td><input type="text" name="party_date" id="party_date" size="10" value="<?php echo ConvertSQLDate($party_date);?>" class="datepicker" style="width: 100%"; readonly>
	
</td>
			    <td colspan="2"><div align="center"><input type="button" name="item_popup" value="Terms &amp; Conditions" id="item_popup"  onclick="open_items();" /></div></td>
			    
		      </tr>
				   </table>
				   <br />
				   <div align="center">
				   
				   <div style="overflow:auto; width:950px; height:auto; border: solid 1px #999999">
				   <table border="0"  cellpadding="2" cellspacing="2" style="border: solid 1px #999999; background-color:#CCCCCC">
				    <tr>
				   <th ><strong>Item Code</strong></th>
				   <th ><strong>Item Name</strong></th>
				   <th ><strong>Item No</strong></th>
				   <th ><strong>Make</strong></th>
				   <th ><strong>Color</strong></th>
				   <th ><strong>Grade</strong></th>
				   <th><strong>SIZE</strong></th>
				   <th ><strong>UOM</strong></th>
				   <th ><strong>Qty</strong></th>
				   <th ><strong>Rate</strong></th>
				   <th ><strong>Total Price</strong></th>
				   <th ><strong>Discount Percent</strong></th>
				   <th ><strong>Discount</strong></th>
				   <th ><strong>Discount Amount</strong></th>
				   <th ><strong>Sub Total</strong></th>
					<TH><strong>SPECIAL DISCOUNT</strong></TH>
					<TH><strong>SPECIAL DISCOUNT AMOUNT</strong></TH>
					<th ><strong>BASIC AMOUNT</strong></th>
					<th ><strong>Tax Type</strong></th>
					<th width="33%"><strong>Excise</strong></th>
					<th><strong>E-Cess</strong></th>
					
					<th><strong>SAH-E Cess</strong></th>
					
					<th><strong>Taxable Amount </strong></th>
					<th><strong>VAT/CST</strong></th>
					<th><strong>VAT/CST Amount</strong></th>
									
					<TH><strong>TOTAL AMOUNT</strong></TH>
					
 				   </tr>
				   <?php $prid=array();
				   $val=$_GET['RequisitionNo']; 
				    
		
				     $sql="SELECT  product_id, product_description,make,color,grade,size ,App_quantity,App_quantity1,app_qty_for_qtn, delivery_by FROM requisitionorderdetails WHERE requsitionno='".$val."' and status='Active' and App_quantity!='0.00' and app_status=0 ";
			
				  $ErrMsg="Requisition Details Don't Exist";
				  $result_req =DB_query($sql,$db,$ErrMsg);
				  $i=1;
				  while($myrow_req = DB_fetch_array($result_req))
				  {
						 	$proid=$myrow_req['product_id'];
							$proname=$myrow_req['product_description'];
							$make=$myrow_req['make'];
							$color=$myrow_req['color'];
							$grade=$myrow_req['grade'];
							$size=$myrow_req['size'];
							$uom=$unit_row['unitname'];
							
							if($myrow_req['App_quantity1']!='0' && $myrow_req['App_quantity1']!='')
							{$quantity=$myrow_req['App_quantity1'];}
							else
							{$quantity=$myrow_req['app_qty_for_qtn'];}
							$deliverby=$myrow_req['delivery_by'];
					
$rate_master="Select * from rate_master where ItemId='".$proid."' AND PartyId='".$VendorCode."' AND Category='Purchase'
AND DeActivate='0'";
$rate_result=DB_query($rate_master,$db);
$rate_row=DB_fetch_array($rate_result);
 ?>	
	<tr bgcolor="#FFFFFF">
	<td><input type="text" value="<?php echo $proid;?>" readonly="true"/>
	<input type="hidden" name="mst_productid[<?php echo $i;?>]"  value="<?php echo
	$s->GetFieldValue('item_master',"StockID='".$proid."'" ,'id'); ?>"   />
	<input type="hidden" name="ProductID[<?php echo $i;?>]" style="width: 100%" value="<?php echo $proid;?>" readonly></td>
	<td><?php echo $proname;?><input type="hidden" name="ProductDes[<?php echo $i;?>]" style="width: 100%"  value="<?php echo $proname;?>" readonly></td>
	<td><?php echo $myrow_req['item_no']; ?><input type="hidden" name="item_no[]" value="<?php echo $myrow_req['item_no']; ?>" /></td>
	<td> 
	<?php echo $makename=$s->getField('product_manufacture','id',$make,'manufacturer');?>
	<input type="hidden" Name="Make[<?php echo $i;?>]" value="<?php echo $makename;?>" readonly>
	</td>
	<td><?php 

	$colorname=$s->getField('product_color','id',$color,'color');
	echo $colorname;?><input type="hidden" Name="Color[<?php echo $i;?>]" value="<?php echo $color;?>" readonly>	</td>
	<td><?php 
	$gradename=$s->getField('product_grade','id',$grade,'grade');
	echo $gradename;?><input type="hidden" Name="Grade[<?php echo $i;?>]" value="<?php echo $grade;?>" readonly>	</td>
	<td><?php 
	$gradename1=$s->getField('size_master','id',$size,'name');
	echo $gradename1;?><input type="hidden" Name="size[<?php echo $i;?>]" value="<?php echo $size;?>" readonly>	</td>
	
	
	
	<td><?php 
		$unit=$s->getField('item_master','StockID',$proid,'unit');
		$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?><input type="hidden" name="UOM[<?php echo $i;?>]" style="width: 100%"  value="<?php echo $unit;?>" readonly></td>
            <?php $query =DB_query("select * from item_master", $db);
				$quer_row=DB_fetch_array($query);
			?> 
            <td><?php echo $quantity;?><input type="hidden" name="Quantity[<?php echo $i;?>]" id="Quantity_<?php echo $i;?>" style="width: 100%"  value="<?php echo $quantity;?>"
	/></td>
<td><input style="width:100%;"  type="text" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>"    value="<?php echo $rate_row['Rate'];?>"/></td>
		  
		  <td><input style="width:100%;" type="text" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="" onfocus="calculateTotalPrice(<?php echo $i;?>)" readonly="true"/></td>
		  
		  <td><select style="width:100%;" name="PerAmo[<?php echo $i;?>]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['PerAmo']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($_POST['PerAmo']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>

<td><?php echo '<input type="text" name="Discount['.$i.']" id="Discount_'.$i.'" onblur="DiscountAmount(this.value,'.$i.')" style="width:100%;" />';?>
</td>
<td><?php echo '<input type="text" name="perc['.$i.']" id="perc_'.$i.'"  readonly="true" style="width:100%;" onblur="checkamount(this.value,'.$i.')"/>';?></td>
<td><?php echo '<input type="text" id="NetRate_'.$i.'" name="NetRate['.$i.']" style="width:100%;" readonly/>';?></td>

 
<td><?php echo '<input type="text" name="SpecialDiscount['.$i.']" id="SpecialDiscount_'.$i.'" size="10" style="width:100%;" onblur="DiscountAmountspe(this.value,'.$i.')" />';?>
</td>
<td><?php echo '<input type="text" name="Specialperc['.$i.']" id="Specialperc_'.$i.'"  style="width:100%;" size="10" onblur="checkspecialamt(this.value,'.$i.')"/>';?></td>
<td><?php echo '<input type="text" id="basic_'.$i.'" name="basic['.$i.']" size="8" style="width:100%;" readonly/>';?></td>
<td><select name="hid_billing_type[<?php echo $i;?>]" style="width: 100%" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
	
</select></td>
<td><select name="exciseDuty[<?php echo $i;?>]" id="exciseDuty_<?php echo $i;?>" style="width:100%;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $i; ?>" style="width: 100px;">
  	      	<input name="ExcisePercentage[<?php echo $i;?>]" id="ExcisePercentage_<?php echo $i;?>" type="text" value=""  style="width:80%;" readonly /> 
  	      	<input name="exciseValue[<?php echo $i; ?>]" id="exciseValue_<?php echo $i; ?>" type="text" value="" style="width:70%;" onfocus="calculateExciseDuty(<?php echo $i; ?>)" /></div>
  	      </td><?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
  	      

<td><input name="ECessPercentage[<?php echo $i;?>]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:100%;" readonly /><input name="ECessValue[<?php echo $i; ?>]" id="ECessValue_<?php echo $i;?>" type="text" value="" size="25" style="width:100%;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>

<td><input name="SAHCessPercentage[<?php echo $i;?>]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:100%;" readonly/><input name="SAHCessValue[<?php echo $i;?>]" id="SAHCessValue_<?php echo $i;?>" type="text" value="" size="25" style="width:100%;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
<td><input type="text" name="taxable_amt[<?php echo $i;?>]" id="taxable_amt_<?php echo $i;?>" value="" style="width:100%;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
<?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td>
	<select id="taxname_<?php echo $i;?>" name="taxname[<?php echo $i;?>]" onchange="tax_rate(this.value,<?php echo $i; ?>)" style="width:100%;">
	<option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><div id="taxval_<?php echo $i; ?>">
                  <input type="text" name="taxvalue[<?php echo $i;?>]" id="taxvalue_<?php echo $i;?>" style="width:100%;" value="" readonly="true"/>
              </div>
<input type="hidden" name="hidden_suroct[<?php echo $i;?>]" id="hidden_suroct_<?php echo $i;?>" value="SUR" />
			</td>
			<td><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalSpecial[<?php echo $i;?>]" size="8" style="width:100%;" readonly  onfocus="cal_grandtotal(<?php echo $i;?>);"/></td>
</tr>
		<?php 		  $i++;
				 }	?>	  
			<input type="hidden" name="count" id="count" value="<?php echo $i;?>" size="10" /> 
			</table>
			</div>
			</div>
			<br />	
			<table width="40%" align="right">
			
			<tr><th>
		      <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
                </tr>
               
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges" id="packagingCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
				<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;" /></td>
				</tr>
				
                <tr>
                  <td><input type="button" name="grandbutton" value="Grand Total" onclick="cal_roundamt()"/></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" style="width:100%;" readonly="readonly" onfocus="cal_grandamount()" /></td>
                </tr>
              </table>
		     </th>
		<td>		</td>
		
		</tr>
				
			</table>
		</td>
		</tr>
		</table>		 
	<p align="center"><input type="Submit" name="submit" VALUE="Save" onclick="return checkvalid()">
	</form><!--onclick="return checkvalid()"-->
<?php 		} 
}	
 
include('includes/footer.inc');
?> 
<script type="text/javascript">
function calculateExciseDuty(i)
{
	
	var basic=document.getElementById("basic_"+i).value;
	
	var ExcisePercentage=document.getElementById("ExcisePercentage_"+i).value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue_"+i).value=exciseVal.toFixed(2);
}
function hid_billing_typecheck(i,str){

	//alert(str);
	//var type= document.getElementById("ExcisePercentage_"+i).value;
	if(str=='')
	{
		alert("Select Tax Type");
	}

}
function checkExcisable(str,i)
{
 	
	if(str=='NonExcisable')
	{
		document.getElementById("ExcisePercentage_"+i).disabled=true;
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		
		document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("exciseValue_"+i).value='';
		//document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		//document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
		document.getElementById("ExcisePercentage_"+i).value='';
	//	document.getElementById("taxvalue").disabled=true;
		//document.getElementById("sur_oct_perc").disabled=true;
		//document.getElementById("sur_oct_amt").disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("ECessPercentage_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;		
		document.getElementById("SAHCessPercentage_"+i).disabled=false;
	
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("sur_oct_perc_"+i).disabled=false;
		document.getElementById("sur_oct_amt_"+i).disabled=false;
		
		document.getElementById("TotalCharge_"+i).disabled=false;
		document.getElementById("packagingCharges_"+i).disabled=false;
		document.getElementById("additionalCharges_"+i).disabled=false;
		document.getElementById("roundOff_"+i).disabled=false;	
		
		
	}
	else{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=true;
		document.getElementById("taxvalue_"+i).disabled=true;
		document.getElementById("sur_oct_perc_"+i).disabled=true;
		document.getElementById("sur_oct_amt_"+i).disabled=true;
		document.getElementById("TotalCharge_"+i).disabled=true;
		document.getElementById("packagingCharges_"+i).disabled=true;
		document.getElementById("additionalCharges_"+i).disabled=true;
		document.getElementById("roundOff_"+i).disabled=true;

		document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("exciseValue_"+i).value='';
		document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
		document.getElementById("taxname_"+i).value='';
		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("sur_oct_perc_"+i).value='';
		document.getElementById("sur_oct_amt_"+i).value='';
		document.getElementById("TotalCharge_"+i).value='';
		document.getElementById("packagingCharges_"+i).value='';
		document.getElementById("additionalCharges_"+i).value='';
		document.getElementById("roundOff_"+i).value='';


	
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}
function calculateECess(i)
{
	
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessPercentage=document.getElementById("ECessPercentage_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue_"+i).value=total.toFixed(2);
}
function calculateSAHCess(i)
{
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage_"+i).value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue_"+i).value=total.toFixed(2);
}
function checkexiseflag(i)
{
	
if(document.getElementById("hid_billing_type_"+i).value=='')
	{
	alert("Must Select Tax Type");
	document.getElementById("hid_billing_type_"+i).focus();
	}	
	
}
function claculateExcise(i,str)
{
	if(str!='')
	{
	
	}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		var data=xmlhttp.responseText.split("__");
    			    		
    		if(data[0]==1)
    		{
    			
    	document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("exciseId_"+i).innerHTML=data[1];
    		}	
    		else 
    		{
         document.getElementById("ECessPercentage_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;
		document.getElementById("SAHCessPercentage_"+i).disabled=false;
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("exciseId_"+i).innerHTML=data[1];
    		}
    		}
  		}
		xmlhttp.open("GET","checkdata.php?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();	
		
	
	
	
}


function checkamount(str,i)
{
	
var k=parseFloat(document.getElementById("totalValue_"+i).value);

var t=parseFloat(str);
if(t>k)
{
alert("Discount Amount Not Greater Then Rate");
document.getElementById("Discount_"+i).value='';
document.getElementById("NetRate_"+i).value='';
document.getElementById("perc_"+i).value='';
document.getElementById("Discount_"+i).focus();	
}	
}
function checkspecialamt(str,i)
{
var k=parseFloat(document.getElementById("NetRate_"+i).value);

var t=parseFloat(str);
if(t>k)
{
alert("Special Discount Amount Not Greater Then Sub Total");
document.getElementById("SpecialDiscount_"+i).value='';
document.getElementById("Specialperc_"+i).value='';
document.getElementById("basic_"+i).value='';
document.getElementById("SpecialDiscount_"+i).focus();	
}		
	
	
	
	
}

function calculateTotalPrice(i)
{
 if(document.getElementById("Rate_"+i).value=='')
 {
 	alert("Must Enter Rate");
 	document.getElementById("Rate_"+i).focus();
 }	
 else
 {
	Quantity = document.getElementById("Quantity_"+i).value;
	Rate= document.getElementById("Rate_"+i).value;
	var Total=Quantity*Rate;
	document.getElementById("totalValue_"+i).value=Total.toFixed(2);
}
}


function calculateTaxable(i)
{
	var totalDiscountedPrice=document.getElementById("basic_"+i).value;
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessValue=document.getElementById("ECessValue_"+i).value;
	var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	//var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxable_amt_"+i).value=TOTAL.toFixed(2);
}




function calc_tax_amount()
{
	var taxable=document.getElementById("taxable_amt").value;
	var taxval=document.getElementById("taxvalue").value;
	var final=taxable*(taxval/100);
	document.getElementById("tot_tax_amount").value=final.toFixed(2);
}

function get_charge(str)
{
	document.getElementById("hidden_suroct").value=str
}

function cal_suroct(i,str)
{
	
	var total_tax=document.getElementById("taxvalue_"+i).value;
	
	var final_sur=total_tax*(str/100);
	document.getElementById("sur_oct_amt_"+i).value=final_sur.toFixed(2);
}
function tax_rate(str,i)
{

var billing_type=document.getElementById("hid_billing_type_"+i).value;

if(billing_type=='NonExcisable')
{
var taxableAmount=document.getElementById("basic_"+i).value;}
else if(billing_type=='Excisable')
{
var taxableAmount=document.getElementById("taxable_amt_"+i).value;}
//alert(taxableAmount);
if (str.length==0)
  {
  document.getElementById("taxval_"+i).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("taxval_"+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount+"&data="+i,true);
xmlhttp.send();
}
function getdata(str)
{
	
	if (str.length==0)
  		{
  			document.getElementById("PaymentTerm").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			document.getElementById("PaymentTerm").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","paytermsdata.php?site="+str,true);
		xmlhttp.send();
}
function checkvalid()
{
	var count = document.getElementById("count").value;
	if(document.getElementById("Basis").value == '000')
	{
		alert("Please Select Basis");
		document.getElementById("Basis").focus();
		return false;
	}
	if(document.getElementById("PaymentTerm").value == '000')
	{
		alert("Please Select Payment Term");
		document.getElementById("PaymentTerm").focus();
		return false;
	}
	if(document.getElementById("PayMode").value == '000')
	{
		alert("Please Select Pay Mode");
		document.getElementById("PayMode").focus();
		return false;
	}
	
	if(document.getElementById("party_date").value == '//')
	{
		alert("Please Select Party Date");
		document.getElementById("party_date").focus();
		return false;
	}
	if(document.getElementById("delivery_date").value == '')
	{
		alert("Please Select Delivery Date");
		document.getElementById("delivery_date").focus();
		return false;
	}
	
	for(var i=1; i<=count; i++)
	{
		if(document.getElementById("Rate_"+i).value == '')
		{
			alert("Please Enter Rate Of Item");
			document.getElementById("Rate_"+i).focus();
			return false;
		}
		
	}
	
	if(document.getElementById("total_item_amount").value=='')
	{
	alert("Check Total amount ");
	document.getElementById("total_item_amount").focus();
	return false;	
	}
	if(document.getElementById("GrandTotal").value=='')
	{
	alert("Check Grand amount ");
	document.getElementById("GrandTotal").focus();
	return false;	
	}
	
	
	//if(document.getElementById("Total") == '')
	//{
	//	alert("Please Press The Button Which Would calculate The Total Material Cost With Taxes");
	////	document.getElementById("Total").focus();
	//	return false;
	//}
	//for(var k=1; k<cnt_charge; k++)
	//{
	//	var inclusive = document.getElementById("Charge_"+k).value;
	//	var actual = document.getElementById("actual_"+k).value;
	////	var desc = document.getElementById("desc_"+k).value;
//		if(inclusive=='NO' && actual=='')
	//	{
		//	alert("Please Enter Some Value For "+desc+" Since It Is Not Inclusive");
		//	document.getElementById("actual_"+k).focus();
	//		return false;
	//	}
		
		
	//}
	//return false;
}
//////////////////////////////////////////////////Charges Details Some Hint By Amit Kumar /////////////////////////////////////////////
// As Per Actual- Amount = Amount                                                                                                    //
// As Per Actual- Amt    = Persent Amt                                                                                               //
// Total Charges Cost    = All Charges Amount Add                                                                                    //
// Grand Total           = Total Charges  + Material Cost With Taxes                                                                //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//function calc_basicamt()
//{
//	var total_basic=0;
//	var cnt=document.getElementById("count").value
//	for(var j=1;j<cnt;j++)
//	{
	//	var netrate=document.getElementById("TotalSpecial_"+j).value;
	//	if(netrate==''){netrate=0;}
//		total_basic=parseFloat(total_basic)+parseFloat(netrate);
//	}
//	document.getElementById("basic").value=total_basic.toFixed(2);
//}
function calc_totaltax()
{
	var total_tax=0;
	var cnt=document.getElementById("count").value
	for(var j=1;j<cnt;j++)
	{
		var taxamt=document.getElementById("totaltaxamount_"+j).value;
		total_tax=parseFloat(total_tax)+parseFloat(taxamt);
	}
	document.getElementById("total_tax").value=total_tax.toFixed(2);
}
function cal_totalcharge()
{
	var total=0;
	var count=document.getElementById("countcharges").value;
	for(var i=1; i<count;i++)
	{
		var actualamt=document.getElementById("actual_"+i).value;
		if(actualamt!='')
		{
		total=parseFloat(total)+parseFloat(actualamt);
		}
	}
	document.getElementById("TotalCharge").value=total.toFixed(2);
}

function cal_totalamount()
{
	
	var total=0;
var t=document.getElementById("count").value;

for(var i=1;i<t;i++)
{
var amt=parseFloat(document.getElementById("TotalSpecial_"+i).value);
total=parseFloat(total)+amt;	
}	
document.getElementById("total_item_amount").value=total.toFixed(2);	
}
function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges);
	if(roundOffVal==''){roundOffVal='-.0';}
	
	var test=roundOffVal.split(".");
	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=(parseFloat(grandtotal) + parseFloat(roundval)).toFixed(2);	
	 }
	
}

function cal_grandamount()
{
	
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges);
	if(roundOffVal==''){roundOffVal='-.0';}
	
	var test=roundOffVal.split(".");
	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
	
	
//document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	

}


function cal_grandtotal(i)
{
	var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	//alert(basic);
	var Totaltaxable=document.getElementById("taxable_amt_"+i).value;
	var vatcstAmt=document.getElementById("taxvalue_"+i).value;
	

	//var roundOffVal=document.getElementById("roundOff_").value;
	
	//if(roundOffVal==''){roundOffVal='-.0';}
	
	//var test=roundOffVal.split(".");
	
	//alert(test[0]);
	
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	if(vatcstAmt==''){vatcstAmt=0;}
	
	
	
	
	if(document.getElementById("hid_billing_type_"+i).value=='NonExcisable')
	{
	
		var grand_tot1=parseFloat(basic)+parseFloat(vatcstAmt);
		var grand_tot=grand_tot1.toFixed(2);
		
	}	
	
	
else if(document.getElementById("hid_billing_type_"+i).value=='IncludeTax'){

var grand_tot1= parseFloat(basic) ;
var grand_tot=grand_tot1.toFixed(2);
}
	else{
	
		var grand_tot1= parseFloat(Totaltaxable)+parseFloat(vatcstAmt);
			var grand_tot=grand_tot1.toFixed(2);
		
		 }
	  //alert(	document.getElementById("TotalSpecial_"+i).value);
	 	//alert(grand_tot);
	 	document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
		//alert(	document.getElementById("TotalSpecial_"+i).value);
	
}


function checkstatus(str)
{
	var Charge = document.getElementById("Charge_"+str).value;
	var actual = document.getElementById("actual_"+str).value;
	if(Charge == 'NO' && actual == '')
	{
		alert("Please Enter Some Value Since It Is Not Inclusive");
		return false;
	}
}
var TotalPercent=0;
var TotalAmnt=0;
var finalAmount=0;

function ChargeCalculater(Amt,Amtid)
  {
	 var AsPerActual=document.getElementById(Amtid).value;
	 var ActualType=document.getElementById("AsPerActual_" +Amtid).value;
	 
	 if(AsPerActual !='')
	 {
	 if(ActualType=='PercentAmt')
	   {
	     var Total= document.getElementById("Total").value;
		 var charge= parseFloat(Total) * parseFloat(AsPerActual)/100;
		 document.getElementById("actual_"+Amtid).value = charge;
		 TotalPercent= parseFloat(TotalPercent) + parseFloat(charge);
	   }
	 else
	   {
	     document.getElementById("actual_"+Amtid).value=AsPerActual; 
		 TotalAmnt=parseFloat(TotalAmnt) + parseFloat(AsPerActual);
	   }
	}
	return true;
  }
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
// Total Charges Cost    = All Charges Amount Add                                                    //
// Grand Total           = Total Charges  + Material Cost With Taxes                                 //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function FinalGrandTotal(A)
   {
	  var Total=document.getElementById("Total").value;
	  var FinalGT= parseFloat(Total) + parseFloat(A);
	  
	  /*if(A == '')
	  {*/
	  if(isNaN(FinalGT))
		{
		  document.getElementById("GrandTotal").value=parseFloat(Total);
		}
		else
		{
		  document.getElementById("GrandTotal").value=parseFloat(FinalGT);
		}
		  
   }
   
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
//As Per Requirment Inclusive Option Yes -> Hide As Per Actual                                       //
//As Per Requirment Inclusive Option NO ->  Show As Per Actual                                       //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function ChargeAmount(CA,ID)
 {
   if (CA=='NO')
     {
		document.getElementById(ID).disabled=false;
		document.getElementById("actual_"+ID).disabled=false;
		document.getElementById("AsPerActual_"+ID).disabled=false;
	 }
	else if (CA!='NO')
	 {
		document.getElementById(ID).disabled=true;
		document.getElementById("AsPerActual_"+ID).disabled=true; 
		document.getElementById("actual_"+ID).disabled=true;
		document.getElementById(ID).value='';
		document.getElementById("actual_"+ID).value='';
	 }    
  }
var Total=0;
 function DiscountAmount(DA,i)
{
	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var rate = document.getElementById("Rate_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var quantity = document.getElementById("Quantity_"+i).value;
	var totalPrice = quantity*rate;
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("Discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("NetRate_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	//return true;
}	

function DiscountAmountspe(DA,i)
{
	
	
	var total1=document.getElementById("NetRate_"+i).value;
	
	var discount1 = document.getElementById("SpecialDiscount_"+i).value;
	var Specialperc=document.getElementById("Specialperc_"+i).value;
	
	if(discount1=='' && Specialperc=='')
	{
		var total1=document.getElementById("NetRate_"+i).value;
		
		document.getElementById("basic_"+i).value=total1;
	
	}
	else
	{
		if(discount1=='' && Specialperc!='')
		{
			var elx=document.getElementById("Specialperc_"+i).value;
			var total1=document.getElementById("NetRate_"+i).value;
			
			var TotalAmount2 = total1-parseFloat(elx);
			
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
		else
		{
			var percent1 = total1 * parseFloat(discount1)/100;
			var TotalAmount2 = total1-parseFloat(percent1);
	
			document.getElementById("Specialperc_"+i).value=percent1.toFixed(2);
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
	
	}
}
 
</script>

<script>
 var TotalAmount=0;
function AmountWithtax(AWT, i ,j)
{
	//alert("manvi");
    var NetRate = document.getElementById("NetRate_"+i).value;
   	var TaxValue = document.getElementById("taxvalue_"+i).value;
	var TotalAmountWithTax = (parseFloat(NetRate) * parseFloat(TaxValue))/100;
	if(isNaN(TotalAmountWithTax)){
	document.getElementById("totaltaxamount_"+i).value=parseFloat(0);
	document.getElementById("TotalAmountWirhTaxAmount_"+i).value = NetRate;
	}else{
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	if(isNaN(TotalTaxAmount)){
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(0);
	}else{	
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(TotalTaxAmount) + parseFloat(NetRate);
	}
	}	
	TotalAmount=parseFloat(TotalAmount) + parseFloat(TotalCostWithTax);
		//document.getElementById("Total").value=TotalAmount;
	return true;
}
function totalGetvalue()
	{
		//alert("manvi");
		var amount=0; 
		var ob;
		var count = document.getElementById("count").value;
		for(i=1;i<count;i++)
		{
			ob=document.getElementById("TotalAmountWirhTaxAmount_"+i);
			if(ob.value!='')
			{
				amount +=parseFloat(ob.value);
			}
	    }
		document.getElementById("Total").value=amount;
	}
	function openPopUp(i)
{
	window.open("Search_Vendor.php?rowcount="+i,"Search_Vendor_window","height=425,width=400,toolbar=no,menubar=no,dependent=yes,resizable=yes,scrollbars=yes");
}
</script>
