<link rel="stylesheet" type="text/css" href="css/professional/table_frize.css">
<?php
error_reporting("E_ALL");
$PageSecurity = 5;

if($_REQUEST['action']=='delete')
{
DB_query("update direct_po_details set del_status=1 where parent_id='".$_REQUEST['SID']."' and id='".$_REQUEST['dirid']."'",$db);

}
if($_REQUEST['action']=='undo')
{
DB_query("update direct_po_details set del_status=0 where parent_id='".$_REQUEST['SID']."' ",$db);

}


if(isset($_POST['Save']))
{
     $del=DB_query("delete from direct_po_details where parent_id='".$_REQUEST['SID']."'",$db);
	
	$data['site']=$_REQUEST['mst_branchid'];
	$data['pr_date']=FormatDateForSQL($_REQUEST['prdate']);
	$data['vender_id']=$_REQUEST['mst_supplierno'];
	$data['contact_person']=$_REQUEST['contact_name'];
	$data['delivery_date']=ConvertSQLDate($_REQUEST['delivery_date']);
	$data['delivery_place']=$_REQUEST['delivery_place'];
	$data['payment_mode']=$_REQUEST['PayMode'];
	$data['sop_no']=$_REQUEST['against_wo'];
	$data['sop_mst_itemid']=$_REQUEST['itemdetail'];
	$data['quotation_no']=$_REQUEST['party_no'];
	$data['quotation_date']=FormatDateForSQL($_REQUEST['party_date']);
	$data['basic_amt']=$_REQUEST['basicAmount'];
	$data['pkg_charge']=$_REQUEST['pkg_charges1'];
	$data['excise_id']=$_REQUEST['EDBillRate'];
	$data['excise_value']=$_REQUEST['totalDiscountedPrice'];
	$data['ecess_per']=$_REQUEST['ECessPercentage'];
	$data['ecess_amt']=$_REQUEST['ECessValue1'];
	$data['sah_per']=$_REQUEST['SAHCessValue1'];
	$data['sah_amt']=$_REQUEST['SAHCessValue'];
	$data['total_excise_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['freight']=$_REQUEST['TotalCharge']; 
	$data['add_charges']=$_REQUEST['add_charges']; 
	$data['freight1']=$_REQUEST['freight1'];
	$data['mode_transport']=$_REQUEST['mode_transport'];
	$data['grand_total']=$_REQUEST['GrandTotal'];	
	$condition="id='".$_REQUEST['SID']."'"; 
	$s->RecordEdit('direct_po', $data, $condition);
  	 
	if($_REQUEST['SID']!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['mst_productid']);$cnt++)
	{
	if($_REQUEST['mst_productid'][$cnt]!=''){
	 $insert2="Insert into direct_po_details set
	  parent_id='".$_REQUEST['SID']."',  
	  mst_itemid='".$_REQUEST['mst_productid'][$cnt]."',  
	  qty='".$_POST['Quantity'][$cnt]."',   
	  rate='".$_POST['Rate'][$cnt]."',
	  amt ='".$_REQUEST['totalValue'][$cnt]."', 
	 dis_type='".$_REQUEST['PerAmo'][$cnt]."', 
	 dis_per='".$_REQUEST['Discount'][$cnt]."',
	 net_total='".$_REQUEST['NetRate'][$cnt]."',
	 dis_price='".$_REQUEST['perc'][$cnt]."',
	 spl_dis_type='".$_REQUEST['Perspc'][$cnt]."',
	 spl_dis_per='".$_REQUEST['SpecialDiscount'][$cnt]."',
	 spl_dis_amt='".$_REQUEST['Specialperc'][$cnt]."',
	 basic='".$_REQUEST['basic'][$cnt]."',
	 excise_flag='".$_REQUEST['hid_billing_type'][$cnt]."',
	 excise_duty='".$_REQUEST['exciseDuty'][$cnt]."',
	 ExcisePercentage='".$_REQUEST['ExcisePercentage'][$cnt]."',
	 exciseValue='".$_REQUEST['exciseValue'][$cnt]."',
	 ECessPercentage='".$_REQUEST['ECessPercentage1'][$cnt]."',
	 ECessValue='".$_REQUEST['ECessValue'][$cnt]."',
	 SAHCessPercentage='".$_REQUEST['SAHCessPercentage1'][$cnt]."',
	 SAHCessValue='".$_REQUEST['SAHCessValue'][$cnt]."',	 
	 taxable_amt='".$_REQUEST['taxable_amt'][$cnt]."',
	 taxname='".$_REQUEST['taxname'][$cnt]."',
	 TotalSpecial='".$_REQUEST['TotalSpecial'][$cnt]."',    	
	 delivery_date='".FormatDateForSQL($_REQUEST['delivery_date1'][$cnt])."' ";
	$result2=DB_query($insert2,$db);
					
	}	
	}
	}
	unset($_SESSION['prdate']);	unset($_SESSION['site']);
	unset($_SESSION['mst_supplierno']);unset($_SESSION['VenderCode']);
	unset($_SESSION['mobile']);unset($_SESSION['address1']);
	unset($_SESSION['address2']);unset($_SESSION['contact_name']);
	unset($_SESSION['delivery_date']);unset($_SESSION['delivery_place']);
	unset($_SESSION['PayMode']);unset($_SESSION['against_wo']);
	unset($_SESSION['itemdetails']);unset($_SESSION['freight1']);
	unset($_SESSION['party_no']);unset($_SESSION['party_date']);
	unset($_SESSION['mode_transport']);
	unset($_SESSION['ACGRequisition-ItemList']);
	unset($_SESSION['ACGRequisition-ItemList_1']);
	unset($_SESSION['IntermediateList']);
	$s->pageLocation("index.php?route=POModule/direct_po_index".$rurl);
	
}
if(isset($_POST['cancel']))
{
unset($_SESSION['prdate']);	unset($_SESSION['site']);
	unset($_SESSION['mst_supplierno']);unset($_SESSION['VenderCode']);
	unset($_SESSION['mobile']);unset($_SESSION['address1']);
	unset($_SESSION['address2']);unset($_SESSION['contact_name']);
	unset($_SESSION['delivery_date']);unset($_SESSION['delivery_place']);
	unset($_SESSION['PayMode']);unset($_SESSION['against_wo']);
	unset($_SESSION['itemdetails']);unset($_SESSION['freight1']);
	unset($_SESSION['party_no']);unset($_SESSION['party_date']);
	unset($_SESSION['mode_transport']);
	unset($_SESSION['ACGRequisition-ItemList']);
	unset($_SESSION['ACGRequisition-ItemList_1']);
	unset($_SESSION['IntermediateList']);
	

}






?>
<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" type="text/css" href="css/professional/table_frize.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("crmquotesedit1.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 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
$sql=DB_query("select * from direct_po where id='".$_REQUEST['SID']."'",$db);
$myrow1=DB_fetch_array($sql);

 
?>
	
			<form action="" method="post">
				<div style="width:auto; margin-left:auto; margin-right:auto;">


					<table width="96%" border="1" cellpadding="3" cellspacing="0">
			 <tr> <?php 
				  $sql="SELECT sitecode, requisition_site, prdate FROM materialrequisitions WHERE requisitionno='".$reqno."' and status='1'";
				  $result=DB_query($sql,$db);
				  $myrow = DB_fetch_array($result);
				  ?>
		<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 ='".$myrow1['site']."' ",$db);?> 
		<select name="mst_branchid" id="mst_branchid" style="width:100%;" >
			<?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>PR Number</strong></th>
		<td width="16%"> <input type="text" name="prno" value="<?php echo $myrow1['pr_no']; ?>" style="width:100%;" readonly="readonly" ></td>
		<th width="15%" nowrap="nowrap"><strong>PR Date</strong></th>
		<td width="27%"><input type="text" name="prdate" value="<?php echo ConvertSQLDate($myrow1['pr_date']); ?>" style="width:100%;"  class="datepicker" /></td>
			 </tr>
			 <tr>
			<th><strong>Vendor Name</strong></th>
			<td> 
			<select name="mst_supplierno" id="mst_supplierno" style="width:100%" onchange="showvendor(this.value);"  >
			<option value="0">Select</option>
			<?php
			$sql="select id  ,vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($myrow1['vender_id']==$myrow['id'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
			</select>			</td>
			<th><strong>Vendor Code</strong></th>
			<td><div id="vendor">
			<?php $vencode=$s->getField('suppliers','id',$myrow1['vender_id'],'vendor_code');?>
			<input type="text" name="VenderCode" value="<?php echo $vencode; ?>" style="width:100%;" readonly ></div>			</td>
			
			
			<th><strong>Mobile No </strong></th>
			<td><div id="mob">
			<?php $vencode1=$s->getField('suppliers','id',$myrow1['vender_id'],'mobile');?>
              <input type="text" name="mobile" id="mobile" value="<?php echo $vencode1; ?>" style="width:100%"/>
            </div></td></tr>
			  <tr>
				<th height="31" nowrap="nowrap"><strong>Address1</strong></th>
				<td><div id="add1">
				<?php $venadd=$s->getField('suppliers','id',$myrow1['vender_id'],'adrress1');?>
				<input type="text" name="address1" value="<?php echo $venadd; ?>" style="width:100%;"; readonly></div></td>
			<th nowrap="nowrap"><strong>Address2</strong></th>
			<?php $venadd1=$s->getField('suppliers','id',$myrow1['vender_id'],'adrress2');?>
            <td><div id="add2"><input type="text" name="address2" value="<?php echo $venadd1; ?>" style="width:100%;" readonly></div></td>
<th><strong>Contact Person</strong></th>
<td><input type="text" name="contact_name" id="contact_name" value="<?php echo $myrow1['contact_person']; ?>" style="width:100%"/></td>
             </tr>
			 <tr>
				<th nowrap="nowrap"><strong>Delivery Date</strong></th>
				<td><input type="text" name="delivery_date" value="<?php echo ConvertSQLDate($myrow1['delivery_date']); ?>" style="width:100%;"  class="datepicker"></td>
			<th nowrap="nowrap"><strong>Delivery Place</strong></th>
            <td><input type="text" name="delivery_place" value="<?php echo $myrow1['delivery_place']; ?>" 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($myrow1['payment_mode'] == $myrow['paymentid'])
							$p="selected";
						?>
  <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
  <?php 	} ?>
</select></td>
             </tr>
			 <tr>
				<th nowrap="nowrap">Against  WO </th>
				<td><div id="agnstwo">
				<select name="against_wo" id="against_wo" style="width:100%">
				<option value="">Select</option>				<?php
				$sql=DB_query("select * from salesorder",$db);
				while($row1=DB_fetch_array($sql))
				{
				             $p='';
							if($myrow1['sop_no'] == $row1['id'])
							$p="selected";
				 ?>
				 <option value="<?php echo $row1['id']; ?>" <?php echo $p; ?>><?php echo $row1['orderNo']; ?></option>
				
				<?php } ?>
				</select></div>				</td>
			<th nowrap="nowrap"><strong>Item Details</strong></th>
            <td><div id="item1">
             <?php echo $s->getField('item_master','id',$myrow1['sop_mst_itemid'],'item_name');?>
            </div></td>
            <th>Freight</th>
<td><input type="text" name="freight1" id="freight1" style="width:100%" value="<?php echo $myrow1['freight1']; ?>" /></td>
             </tr>
			  <tr>
			    <th ><strong>Quotation No</strong></th>
			    <td><input type="text" name="party_no" value="<?php echo $myrow1['quotation_no']; ?>" style="width:100%;" /></td>
			    <th><strong> Quotation Date</strong></th>
			    <td ><input type="text" name="party_date" id="party_date" value="<?php echo ConvertSQLDate($myrow1['quotation_date']);?>" class="datepicker" style="width:100%;"; readonly /></td>
			    <th><strong>Mode Of Transport</strong></th>
				<td><input type="text" name="mode_transport" id="mode_transport" style="width:100%" value="<?php echo $myrow1['mode_transport']; ?>" /></td>
			      </table>
				   
									
				
				</div>
				   <br />
				 
<p align="left">	
<input type="submit" name="PickItems" value="PickItems" onclick="open_items()" />	<a href="index.php?route=POModule/direct_po_edit&action=undo&SID=<?php echo $_REQUEST['SID']; ?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><input type="button" name="Undo Deletions" value="Undo Deletions" /></a>
		 
</p>				 
<h3><center>Item Details</center></h4>
<div style="width:auto; margin-left:auto; margin-right:auto;"> 
 <div class="frisetable">
<div class="bodywidth1"> 			 
<table align='center' width='100%;' border='1' cellpadding='3' cellspacing='0'>
 <tr>
                    <td class="headcol_1" style="padding-top:12px; padding-bottom:13px;">Item Code</td>
				   <td class="headco2_1" style="padding-top:12px; padding-bottom:13px;">Item Name</td>
				    <td class="long">P.UOM</td>
					<td class="long">S.UOM</td>
				   <td class="long">P.Qty</td>
				    <td class="long">S.Qty</td>
				   <td class="long">Negotiated Rate </td>
				   <td class="long">Total Price</td>
				   <td class="long">Dis. % </td>
				   <td class="long">Dis. % <br />or amt.</td>
				   <td class="long">Final<br  />Dis. Amt.</td>
				   <td class="long">Sub Total</td>
				   <td class="long">Spl. Dis. Type<br /> %</td>
					<td class="long">Spl. Dis.<br /> %</td>
					<td class="long">Spl. Dis.<br /> Amt.</td>
					<td class="long">Basic<br /> Amt.</td>
					<td class="long">Excise flag</td>
					<td class="long">Excise</td>
					<td class="long">E-Cess</td>
					<td class="long">SAH-E Cess</td>
					<td class="long">Excise<br />
					   Amt. </td>
					<td class="long">VAT/CST</td>
					<td class="long">VAT/CST Amount</td>
					<td class="long">Total<br /> Amt.</td>
					<td class="long">Action</td>
 				   </tr>

<?php 
$i=0;
$_SESSION['requsition_itemcode']=array();
$sql2=DB_query("select * from direct_po_details where parent_id='".$_REQUEST['SID']."' and del_status=0",$db);
while($row2=DB_fetch_array($sql2))
{
$_SESSION['requsition_itemcode'][]=$row2['mst_itemid'];
$itemcode=$s->getField('item_master','id',$row2['mst_itemid'],'StockID'); 
$itemname=$s->getField('item_master','id',$row2['mst_itemid'],'item_name'); 
$secunit=$s->getField('item_master','id',$row2['mst_itemid'],'conv_unit'); 
$confac=$s->getField('item_master','id',$row2['mst_itemid'],'conv_factor');	
?>
<tr bgcolor="#FFFFFF">

	<td class="headcol"><?php echo $itemcode;?>
	<input type="hidden" name="mst_productid[]" style="width:70px"  value="<?php echo $row2['mst_itemid']; ?>"   />
	</td>
	<td class="headco2" width="8%"><?php echo $itemname;?></td>
	
	<td class="long1"><?php 
		$unit=DB_query("select * from item_master where id='".$row2['mst_itemid']."' ",$db);
		$unit1=DB_fetch_array($unit);
		//$s->getField('item_master','id',$myrow_req['mst_itemid'],'unit');
		$unitname=$s->getField('unitsofmeasure','unitid',$unit1['mst_unitid'],'unitname');
	echo $unitname;?></td>
	<td class="long1"><?php echo  $unitname1=$s->getField('unitsofmeasure','unitid',$secunit,'unitname'); ?></td>
    
   <td class="long1"><input type="text" name="Quantity[]" id="Quantity_<?php echo $i;?>" style="width:70px;"  value="<?php echo $row2['qty']; ?>"	/></td>
   <?php 
   if($confac!='')
   {
   $sec=round($row2['qty']/$confac,2);
   }
   else
   {
   $sec=0;
   }
   ?>
  <td class="long1"><?php echo $sec; ?></td> 
   
<td class="long1"><input style="width:70px;"  type="text" name="Rate[]" id="Rate_<?php echo $i;?>"    value="<?php echo $row2['rate']; ?>"/></td>
  <td class="long1"><input style="width:70px;" type="text" name="totalValue[]" id="totalValue_<?php echo $i;?>" value="<?php echo $row2['amt']; ?>" onfocus="calculateTotalPrice(<?php echo $i;?>)" readonly="true"/></td>
  <td class="long1"><select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($row2['dis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($row2['dis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>

<td class="long1"><?php echo '<input type="text" style="width:35px" name="Discount[]" id="Discount_'.$i.'" onblur="DiscountAmount(this.value,'.$i.')" value='.$row2['dis_per'].' />';?>
</td>
<td class="long1"><?php echo '<input type="text" style="width:35px" name="perc[]" id="perc_'.$i.'"  readonly="true" style="width:100%;" onfocus="Check(this.value,'.$i.')" value='.$row2['dis_price'].' />';?></td>
<td class="long1"><?php echo '<input type="text"  id="NetRate_'.$i.'" name="NetRate[]" style="width:70px;" readonly   value='.$row2['net_total'].' />';?></td>
<td class="long1"><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
    <option value="Amount" <?php echo ($row2['spl_dis_type']=='Amount')?'selected':''?>>Amount</option>
     <option value="PercentAmt" <?php echo ($row2['spl_dis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
     </select></td>
 
<td class="long1"><?php echo '<input type="text" name="SpecialDiscount[]" id="SpecialDiscount_'.$i.'" size="10" style="width:35px;" onblur="DiscountAmountdpc(this.value,'.$i.')" value='.$row2['spl_dis_per'].' />';?>
</td>
<td class="long1"><?php echo '<input type="text" style="width:35px" name="Specialperc[]" id="Specialperc_'.$i.'"  style="width:70px;" onfocus="check1(this.value,'.$i.')" value='.$row2['spl_dis_amt'].' />';?></td>
<td class="long1"><?php echo '<input type="text" style="width:70px" id="basic_'.$i.'" name="basic[]" value='.$row2['basic'].' readonly/>';?></td>
<td class="long1"><select name="hid_billing_type[]" style="width:85px" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)">
	<option value="">Select</option>
	<option value="NonExcisable"<?php if($row2['excise_flag']=='NonExcisable') { ?>selected="selected" <?php } ?> >NonExcisable</option>
	<option value="Excisable" <?php if($row2['excise_flag']=='Excisable') { ?>selected="selected" <?php } ?>>Excisable</option>
	<option value="IncludeTax" <?php if($row2['excise_flag']=='IncludeTax') { ?>selected="selected" <?php } ?>>IncludeTax</option>
	
</select></td>
<td class="long1"><select name="exciseDuty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;"    onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"<?php if($row2['excise_duty']==$excise_row['id']) { ?> selected="selected" <?php } ?> ><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $i; ?>"><input type="text" value="<?php echo $row2['exciseValue']; ?>"  style="width:120px;"/></div>
  	      </td><?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
  	      

<td class="long1"><input name="ECessPercentage1[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(<?php echo $i;?>)"  /><input name="ECessValue[]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $row2['ECessValue']; ?>"  style="width:70px;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>

	<td class="long1"><input name="SAHCessPercentage1[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="SAHCessValue[]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $row2['SAHCessValue']; ?>"  style="width:65px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
<td class="long1"><input type="text" name="taxable_amt[]" id="taxable_amt_<?php echo $i;?>" value="<?php echo $row2['taxable_amt']; ?>" style="width:70px;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
<?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
           <td class="long1">
	<select id="taxname_<?php echo $i;?>" name="taxname[]" onchange="tax_rate(this.value,<?php echo $i; ?>)" 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']==$row2['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td class="long1"><div id="taxval_<?php echo $i; ?>">
                  <input type="text" name="taxvalue[]" id="taxvalue_<?php echo $i;?>" style="width:100%;" value="" readonly="true"/>
              </div>
<input type="hidden" name="hidden_suroct[]" id="hidden_suroct_<?php echo $i;?>" value="SUR" />
	</td>
			<td class="long1"><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalSpecial[]" size="8" style="width:70px;" readonly  onfocus="cal_grandtotal(<?php echo $i;?>);" value="<?php echo $row2['TotalSpecial']; ?>"/></td>
			<td class="long1"><a href="index.php?route=POModule/direct_po_edit&action=delete&SID=<?php echo $_REQUEST['SID']; ?>&dirid=<?php echo $row2['id']; ?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>">Delete</a></td>
</tr>	
<?php 
 $i++; }
 
 ?>
 <?php 
 if(isset($_SESSION['ACGRequisition-ItemList_1']) )
{
	// print_r($_SESSION['ACGRequisition-ItemList_1']);
	  $itemcode_list=explode('#',$_SESSION['ACGRequisition-ItemList_1']);
	 //echo"<pre>";
	  //print_r($itemcode_list);
	 
	 	for($j=0,$k=$i;$j<count($itemcode_list);$j++,$k++)
		{
				
			$yy=explode(",",$itemcode_list[$j]);
			//print_r($yy);
			if($j%2==0)
			{$bg="#CCCCCC";}
			else
			$bg="#C8BECB";
				
			$_SESSION['requsition_itemcode'][]=$yy[0];
		    // echo "select * from item_master where id='".$itemcode_list[$j]."'";
			 $itemquery=DB_query("select * from item_master where id='".$itemcode_list[$j]."'" , $db);
         	$item_row=DB_fetch_array($itemquery);
			?>
			<tr bgcolor="#FFFFFF">
			
	<td class="headcol"><?php echo $item_row['StockID'];?>
	<input type="hidden" name="mst_productid[]" style="width:70px"  value="<?php echo $item_row['id']; ?>"   />
	</td>
	<td class="headco2" width="8%"><?php echo $item_row['item_name'];?></td>
	
	<td class="long1"><?php 
		$unit=DB_query("select * from item_master where id='".$item_row['id']."' ",$db);
		$unit1=DB_fetch_array($unit);
		//$s->getField('item_master','id',$myrow_req['mst_itemid'],'unit');
		$unitname=$s->getField('unitsofmeasure','unitid',$unit1['mst_unitid'],'unitname');
	echo $unitname;?></td>
    
   <td class="long1"><input type="text" name="Quantity[]" id="Quantity_<?php echo $i;?>" style="width:70px;"  value=""	/></td>
<td class="long1"><input style="width:70px;"  type="text" name="Rate[]" id="Rate_<?php echo $i;?>"    value=""/></td>
  <td class="long1"><input style="width:70px;" type="text" name="totalValue[]" id="totalValue_<?php echo $i;?>" value="" onfocus="calculateTotalPrice(<?php echo $i;?>)" readonly="true"/></td>
  <td class="long1"><select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['PerAmo']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt"<?php echo ($_POST['PerAmo']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>

<td class="long1"><?php echo '<input type="text" style="width:35px" name="Discount[]" id="Discount_'.$i.'" onblur="DiscountAmount(this.value,'.$i.')" />';?>
</td>
<td class="long1"><?php echo '<input type="text" style="width:35px" name="perc[]" id="perc_'.$i.'"  readonly="true" style="width:100%;" onfocus="Check(this.value,'.$i.')"/>';?></td>
<td class="long1"><?php echo '<input type="text"  id="NetRate_'.$i.'" name="NetRate[]" style="width:70px;" readonly/>';?></td>
<td><select style="width:100%;" name="Perspc[]" id="Perspc_<?php echo $i;?>">
    <option value="Amount" <?php echo ($_POST['Perspc']=='Amount')?'selected':''?>>Amount</option>
     <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt')?'selected':''?>>Percent Amt</option>
     </select></td>
 
<td class="long1"><?php echo '<input type="text" name="SpecialDiscount[]" id="SpecialDiscount_'.$i.'" size="10" style="width:35px;" onblur="DiscountAmountdpc(this.value,'.$i.')" />'; ?>
</td>
<td class="long1"><?php echo '<input type="text" style="width:35px" name="Specialperc[]" id="Specialperc_'.$i.'"  style="width:70px;" onfocus="check1(this.value,'.$i.')"/>';?></td>
<td class="long1"><?php echo '<input type="text" style="width:70px" id="basic_'.$i.'" name="basic[]" readonly/>';?></td>
<td class="long1"><select name="hid_billing_type[]" style="width:85px" id="hid_billing_type_<?php echo $i;?>"  onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
	
</select></td>
<td class="long1"><select name="exciseDuty[]" id="exciseDuty_<?php echo $i;?>" style="width:120px;"    onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $i; ?>"></div>
  	      </td><?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
  	      

<td class="long1"><input name="ECessPercentage1[]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(<?php echo $i;?>)"  /><input name="ECessValue[]" id="ECessValue_<?php echo $i;?>" type="text" value=""  style="width:70px;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>

	<td class="long1"><input name="SAHCessPercentage1[]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="SAHCessValue[]" id="SAHCessValue_<?php echo $i;?>" type="text" value=""  style="width:65px;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
<td class="long1"><input type="text" name="taxable_amt[]" id="taxable_amt_<?php echo $i;?>" value="" style="width:70px;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
<?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
           <td class="long1">
	<select id="taxname_<?php echo $i;?>" name="taxname[]" onchange="tax_rate(this.value,<?php echo $i; ?>)" 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['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td class="long1"><div id="taxval_<?php echo $i; ?>">
                  <input type="text" name="taxvalue[]" id="taxvalue_<?php echo $i;?>" style="width:100%;" value="" readonly="true"/>
              </div>
<input type="hidden" name="hidden_suroct[]" id="hidden_suroct_<?php echo $i;?>" value="SUR" />
	</td>
			<td class="long1"><input type="text" id="TotalSpecial_<?php echo $i;?>" name="TotalSpecial[]" size="8" style="width:70px;" readonly  onfocus="cal_grandtotal(<?php echo $i;?>);" value="0"/></td>
			<td class="long1"></td>
</tr>	
<?php 
		}
	  }
	  ?>
	  <input type="hidden" name="count" id="count" value="<?php echo ($i+$j);?>" style="width:70px" /> 
 
			
			


			
			</table>
			</div>

			</div>
	</div>
	<br />	
<div align="right">			
			<table width="40%" border="0">
			
			<tr><td>
		      <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input name="basicAmount" type="text" value="<?php echo $myrow1['basic_amt']; ?>"  onfocus="cal_totalamount()" id="afterdiscountprice" style="width:100%" ></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
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				$c='';
				if($myrow1['excise_id']==$ServiceRow['id'])
				$c='selected';
				?>
				<option value="<?php echo $ServiceRow['id']?>"<?php echo $c; ?>><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" onfocus="calculateTotalExcise()" value="<?php echo $myrow1['excise_value']; ?>"/>
				</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="ECessValue1" id="ECessValue" type="text" value="<?php echo $myrow1['ecess_amt']; ?>" style="width:176px;" readonly onfocus="calculateECess1()"/></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="SAHCessValue1" id="SAHCessValue" type="text" value="<?php echo $myrow1['sah_amt']; ?>" 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()" value="<?php echo $myrow1['total_excise_amt']; ?>" /></td>
					
					</tr>
					<tr>
					<td><strong>Taxable Amount</strong></td>
					<td><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%" onfocus="showexiseamt1()"  value="<?php echo $myrow1['total_taxable_amt']; ?>"/></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 ($myrow1['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 
              </tr>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $myrow1['vat_amt']; ?>" readonly="true"/>
              </div>	</td>
                </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  size="10" onchange="calsuroctamt(this.value)" value="<?php echo $myrow1['sur_per']; ?>"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $myrow1['sur_amt']; ?>" style="width:72%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" style="width:100%;" value="<?php echo $myrow1['freight']; ?>"/></td>
                </tr>
				<tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges1" id="pkg_charges1" type="text" value="<?php echo $myrow1['pkg_charge']; ?>" size="42" /></td>
                </tr>
                
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $myrow1['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
							
                <tr>
				<td><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" onfocus="cal_grandamount()"  value="<?php echo $myrow1['grand_total']; ?>" size="12"/></td>
                </tr>
              </table></td></tr>
		 
			</table>
</div>
<p align="center"><input type="submit" name="Save" value="Save" />
<input type="submit" name="cancel" value="cancel" /></p>



<script type="text/javascript">
function calcPackaging(str)
{
	if(str!='')
	{
		var tota_amt=document.getElementById("total_item_amount").value;
		var pckgng_val=(str/100)*tota_amt;
		document.getElementById("pkg_charges1").value=pckgng_val.toFixed(2);
	}
}
function calcRounded(str)
{
	var gtotal=document.getElementById('orig_grand_tot').value;
	var gtotal_brk=gtotal.split('.');
	if(str=='+')
	{var final=parseInt(gtotal_brk[0])+1;}
	else if(str=='-')
	{var final=parseInt(gtotal_brk[0]);}
	else if(str=='')
	{var final=gtotal;}
	document.getElementById('GrandTotal').value=final;
}
function calculateExciseDuty(i)
{
	var basic=document.getElementById("basic_"+i).value;
	var ExcisePercentage=document.getElementById("ExcisePercentage_"+i).value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue_"+i).value=exciseVal.toFixed(2);
}
function hid_billing_typecheck(i,str){

	//alert(str);
	//var type= document.getElementById("ExcisePercentage_"+i).value;
	if(str=='')
	{
		alert("Select Tax Type");
	}

}
function checkExcisable(str,i)
{
 	
	if(str=='NonExcisable')
	{
		
		
		document.getElementById("exciseDuty_"+i).disabled=true;
		//document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		//document.getElementById("taxname_"+i).disabled=false;
		//document.getElementById("taxvalue_"+i).disabled=false;
		//document.getElementById("exciseDuty_"+i).value='';
		//document.getElementById("exciseValue_"+i).value='';
		//document.getElementById("ECessPercentage_"+i).value='';
		//document.getElementById("ECessValue_"+i).value='';
		//document.getElementById("SAHCessPercentage_"+i).value='';
		//document.getElementById("SAHCessValue_"+i).value='';
		//document.getElementById("taxable_amt_"+i).value='';
		//document.getElementById("ExcisePercentage_"+i).value='';
	//	document.getElementById("taxvalue").disabled=true;
		//document.getElementById("sur_oct_perc").disabled=true;
		//document.getElementById("sur_oct_amt").disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty_"+i).disabled=false;
		//document.getElementById("exciseValue_"+i).disabled=false;
		document.getElementById("ECessPercentage_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;		
		document.getElementById("SAHCessPercentage_"+i).disabled=false;
	
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("sur_oct_perc_"+i).disabled=false;
		document.getElementById("sur_oct_amt_"+i).disabled=false;
		
		document.getElementById("TotalCharge_"+i).disabled=false;
		document.getElementById("packagingCharges_"+i).disabled=false;
		document.getElementById("additionalCharges_"+i).disabled=false;
		document.getElementById("roundOff_"+i).disabled=false;	
		
		
	}
	else{
		document.getElementById("exciseDuty_"+i).disabled=true;
		//document.getElementById("exciseValue_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=true;
		document.getElementById("taxvalue_"+i).disabled=true;
		document.getElementById("sur_oct_perc_"+i).disabled=true;
		document.getElementById("sur_oct_amt_"+i).disabled=true;
		document.getElementById("TotalCharge_"+i).disabled=true;
		document.getElementById("packagingCharges_"+i).disabled=true;
		document.getElementById("additionalCharges_"+i).disabled=true;
		document.getElementById("roundOff_"+i).disabled=true;

		document.getElementById("exciseDuty_"+i).value='';
		//document.getElementById("exciseValue_"+i).value='';
		document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
		document.getElementById("taxname_"+i).value='';
		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("sur_oct_perc_"+i).value='';
		document.getElementById("sur_oct_amt_"+i).value='';
		document.getElementById("TotalCharge_"+i).value='';
		document.getElementById("packagingCharges_"+i).value='';
		document.getElementById("additionalCharges_"+i).value='';
		document.getElementById("roundOff_"+i).value='';


	
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}
function calculateECess(i)
{
	
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessPercentage=document.getElementById("ECessPercentage_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue_"+i).value=total.toFixed(2);
}
function calculateSAHCess(i)
{
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage_"+i).value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue_"+i).value=total.toFixed(2);
}
function checkexiseflag(i)
{

	if(document.getElementById("hid_billing_type_"+i).value=='')
	{
	//document.getElementById("exciseDuty_"+i).disabled=true;
	//document.getElementById("exciseValue_"+i).disabled=true;
	//document.getElementById("ECessPercentage_"+i).disabled=true;
	//document.getElementById("ECessValue_"+i).disabled=true;
	//document.getElementById("SAHCessPercentage_"+i).disabled=true;
	//document.getElementById("SAHCessValue_"+i).disabled=true;
	//document.getElementById("taxable_amt_"+i).disabled=true;
	//document.getElementById("taxname_"+i).disabled=true;
	//document.getElementById("taxvalue_"+i).disabled=true;	
	alert("Select Tax Type");
	document.getElementById("hid_billing_type_"+i).focus();
	}	
	
}
function claculateExcise(i,str)
{
	
	var discounted=document.getElementById("basic_"+i).value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId_"+i).innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			document.getElementById("exciseId_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();
}

function calculateTotalPrice(i)
{
  if(document.getElementById("Rate_"+i).value=='')
  {
  alert("must Enter Rate");
  document.getElementById("Rate_"+i).focus();	
  }
  else
  {	
	Quantity = document.getElementById("Quantity_"+i).value;
	Rate= document.getElementById("Rate_"+i).value;
	var Total=Quantity*Rate;
	document.getElementById("totalValue_"+i).value=Total.toFixed(2);
}
}


function calculateTaxable(i)
{
	//var totalDiscountedPrice=document.getElementById("basic_"+i).value;
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessValue=document.getElementById("ECessValue_"+i).value;
	var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
	
	//if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	//var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxable_amt_"+i).value=TOTAL.toFixed(2);
}




function calc_tax_amount()
{
	var taxable=document.getElementById("taxable_amt").value;
	var taxval=document.getElementById("taxvalue").value;
	var final=taxable*(taxval/100);
	document.getElementById("tot_tax_amount").value=final.toFixed(2);
}

function get_charge(str)
{
	document.getElementById("hidden_suroct").value=str
}

function cal_suroct(i,str)
{
	
	var total_tax=document.getElementById("taxvalue_"+i).value;
	
	var final_sur=total_tax*(str/100);
	document.getElementById("sur_oct_amt_"+i).value=final_sur.toFixed(2);
}
//function tax_rate(str,i)
//{

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

//if(billing_type=='NonExcisable')
//{
//var taxableAmount=document.getElementById("basic_"+i).value;}
//else if(billing_type=='Excisable')
//{
//var taxableAmount=document.getElementById("taxable_amt_"+i).value;}
//alert(taxableAmount);
//if (str.length==0)
 // {
  //document.getElementById("taxval_"+i).innerHTML="";
  //return;
  //}
//if (window.XMLHttpRequest)
 // {// code for IE7+, Firefox, Chrome, Opera, Safari
 // xmlhttp=new XMLHttpRequest();
  //}
//else
 // {// code for IE6, IE5
 // xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 // }
//xmlhttp.onreadystatechange=function()
 // {
 // if (xmlhttp.readyState==4 && xmlhttp.status==200)
  //  {
  //  document.getElementById("taxval_"+i).innerHTML=xmlhttp.responseText;
 //   }
 // }
//xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount+"&data="+i,true);
//xmlhttp.send();
//}

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

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

if(billing_type=='NonExcisable')
{
var taxableAmount=document.getElementById("basic_"+i).value;}
else if(billing_type=='Excisable')
{
var taxableAmount=document.getElementById("taxable_amt_"+i).value;}
alert(taxableAmount);
if (str.length==0)
  {
  document.getElementById("taxval_"+i).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("taxval_"+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_valdata.php?taxid="+str+"&amt="+taxableAmount+"&data="+i,true);
xmlhttp.send();
}


function getdata(str)
{
	
	if (str.length==0)
  		{
  			document.getElementById("PaymentTerm").innerHTML="";
  			return;
  		}
		if (window.XMLHttpRequest)
  		{// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
  		}
		else
  		{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		xmlhttp.onreadystatechange=function()
  		{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    			document.getElementById("PaymentTerm").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","paytermsdata.php?site="+str,true);
		xmlhttp.send();
}
function checkvalid()
{
	var count = document.getElementById("count").value;
	//alert(count);
	
	//alert(count);
	if(document.getElementById("mst_supplierno").value == '0')
	{
		alert("Please Select Vendor");
		document.getElementById("mst_supplierno").focus();
		return false;
	}
	
	if(document.getElementById("Basis").value == '000')
	{
		alert("Please Select Basis");
		document.getElementById("Basis").focus();
		return false;
	}
	if(document.getElementById("PaymentTerm").value == '000')
	{
		alert("Please Select Payment Term");
		document.getElementById("PaymentTerm").focus();
		return false;
	}
	if(document.getElementById("PayMode").value == '000')
	{
		alert("Please Select Pay Mode");
		document.getElementById("PayMode").focus();
		return false;
	}
	
	if(document.getElementById("party_date").value == '//')
	{
		alert("Please Select Party Date");
		document.getElementById("party_date").focus();
		return false;
	}
	var ratedata;
	for(var i=1; i<count; i++)
	{
	//alert(document.getElementById("Rate_"+i).value);
	if(document.getElementById("Rate_"+i).value =='')
	{
	 ratedata=0;
	}
	else
     {
      ratedata=1;
	  break;
      }
		
	}
	//alert(ratedata);
if(ratedata==0)
{
alert("Please Enter Rate Of Item");
return false;
}	
return true;
	
}
function calc_totaltax()
{
	var total_tax=0;
	var cnt=document.getElementById("count").value
	for(var j=1;j<cnt;j++)
	{
		var taxamt=document.getElementById("totaltaxamount_"+j).value;
		total_tax=parseFloat(total_tax)+parseFloat(taxamt);
	}
	document.getElementById("total_tax").value=total_tax.toFixed(2);
}
function cal_totalcharge()
{
	var total=0;
	var count=document.getElementById("countcharges").value;
	for(var i=1; i<count;i++)
	{
		var actualamt=document.getElementById("actual_"+i).value;
		if(actualamt!='')
		{
		total=parseFloat(total)+parseFloat(actualamt);
		}
	}
	document.getElementById("TotalCharge").value=total.toFixed(2);
}

function cal_totalamount()
{
	
	var total=0;
var t=document.getElementById("count").value;

alert(t);
for(var i=0;i<t;i++)
{
var amt=parseFloat(document.getElementById("TotalSpecial_"+i).value);
total=parseFloat(total)+amt;	
}	
document.getElementById("afterdiscountprice").value=total.toFixed(2);	
}

function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var 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 roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	/*if(roundOffVal==''){roundOffVal='-.0';}
	
	var test=roundOffVal.split(".");
	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
	 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }*/
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}
function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;
	var taxamt=document.getElementById("taxvalue").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 roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
	if(roundOffVal==''){roundOffVal='-.0';}	
	var test=roundOffVal.split(".");	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
}

function cal_grandtotal(i)
{
	var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	//alert(basic);
	var Totaltaxable=document.getElementById("taxable_amt_"+i).value;
	//var vatcstAmt=document.getElementById("taxvalue_"+i).value;
	

	//var roundOffVal=document.getElementById("roundOff_").value;
	
	//if(roundOffVal==''){roundOffVal='-.0';}
	
	//var test=roundOffVal.split(".");
	
	//alert(test[0]);
	
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	//if(vatcstAmt==''){vatcstAmt=0;}
	
	
	
	
	if(document.getElementById("hid_billing_type_"+i).value=='NonExcisable')
	{
	
		//var grand_tot1=parseFloat(basic)+parseFloat(vatcstAmt);
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		
	}	
	
	
else if(document.getElementById("hid_billing_type_"+i).value=='IncludeTax'){

var grand_tot1= parseFloat(basic) ;
var grand_tot=grand_tot1.toFixed(2);
}
	else{
	//var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(vatcstAmt);
	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		//var grand_tot1= parseFloat(Totaltaxable)+parseFloat(vatcstAmt);
			var grand_tot=grand_tot1.toFixed(2);
		
		 }
	  //alert(	document.getElementById("TotalSpecial_"+i).value);
	 	//alert(grand_tot);
	 	document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
		//alert(	document.getElementById("TotalSpecial_"+i).value);
	
}


function checkstatus(str)
{
	var Charge = document.getElementById("Charge_"+str).value;
	var actual = document.getElementById("actual_"+str).value;
	if(Charge == 'NO' && actual == '')
	{
		alert("Please Enter Some Value Since It Is Not Inclusive");
		return false;
	}
}
var TotalPercent=0;
var TotalAmnt=0;
var finalAmount=0;

function ChargeCalculater(Amt,Amtid)
  {
	 var AsPerActual=document.getElementById(Amtid).value;
	 var ActualType=document.getElementById("AsPerActual_" +Amtid).value;
	 
	 if(AsPerActual !='')
	 {
	 if(ActualType=='PercentAmt')
	   {
	     var Total= document.getElementById("Total").value;
		 var charge= parseFloat(Total) * parseFloat(AsPerActual)/100;
		 document.getElementById("actual_"+Amtid).value = charge;
		 TotalPercent= parseFloat(TotalPercent) + parseFloat(charge);
	   }
	 else
	   {
	     document.getElementById("actual_"+Amtid).value=AsPerActual; 
		 TotalAmnt=parseFloat(TotalAmnt) + parseFloat(AsPerActual);
	   }
	}
	return true;
  }
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
// Total Charges Cost    = All Charges Amount Add                                                    //
// Grand Total           = Total Charges  + Material Cost With Taxes                                 //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function FinalGrandTotal(A)
   {
	  var Total=document.getElementById("Total").value;
	  var FinalGT= parseFloat(Total) + parseFloat(A);
	  
	  /*if(A == '')
	  {*/
	  if(isNaN(FinalGT))
		{
		  document.getElementById("GrandTotal").value=parseFloat(Total);
		}
		else
		{
		  document.getElementById("GrandTotal").value=parseFloat(FinalGT);
		}
		  
   }
   
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
//As Per Requirment Inclusive Option Yes -> Hide As Per Actual                                       //
//As Per Requirment Inclusive Option NO ->  Show As Per Actual                                       //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function ChargeAmount(CA,ID)
 {
   if (CA=='NO')
     {
		document.getElementById(ID).disabled=false;
		document.getElementById("actual_"+ID).disabled=false;
		document.getElementById("AsPerActual_"+ID).disabled=false;
	 }
	else if (CA!='NO')
	 {
		document.getElementById(ID).disabled=true;
		document.getElementById("AsPerActual_"+ID).disabled=true; 
		document.getElementById("actual_"+ID).disabled=true;
		document.getElementById(ID).value='';
		document.getElementById("actual_"+ID).value='';
	 }    
  }
var Total=0;
 function DiscountAmount(DA,i)
{
	//var totalnetrate=document.getElementById("totalValue_"+i).value;	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	
	var rate = document.getElementById("Rate_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var quantity = document.getElementById("Quantity_"+i).value;
	var totalPrice = parseFloat(quantity)*parseFloat(rate);
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
		
	//alert(totalnetrate);
	
		var percent = parseFloat(document.getElementById("Discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = totalPrice-parseFloat(percent);
	
	}
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("NetRate_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	//return true;
}	
function Check(Ta,i)
{
var totalnetrate=parseFloat(document.getElementById("totalValue_"+i).value);
var discount = parseFloat(document.getElementById("Discount_"+i).value);
var discount1=parseFloat(document.getElementById("perc_"+i).value);

if(totalnetrate<discount)	
	{
	alert("Discount Amount Not Greater then Total Price");
	document.getElementById("Discount_"+i).value='';
	document.getElementById("perc_"+i).value='';	
	document.getElementById("Discount_"+i).focus();
	
	}	
else if(totalnetrate<discount1)	
{
	
alert("Discount Amount Not Greater then Total Price");
	document.getElementById("Discount_"+i).value='';
	document.getElementById("perc_"+i).value='';	
	document.getElementById("Discount_"+i).focus();
		
}	
	
}
function check1(Ta1,i)
{
var total1=parseFloat(document.getElementById("NetRate_"+i).value);	
var Specialperc=parseFloat(document.getElementById("Specialperc_"+i).value);
if(total1<Specialperc)	
{
alert("Special Discount Amount Not Greater then Sub Total");
	document.getElementById("SpecialDiscount_"+i).value='';
	document.getElementById("Specialperc_"+i).value='';	
	document.getElementById("SpecialDiscount_"+i).focus();	
}
}

function DiscountAmountspe(DA,i)
{
	
	
	var total1=document.getElementById("NetRate_"+i).value;
	
	var discount1 = document.getElementById("SpecialDiscount_"+i).value;
	var Specialperc=document.getElementById("Specialperc_"+i).value;
	
	if(discount1=='' && Specialperc=='')
	{
		var total1=document.getElementById("NetRate_"+i).value;
		
		document.getElementById("basic_"+i).value=total1;
	
	}
	else
	{
		if(discount1=='' && Specialperc!='')
		{
			var elx=document.getElementById("Specialperc_"+i).value;
			var total1=document.getElementById("NetRate_"+i).value;
			
			var TotalAmount2 = total1-parseFloat(elx);
			
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
		else
		{
			var percent1 = total1 * parseFloat(discount1)/100;
			var TotalAmount2 = total1-parseFloat(percent1);
	
			document.getElementById("Specialperc_"+i).value=percent1.toFixed(2);
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
	
	}
}
function DiscountAmountdpc(DA,i)
{
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("NetRate_"+i).value;
	var discount = document.getElementById("SpecialDiscount_"+i).value;
	
	if(discount_percent=='PercentAmt' )
	{
	   if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("SpecialDiscount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	if(parseFloat(discount)>=100 && discount_percent=='PercentAmt')
		{
		alert("Discount Percentage Should Be Less Then 100");
		document.getElementById("Specialperc_"+i).value='';
		document.getElementById("SpecialDiscount_"+i).value='';
	     document.getElementById("basic_"+i).value='';
	     document.getElementById("SpecialDiscount_"+i).focus();
		return false;
		}
		else
		{
	document.getElementById("Specialperc_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;

}
	}


function caldata(i)
{
if(document.getElementById("exciseDuty_"+i).value=='')
{
alert("Please Select Excise Duty");
document.getElementById("exciseDuty_"+i).focus();
	
}	
	
}
 
</script>

<script>
 var TotalAmount=0;
function AmountWithtax(AWT, i ,j)
{
	//alert("manvi");
    var NetRate = document.getElementById("NetRate_"+i).value;
   	var TaxValue = document.getElementById("taxvalue_"+i).value;
	var TotalAmountWithTax = (parseFloat(NetRate) * parseFloat(TaxValue))/100;
	if(isNaN(TotalAmountWithTax)){
	document.getElementById("totaltaxamount_"+i).value=parseFloat(0);
	document.getElementById("TotalAmountWirhTaxAmount_"+i).value = NetRate;
	}else{
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	if(isNaN(TotalTaxAmount)){
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(0);
	}else{	
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(TotalTaxAmount) + parseFloat(NetRate);
	}
	}	
	TotalAmount=parseFloat(TotalAmount) + parseFloat(TotalCostWithTax);
		//document.getElementById("Total").value=TotalAmount;
	return true;
}
function totalGetvalue()
	{
		//alert("manvi");
		var amount=0; 
		var ob;
		var count = document.getElementById("count").value;
		for(i=1;i<count;i++)
		{
			ob=document.getElementById("TotalAmountWirhTaxAmount_"+i);
			if(ob.value!='')
			{
				amount +=parseFloat(ob.value);
			}
	    }
		document.getElementById("Total").value=amount;
	}






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 open_items()
{
window.open("crmquotes3.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&SID=<?php echo $_REQUEST['SID']; ?>","item_popup_window","height=500,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}



function calculateBillExcise(str)
{
	var value=document.getElementById("afterdiscountprice").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;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}

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


function 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 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 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 cal_grandamount()
{
	var total=document.getElementById("afterdiscountprice").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var totalitemamt=document.getElementById("total_item_amount").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(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(     additionalCharges)+parseFloat(taxamt);

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


</script>
