<?php
error_reporting("E_ALL");
$PageSecurity = 5;


if(isset($_POST['Save']))
{
    $prefixtitle='ATL/'.$_REQUEST['site'].'/PO';	
   					
	$SQLMax=DB_query("select pr_no as QutNo from log_po where site='".$_REQUEST['site']."' order by id DESC limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$explode=explode("/",$MaxQut['QutNo']);
	$FinMx=$explode[3]+1;
	$FinalCode=$prefixtitle."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$prefixtitle."/".'00001';
	}	
	
	$data['site']=$_REQUEST['site'];
	$data['store']=$_REQUEST['storecode'];
	$data['pr_no']=$FinalCode;
	$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['ptype'] = $_REQUEST['ptype'];
	$data['total_amt'] = $_REQUEST['total_item_amount'];
	$data['pkg_per'] = $_REQUEST['pkg_perc'];
	$data['pkg_amt'] = $_REQUEST['pkg_charges'];
	$data['excise_id'] = $_REQUEST['EDBillRate'];
	$data['excise_amt'] = $_REQUEST['totalDiscountedPrice'];
	$data['ecess_per'] = $_REQUEST['ECessPercentage'];
	$data['ecess_amt'] = $_REQUEST['ECessValue1'];
	$data['sah_per'] = $_REQUEST['SAHCessPercentage'];
	$data['sah_amt'] = $_REQUEST['SAHCessValue1'];
	$data['total_excise_amt'] = $_REQUEST['total_excise_amount'];		
	$data['vat_cst'] = $_REQUEST['vat_cst'];
	$data['vat_cst_amt'] = $_REQUEST['taxvalue'];
	$data['sur_per'] = $_REQUEST['sur_oct_per'];	
	$data['sur_amt'] = $_REQUEST['sur_oct_amt'];
	$data['freight'] = $_REQUEST['tot_freight'];
	$data['loading'] = $_REQUEST['loading'];
	$data['additional_charge'] = $_REQUEST['add_charges'];
	$data['grand_total'] = $_REQUEST['grandtotal'];
	$data['companyID'] = $_SESSION['ACGCompanyId'];
	$data['created_by']=$_SESSION['UserID'];
	$data['created_date']=date('Y-m-d');
	$s->RecordInsert('log_po', $data);
    $masterId=DB_Last_Insert_ID($db,'log_po','id');
	if($masterId!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['itemdataid']);$cnt++)
	{
	if($_REQUEST['poqty'][$cnt]!='')
	{
	  $insert2="Insert into log_po_details set
	  parent_id='".$masterId."',  
	  mst_itemid='".$_REQUEST['itemdataid'][$cnt]."',  
	  qty='".$_POST['poqty'][$cnt]."',
	  qty1='".$_POST['poqty'][$cnt]."',   
	  rate='".$_POST['porate'][$cnt]."',
	  amt ='".$_REQUEST['totalamt'][$cnt]."'";
	$result2=DB_query($insert2,$db);
	
	}	
	}
	}	
	$s->pageLocation("index.php?route=LOG/transaction/po_index".$rurl);
}
?>
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:fixed;
left:280px;
top:200px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<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 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>

	
			<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%" class="tabledata1">Location </th>
    <td width="17%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td><?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
      $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql=DB_query($ss,$db);
	  }
	  else
	  {
		$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql=DB_query($ss,$db);
	  }?>
     <select name="site" onchange="getreqitemdata(this.value)" id="sitecode" style="width:70px"    >
      <option value="0">---Select---</option>
      <?php
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($sitecode==$site_row['loccode']?'selected':'')?>><?php echo $site_row['loccode'];?></option>
      <?php } ?>
    </select></td>
	  <td><div id="txtsite">
	    <?php
	
	$site_sql="Select locationname from locations where loccode ='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	if(isset($sitecode))
	{
	?>
	    <input name="sitename2" type="text" id="sitename2"  value="<?php echo $site_row['locationname'];?>" size="20" readonly="true" />
	    <?php } else {?>
	<input name="sitename" type="text" id="sitename"  value="<?php echo $sitename;?>" size="20" readonly="true">
	<?php } ?>
	<input type="hidden" name="hidden_site" id="hidden_site" value="<?php echo $_REQUEST['hidden_site'];?>"/></div></td>
	</tr>
	<tr></tr>
	</table>
	</td>
	<th width="14%" class="tabledata1">Warehouse</td>
    <td width="16%" id="storedata">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
		<td>	
		<?php
		$sql_store = "select id, StoreCode, StoreName from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in ('".$_SESSION['AssignedBranch']."') order by StoreCode ASC";
		$resultStkLocs = DB_query($sql_store,$db);
		?>
		<select id="storecode" name="storecode"  style="width:100%">
		<option value="000">Select</option> 
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
		{
				$p='';
				if($storecode==$myrow['id'])
				$p="selected";
		?>
			<option Value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo $myrow['StoreName']; ?></option>
		<?php }
		?>
		</select>		</td>
        <!--<td><div id="txtid"><input type="text" name="storename" id="storename" size="20" readonly="true" value="<?php echo $storename; ?>"></div></td>-->
      </tr>
    </table></td>

		<th width="15%"><strong>PO Number</strong></th>
		<td width="27%"> <input type="text" name="prno" value="Auto Generated" style="width:100%;" readonly="readonly" ></td>
			 </tr>
			 <tr>
			 <th nowrap="nowrap"><strong>PO Date</strong></th>
			<td><input type="text" name="prdate"  style="width:100%;"  class="datepicker" value="" /></td>
			<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($_SESSION['mst_supplierno']==$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">
			<input type="text" name="VenderCode" value="<?php echo $_SESSION['VenderCode']; ?>" style="width:100%;"; readonly>
			</div>			</td>
			
			
			</tr>
			  <tr>
			  <th><strong>Mobile No </strong></th>
			<td><div id="mob">
              <input type="text" name="mobile" id="mobile" value="<?php echo $_SESSION['mobile']; ?>" style="width:100%"/>
            </div></td>
				<th height="31" nowrap="nowrap"><strong>Address1</strong></th>
				<td><div id="add1">
				<input type="text" name="address1" value="<?php echo $_SESSION['address1']; ?>" style="width:100%;"; readonly></div></td>
			<th nowrap="nowrap"><strong>Address2</strong></th>
            <td><div id="add2"><input type="text" name="address2" value="<?php echo $_SESSION['address1']; ?>" style="width:100%;" readonly></div></td>

             </tr>
			 <tr>
			 <th><strong>Contact Person</strong></th>
<td><input type="text" name="contact_name" id="contact_name" value="<?php echo $_SESSION['contact_name']; ?>" style="width:100%"/></td>
				<th nowrap="nowrap"><strong>Delivery Date</strong></th>
				<td><input type="text" name="delivery_date" value="<?php echo $_SESSION['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 $_SESSION['delivery_place']; ?>" style="width:100%;" ></td>
             </tr>
			 <tr>
			 <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($_SESSION['PayMode'] == $myrow['paymentid'])
							$p="selected";
						?>
  <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
  <?php 	} ?>
</select></td>
	<th>Type</th>
    <td>
		<select name="ptype" id="ptype"	style="width:150px;">
			<option value="0">Select</option>
			<option value="1">Local</option>
			<option value="2">Import</option>
		</select>
	</td>
				<th nowrap="nowrap">&nbsp;</th>
				<td>&nbsp;</td>
			 </tr>
			      </table>
				   
									
				
				</div>
				   <br />
				 
<p align="left" style="padding-left:10px;">
 <!-- <input type="button" name="Add" value="Add"  onclick="addRow('dataTable')"/>
  <input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="checkdata()" class="search" />-->
    <div id="para" style="display:none;"><input type="button" name="Add" value="Add" class="search" /></div>
	<input type="button" class="search"   onclick="deleteRowOrderO('dataTable')" value="Delete" />
  </p>			 
<h3><center>Item Details</center></h4>

<div style="overflow:auto; width:950px; margin-left:auto; margin-right:auto; height:auto">
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
          <th><strong>S. No.</strong></th>
          <th></th>
          <th><strong>Item Code</strong></th>
          <th><strong>Item Name</strong></th>
          <th><strong>UOM</strong></th>
          <th><strong>Qty</strong></th>
		   <th><strong>Rate</strong></th>
		    <th><strong>Total Amt</strong></th>
        </tr>
        <tbody id="dataTable">
          <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" id="delitem" /></td>
            <td><input  type="hidden"   readonly=""  id="itemdataid"  name="itemdataid[]" /></td>
            <td><input type="text" value="" tabindex=""   id="itemcode" name="itemcode[]"size="20"
			 onkeyup="opendatas(this.value,this.id)"/>
            </td>
            <td><input type="text" name="desc[]"  id="descriptions" size="25"  value=""/></td>
            <td><input type="text" name="uom[]" id="uom" value="" readonly /> </td>
	 		<td><input  type="text" name="poqty[]"  id="poqty" size="30"   value=""   /></td>
		  <td><input  type="text" name="porate[]"  id="porate" size="30"  value="" onkeyup="calamt1(this.id,this.value)" /></td>
            <td><input  type="text" name="totalamt[]"  id="itemtotalrate" size="30"   value="" readonly  /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />
	<br />	
<div align="right">			
			<table width="40%" border="0">
			
			<tr><td>
		      <table width="40%" border="1" cellspacing="0" cellpadding="3" align="right">
                <tr>
                  <td><strong>TOTAL AMOUNT <font color="#FF0000">*</font></strong> </td>
                  <td >
				 
				  <input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()" readonly="true"/>
				
				  </td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_perc" id="pkg_perc" value="<?php echo $venddata['pkg_per']; ?>" size="5" onkeyup="calcPackaging(this.value)" /><input name="pkg_charges" id="pkg_charges1" type="text" value="" size="28"  
				  onfocus="calcPackaging1()" /></td>
                </tr>
				<tr>
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:150px;" onchange="calculateBillExcise(this.value)"  >
				<option value="0">--Select--</option>
				<?php
				$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				$ServiceRes=DB_query($ServiceSql,$db);
				while($ServiceRow=DB_fetch_array($ServiceRes))
				{
				?>
				<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()"/>
				</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 $ECessValue?>" style="width:120px;" 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 $SAHCessValue?>" style="width:120px;" readonly onfocus="calculateSAHCess1()"/></td>
				</tr>
					<tr>
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_excise_amount" id="total_item_amount1" style="width:150px;" onfocus="showexiseamt()" /></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="vat_cst" 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 ($venddata['vat_cst_per']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
              </tr>
              <?php  $taxdata=$s->getField('sales_tax_master','salestax_id',$venddata['vat_cst_per'],'taxrate'); ?>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="" readonly="true" <?php if($venddata['vat_cst_per']!='') {?> onfocus="tax_rate1(<?php echo $venddata['vat_cst_per']; ?>)" <?php } ?>/>
              </div>

	</td>
                </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per" value=""  size="10" onfocus="calsuroctamt(this.value)"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:60%;" onfocus="calsuroctamt1()" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value=""     /></td>
                </tr>
				<tr>
                  <td><strong>Loading /Unloading</strong> </td>
                  <td><input type="text" name="loading" id="loading1" style="width:100%;" value=""     /></td>
                </tr>
                <tr>
                  <td><strong>Additional Duties </strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
				
                <tr>
				<td><strong>Grand Total <font color="#FF0000">*</font></strong></td>
                  <td><input type="text" name="grandtotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12"/><input type="hidden"  id="orig_grand_tot" />&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+">+</option>
				  <option value="-">-</option>
				  </select></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>
</form>



<script type="text/javascript">
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)
{
	alert(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_rate1(str)
{
if(document.getElementById("EDRate").value=='0')
{
var taxableAmount=document.getElementById("afterdiscountprice").value;
}
else
{
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;}
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_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("Specialperc_"+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 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 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 opendatas(str,id)
{
  var sitecode=document.getElementById("sitecode").value;
  var storecode=document.getElementById("storecode").value;

 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	if(sitecode=='0')
	{
	alert("Must Select Site");
	document.getElementById("sitecode").focus();
	return;
	}
	
	if(storecode=='000')
	{
	alert("Must Select Warehouse");
	document.getElementById("storecode").focus();
	return;
	}

var xmlhttp;
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)
    {
	//alert(xmlhttp.responseText);
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
    }
  }
  
  xmlhttp.open("GET","log_showpopup.php?site="+str+"&data="+id+"&site1="+storecode,true);
	xmlhttp.send();	
}

function getItemsList1(id,code,shade,netrate,ctr)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	}
	else
	{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow('dataTable')
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}

function calamt1(id,str)
{
	var id1=id.split("_");
	var i=id1[1];
	if(id1[1]==undefined)
	{
		if(document.getElementById("poqty").value==''){
			alert("Please fill qty field");
			document.getElementById("poqty").focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty").value);
		document.getElementById("itemtotalrate").value=total.toFixed(2);
	}
	else
	{
	if(document.getElementById("poqty_"+i).value==''){
			alert("Please fill qty field");
			document.getElementById("poqty_"+i).focus();
		}
	
		var total=parseFloat(str)*parseFloat(document.getElementById("poqty_"+i).value);
		document.getElementById("itemtotalrate_"+i).value=total.toFixed(2);
	}
}

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

}

function cal_totalamount()
{
if(document.getElementById("itemtotalrate").value!='')
var firstrow=parseFloat(document.getElementById("itemtotalrate").value);
else
var firstrow=0;


	var count=document.getElementById("hiditemcount").value;
	if(count!='')
	{
		var totalprice=0;
		var totalprice1=0;
		for(var i=1;i<=count;i++)
		{
		 if(document.getElementById("itemtotalrate_"+i))
		   {
			  if(document.getElementById("itemtotalrate_"+i).value!='')
			  {
				totalprice=parseFloat(totalprice)+parseFloat(document.getElementById("itemtotalrate_"+i).value);
				}
				
			
				
		   }	
		}
		var amt=parseFloat(totalprice)+parseFloat(firstrow);
		document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	else
	{
	var amt=parseFloat(firstrow);
	document.getElementById("total_item_amount").value=amt.toFixed(2);
	}
	

	
}
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 calcPackaging1()
{
var str=document.getElementById("pkg_perc").value;
	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 calculateBillExcise(str)
{
	var value=document.getElementById("total_item_amount").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 calsuroctamt(str)
{
	var amt=document.getElementById("taxvalue").value;
	var	suroctper=document.getElementById("sur_oct_per").value;
	if(amt==''){amt=0;}
	if(suroctper==''){suroctper=0;}
	var amount=(amt*suroctper)/100;
	document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}

function calsuroctamt1()
{  
	var amt=document.getElementById("taxvalue").value;
	var	suroctper=document.getElementById("sur_oct_per").value;
	if(amt==''){amt=0;}
	if(suroctper==''){suroctper='0';}
	var amount=(amt*suroctper)/100;
	document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}
function cal_grandamount()
{
	var total=document.getElementById("total_item_amount").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var totamt=document.getElementById("total_item_amount1").value;
	var taxamt=document.getElementById("taxvalue").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var loading1=document.getElementById("loading1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	

	if(total==''){total=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(totamt==''){totamt=0;}
	if(taxamt==''){taxamt=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(loading1=='') {loading1=0;}
	if(additionalCharges==''){additionalCharges=0;}
	
	//var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(packagingCharges)+parseFloat(totamt)+parseFloat(taxamt)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(additionalCharges)+parseFloat(loading1);
	/*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 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;
}

</script>