<?php
$prefixtitle='Process Sale Order';
include('includes/stockcalculation.php');

if(isset($_POST['Submit']) && $_REQUEST['action']=='Edit')
	{
		   
						 
						 
						 $sql = DB_query("update dbl_process_sale_order SET
						`order_type`       ='".$_POST['ordertype']."',
						`SOI_date`	      ='".FormatDateForSQL($_POST['enquiry_date'])."',  
						`customer`	      ='".$_POST['customer']."',  
						`dealer`	      ='".$_POST['dealer']."',
						`zone`	          ='".$_POST['zone']."',
						`subzone`	      ='".$_POST['subzone']."',
						`engineer`	      ='".$_POST['engname']."',
						`enquiry_no`	  ='".$_POST['enquiry']."',
						`consignee_code`  ='".$_POST['consignee_code']."',
						`consignee_Address`  ='".$_POST['consignee_Address']."',
						`vend_code`	      ='".$_POST['vend_code']."',
						`quotation_no`	  ='".$_POST['quotation_no']."',
						`po_no`	          ='".$_POST['po_no']."',
						`po_date`	      ='".FormatDateForSQL($_POST['po_date'])."',
						`po_amount`	      ='".$_POST['po_amt']."',
						`party_date`	  ='".FormatDateForSQL($_POST['part_deliverydate'])."',
						`delivery_date`	  ='".$_POST['delivery_date']."',						
						`adv_amt`	      ='".$_POST['ad_amt']."',
						`sales_remarks`	  ='".trim($_POST['sales_remarks'])."',
						`dispatch_remarks`='".trim($_POST['dispatch_remarks'])."',
						`basic_amt`='".$_POST['basic_amt']."',
						`discount`='".$_POST['discount']."',
						`discount_Amt`='".$_POST['discount_Amt']."',
						`EDBillRate`='".$_POST['EDBillRate']."',
						`totalDiscountedPrice`='".$_POST['totalDiscountedPrice']."',
						`VatCst`='".$_POST['VatCst']."',
						`VatCstValue`='".$_POST['VatCstValue']."',
						`surcharge`='".$_POST['surcharge']."',
						`surcharge_Amt`='".$_POST['surcharge_Amt']."',
						`ecess_per`='".$_POST['ECessPercentage']."',
						`sah_per`='".$_POST['SAHCessPercentage']."',
						`ecess_value`='".$_POST['ECessValue1']."',
						`sah_value`='".$_POST['SAHCessValue1']."',
						`totalexcise`='".$_POST['totalexcise']."',
						`discountAmt`='".$_POST['discountAmt']."',
						`additional_chrg`='".$_POST['additional_chrg']."',
						`p_and_f`         ='".$_POST['p_and_f']."',
						`pnf_amt`         ='".$_POST['pnf_amt']."',
						`Inc_chrg`        ='".$_POST['Inc_chrg']."',
						`incidental_Amt` ='".$_POST['incidental_Amt']."',
						`grand_tatal`='".$_POST['grand_tatal']."',	
						`term_and_condition`='".$_POST['term_and_condition']."',
						`validity`='".FormatDateForSQL($_POST['validity'])."',
						`payment_term`='".$_POST['payment_term']."',						
						`temrs_condition` ='".trim($_POST['temrs_condition'])."'
						 where id='".$_REQUEST['id']."'",$db);						 
						 
	
	$deletebill=DB_query("delete from dbl_process_sale_order_details where parentid='".$_REQUEST['id']."'",$db);
	
	           for($CR=0;$CR<count($_REQUEST['item_code']);$CR++)
					{
						if($_REQUEST['item_code'][$CR]!='')
						{
						  $insert_contact="Insert into dbl_process_sale_order_details set
												parentid='".$_REQUEST['id']."',  
												mst_itemid='".$_REQUEST['item_code'][$CR]."',  
												req_qty ='".$_REQUEST['prqty'][$CR]."', 
												order_qty='".$_REQUEST['orderqty'][$CR]."',  
												rate='".$_REQUEST['rate'][$CR]."',
												pendingQty='".$_REQUEST['orderqty'][$CR]."',
												sub_amt='".$_REQUEST['netrate'][$CR]."',
												discount_type='".$_REQUEST['PerAmo'][$CR]."',
												discount_per='".$_REQUEST['Discount'][$CR]."',
												reserve_po_applicable='".$_REQUEST['reserve'][$CR]."',
												items_date='".FormatDateFORSQL($_REQUEST['items_date'][$CR])."',
												total='".$_REQUEST['total'][$CR]."'";	
						$insert_res=DB_query($insert_contact,$db);			
					   }
						
				   }	
					
	$del_chargedata=DB_query("delete from dbl_sale_order_charge where parentid='".$_REQUEST['id']."'",$db);
				
	for($CR=0;$CR<count($_REQUEST['freight']);$CR++)
	{
	$data11['parentid']=$_REQUEST['id'];
	$data11['charge_per']=$_REQUEST['freight'][$CR];
	$data11['charge_amt']=$_REQUEST['freight_Amt'][$CR];
	$data11['charge_id']=$_REQUEST['chargeid'][$CR];
	$s->RecordInsert('dbl_sale_order_charge', $data11);
	}				
	
$s->pageLocation('index.php?route=DealerDistrbutions/Transaction/process_sale_order_index&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
	}
	
	

if($_REQUEST['action']=='Edit')
{
	$sql=DB_query("select * from dbl_process_sale_order where id='".$_REQUEST['id']."'",$db);
	$row1=DB_fetch_array($sql);
	extract($row1);
	if(isset($_SESSION['dealerid']))
	$function_filter[]=$_SESSION['dealerid'];
	else
	$function_filter[]=$dealer;
	$function_filter[]='';
	$function_filter[]=$SOI_date; 
	$function_filter[]=$SOI_date; 
}


?>



<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css"><h2 align="center"><strong><?php echo $s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'CompanyName'); ?>
</strong></h2>
<h3 align="center" style="text-align:center; font-size:14PX;"><strong>Process Sale Order</strong></h3>
<br />

<form name="form1" action="" method="post" >


<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td class="tabledata1">Order Type<strong><font color="#FF0000"><strong>*</strong></font></strong></td>
    <td width="20%" align="left" valign="top">	
	<input type="text" name="ordertype" id="ordertype" style="width:100%" value="<?php echo $order_type; ?> " readonly >
	</td>
    <td class="tabledata1">Enquiry No<font color="#FF0000"><strong>*</strong></font></td>
	<td width="20%"><input type="text" name="enquire_no" id="enquiry_no" style="width:100%" 
	value="<?php echo $s->getField('dbl_enquiry_form','id',$enquiry_no,'form_no'); ?>" readonly="readonly" />
	<input type="hidden" name="enquiry" id="enquiry" value="<?php echo $enquiry_no; ?>" />
	</td>
<td class="tabledata1">Enquiry Date<font color="#FF0000"><strong>*</strong></font></td>
<td width="20%"><input name="enquiry_date" type="text" style="width:100%"   id="enquiry_date"
	value="<?php echo ConvertSQLDate($s->getField('dbl_enquiry_form','id',$enquiry_no,'date')); ?>" readonly="readonly" /></td>
</tr>
<tr class="row1">

<td class="tabledata1"> Associate Name<strong><font color="#FF0000"><strong>*</strong></font></strong></td>
<td align="left" valign="top"><input name="areaname" type="text" style="width:100%" id="areaname"
value="<?php echo $s->getField('dbl_dealer','id',$dealer,'dealer_name'); ?>" readonly="readonly"  />
<input name='dealer' type='hidden' style='width:100%' id='zone' value="<?php echo $dealer; ?>"  />

</td>
<td class="tabledata1">SOI No<font color="#FF0000"><strong>*</strong></font></td>
<td><input name="soi_no" type="text" style="width:100%" id="soi_no" 
value="<?php if(isset($SOI_no)) { echo $SOI_no; } else { echo "Auto Generate"; }  ?>"  readonly="readonly"/></div></td>
<td class="tabledata1">SOI Date<font color="#FF0000"><strong>*</strong></font></td>
 <td><input name="soi_date" id="soi_date" type="text" style="width:100%"  value="<?php if(isset($SOI_date)){echo ConvertSQLDate($SOI_date);}else{echo date('d/m/Y');} ?>"
   class="datepicker" /> </td>
</tr>

<tr class="row1">

<td class="tabledata1"> Area Name<strong><font color="#FF0000"><strong>*</strong></font></strong></td>
<td align="left" valign="top"><input name="areaname" type="text" style="width:100%" id="areaname"
value="<?php echo $s->getField('zone_master','id',$zone,'ZoneTitle'); ?>" readonly="readonly"  />
<input name='zone' type='hidden' style='width:100%' id='zone' value="<?php echo $zone; ?>"  />

</td>
<td class="tabledata1">Sub Area Name</td>
<td><input name="subareaname" type="text" style="width:100%" id="subareaname" 
value="<?php echo $s->getField('subzone_master','id',$subzone,'subzone'); ?>" readonly="readonly" />
<input name='subzone' type='hidden' style='width:100%' id='subzone' value="<?php echo $subzone; ?>" /></td>
<td class="tabledata1">Engineer Name<font color="#FF0000"><strong>*</strong></font></td>
 <td><input name="engineer_name" id="engineer_name" type="text" style="width:100%"  value="<?php echo $s->getField('dbl_engineer_dealer_maste','id',$engineer,'engineer_name'); ?>"  readonly="readonly" />
 <input name='engname' type='hidden' style='width:100%' id='engname' value="<?php echo $engineer; ?>"  />

 
</td>
</tr>

<tr class="row1">

       <td class="tabledata1">Customer Name </td>
        <td align="left" valign="top" >	
	<select name="customer" id="customer" style="width:100%" >	
	<?php 

	$sql=DB_query("select * from clientmaster where id='".$customer."'",$db);
	while($row1=DB_fetch_array($sql))
	{
	$c='';
	if($row1['id']==$customer)
	$c='selected';
	?>
	<option value="<?php echo $row1['id']; ?>"<?php echo $c; ?>><?php echo $row1['c_name']; ?></option> 
	<?php } ?>
	
	 </select></td>


    
    <td class="tabledata1">Customer Code </td>
    <td><div id="subareacodedata"><input name="customer_code" id="customer_code" type="text" style="width:100%" 
	value="<?php echo $s->getField('clientmaster','id',$customer,'client_code'); ?>"   readonly="readonly" /></td>
   <td class="tabledata1">Engineer Code</td>
    <td><div id="engineercodedata"><input name="engineer_code" id="engineer_code" type="text" style="width:100%" value="<?php echo $s->getField('dbl_engineer_dealer_maste','id',$engineer,'engineer_code'); ?>" readonly="readonly"  /></div></td>
</tr>

<tr class="row1">

 <td class="tabledata1">Consignee Code </td>
 <td align="left" valign="top" ><input name="consignee_code" id="consignee_code" type="text" style="width:100%"
  value="<?php if(isset($consignee_code)) { echo $consignee_code; } ?>" /></td>
 <td class="tabledata1">Vend Code </td>
 <td><input name="vend_code" id="vend_code" type="text" style="width:100%" value="<?php if(isset($vend_code)) { echo $vend_code; } ?>" /></td>
    <td class="tabledata1">Quotation No</td>
    <td><input name="quotation_no" id="quotation_no" type="text" style="width:100%" value="<?php if(isset($quotation_no)) { echo $quotation_no; } ?>"  /></td>
</tr>

<tr class="row1">

 <td class="tabledata1">Consignee Address</td>
 <td align="left" valign="top" ><textarea name="consignee_Address" id="consignee_Address" type="text" style="width:100%" /><?php if(isset($consignee_Address)) { echo $consignee_Address; }else{echo $s->getField('clientmaster','id',$customer,'pre_address1');} ?></textarea></td>
 <td class="tabledata1">PO No<strong><font color="#FF0000"><strong>*</strong></font></strong></td>
 <td align="left" valign="top" ><input name="po_no" id="po_no" type="text" style="width:100%" value="<?php if(isset($po_no)) { echo $po_no; } ?>"  /></td>
<td class="tabledata1">PO Date<font color="#FF0000"><strong>*</strong></font></td>
 <td><input name="po_date" id="po_date" type="text" style="width:100%" value="<?php if(isset($po_date)) { echo $po_date; } ?>"   class="datepicker" /></td>
</tr>
<tr class="row1">

<td class="tabledata1">PO Amount</td>
    <td><input name="po_amt" id="po_amt" type="text" style="width:100%" value="<?php if(isset($po_amount)) { echo $po_amount; } ?>"  /></td>
 
 <td class="tabledata1">Delivery Date </td>
 <td><div id="subareacodedata"><input name="delivery_date" id="delivery_date" type="text" style="width:100%" value="<?php if(isset($delivery_date)) { echo $delivery_date; } ?>"  class="datepicker" /></td>
 <td class="tabledata1">Advance Amount</td>
    <td><input name="ad_amt" id="ad_amt" type="text" style="width:100%" value="<?php if(isset($adv_amt)) { echo $adv_amt; } ?>"  /></td>
</tr>




<tr class="row1">

    <td class="tabledata1">Sales Remarks</td>
    <td colspan="5" align="left" valign="top"><textarea name="sales_remarks" id="sales_remarks"  style="width:100%"><?php echo trim($sales_remarks); ?></textarea></td>
    </tr>
	<tr>
    <td class="tabledata1">Dispatch Remark</td>
    <td colspan="5" align="left" valign="top"><textarea name="dispatch_remarks" id="dispatch_remarks"  style="width:100%"><?php echo trim($dispatch_remarks); ?></textarea></td>
    </tr>
	
<tr class="row1">

   <td class="tabledata1">Terms & Conditions</td>
    <td colspan="5" align="left" valign="top"><textarea name="temrs_condition" id="temrs_condition"  style="width:100%"><?php echo $temrs_condition; ?></textarea></td>
    </tr>
	
</table> 
	
<p align="left">

<!--<input type="button" class="search"  value="Add Charges" onclick="open_items()"  /> -->
<input type="button" class="search"  value="Add Terms" onClick="open_items1()" />                 
</p>

<!--<th align="left" valign="top"><strong>Part Delivery Date<font color="#FF0000"><strong>*</strong></font></strong></th>
 <td align="left" valign="top" ><input name="part_deliverydate" id="part_deliverydate" type="text" style="width:100%" value="<?php //if(isset($party_date)) { echo $party_date; } ?>" class="datepicker" /></td>-->



<div id="alldata">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th ><strong>S.N.</strong></th>
<th >&nbsp;</th>
<th ><strong>Part Number </strong></th>
<th ><strong>Part Name</strong></th>
<th ><strong> UOM</strong></th>
<th><strong>Stock Qty</strong></th>
<th ><strong>PR Qty </strong></th>
<th ><strong>Order Qty</strong></th>
<th ><strong>Rate</strong></th>
<th ><strong>Sub Amt</strong></th>
<th ><strong>Discount Type</strong></th>
<th ><strong>Discount(%)</strong></th>
<th ><strong>Total Amt</strong></th>
<th><strong>Reserve Stock</strong></th>
<th><strong>Delivery Date</strong></th>
</tr>
<?php
$i=0;
$exciseamt12=0;

$sql=DB_query("select * from dbl_process_sale_order_details where parentid='".$_REQUEST['id']."'",$db);
while($row=DB_fetch_array($sql))
{
$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
$unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname'); 

$op=openingBalance($function_filter,$row['mst_itemid']);
$in_1=receivedMRN($function_filter,$row['mst_itemid']);
$out_1=issueSlip($function_filter,$row['mst_itemid']);
$out_2=issueSiteToSite($function_filter,$row['mst_itemid']);		
$in_2=receivedSiteToSite($function_filter,$row['mst_itemid']);
$out_3=issueMatarialReturn($function_filter,$row['mst_itemid']);
$in_3=receivedReturn($function_filter,$row['mst_itemid']);	
$out_4=Rgpchallan($function_filter,$row['mst_itemid']);
$out_5=Nrgp($function_filter,$row['mst_itemid']);
$in_4=Rgpreturn($function_filter,$row['mst_itemid']);	 
$in_5=FinishedMR($function_filter,$row['mst_itemid']);
$out_6=dispatchsaleorder($function_filter,$row['mst_itemid']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);
$tot=$invalue-$outvalue;
$stockbalance=$tot;	


 $pendingqty=$row['pendingQty'];




$rate=$row['rate'];

if($pendingqty!='')
{
$orderqty=$pendingqty;
}
else
{
$orderqty=$row['req_qty'];
}
 $rowtype=$s->getField('item_master','id',$row['mst_itemid'],'item_exciable');
if($rowtype=='exciable')
{
$exciseamt12=$exciseamt12+$row['total'];
}


?>
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><?php echo $i+1; ?></td>	
<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" value="<?php echo $row['mst_itemid']; ?>" /></td>
<td class="tabledata"><?php echo $itemcode; ?> <input type="hidden" name="rowid[]" value="<?php echo $row['id']; ?>" /> </td>
<td class="tabledata" style="white-space:nowrap"><?php echo $itemname; ?></td>
<td class="tabledata"><?php echo $unitname; ?>
<input type="hidden" name="type[]" id="type1_<?php echo $i; ?>" value="<?php echo $rowtype; ?>" readonly="readonly" />

</td>
<td class="tabledata"><?php echo $stockbalance; ?></td>
<td class="tabledata"><input type="text" name="prqty[]" value="<?php echo $pendingqty; ?>" id="prqty_<?php echo $i; ?>" style="width:50;" readonly="readonly"/></td>
<td class="tabledata"><input type="text" name="orderqty[]" id="orderqty_<?php echo $i; ?>" style="width:50;"  value="<?php echo $orderqty; ?>" onKeyUp="caldispatch(<?php echo $i; ?>)" /></td>
<td class="tabledata"><input type="text" name="rate[]"  id="rate_<?php echo $i; ?>" style="width:40;"  onkeyup="calamt(this.value,<?php echo $i; ?>)" value="<?php echo $rate; ?>" readonly="readonly" /></td>
<td class="tabledata"><input type="text" name="netrate[]"  id="netrate_<?php echo $i; ?>" style="width:60;" value="<?php echo $row['sub_amt']; ?>" readonly="readonly" onFocus="calamt1(this.value,<?php echo $i; ?>)" /></td>
<td class="tabledata"><select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i; ?>">
<option value="Amount" <?php if($row['discount_type']=='Amount') { ?> selected="selected" <?php } ?> >Amount</option>
<option value="PercentAmt" <?php if($row['discount_type']=='PercentAmt') { ?> selected="selected" <?php } ?>>Percent Amt</option>
</select></td>
<td class="tabledata"><input type="text"  name="Discount[]" id="Discount_<?php echo $i; ?>" onBlur="DiscountAmount(this.value,<?php echo $i; ?>)" style="width:60;" value="<?php echo $row['discount_per']; ?>" /></td>		  
<td class="tabledata"><input type="text" name="total[]" id="total_<?php echo $i; ?>" style="width:50px;"  readonly="true"
value="<?php echo $row['total']; ?>" 
 /></td>
  <td class="tabledata"><select name="reserve[]" id="reserve_<?php echo $i; ?>" style="width:40px;">
 <option value="N" <?php if($row['reserve_po_applicable']=='N') { ?> selected="selected" <?php } ?>>No</option>
  <option value="Y"<?php if($row['reserve_po_applicable']=='Y') { ?> selected="selected" <?php } ?>>Yes</option>
 </select>
 </td>
 <td class="tabledata"><input type="text" style="width:60;" class="datepicker" name="items_date[]" id="items_date_<?php echo $i; ?>"  value="<?php echo ConvertSQLDate($row['items_date']); ?>"  /></td>
</tr>

<?php $i++; } ?>
<input type="hidden" name="count" id="count" value="<?php echo $i; ?>" />
</table>
</div>

<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="50%" valign="top">
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
			<tr class="row1">
				<td class="tabledata1">Term & Conditions</td>
				<td><input type="text" name="term_and_condition" id="term_and_condition" value="<?php echo $term_and_condition; ?>" style="width:150px;" /></td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">Validity</td>
				<td><input type="text" name="validity" id="validity" value="<?php echo ConvertSQLDate($validity); ?>" class="datepicker" style="width:150px;" /></td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">Payment Terms</td>
				<td><select name="payment_term" id="payment_term" style="width:150px;">
						<option value="">Select</option>
						<?php $SQLP=DB_query("SELECT * FROM paymentterms",$db);
						while($Payment=DB_fetch_array($SQLP)) {
						$selA='';
						if($payment_term==$Payment['termsindicator'])
						$selA='selected';
						?>
						<option value="<?php echo $Payment['termsindicator']; ?>" <?php echo $selA; ?>><?php echo $Payment['terms']; ?></option>
						<?php } ?>
					</select>
				</td>
			</tr>
		</table>
	</td>
	<td width="50%" valign="top">
		<table width="100%" border="1" cellpadding="3" cellspacing="0">
			<tr class="row1">
				<td class="tabledata1">Basic Amount</td>
				<td><input type="text"  name="basic_amt" id="basic_amt" style="width:70px;"  onfocus="calamount()"  value="<?php echo $basic_amt; ?>" readonly /></td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">Discount</td>
				<td><input type="text" name="discount" id="discount" value="<?php echo $discount; ?>" style="width:60px;" readonly />
				<input type="text" name="discount_Amt" id="discountAmt" onFocus="caldiscountAmt()" value="<?php echo $discount_Amt; ?>" style="width:90px;" readonly="readonly" />
				</td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">Discounted Amount </td>
				<td><input type="text" name="discountAmt" id="discount_Amt"  value="<?php echo $discountAmt; ?>" style="width:150px;" readonly="readonly" />
				</td>
			</tr>
			<tr class="row1">
			<td class="tabledata1">P & F  </td>
				<td><input type="text" name="p_and_f" id="p_and_f" value="<?php echo $p_and_f; ?>" style="width:60px;" readonly />
				<input type="text" name="pnf_amt" id="pnf_amt" onfocus="calpnfAmt()" value="<?php echo $pnf_amt; ?>"  style="width:90px;" readonly="readonly" />
				</td>
			</tr>
			<tr class="row1">
			<td class="tabledata1">Excise Item Total Amount </td>
				<td><input type="text" name="excise_value" id="excise_value" value="<?php echo $exciseamt12; ?>" readonly />
				</td>
			</tr>
			<tr class="row1"><?php 
			if($exciseamt12!=0)
			{
			$exciseamt_dis=($exciseamt12*$discount)/100;
			$exciseamt_dis1=$exciseamt12-$exciseamt_dis;
			}
			else
			$exciseamt_dis1=0;
			 ?>
			<td class="tabledata1">Excise Item After Discount </td>
				<td><input type="text" name="excise_value1" id="excise_value1" value="<?php echo $exciseamt_dis1; ?>" readonly />
				</td>
			</tr>
			
			<tr class="row1">
				<td class="tabledata1">Excise Duty</td>
				<td><select name="EDBillRate" id="EDRate" style="width:150px" onChange="calculateBillExcise(this.value)"  >
						<option value="0">--Select--</option>
						<?php
						$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
						$ServiceRes=DB_query($ServiceSql,$db);
						while($ServiceRow=DB_fetch_array($ServiceRes))
						{
						$selA11='';
						if($EDBillRate==$ServiceRow['id'])
						$selA11='selected';
						?>
			<option value="<?php echo $ServiceRow['id'];?>" <?php echo $selA11; ?>><?php echo $ServiceRow['caption']?></option>
						<?php }	?>
						</select>
			<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" 
			value="<?php echo $totalDiscountedPrice; ?>"  style="width:90px;" 
			onfocus="calculateTotalExcise()" readonly="readonly"/>
						</td>
			</tr>
			
			<?php 
			$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			$k=1;
			while($cessRow=DB_fetch_array($cessSql))
			{
			$caption[$k]=$cessRow['caption']; 
			
			$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
			while($rate_row=DB_fetch_array($rate_sql))
			{
			$rate[$k]=$rate_row['def_rate'];
			}
			$k++;
			} 
			?>
			<tr>
					<td class="tabledata1">E-Cess</td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue1" id="ECessValue" type="text" value="<?php echo $ecess_value?>" style="width:120px;" readonly onFocus="calculateECess1()" /></td>
					</tr>
			<tr >
					<td class="tabledata1">SAH-E Cess</td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue1" id="SAHCessValue" type="text" value="<?php echo $sah_value?>" style="width:120px;" readonly onFocus="calculateSAHCess1()" /></td>
					</tr>
					
				<tr>
				<td class="tabledata1">Total Excise Amout</td>
<td><input name="totalexcise" id="totalDiscountedamount" type="text" value="<?php echo $totalexcise; ?>" style="width:120px;" readonly onFocus="caltotalexciseamt()" /></td>
				
				</tr>	
			
			
			<tr class="row1">
				<td class="tabledata1">Sales Tax</td>
				<td><select name="VatCst" id="value3" onChange="calculateVATCST(this.value)" style="width:150px;">
						<option value="" >Select</option>
						<?php 
						$salesSql=DB_query("Select * from sales_tax_master",$db);
						while($salesRow=DB_fetch_array($salesSql))
						{?>
						<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
						<?php 	
						}
						?>
						</select>
						<div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:150px;" readonly  onfocus="calculateEditVATCST()"  /></div>
						<?php $rate2=$s->getField('sales_tax_master','salestax_id',$VatCst,'taxrate'); ?>
						<input type="hidden" name="" id="rate" value="<?php echo $rate2;?>" /> </td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">Incidental Charges</td>
				<td><input type="text" name="Inc_chrg" id="Inc_chrg" value="<?php echo $Inc_chrg; ?>" style="width:60px;" onfocus="calincidentalchrg(this.value)" />
					<input type="text" name="incidental_Amt" id="incidental_Amt" value="<?php echo $incidental_Amt; ?>"  style="width:90px;" readonly="readonly" />
				</td>
			</tr>
			<tr class="row1">
				<td class="tabledata1">SurCharges</td>
				<td><input type="text" name="surcharge" id="surcharge" value="<?php echo $surcharge; ?>" style="width:60px;" />
					<input type="text" name="surcharge_Amt" id="surcharge_Amt" value="<?php echo $surcharge_Amt; ?>" onFocus="calsurchrg()" style="width:90px;" readonly="readonly" />
				</td>
			</tr>
			<?php 
			$u=1;
			
			$sql_charge=DB_query("select * from dbl_sale_order_charge where parentid='".$_REQUEST['id']."'",$db);
					
			while($row12=DB_fetch_array($sql_charge))
			{
			?>
			<tr class="row1">
			<input type='hidden' name='chargeid[]' value='<?php echo $row12['charge_id']; ?>'>
		<td class="tabledata1"><?php echo $s->getField('dbl_dealer_charge_master','id',$row12['charge_id'],'charge_name'); ?></td>
				<td><input type="text" name="freight[]" id="freight_<?php echo $u; ?>" value="<?php echo $row12['charge_per']; ?>"  style="width:60px;" readonly="readonly"  />
					<input type="text" name="freight_Amt[]" id="freight_Amt_<?php echo  $u; ?>" value="<?php echo $row12['charge_amt']; ?>" style="width:90px;" onFocus="calfreight(<?php echo $u; ?>)"  readonly/>
				</td>
			</tr>
			<?php $u++; }?>
			<input type='hidden' id='charge_count' name='charge_count' value='<?php echo $u; ?>'>
			
			<tr class="row1">
				<td class="tabledata1"><strong>Grand Total</strong></td>
				<td><input type="text" name="grand_tatal" id="grand_tatal" value="<?php echo $grand_tatal; ?>" onFocus="calgrandTotal()" style="width:150px;" readonly="readonly" /></td>
			</tr>
		</table>
	</td>
</tr>
</table>

<p align="center">
  <input type="submit" name="Submit" onClick="return validate();" value="Save"  />
  
 
</p>
</form>
<script>
function calamt(str,i)
{
if(document.getElementById("orderqty_"+i).value=='')
var qty=0;
else
var qty=parseFloat(document.getElementById("orderqty_"+i).value);
if(str!='')
var amount=parseFloat(str)*qty;
else
var amount=0;
document.getElementById("netrate_"+i).value=amount.toFixed(2);
}

function calamt1(str,i)
{
var str1=document.getElementById("rate_"+i).value;
if(document.getElementById("orderqty_"+i).value=='')
var qty=0;
else
var qty=parseFloat(document.getElementById("orderqty_"+i).value);
if(str1!='')
var amount=parseFloat(str1)*qty;
else
var amount=0;
document.getElementById("netrate_"+i).value=amount.toFixed(2);
}


function DiscountAmount(DA,i)
{
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var rate = document.getElementById("netrate_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	
	var totalPrice = 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("total_"+i).value=subTotal.toFixed(2);
	
	
}	

function open_items()
{
window.open("charges_items.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>","itempopup_window","height=500,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function open_items1()
{
window.open("saleorder_temscondition.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=480,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}


function calamount()
{
var amount=0;
var amount1=0;
var count1=document.getElementById("count").value;
for(var i=0;i<count1;i++)
{
if(document.getElementById("total_"+i).value!='')
{
amount=parseFloat(amount)+parseFloat(document.getElementById("total_"+i).value);
if(document.getElementById("type1_"+i).value=='exciable')
{
amount1=parseFloat(amount1)+parseFloat(document.getElementById("total_"+i).value);
}
}


}
document.getElementById("basic_amt").value=amount.toFixed(2);
document.getElementById("excise_value").value=amount1.toFixed(2);
}

function calsalamt()
{
var amount=0;
var amount1=0;
var totalamt=0;
var count=document.getElementById("hiditemcount").value;
var count1=document.getElementById("cout1").value;
if(count=='' && count1=='')
{
document.getElementById("total_sal_amt").value=document.getElementById("grnad_total").value;
}
else
{

for($t=1;$t<count1;$t++)
{
if(document.getElementById("chargeid1_"+k))
{
if(document.getElementById("chargeid1_"+k).value!='')
{
amount1=parseFloat(amount1)+parseFloat(document.getElementById("chargeper1_"+k).value);
}
}
}
if(document.getElementById("chargeper").value!='')
var firstamt=document.getElementById("chargeper").value;
else
var firstamt=0;
for(var k=1;k<=count;k++)
{
if(document.getElementById("chargeid_"+k))
{
if(document.getElementById("chargeid_"+k).value!='')
{
amount=parseFloat(amount)+parseFloat(document.getElementById("chargeper_"+k).value);
}
}
}

amount=parseFloat(firstamt)+amount+amount1;
totalamt=(parseFloat(document.getElementById("grnad_total").value)*amount)/100;
totalamt1=(parseFloat(document.getElementById("grnad_total").value)+parseFloat(totalamt));
document.getElementById("total_sal_amt").value=totalamt1.toFixed(2);
}






}

function caldispatch(str)
{
if(parseFloat(document.getElementById("orderqty_"+str).value)>parseFloat(document.getElementById("prqty_"+str).value))
{
alert("Order Qty Should Be less then Order Qty");
document.getElementById("orderqty_"+str).value='';
document.getElementById("orderqty_"+str).focus();
}






}


function showshortdata(str,str1)
{

if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
document.getElementById("alldata").innerHTML=xmlhttp.responseText;
  }
}

var enquiry=document.getElementById("enquiry").value;
xmlhttp.open("GET","showshorteddata1.php?site="+str+"&id="+str1,true);
xmlhttp.send();
}
</script>
<script type="text/javascript" language="javascript">
function validate()
{
	if(document.getElementById("ordertype").value=='0')
	{
		alert("Please Select The Order Type First");
		document.getElementById("ordertype").focus();
		return false;
	}
	if(document.getElementById("soi_date").value=='')
	{
		alert("Please Fill SOI Date First");
		document.getElementById("soi_date").focus();
		return false;
	}
	if(document.getElementById("po_no").value=='')
	{
		alert("Please Fill The PO No First");
		document.getElementById("po_no").focus();
		return false;
	}
	if(document.getElementById("po_date").value=='')
	{
		alert("Please Fill The PO Date First");
		document.getElementById("po_date").focus();
		return false;
	}
	if(document.getElementById("part_deliverydate").value=='')
	{
		alert("Please Fill The Part Delivery Date First");
		document.getElementById("part_deliverydate").focus();
		return false;
	}
	var count1=document.getElementById("count").value;
	var to=0;
	for(var i=0;i<count1;i++)
	{
		if(document.getElementById("orderqty_"+i).value!='' && document.getElementById("rate_"+i).value!='' && document.getElementById("rate_"+i).value!='' && document.getElementById("total_"+i).value!='')
		{
			to=1;
			break; 
		}
	}
	if(to==0)
	{
		alert("Please Fill The Items Field");
		return false;
	}
	
	if(document.getElementById("grnad_total").value=='' || document.getElementById("grnad_total").value=='0.00')
	{
		alert("Please Fill The Grand Total First");
		document.getElementById("grnad_total").focus();
		return false;
	}
	if(document.getElementById("total_sal_amt").value=='' || document.getElementById("total_sal_amt").value=='0.00')
	{
		alert("Please Fill Total Sales Order Amount First");
		document.getElementById("total_sal_amt").focus();
		return false;
	}
	
}

function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 1) 
	{
	alert("Cannot delete all the rows.");
	break;
	}
	table.deleteRow(i);
	rowCount--;
	i--;
	}
	}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
	alert(e);
	}
}



function showamount(str)
{
if(document.getElementById("grnad_total").value=='')
var amt=0;
else
var amt=parseFloat(document.getElementById("grnad_total").value);
var per=parseFloat(document.getElementById("chargeper1_"+str).value);
var amount=(amt*per)/100;
document.getElementById("chargeamt1_"+str).value=amount.toFixed(2);


}

function showamount1(str)
{
if(document.getElementById("grnad_total").value=='')
var amt=0;
else
var amt=parseFloat(document.getElementById("grnad_total").value);

var i=str.split("_");
if(i[1]==undefined)
{
if(document.getElementById("chargeper").value!='')
{
var per=parseFloat(document.getElementById("chargeper").value);
var amount=(amt*per)/100;
document.getElementById("chargeamt").value=amount.toFixed(2);
}
else
{
var per=0;
var amount=0;
document.getElementById("chargeamt").value=amount.toFixed(2);
}


}
else
{
var j=i[1];
if(document.getElementById("chargeper_"+j).value!='')
{
var per=parseFloat(document.getElementById("chargeper_"+j).value);
var amount=(amt*per)/100;
document.getElementById("chargeamt_"+j).value=amount.toFixed(2);
}
else
{
document.getElementById("chargeamt_"+j).value=0;
}
}
}

function calculateBasicAmt()
{
var firstrow=parseFloat(document.getElementById("total").value);
	var count=document.getElementById("hiditemcount").value;
	if(count!='')
	{
		var totalprice=0;
		for(var i=1;i<count;i++)
		{
		
	      if(document.getElementById("total_"+i).value!='')
			totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("total_"+i).value);
			else
			totalprice=0;
			
		}
		var amt=totalprice+firstrow;
		document.getElementById("basic_amt").value=amt.toFixed(2);
	}
	
	if(document.getElementById("manualitems").style.display=='block')
	{
	var count1=document.getElementById("hiditemcount11").value;
	if(count1!='')
	{
	var pricTotal=0;
		for(var i=0;i<count1;i++)
		{
			if(document.getElementById("total123_"+i).value!='')
			pricTotal=parseFloat(pricTotal)+parseFloat(document.getElementById("total123_"+i).value);
			else
			pricTotal=0;
		}
		document.getElementById("basic_amt").value=pricTotal.toFixed(2);
	}
	}
	
}

//function caldiscountAmt()
//{
//	var basic=parseFloat(document.getElementById("basic_amt").value);
//	var discount;
//	if(document.getElementById("discount").value=='')
//	{
//	discount=0;
//	}
//	else
//	{
//	 discount=parseFloat(document.getElementById("discount").value);
//	}
//	if(discount==0)
//	{
//	document.getElementById("discountAmt").value=0;
//	document.getElementById("discount_Amt").value=basic.toFixed(2);
//	}
//	else
//	{
//	var disAmt=(basic*discount)/100;
//	document.getElementById("discountAmt").value=disAmt.toFixed(2);
//	var amt=basic-parseFloat(disAmt);
//	document.getElementById("discount_Amt").value=amt.toFixed(2);
//	}
//}


function caldiscountAmt()
{   
   if(document.getElementById("basic_amt").value!='')
	var basic=parseFloat(document.getElementById("basic_amt").value);
	else
	var basic=0;
	if(document.getElementById("excise_value").value!='')
	var excise_amt=parseFloat(document.getElementById("excise_value").value);
	else
	var excise_amt=0;
	var discount;
	if(document.getElementById("discount").value=='')
	{
	discount=0;
	}
	else
	{
	 discount=parseFloat(document.getElementById("discount").value);
	}
	if(discount==0)
	{
	document.getElementById("discountAmt").value=0;
	document.getElementById("discount_Amt").value=basic.toFixed(2);
	document.getElementByid("excise_value1").value=excise_amt.toFixed(2);
	if(document.getElementById("p_and_f").value!='')
	var pnf=parseFloat(document.getElementById("p_and_f").value);
	else
	var pnf=0;
	var discount_pnf=(parseFloat(basic)*pnf)/100;
	document.getElementByid("pnf_amt").value=discount_pnf.toFixed(2);
	}
	else
	{
	var disAmt=(basic*discount)/100;
	var disexciseamt=(excise_amt*discount)/100;
	document.getElementById("discountAmt").value=disAmt.toFixed(2);
	var amt=basic-parseFloat(disAmt);
	var amt1=excise_amt-parseFloat(disexciseamt);
	if(document.getElementById("p_and_f").value!='')
	var pnf=parseFloat(document.getElementById("p_and_f").value);
	else
	var pnf=0;
	var discount_pnf=(parseFloat(amt)*pnf)/100;
	document.getElementById("pnf_amt").value=discount_pnf.toFixed(2);
	document.getElementById("discount_Amt").value=amt.toFixed(2);
	document.getElementById("excise_value1").value=amt1.toFixed(2);
	
	}
}



function calculateBillExcise(str)
	{
		var value=document.getElementById("excise_value1").value;
		if(str.length==0)
		{
		document.getElementById("totalDiscountedPrice").innerHTML="";
		return;
		}
		if(window.XMLHttpRequest)
		{
		xmlhttp=new XMLHttpRequest();
		}
		else
		{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
		}
		}
		if(document.getElementById("p_and_f"),value!='')
		var pnf=parseFloat(document.getElementById("p_and_f").value);
		else
		var pnf=0;
		var pnf_excise=(parseFloat(value)*pnf)/100;
		
		var amount=parseFloat(value)+parseFloat(pnf_excise);
		
		xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+amount,true);
		xmlhttp.send();	
	}


function calculateECess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}
function calculateSAHCess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function caltotalexciseamt()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var exciseValue=document.getElementById("totalDiscountedPrice").value;
else
var exciseValue=0;
if(document.getElementById("ECessValue").value!='')
var ecessvalue=document.getElementById("ECessValue").value;
else
var ecessvalue=0;
if(document.getElementById("SAHCessValue").value!='')
var SAHCessValue=document.getElementById("SAHCessValue").value;
else
var SAHCessValue=0;

var amt=parseFloat(exciseValue)+parseFloat(ecessvalue)+parseFloat(SAHCessValue);

document.getElementById("totalDiscountedamount").value=amt.toFixed(2);



}
function calculateVATCST(str)
{
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("rate").value=data[0];
	document.getElementById("VatCstValue").value=data[1];
	}
	}
	var amt1=document.getElementById("totalDiscountedamount").value;
	var amt2=document.getElementById("discount_Amt").value;
	var amount=parseFloat(amt1)+parseFloat(amt2);
	//var amt1=document.getElementById("totalDiscountedamount").value;
	xmlhttp.open("GET","calculateExcise.php?salesIdamount="+str+"&amt="+amount,true);
	xmlhttp.send();
}



function calsurchrg()
{
	var salamt=parseFloat(document.getElementById("VatCstValue").value);
	var surchrg;
	if(document.getElementById("surcharge").value=='')
	{
		surchrg=0;
	}
	else
	{
		surchrg=parseFloat(document.getElementById("surcharge").value);
	}
	if(surchrg==0)
	{
		document.getElementById("surcharge_Amt").value=0;
	}
	else
	{
		var suramt=(salamt*surchrg)/100;
		document.getElementById("surcharge_Amt").value=suramt.toFixed(2);
	}
}

function calfreight(i)
{
    if(document.getElementById("discount_Amt").value!='')
	var basic=parseFloat(document.getElementById("discount_Amt").value);
	else
	var basic=0;
	if(document.getElementById("freight_"+i).value!='')
	var freihgt=parseFloat(document.getElementById("freight_"+i).value);
	else
	var freihgt=0;
	var totalfr=(basic*freihgt)/100;
	document.getElementById("freight_Amt_"+i).value=totalfr;
	
}

function calgrandTotal()
{    
    var  Freight=0;
	//var basicamt=document.getElementById("basic_amt").value;
	var discAmt=document.getElementById("discount_Amt").value;
	var ExciseAmt=document.getElementById("totalDiscountedPrice").value;
	var vatAmt=document.getElementById("VatCstValue").value;
	var SurAmt=document.getElementById("surcharge_Amt").value;
	if(document.getElementById("charge_count"))
	{
	var count1=document.getElementById("charge_count").value;
	if(count1!='')
	{
	for(var i=1;i<count1;i++)
	{
	 Freight=parseFloat(Freight)+parseFloat(document.getElementById("freight_Amt_"+i).value);
	}
	}
	}
	else
	{
	Freight=0;
	}
	
	var PF=document.getElementById("pnf_amt").value;
	var IncChrg=document.getElementById("incidental_Amt").value;
	//var AddChrg=document.getElementById("additional_chrg").value;
	var ecess=document.getElementById("ECessValue").value;
	var sahcess=document.getElementById("SAHCessValue").value;
	
	//if(basicamt==''){basicamt=0;}
	if(discAmt==''){discAmt=0;}
	if(ExciseAmt==''){ExciseAmt=0;}
	if(vatAmt==''){vatAmt=0;}
	if(SurAmt==''){SurAmt=0;}
	if(Freight==''){Freight=0;}
	if(PF==''){PF=0;}
	if(IncChrg==''){IncChrg=0;}
	//if(AddChrg==''){AddChrg=0;}
	if(ecess==''){ecess=0;}
    if(sahcess==''){sahcess=0;}

/*	var Total=parseFloat(discAmt)+parseFloat(ExciseAmt)+parseFloat(vatAmt)+parseFloat(SurAmt)+parseFloat(Freight)+parseFloat(PF)+parseFloat(IncChrg)+parseFloat(AddChrg)+parseFloat(ecess)+parseFloat(sahcess);
	*/
	
	var Total=parseFloat(discAmt)+parseFloat(ExciseAmt)+parseFloat(vatAmt)+parseFloat(SurAmt)+parseFloat(Freight)+parseFloat(ecess)+parseFloat(sahcess)+parseFloat(PF)+parseFloat(IncChrg);
	
document.getElementById("grand_tatal").value=Total.toFixed(2);
}

function calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	var first_row=document.getElementById("excise_value1").value;
	if(first_row==''){first_row=0;}	
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
	}
	}
	if(document.getElementById("p_and_f").value!='')
	var pnf=parseFloat(document.getElementById("p_and_f").value);
	else
	var pnf=0;
	var pnf_excise=(parseFloat(first_row)*pnf)/100;
	
	var amount=parseFloat(first_row)+parseFloat(pnf_excise);
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+EDRate+"&value="+amount,true);
	xmlhttp.send();	
	
}


//function calgrandTotal()
//{    
//    var  Freight=0;
//	//var basicamt=document.getElementById("basic_amt").value;
//	var discAmt=document.getElementById("discount_Amt").value;
//	var ExciseAmt=document.getElementById("totalDiscountedPrice").value;
//	var vatAmt=document.getElementById("VatCstValue").value;
//	var SurAmt=document.getElementById("surcharge_Amt").value;
//	var count1=document.getElementById("charge_count").value;
//	if(count1!='')
//	{
//	for(var i=1;i<count1;i++)
//	{
//	 Freight=parseFloat(Freight)+parseFloat(document.getElementById("freight_Amt_"+i).value);
//	}
//	}
//	
//	/*var PF=document.getElementById("p_and_f_Amt").value;
//	var IncChrg=document.getElementById("Inc_chrg_Amt").value;*/
//	var AddChrg=document.getElementById("additional_chrg").value;
//	var ecess=document.getElementById("ECessValue").value;
//	var sahcess=document.getElementById("SAHCessValue").value;
//	
//	//if(basicamt==''){basicamt=0;}
//	if(discAmt==''){discAmt=0;}
//	if(ExciseAmt==''){ExciseAmt=0;}
//	if(vatAmt==''){vatAmt=0;}
//	if(SurAmt==''){SurAmt=0;}
//	if(Freight==''){Freight=0;}
//	/*if(PF==''){PF=0;}
//	if(IncChrg==''){IncChrg=0;}*/
//	if(AddChrg==''){AddChrg=0;}
//	if(ecess==''){ecess=0;}
//    if(sahcess==''){sahcess=0;}
//
///*	var Total=parseFloat(discAmt)+parseFloat(ExciseAmt)+parseFloat(vatAmt)+parseFloat(SurAmt)+parseFloat(Freight)+parseFloat(PF)+parseFloat(IncChrg)+parseFloat(AddChrg)+parseFloat(ecess)+parseFloat(sahcess);
//	*/
//	
//	var Total=parseFloat(discAmt)+parseFloat(ExciseAmt)+parseFloat(vatAmt)+parseFloat(SurAmt)+parseFloat(Freight)+parseFloat(AddChrg)+parseFloat(ecess)+parseFloat(sahcess);
//	
//	document.getElementById("grand_tatal").value=Total.toFixed(2);
//}




function calfreight(i)
{
    if(document.getElementById("basic_amt").value!='')
	var basic=parseFloat(document.getElementById("basic_amt").value);
	else
	var basic=0;
	if(document.getElementById("freight_"+i).value!='')
	var freihgt=parseFloat(document.getElementById("freight_"+i).value);
	else
	var freihgt=0;
	var totalfr=(basic*freihgt)/100;
	document.getElementById("freight_Amt_"+i).value=totalfr;
	
}





function calsurchrg()
{
	var salamt=parseFloat(document.getElementById("VatCstValue").value);
	var surchrg;
	if(document.getElementById("surcharge").value=='')
	{
		surchrg=0;
	}
	else
	{
		surchrg=parseFloat(document.getElementById("surcharge").value);
	}
	if(surchrg==0)
	{
		document.getElementById("surcharge_Amt").value=0;
	}
	else
	{
		var suramt=(salamt*surchrg)/100;
		document.getElementById("surcharge_Amt").value=suramt.toFixed(2);
	}
}






function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	if(document.getElementById("totalDiscountedamount").value!='')
	var taxableAmount=document.getElementById("totalDiscountedamount").value;
	else
	var taxableAmount=0;	
	if(document.getElementById("discount_Amt").value!='')
	var taxableAmount1=document.getElementById("discount_Amt").value;
	else
	var taxableAmount1=0;
	if(document.getElementById("pnf_amt").value!='')
	var taxableAmount2=document.getElementById("pnf_amt").value;
	else
	var taxableAmount2=0;
	var taxamt11=parseFloat(taxableAmount)+parseFloat(taxableAmount1)+parseFloat(taxableAmount2);
	var vat_cst=taxamt11*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}


function calculateVATCST(str)
{
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("rate").value=data[0];
	document.getElementById("VatCstValue").value=data[1];
	}
	}
	var amt1=document.getElementById("totalDiscountedamount").value;
	var amt2=document.getElementById("discount_Amt").value;
	var amt3=document.getElementById("pnf_amt").value;
	
	var amount=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);

	xmlhttp.open("GET","calculateExcise.php?salesIdamount="+str+"&amt="+amount,true);
	xmlhttp.send();
}





function calculateSAHCess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}






function calculateECess1()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}














function caldiscountAmt()
{
	var basic=parseFloat(document.getElementById("basic_amt").value);
	var discount;
	if(document.getElementById("discount").value=='')
	{
	discount=0;
	}
	else
	{
	 discount=parseFloat(document.getElementById("discount").value);
	}
	if(discount==0)
	{
	document.getElementById("discountAmt").value=0;
	document.getElementById("discount_Amt").value=basic.toFixed(2);
	}
	else
	{
	var disAmt=(basic*discount)/100;
	document.getElementById("discountAmt").value=disAmt.toFixed(2);
	var amt=basic-parseFloat(disAmt);
	document.getElementById("discount_Amt").value=amt.toFixed(2);
	}
}


function calincidentalchrg(str)
{
if(document.getElementById("discount_Amt").value!='')
var discountamt=parseFloat(document.getElementById("discount_Amt").value);
else
var discountamt=0;
if(document.getElementById("pnf_amt").value!='')
var pnf=parseFloat(document.getElementById("pnf_amt").value);
else
var pnf=0;
var totalamt=parseFloat(discountamt)+parseFloat(pnf);
var totalamt1=(parseFloat(totalamt)*parseFloat(str))/100;
document.getElementById("incidental_Amt").value=totalamt1.toFixed(2);







}


</script>

