<?php 

$year = $_SESSION['financialYearStart'];
$year_after=$_SESSION['financialYearEnd'];
$CurrentFinancialYear = $year.$year_after;  
if(isset($_POST['save']))
{
	
	
	 $siteCode = $_REQUEST['vendor_quotes_ammendment']['sitecode'];
      $sql="select * from vendor_quotes_ammendment 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,20);
				$strChar1 = substr($myrow['vernder_quotation'],0,9);
				$strChar = $strChar1."/".$siteCode."/".$CurrentFinancialYear."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			$strChar = "JJRS/AMDQT/".$siteCode."/".$CurrentFinancialYear."/";
		}
	  }
	  else
	  {
	  	$strChar = "JJRS/AMDQT/".$siteCode."/".$CurrentFinancialYear."/";
	  }
	  
	 $strFinal = $maxval+1;
	
	 $strBothFinal = $strChar.str_pad($strFinal,4,"0",STR_PAD_LEFT);  
	$rev_sql=DB_query("Select revision_no from vendor_quotes_ammendment where old_quotetion_no=".$_REQUEST['vendor_quotes_ammendment']['old_quotetion_no']." order by id desc limit 0,1",$db);
		 if(DB_num_rows($rev_sql)>0)
		 {
		 	$revision_row=DB_fetch_array($rev_sql);
			$old_rev=$revision_row['revision_no'];
			$new_rev=$old_rev+1;
		 }
		 else
		 {$new_rev=1;}
	
	//print_r($_REQUEST['vendor_quotes_ammendment']); exit;
		//print_r($_REQUEST); exit;
	        $requisition_date=FormatDateForSQL($_REQUEST['vendor_quotes_ammendment']['requisition_date']);
			$_REQUEST['vendor_quotes_ammendment']['requisition_date']=$requisition_date;
				$quotation_date=FormatDateForSQL($_REQUEST['vendor_quotes_ammendment']['quotation_date']);
			$_REQUEST['vendor_quotes_ammendment']['quotation_date']=$quotation_date;
				$party_quotation_date=FormatDateForSQL($_REQUEST['vendor_quotes_ammendment']['party_quotation_date']);
			$_REQUEST['vendor_quotes_ammendment']['party_quotation_date']=$party_quotation_date;
			$_REQUEST['vendor_quotes_ammendment']['revision_no']=$new_rev;
			$req_id=$_REQUEST['vendor_quotes_ammendment']['requisition_id'];
			$_REQUEST['vendor_quotes_ammendment']['vernder_quotation']=$strBothFinal;
			$_REQUEST['vendor_quotes_ammendment']['vat_cst_amount']=$_REQUEST['taxvalue'];
		
			extract($_REQUEST['vendor_quotes_ammendment']);
			
		if($s->RecordInsert('vendor_quotes_ammendment',$_REQUEST['vendor_quotes_ammendment']))
		{
			 $last_id=DB_Last_Insert_Id($db,"vendor_quotes_ammendment","id");
			// echo $last_id;
			// exit;
			for($i=0;$i<count($_REQUEST['item_id']);$i++)
			{			
			$item_code = htmlspecialchars($_REQUEST['item_code'][$i], ENT_QUOTES);
			$item_name = htmlspecialchars($_REQUEST['item_name'][$i], ENT_QUOTES);
			$insert_details=array('id'=>'',
						'vendor_quotes_ammendment_id'=>$last_id,
						'requisition_id'=>$req_id,
						'item_id'=>$_REQUEST['item_id'][$i],
						'item_code'=>$item_code,
						'item_name'=>$item_name,
						'item_no'=>$_REQUEST['item_no'][$i],
						'make'=>$_REQUEST['make'][$i],
						'color'=>$_REQUEST['color'][$i],
						'grade'=>$_REQUEST['grade'][$i],
						'uom'=>$_REQUEST['uom'][$i],
						'quantity'=>$_REQUEST['quantity'][$i],
						'rate'=>$_REQUEST['rate'][$i],
						'total_price'=>$_REQUEST['total_price'][$i],
						'discount'=>$_REQUEST['discount'][$i],
						'discount_per'=>$_REQUEST['discount_per'][$i],
						'discount_amount'=>$_REQUEST['discount_amount'][$i],
						'sub_total'=>$_REQUEST['sub_total'][$i],
						'specialdis_type'=>$_REQUEST['Perspc'][$i],
						'special_discount'=>$_REQUEST['special_discount'][$i],
						'special_discount_amount'=>$_REQUEST['special_discount_amount'][$i],
						'basic_amount'=>$_REQUEST['basic_amount'][$i],
						'tax_type'=>$_REQUEST['tax_type'][$i],
						'excise'=>$_REQUEST['excise'][$i],
						'excise_percentage'=>$_REQUEST['excise_percentage'][$i],
						'excise_value'=>$_REQUEST['excise_value'][$i],
						'ecess_per'=>$_REQUEST['ecess_per'][$i],
						'ecess_value'=>$_REQUEST['ecess_value'][$i],
						'sah_ecess_per'=>$_REQUEST['sah_ecess_per'][$i],
						'sah_ecess_value'=>$_REQUEST['sah_ecess_value'][$i],
						'taxable_amount'=>$_REQUEST['taxable_amount'][$i],
						'vat_cst'=>$_REQUEST['vat_cst'][$i],
						'vat_cst_amount'=>$_REQUEST['vat_cst_amount'][$i],
						'total_amount'=>$_REQUEST['total_amount'][$i]);
						
						
						if(!empty($insert_details['vendor_quotes_ammendment_id']))
					{
						$s->RecordInsert('vendor_quotes_ammendment_details',$insert_details);
					}
			}
				
				
				unset($_REQUEST['vendor_quotes_ammendment']);	
				//print_r($_REQUEST); exit;
				$_SESSION['success_msg']="Saved Successfully";	
				echo "<script>location.href='index.php?route=POModule/Vendor_Quotes_Ammendment_index1&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&tab=1&type=POModule/AVQ'</script>";
			}	
		
}
?>
<?php

	//echo $_REQUEST['VQuotesId'];
	if($_REQUEST['idfy_quotes']=='QUOT')
	{
		$identify="1";
		$recEdit=$s->GetRecordById('venderquotations','id='.$_REQUEST['VQuotesId']);

	$recEditrow=DB_fetch_array($recEdit);
	//echo "<pre>";
	//print_r($recEditrow);
	$sitecode=$recEditrow['sitecode'];
	$sitename=$recEditrow['site'];
	$quotation_date=$recEditrow['date1'];
	$vernder_quotation=$recEditrow['vernder_quotation'];
	$vendor_code=$recEditrow['vendercode'];
	$vendor_name=$recEditrow['vendername'];
	$mst_supplierno=$recEditrow['mst_supplierno'];
	$basis=$recEditrow['basis'];
	$requisition_id=$recEditrow['mst_requisition_no'];
	
	$reqno=$recEditrow['pr_no'];
	 $sql2 = "Select * from materialrequisitions where requisitionno = '".$reqno."' ";
	$result2=DB_query($sql2, $db);
	$myrow2=DB_fetch_array($result2);
	 
	$requisition_no=$myrow2['Reqno'];;
	$requisition_date= $myrow2['prdate'];
	$pay_terms=$recEditrow['payment_term'];
	$payment_mode=$recEditrow['payment_mode'];
	$party_quotation_no=$recEditrow['party_no'];
	$party_quotation_date=$recEditrow['party_date'];
	$total_amount=$recEditrow['total_amt'];
	$surcharge_per=$recEditrow['sur_oct_per'];
	$surcharge_amount=$recEditrow['sur_oct_amt'];
	$freight=$recEditrow['totalcharge'];
	$pkg_charges=$recEditrow['pkg_charges'];
	$pkg_per=$recEditrow['pkg_per'];
 	$vat_per=$recEditrow['vat_cst_per'];
	$vat_amount=$recEditrow['vat_cst_amount'];
	$additional_charges=$recEditrow['add_charges'];
	$round_off=$recEditrow['roundOff'];
	$grand_total=$recEditrow['grand_total'];
	$VenderQutation_TermCondition=$recEditrow['VenderQutation_TermCondition'];
	}
	else
	{
		$identify="0";
		$recEdit=$s->GetRecordById('vendor_quotes_ammendment','id='.$_REQUEST['VQuotesId']);

	$recEditrow=DB_fetch_array($recEdit);
	//echo "<pre>";
	//print_r($recEditrow);
	$sitecode=$recEditrow['sitecode'];
	$sitename=$recEditrow['sitename'];
	$quotation_date=$recEditrow['quotation_date'];
	$vernder_quotation=$recEditrow['vernder_quotation'];
	$vendor_code=$recEditrow['vendor_code'];
	$vendor_name=$recEditrow['vendor_name'];
	$mst_supplierno=$recEditrow['mst_supplierno'];
	$basis=$recEditrow['basis'];
	$requisition_id=$recEditrow['requisition_id'];
	$requisition_no=$myrow2['requisition_no'];;
	$requisition_date= $myrow2['requisition_date'];
	$pay_terms=$recEditrow['pay_terms'];
	$payment_mode=$recEditrow['payment_mode'];
	$party_quotation_no=$recEditrow['party_quotation_no'];
	$party_quotation_date=$recEditrow['party_quotation_date'];
	$total_amount=$recEditrow['total_amount'];
	$surcharge_per=$recEditrow['sur_oct_per'];
	$surcharge_amount=$recEditrow['surcharge_amount'];
	$freight=$recEditrow['freight'];
	$pkg_charges=$recEditrow['pkg_charges'];
	$vat_per=$recEditrow['vat_cst_per'];
	$vat_amount=$recEditrow['vat_cst_amount'];
	$additional_charges=$recEditrow['additional_charges'];
	$round_off=$recEditrow['round_off'];
	$grand_total=$recEditrow['grand_total'];
	$VenderQutation_TermCondition=$recEditrow['VenderQutation_TermCondition'];
	
	}
	
	
?>
<style>
#trsizelabel
{ font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px; color:#000000;}

</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Vendor Quotation Ammendment</h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1"> <!--   can not delete $identify -->
  		<input type="hidden" name="vendor_quotes_ammendment[identify]" value="AMD" />
	<!--   can not delete $identify -->
  <input type="hidden" name="vendor_quotes_ammendment[old_quotetion_no]" value="<?php echo $_REQUEST['VQuotesId'];?>" />
   <input type="hidden" name="vendor_quotes_ammendment[old_identify]" value="<?php echo $_REQUEST['idfy_quotes'];?>" />
    <td id="trsizelabel" class="tabledata1" ><strong>Site Code</strong></td>
    <td><input type="text" name="vendor_quotes_ammendment[sitecode]" value="<?php echo $sitecode; ?>" id="sitecode" /></td>
    <td class="tabledata1" id="trsizelabel"><strong>Site Name</strong></td>
    <td><input type="text" name="vendor_quotes_ammendment[sitename]" value="<?php echo $sitename; ?>" id="sitename" /></td>
	<td class="tabledata1" id="trsizelabel"><strong>Quotation Date / No</strong></td>
	<td><input type="text" name="vendor_quotes_ammendment[quotation_date]" value="<?php echo date('d/m/Y');?>" size="12" readonly="true" />
	<input type="text" name="vendor_quotes_ammendment[vernder_quotation]" value="Auto Generate" size="13" readonly>
	</td>
<tr class="row1">
    <td class="tabledata1" id="trsizelabel"><strong>Vendor Code</strong></td>
    <td> <input type="hidden" name="vendor_quotes_ammendment[mst_supplierno]" value="<?php echo $mst_supplierno; ?>" />
	<input type="text" name="vendor_quotes_ammendment[vendor_code]" value="<?php echo $vendor_code; ?>" id="vendor_code" /></td>
    <td class="tabledata1" id="trsizelabel"><strong>Vendor Name</strong></td>
    <td><input type="text" name="vendor_quotes_ammendment[vendor_name]" value="<?php echo $vendor_name; ?>" id="vendor_name" /></td>
    <td class="tabledata1" id="trsizelabel"><strong>Basis</strong></td>
    <td><select name="vendor_quotes_ammendment[basis]" id="basis" style="width:80px;">
		<option value="">Select Basis </option>
		<option value="CREDIT"<?php echo ($basis=='CREDIT'?'selected':''); ?>>CREDIT</option>
		<option value="CASH"<?php echo ($basis=='CASH'?'selected':''); ?>>CASH</option>
	</select></td>
</tr>
<tr class="row1">
    <td class="tabledata1" id="trsizelabel"><strong>Requisition Number</strong></td>
    <td><input type="hidden" name="vendor_quotes_ammendment[requisition_id]" value="<?php echo $requisition_id; ?>" />
	<input type="text" name="vendor_quotes_ammendment[requisition_no]" value="<?php echo $requisition_no; ?>" id="requisition_no" readonly="true" /></td>
    <td class="tabledata1" id="trsizelabel"><strong>Requisition Date</strong></td>
    <td><input type="text" name="vendor_quotes_ammendment[requisition_date]" value="<?php echo ConvertSQLDate($requisition_date); ?>" id="requisition_date" readonly="true" /></td>
    <td class="tabledata1" id="trsizelabel"><strong>Remarks</strong></td>
    <td ><input type="text" name="vendor_quotes_ammendment[remarks]" value="<?php echo $remarks; ?>" id="remarks" /></td>
</tr>
<tr class="row1">
    <td class="tabledata1" id="trsizelabel"><strong>Pay Terms</strong></td>
    <td><select name="vendor_quotes_ammendment[pay_terms]" id="pay_terms" style="width:80px;">
		<option value="">Select Pay Terms </option>
		<?php
		$sqlpay_terms=DB_query("select * from paymentterms",$db);
		while($pay_terms_row=DB_fetch_array($sqlpay_terms))
		{
				$s='';
				if($pay_terms==$pay_terms_row['termsindicator'])
				$s="selected";
		?>
		 <option value="<?php echo $pay_terms_row['termsindicator'];?>" <?php echo $s;?>><?php echo $pay_terms_row['terms'];?></option>
		<?php } ?>
		</select></td>
    <td id="trsizelabel" class="tabledata1"><strong>Payment Mode</strong></td>
    <td><select name="vendor_quotes_ammendment[payment_mode]" id="payment_mode" style="width:80px;">
		<option value="">Select Payment Mode </option>
		<?php
		$sqlpayment_mode=DB_query("select * from paymentmethods",$db);
		while($payment_mode_row=DB_fetch_array($sqlpayment_mode))
		{
				$s='';
				if($payment_mode==$payment_mode_row['paymentid'])
				$s="selected";
		?>
		 <option value="<?php echo $payment_mode_row['paymentid'];?>" <?php echo $s;?>><?php echo $payment_mode_row['paymentname'];?></option>
		<?php } ?>
		</select></td>
		 <td id="trsizelabel" class="tabledata1"><strong>Party Quotation Number</strong></td>
    <td><input type="text" name="vendor_quotes_ammendment[party_quotation_no]" value="<?php echo $party_quotation_no; ?>" id="party_quotation_no" /></td>
    
  </tr>
<tr class="row1">
    <td id="trsizelabel" class="tabledata1"><strong>Party Quotation Date</strong></td>
    <td colspan="5"><input type="text" name="vendor_quotes_ammendment[party_quotation_date]" value="<?php echo ConvertSQLDate($party_quotation_date); ?>" id="party_quotation_date" class="datepicker" /></td>
  </tr>
<tr class="row1">
	<td class="tabledata1" colspan="6">
	<div style="overflow:auto; width:947px;">
<table singleSelect="true" cellpadding="3" cellspacing="0" border="1">
<tr class="row1">
	<!-- <td class="tabledata"><strong>&nbsp;</strong></th>-->
	 <td class="tabledata"><strong>Item Code</strong></td>
	 <td class="tabledata"><strong>Item Name</strong></td>		
	 <td class="tabledata"><strong>Item No</strong></td>
	 <td class="tabledata"><strong>Make</strong></td>
	 <td class="tabledata"><strong>Color</strong></td>
	 <td class="tabledata"><strong>Grade</strong></td>
	 <td class="tabledata"><strong>UOM</strong></td>
	 <td class="tabledata"><strong>Qty</strong></td>
	 <td class="tabledata"><strong>Rate</strong></td>
	 <td class="tabledata"><strong>Total Price</strong></td>
	 <td class="tabledata"><strong>Discount Percent</strong></td>
	 <td class="tabledata"><strong>Discount %</strong></td>
	 <td class="tabledata"><strong>Discount Amount</strong></td>
	 <td class="tabledata"><strong>Sub Total</strong></td>
	 <td class="tabledata"><strong>SPECIAL DISCOUNT Type</strong></td>
	 <td class="tabledata"><strong>Special <br />Discount<br />Per</strong></td>
	 <td class="tabledata"><strong>Special <br />Discount<br />Amount</strong></td>
	 <td class="tabledata"><strong>BASIC AMOUNT</strong></td>
	<th ><strong>Excise flag</strong></td>
	 <td class="tabledata"><strong>Excise</strong></td>
	 <td class="tabledata"><strong>E-Cess</strong></td>
	 <td class="tabledata"><strong>SAH-E Cess</strong></td>
	 <td class="tabledata"><strong>Excise Amount </strong></td>
	<!-- <td class="tabledata"><strong>VAT/CST</strong></td>
	
	 <td class="tabledata"><strong>VAT/CST Amount</strong></td>-->
	 <td class="tabledata"><strong>TOTAL AMOUNT</strong></td>
</tr>
		
		<?php 
		if($_REQUEST['idfy_quotes']=='QUOT')
		{
		//echo $_REQUEST['quotes'];
		//echo "select * from vendorquotationdetails where quotation_no='".$_REQUEST['VQuotesId']."'";
			$sql_query=DB_query("select * from vendorquotationdetails where quotation_no='".$_REQUEST['VQuotesId']."'",$db);
			
			$i=0;
			while($sql_row=DB_fetch_array($sql_query))
			{
			$i++;
			//echo "<pre>";
			//print_r($sql_row);
		?>
<tr class="row1">
			<!--<td>
	<input type="checkbox" name="chk[]" value="<?php echo $sql_row['mst_productid']; ?>" id="chk_<?php echo $i;?>" onclick="uncheck_field(<?php echo $i; ?>)" /> </td> -->
		<td class="tabledata"><?php echo $sql_row['prod_id'];?>
		<input type="hidden" name="item_id[]" value="<?php echo $sql_row['mst_productid'];?>" />
		
		<input type="hidden" name="item_code[]" value="<?php echo $sql_row['prod_id'];?>" /></td>
		<td class="tabledata"><?php echo $sql_row['prod_dec'];?>
		<input type="hidden" name="item_name[]" value="<?php echo $sql_row['prod_dec'];?>" readonly="true"/></td>
		
		<td class="tabledata"><?php echo $sql_row['item_no'];?>
		<input type="hidden" name="item_no[]" value="<?php echo $sql_row['item_no'];?>" /></td>
		<td class="tabledata"><?php echo $sql_row['make'];?>
		<input type="hidden" name="make[]" value="<?php echo $sql_row['make'];?>" /></td>
		<td class="tabledata"><?php echo $sql_row['color'];?>
		<input type="hidden" name="color[]" value="<?php echo $sql_row['color'];?>" /></td>
		<td class="tabledata"><?php echo $sql_row['grade'];?>
		<input type="hidden" name="grade[]" value="<?php echo $sql_row['grade'];?>" /></td>
		<td class="tabledata"><?php $unitdata=DB_query("select * from unitsofmeasure where unitid='".$sql_row['uom']."'",$db);
		     $unitdata1=DB_fetch_array($unitdata);
		
		  echo $unitdata1['unitname'] ;?>
		<input type="hidden" name="uom[]" value="<?php echo $sql_row['uom'];?>" /></td>
		
		<td class="tabledata"><?php echo $sql_row['quantity'];?>
		<input type="hidden" name="quantity[]" value="<?php echo $sql_row['quantity'];?>" id="quantity_<?php echo $i;?>" /></td>
		<td class="tabledata"><input type="text" name="rate[]" value="<?php echo $sql_row['rate'];?>" id="rate_<?php echo $i;?>"   /></td>
		<td class="tabledata"><input type="text" name="total_price[]" value="<?php echo $sql_row['rate']*$sql_row['quantity'];?>" id="total_value_<?php echo $i;?>"  onfocus="calculateTotalPrice(<?php echo $i;?>)" /></td>
		<td class="tabledata">
			<select style="width:100%;" name="discount[]" id="discount_<?php echo $i;?>" >
            <option value="Amount" <?php echo ($sql_row['discount_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($sql_row['discount_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select>
		</td>
		<td class="tabledata"><input type="text" name="discount_per[]" value="<?php echo $sql_row['discount'];?>" id="discount_per_<?php echo $i;?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" /></td>
		<td class="tabledata"><input type="text" name="discount_amount[]" value="<?php echo $sql_row['discount_amount'];?>" id="discount_amount_<?php echo $i;?>" /></td>
		<td class="tabledata"><input type="text" name="sub_total[]" value="<?php echo $sql_row['sub_total'];?>" id="sub_total_<?php echo $i;?>" /></td>
		<td class="tabledata"><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $sql_row['specialdis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $sql_row['specialdis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
		<td class="tabledata"><input type="text" name="special_discount[]" value="<?php echo $sql_row['specialdiscount'];?>" id="special_discount_<?php echo $i;?>" onblur="DiscountAmountdpc(this.value,<?php echo $i;?>)" /></td>
		<td class="tabledata"><input type="text" name="special_discount_amount[]" value="<?php echo $sql_row['specialdiscount_amount'];?>" id="special_discount_amount_<?php echo $i;?>"  /></td>
	<td class="tabledata"><input type="text" name="basic_amount[]" value="<?php echo $sql_row['basic_amt'];?>" id="basic_amount_<?php echo $i;?>" /></td>
	<td class="tabledata"><select name="tax_type[]" style="width: 100px;" id="tax_type_<?php echo $i;?>" onblur="hid_billing_typecheck(<?php echo $i; ?>,this.value)" onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)" >
	<option value="">Select</option>
	<option value="NonExcisable" <?php echo ($sql_row['tax_type']=='NonExcisable')?'selected':''?>>NonExcisable</option>
	<option value="Excisable" <?php echo ($sql_row['tax_type']=='Excisable')?'selected':''?>>Excisable</option>
	<option value="IncludeTax" <?php echo ($sql_row['tax_type']=='IncludeTax')?'selected':''?>>IncludeTax</option>
	</select>
		</td>
		<td class="tabledata"><select name="excise[]" id="excise_<?php echo $i;?>" style="width:90px;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" >
    	    <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 ($sql_row['Excise_Duty']==$excise_row['id'])?'selected':''?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $i; ?>">
		  <input name="excise_percentage[]" id="excise_percentage_<?php echo $i;?>" type="text" value="<?php echo $sql_row['ExcisePercentage']; ?>"  style="width:30%;"  />
		   <input name="excise_value[]" id="excise_value_<?php echo $i; ?>" type="text" value="<?php echo $sql_row['Excise_Duty_value']; ?>" style="width:50%;" 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'];
					//print_r($rate[$k]);
				}
				$k++;
				//echo $rate[1];
			 } 			
    	     ?>
		</td>
		<td class="tabledata"><input type="text" name="ecess_per[]" id="ecess_per_<?php echo $i;?>" style="width:100%;" value="<?php echo $rate[1]; ?>" />
		<input name="ecess_value[]" id="ecess_value_<?php echo $i;?>" type="text" value="<?php echo $sql_row['Edu_Cess'];?>" style="width:75%;" readonly onfocus="calculateECess(<?php echo $i; ?>)" />
		</td>
		
	    <td class="tabledata"><input type="text" name="sah_ecess_per[]" value="<?php echo $rate[2];?>" id="sah_ecess_per_<?php echo $i;?>" style="width:100%;" />
		<input name="sah_ecess_value[]" id="sah_ecess_value_<?php echo $i;?>" type="text" value="<?php echo $sql_row['SHE_Cess'];?>" style="width:75%;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)" />
		</td>
		
		<td class="tabledata"><input type="text" name="taxable_amount[]" id="taxable_amount_<?php echo $i;?>" value="<?php echo $sql_row['taxable_amt']; ?>" style="width:100%;" onfocus="calculateTaxable(<?php echo $i; ?>)" /></td>
		<?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
		<!--<td>
		<select id="vat_cst_<?php echo $i;?>" name="vat_cst[]" onchange="tax_rate(this.value,<?php echo $i; ?>)" style="width:100%;" disabled="disabled">
	<option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['id']; ?>"<?php echo ($sql_row['taxnameid']==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select>
		</td>
		<td><div id="taxval_<?php echo $i; ?>">
		<input type="text" name="vat_cst_amount[]" value="<?php echo $sql_row[' taxable_amt'];?>" id="vat_cst_amount_<?php echo $i;?>"  disabled="disabled"/>
		</div></td>-->
		<td class="tabledata"><input type="text" name="total_amount[]" value="<?php echo $sql_row['total_amount'];?>" id="total_amount_<?php echo $i;?>" onfocus="cal_grandtotal(<?php echo $i;?>)" style="width:100px;"   /></td>
		
</tr>	
		
	<?php } } ?>

	<input type="hidden" name="count" id="count" value="<?php echo $i;?>" size="10" />
</table>
</div>
	</td>
</tr>
<tr class="row1">
	<td colspan="6">
	<table width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
			<td width="50%">&nbsp;</td>
			<td width="50%">
			<table width="100%" border="0" cellspacing="0" cellpadding="3">
                <tr class="row1">
                  <td class="tabledata1"><strong>TOTAL AMOUNT </strong></td>
                  <td ><input type="text" name="vendor_quotes_ammendment[total_item_amount]" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" value="<?php echo $total_amount; ?>" /></td>
                </tr>
               <tr class="row1">
                  <td class="tabledata1"><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="vendor_quotes_ammendment[pkg_per]" id="pkg_perc" value="<?php echo $pkg_per; ?>" size="5" onkeyup="calcPackaging(this.value)" /><input name="vendor_quotes_ammendment[pkg_charges]" id="pkg_charges" type="text" value="<?php echo $pkg_charges; ?>" size="28" /></td>
                </tr>
               
               
				
				 <tr class="row1">
                  <td class="tabledata1"><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><select id="taxname" name="vendor_quotes_ammendment[vat_cst_per]" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($vat_per==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
			  </tr> 
              <tr class="row1">
              	<td class="tabledata1"><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $vat_amount;?>" readonly="true"/>
              </div></td>
                   </tr>
  <tr class="row1">
                  <td class="tabledata1"><strong>Surcharge Amount</strong> </td>
                  <td>				  
				  <input type="text" name="vendor_quotes_ammendment[sur_oct_per]" id="surcharge_per"  size="10" onchange="calsuroctamt(this.value)" value="<?php echo $surcharge_per;  ?>"   />
<input name="vendor_quotes_ammendment[sur_oct_amt]" type="text" id="surcharge_amount" value="<?php echo $surcharge_amount; ?>" style="width:60%;" />
				  
				  
				  </td>
                </tr>
             <tr class="row1">
                  <td class="tabledata1"><strong>Freight</strong> </td>
                  <td><input type="text" name="vendor_quotes_ammendment[freight]" id="freight" style="width:100%;" value="<?php echo $freight; ?>"/></td>
                </tr>
                <tr class="row1">
                <td class="tabledata1"><strong>Additional Charges</strong> </td>
                  <td><input type="text" name="vendor_quotes_ammendment[additional_charges]" id="additional_charges"  value="<?php echo $additional_charges; ?>" size="25" style="width:100%;" /></td>
                </tr>
				<!--<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="vendor_quotes_ammendment[round_off]" value="" id="round_off" style="width:100%;"/></td>
				</tr>-->
				
              <tr class="row1">
                 <td class="tabledata1">Grand Total</td>
                  <td><input type="text" name="vendor_quotes_ammendment[grand_total]" id="grand_total" style="width:100%;" readonly="readonly" value="<?php echo $grand_total; ?>" onfocus="cal_grandamount()"/></td>
                </tr>
              </table>
			</td>
		</tr>
	</table>
	</td>
</tr>
<tr class="row1">
	<td colspan="6" style="text-align:center;">
	<input type="submit" value="Save" name="save" class="search" />
	</td>
</tr>
</table>


</form>



<script language="javascript" type="text/javascript">

function openPopupProfile(str1,str2,str3)
{ 
alert(str3);
window.open("vendor_quotes_ammendment_ajax.php?vendorid="+str1+"&quotes="+str2+"&identify="+str3+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","","height=500,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");

//window.open("vendor_quotes_ammendment_ajax.php?vendorid="+str1+"&quotes="+str2,"height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable=yes");

//window.open("vendor_quotes_ammendment_ajax.php?vendorid="+str1,"&quotes="+str2,"height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}

function calculateTotalPrice(i)
{


if(document.getElementById("rate_"+i).value=='0')
  {
  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("total_value_"+i).value=Total.toFixed(2);
}
}

function DiscountAmount(DA,i)
{
	
	var discount_percent = document.getElementById("discount_"+i).value;
	
	var rate = document.getElementById("rate_"+i).value;
	var discount = document.getElementById("discount_per_"+i).value;
	var quantity = document.getElementById("quantity_"+i).value;
	var totalPrice = parseFloat(quantity)*parseFloat(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_per_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
	}
	document.getElementById("discount_amount_"+i).value=percent.toFixed(2);
	document.getElementById("sub_total_"+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("sub_total_"+i).value;
	
	var discount1 = document.getElementById("special_discount_"+i).value;
	var Specialperc=document.getElementById("special_discount_amount_"+i).value;
	
	if(discount1=='' && Specialperc=='')
	{
		var total1=document.getElementById("sub_total_"+i).value;
		
		document.getElementById("basic_amount_"+i).value=total1;
	
	}
	else
	{
		if(discount1=='' && Specialperc!='')
		{
			var elx=document.getElementById("special_discount_amount_"+i).value;
			var total1=document.getElementById("sub_total_"+i).value;
			
			var TotalAmount2 = total1-parseFloat(elx);
			
			document.getElementById("basic_amount_"+i).value=TotalAmount2.toFixed(2);
		}
		else
		{
			var percent1 = total1 * parseFloat(discount1)/100;
			var TotalAmount2 = total1-parseFloat(percent1);
	
			document.getElementById("special_discount_amount_"+i).value=percent1.toFixed(2);
			document.getElementById("basic_amount_"+i).value=TotalAmount2.toFixed(2);
		}
	
	}
}
function hid_billing_typecheck(i,str){

	
	if(str=='')
	{
		
		alert("Select Tax Type");
		document.getElementById("tax_type_"+i).focus();
	}

}
function checkExcisable1(str,i)
{
 	
	
	if(str=='NonExcisable')
	{
		document.getElementById("excise_"+i).disabled=true;
		document.getElementById("ecess_per_"+i).disabled=true;
		document.getElementById("ecess_value_"+i).disabled=true;
		document.getElementById("excise_value_"+i).disabled=true;		
		document.getElementById("excise_percentage_"+i).disabled=true;
		document.getElementById("sah_ecess_per_"+i).disabled=true;
		document.getElementById("sah_ecess_value_"+i).disabled=true;
				
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("excise_"+i).disabled=false;
		document.getElementById("excise_value_"+i).disabled=false;
		document.getElementById("excise_percentage_"+i).disabled=false;
		document.getElementById("ecess_per_"+i).disabled=false;
		document.getElementById("ecess_value_"+i).disabled=false;	
		document.getElementById("sah_ecess_per_"+i).disabled=false;
		document.getElementById("sah_ecess_value_"+i).disabled=false;	
	}
	else{
		document.getElementById("excise_"+i).disabled=true;
		document.getElementById("excise_value_"+i).disabled=true;
		document.getElementById("ecess_per_"+i).disabled=true;
		document.getElementById("ecess_value_"+i).disabled=true;
		document.getElementById("excise_percentage_"+i).disabled=true;
		document.getElementById("sah_ecess_per_"+i).disabled=true;
		document.getElementById("sah_ecess_value_"+i).disabled=true;
		document.getElementById("taxable_amount_"+i).disabled=true;
		document.getElementById("vat_cst_"+i).disabled=true;
		document.getElementById("vat_cst_amount_"+i).disabled=true;

		document.getElementById("excise_"+i).value='';
		document.getElementById("excise_value_"+i).value='';
		document.getElementById("ecess_per_"+i).value='';
		document.getElementById("ecess_value_"+i).value='';
		document.getElementById("excise_percentage_"+i).value='';
		document.getElementById("sah_ecess_per_"+i).value='';
		document.getElementById("sah_ecess_value_"+i).value='';
		document.getElementById("taxable_amount_"+i).value='';
		document.getElementById("vat_cst_"+i).value='';
		document.getElementById("vat_cst_amount_"+i).value='';	
	}
	document.getElementById("tax_type_"+i).value=str;
}



function checkExcisable(str,i)
{
 	
	if(str=='NonExcisable')
	{
		
		
		document.getElementById("excise_"+i).disabled=true;
		document.getElementById("ecess_per_"+i).disabled=true;
		document.getElementById("ecess_value_"+i).disabled=true;
		document.getElementById("sah_ecess_per_"+i).disabled=true;
		document.getElementById("sah_ecess_value_"+i).disabled=true;
		document.getElementById("excise_value_"+i).disabled=true;		
		document.getElementById("excise_percentage_"+i).disabled=true;
	
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("excise_"+i).disabled=false;
		//document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("ecess_per_"+i).disabled=false;
		document.getElementById("ecess_value_"+i).disabled=false;		
		document.getElementById("sah_ecess_per_"+i).disabled=false;
		document.getElementById("sah_ecess_value_"+i).disabled=false;
		document.getElementById("taxable_amount_"+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("excise_value_"+i).disabled=false;		
		document.getElementById("excise_percentage_"+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("excise_"+i).disabled=true;
		//document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("ecess_per_"+i).disabled=true;
		document.getElementById("ecess_value_"+i).disabled=true;
	   document.getElementById("sah_ecess_per_"+i).disabled=true;
		document.getElementById("sah_ecess_value_"+i).disabled=true;
		document.getElementById("taxable_amount_"+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("excise_value_"+i).disabled=false;		
		document.getElementById("excise_percentage_"+i).disabled=false;
	

		document.getElementById("exciseDuty_"+i).value='';
		//document.getElementById("exciseValue_"+i).value='';
		document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("sah_ecess_per_"+i).value='';
		document.getElementById("sah_ecess_value_"+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 claculateExcise(i,str)
{
	
	var discounted=document.getElementById("basic_amount_"+i).value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId_"+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("exciseId_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","vendor_quotes_ammendment_calculateExcise.php?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();
}

function calculateExciseDuty(i)
{
	var basic=document.getElementById("basic_amount_"+i).value;
	var ExcisePercentage=document.getElementById("excise_percentage_"+i).value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("excise_value_"+i).value=exciseVal.toFixed(2);
}

function calculateECess(i)
{
	
	var exciseValue=document.getElementById("excise_value_"+i).value;
	var ECessPercentage=document.getElementById("ecess_per_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ecess_value_"+i).value=total.toFixed(2);
}
function calculateSAHCess(i)
{
	var exciseValue=document.getElementById("excise_value_"+i).value;
	var SAHCessPercentage=document.getElementById("sah_ecess_per_"+i).value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("sah_ecess_value_"+i).value=total.toFixed(2);
}

function calculateTaxable(i)
{
	var totalDiscountedPrice=document.getElementById("basic_amount_"+i).value;
	var exciseValue=document.getElementById("excise_value_"+i).value;
	var ECessValue=document.getElementById("ecess_value_"+i).value;
	var SAHCessValue=document.getElementById("sah_ecess_value_"+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(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxable_amount_"+i).value=TOTAL.toFixed(2);
}

function tax_rate(str,i)
{

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

if(billing_type=='NonExcisable')
{
var taxableAmount=document.getElementById("basic_amount_"+i).value;

}

else if(billing_type=='Excisable')
{
var taxableAmount=document.getElementById("taxable_amount_"+i).value;

}

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","vendor_quotes_ammendment_get_tax_val.php?taxid="+str+"&amt="+taxableAmount+"&data="+i,true);
xmlhttp.send();
}

function cal_grandtotal(i)
{

	var type_of_bill=document.getElementById("tax_type_"+i).value;
	var basic=document.getElementById("basic_amount_"+i).value;
	
	var Totaltaxable=document.getElementById("taxable_amount_"+i).value;
	//var vatcstAmt=document.getElementById("vat_cst_amount_"+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("tax_type_"+i).value=='NonExcisable')
	{
	
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		
	}	
	
	
else if(document.getElementById("tax_type_"+i).value=='IncludeTax'){

var grand_tot1= parseFloat(basic) ;
var grand_tot=grand_tot1.toFixed(2);
}
	else{
	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		//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("total_amount_"+i).value=grand_tot ;	
		//alert(	document.getElementById("TotalSpecial_"+i).value);
	
}
function cal_totalamount()
{
	
	
	var total=0;
var t=document.getElementById("count").value;



for(var i=1;i<=t;i++)
{

var amt=parseFloat(document.getElementById("total_amount_"+i).value);

total=parseFloat(total)+amt;	
}	

//document.getElementById("total_item_amount").value=total.toFixed(2);
	
	
	

//var total=0;
//var t=document.getElementById("count").value;

//for(var i=1;i<=t;i++)
//{	
	//var chk_dis=document.getElementById("total_amount_"+i).disabled;
	
	//if(chk_dis==true)
	//{
		
		//var val="0";
		//ar amt=parseFloat(val);
		
	//}
	//else
	//{
		//var amt=parseFloat(document.getElementById("total_amount_"+i).value);
	//}
//total=parseFloat(total)+amt;

//}	
document.getElementById("total_item_amount").value=total.toFixed(2);	
}

function cal_grandamount()
{


	var total=document.getElementById("total_item_amount").value;
	var taxvalue=document.getElementById("taxvalue").value;
	var sur_oct_amt=document.getElementById("surcharge_amount").value;
	var TotalCharge=document.getElementById("freight").value;
	var packagingCharges=document.getElementById("pkg_charges").value;
	var additionalCharges=document.getElementById("additional_charges").value;	
	if(total==''){total=0;}
	if(taxvalue==''){taxvalue=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	var grandtotal=parseFloat(total)+parseFloat(taxvalue)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges);
		
	document.getElementById("grand_total").value=parseFloat(grandtotal).toFixed(2) ;
}

function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("surcharge_amount").value;
	var TotalCharge=document.getElementById("freight").value;
	var packagingCharges=document.getElementById("pkg_charges").value;
	var additionalCharges=document.getElementById("additional_charges").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("grand_total").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("grand_total").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("grand_total").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
}
function uncheck_field(i)
{
	
	
	if(document.getElementById("chk_"+i).checked)
	{	var type=document.getElementById("tax_type_"+i).value;
				
		document.getElementById("quantity_"+i).disabled=false;
		document.getElementById("rate_"+i).disabled=false;
		document.getElementById("total_value_"+i).disabled=false;
		document.getElementById("discount_"+i).disabled=false;
		document.getElementById("discount_per_"+i).disabled=false;
		document.getElementById("discount_amount_"+i).disabled=false;
		document.getElementById("sub_total_"+i).disabled=false;
		document.getElementById("special_discount_"+i).disabled=false;
		document.getElementById("special_discount_amount_"+i).disabled=false;
		document.getElementById("basic_amount_"+i).disabled=false;
		document.getElementById("tax_type_"+i).disabled=false;
		document.getElementById("excise_"+i).disabled=false;
		document.getElementById("excise_value_"+i).disabled=false;
		document.getElementById("ecess_per_"+i).disabled=false;
		document.getElementById("ecess_value_"+i).disabled=false;
		document.getElementById("excise_percentage_"+i).disabled=false;
		document.getElementById("sah_ecess_per_"+i).disabled=false;
		document.getElementById("sah_ecess_value_"+i).disabled=false;
		document.getElementById("taxable_amount_"+i).disabled=false;
		document.getElementById("vat_cst_"+i).disabled=false;
		document.getElementById("vat_cst_amount_"+i).disabled=false;
		document.getElementById("total_amount_"+i).disabled=false;
		document.getElementById("taxable_amount_"+i).disabled=false;
		document.getElementById("vat_cst_"+i).disabled=false;
		document.getElementById("vat_cst_amount_"+i).disabled=false;
		document.getElementById("tax_type_"+i).value='';
			
	}	
	else
	{
		document.getElementById("quantity_"+i).disabled=true;
		document.getElementById("rate_"+i).disabled=true;
		document.getElementById("total_value_"+i).disabled=true;
		document.getElementById("discount_"+i).disabled=true;
		document.getElementById("discount_per_"+i).disabled=true;
		document.getElementById("discount_amount_"+i).disabled=true;
		document.getElementById("sub_total_"+i).disabled=true;
		document.getElementById("special_discount_"+i).disabled=true;
		document.getElementById("special_discount_amount_"+i).disabled=true;
		document.getElementById("basic_amount_"+i).disabled=true;
		document.getElementById("tax_type_"+i).disabled=true;
		
		document.getElementById("excise_"+i).disabled=true;
		document.getElementById("excise_value_"+i).disabled=true;
		document.getElementById("ecess_per_"+i).disabled=true;
		document.getElementById("ecess_value_"+i).disabled=true;
		document.getElementById("excise_percentage_"+i).disabled=true;
		document.getElementById("sah_ecess_per_"+i).disabled=true;
		document.getElementById("sah_ecess_value_"+i).disabled=true;
		document.getElementById("taxable_amount_"+i).disabled=true;
		document.getElementById("vat_cst_"+i).disabled=true;
		document.getElementById("vat_cst_amount_"+i).disabled=true;
		document.getElementById("total_amount_"+i).disabled=true;
		document.getElementById("taxable_amount_"+i).disabled=true;
		document.getElementById("vat_cst_"+i).disabled=true;
		document.getElementById("vat_cst_amount_"+i).disabled=true;
		
	}

}


function calsuroctamt(str)
{

var amt=parseFloat(document.getElementById("taxvalue").value);

var	suroctper=parseFloat(document.getElementById("surcharge_per").value);

var amount=(amt*suroctper)/100;
document.getElementById("surcharge_amount").value=amount.toFixed(2);	
	
	
	
	
}





function tax_rate1(str)
{
var taxableAmount=document.getElementById("total_item_amount").value;
var taxableAmount1=document.getElementById("pkg_charges").value;
if(taxableAmount1==''){taxableAmount1=0;}
var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
if (str.length==0)
  {
  document.getElementById("taxval").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").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount2,true);
xmlhttp.send();
}
/****************************************/
function DiscountAmountdpc(DA,i)
{
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("sub_total_"+i).value;
	var discount = document.getElementById("special_discount_"+i).value;
	
	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("special_discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	if(parseFloat(discount)>=100 && discount_percent=='PercentAmt')
		{
		alert("Discount Percentage Should Be Less Then 100");
		document.getElementById("special_discount_amount_"+i).value='';
		document.getElementById("special_discount_"+i).value='';
	     document.getElementById("basic_amount_"+i).value='';
	     document.getElementById("special_discount_"+i).focus();
		return false;
		}
		else
		{
	document.getElementById("special_discount_amount_"+i).value=percent.toFixed(2);
	document.getElementById("basic_amount_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;

}
	}
	
	function calcPackaging(str)
{
	if(str!='')
	{
		var tota_amt=document.getElementById("total_item_amount").value;
		var pckgng_val=(str/100)*tota_amt;
		document.getElementById("pkg_charges").value=pckgng_val.toFixed(2);
	}
}













</script>
