<?php
$prefixtitle='Process Sale Order';
include('includes/stockcalculation.php');
if(isset($_POST['Submit']))
{							
	 $prefixtype=$s->getField('dbl_prefix_tbl','prefix_name',$prefixtitle,'prefix_code');	
	$SQLMax=DB_query("select SOI_no as QutNo from dbl_process_sale_order order by id desc limit 0,1 ",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$MXNo=substr($MaxQut['QutNo'],-4);
	$FinMx=$MXNo+1;
	$FinalCode=$prefixtype."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$prefixtype."/".'00001';
	}										 
	
	 $sql = "INSERT dbl_process_sale_order SET
	`order_type`       ='".$_POST['ordertype']."',
	`SOI_no`	      ='".$FinalCode."', 
	`SOI_date`	      ='".FormatDateForSQL($_POST['soi_date'])."',  
	`customer`	      ='".$_POST['customer']."',  
	`dealer`	      ='".$_POST['dealer']."',
	`zone`	          ='".$_POST['zone']."',
	`subzone`	      ='".$_POST['subzone']."',
	`consignee_code`  ='".$_POST['consignee_code']."',
	`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`	  ='".FormatDateForSQL($_POST['delivery_date'])."',						
	`adv_amt`	      ='".$_POST['ad_amt']."',
	`sales_remarks`	  ='".trim($_POST['sales_remarks'])."',
	`dispatch_remarks`='".trim($_POST['dispatch_remarks'])."',
	`temrs_condition` ='".trim($_POST['terms_condition'])."',
	`validity`        ='".FormatDateForSQL($_POST['validity'])."',
	`payment_term`    ='".$_POST['payment_term']."',
	`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']."',	
	`type`            ='Direct',
	`company`	      ='".$_SESSION['ACGCompanyId']."'";						
	
	$res = DB_query($sql,$db,$ErrMsg,$DbgMsg);
	$lastid=DB_Last_Insert_ID($db,'dbl_process_sale_order', 'id');
	
	
	for($CR=0;$CR<count($_REQUEST['item_code']);$CR++)
	{
	if($_REQUEST['item_code'][$CR]!='' && $_REQUEST['orderqty'][$CR])
	{
	
	$insert_contact="Insert into dbl_process_sale_order_details set
		parentid='".$lastid."',  
		mst_itemid='".$_REQUEST['item_code'][$CR]."',  
		req_qty ='".$_REQUEST['prqty'][$CR]."', 
		order_qty='".$_REQUEST['orderqty'][$CR]."',  
		rate='".$_REQUEST['rate'][$CR]."',
		sub_amt='".$_REQUEST['netrate'][$CR]."',
		discount_type='".$_REQUEST['PerAmo'][$CR]."',
		pendingQty='".$_REQUEST['orderqty'][$CR]."',
		discount_per='".$_REQUEST['Discount'][$CR]."',
		reserve_po_applicable='".$_REQUEST['reserve'][$CR]."',
		total='".$_REQUEST['total'][$CR]."'";	
	 $insert_res=DB_query($insert_contact,$db);		
	
	}
	
	}
	    for($CR=0;$CR<count($_REQUEST['freight']);$CR++)
			{
			$data11['parentid']=$lastid;
			$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_salesorder_details&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}

if(isset($_POST['Submit']) && $_REQUEST['action']=='Edit')
	{
	
						 
						 $sql = DB_query("update dbl_process_sale_order SET
						`order_type`       ='".$_POST['ordertype']."',
						`SOI_date`	      ='".FormatDateForSQL($_POST['soi_date'])."',  
						`customer`	      ='".$_POST['customer']."',  
						`dealer`	      ='".$_POST['dealer']."',
						`zone`	          ='".$_POST['zone']."',
						`subzone`	      ='".$_POST['subzone']."',
						`consignee_code`  ='".$_POST['consignee_code']."',
						`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'])."',
						`total_sale_amt`  ='".$_POST['total_sal_amt']."',						
						`grand_total`	  ='".$_POST['grand_total']."',
						`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);
	$deletebill=DB_query("delete from dbl_process_charge_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]."',
												sub_amt='".$_REQUEST['netrate'][$CR]."',
												discount_type='".$_REQUEST['PerAmo'][$CR]."',
												discount_per='".$_REQUEST['Discount'][$CR]."',
												total='".$_REQUEST['total'][$CR]."'";	
						$insert_res=DB_query($insert_contact,$db);			
					}
						
				}	
					
					
					
				for($CR=0;$CR<count($_REQUEST['chargeid']);$CR++)
					{
					if($_REQUEST['chargeid'][$CR]!='')
					{
						 $insert_contact="Insert into dbl_process_charge_details set
												parentid='".$_REQUEST['id']."',  
												chargeid='".$_REQUEST['chargeid'][$CR]."'";	
						$insert_res=DB_query($insert_contact,$db);			
					}
						
				}			
		
	
$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);
 $function_filter[]=$dealer;
$function_filter[]='';
$function_filter[]=$SOI_date; 
$function_filter[]=$SOI_date; 
}




 


?>



<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">

<!--<h1 align="center"><strong><?php //echo $s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'CompanyName'); ?>
</strong></h1>-->
<h1>Direct Sale Order</h1>

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


<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
<td class="tabledata1">Order Type<font color="#FF0000">*</font></td>
<td width="20%" align="left" valign="top">	
<select name="ordertype" id="ordertype" style="width:100%" >
<option value="Exciable"<?php if($order_type=='Exciable'){ ?> selected="selected" <?php } ?> ?>Exciable </option>
<option value="Non Exciable"<?php if($order_type=='Non Exciable'){ ?> selected="selected" <?php } ?> ?>Non Exciable </option>
</select></td>
<td class="tabledata1">Associate Name<font color="#FF0000">*</font></td>
<td width="20%">
<select name="dealer" id="dealer" style=" width:100%;" onchange="showsubdata(this.value)">
<?php
if(!empty($_SESSION['dealerid']))
{
$sql_dealer=DB_query("select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."' and id='".$_SESSION['dealerid']."'",$db);
}
else
{
$sql_dealer=DB_query("select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."'",$db);

}
while($sql_dl=DB_fetch_array($sql_dealer))
{
?>
<option value="<?php echo $sql_dl['id']; ?>"><?php echo $sql_dl['dealer_name']; ?></option>
<?php } ?>
</select></td>
<td class="tabledata1">SOI No<font color="#FF0000"><strong>*</strong></font></td>
<td width="20%"><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"/></td>
</tr>

<tr class="row1"> 
<td class="tabledata1">Customer Name<font color="#FF0000">*</font>
  </th>
    
<td align="left" valign="top">
	<?php
	  if($_REQUEST['action']!='Edit')
 	  $dealer=$_SESSION['dealerid'];
	  else
	  $dealer=$s->GetFieldValue("dbl_dealer","id='".$dealer."'","id");   ?>
	<select name="customer" id="customer" style="width:150px;" onchange="showclientcode(this.value)">	
	<option value="0">--Select--</option>
	<option value="new">--New--</option>
	<?php 
	if($dealer=='')
	$sql=DB_query("select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	else
	$sql=DB_query("select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and dealer='".$dealer."'",$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<font color="#FF0000">*</font>
      </th>
    
    <td><div id="customercode1"><input name="customer_code" id="customer_code" type="text" style="width:150px;" 
	value="<?php echo $s->getField('clientmaster','id',$customer,'client_code'); ?>" readonly="readonly"   /></div></td>
    <td class="tabledata1">Under Associate <font color="#FF0000">*</font>
      </th>
    
    <td><div id="dealerdata2">
	<input name="dealer1" type="text" id="dealer1" style="width:150px;" value="<?php echo $s->getField('dbl_dealer','id',$dealer,'dealer_name') ; ?>"  readonly="readonly" />
	<input type="hidden" name="dealer" id="dealer" value="<?php echo $dealer;?>" />
	</div>	</td>
</tr>

<tr class="row1">
<td class="tabledata1"> Area Name<font color="#FF0000">*</font>
  </th>

<td align="left" valign="top"><div id="areadata"><input name="areaname" type="text" style="width:150px;" id="areaname"
value="<?php echo $s->getField('zone_master','id',$zone,'ZoneTitle'); ?>"  />
<input name='zone' type='hidden' style='width:100%' id='zone' value="<?php echo $zone; ?>"  />

</div></td>
<td class="tabledata1">Sub Area Name<strong>
  </th>
</strong>

<td><div id="subdata"><input name="subareaname" type="text" style="width:150px;" id="subareaname" 
value="<?php echo $s->getField('subzone_master','id',$subzone,'subzone'); ?>" />
<input name='subzone' type='hidden' style='width:100%' id='subzone' value="<?php echo $subzone; ?>" /></div></td>
<td class="tabledata1">Engineer Name</th>
 
<td><div id="engineerdata"><input name="engineer_name" id="engineer_name" type="text" style="width:150px;"  value="<?php echo $s->getField('dbl_engineer_master','id',$engineer,'engineer_name'); ?>"  />
 <input name='engname' type='hidden' style='width:100%' id='engname' value="<?php echo $engineer; ?>"  />

 
 </div></td>
</tr>

<tr class="row1">
       <td class="tabledata1">Area Code<font color="#FF0000">*</font>
        </th>
      
      <td align="left" valign="top" ><div id="areacodedata"><input name="areacode" id="areacode" type="text" style="width:150px;" value="<?php echo $s->getField('zone_master','id',$zone,'zonecode'); ?>" readonly="readonly" /></div></td>


    
    <td class="tabledata1">Sub Area Code  </td>
       <td><div id="subareacodedata"><input name="subareacode" id="subareacode" type="text" style="width:150px;"  value="<?php echo $s->getField('subzone_master','id',$subzone,'subzonecode'); ?>" readonly="readonly" /></div></td>
    <td class="tabledata1">Engineer Code</th>
    
    <td><div id="engineercodedata"><input name="engineer_code" id="engineer_code" type="text" style="width:150px;" value="<?php echo $s->getField('dbl_engineer_master','id',$engineer,'engineer_code'); ?>"  /></div></td>
</tr>
<tr class="row1">
<td class="tabledata1">SOI Date<font color="#FF0000"><strong>*</strong></font></td>
<td align="left" valign="top"><input name="soi_date" id="soi_date" type="text" style="width:100%"  value=""  class="datepicker" /></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>
<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>
</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">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">PO No<font color="#FF0000">*</font></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><div id="subareacodedata">
      <input name="po_date" id="po_date" type="text" style="width:100%" value="<?php if(isset($po_date)) { echo $po_date; } ?>"   class="datepicker" /></td>
    <td class="tabledata1">Delivery Date </td>
    <td><input name="delivery_date" id="delivery_date" type="text" style="width:100%" value="<?php if(isset($delivery_date)) { echo $delivery_date; } ?>"  class="datepicker" /></td>
</tr>

<tr class="row1">
 <td class="tabledata1">Part Delivery Date<font color="#FF0000">*</font></td>
 <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>
 <td>&nbsp;</tdh>
 <td><input name='margin_fac' type='text' style='width:100%' id='marginfac' value=""  readonly='readonly' /></td>
    <td>&nbsp;</td>
    <td>&nbsp;</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%"></textarea></td>
</tr>
<tr class="row1">
<td class="tabledata1">Dispatch Remark</td>
<td colspan="5" align="left" valign="top">
<textarea name="dispatch_remarks" id="dispatch_remarks"  style="width:100%"></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%"></textarea></td>
    </tr>
</table> 
	
<p align="left">
  <input type="button" class="search"  value="Add Item " onclick="open_items2()" />                  
<input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />               
</p>

<div id="alldata" style="overflow:auto; width:970px;">
<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></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 PO</strong></th>
</tr>
<tbody id="dataTable">
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]"  type="checkbox" value="" /></td>	
<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" /></td>
<td class="tabledata"><input type="text" name="" value="" id="itemcode" size="9"  readonly /></td>
<td class="tabledata" style="white-space:nowrap"><input type="text" name="" value="" id="itemname" readonly /></td>
<td class="tabledata"><input type="text" name="uom[]" id="uom" readonly size="9" /></td>
<td class="tabledata"><input type="text" name="stockqty[]"  id="total_stock" size="9" readonly /></td>
<td class="tabledata"><input type="text" name="prqty[]" value="" id="prqty" size="6" /></td>
<td class="tabledata"><input type="hidden" name="type[]" id="type1" value="<?php echo $rowtype; ?>" readonly="readonly" /></td>
<td class="tabledata"><input type="text" name="orderqty[]" id="orderqty" size="9" onkeyup="calprqty(this.value,this.id)"  /></td>
<td class="tabledata"><input type="text" name="rate[]" value="" id="rate" size="9"  onkeyup="calcValue2(this.value,this.id)" readonly  /></td>
<td class="tabledata"><input type="text" name="netrate[]" id="netrate" style="width:50px;"  readonly /></td>
<td class="tabledata"><select style="width:80px;" name="PerAmo[]" id="PerAmo">
<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" onblur="DiscountAmount(this.value,this.id)" style="width:80px;" value="<?php echo $row['discount_per']; ?>" /></td>		  
<td class="tabledata"><input type="text" name="total[]" id="total" style="width:50px;"  readonly="true"
value="<?php echo $row['total']; ?>" 
 /></td>
 <td class="tabledata"><select name="reserve[]" id="reserve" style="width:50px;">
 <option value="Y">Yes</option>
 <option value="N">No</option>
 </select>
 </td>

 </tr>
</tbody>
</table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="" id="edit_cnt" />

</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;
			} ?>
			<td class="tabledata1">Excise Item After Discount </td>
				<td><input type="text" name="excise_value" 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>
			<tr class="row1">
            <td colspan="2"><div id="chargedata"></div>
			</td>
			</tr>
			
			<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 calcValue2(str,id)
{
	var brk=id.split('_');
	if(brk[1]==undefined)
	{
		var qty=document.getElementById("orderqty").value;
		if(qty!=''){
		
		var tot=qty*str;
		document.getElementById("netrate").value=tot;}
	}
	else
	{
		var qty=document.getElementById("orderqty_"+brk[1]).value;
		if(qty!=''){
		
		var tot=qty*str;
		document.getElementById("netrate_"+brk[1]).value=tot;}
	}
}

function calprqty(str,id)
{
	var brk=id.split('_');
	if(brk[1]==undefined)
	{
		if(parseFloat(document.getElementById("orderqty").value)>parseFloat(document.getElementById("prqty").value))
		{
		alert("Order Qty Sholud Be less then PR qty");
		document.getElementById("orderqty").value='';
		document.getElementById("orderqty").focus();
		}
		
	}
	else
	{ 
	  var i=brk[1]; 
		if(parseFloat(document.getElementById("orderqty_"+i).value)>parseFloat(document.getElementById("prqty_"+i).value))
		{
		alert("Order Qty Sholud Be less then PR qty");
		document.getElementById("orderqty_"+i).value='';
		document.getElementById("orderqty_"+i).focus();
		}
	}
}





function DiscountAmount(str,id)
{
var brk=id.split('_');
	if(brk[1]==undefined)
	{
	var discount_percent = document.getElementById("PerAmo").value;
	var rate = document.getElementById("netrate").value;
	var discount = document.getElementById("Discount").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").value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
	
	}
	document.getElementById("total").value=subTotal.toFixed(2);
	
	}	
	
	else
	{
	var i=brk[1];
	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 calsalamt()
{
var amount=0;
var totalamt=0;
var count=document.getElementById("hiditemcount1").value;
if(count=='')
{
document.getElementById("total_sal_amt").value=document.getElementById("grnad_total").value;
}
else
{
var firstamt=document.getElementById("chargeper").value;
for(var k=1;k<=count;k++)
{
if(document.getElementById("chargeid_"+k).value!='')
{
amount=parseFloat(amount)+parseFloat(document.getElementById("chargeper_"+k).value);
}
}

amount=parseFloat(firstamt)+amount;
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 calamount()
{
var amount=0;
var amount1=0;
var totalamt=0;
var count=document.getElementById("hiditemcount").value;
if(count=='')
{
document.getElementById("basic_amt").value=document.getElementById("total").value;
if(document.getElementById("type1").value=='y')
{
amount1=parseFloat(amount1)+parseFloat(document.getElementById("total").value);

}
document.getElementById("excise_value").value=amount1.toFixed(2);
}
else
{
var firstamt=document.getElementById("total").value;
if(document.getElementById("type1").value=='y')
{
var firstamt1=document.getElementById("total").value;
}
for(var k=1;k<count;k++)
{
if(document.getElementById("total_"+k).value!='')
{
amount=parseFloat(amount)+parseFloat(document.getElementById("total_"+k).value);

if(document.getElementById("type1_"+k).value=='y')
{
amount1=parseFloat(amount1)+parseFloat(document.getElementById("total_"+k).value);
}
}
}

amount=parseFloat(firstamt)+parseFloat(amount);
amount1=parseFloat(firstamt1)+parseFloat(amount1);

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

}
}




function open_items()
{
window.open("charges_items1.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_items2()
{
var str=document.getElementById("dealer").value;
window.open("direct_Enquiry_items.php?site="+str+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=700,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");
}












</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 showsubdata(str)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data=xmlhttp.responseText.split("__");
document.getElementById("area").innerHTML=data[0];
document.getElementById("customer").innerHTML=data[1];

  }
}

xmlhttp.open("GET","get_direct_po_items.php?site="+str,true);
xmlhttp.send();



}
function showzone(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)
    {
    document.getElementById("subareacode").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showzonedata1.php?str1="+str,true);
xmlhttp.send();




}

function showcustomercode(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)
    {
    document.getElementById("customercodedata").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showclientcode.php?str1="+str,true);
xmlhttp.send();




}

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 showclientcode(str)
{
	if(str=='new')
	{
		window.open("index.php?route=DealerDistrbutions/Client_Master&modid=21&frmid=454","_self")
	return false;
	}
	if(str==0)
	{
		document.getElementById("areadata").innerHTML='';
		document.getElementById("subdata").innerHTML='';
		document.getElementById("engineerdata").innerHTML='';
		document.getElementById("areacodedata").innerHTML='';
		document.getElementById("subareacodedata").innerHTML='';
		document.getElementById("engineercodedata").innerHTML='';	
		document.getElementById("customercode1").innerHTML='';
		document.getElementById("dealerdata2").innerHTML='';
		document.getElementById("discount").value='';
		document.getElementById("chargedata").innerHTML='';
		document.getElementById("margin_fac").value='';
		document.getElementById("Inc_chrg").value='';
		//document.getElementById("freight").value='';
		document.getElementById("p_and_f").value='';
		//document.getElementById("Inc_chrg").value='';
		//document.getElementById("freight").value='';
		//document.getElementById("p_and_f").value='';
	}
	if(str!=0)
	{
	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("areadata").innerHTML=data[0];
	document.getElementById("subdata").innerHTML=data[1];
	document.getElementById("engineerdata").innerHTML=data[2];
	document.getElementById("areacodedata").innerHTML=data[3];
	document.getElementById("subareacodedata").innerHTML=data[4];
	document.getElementById("engineercodedata").innerHTML=data[5];	
	document.getElementById("customercode1").innerHTML=data[6];
	document.getElementById("dealerdata2").innerHTML=data[7];
	document.getElementById("discount").value=data[8];
	document.getElementById("chargedata").innerHTML=data[9];
	document.getElementById("marginfac").value=data[10];
	document.getElementById("Inc_chrg").value=data[11];
	//document.getElementById("freight").value=data[10];
	document.getElementById("p_and_f").value=data[12];
	//document.getElementById("Inc_chrg").value=data[9];
	//document.getElementById("freight").value=data[10];
	//document.getElementById("p_and_f").value=data[10];
	
	}
	}
	xmlhttp.open("GET","dbl_customerdata.php?str1="+str,true);
	xmlhttp.send();
	}
}

function calculateBasicAmt()
{
if(document.getElementById("total").value!='')
var firstrow=parseFloat(document.getElementById("total").value);
else
var firstrow=0;
if(document.getElementById("type1").value=='exciable')
var firstrow1=parseFloat(document.getElementById("total").value);
else
var firstrow1=0;
	var count=document.getElementById("hiditemcount").value;
	if(count!='')
	{
		var totalprice=0;
		var totalprice1=0;
		for(var i=1;i<=count;i++)
		{
		 if(document.getElementById("total_"+i))
		   {
			  if(document.getElementById("total_"+i).value!='')
			  {
				totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("total_"+i).value);
				
				if(document.getElementById("type1_"+i).value=='exciable')
				{
				amount1=parseFloat(totalprice1)+parseFloat(document.getElementById("total_"+i).value);
				}
				
				
				}
				
		   }	
		}
		var amt=parseFloat(totalprice)+parseFloat(firstrow);
		var amt1=parseFloat(amount1)+parseFloat(firstrow1);
		
		document.getElementById("basic_amt").value=amt.toFixed(2);
		document.getElementById("excise_value").value=amt1.toFixed(2);
	}
	else
	{
	var amt=parseFloat(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);
			
		}
		document.getElementById("basic_amt").value=pricTotal.toFixed(2);
	}
	}
	
}
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(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()
{   if(document.getElementById("rate").value!='')
	var rate=document.getElementById("rate").value;
	else
	var rate=0;
	if(document.getElementById("totalDiscountedamount").value!='')
	var taxableAmount=document.getElementById("totalDiscountedamount").value;
	else
	var taxableAmount=0;
	if(document.getElementById("pnf_amt").value!='')
	var taxableAmount1=document.getElementById("pnf_amt").value;
	else
	var taxableAmount1=0;
	if(document.getElementById("discount_Amt").value!='')
	var taxableAmount2=document.getElementById("discount_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 calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	var first_row=document.getElementById("discount_Amt").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;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+EDRate+"&value="+first_row,true);
	xmlhttp.send();	
	
}



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 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 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 calincidentalchrg(str)
{
if(str!='')
var str1=parseFloat(str);
else
var str1=0;
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(str1))/100;
document.getElementById("incidental_Amt").value=totalamt1.toFixed(2);

}



</script>

