<?php 
if($_REQUEST['Save']!='')
{
	$insert1="Insert into quotation set 
					site='".$_REQUEST['site1']."',    
					quotationNo='".$_REQUEST['quotationNo1']."',  
					quotationDate='".FormatDateForSQL($_REQUEST['quotationDate1'])."',  
					party='".$_REQUEST['party1']."',   
					quotationType='".$_REQUEST['quotationType1']."',  
					enquiryNo='".$_REQUEST['enquiryNo1']."',  
					source='".$_REQUEST['source1']."',  
					partyContact='".$_REQUEST['partyContact1']."',  
					validTill='".FormatDateForSQL($_REQUEST['validTill1'])."',  
					pack_forward='".$_REQUEST['pack_forward']."',  
					freight= '".$_REQUEST['freight']."', 
					payTerms='".$_REQUEST['payTerms']."',  
					salesTax='".$_REQUEST['salesTax']."',  
					Excise='".$_REQUEST['Excise']."',  
					insurance='".$_REQUEST['insurance']."',  
					basicAmount='".$_REQUEST['basicAmount']."',  
					totalDiscountedPrice='".$_REQUEST['totalDiscountedPrice']."',  
					exciseDuty='".$_REQUEST['exciseDuty']."',  
					exciseValue='".$_REQUEST['exciseValue']."',  
					ECessValue='".$_REQUEST['ECessValue']."',  
					SAHCessValue='".$_REQUEST['SAHCessValue']."',  
					taxableAmount='".$_REQUEST['taxableAmount']."',
					VatCst='".$_REQUEST['VatCst']."',  
					VatCstValue='".$_REQUEST['VatCstValue']."',  
					freightValue='".$_REQUEST['freightValue']."',  
					packagingCharges='".$_REQUEST['packagingCharges']."',  
					additionalCharges='".$_REQUEST['additionalCharges']."',  
					roundOff='".$_REQUEST['roundOff']."',  
					grandTotal='".$_REQUEST['grandTotal']."',  
					createdBy='".$_SESSION['UserID']."',  
					createdDate='".date('Y-m-d')."' ,
					CompanyId='".$_SESSION['ACGCompanyId']."'";
					
	$result1=DB_query($insert1,$db);
	
	$masterId=DB_Last_Insert_ID($db,'quotation','id');
	
	if($masterId!='')
	{
		for($cnt=0;$cnt<$_REQUEST['count'];$cnt++)
		{	
			$insert2="Insert into quotation_details set
						parentId='".$masterId."',  
						itemCode='".$_REQUEST['itemCode'][$cnt]."',  
						quantity='".$_REQUEST['quantity'][$cnt]."',   
						price='".$_REQUEST['price'][$cnt]."',
						PerUnits ='".$_REQUEST['PerUnits'][$cnt]."', 
						totalValue='".$_REQUEST['totalValue'][$cnt]."',  
						discountType='".$_REQUEST['discountType'][$cnt]."',  
						discount='".$_REQUEST['discount'][$cnt]."',  
						valueAfterDisc='".$_REQUEST['valueAfterDisc'][$cnt]."',  
						requisitionDate='".$_REQUEST['requisitionDate'][$cnt]."'  ";
			$result2=DB_query($insert2,$db);
		}
	}
echo "<script>location.href='index.php?route=quotation_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&action=view&Id=".$masterId."'</script>";
}
?>
<script language="JavaScript" type="text/javascript">
	function enquiryDetails(str)
	{
		var branch=document.getElementById("site").value;
		
		if (str.length==0)
  		{
  			document.getElementById("enquiryId").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("enquiryId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","showEnquiryDetails.php?party="+str+"&branch="+branch,true);
		xmlhttp.send();
	}
	function showEnqDetails(str)
	{
		if (str.length==0)
  		{
  			document.getElementById("enqdetailsId").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("enqdetailsId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","showEnquiryDetails.php?enquiryNo="+str,true);
		xmlhttp.send();
	}
function calculateDiscount(str,a)
{
	var discType=document.getElementById("discountType_"+a).value;
	var value=document.getElementById("totalValue_"+a).value;
	if(str==''){str=0;}
	if(discType=='A') 
	{
		var discount=str;
	}
	else
	if(discType=='P') 
	{
		var discount=value*(str/100);	
	}
	document.getElementById("valueAfterDisc_"+a).value=(parseFloat(value)-parseFloat(discount)).toFixed(2);
}
function calculateBasic()
{
	var totalBasic=0;
	var cnt=document.getElementById("count").value;
	for(var i=0;i<cnt;i++)
	{
		var totalValue=document.getElementById("totalValue_"+i).value;
		totalBasic=parseFloat(totalBasic)+parseFloat(totalValue);	
	}
	document.getElementById("basicAmount").value=totalBasic.toFixed(2);
}
function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("count").value;
	for(var i=0;i<cnt;i++)
	{
		var totaldisc=document.getElementById("valueAfterDisc_"+i).value;
		totalDiscounted=parseFloat(totalDiscounted)+parseFloat(totaldisc);	
	}
	document.getElementById("totalDiscountedPrice").value=totalDiscounted.toFixed(2);
}
function checkApplicable(str)
{
	for(var i=1; i<6;i++)
	{
		if(document.getElementById("menu"+i).value=='NA')
		{
			document.getElementById("remarks"+i).disabled=true;
			document.getElementById("value"+i).disabled=true;
		}
		else
		if(document.getElementById("menu"+i).value=='AS')
		{
			document.getElementById("remarks"+i).disabled=false;
			document.getElementById("value"+i).disabled=false;
		}
	}
}
function claculateExcise(str)
{
	var discounted=document.getElementById("totalDiscountedPrice").value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId").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("exciseId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?taxId="+str+"&discounted="+discounted,true);
		xmlhttp.send();
}
function calculateVATCST(str)
{
	var taxableAmount=document.getElementById("taxableAmount").value;
	if (str.length==0)
  		{
  			document.getElementById("VATId").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("VATId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?salesId="+str+"&taxable="+taxableAmount,true);
		xmlhttp.send();
}
function calculateECess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}
function calculateSAHCess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function calculateTaxable()
{
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}
function calculateGrand()
{
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	var d=document.getElementById("value2").value;
	var e=document.getElementById("value1").value;
	var f=document.getElementById("value4").value;
	
	
	if(b==''){b=0;}
	if(c==''){c=0;}
	if(d==''){d=0;}
	if(e==''){e=0;}
	if(f==''){f=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	
}
function getCode(str)
{
	if (str.length==0)
  {
  document.getElementById("CODE").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("CODE").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","codeGenerator.php?quotesite="+str,true);
xmlhttp.send();
}

function datavalidation()
{
if(document.frm1.site.value=='000')
{
alert("Must Select Branch Name");
document.frm1.site.focus();
return false;	
}
if(document.frm1.quotationNo.value=='')
{
alert("Must Enter Quotation Number");
document.frm1.quotationNo.focus();
return false;	
}		
if(document.frm1.quotationDate.value=='')
{
alert("Must Select Quotation Date");
document.frm1.quotationDate.focus();
return false;	
}	
if(document.frm1.party.value=='000')
{
alert("Must Select Party Name");
document.frm1.party.focus();
return false;	
}	
if(document.frm1.quotationType.value=='')
{
alert("Must Select Qutotaion Type");
document.frm1.quotationType.focus();
return false;	
}				
if(document.frm1.enquiryNo.value=='000')
{
alert("Must Enter Enquiry No");
document.frm1.enquiryNo.focus();
return false;	
}	

return false;	
	
}


</script>
<p><h2 align="center">Quote Offer To Customer</h2></p>
<form action="" method="post"  name="frm1">
<table width="80%" cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF" style="border:1px solid #CCC;" align="center">
	<table width="70%">	
	<?php if(count($msgErr)>0){?>
   <tr>
   <td colspan="4"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
   </tr>
   <?php } ?>
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th width="25%" nowrap="nowrap" scope="row"><strong>Branch</strong></th>
    <td width="25%" nowrap="nowrap">
    <select name="site" style="width:98%;" id="site" onchange="getCode(this.value)">
    <option value="000">Select</option>
    <?php 
    $site_sql=DB_query("Select prefix, loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
    while($site_row=DB_fetch_array($site_sql))
	{?>
		<option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
	<?php 	
	}
    ?>
    </select></td>
    <th width="25%"><strong>Quotation No.</strong></th>
    <td width="25%" id="CODE"><input name="quotationNo" type="text" value="<?php echo $_REQUEST['quotationNo'];?>" size="25"  style="width:98%;"/></td>
  </tr>
  <tr>
    <th scope="row"><strong>Date </strong></th>
    <td nowrap="nowrap"><input type="text" name="quotationDate" value="<?php if(isset($_REQUEST['quotationDate'])){echo $_REQUEST['quotationDate'];} else {echo date('d/m/Y');}?>" style="width:98%;" class="datepicker"/></td>
    <th nowrap="nowrap">Format</th>
    <td nowrap="nowrap"><select name="format" style="width:98%;">
      <option value="Standard">Standard</option>
    </select></td>
  </tr>
  <tr>
    <th nowrap="nowrap"><strong>Party Name</strong></th>
    <td nowrap="nowrap">
    <select name="party" style="width:98%;" onchange="enquiryDetails(this.value)">
      <option value="000">Select</option>
      <?php 
      $client_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') 
		and Zone in(".$_SESSION['AssignedSites'].") order by c_name",$db);
	  while($client_row=DB_fetch_array($client_sql))
	  {?>
	  	<option value="<?php echo $client_row['client_code'];?>"<?php echo($_REQUEST['party']==$client_row['client_code']?'selected':'')?>><?php echo $client_row['c_name'];?></option>
	  <?php 	
	  }
      ?>
    </select></td>
    <th scope="row"><strong>Type of Quotation</strong></th>
    <td><select name="quotationType" style="width:98%;">
      <option value="M"<?php echo($_REQUEST['quotationType']=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo($_REQUEST['quotationType']=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo($_REQUEST['quotationType']=='R'?'selected':'')?>>Retail</option>
    </select></td>
    </tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="4">
 
    <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
    <td colspan="2" valign="top"><div id="enquiryId">
    	<table width="100%" cellpadding="2" cellspacing="1" border="0">
        	<tr>
            <th nowrap="nowrap" width="50%"><strong>Against Enquiry</strong></th>
            <td nowrap="nowrap" width="50%">
            <select name="enquiryNo" style="width:98%;" onchange="showEnqDetails(this.value)">
              <option value="000">Select</option>
              <?php 
             $enq_sql=DB_query("Select id,enquiryNo from enquiry where party='".$_REQUEST['party']."' and site='".$_REQUEST['site']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($enq_row=DB_fetch_array($enq_sql))
			{?>
				<option value="<?php echo $enq_row['id'];?>"<?php echo($_REQUEST['enquiryNo']==$enq_row['id']?'selected':'')?>><?php echo $enq_row['enquiryNo'];?></option>	
			<?php 	
			}
            ?>
            </select></td>
   		 </tr>
         <tr>
            <th scope="row" rowspan="3"><strong>Address</strong></th>
            <td><input name="partyaddress1" type="text" value="<?php echo $_REQUEST['partyaddress1'];?>" size="25"  style="width:98%;"/></td>
            </tr>
            <tr>
            <td><input name="partyaddress2" type="text" value="<?php echo $_REQUEST['partyaddress2'];?>" size="25"  style="width:98%;"/></td>
            </tr>
            <tr>
            <td><input name="partyaddress3" type="text" value="<?php echo $_REQUEST['partyaddress3'];?>" size="25"  style="width:98%;"/></td>
            </tr>
     </table></div>
    </td>
    <td valign="top"><div id="enqdetailsId"><table width="100%" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <th width="50%" scope="row"><strong>Source Through </strong></th>
        <td width="50%">	
        <input name="source" type="text" value="<?php echo $_REQUEST['source'];?>" size="25"  style="width:98%;"/></td>
      </tr>
      <tr>
        <th scope="row"><strong>Contact Person</strong></th>
        <td><input type="text" name="partyContact" style="width: 98%" value="<?php echo $_REQUEST['partyContact'];?>" /></td>
      </tr>
      <tr>
        <th scope="row"><strong>Mobile No.</strong></th>
        <td><input name="ContactMobile" type="text" value="<?php echo $_REQUEST['ContactMobile'];?>" size="25" style="width:98%;"/></td>
      </tr>
    </table></div>
    <table border="0" width="100%"><tr><th width="50%">Valid Till</th><td width="50%"><input name="validTill" type="text" value="<?php if(isset($_REQUEST['validTill'])){echo $_REQUEST['validTill'];} else {echo date('d/m/Y');}?>" size="12" class="datepicker"  style="width:98%;"/></td></tr></table>	
    </td>
    </tr>
</table>

</td>
</tr>
</table>
</td>
</tr>
</table>

<p align="center"><input type="submit" name="Proceed" value="Proceed" /><b>(After filling all required details above)</b></p>
</form>

<form action="" method="post">
	
<input type="hidden" name="site1" value="<?php echo $_REQUEST['site'];?>" />
<input type="hidden" name="quotationNo1" value="<?php echo $_REQUEST['quotationNo'];?>" />
<input type="hidden" name="quotationDate1" value="<?php echo $_REQUEST['quotationDate'];?>" />
<input type="hidden" name="format1" value="<?php echo $_REQUEST['format'];?>" />
<input type="hidden" name="party1" value="<?php echo $_REQUEST['party'];?>" />
<input type="hidden" name="quotationType1" value="<?php echo $_REQUEST['quotationType'];?>" />
<input type="hidden" name="enquiryNo1" value="<?php echo $_REQUEST['enquiryNo'];?>" />
<input type="hidden" name="partyaddress11" value="<?php echo $_REQUEST['partyaddress1'];?>" />
<input type="hidden" name="partyaddress21" value="<?php echo $_REQUEST['partyaddress2'];?>" />
<input type="hidden" name="partyaddress31" value="<?php echo $_REQUEST['partyaddress3'];?>" />
<input type="hidden" name="source1" value="<?php echo $_REQUEST['source'];?>" />
<input type="hidden" name="partyContact1" value="<?php echo $_REQUEST['partyContact'];?>" />
<input type="hidden" name="ContactMobile1" value="<?php echo $_REQUEST['ContactMobile'];?>" />
<input type="hidden" name="validTill1" value="<?php echo $_REQUEST['validTill'];?>" />

<table align="center" width="100%">
<tr><th style="text-align:center;" colspan="11">Item Details</th></tr>
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Discount Type</th>
<th>Discount</th>
<th>Discounted Price</th>
<th>Date Of Requisition</th>
</tr>
	<?php 
if($_REQUEST['Proceed']!='')
{
$details_sql=DB_query("Select * from enquiry_details where parentId='".$_REQUEST['enquiryNo']."'",$db);
$i=0;
while($details_row=DB_fetch_array($details_sql))
{
	$item_sql=DB_query("Select item_name, unit from item_master where StockID='".$details_row['itemCode']."'",$db);
	$item_row=DB_fetch_array($item_sql);
?>          
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['itemCode']?><input type="hidden" name="itemCode[<?php echo $i;?>]" value="<?php echo $details_row['itemCode']?>" id="itemCode_<?php echo $i;?>" /></td>
<td><?php echo $item_row['item_name']?></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName?></td>
<td><?php echo $details_row['quantity']?><input type="hidden" name="quantity[<?php echo $i;?>]" value="<?php echo $details_row['quantity']?>" id="quantity_<?php echo $i;?>" /></td>
<td><?php echo $details_row['price']?><input type="hidden" name="price[<?php echo $i;?>]" value="<?php echo $details_row['price']?>" id="price_<?php echo $i;?>" /></td>
<td><?php echo $details_row['pricePer']?><input type="hidden" name="PerUnits[<?php echo $i;?>]" id="PerUnits_<?php echo $i;?>" value="<?php echo $details_row['pricePer']?>" /></td>
<td><?php echo $details_row['totalValue']?><input type="hidden" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $details_row['totalValue']?>" /></td>
<td>
<select name="discountType[<?php echo $i;?>]" id="discountType_<?php echo $i;?>" style="width: 98%">
	<option value="A">Amount</option>
	<option value="P">Percent</option>
</select>
</td>
<td><input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" value="" size="15" onblur="calculateDiscount(this.value,<?php echo $i;?>)" /></td>
<td><input type="text" name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" value="" size="15"/></td>
<td><?php echo $details_row['requisitionDate']?><input type="hidden" name="requisitionDate[<?php echo $i;?>]" id="requisitionDate_<?php echo $i;?>" value="<?php echo $details_row['requisitionDate']?>" size="15"/></td>
</tr>
<?php  $i++;
}	
}
?>
<input type="hidden" name="count" id="count" value="<?php echo $i;?>" />
</table>
<br>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="50%">
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
	<tr>
    	<th style="text-align:center;" colspan="2">Terms And Conditions</th>
    </tr>
    <tr>
      <th width="19%" scope="row"><strong>Pkg &amp; Forwarding</strong></th>
      <td width="28%" nowrap="nowrap">
      <select name="pack_forward" id="menu1" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="PFRemarks" id="remarks1" value="" size="23%" style="width:48%;" />
      </td>
      </tr>
      <tr>
    <th width="25%" scope="row"><strong>Freight</strong></th>
    <td width="28%" nowrap="nowrap"><select name="freight" id="menu2" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="freightRemarks" id="remarks2" value="" size="23%" style="width:48%;" /></td>
    </tr>
  <tr>
    <th scope="row"><strong>Payment Terms</strong></th>
    <td><select name="payTerms" style="width: 98%">
      	<?php 
      	$payment_sql=DB_query("Select * from paymentterms",$db);
		while($payment_row=DB_fetch_array($payment_sql))
		{?>
			<option value="<?php echo $payment_row['termsindicator'];?>"><?php echo $payment_row['terms'];?></option>
		<?php 	
		}
      	?>
      </select></td>
    </tr>
    <tr>
    <th scope="row"><strong>Sales Tax</strong></th>
    <td nowrap="nowrap"><select name="salesTax" id="menu3" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="salesRemarks" id="remarks3" value="" size="23%"  style="width:48%;"/></td>
  </tr>
  <tr>
    <th>Excise</th>
    <td nowrap="nowrap"><select name="Excise" id="" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="exciseRemarks" id="" value="" size="23%" style="width:48%;" /></td>
    </tr>
    <tr>
    <th nowrap="nowrap">Insurance</th>
    <td nowrap="nowrap"><select name="insurance" id="menu4" style="width: 49%" onchange="checkApplicable(this.value)">
      	<option value="AS">As per calculation</option>
      	<option value="NA">N/A</option>
      </select><input type="text" name="insRemarks" id="remarks4" value="" size="23%"  style="width:48%;"/></td>
    </tr>
</table>	
</td>
<td valign="top">
<table width="95%" border="0" cellspacing="1" cellpadding="0" align="right" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
    		<tr>
    	<th style="text-align:center;" colspan="2">Amount And Taxes</th>
    </tr>
    <tr>
    	  <tr>
    	    <th width="14%">Basic Amount</th>
    	    <td width="31%"><input name="basicAmount" type="text" value="<?php echo $_REQUEST['basicAmount'];?>" size="25" style="width:98%;" onfocus="calculateBasic()" id="basicAmount" readonly /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th nowrap="nowrap">Discounted Price</th>
    	    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="" size="25" style="width:98%;"  readonly onfocus="calculateDiscounted()" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Excise</th>
    	    <td nowrap="nowrap">
    	    <select name="exciseDuty" style="width:98%;" onchange="claculateExcise(this.value)">
    	    <option value="0">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Sales'",$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"><input name="exciseValue" id="exciseValue" type="text" value="" size="25" style="width:98%;" /></div>
    	   </tr>
    	     
    	     <?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++;
			 } 
    	     ?>
    	     <tr>
    	    <th>E-Cess</th>
    	    <td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" size="25" style="width:20%;" readonly />
    	    	<input name="ECessValue" id="ECessValue" type="text" value="" size="25" style="width:75%;" readonly onfocus="calculateECess()"/></td>
    	    </tr>
    	    <tr>
            <th nowrap="nowrap">SAH-E Cess </th>
    	    <td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" size="25" style="width:20%;" readonly/>
    	    	<input name="SAHCessValue" id="SAHCessValue" type="text" value="" size="25" style="width:75%;" readonly onfocus="calculateSAHCess()"/></td>
  	    	</tr>
    	  
    	  
   <tr>
   	<th>Taxable Amount</th>
   	<td><input name="taxableAmount" id="taxableAmount" type="text" value="" size="25" style="width:98%;" onfocus="calculateTaxable()"/></td>
   </tr>
    	  
    	  
    	  
    	  <tr>
    	    <th>VAT/CST</th>
    	    <td nowrap="nowrap">
    	    <select name="VatCst" id="value3" style="width:98%;" onchange="calculateVATCST(this.value)">
    	    <option value="">Select</option>
    	    <?php 
    	    $salesSql=DB_query("Select * from sales_tax_master",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{?>
				<option value="<?php echo $salesRow['salestax_id'];?>"><?php echo $salesRow['tax_code'];?></option>
			<?php 	
			}
    	    ?>
  	      </select>
    	      <div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="" size="25" style="width:98%;" readonly /></div></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Freight</th>
    	    <td><input name="freightValue" id="value2" type="text" value="" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Pkg Charges</th>
    	    <td><input name="packagingCharges" id="value1" type="text" value="" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
  	    <tr>
    	    <th>Additional Charges</th>
    	    <td><input name="additionalCharges" id="value4" type="text" value="" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Round Off</th>
    	    <td><input name="roundOff" type="text" value="" size="25" style="width:98%;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Grand Total</th>
    	    <td><input name="grandTotal" id="grandTotal" type="text" value="" size="25" style="width:98%;" onfocus="calculateGrand()" readonly="readonly" /></td>
    	    
  	    </tr>
  	    </table>
</td>
</tr></table>
<p align="center"><input type="submit" name="Save" value="Save"  /></p>
</form>