<?php extract($_POST);
$PageSecurity = 1;
global $db;?>
<?php 
$year=$_SESSION['financialYearStart'];
$year_after=$_SESSION['financialYearEnd'];
if($_REQUEST['Order'])
{
	  	 $sql ="select * from purchorders  where orderno='".$_REQUEST['POID']."'";
  		 $PurchOrdersResult = DB_query($sql,$db);
		 
		 $rowdata=DB_fetch_array($PurchOrdersResult);
		 $site_str=substr($rowdata['sitecode'],0,3);
/***********************INSERT DATA IN ARRAY*********************************************/		
		 //$prefix_sql=DB_query("SELECT * FROM `prefix_tbl` where prefix_name='PO Ammendement'",$db);
		 //$prefix_row=DB_fetch_array($prefix_sql);
		 $prefix="PO";
		 $prefix1="AMD";
		 
		 $check_prev_code="Select ammndmnt_no from purchorders_ammd 
		 where sitecode='".$rowdata['sitecode']."'";
		 
		 $prev_code_res=DB_query($check_prev_code,$db);
		 if(DB_num_rows($prev_code_res)>0)
		 {
		 	$GetMaxSQL=DB_query("Select Max(ammndmnt_no) AS MAXAMMD from purchorders_ammd 
		 where sitecode='".$rowdata['sitecode']."'",$db);
		 	$prev_code_row=DB_fetch_array($GetMaxSQL);
		 	$prev_code=$prev_code_row['MAXAMMD'];
			$numeric=explode("-",$prev_code);
			$new=$numeric[1]+1;
			$final_string=$site_str."/".$prefix."/".$year.$year_after."/".$prefix1."-".$new;
		 }
		 else
		 {
			$final_string=$site_str."/".$prefix."/".$year.$year_after."/".$prefix1."-".'1';
		 }		 
		 
		 		 
		 $rev_sql=DB_query("Select revision_no from purchorders_ammd 
		 where against_po_id=".$_REQUEST['POID']." order by orderno 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;}
		 $data['against_po_id']=$_REQUEST['POID'];
		 $data['revision_no']=$new_rev ;
		 $data['ammndmnt_no']=$final_string ;
		 $data['mst_reqino']=$rowdata['mst_reqino'] ;
		 $data['mst_vendor_pid']=$rowdata['mst_vendor_pid'] ;
		 $data['mst_vendor_quotesid']=$rowdata['mst_vendor_quotesid'] ;
		 $data['mst_comperitive']=$rowdata['mst_comperitive'] ;
		 $data['vendor_id']=$rowdata['vendor_id'] ;
		 $data['supplierno']=$rowdata['supplierno'] ;		
		 $data['sitecode']=$rowdata['sitecode'] ;		
		 $data['delivery_place1']=$_REQUEST['delivery_place1'] ;
		 $data['delivery_place2']=$_REQUEST['delivery_place2'] ;
		 $data['mode_of_transport']=$_REQUEST['mode_of_transport'] ;
		 $data['freight_details']=$_REQUEST['freight_details'] ;
		 $data['transit_insurance']=$_REQUEST['transit_insurance'] ;
		 $data['delivery_date']=FormatDateForSQL($_REQUEST['delivery_date']);
		 $data['delivery_time']=$_REQUEST['delivery_time'] ;
		 $data['contact_person']=$_REQUEST['contact_person'] ;
		 $data['orddate']=date('Y-m-d') ;
		 $data['basic_amt']=$_POST['total_item_amount'];
		 $data['vat_cst_per']=$_POST['taxname'];
		 $data['vat_cst_amount']=$_POST['taxvalue'];
		 $data['sur_oct_perc']=$_POST['sur_oct_per'];
		 $data['sur_oct_amt']=$_POST['sur_oct_amt'];
		 $data['fright']=$_POST['TotalCharge'] ;
		 $data['pkg_charges']=$_POST['pkg_charges'] ;
		 $data['pkg_charges']=$_POST['pkg_charges'] ;
		 $data['additional_charges']=$_POST['add_charges'] ;
		 $data['grand_total']=$_POST['GrandTotal'] ;
		 $data['pkg_per']=$_POST['pkg_per'];		
		 $data['identify']="POAMD";
		//echo "<pre>";print_r($data); exit;
		//********* Insert New Ammendement*********/////
		
		$insert1=$s->RecordInsert('purchorders_ammd', $data);
	//exit;
		$last_amd_id=DB_Last_Insert_ID($db,'purchorders_ammd','id');
/**************************UPDATE PURCHORDERDETAILS*******************/
	       if($last_amd_id!='')
		   {
		    	for($i=0;$i<$_REQUEST['count'];$i++)
				{
					$data_detail['orderno']=$last_amd_id;
					$data_detail['mst_reqino']=$_REQUEST['mst_reqino'][$i];
					$data_detail['mst_itemid']=$_REQUEST['mst_itemid'][$i];
					$data_detail['prod_id']=$_REQUEST['prod_id'][$i];
					$data_detail['prod_dec']=$_REQUEST['prod_dec'][$i];
					$data_detail['quatity']=$_REQUEST['quatity'][$i];					
					$data_detail['rate']=$_REQUEST['Rate'][$i];
					$data_detail['discount_type']=$_REQUEST['PerAmo'][$i];
					$data_detail['discount']=$_REQUEST['Discount'][$i];
					$data_detail['discount_amount']=$_REQUEST['perc'][$i];
					$data_detail['Sub_total']=$_REQUEST['NetRate'][$i];
					$data_detail['specialdis_type']=$_REQUEST['Perspc'][$i];
					$data_detail['specialdiscount']=$_REQUEST['SpecialDiscount'][$i];
					$data_detail['specialdiscount_amount']=$_REQUEST['Specialperc'][$i];
					$data_detail['basic_amt']=$_REQUEST['basic'][$i];
					$data_detail['tax_type']=$_REQUEST['hid_billing_type'][$i];
					$data_detail['Excise_Duty']=$_REQUEST['exciseDuty'][$i];
					$data_detail['ExcisePercentage']=$_REQUEST['ExcisePercentage'][$i];
					$data_detail['Excise_Duty_value']=$_REQUEST['exciseValue'][$i];
					$data_detail['Edu_Cess_perc']=$_REQUEST['ECessPercentage'][$i];
					$data_detail['Edu_Cess']=$_REQUEST['ECessValue'][$i];
					$data_detail['SHE_Cess_perc']=$_REQUEST['SAHCessPercentage'][$i];
					$data_detail['SHE_Cess']=$_REQUEST['SAHCessValue'][$i];
					$data_detail['taxabel_amt']=$_REQUEST['taxable_amt'][$i];
					$data_detail['totalamount']=$_REQUEST['TotalSpecial'][$i];					            
					$data_detail['item_no']=$_REQUEST['item_no'][$i];
					$data_detail['Make']=$_REQUEST['Make'][$i];
					$data_detail['Color']=$_REQUEST['Color'][$i];
					$data_detail['Grade']=$_REQUEST['Grade'][$i];
					$data_detail['UOM']=$_REQUEST['UOM'][$i];
			$Update2=$s->RecordInsert('purchorderdetails_ammd',$data_detail);
		
				}
		   }
		 $s->pageLocation("index.php?route=POModule/POorder_Ammendment_index".$rurl."&tab=2&type=POModule/APO");
}
if($_REQUEST['daction'])
{
   echo "<div class='success'>PO Order Ammended Successfully</div>";
}
?>



<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Order Ammendment Add</h1>
 <form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">
		<h3><strong>Item Details</strong></h3>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1">
		<div style="overflow:auto; width:860px;">
 <table border="1" width="100%" cellpadding="3" cellspacing="0">
                   <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>Unit</strong></td>
<!--			   <td class="tabledata"><strong>Length</strong></td>
				   <td class="tabledata"><strong>Width</strong></td>
				   <td class="tabledata"><strong>Origanal/Local</strong></td>
				   <td class="tabledata"><strong>Quality</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 Type </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 DISCOUNT</strong></td>
				    <td class="tabledata"><strong>SPECIAL DISCOUNT AMOUNT</strong></td>
				    <td class="tabledata"><strong>BASIC AMOUNT</strong></td>
					<td class="tabledata"><strong>Tax Type</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>TOTAL AMOUNT</strong></td>    </tr>	 
<?php 
$CHECK_POSTATUS=DB_fetch_array(DB_query("select * from purchorders where orderno='".$_REQUEST['POID']."'",$db)); 
$sql="SELECT * FROM purchorderdetails WHERE orderno='".$_REQUEST['POID']."'";
$result=DB_query($sql,$db);
$i=0;
while($myrow=DB_fetch_array($result))
{
//echo "<pre>";
//print_r($myrow);
if($i%2==0)
{$bg="#CCCCCC";}
else
$bg="#C8BECB";
?>
    <tr bgcolor="#99CCCC">
	<td><?php echo $myrow['prod_id'];?>
	<input type="hidden" name="mst_reqino[]"  value="<?php echo $myrow['mst_reqino']; ?>"   />
	<input type="hidden" name="mst_itemid[]"  value="<?php echo $myrow['mst_itemid']; ?>"   />
	<input type="hidden" name="prod_id[]" style="width: 100%" value="<?php echo $myrow['prod_id'];?>" readonly></td>
	<td><?php echo $myrow['prod_dec'];?><input type="hidden" name="prod_dec[]" style="width: 100%"  value="<?php echo $myrow['prod_dec'];?>" readonly></td>
	<td><?php echo $myrow['item_no']; ?><input type="hidden" name="item_no[]" value="<?php echo $myrow['item_no']; ?>" /></td>
	<td> 
	<?php echo $makename=$s->getField('product_manufacture','id',$myrow['Make'],'manufacturer');?>
	<input type="hidden" Name="Make[]" value="<?php echo $myrow['Make'];?>" readonly>
	</td>
	<td><?php 

	$colorname=$s->getField('product_color','id',$myrow['Color'],'color');
	echo $colorname;?><input type="hidden" Name="Color[]" value="<?php echo $myrow['Color'];?>" readonly>	</td>
	<td><?php 
	$gradename=$s->getField('product_grade','id',$myrow['Grade'],'grade');
	echo $gradename;?><input type="hidden" Name="Grade[]" value="<?php echo $myrow['Grade'];?>" readonly>	</td>
	<td><?php 
	echo $unitname=$s->getField('unitsofmeasure','unitid',$myrow['UOM'],'unitname');
	 ?><input type="hidden" name="UOM[]" style="width: 100%"  value="<?php echo $myrow['UOM'];?>" readonly></td>
	 <!--<td>
	  <?php // $query_item=DB_query("select * from item_master where StockID='".$myrow['prod_id']."'", $db);
		  	//$item_row=DB_fetch_array($query_item); ?>
	 <input type="hidden" name="length[]" id="length" value="<?php// echo $item_row['length'];?>" readonly="" />
	 </td>
	 <td>
	 <input type="hidden" name="width[]" id="width" value="<?php// echo $item_row['width'];?>" readonly="" />
	 </td>
	 <td>
	 <input type="hidden" name="orig_local[]" id="orig_local" value="<?php// echo $item_row['orig_local'];?>" readonly="" />
	 </td>
	  <td>
	 <input type="hidden" name="quality[]" id="quality" value="<?php// echo $item_row['quality'];?> " readonly="" />
	 </td>-->
            <?php $query =DB_query("select * from item_master", $db);
				$quer_row=DB_fetch_array($query);
			?> 
<td><?php echo  $myrow['quatity'];?><input type="hidden" name="quatity[<?php echo $i;?>]" id="Quantity_<?php echo $i;?>" style="width:50px;"  value="<?php echo $myrow['quatity'];?>"/></td>
<td><input   type="text" name="Rate[]" id="Rate_<?php echo $i;?>" style="width:80px;"   value="<?php echo $myrow['rate'];?>" /></td>
		  
		  <!--<td><input style="width:100%;" type="text" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $myrow['total_price']; ?>" onfocus="calculateTotalPrice(<?php echo $i;?>)" readonly="true" disabled="true"/></td>-->
		  
		  <td><select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($myrow['discount_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($myrow['discount_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>

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

 <td><select style="width:100px;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $myrow['specialdis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $myrow['specialdis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
<td><input type="text" name="SpecialDiscount[]" id="special_discount_<?php echo $i;?>" style="width:80px;" onblur="DiscountAmountdpc(this.value,<?php echo $i;?>)" value="<?php echo $myrow['specialdiscount']; ?>" />
</td>
<td><input type="text" name="Specialperc[]" id="special_discount_amount_<?php echo $i;?>"  style="width:100%;" size="10"  value="<?php echo $myrow['specialdiscount_amount']; ?>" /></td>
<td><input type="text" id="basic_<?php echo $i;?>" name="basic[]" value="<?php echo $myrow['basic_amt']; ?>" size="8" style="width:100%;" readonly /></td>
<td><select name="hid_billing_type[]" style="width: 100px;" id="hid_billing_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 ($myrow['tax_type']=='NonExcisable')?'selected':''?>>NonExcisable</option>
	<option value="Excisable" <?php echo ($myrow['tax_type']=='Excisable')?'selected':''?>>Excisable</option>
	<option value="IncludeTax" <?php echo ($myrow['tax_type']=='IncludeTax')?'selected':''?>>IncludeTax</option>
	
</select></td>
<td>
	<!--<select name="exciseDuty[]" id="exciseDuty_<?php echo $i;?>" style="width:100%;" 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 ($myrow['Excise_Duty']==$excise_row['id'])?'selected':''?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	   </select>-->
  	      <div id="exciseId_<?php echo $i; ?>"><input name="ExcisePercentage[]" id="ExcisePercentage_<?php echo $i;?>" type="text" value="<?php echo $myrow['ExcisePercentage']; ?>"  style="width:45px;" readonly /> <input name="exciseValue[]" id="exciseValue_<?php echo $i; ?>" type="text" value="<?php echo $myrow['Excise_Duty_value']; ?>" style="width:45;" 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[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:45px;" readonly /><input name="ECessValue[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $myrow['Edu_Cess']; ?>" style="width:45px;" readonly onfocus="calculateECess(<?php echo $i; ?>)" /></td>

<td><input name="SAHCessPercentage[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:45px;" readonly /><input name="SAHCessValue[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $myrow['SHE_Cess']; ?>" size="25" style="width:45px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)" /></td>  
<td><input type="text" name="taxable_amt[]" id="taxable_amt_<?php echo $i;?>" value="<?php echo $myrow['taxabel_amt']; ?>" style="width:80px;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly /></td>
<td><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalSpecial[]" style="width:90px;" readonly  onfocus="cal_grandtotal(<?php echo $i;?>);" value="<?php echo $myrow['totalamount']; ?>" /></td>
</tr><?php $i++; } ?>

  </table>
  <input type="hidden" name="count" id="count" value="<?php echo $i;?>" size="10" /> 
  </div>
	</td>
</tr>

<?php 
if($_REQUEST['POID']!=''){$POSQL=DB_query("Select * from purchorders where orderno='".$_REQUEST['POID']."'",$db);}
else{$POSQL=DB_query("Select * from purchorders_ammd where orderno='".$_REQUEST['POAMDId']."'",$db);}
$PORESULT=DB_fetch_array($POSQL);
$delivery_place1=$PORESULT['delivery_place1'];
$delivery_place2=$PORESULT['delivery_place2'];
$mode_of_transport=$PORESULT['mode_of_transport'];
$freight_details=$PORESULT['freight_details'];
$transit_insurance=$PORESULT['transit_insurance'];
$delivery_date=$PORESULT['delivery_date'];
$delivery_time=$PORESULT['delivery_time'];
$contact_person=$PORESULT['contact_person'];
?>

<tr class="row1">
	<td class="tabledata1">
		<table border="0" width="100%" cellpadding="3" cellspacing="0">
			<tr class="row1">
			<td width="50%">
			<table width="100%" border="0" style="border:solid 1px #CCC; background:#FFFFFF">
<tr><th rowspan="2">Delivery Place</th><td><input type="text" name="delivery_place1" id="" value="<?php echo $delivery_place1;?>" style="width:100%" /></td></tr>
<tr><td><input type="text" name="delivery_place2" id="Input7" value="<?php echo $delivery_place2;?>" style="width:100%"/></td>
</tr>
<tr><th>Mode Of Transport</th><td>
<select name="mode_of_transport" id="mode_of_transport" style="width:100%">
<option value="Road" <?php if($mode_of_transport=='Road') echo "selected";?>>By Road</option>
<option value="Air" <?php if($mode_of_transport=='Air') echo "selected";?>>By Air</option>
<option value="Sea" <?php if($mode_of_transport=='Sea') echo "selected";?>>By Sea</option>
</select></td></tr>
<tr><th>Freight</th><td><input type="text" name="freight_details" id="freight_details" value="<?php echo $freight_details;?>" style="width:100%"/></td></tr>
<tr><th>Transit Insurance</th><td><input type="text" name="transit_insurance" id="transit_insurance" value="<?php echo $transit_insurance;?>" style="width:100%"/></td></tr>
<tr><th>Delivery Date</th><td><input type="text" name="delivery_date" id="delivery_date" value="<?php echo ConvertSQLDate($delivery_date);?>" style="width:100%" class="datepicker"/></td></tr>
<tr><th>Delivery Time</th><td><input type="text" name="delivery_time" id="delivery_time" value="<?php echo $delivery_time;?>" style="width:100%"/></td></tr>
<tr><th>Contact Person</th><td><input type="text" name="contact_person" id="contact_person" value="<?php echo $contact_person;?>" style="width:100%"/></td></tr>
</table>
			</td>
			<td width="50%">
			<table width="50%" border="0" cellspacing="2" cellpadding="2" align="right" class="label">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" value="<?php echo  $CHECK_POSTATUS['basic_amt'];?>" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
                </tr>
                 <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_per" id="pkg_perc" value="<?php echo $CHECK_POSTATUS['pkg_per']; ?>" size="5" onkeyup="calcPackaging(this.value)" /><input name="pkg_charges" id="pkg_charges" type="text" value="<?php echo  $CHECK_POSTATUS['pkg_charges'];?>" size="28" /></td>
                </tr>
               
                
               <!--<tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges" id="packagingCharges" type="text" value="<?php echo  $CHECK_POSTATUS['pkg_charges'];?>" size="25" style="width:100%;" /></td>
               </tr>-->
				<tr>
                  <td><strong>VAT/CST(Description) </strong> </td>
                  <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><select id="taxname" name="taxname" 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['id']; ?>"<?php echo ($CHECK_POSTATUS['vat_cst_per']==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select>
              <?php $vat_perc=$s->getField('service_tax_master','id',$CHECK_POSTATUS['vat_cst_per'],'taxrate');?>
 				
              </td>
              </tr>
				
				<tr>
				<td><strong>VAT/CST Amount</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $CHECK_POSTATUS['vat_cst_amount'];?>" readonly="true" onfocus="calcVatTax(<?php echo $vat_perc;?>)"/>
              </div>

	</td>
				</tr>
				<tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" value="<?php echo $CHECK_POSTATUS['sur_oct_perc'] ?>" id="sur_oct_per"  size="5" onchange="calsuroctamt(this.value)"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo  $CHECK_POSTATUS['sur_oct_amt'];?>" style="width:60%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo  $CHECK_POSTATUS['fright'];?>" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo  $CHECK_POSTATUS['additional_charges'];?>" 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><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" value="<?php echo  $CHECK_POSTATUS['grand_total'];?>" style="width:100%;" readonly="readonly"  onfocus="cal_grandamount()"/></td>
                </tr>
              </table>
			</td>
			</tr>
		</table>
	</td>
</tr>
</table>
 <input name="Order" type="submit" class="search" value="Process Order" />

 </form>
 <script type="text/javascript">
 
 function calcVatTax(rate)
 {
 	var basic=document.getElementById("total_item_amount").value;
	var pack=document.getElementById("packagingCharges").value;
	var tot=parseFloat(basic)+parseFloat(pack);
	var value=(rate/100)*tot;
	document.getElementById("taxvalue").value=value.toFixed(2);
 }
 
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("hidden_suroct_"+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("taxval_"+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 claculateExcise(i,str)
{
	
	var discounted=document.getElementById("basic_"+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","calculateExcise.php?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();
}

function calculateTotalPrice(i)
{
	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(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 calculateVATCST(str)
{
alert(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 tax_rate(str,i)
{

alert(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;
	var cnt_charge = document.getElementById("countcharges").value;
	if(document.getElementById("QuotationCategory").value == '000')
	{
		alert("Please Select Quotation Category");
		document.getElementById("QuotationCategory").focus();
		return false;
	}
	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("Event").value == '000')
	{
		alert("Please Select Event");
		document.getElementById("Event").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") == '')
	{
		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=0;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_grandamount()
{
	
	var total=document.getElementById("total_item_amount").value;
	var packagingCharges=document.getElementById("pkg_charges").value;
	var Vatcsttaxablevalue=document.getElementById("taxvalue").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(Vatcsttaxablevalue==''){Vatcsttaxablevalue=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;
	
	var grandtotal=parseFloat(total)+parseFloat(Vatcsttaxablevalue)+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_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);	
	 }
	
}

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);
		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(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("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 = 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_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = 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);
		}
	
	}
}
 function uncheck_field(i)
{
	
	
	if(document.getElementById("chk_"+i).checked)
	{	var type=document.getElementById("hid_billing_type_"+i).value='';
				
		
		document.getElementById("Rate_"+i).disabled=false;
		document.getElementById("PerAmo_"+i).disabled=false;
		document.getElementById("Discount_"+i).disabled=false;
		document.getElementById("perc_"+i).disabled=false;
		document.getElementById("NetRate_"+i).disabled=false;
		document.getElementById("SpecialDiscount_"+i).disabled=false;
		document.getElementById("Specialperc_"+i).disabled=false;
		document.getElementById("basic_"+i).disabled=false;
		document.getElementById("hid_billing_type_"+i).disabled=false;
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("ExcisePercentage_"+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("taxvalue_"+i).disabled=false;
		document.getElementById("TotalSpecial_"+i).disabled=false;
		
			
	}	
	else
	{
		
		document.getElementById("Rate_"+i).disabled=true;
		document.getElementById("PerAmo_"+i).disabled=true;
		document.getElementById("Discount_"+i).disabled=true;
		document.getElementById("perc_"+i).disabled=true;
		document.getElementById("NetRate_"+i).disabled=true;
		document.getElementById("SpecialDiscount_"+i).disabled=true;
		document.getElementById("Specialperc_"+i).disabled=true;
		document.getElementById("basic_"+i).disabled=true;
		document.getElementById("hid_billing_type_"+i).disabled=true;
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("ExcisePercentage_"+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("taxvalue_"+i).disabled=true;
		document.getElementById("TotalSpecial_"+i).disabled=true;
		
	}

}

function calsuroctamt(str)
{
var amt=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=parseFloat(document.getElementById("sur_oct_per").value);
var amount=(amt*suroctper)/100;
document.getElementById("sur_oct_amt").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("NetRate_"+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_"+i).value='';
	     document.getElementById("special_discount_"+i).focus();
		return false;
		}
		else
		{
	document.getElementById("special_discount_amount_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+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>
