<?php
$PageSecurity = 5;
include("includes/stockcalculation.php");
if(isset($_POST['Save']))
{
     $sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['mst_branchid']."'",'prefix');
	$sqlqut=DB_query("select * from quotation where site='".$_REQUEST['mst_branchid']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select pr_no as QutNo from direct_po where site='".$_REQUEST['mst_branchid']."' order by id desc limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-4);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."DPO"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."DPO"."/".'00001';
	}	
	if(count($_REQUEST['against_wo'])>1)
	{
	$against_wo=implode(",",$_REQUEST['against_wo']);	
	}
	else
	{
	$against_wo=$_REQUEST['against_wo'][0];
	}
	$data['site']=$_REQUEST['mst_branchid'];
	$data['pr_no']=$FinalCode;
	$data['pr_date']=FormatDateForSQL($_REQUEST['prdate']);
	$data['delivery_date']=ConvertSQLDate($_REQUEST['delivery_date']);
	$data['delivery_place']=$_REQUEST['delivery_place'];
	$data['payment_mode']=$_REQUEST['PayMode'];
	$data['dealer']=$_REQUEST['dealer'];	
	$data['sop_no']=$against_wo;
	$data['quotation_no']=$_REQUEST['quotations'];
	$data['quotation_date']=FormatDateForSQL($_REQUEST['quotation_date']);
	$data['basic_amt']=$_REQUEST['basicAmount'];
	$data['pkg_charge']=$_REQUEST['pkg_value'];
	$data['pkg_per']=$_REQUEST['pkg_charges1'];
	$data['excise_id']=$_REQUEST['EDBillRate'];
	$data['excise_value']=$_REQUEST['totalDiscountedPrice'];
	$data['ecess_per']=$_REQUEST['ECessPercentage'];
	$data['ecess_amt']=$_REQUEST['ECessValue'];
	$data['sah_per']=$_REQUEST['SAHCessValue'];
	$data['sah_amt']=$_REQUEST['SAHCessValue'];
	$data['total_excise_amt']=$_REQUEST['total_item_amount1'];  
	$data['total_taxable_amt']=$_REQUEST['total_item_amount'];  
	$data['vat_cst']=$_REQUEST['taxname'];  
	$data['vat_amt']=$_REQUEST['taxvalue']; 
	$data['sur_per']=$_REQUEST['sur_oct_per']; 
	$data['sur_amt']=$_REQUEST['sur_oct_amt']; 	
	$data['mode_transport']=$_REQUEST['mode_transport'];
	$data['grand_total']=$_REQUEST['GrandTotal'];	 
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['type']=$_REQUEST['ordertype1'];
	$data['subject']=$_REQUEST['subject'];
	$data['remarks']=$_REQUEST['ramarks'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$s->RecordInsert('dbl_direct_po', $data);
    $masterId=DB_Last_Insert_ID($db,'dbl_direct_po','id');	 
	if($masterId!='')
	{
		for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
		{
					if($_REQUEST['item_code'][$cnt]!='')
					{
							 $insert2="Insert into dbl_direct_po_details set
							  parent_id='".$masterId."',  
							  mst_itemid='".$_REQUEST['item_code'][$cnt]."',  
							  qty='".$_REQUEST['stock_qty'][$cnt]."',   
							  rate='".$_REQUEST['stock_price'][$cnt]."',
							  amt ='".$_REQUEST['stock_value'][$cnt]."', 
							  dis_type='".$_REQUEST['PerAmo'][$cnt]."', 
							  dis_per='".$_REQUEST['Discount'][$cnt]."',
							  dis_price='".$_REQUEST['perc'][$cnt]."',
							  net_total='".$_REQUEST['value_dis'][$cnt]."',
							  delivery_date='".FormatDateForSQL($_REQUEST['delivery_date1'][$cnt])."'";
							  $result2=DB_query($insert2,$db);	
					  
					 
						  $update=DB_query("update dbl_process_sale_order_details set po_status=1
						  where id='".$_REQUEST['rowid'][$cnt]."'",$db);  /* Update Po status*/
					 			
					}	
		}
	}
		
	$count1=0;	
	$sql=DB_query("select * from dbl_process_sale_order_details where parentid in('".$against_wo."')",$db);
	$num=DB_num_rows($sql);
		while($row1=DB_fetch_array($sql))
		{
			if($row1['po_status']==1)
			{
			$count1=$count1+1;	
			}
		}
	if($count1==$num)
	{
	
   $update=DB_query("update dbl_process_sale_order set PoStatus=1 where id in('".$against_wo."')",$db);
	}	
	
	
	
	$s->pageLocation("index.php?route=DealerDistrbutions/POORDER/direct_po_index".$rurl);
	
}

if(isset($_SESSION['dealerid']))
$dealer=$_SESSION['dealerid'];
else
$dealer=$s->GetFieldValue('dbl_process_sale_order',"id in('".$_REQUEST['id']."')",'dealer');

if($_REQUEST['action']!='exciable')
{

$assign_excise_sites1=explode(",",$s->getField('dbl_dealer','id',$dealer,'merge_nonexcise_sites'));
$assign_excise_sites=implode("','",$assign_excise_sites1);
$poamount=$s->getField('dbl_dealer','id',$dealer,'min_po_amt_non');
}
else
{

$assign_excise_sites1=explode(",",$s->getField('dbl_dealer','id',$dealer,'merge_excise_sites'));
$assign_excise_sites=implode("','",$assign_excise_sites1);

$poamount=$s->getField('dbl_dealer','id',$dealer,'min_po_amt');
}
$function_filter[]=$dealer;
$function_filter[]='';
$function_filter[]=date('Y-m-d');
$function_filter[]=date('Y-m-d'); 
?>
<link rel="stylesheet" href="css/new_mxerp.css">

<link rel="stylesheet" href="css/jquery.ui.all.css" />
<script src="js/jquery-1.5.1.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>



<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>
<script language="javascript" type="text/javascript">
function open_items()
{
window.open("directpoitems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

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


function generate_reqno(str)
{
	if (str.length==0)
  {
  document.getElementById("reqno").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("reqno").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_reqno.php?site="+str,true);
xmlhttp.send();
}
function check_approveqty(str,j)
{
	var req_qty=document.getElementById("req_qty_"+j).value;
	if(str>req_qty)
	{
		alert("Quantity to approve cannot be greater than requsition quantity");
		document.getElementById("app_qty_"+j).value='';
		document.getElementById("app_qty_"+j).focus();
		}
}
</script>
<?php 
$zone=$s->getField('dbl_dealer','id',$dealer,'area_code'); 
$subzone=$s->getField('dbl_dealer','id',$dealer,'subarea_code'); 
$engineer=$s->getField('dbl_dealer','id',$dealer,'engineer_code'); 


?>

	
			<form action="" method="post">
			<fieldset><p align="left"><strong><span>Direct PO ORDER</span></strong></p>
				<div style="width:auto; margin-left:auto; margin-right:auto;">
				<input type="hidden" name="poamtdata" id="poamtdata" value="<?php echo $poamount; ?>" />
				<input type="hidden" name="dealer" value="<?php echo $dealer; ?>" />
			<table width="96%" border="1" cellpadding="3" cellspacing="0">
			<tr> 
		<th width="11%"><strong>Branch Code</strong></th>
		<td width="17%">
		<?php  
		$sql_state=DB_query("SELECT loccode,locationname FROM  locations where CompanyId='".$_SESSION['ACGCompanyId']."'
		and loccode in('".$assign_excise_sites."') ",$db);?> 
		<select name="mst_branchid" id="mst_branchid" style="width:100%;" >
			<option value="000">Select Branch</option>
			<?php while($SiteName=DB_fetch_array($sql_state)) {?>]
			<option value="<?php echo $SiteName['loccode']; ?>"><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select></td>
		<th width="14%"><strong>PO Number</strong></th>
		<td width="16%"> <input type="text" name="prno" value="Auto Generated" style="width:100%;" readonly="readonly" ></td>
		<th width="15%" nowrap="nowrap"><strong>PO Date</strong></th>
		<td width="27%"><input type="text" name="prdate" value="" style="width:100%;"  class="datepicker" /></td>
		 </tr>
		 <tr>
		<th nowrap="nowrap"><strong>Delivery Date</strong></th>
		<td><input type="text" name="delivery_date" value="" style="width:100%;"  class="datepicker"></td>
		<th nowrap="nowrap"><strong>Delivery Place</strong></th>
        <td><input type="text" name="delivery_place" value="" style="width:100%;" ></td>
<th><strong>Payment Mode</strong></th>
<td><select name="PayMode" id="PayMode" style="width:100%;">
  <option value="000">---Select Payment Mode---</option>
  <?php 
					$sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($_POST['PayMode'] == $myrow['paymentid'])
							$p="selected";
						?>
  <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
  <?php 	} ?>
</select></td>
             </tr>
			 <tr>
				<th><strong>Order Type</strong></th>
				<td><input type="text" name="ordertype1" id="ordertype1" style="width:100%" value="<?php echo  $_REQUEST['action']; ?>" readonly /></td>
			<th nowrap="nowrap"><strong>Transport</strong></th>
            <td><input type="text" name="mode_transport" id="mode_transport" style="width:100%" /></td>
           <th><strong>Area Code</strong></th>
			<td><input type="text" name="area" id="area" style="width:100%" value="<?php echo $s->getField('zone_master','id',$zone,'zonecode'); ?>" readonly /></td>
			 </tr>
			 <tr>
			<th nowrap="nowrap"><strong>Sub Area Code</strong></th>
            <td><input type="text" name="subarea" id="subarea" style="width:100%" value="<?php echo $s->getField('subzone_master','id',$subzone,'subzonecode'); ?>" /></td>
            <th nowrap="nowrap"><strong>Engineer Code</strong></th>
            <td><input type="text" name="engineer" id="engineer" style="width:100%" value="<?php echo $s->getField('dbl_engineer_dealer_maste','dealer',$dealer,'engineer_code'); ?>" /></td>
			<th><strong>Part Delivery Date</strong></th>
			<td><input type="text" name="part_delivery_date" id="part_delivery_date" style="width:100%" value=""  class="datepicker" /></td>
			 </tr>
			  <tr>
			<th><strong>Quotation No</strong></th>
			<td><input type="text" name="quotations" id="quotations" style="width:100%" value="" readonly /></td>
			<th nowrap="nowrap"><strong>Quotation Date</strong></th>
            <td><input type="text" name="quotation_date" id="quotation_date" style="width:100%" class="datepicker" /></td>
            <th>&nbsp;</th>
			<td>&nbsp;</td>
			  </tr>
			  
				<tr>
				<th nowrap="nowrap">Against  WO</th>
				<td><select name="against_wo[]" id="against_wo" style="width:100%" multiple="multiple">
                  <?php
				$sql=DB_query("select * from dbl_process_sale_order where id in(".$_REQUEST['id'].")",$db);
				while($row1=DB_fetch_array($sql))
				{
				 ?>
                  <option value="<?php echo $row1['id']; ?>" selected="selected"><?php echo $row1['SOI_no']; ?></option>
                  <?php } ?>
                </select></td>
				</tr>
				<tr class="row1">
    <th><strong>Subject</strong></th>
    <td colspan="5"><textarea name="subject" id="subject"  style="width:100%"><?php echo $subject; ?></textarea></td>
    </tr>
	<tr class="row1">
    <th><strong>Remark</strong></th>
    <td colspan="5"><textarea name="ramarks" id="remarks"  style="width:100%"><?php echo $remarks;?></textarea></td>
    </tr>
			      </table>
				   
									
				
				</div>
				   <br />
				 
<p align="left">				 
<input type="button" onClick="addRow('dataTable')" value="Add Rows" accesskey="A" class="search" />&nbsp;
<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />
<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />
<input type="button" name="Terms" value="Terms&Conditions" id="profile_popup"  onclick="open_items1()" class="search" />
</p>				 
<h3><center>Item Details</center></h3>

<div style="width:auto; margin-left:auto; margin-right:auto;"> 
<div style="width:900px; overflow:auto">    			 
<table align='center' width='100%;' border='1' cellpadding='3' cellspacing='0'>
<tr class='row1'><td class='tabledata' style='text-align:center;' colspan='13'>Item Details</td></tr>
<tr class='row1'>
<td class='tabledata'>Sr. No.</td>
<td class='tabledata'>&nbsp;</td>
<td class='tabledata'>Item Code</td>
 <td class='tabledata'>Item Name</td>
 <td class='tabledata'>&nbsp;</td>
 <td class='tabledata'>Qty.</td>
<td class='tabledata'>Price</td>
<td class='tabledata'>Value</td>
<td class='tabledata'>Discount Type</td>
<td class='tabledata'>Discount Per</td>
<td class='tabledata'>Discount Price</td>
<td class='tabledata'>Net Discount</td>
<td class='tabledata'>Delivery Date</td>
</tr>
<tbody id='dataTable'>
<?php 
$i=1;
$stock=0;
$num=0;


$sql2=DB_query("SELECT id,mst_itemid, SUM(order_qty) AS order_qty FROM dbl_process_sale_order_details 
WHERE parentid  in(".$_REQUEST['id'].") and po_status=0 GROUP BY mst_itemid",$db);
while($row2=DB_fetch_array($sql2))
{
$itemcode=$s->getField('item_master','id',$row2['mst_itemid'],'StockID'); 
$itemname=$s->getField('item_master','id',$row2['mst_itemid'],'item_name'); 
$checkitemtype=$s->getField('item_master','id',$row2['mst_itemid'],'item_exciable');
$array1=array("y"=>"exciable","n"=>"non exciable");

if($checkitemtype==$_REQUEST['action'])
{
$num=$num+1;
$op=openingBalance($function_filter,$row2['mst_itemid']);
$in_1=receivedMRN($function_filter,$row2['mst_itemid']);
$out_1=issueSlip($function_filter,$row2['mst_itemid']);
$out_2=issueSiteToSite($function_filter,$row2['mst_itemid']);		
$in_2=receivedSiteToSite($function_filter,$row2['mst_itemid']);
$out_3=issueMatarialReturn($function_filter,$row2['mst_itemid']);
$in_3=receivedReturn($function_filter,$row2['mst_itemid']);	
$out_4=Rgpchallan($function_filter,$row2['mst_itemid']);
$out_5=Nrgp($function_filter,$row2['mst_itemid']);
$in_4=Rgpreturn($function_filter,$row2['mst_itemid']);	 
$in_5=FinishedMR($function_filter,$row2['mst_itemid']);
$in_6=dispatchreturnsaleorder($function_filter,$row2['mst_itemid']);
$out_6=dispatchsaleorder($function_filter,$row2['mst_itemid']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5+$in_6);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);

$tot=$invalue-$outvalue;
$stockbalance=$tot;
if($stockbalance>=$row2['order_qty'])
$req_qty3=0;
else if($stockbalance<$row2['order_qty'])
$req_qty3=($row2['order_qty']-$stockbalance);
$req_qty3;
if($req_qty3==0)
{
$stock=$stock+1;
}
if($req_qty3!=0)
{
?>
<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_<?php echo $i; ?>' value='<?php echo $row2['mst_itemid'];?>'  readonly /></td>
<td class='tabledata'><input type='text' name='' id='itemcode_<?php echo $i; ?>' value='<?php echo $itemcode;?>'  readonly /></td>
<td class='tabledata' style='white-space:nowrap'><input type='text' name='item_name[]' id='itemname_<?php echo $i; ?>' value='<?php echo $itemname;?>' readonly /></td>
<td class="tabledata"><input type="hidden" name="rowid[]" id="rowid2_<?php echo $i; ?>" value="<?php echo $row2['id']; ?>" /></td>
<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty_<?php echo $i; ?>' size='9' onkeyup='calcValue1(this.value,this.id)'  value="<?php echo $req_qty3;?>"  /></td>
<td class='tabledata'><input type='text' name='stock_price[]'  id='stockprice_<?php echo $i; ?>' size='6' value=''/></td>
<td class='tabledata'><input type='text' name='stock_value[]'  id='stockvalue_<?php echo $i; ?>' size='9' onfocus='CalculateTotalLeadAmt(this.value,this.id)' value='<?php echo $row2['amt'];?>'/></td>
<td class='tabledata'><select style='width:80px;' name='PerAmo[]' id='PerAmo_<?php echo $i; ?>' >
<option value='Amount' <?php if($row2['dis_type']=='Amount') { ?> selected="selected" <?php } ?> >Amount</option>
<option value='PercentAmt' <?php if($row2['dis_type']=='PercentAmt') { ?> selected="selected" <?php } ?>>Percent Amt</option>
</select></td>
<td class='tabledata'><input type='text' style='width:90px' name='Discount[]' id='Discount_<?php echo $i; ?>' onkeyup='DiscountAmount1(this.value,this.id)'  value='<?php echo $row2['dis_per']; ?>'/></td>
<td class='tabledata'><input type='text' style='width:90px' name='perc[]' id='perc_<?php echo $i; ?>'  readonly='true' value='<?php echo $row2['dis_price']; ?>' /></td>
<td class='tabledata'><input type='text' style='width:90px' name='value_dis[]' id='valuedis_<?php echo $i; ?>'
value='<?php echo $row2['net_amt']; ?>'  readonly='true'  /></td>
<td class='tabledata'><input type='text' style='width:90px' name='delivery_date1[]' id='deliverydata1_<?php echo $i; ?>' 
value='<?php echo $row2['delivery_date']; ?>'  class="datepicker"/></td>
 </tr>
<?php  $i++;  } } } ?>
<input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
</tbody>
<?php 
if($num==$stock && $num!=0) { ?>
<tr ><td colspan="12" ><strong><font color="#000000"><?php echo "All Items Stock Available "; ?></font></strong></td></tr>
<?php } else if($num==0) { ?>
<tr class="row1"><td colspan="12" ><strong><font color="#000000"><?php echo ucwords($_REQUEST['action']);?> Items Not Found </font></strong></td></tr><?php } ?></table></div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
			
	</div>
	<br />	
	<?php if($num!=$stock)  { 	?>
	
	
	<?php
	if(!empty($_SESSION['dealeid']))
	{
	$sql_dealer=DB_query("select * from dbl_dealer  where id='".$_SESSION['dealerid']."' 
	and company='".$_SESSION['ACGCompanyId']."'",$db);
	}
	else
	{
	$sql_dealer=DB_query("select * from dbl_dealer  where  company='".$_SESSION['ACGCompanyId']."'",$db);
	}
	$row1=DB_fetch_array($sql_dealer);
	
	
	           if($row1['edu_cess']!='')
				$edu_cess=$row1['edu_cess'];
				else
				$edu_cess='';
				 if($row1['sales_tax']!='')
				$sales_tax=$row1['sales_tax'];
				else
				$sales_tax='';
				 if($row1['insurance']!='')
				$insurance=$row1['insurance'];
				else
				$insurance='';
				if($row1['freight_type']!='')
				{
				if($row1['freight_type']=='Amount')
				{
				$freight_per='';
				$freight_amount=$row1['freight'];
				}
				$freight_per=$row1['freight'];
				$freight_amount='';
				}
				else
				{
				$freight_per='';
				$freight_amount='';
				}
				
				if($row1['pnf']!='')
				$pnf=$row1['pnf'];
				else
				$pnf='';
	
	
	 
	
	?>
	
	
<div align="right">			
			<table width="40%" border="0">
			
			<tr class="row1"><td>
		      <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input name="basicAmount" type="text" value=""  onfocus="calculateBasic()" id="afterdiscountprice" style="width:100%" ></td>
               </tr>
			    <tr>
                  <td><strong>P & F Charges</strong> </td>
                  <td><input name="pkg_charges1" id="pkg_charges1" type="text" value="<?php echo $pnf; ?>"
				   style="width:60px;" readonly />
						<input name="pkg_value" id="pkg_value" type="text" value="" style="width:176px;" readonly onfocus="calculatepkg()" /></td>
                </tr>
              
				<tr>
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:100%" onchange="calculateBillExcise(this.value)"  >
				<option value="0">--Select--</option>
				<?php
				if($row1['excise']!='')
				$excise1=$row1['excise'];
				else
				$excise1='';
				if($excise1!='')
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%' and id='".$row1['excise']."'"  ;
				else
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'"  ;
				
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				?>
				<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" 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><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php //echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue" id="ECessValue" type="text" value="<?php //echo $ECessValue?>" style="width:176px;" readonly onfocus="calculateECess()" /></td>
					</tr>
			<tr >
					<td><strong>SAH-E Cess</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php //echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php //echo $SAHCessValue?>" style="width:176px;" readonly onfocus="calculateSAHCess()" /></td>
					</tr>-->
					
					
					<tr>
					<td><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $edu_cess;?>" style="width:60px;" readonly />
						<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:176px;" readonly onfocus="calculateECess()" /></td>
					</tr>
			<tr >
					<td><strong>sales_tax</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $sales_tax;?>" style="width:60px;" readonly/>
						<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:176px;" readonly onfocus="calculateSAHCess()" /></td>
					</tr>	
					
					<tr>
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_item_amount" id="total_item_amount1" style="width:100%" onfocus="showexiseamt()" readonly="readonly" /></td>
					
					</tr>
					
                <!--<tr>
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				//$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				//$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><select id="taxname" name="taxname" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			//while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php //echo $Taxmyrow['salestax_id']; ?>"<?php //echo ($myrow4_req['taxnameid']==$Taxmyrow['id']?'selected':'')?>><?php //echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php //} ?>
              </select></td>
 
              </tr>-->
              <!--<tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval1">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="" readonly="true"/>
              </div>	</td>
                </tr>-->
				<tr >
					<td><strong>Insurance</strong> </td>
					<td><input name="insurance" id="insurance" type="text" value="<?php echo $insurance;?>"
					 style="width:60px;" readonly/>
						<input name="insurance_value" id="insurance_value" type="text" 
						value="<?php echo $SAHCessValue?>" style="width:176px;" readonly onfocus="calculateinsurance()" /></td>
					</tr>	
               
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="freight_per" id="freight_per"   style="width:60px;" value="<?php echo $freight_per; ?>" readonly />
				  <input name="freight_amt" id="freight_amt" type="text" 
						value="<?php echo $freight_amount?>" style="width:176px;" readonly onfocus="calculatefreight()" />
				  </td>
                </tr>              
						
                <tr>
				<td><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12" readonly="readonly"/></td>
                </tr>
              </table></td></tr>
		 
			</table>
</div>
<p align="center"><input type="submit" name="Save" value="Save" onclick="return checkdata()" /></p>
<?php } ?>




<script type="text/javascript">
function DiscountAmountvalue(DA)
{

var discount_percent = document.getElementById("PerAmount").value;
	var discount = document.getElementById("Discount_amount").value;
	var total = document.getElementById("basicAmount").value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}		
	document.getElementById("discountperc").value=percent.toFixed(2);
	document.getElementById("afterdiscountprice").value=subTotal.toFixed(2);
	
}
function CalculateTotalLeadAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	var stock_price = document.getElementById("stockprice_"+i).value;
	var stock_qty = document.getElementById("stockqty_"+i).value;
	document.getElementById("stockvalue_"+i).value=(stock_price*stock_qty);
		
	
	
	
}
function DiscountAmount1(DA,str)
{
  var k=str.split("_");  
	var i=k[1];	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;

	var total = document.getElementById("stockvalue_"+i).value;	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0; var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	if(discount==''){discount=0; var percent=0;}
	else
	{
	var percent = parseFloat(DA);
	}
	var subTotal = parseFloat(total)-percent;	
	}		
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("valuedis_"+i).value=subTotal.toFixed(2);
	
	
}
 
</script>

<script>

function showvendor(str)
{
if (str.length==0)
  		{
  			document.getElementById("vendor").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
			  var data=xmlhttp.responseText.split("__");
    			document.getElementById("vendor").innerHTML=data[0];
				document.getElementById("add1").innerHTML=data[1];
				document.getElementById("add2").innerHTML=data[2];
				document.getElementById("mob").innerHTML=data[3];
    		}
  		}
		xmlhttp.open("GET","vendorshow_direct.php?site="+str,true);
		xmlhttp.send();



}

function showstorecode(str)
{
 if (str.length==0)
  		{
  			document.getElementById("agnstwo").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
			 
    			document.getElementById("agnstwo").innerHTML=xmlhttp.responseText;
				
    		}
  		}
		xmlhttp.open("GET","siteshowdata.php?site="+str,true);
		xmlhttp.send();


}

function showitemdetails(str)
{
 if (str.length==0)
  		{
  			document.getElementById("item1").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
			 
    			document.getElementById("item1").innerHTML=xmlhttp.responseText;
				
    		}
  		}
		xmlhttp.open("GET","workorderitem.php?site="+str,true);
		xmlhttp.send();


}







function addRow(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount").value=='')
	r =rowCount+1;
	else
	{
	var t=document.getElementById("edit_cnt").value;
	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1)+parseInt(t)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=r;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	//document.getElementById("stock_perunit_"+rowCount).value='1';
}
	
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--;
					}
					
				}
	var t=document.getElementById("edit_cnt").value;
	if(document.getElementById("hiditemcount").value!='')
	var t1=document.getElementById("hiditemcount").value;
	else
	var t1=0;
	r=parseInt(t1)+parseInt(t)-1;
		document.getElementById("hiditemcount").value=r;		
		}
		catch(e) 
		{
			alert(e);
		}

	}	
function calculateBasic()
{
	var totalBasic=0;
	var totalBasic2=0;
	var totalBasic4=0;
	if(document.getElementById("hiditemcount").value=='')
	var cnt=0;
	else
	var cnt=document.getElementById("hiditemcount").value;
	var cnt1=document.getElementById("edit_cnt").value;
	var cnt2=parseInt(cnt)+(parseInt(cnt1)-1);
	for(var i=1;i<=cnt2;i++)
	{
	if(document.getElementById("valuedis_"+i))
	{
	if(document.getElementById("valuedis_"+i).value!='')
	{
	var totalBasic1=document.getElementById("valuedis_"+i).value;
	
	var totalBasic=parseFloat(totalBasic)+parseFloat(totalBasic1);
	}
	}
	}
	
	var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic2);	
	document.getElementById("afterdiscountprice").value=totalBasic3;
}
function calculateBillExcise(str)
{    
    if(document.getElementById("afterdiscountprice").value!='')
	var value2=document.getElementById("afterdiscountprice").value;
	else
	var value2=0;
	if(document.getElementById("pkg_value").value!='')
	var value1=document.getElementById("pkg_value").value;
	else
	var value1=0;
	var value=parseFloat(value2)+parseFloat(value1);
	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;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}


function calculateECess()
{
	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 calculateSAHCess()
{
	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 calsuroctamt(str)
{
var amt=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=parseFloat(document.getElementById("sur_oct_per").value);
var amount=(amt*suroctper)/100;
document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}
function tax_rate1(str)
{

var taxableAmount=document.getElementById("total_item_amount").value;
var taxableAmount1=document.getElementById("pkg_charges1").value;
if(taxableAmount1==''){taxableAmount1=0;}
var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
if (str.length==0)
  {
  document.getElementById("taxval").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("taxval").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_valdata.php?taxid="+str+"&amt="+taxableAmount2,true);
xmlhttp.send();
}
/*function cal_grandamount()
{
	var total=document.getElementById("afterdiscountprice").value;
	//var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var totalitemamt=document.getElementById("total_item_amount1").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	//var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	//if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	//if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(taxamt);

document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}*/


function cal_grandamount()
{
	var total=document.getElementById("afterdiscountprice").value;
	
	//var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var totalitemamt=document.getElementById("total_item_amount1").value;
	
	//var TotalCharge=document.getElementById("TotalCharge").value;
	//var taxamt=document.getElementById("taxvalue").value;
	var insurance=document.getElementById("insurance_value").value;
	var freight=document.getElementById("freight_amt").value;
	var packagingCharges=document.getElementById("pkg_value").value;
	//var additionalCharges=document.getElementById("additionalCharges").value;	
	//var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	//if(sur_oct_amt==''){sur_oct_amt=0;}
	if(totalitemamt==''){totalitemamt=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(insurance==''){insurance=0;}
	if(freight==''){freight=0;}

	//if(additionalCharges==''){additionalCharges=0;}
	//if(taxamt==''){taxamt=0;}
	//var grand=document.getElementById("GrandTotal").value;
	//grandtotal=parseFloat(total)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(taxamt);
var grandtotal=parseFloat(total)+parseFloat(totalitemamt)+parseFloat(packagingCharges)+parseFloat(freight)+parseFloat(insurance);
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
//document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}

function showexiseamt()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var amt1=document.getElementById("totalDiscountedPrice").value;
else
var amt1=0;
if(document.getElementById("ECessValue").value!='')
var amt2=document.getElementById("ECessValue").value;
else
var amt2=0;
if(document.getElementById("SAHCessValue").value!='')
var amt3=document.getElementById("SAHCessValue").value;
else
var amt3=0;
var amount=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);
document.getElementById("total_item_amount1").value=amount.toFixed(2);

}
function showexiseamt1()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var amt1=document.getElementById("totalDiscountedPrice").value;
else
var amt1=0;
if(document.getElementById("total_item_amount1").value!='')
var amt2=document.getElementById("total_item_amount1").value;
else
var amt2=0;

var amount=parseFloat(amt1)+parseFloat(amt2);
document.getElementById("total_item_amount").value=amount.toFixed(2);

}

function checkExcisable(str,t)
{
var k=t.split("_");
if(k[1]==undefined)
{
 if(str=='NonExcisable')
	{
		
		
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("ECessPercentage").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("SAHCessPercentage").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		document.getElementById("taxname").disabled=false;
		document.getElementById("taxvalue").disabled=false;
		document.getElementById("surper").disabled=false;
		document.getElementById("suramt").disabled=false;
		
	}
	else if(str=='Excisable' || str==0)
	{

	    document.getElementById("exciseDuty").disabled=false;
		document.getElementById("ECessPercentage").disabled=false;
		document.getElementById("ECessValue").disabled=false;
		document.getElementById("SAHCessPercentage").disabled=false;
		document.getElementById("SAHCessValue").disabled=false;
		document.getElementById("taxable_amt").disabled=false;
		document.getElementById("taxname").disabled=false;
		document.getElementById("taxvalue").disabled=false;
		document.getElementById("surper").disabled=false;
		document.getElementById("suramt").disabled=false;
		
		
		
		
	}
	else
	{
				
		 document.getElementById("exciseDuty").disabled=true;
		document.getElementById("ECessPercentage").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("SAHCessPercentage").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		document.getElementById("taxname").disabled=true;
		document.getElementById("taxvalue").disabled=true;
		document.getElementById("surper").disabled=true;
		document.getElementById("suramt").disabled=true;
		
		
		
		 document.getElementById("exciseDuty").value='';
		document.getElementById("ECessPercentage").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("SAHCessPercentage").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxable_amt").value='';
		document.getElementById("taxname").value='';
		document.getElementById("taxvalue").value='';
		document.getElementById("surper").value='';
		document.getElementById("suramt").value='';
		

		


	
	}
	document.getElementById("hidbillingtype").value=str;
	}
	else
	{
		var i=k[1];

	if(str=='NonExcisable')
	{
		
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("surper_"+i).disabled=false;
		document.getElementById("suramt_"+i).disabled=false;
				
		}
	else if(str=='Excisable' || str==0)
	{
	
	
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("ECessPercentage_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;		
		document.getElementById("SAHCessPercentage_"+i).disabled=false;	
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("surper_"+i).disabled=false;
		document.getElementById("suramt_"+i).disabled=false;
		
		
	}
	else
	{
	
	   document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=true;
		document.getElementById("taxvalue_"+i).disabled=true;
		document.getElementById("surper_"+i).disabled=true;
		document.getElementById("suramt_"+i).disabled=true;
				
		
		 document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
		document.getElementById("taxname_"+i).value='';
		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("surper_"+i).value='';
		document.getElementById("suramt_"+i).value='';
	
	}
	
	
	document.getElementById("hid_billing_type_"+i).value=str;
	}
	
}

function claculateExcise(t,str)
{
  var k=t.split("_");
if(k[1]==undefined)
{	
var i=0;
	var discounted=document.getElementById("value_dis").value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			document.getElementById("exciseId").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?caltaxdata="+str+"&data="+i,true);
		xmlhttp.send();
}
else
{
var i=k[1];
var discounted=document.getElementById("value_dis_"+i).value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId_"+i).innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?caltaxdata="+str+"&data="+i,true);
		xmlhttp.send();


}
}


function checkdata()
{

if(document.getElementById("afterdiscountprice").value=='')
{
alert("Please Check Total Amount");
return false;
}
else
{
var amt=parseFloat(document.getElementById("afterdiscountprice").value);
var pkg=parseFloat(document.getElementById("pkg_charges1").value);
var amount=amt+pkg;
if(parseFloat(document.getElementById("poamtdata").value)>parseFloat(amount))
{
alert("Amount should be Equal To Min Po Amount Assigned For Dealer Plz Add Items");
return false;
}
if(document.getElementById("mst_branchid").value=='000')
{
alert("Must Select Unit");
return false;

}
return true;

}
}
function calculatepkg()
{
	var exciseValue=document.getElementById("afterdiscountprice").value;
	var ECessPercentage=document.getElementById("pkg_charges1").value;
	var total=(exciseValue*ECessPercentage)/100;
	document.getElementById("pkg_value").value=total.toFixed(2);
}
function calculateinsurance()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("insurance").value;
	var total=(exciseValue*ECessPercentage)/100;
	document.getElementById("insurance_value").value=total.toFixed(2);
}

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

function calculateTotalExcise()
{
  if(document.getElementById("afterdiscountprice").value!='')
	var value2=document.getElementById("afterdiscountprice").value;
	else var value2=0;
	if(document.getElementById("pkg_value").value!='')
	var value1=document.getElementById("pkg_value").value;
	else	var value1=0;
 var value=parseFloat(value2)+parseFloat(value1);
	
	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;
	}
	}
	
	var str=document.getElementById("EDRate").value;
	
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	


}

</script>
