<?php    
   $title = _('Purchase Order');
   // echo '<pre>';
   // print_r($_SESSION);
   // echo '</pre>';
   if($_REQUEST['save'])
   {
   	// echo '<pre>';
   	// print_r($_REQUEST);
   	// exit;//
   
   	//echo $_REQUEST['site'];
   	 
   	$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
   	$prefix_row=DB_fetch_array($prefix_sql);
   	//$prefixf=explode("/",$prefix_row['prefix_code']);
   	//$prefix=$prefixf[1];
   	//$prefix1=$prefixf[0];
   	 $prefix1=$prefix_row['prefix_code'];
   	$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
   	   	$sql="Select purchase_ordNo from purchorders where site='".$_REQUEST['site']."' and INSTR(`purchase_ordNo`, '$financial') > 0 order by id desc limit 0,1";
   
   	$result=DB_query($sql,$db);
   	$myrow=DB_fetch_array($result);
   	//echo DB_num_rows($result);
   	//echo $myrow['purchase_ordNo'];
   	if(DB_num_rows($result)>0)
   	{
   	//$Reqno=$myrow['Reqno'];
   	//$req_part1=substr($Reqno,-4);
   	$ExplBill=explode("/",$myrow['purchase_ordNo']);
   	$maxval = $ExplBill[3];
   	//echo $req_part1;
   	$req_final=$maxval+1;
   	//echo "<br>".$req_final;
   	}
   	else
   	{
   	$req_final="1";
   	}
   	
   	$string=$_REQUEST['site']."/".$financial."/".$prefix1."/";
   	
   	//$string=$_REQUEST['site']."/".$financial."/".$_REQUEST['purch_ord_type']."/".$_REQUEST['purch_ord_category']."/".$prefix."/";
   	        $final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
   	  // exit;
   
   	
   	//***************************  Document Uploading ************************//
   
   	   $FinempCode1=rand(0,9999);
   	    if($_FILES['file_attach']['name']!='')
   	    {
           $name=$_FILES['file_attach']['name'];
   		$tmp_name=$_FILES['file_attach']['tmp_name'];
   		$name_brk=explode('.',$name);
   		$type=$name_brk[1];
   		$new_name=$FinempCode1.'.'.$type;
   		$path="uploaded_docs/".$new_name;
   		$file_copy=copy($tmp_name,$path);		
   		}		
   
   	//************************************************************************//
   
   	$data['purchase_ordNo']=$final_string;
   	//$data['po_date']=date('Y-m-d');
   	$data['po_date']=FormatDateForSQL($_REQUEST['po_date']);	
   	$data['vendorId']             =$_REQUEST['vendor_id'];
   	$data['contact_person']       =$_REQUEST['contact_person'];
   	$data['quotationId']          =$_REQUEST['quote_No'];
   	$data['qutation_date']        =FormatDateForSQL($_REQUEST['quote_date']);
   	$data['mobileNo']             =$_REQUEST['mobile_no'];
   	$data['purchase_ord_Type']    =$_REQUEST['purch_ord_type'];
   	$data['po_category']          =$_REQUEST['purch_ord_category'];
   	$data['site']                 =$_REQUEST['site'];
   	$data['biiling_Address']      =$_REQUEST['billing_Address'];
   	$data['biiling_Address1']     =$_REQUEST['billing_Address1'];
   	$data['biiling_Address2']     =$_REQUEST['billing_Address2'];
   	$data['biiling_Country']      =$_REQUEST['billing_country'];
   	$data['biiling_State']        =$_REQUEST['billing_state'];
   	$data['biiling_City']         =$_REQUEST['billing_city'];
   	$data['biiling_PostalCode']   =$_REQUEST['biiling_PostalCode'];
   	$data['sippiling_Address']    =$_REQUEST['sippiling_Address'];
   	$data['sippiling_Address1']   =$_REQUEST['sippiling_Address1'];
   	$data['sippiling_Address2']   =$_REQUEST['sippiling_Address2'];
   	$data['sippiling_Country']    =$_REQUEST['shipping_country'];
   	$data['sippiling_State']      =$_REQUEST['shipping_state'];
   	$data['sippiling_City']       =$_REQUEST['shipping_city'];
   	$data['sippiling_PostalCode'] =$_REQUEST['sippiling_PostalCode'];	
   	$data['delivery_date']        =FormatDateForSQL($_REQUEST['delivery_date']);
   	$data['valid_till']           =FormatDateForSQL($_REQUEST['valid_till']);	
   	$data['payment_terms']        =$_REQUEST['PaymentTerm'];
   	$data['payment_mod']          =$_REQUEST['payment_mod'];
   	$data['remarks']              =$_REQUEST['remarks'];
   	$data['total_amount']         =$_REQUEST['basic_amt'];	
   	$data['discount_amt']         =$_REQUEST['discount_amt'];	
   	$data['discounted_amt']       =$_REQUEST['discounted_amt'];
   	$data['pkg_per']              =$_REQUEST['pkg_per'];
   	$data['pkg_charges']          =$_REQUEST['pkg_charges'];  
   	$data['non_tax_insurance']    =$_REQUEST['insurance_non_taxable'];  
   	$data['total_amt']            =$_REQUEST['total_amt'];
   
   	$excise_id=explode('**',$_REQUEST['excise']);
   	$data['excise']               =$excise_id[0];
   	$data['excise_amt']           =$_REQUEST['excise_amt'];
   
   	$ecess=explode('**',$_REQUEST['ecess']);
   	$data['ecess']                =$ecess[0];
   	$data['ecess_amt']            =$_REQUEST['ecess_amt'];
   
   	$secess=explode('**',$_REQUEST['shecess']);
   	$data['shecess']              =$secess[0];
   	$data['shecess_amt']          =$_REQUEST['shecess_amt'];
   	$data['tot_tax_amt']          =$_REQUEST['tot_tax_amt'];
   
   	$vat_cst=explode('**',$_REQUEST['vat_cst']);
   	$data['vatcst']               =$vat_cst[0];
   	$data['vat_amt']              =$_REQUEST['vat_amt'];
   	$data['surcharge_per']        =$vat_cst[2];
   	$data['surcharge_amt']        =$_REQUEST['sur_amt'];
   	$data['entry_tax_amt']        =$_REQUEST['entry_tax_amt'];
   	$data['insurancecharges_amt'] =$_REQUEST['insr_amt'];	
   	$data['Freight']              =$_REQUEST['Freight'];
   	$data['other_amt']            =$_REQUEST['other_amt'];
   	$data['total_po_amt']         =$_REQUEST['total_po_amt'];
   	$data['roundVal']             =$_REQUEST['roundVal'];
       $data['pluMin']               =$_REQUEST['pluMin'];
   	$data['GrandTotal']           =$_REQUEST['GrandTotal'];
   	$data['ordertype']            ='D';
   	$data['uploaded_file']        =$new_name;
   	$data['doc_name']             =$_REQUEST['docname'];
   	$data['surcharge_amt']        =$_REQUEST['surcharge_amt'];
   	$data['pkg_charges']          =$_REQUEST['pkg_charges'];
   	$data['created_date']         =date('Y-m-d');
   		
   	
   	//echo "<pre>";
   	//print_r($data);
   //	exit;
   	$s->RecordInsert('purchorders',$data);			//INSERT INTO PARANT TABLE
   	$last_id=DB_Last_Insert_ID($db,'purchorders','id');// GET LAST INSERT ID	
   	
   	for($i=0;$i<=count($_REQUEST['mst_itemid']);$i++)
   	{ 
   		if($_REQUEST['mst_itemid'][$i]!='')
   		{			
            $unitid=$s->getField('item_master','id',$_REQUEST['mst_itemid'][$i],'mst_unitid');
   			$dataArr['parantId']=$last_id;
   			$dataArr['mst_itemid']=$_REQUEST['mst_itemid'][$i];
   			$dataArr['itemgrade']=$_REQUEST['itemgrade'][$i];
   			$dataArr['itemsize']=$_REQUEST['itemsize'][$i];
   			$dataArr['Quantity']=$_REQUEST['Quantity'][$i];
   			$dataArr['remarks']=$_REQUEST['item_remarks'][$i];			
   			$dataArr['Rate']=$_REQUEST['Rate'][$i];
   			$dataArr['currnecy']=$_REQUEST['currency'][$i];
   			$dataArr['totalPrice']=$_REQUEST['totalPrice'][$i];
   			$dataArr['DiscountType']=$_REQUEST['DiscountType'][$i];
   			$dataArr['unitwisedis']=$_REQUEST['unitdiscount'][$i];
   			$dataArr['Discount']=$_REQUEST['Discount'][$i];
   			$dataArr['discounted_amount']=$_REQUEST['discounted_amount'][$i];
   			$dataArr['NetRate']=$_REQUEST['NetRate'][$i];
   			$dataArr['basic_Amt']=$_REQUEST['basic_Amt'][$i];
   			$dataArr['Excise_type']=$_REQUEST['Excise_type'][$i];
   			$excise_id=explode("#",$_REQUEST['Excise_Duty'][$i]);
   			$dataArr['Excise_Duty']=$excise_id[0];
   			$dataArr['exciseValue']=$_REQUEST['exciseValue'][$i]; 
               $ecess_id=explode("#",$_REQUEST['Cess_ID'][$i]);
   			$dataArr['Cess_ID']=$ecess_id[0]; 
   			$dataArr['ECessValue']=$_REQUEST['ECessValue'][$i]; 
   			$shecess_id=explode("#",$_REQUEST['SHECess_ID'][$i]);
   			$dataArr['SHECess_ID']=$shecess_id[0]; 
   			$dataArr['SAHCessValue']=$_REQUEST['SAHCessValue'][$i];
   			$dataArr['taxable_amt']=$_REQUEST['taxable_amt'][$i];
   			$dataArr['freight']=$_REQUEST['freightItem'][$i];
   			$dataArr['vat_id']=$_REQUEST['inputVat'][$i];
   			$dataArr['vat_value']=$_REQUEST['taxvalue1'][$i];
   			$dataArr['pkg_amt']=$_REQUEST['pkg_Amt'][$i];
   			$dataArr['sur_per']=$_REQUEST['surchargeper'][$i];
   			$dataArr['sur_amt']=$_REQUEST['surchargeamt'][$i];
   			$dataArr['mst_unitid']=$unitid;
   			$dataArr['equivalent_qty']=$_REQUEST['equivalentqty'][$i];
   			$dataArr['free_qty']=$_REQUEST['freeqty'][$i];
   			$dataArr['mrp']=$_REQUEST['Mrp'][$i];
   			//$dataArr['brand']=$_REQUEST['brand'][$i];
   		
   			//$dataArr['cuntomDuty_Flag']=$_REQUEST['cuntomDuty_Flag'][$i];
   			//$dataArr['Custon_Duty']=$_REQUEST['Custon_Duty'][$i];
   			//$dataArr['CustomDutyAmt']=$_REQUEST['CustomDutyAmt'][$i];
   			$dataArr['TotalAmount']=$_REQUEST['TotalAmount'][$i];
   			//echo "<pre>";
   			//print_r($dataArr);
   			
   			$s->RecordInsert('purchorderdetails',$dataArr);//INSERT INTO CHIELD TABLE
   		}
   	}
   //exit;
   	for($k=0;$k<count($_REQUEST['Terms_Condition']);$k++)
   						{
   							if($_REQUEST['Terms_Condition'][$k]!='')
   							{
   								
   							$dataterm['parant_id']    =$last_id;
   							$dataterm['termsid']      =$_REQUEST['terms'][$k];
   							$dataterm['condid']       =$_REQUEST['Terms_Condition'][$k];
   							$dataterm['frm_id']       =$_REQUEST['frmid'];
   							$dataterm['company_id']   =$_SESSION['ACGCompanyId'];
   							//$dataterm['type']         ="quotation";
   							$s->RecordInsert('direct_po_terms_conditions',$dataterm);
   							}
   						}
   	$s->pageLocation("index.php?route=POModule/view_purchase_order_direct".$rurl);
   }
   //$sql_loc=DB_query("Select deladd1,deladd2,deladd3,city,state,pincode,state,country from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') Order By locationname LIMIT 0,1",$db);
   //$row_loc=DB_fetch_array($sql_loc);
   
   ?>
<!-- <script src="POModule/po_calculation.js" type="text/javascript" language="javascript"></script> -->
<script type="text/javascript" language="javascript">
   function calculateBillExcise1(value)
   {
     if(value!='0')
     {
       $.post('calculateExcise.php',{'getdef_rate':'yes','ecessid':value},function(data){
         if(data!='')
         {
           document.getElementById('ECessPercentage').value=data;
           calculateECess();
         }
         
       });
     }
     else
     {
        document.getElementById('ECessPercentage').value=0;
        calculateECess();
       
     }
   }
   
   function calculateBillExcise2(value)
   {
     if(value!='0')
     {
       $.post('calculateExcise.php',{'getdef_rate':'yes','ecessid':value},function(data){
         if(data!='')
         {
           document.getElementById('SAHCessPercentage').value=data;
           calculateSAHCess();
         }
         
       });
     }
      else
     {
        document.getElementById('SAHCessPercentage').value=0;
        calculateSAHCess();
       
     }
   }
   
   
   
   //$.noConflict();
   $(document).ready(function(){	
   
   		
   
   		$('input[name=profile_popup]').click(function(){
   			var vend=document.getElementById("vendor_id").value;
   			var vf=document.getElementById("vend_itm_flag").value;
   			if(vend=='000' && vf==1)
   			{
   				alert("Please select vendor");
   				return false;
   			}
   			
   		var tt=this.id;
   		var tt1=tt.split("_");
   		var tt2=tt1[1];
   		var site=document.getElementById("site").value;
   		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
   		$("#PickedItems").dialog({
   				title:'Item List',
   				modal: true,
   				resizable: false,
   				width:1000,
   				height:400,
   				closeText: 'fechar',
   				draggable: true,
   				show: 'fade',
   				hide: 'fade',
   				dialogClass: 'main-dialog-class',
   				buttons: {
   					Exit: function()
   					{
   						$(this).dialog("close");
   					}
   				}
   				
   			});
   		GetitemListForDirectPO(site,vend,vf);
   		//$('.ui-widget-content .ui-helper-clearfix').append('<div style="float:left;">Displaying latest 10 records </div>');
   		});
   	});
   
   
   function cal_po_charges1(obj,value)
   {
   	var basic=document.getElementById('basic_amt').value;
   	if(basic!='' && value!='')
   	{
   		if(parseFloat(value)>parseFloat(basic))
   		{
   			alert('Discount amount should be less then basic amount');
   			document.getElementById('discount_percent').value='0.00';
   			document.getElementById('discount_amt').value='0.00';
   
   		}
   	}
   	else
   	{
   		document.getElementById('discount_percent').value='0.00';
   		document.getElementById('discount_amt').value='0.00';
   	}
   	cal_po_charges(obj);
   }
   function cal_po_charges2(obj,value)
   {
   	if(value!='')
   	{
   
   		if(parseFloat(value)>100)
   		{
   			alert('Discount percent cannot be greater then 100%');
   			document.getElementById('discount_percent').value='0.00';
   			document.getElementById('discount_amt').value='0.00';
   		}
   	}
   	else
   	{
   		document.getElementById('discount_percent').value='0.00';
   		document.getElementById('discount_amt').value='0.00';
   	}
   	cal_po_charges(obj);
   }
   
   function GetitemListForDirectPO(str,vend,vend_flg)
   {
   	//$('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
   	//alert(vend_flg)
   	//alert(vend)
   	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("PickedItems").innerHTML=xmlhttp.responseText;
   	}
   	}
   	//alert("direct_po_items12.php?site="+str+"&vend="+vend+"&vend_flg="+vend_flg);
   	xmlhttp.open("GET","direct_po_items_new.php?site="+str+"&vend="+vend+"&vend_flg="+vend_flg,true);
   	xmlhttp.send();
   }
   function calculateECess()
   {
   	var exciseValue=document.getElementById("excise_amt").value;
   	var ECessPercentage=document.getElementById("ECessPercentage").value;
   	if(ECessPercentage!='0' || ECessPercentage!='')
   	{
   		var total=exciseValue*(ECessPercentage/100);
   		document.getElementById("ecess_amt").value=total.toFixed(2);
   		calculateSAHCess();	
   	}
   	
   }
   function calculateSAHCess()
   {
   	var exciseValue=document.getElementById("excise_amt").value;
   	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
   	if(SAHCessPercentage!='0' || SAHCessPercentage!='')
   	{
   		var total=exciseValue*(SAHCessPercentage/100);
   		document.getElementById("SAHCessValue").value=total.toFixed(2);
   		calculateTaxable();	
   	}
   	
   }
   function getSubCategory()
   {   
   //$('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>'); 
   	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)
   	{   
   	document.getElementById("srch_subcateory").innerHTML=xmlhttp.responseText;
          // getdata1();
   	}
   	}
       var category=document.getElementById("srch_cateory").value;
       if(category=="")
       	return;
   	xmlhttp.open("GET","ajax_subcategory.php?cat="+category,true);
   	xmlhttp.send();
   	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
   }
   
   function getdata1()
   { 
   	$('#ItemListDiv').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
   	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)
   	{
   	document.getElementById("ItemListDiv").innerHTML=xmlhttp.responseText;
   	}
   	}
   	 var site=document.getElementById("site").value;
            var code=document.getElementById("srch_code").value;
            var name=document.getElementById("srch_name").value; 
            var category=document.getElementById("srch_cateory").value;
            var subcat=document.getElementById("srch_subcateory").value;
            var vendor=document.getElementById("vendor_id").value;
           
   	xmlhttp.open("GET","ajax_item_list_srch_new.php?code="+code+"&site="+site+"&name="+name+"&cat="+category+"&subcat="+subcat+"&vendor="+vendor,true);
   	xmlhttp.send();
   	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
   }	
   
   function VendorAddressContactpeson(str)
   {   
   	if (window.XMLHttpRequest)
   	{// code for IE7+, Firefox, Chrome, Opera, Safari
   	xmlhttp=new XMLHttpRequest();
   	}
   	else
   	{// code for IE6, IE5
   	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   	}
   	xmlhttp.onreadystatechange=function()
   	{
   	if (xmlhttp.readyState==4 && xmlhttp.status==200)
   	{
   		       var data=xmlhttp.responseText.split("__");		
   		       document.getElementById("ordType").innerHTML=data[0];
                  document.getElementById("divordertype").innerHTML=data[1];
                  document.getElementById("basicamtdetails").innerHTML=data[2];
   			   document.getElementById("terms_condition").innerHTML=data[6];
   			   document.getElementById("CPerson").innerHTML=data[4];
                  document.getElementById("mobile_no").value=data[5];            
   	}
   	}
   	//alert("GetVenAddressContact.php?VID="+str+"&frmid="+<?php echo $_REQUEST['frmid'] ?>)
   	var site=document.getElementById("site").value;
   	xmlhttp.open("GET","GetVenAddressContact.php?VID="+str+"&site="+site+"&frmid="+<?php echo $_REQUEST['frmid'] ?>,true);
   	xmlhttp.send();
   }
   function isNumberKey(evt)
          {
             var charCode = (evt.which) ? evt.which : event.keyCode;
             if (charCode != 46 && charCode > 31 
               && (charCode < 48 || charCode > 57))
                return false;
   
             return true;
          } 
   
   function VendorAddressContactpeson1(str)
   {
   	if (window.XMLHttpRequest)
   	{// code for IE7+, Firefox, Chrome, Opera, Safari
   	xmlhttp=new XMLHttpRequest();
   	}
   	else
   	{// code for IE6, IE5
   	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   	}
   	xmlhttp.onreadystatechange=function()
   	{
   	if (xmlhttp.readyState==4 && xmlhttp.status==200)
   	{
   		//alert(xmlhttp.responseText);
   		var data=xmlhttp.responseText.split("__");
   		//document.getElementById("CPerson").innerHTML=data[0];
   		document.getElementById("billing_Address").value=data[1];
   		document.getElementById("billing_Address1").value=data[7];
   		document.getElementById("billing_Address2").value=data[8];
   		document.getElementById("billing_city").value=data[2];
   		document.getElementById("billing_state").value=data[3];
   		document.getElementById("billing_state1").value=data[4];
   		document.getElementById("billing_country").value=data[5];
   		document.getElementById("billing_country1").value=data[6];
   		document.getElementById("zipcode").value=data[9];
   		document.getElementById("vendor_id").innerHTML=data[10];
   	}
   	}
   	xmlhttp.open("GET","GetVenAddressContact1.php?VID="+str,true);
   	xmlhttp.send();
   }
   
   
   function GetMobileNo(id)
   {
   	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("mobile_no").value=xmlhttp.responseText;
   	}
   	}
   	xmlhttp.open("GET","GetContactNo.php?contactId="+id,true);
   	xmlhttp.send();
   }
   
   
</script>
<div id="PickedItems" style="display:none"></div>
<div id="div_id" style="display:none"></div>
<div id="div_idEcess" style="display:none"></div>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
   <div class="tab_div">
      <h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></h1>
      <form action="" method="post" enctype="multipart/form-data">
         <!--GENERAL DETAILS-->
         <h3>General Details</h3>
         <table width="100%" border="0" cellspacing="0" cellpadding="3">
            <tr class="row1">
               <td width="13%" align="right">Branch</td>
               <td width="20%" align="left">
                  <?php 
                     $ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') order by locationname";
                     $site_sql=DB_query($ss1,$db);?>
                  <select name="site" id="site" onchange="VendorAddressContactpeson1(this.value)">
                     <!-- onchange="generate_reqno(this.value)"-->
                     <option value="000">---Select---</option>
                     <?php while($site_row=DB_fetch_array($site_sql)){?>
                     <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                     <?php } ?>
                  </select>
               </td>
               <td width="13%" align="right">PO No.</td>
               <td width="20%" align="left"><input type="text" value="Auto Generated" disabled="disabled"/></td>
               <td width="13%" align="right">Date</td>
               <td align="left"><input type="text" name="po_date" readonly="" id="po_date" value="<?php  echo date('d/m/Y');?>" class="datepicker" /></td>
            </tr>
            <tr class="row1">
               <td align="right">Vendor</td>
               <td align="left">
                  <?php 
                     $SQLV="Select id,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'";
                     $VDetails1=DB_query($SQLV,$db);?>
                  <select name="vendor_id" id="vendor_id" onchange="VendorAddressContactpeson(this.value)" >
                     <option value="000">---Select---</option>
                     <?php //while($VDetails=DB_fetch_array($VDetails1)){?>
                     <!--<option value="<?php echo $VDetails['id'];?>"><?php  echo $VDetails['vendor_name'];?></option>-->
                     <?php // } ?>
                  </select>
               </td>
               <td align="right">Quote No.</td>
               <td align="left"><input type="text" name="quote_No" id="quote_No" /></td>
               <td align="right">Quote Date</td>
               <td align="left"><input type="text" name="quote_date" readonly="" id="quote_date" class="datepicker" value="<?php  echo date('d/m/Y');?>" /></td>
            </tr>
            <tr class="row1">
               <td align="right">PO Type <font style="color:red;">*</font></td>
               <td align="left" id="ordType">
                  <select name="purch_ord_type" id="purch_ord_type" onChange="GetOrderType(this.value)">
                     <option value="0">Select</option>
                  </select>
               </td>
               <td align="right">Category <font style="color:red;">*</font></td>
               <td align="left">
                  <select name="purch_ord_category" id="purch_ord_category">
                     <option value="0">Select</option>
                     <option value='AT'>Asset</option>
                     <option value='MT'>Material</option>
                     <option value='SV'>Service</option>
                  </select>
               </td>
               <td align="right">Delivery Date</td>
               <td align="left"><input type="text" readonly="" name="delivery_date" id="delivery_date"  class="datepicker" value="<?php  echo date('d/m/Y');?>"  onchange="checkvalidate()"   /></td>
            </tr>
            <tr class="row1">
               <td align="right">Payment Terms</td>
               <td align="left">
                  <select name="PaymentTerm" id="PaymentTerm">
                     <option value="000">---Select Payment Terms---</option>
                     <?php 
                        $sql="select * from paymentterms";
                        $result=DB_query($sql, $db);
                        while($myrow = DB_fetch_array($result))
                        { 
                        $p='';
                        if($_POST['PaymentTerm']==$myrow['termsindicator'])
                        $p="selected";
                        ?>
                     <option value="<?php echo $myrow['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow['terms'];?></option>
                     <?php } ?>
                  </select>
               </td>
               <td align="right">Payment Mode</td>
               <td align="left">
                  <select name="payment_mod" id="payment_mod">
                     <option value="000">---Select Payment Mode---</option>
                     <?php 
                        $sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
                        $result=DB_query($sql, $db);
                        while($myrow = DB_fetch_array($result))
                        	{ 
                        		$p='';
                        		if($_POST['PayMode'] == $myrow['paymentid'])
                        		$p="selected";
                        	?>
                     <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
                     <?php } ?>
                  </select>
               </td>
               <td align="right">Valid Upto</td>
               <td align="left"><input type="text" readonly=""  class="datepicker" name="valid_till" id="valid_till" value="<?php  echo date('d/m/Y');?>"  onchange="checktilldate()"    /></td>
            </tr>
            <?php $vend_itm_flag=DB_fetch_assoc(DB_query("select * from vendoritemmap_flag where company_id ='".$_SESSION['ACGCompanyId']."'",$db));?>
            <input type="hidden" id="vend_itm_flag" value="<?php echo $vend_itm_flag['map_flag'] ?>">
            <tr class="row1">
               <td align="right">Contact Person</td>
               <td align="left" id="CPerson">
                  <select name="contact_person" id="contact_person">
                     <option value="">Select</option>
                  </select>
               </td>
               <td align="right">Mobile No.</td>
               <td align="left"><input type="text" name="mobile_no"  onkeypress="return isNumberKey(event)" maxlength="10" id="mobile_no" ></td>
               <td align="left">&nbsp;</td>
               <td align="left">&nbsp;</td>
            </tr>
         </table>
         <br>
         <h3>Address Details (Check If both Address are Same <input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()">)</h3>
         <table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
            <tr>
               <th colspan="3" style="text-align:center;">Billing Address</th>
               <th width="14%" style="text-align:center;">City</th>
               <th width="14%" style="text-align:center;">State</th>
               <th width="14%" style="text-align:center;">Country</th>
               <th width="10%" style="text-align:center;">Postal Code</th>
            </tr>
            <tr>
               <td><input type="text" name="billing_Address" id="billing_Address" value="<?php echo $row_loc['deladd1']?>"/></td>
               <td><input type="text" name="billing_Address1" id="billing_Address1" value="<?php echo $row_loc['deladd2']?>" /></td>
               <td><input type="text" name="billing_Address2" id="billing_Address2" value="<?php echo $row_loc['deladd3']?>" /></td>
               <td>
                  <select name="billing_city" id="billing_city" onchange="GetSatateCountry(this.value)">
                     <option value="">Select</option>
                     <?php 
                        $city_sql=DB_query("select * from city_master",$db);
                        while($city_row=DB_fetch_array($city_sql)) { ?>
                     <option value="<?php echo $city_row['id'];?>"<?php echo($row_loc['city']==$city_row['id']?'selected':''); ?>><?php echo $city_row['city'];?></option>
                     <?php } ?>
                  </select>
               </td>
               <td><input type="hidden" name="billing_state" id="billing_state" value="<?php echo $row_loc['state']; ?>" />
                  <?php $STname=$s->GetFieldValue('state_master',"id='".$row_loc['state']."'",'state'); ?>
                  <input type="text" name="billing_state1" id="billing_state1" value="<?php echo $STname; ?>" />
               </td>
               <td><input type="hidden" name="billing_country" id="billing_country" value="<?php echo $row_loc['country']; ?>" />
                  <?php $Conname=$s->GetFieldValue('country_master',"id='". $row_loc['country']."'",'country'); ?>
                  <input type="text" name="billing_country1" id="billing_country1" value="<?php echo $Conname; ?>" />
               </td>
               <td><input type="text" name="biiling_PostalCode" id="zipcode" onkeypress="return isNumberKey(event)" maxlength="6" value="<?php echo $row_loc['pincode']?>"/></td>
            </tr>
            <tr>
               <th colspan="3" style="text-align:center;">Delivery Address </th>
               <th width="14%" style="text-align:center;">City</th>
               <th width="14%" style="text-align:center;">State</th>
               <th width="14%" style="text-align:center;">Country</th>
               <th width="10%" style="text-align:center;">Postal Code</th>
            </tr>
            <tr>
               <td id="CODE"><input type="text" id="Shipping_address" name="sippiling_Address" /></td>
               <td id="CODE"><input type="text" id="Shipping_address1" name="sippiling_Address1" /></td>
               <td id="CODE"><input type="text" id="Shipping_address2" name="sippiling_Address2" /></td>
               <td>
                  <select name="shipping_city" id="shipping_city" onchange="GetSatateCountry1(this.value)">
                     <option value="">Select</option>
                     <?php 
                        $city_sql=DB_query("select * from city_master",$db);
                        while($city_row=DB_fetch_array($city_sql)) { ?>
                     <option value="<?php echo $city_row['id'];?>"<?php echo($city==$city_row['id']?'selected':''); ?>><?php echo $city_row['city'];?></option>
                     <?php } ?>
                  </select>
               </td>
               <td><input type="hidden" name="shipping_state" id="shipping_state" value="<?php echo $state; ?>" />
                  <?php $STname=$s->GetFieldValue('state_master',"id='".$state."'",'state'); ?>
                  <input type="text" name="shipping_state1" id="shipping_state1" value="<?php echo $STname; ?>" />	
               </td>
               <td><input type="hidden" name="shipping_country" id="shipping_country" value="<?php echo $country; ?>" />
                  <?php $Conname=$s->GetFieldValue('country_master',"id='".$country."'",'country'); ?>
                  <input type="text" name="shipping_country1" id="shipping_country1" value="<?php echo $Conname; ?>" />
               </td>
               <td><input type="text" name="sippiling_PostalCode" maxlength="6" onkeypress="return isNumberKey(event)" id="Shipping_zipcode" /></td>
            </tr>
         </table>
         <br>
         <!--OTHER DETAILS-->
         <h3>Items Details</h3>
         <p align="left">	
            <input type="button" name="profile_popup" value="Pick Items" id="profile_popup" class="search" />
            <input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />
         </p>
         <div id="divordertype" style="overflow:auto; float:left; width:100%;"></div>
         <input type="hidden" name="" id="hiditemcount"  value="1" />
         <input type="hidden" name="" id="edit_count" value="1" />
         <input type="hidden" name="" id="rowcount1" value="1"  />
         <table border="0" width="100%" cellpadding="3" cellspacing="0">
            <tr>
               <td valign="top">
                  <div id="terms_condition"></div>
               </td>
               <td width="36%" valign="top">
                  <div id="basicamtdetails"></div>
               </td>
            </tr>
         </table>
         <br>
         <table border="0" width="100%" cellpadding="3" cellspacing="0">
            <tr class="row1">
               <td width="13%" align="right">Doc Name:</td>
               <td><input type="text" name="docname" style="width:40%; float:left; margin-right:3px;" /> <input type="file" name="file_attach" value="Attach File"  id="filename" onchange="Checkfiles()" style="width:40%; float:left;" /></td>
            </tr>
         </table>
         <p class="text-center"><input name="save" type="submit" value="Save" class="search"  onclick="return validate();"/></p>
      </form>
   </div>
</div>
<script language="JavaScript">
   function checkvalidate()
   {
   	
   var curr_date2='';	
   var curr_month2='';
   var d = new Date();
   //alert(d.format("m/dd/yy"));
   var curr_date = d.getDate();
   var curr_month1 = d.getMonth();
   var curr_year = d.getFullYear();
   var curr_month=curr_month1+1;
   var t=curr_month;
   var d=curr_date;
   if(t!=10 || t!=11 ||t!=12 )
   {
    curr_month2="0" + curr_month;	
   }
   else
   {
    curr_month2=curr_month;	
   }
   if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
   {
    curr_date2="0" + curr_date;		
   }
   else
   {
    curr_date2=curr_date;		
   }
   
   
   var datedat=(curr_date2 + "/" + curr_month2 
   + "/" + curr_year);
   var del=document.getElementById("delivery_date").value;	
   if(del<datedat)
   {
   alert("Delivery  Date Not less then current  Date");
   //document.getElementById("delivery_date").value='';
   document.getElementById("delivery_date").focus();
   document.getElementById("delivery_date").value='';
   return false;	
   }
   
   
   }
   function checktilldate()
   {
   var curr_date2='';	
   var curr_month2='';
   var d = new Date();
   //alert(d.format("m/dd/yy"));
   var curr_date = d.getDate();
   var curr_month1 = d.getMonth();
   var curr_year = d.getFullYear();
   var curr_month=curr_month1+1;
   var t=curr_month;
   var d=curr_date;
   if(t!=10 || t!=11 ||t!=12 )
   {
    curr_month2="0" + curr_month;	
   }
   else
   {
    curr_month2=curr_month;	
   }
   if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
   {
    curr_date2="0" + curr_date;		
   }
   else
   {
    curr_date2=curr_date;		
   }	
   var datedat=(curr_date2 + "/" + curr_month2 
   + "/" + curr_year);
   var del1=document.getElementById("valid_till").value;	
   if(del1<datedat)
   {
   alert("Valid Till Date Not less then current  Date");
   //document.getElementById("valid_till").value='';
   document.getElementById("valid_till").focus();
   document.getElementById("valid_till").value='';
   return false;	
   }		
   }		
   	
   function validate()
   {
   if(document.getElementById("purch_ord_type").value=='0')
   {
   alert("Plz Select Purchase Order Type");
   document.getElementById("purch_ord_type").focus();
   return false;
   }
   if(document.getElementById("purch_ord_category").value=='0')
   {
   alert("Plz Select Purchase Order Category");
   document.getElementById("purch_ord_category").focus();
   
   return false;
   }
   
   if(document.getElementById("total_item_amount").value=='')
   {
   alert("Plz enter Total Item Amount First");
   document.getElementById("total_item_amount").focus();
   return false;
   }
   if(document.getElementById("VatcstVal").value=='')
   {
   alert("Plz enter Vat Cst Amount First");
   document.getElementById("VatcstVal").focus();
   return false;
   }
   
   
   if(document.getElementById("GrandTotal").value=='')
   {
   alert("Plz enter Grand Total Amount First");
   document.getElementById("GrandTotal").focus();
   return false;
   }
   
   
   return true;
   
   }	
   	
   
   function ship_data()
   {
   
   	if(document.getElementById("shipping_data").checked==true)
   	{
   		document.getElementById('Shipping_address').value = document.getElementById('billing_Address').value;
   		document.getElementById('Shipping_address1').value = document.getElementById('billing_Address1').value;
   		document.getElementById('Shipping_address2').value = document.getElementById('billing_Address2').value;
   		document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
   		document.getElementById('shipping_state').value = document.getElementById('billing_state').value;
   		document.getElementById('shipping_country').value = document.getElementById('billing_country').value;
   		document.getElementById('shipping_state1').value = document.getElementById('billing_state1').value;
   		document.getElementById('shipping_country1').value = document.getElementById('billing_country1').value;
   		document.getElementById('Shipping_zipcode').value = document.getElementById('zipcode').value;
   		
   	}else{
   		document.getElementById('Shipping_address').value = '';
   		document.getElementById('Shipping_address1').value = '';
   		document.getElementById('Shipping_address2').value = '';
   		document.getElementById('shipping_state').value = '';
   		document.getElementById('shipping_city').value = '';
   		document.getElementById('shipping_country').value = '';
   		document.getElementById('shipping_state1').value = '';
   		document.getElementById('shipping_country1').value = '';
   		document.getElementById('Shipping_zipcode').value='';
   	}
   }
   
   function GetSatateCountry(str)
   {
   	if (window.XMLHttpRequest)
     	{// code for IE7+, Firefox, Chrome, Opera, Safari
     		xmlhttp=new XMLHttpRequest();
    	}
   	else
     	{// code for IE6, IE5
     		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     	}
   	xmlhttp.onreadystatechange=function()
     	{
     	if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
   		var data=xmlhttp.responseText.split("__");
       	document.getElementById("billing_state").value=data[0];
   		document.getElementById("billing_country").value=data[1];
   		document.getElementById("billing_state1").value=data[2];
   		document.getElementById("billing_country1").value=data[3];
       }
     	}
   	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
   	xmlhttp.send();
   }
   
   
   function GetSatateCountry1(str)
   {
   	if (window.XMLHttpRequest)
     	{// code for IE7+, Firefox, Chrome, Opera, Safari
     		xmlhttp=new XMLHttpRequest();
    	}
   	else
     	{// code for IE6, IE5
     		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     	}
   	xmlhttp.onreadystatechange=function()
     	{
     	if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
   		var data=xmlhttp.responseText.split("__");
       	document.getElementById("shipping_state").value=data[0];
   		document.getElementById("shipping_country").value=data[1];
   		document.getElementById("shipping_state1").value=data[2];
   		document.getElementById("shipping_country1").value=data[3];
       }
     	}
   	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
   	xmlhttp.send();
   }
   
   function addRow(tableID) 
   {
   
   	if(document)
   	var table = document.getElementById(tableID);
   	var rowCount = table.rows.length;
   	var rowCount = table.rows.length;
   	if(document.getElementById("hiditemcount").value=='')
   		r =rowCount+1;
   	else
   	{
   		var t=document.getElementById("edit_count").value;
   		var t1=document.getElementById("hiditemcount").value;
   		r=parseInt(t1);
   		r1=parseInt(t1)+1;
   	}
   	var row1=document.getElementById("rowcount1").value;
   	var rr=parseInt(row1)+1;
   	document.getElementById("rowcount1").value=rr;
   	var row = table.insertRow(rowCount);
   	document.getElementById("hiditemcount").value=rr;
   	document.getElementById("edit_count").value=rr;
   	var colCount = table.rows[0].cells.length;
   	for(var i=0; i<colCount; i++) 
   	{		
   		var newcell = row.insertCell(i);
   		//newcell.style.background='#e7e7e7';
   		newcell.className='tabledata';
   		newcell.innerHTML = table.rows[0].cells[i].innerHTML;
   		//alert(newcell.childNodes[0].type);
   		switch(newcell.childNodes[0].type) 
   		{
   			case "text":
   			newcell.childNodes[0].value = "";
   			var nod_id = newcell.childNodes[0].id.split("_");
   			if(!isNaN(nod_id[1]))
   				newcell.childNodes[0].id = nod_id[0]+'_'+rr;
   			else
   				newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
   			break;		
   				case "hidden":
   					newcell.childNodes[0].value = "";
   					var nod_id = newcell.childNodes[0].id.split("_");
   					if(!isNaN(nod_id[1]))
   						newcell.childNodes[0].id = nod_id[0]+'_'+rr;
   					else
   						newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
   					break;
   				case "button":
   					var nod_id = newcell.childNodes[0].id.split("_");
   					if(!isNaN(nod_id[1]))
   						newcell.childNodes[0].id = nod_id[0]+'_'+rr;
   					else
   						newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
   					break;
   				
   				case "checkbox":
   						newcell.childNodes[0].checked = false;
   						var nod_id = newcell.childNodes[0].id.split("_");
   						if(!isNaN(nod_id[1]))
   						newcell.childNodes[0].id = nod_id[0]+'_'+rr;
   						else
   						newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
   						break;
   				
   				case "select-one":
   						newcell.childNodes[0].selectedIndex = 0;
   						var nod_id = newcell.childNodes[0].id.split("_");
   						if(!isNaN(nod_id[1]))
   							newcell.childNodes[0].id = nod_id[0]+'_'+rr;
   						else
   							newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
   						break;	
   				}
   		
   			}
   	}
   
   	
   function deleteRow(tableID) 
   {
   		try 
   		{
   			var table = document.getElementById(tableID);
   			//alert(table);
   			var rowCount = table.rows.length;
   			//alert(rowCount);
   			for(var i=0; i<rowCount; i++) 
   				{
   					var row = table.rows[i];
   					var chkbox = row.cells[0].childNodes[0];
   					if(null != chkbox && true == chkbox.checked) 
   					{
   						if(rowCount <= 1) 
   						{
   							alert("Cannot delete all the rows.");
   							break;
   						}
   					table.deleteRow(i);
   					rowCount--;
   					i--;
   					}
   					
   				}
   				
   		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;
   		//document.getElementById("hiditemcount").value=parseInt(rowCount);		
   		}
   		catch(e) 
   		{
   			alert(e);
   		}
   
   }
   
   
   function getItemsList(id,code,shade,current,s_unit,ctr,unit,vatid,surrate,vatName,equivalent_qty, brand)
       { 
   
   
             
   	var dup='empty';
   	var itemcount=parseInt(document.getElementById('rowcount1').value)+1;
   	var counter=1;
   	
   	//alert(counter);
   //IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
   	
   	if(document.getElementById("row_id_"+ctr).checked==true)
   	{
   		
   			for(var i=counter; i<=itemcount; i++)
   			{	
   				if(!document.getElementById('itemid_'+i))
   				{
   					 addRow('dataTable');
   				}
   												
   					if(document.getElementById('itemid_'+i))
   					{
   						if(document.getElementById('itemid_'+i).value=='')
   						{	//var data= addRow('dataTable');
   							document.getElementById('itemid_'+i).value = id;
   							document.getElementById('itemcode_'+i).value = code;
   							document.getElementById('brand_'+i).value = brand;
   							document.getElementById('itemname_'+i).value = shade;
   							document.getElementById('itemunit_'+i).value = s_unit;
   							$('#inputVat_'+i).empty();
   							// $('#inputVat_'+i).append($('<option>', {
   							//     value: '',
   							//     text: 'Select GST'
   							// }));
   							if(vatid!='' || vatid!='0'){
   								$('#inputVat_'+i).append($('<option>', {
   								    value: vatid,
   								    //text: unit
   								    text: vatName
   								}));
   							}
   							document.getElementById('equivalentqty_'+i).value = equivalent_qty;
   							//document.getElementById('vatdes_'+i).value = unit;
   						    //document.getElementById('inputVat_'+i).value = vatid;
                               //document.getElementById('surchargeper_'+i).value = surrate;
   							//document.getElementById('total_stock_'+i).value = current;			
   						
   							break;
   					 	}
   						else
   						{
   							continue;
   						}
   					}
   				
   			}
   		}	
   
   	else
   	{
   		
   		
   			for(var i=counter; i<itemcount; i++)
   			{
   				if(document.getElementById('itemid_'+i))
   				{
   					if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
   					{
   						document.getElementById('itemid_'+i).value = '';
   						document.getElementById('itemcode_'+i).value = '';
   						document.getElementById('brand_'+i).value = '';
   						document.getElementById('itemname_'+i).value = '';
   						document.getElementById('itemunit_'+i).value = '';
   						document.getElementById('total_stock_'+i).value='';
   						//document.getElementById('vatdes_'+i).value = '';
   						//document.getElementById('inputVat_'+i).value = '';
   						//document.getElementById('surchargeper_'+i).value = '';
   					}
   		   		}
   	  		}
   		
   	}
   //IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
   }
   
   	function Checkfiles()
           {
           var fup = document.getElementById('filename');
           var fileName = fup.value;
           var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
           if(ext == "pdf" || ext=="txt" || ext=="docx")
           {
           return true;
           } 
           else
           {
           alert("Upload pdf/text/word  files only");
           fup.value='';
           fup.focus();
           return false;
           }
           }
   				
   /*    function cal_grandtotal()
       {
        
        var basic_amt=document.getElementById("total_item_amount").value;
        var excise_amt=document.getElementById("excise_duty_val").value;
        var ecess_amt=document.getElementById("ecess_val").value;
        var shecess_amt=document.getElementById("shecess_val").value;
        var TotalCharge=document.getElementById("TotalCharge").value;
        var taxvalue=document.getElementById("taxvalue").value;
   
        var insurance=document.getElementById("insurance").value;
        var miscellaneous=document.getElementById("miscellaneous").value;
        var pkgamt=document.getElementById("pkg_charges").value;
        var surcharge_amt=document.getElementById("surcharge_amt").value;
         if(basic_amt=='') basic_amt=0;
         if(insurance=='') insurance=0;
         if(miscellaneous=='') miscellaneous=0;
          if(excise_amt=='') excise_amt=0;
           if(ecess_amt=='') ecess_amt=0;
             if(shecess_amt=='') shecess_amt=0;
               if(TotalCharge=='') TotalCharge=0;
                  if(taxvalue=='') taxvalue=0;
                   if(pkgamt=='') pkgamt=0;
                  if(surcharge_amt=='') surcharge_amt=0;
               
   
         var total=(parseFloat(basic_amt)+parseFloat(insurance)+parseFloat(miscellaneous)+parseFloat(excise_amt)+parseFloat(ecess_amt)+parseFloat(shecess_amt)+parseFloat(TotalCharge)+parseFloat(taxvalue)+parseFloat(pkgamt)+parseFloat(surcharge_amt)).toFixed(2);
         
       
         document.getElementById("GrandTotal").value=total;
        
   
       }*/
   
   /* new functions  */
   
   function checkExcisable(str,ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   	if(str=='NonExcisable')
   	{	
   		document.getElementById("exciseDuty_"+i).value='';
   		document.getElementById("exciseValue_"+i).value='';
   		document.getElementById("cessID1_"+i).value='';
   		document.getElementById("ECessValue_"+i).value='';
   		document.getElementById("cessID2_"+i).value='';
   		document.getElementById("SAHCessValue_"+i).value='';
   		document.getElementById("taxableAmt_"+i).value='';			
   		document.getElementById("inputVat_"+i).value='';
   
   		document.getElementById("taxvalue_"+i).value='';
   		document.getElementById("surchargeperDisp_"+i).value='';		
   		document.getElementById("surchargeamt_"+i).value='';
   
   	}
   	else if(str=='Excisable')
   	{
   		document.getElementById("taxvalue_"+i).value='';
   		document.getElementById("surchargeperDisp_"+i).value='';		
   		document.getElementById("surchargeamt_"+i).value='';
   		document.getElementById("inputVat_"+i).value='';
   		
   	}
   	else
   	{	
   		document.getElementById("exciseDuty_"+i).value='';
   		document.getElementById("exciseValue_"+i).value='';
   		document.getElementById("cessID1_"+i).value='';
   		document.getElementById("ECessValue_"+i).value='';
   		document.getElementById("cessID2_"+i).value='';
   		document.getElementById("SAHCessValue_"+i).value='';
   		document.getElementById("taxableAmt_"+i).value='';			
   		document.getElementById("inputVat_"+i).value='';
   
   		document.getElementById("taxvalue_"+i).value='';
   		document.getElementById("surchargeperDisp_"+i).value='';		
   		document.getElementById("surchargeamt_"+i).value='';
   
   	}
   	document.getElementById("hidBillingType_"+i).value=str;
   	cal_totalamount();
   }
   
   function cal_totalamount()
   {
   	
   	var sumOfArea=0;
   	var sumOfArea1=0;
   	var sumOfArea2=0;
       var sumOfArea3=0;
       var sumOfArea4=0;
       var sumOfArea5=0;
       var sumOfAreapkg=0;
       var sumOfAreasurcharge=0;
   
       $('#tableDataProduction').find('input[type="text"][class="basic"]').each(function(){
       if($(this).val()!='')
       {
       sumOfArea= sumOfArea + parseFloat($(this).val());   
       }
       else
       {
       sumOfArea= sumOfArea;	
       }
       });
   	sumOfAreapkg= sumOfAreapkg;
   
       // $('#tableDataProduction').find('input[type="text"][class="pkgamt"]').each(function(){
       // if($(this).val()!='')
       // {
       // sumOfAreapkg= sumOfAreapkg + parseFloat($(this).val());   
       // }
       // else
       // {
       // sumOfAreapkg= sumOfAreapkg;	
       // }
       // });
   
       // $('#tableDataProduction').find('input[type="text"][class="excise"]').each(function(){
       // if($(this).val()!='')
       // {
       // sumOfArea1= sumOfArea1 + parseFloat($(this).val());   
       // }
       // else
       // {
       // sumOfArea1= sumOfArea1;	
       // }
       // });
   	sumOfArea1= sumOfArea1;
   
       //  $('#tableDataProduction').find('input[type="text"][class="ecess"]').each(function(){
       // if($(this).val()!='')
       // {
       // sumOfArea2= sumOfArea2 + parseFloat($(this).val());   
       // }
       // else
       // {
       // sumOfArea2= sumOfArea2;	
       // }
       // });
   	sumOfArea2= sumOfArea2;
   
       //  $('#tableDataProduction').find('input[type="text"][class="shecess"]').each(function(){
       // if($(this).val()!='')
       // {
       // sumOfArea3= sumOfArea3 + parseFloat($(this).val());   
       // }
       // else
       // {
       // sumOfArea3= sumOfArea3;	
       // }
       // }); 
   	sumOfArea3= sumOfArea3;
   
        $('#tableDataProduction').find('input[type="text"][class="freight"]').each(function(){
       if($(this).val()!='')
       {
       sumOfArea4= sumOfArea4 + parseFloat($(this).val());   
       }
       else
       {
       sumOfArea4= sumOfArea4;	
       }
       }); 
   
        $('#tableDataProduction').find('input[type="text"][class="vat"]').each(function(){
       if($(this).val()!='')
       {
       sumOfArea5= sumOfArea5 + parseFloat($(this).val());   
       }
       else
       {
       sumOfArea5= sumOfArea5;	
       }
       }); 
   	
   
       // $('#tableDataProduction').find('input[type="text"][class="surcharge"]').each(function(){
       // if($(this).val()!='')
       // {
       // sumOfAreasurcharge= sumOfAreasurcharge + parseFloat($(this).val());   
       // }
       // else
       // {
       // sumOfAreasurcharge= sumOfAreasurcharge;	
       // }
       // });
   	sumOfAreasurcharge= sumOfAreasurcharge;	 
   
   	$tot_basic=sumOfArea.toFixed(2);
   	//document.getElementById("excise_duty_val").value=sumOfArea1.toFixed(2);
   	//document.getElementById("ecess_val").value=sumOfArea2.toFixed(2);
   	//document.getElementById("shecess_val").value=sumOfArea3.toFixed(2);
   	document.getElementById("taxvalue").value=sumOfArea5.toFixed(2);
   	document.getElementById("TotalCharge").value=sumOfArea4.toFixed(2);
   	//document.getElementById("pkg_charges1").value=sumOfAreapkg.toFixed(2);
       //document.getElementById("sur_oct_amt").value=sumOfAreasurcharge.toFixed(2);
       document.getElementById("total_item_amount").value=$tot_basic; 
   
   
   	cal_total_grand();
   }
   function cal_total_grand()
   {
   	var totalbasic=document.getElementById("total_item_amount").value;
   	//var exciseamt=document.getElementById("excise_duty_val").value;
   	//var ecessamt=document.getElementById("ecess_val").value;
   	//var shessamt=document.getElementById("shecess_val").value;
   	var freight=document.getElementById("TotalCharge").value;
   	var vatamt=document.getElementById("taxvalue").value;
   	var insurance=document.getElementById("insurance").value;
   	var miss=document.getElementById("miscellaneous").value;	
   	//var pkg=document.getElementById("pkg_charges1").value;	
   	//var sur=document.getElementById("sur_oct_amt").value;	
   
       if(totalbasic=='') { totalbasic=0;}
       //if(exciseamt=='') { exciseamt=0;}
       //if(ecessamt=='') { ecessamt=0;}
       //if(shessamt=='') { shessamt=0;}
   	exciseamt=0;
   	ecessamt=0;
   	shessamt=0;
       if(freight=='') { freight=0;}
       if(vatamt=='') { vatamt=0;}
       if(insurance=='') { insurance=0;}
         //if(pkg=='') { pkg=0;}
           //if(sur=='') { sur=0;}
   	 pkg=0;
   	 sur=0;
       if(miss=='') { miss=0;}
      var total=(parseFloat(totalbasic)+parseFloat(exciseamt)+parseFloat(ecessamt)+parseFloat(shessamt)+parseFloat(freight)+parseFloat(vatamt)+parseFloat(insurance)+parseFloat(miss)+parseFloat(pkg)+parseFloat(sur)).toFixed(2);
       
   
         var grand_total=total.split(".");
   
   
          if(grand_total[1]<10)
   	{ var first_digit=parseFloat(grand_total[1])*10;}
       else{ var first_digit=grand_total[1];	}
      // echo $first_digit;
    //echo "fd=".$round1[1];exit;
   		  if(first_digit>=50)
   		  {
   		  	//echo $first_digit;
   		  var rov=100-parseFloat(first_digit);
   		  var tot=parseFloat(grand_total[0])+1;
   		  var sign="+";
             var roundval1=rov; 
             var roundval=parseFloat(rov)/100;
   		  var grand1=tot;
   		  	
   		  }
   		  else if(first_digit<50){
   		    var sign="-";
   		    var roundval1=grand_total[1]; 
              var roundval=parseFloat(first_digit)/100;
   		  var grand1=grand_total[0];
   		}
   
   
      document.getElementById("GrandTotal").value=grand1;
      document.getElementById("pluMin").value=sign;
      document.getElementById("roundVal").value=roundval;
   
     
   }
   
   function calcTotAmtInt(str,ids)
   { 
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   
       var totalamt=0;
       var quantity=document.getElementById("qty_"+i).value;
       if(quantity==''){quantity=0;}
       if(str=='') { str=0;}
       //alert(quantity);
       var finalAmt=parseFloat(str)*parseFloat(quantity);
       //alert(finalAmt);
       document.getElementById("price_"+i).value=finalAmt.toFixed(2); 
   
       DiscountAmountsInt(finalAmt,i); 
    }
   
   function DiscountAmountsInt(DA,ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   
   	//numeric(DA,id);
         
          // alert(i);
   		var totValue = document.getElementById("price_"+i).value;
   		var discType = document.getElementById("PerAmo_"+i).value;
   		var disct = document.getElementById("Discount_"+i).value;
   		if(disct=='')
   		{
   			disct = 0.00;
   			document.getElementById("Discount_"+i).value = 0;
   		}
   
   			
                   
                   if(parseFloat(disct)>parseFloat(totValue))
                       {
                           alert('Discount Cannot Be Greater Than Total Amount');
                           document.getElementById("Discount_"+i).value='';
                           document.getElementById("Discount_"+i).focus();
                           
                           document.getElementById("basic_"+i).value='';
                           return false;
                       }
                       
   		if(totValue==''){totValue=0;}
   		if(DA==""){DA=0;}
   		 var totalamt=0;
   		if(discType=='Amount')
   		{
   			var subTotal = parseFloat(totValue)-parseFloat(disct);
   			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
           }
   		else
   		{
   			if(disct>100)
   			{
   				       alert('Discount % Should be less then 100');
                           document.getElementById("Discount_"+i).value='';
                           document.getElementById("Discount_"+i).focus();
                           
                           document.getElementById("basic_"+i).value='';
                           return false;
   
   			}
   			else
   			{
   			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
   			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
   	     	}
                          		
   		}
   		
           
       //     if(document.getElementById("hidBillingType_"+i).value!='')
       //     {
       //       if(document.getElementById("hidBillingType_"+i).value=='Excisable' || document.getElementById("hidBillingType_"+i).value=='IncludeTax')
       //       {
       //       	var exciseid="inputVat_"+i;
       //       	var exciseval=document.getElementById(exciseid).value;
       //       	tax_rate2(exciseval,i);
       //       }
       //       if(document.getElementById("hidBillingType_"+i).value=='NonExcisable')
       //       {
       //         var exciseid="exciseDuty_"+i;
       //       	var exciseval=document.getElementById(exciseid).value;
       //       	claculateExcise(exciseid,exciseval);
       //       }  
       //   }
       //     else
       //     {
           	document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
           	var val=document.getElementById("inputVat_"+i).value;
           	tax_rate2(val,i);
          // }
   
          
   }
   function tax_rate2(str,ids)
   {
   	//alert(i);
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
           
   	// var bill_type=document.getElementById("hidBillingType_"+i).value;
   	var basic=document.getElementById("basic_"+i).value;
   	var freight=document.getElementById("freightItem_"+i).value;
   	
   	//var freight=0.00;
   	// var excise=document.getElementById("taxableAmt_"+i).value;
   	// var pkg=document.getElementById("pkgamt_"+i).value;
   	// var suroctper=document.getElementById("surchargeper_"+i).value;
   	// if(suroctper=='') 
   		suroctper=0;
   	// if(pkg=='') 
   		pkg=0;
   
   	if(basic==''){basic=0;}
   	// if(excise==''){
   		excise=0;
   	// }
   	if(freight==''){freight=0;}
   	// if(pkg==''){pkg=0;}
   	// bill_type=='IncludeTax';
   	// if(bill_type=="NonExcisable" || bill_type=='')
   	// {
   	// 	var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
   	// }
   	// else if(bill_type=="IncludeTax")
   	// {
   	// 	var taxableAmount2=parseFloat(basic)+parseFloat(excise)+parseFloat(freight)+parseFloat(pkg);
   	// }
   	// else if(bill_type=="Excisable")
   	// {
   	// 	var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg)+parseFloat(excise);
   	// }
   
   	var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
   	
   	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 vatamt=xmlhttp.responseText;
   		document.getElementById("taxvalue_"+i).value=vatamt;
   		// var survalue=parseFloat(vatamt)*parseFloat(suroctper)/100;
   		// document.getElementById("surchargeamt_"+i).value=survalue.toFixed(2);
   		cal_grandtotal(i);
   	}
   	}
   	var str2=document.getElementById("inputVat_"+i).value;
   	//alert(str2);
   	if(str2=='')
   		cal_grandtotal(i);	
   	else{
   		xmlhttp.open("GET","get_tax_valdata_item.php?taxid="+str2+"&basicamt="+basic+"&freight="+freight,true);
   		xmlhttp.send();	
   	}
   	
   }
   function claculateExcise(id,val)
   {
   	var id1=id.split("_");
   	var i=id1[1];
   	var basicamt=document.getElementById("basic_"+i).value;
   	var pkgamt=document.getElementById("pkgamt_"+i).value;
   	if(basicamt=='') basicamt=0;
   	if(pkgamt=='') pkgamt=0;
   	var totalabasic=parseFloat(basicamt)+parseFloat(pkgamt);
   	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("__");
   			//console.log(xmlhttp.responseText);
   			var k=data[0];
   			document.getElementById("exciseValue_"+k).value=data[1];
   				var id1="cessID1_"+i;
   	             var val1=document.getElementById(id1).value;
   	             calEcessonchange(id1,val1);
   
   		}
   	
   	}
   	xmlhttp.open("GET","ajax_getexcisevalue.php?ids="+id+"&vls="+val+"&bamt="+totalabasic,false);
   	xmlhttp.send();
   	
   }
   function cal_grandtotal(ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   	//var type_of_bill=document.getElementById("hidBillingType_"+i).value;
   	var basic=document.getElementById("basic_"+i).value;
   	// var Totaltaxable=document.getElementById("taxableAmt_"+i).value;
   	var freight=document.getElementById("freightItem_"+i).value;
   	var vat=document.getElementById("taxvalue_"+i).value;
   	// var pkg=document.getElementById("pkgamt_"+i).value;
   	// var suramt=document.getElementById("surchargeamt_"+i).value;
   
   	if(basic==''){basic=0;}
   	if(freight==''){freight=0;}
   	if(vat==''){vat=0;}
   	// if(pkg==''){
   		pkg=0;
   	// }
   	// if(suramt==''){
   		suramt=0;
   	// }
   	// if(Totaltaxable==''){
   		Totaltaxable=0;
   	// }
   
   	//alert(basic+'---'+freight+'---'+vat+'---'+pkg+'---'+suramt);
   	// if(document.getElementById("hidBillingType_"+i).value=='NonExcisable' || document.getElementById("hidBillingType_"+i).value=='' )
   	// {
   	// var grand_tot1=+parseFloat(basic)+parseFloat(freight)+parseFloat(vat)+parseFloat(pkg)+parseFloat(suramt);
   	// var grand_tot=grand_tot1.toFixed(2);
   	// }	
   	//else {
   	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(freight)+parseFloat(vat)+parseFloat(pkg)+parseFloat(suramt) ;
   	var grand_tot=grand_tot1.toFixed(2);
   	//}
   	
   	document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
   	cal_totalamount();	
   }
   function pkgamt(ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   var rate="rate_"+i;
   var str=document.getElementById(rate).value;
   
   calcTotAmtInt(str,i);
   
   }
   function checkexiseflag(ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   
   	if(document.getElementById("hidBillingType_"+i).value==''){
   		alert("Must Select Tax Type");
   	} else {
   	    if(!isNumber(ids)){
   	    	idNamePrefix=idsArr[0];
   			switch(idNamePrefix) {
   			    case 'cessID1':
   			        if(document.getElementById("exciseDuty_"+i).value==''){
   			        	alert('Please excise duty first');
   			        }
   			        break;
   			    case 'cessID2':
   			        if(document.getElementById("exciseDuty_"+i).value==''){
   			        	alert('Please excise duty first');
   			        }
   			        break;
   			    case 'inputVat':
   			        if(document.getElementById("hidBillingType_"+i).value=='' || document.getElementById("hidBillingType_"+i).value=='Excisable'){
   			        	alert('Please select correct excise flag');
   			        }
   			        break;
   			    case 'exciseDuty':
   			        if(document.getElementById("hidBillingType_"+i).value=='NonExcisable'){
   			        	alert('Please select correct excise flag');
   			        }
   			        break;
   			} 
   	    }
   	}	
   	
   }
   function calEcessonchange(id,val)
   {
   	
   	var id1=id.split("_");
   	var i=id1[1];
   	var ecessval=document.getElementById("exciseValue_"+i).value;
   		
   	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("__");
   		var k=data[0];
   		document.getElementById("ECessValue_"+k).value=data[1];
   		       var id1="cessID2_"+i;
   	             var val1=document.getElementById(id1).value;
   	             calSHEcessonchange(id1,val1);
   	}
   	}
   
   	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,false);
   	xmlhttp.send();
   }
   function calSHEcessonchange(id,val)
   {
   	
   	var id1=id.split("_");
   	var i=id1[1];
   	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("__");
   		var k=data[0];
   		document.getElementById("SAHCessValue_"+k).value=data[1];
   		calculateTaxable(i);
   	}
   	}
   	
   	var ecessval=document.getElementById("exciseValue_"+i).value;
   	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,false);
   	xmlhttp.send();
   }
   function calculateTaxable(ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   	var exciseValue=document.getElementById("exciseValue_"+i).value;
   	var ECessValue=document.getElementById("ECessValue_"+i).value;
   	var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
   	
   	if(exciseValue==''){exciseValue=0;}
   	if(ECessValue==''){ECessValue=0;}
   	if(SAHCessValue==''){SAHCessValue=0;}
   	var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
   	document.getElementById("taxableAmt_"+i).value=TOTAL.toFixed(2);
   	var taxrate=document.getElementById("inputVat_"+i).value;
   	tax_rate2(taxrate,i);
   	//cal_grandtotal(i);
   }
   function tax_rate3(str,ids)
   {
   	//alert(i);
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }
   
       	getsuperCharge(str,i);
           
   	// var bill_type=document.getElementById("hidBillingType_"+i).value;
   	var basic=document.getElementById("basic_"+i).value;
   	var freight=document.getElementById("freightItem_"+i).value;
   	//var freight=0.00;
   	// var excise=document.getElementById("taxableAmt_"+i).value;
   	// var pkg=document.getElementById("pkgamt_"+i).value;
   	// var suroctper=document.getElementById("surchargeper_"+i).value;
   	// if(suroctper=='') 
   		suroctper=0;
   	// if(pkg=='') 
   		pkg=0;
   
   	if(basic==''){basic=0;}
   	// if(excise==''){
   		excise=0;
   	// }
   	if(freight==''){freight=0;}
   	if(pkg==''){pkg=0;}
   //  var bill_type = "IncludeTax";
   // 	if(bill_type=="NonExcisable" || bill_type=='')
   // 	{
   // 		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
   // 	}
   // 	else if(bill_type=="IncludeTax")
   // 	{
   // 		var taxableAmount2=parseFloat(basic)+parseFloat(excise)+parseFloat(freight)+parseFloat(pkg);
   // 	}
   // 	else if(bill_type=="Excisable")
   // 	{
   // 		var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg)+parseFloat(excise);
   // 	}
   var taxableAmount2=parseFloat(basic)+parseFloat(freight)+parseFloat(pkg);
   
   	
   	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 vatamt=xmlhttp.responseText;
   		document.getElementById("taxvalue_"+i).value=vatamt;
   		var survalue=parseFloat(vatamt)*parseFloat(suroctper)/100;
   		//document.getElementById("surchargeamt_"+i).value=survalue.toFixed(2);
   
   		cal_grandtotal(i);
   	}
   	}
   	var str2=document.getElementById("inputVat_"+i).value;
   	if(str2=='')
   		cal_grandtotal(i);	
   	else{
   		xmlhttp.open("GET","get_tax_valdata_item.php?taxid="+str2+"&amt="+taxableAmount2,true);
   		xmlhttp.send();	
   	}
   	
   }
   function DiscountAmounts(DA,ids)
   {
       if(isNumber(ids)){
       	i=ids
       } else {
   	    var idsArr=ids.split('_');
   	    var i=idsArr[1];     	
       }    
   	//numeric(DA,id);
         
           
   		var totValue = document.getElementById("price_"+i).value;
   		var discType = document.getElementById("PerAmo_"+i).value;
   		var disct = document.getElementById("Discount_"+i).value;
                   
                   if(parseFloat(disct)>parseFloat(totValue))
                       {
                           alert('Discount Cannot Be Greater Than Total Amount');
                           document.getElementById("Discount_"+i).value='';
                           document.getElementById("Discount_"+i).focus();                        
                           document.getElementById("basic_"+i).value='';
                           document.getElementById("TotalSpecial_"+i).value='';
                           cal_grandtotal(i);
                           return false;
                       }
                       
   		if(totValue==''){totValue=0;}
   		if(DA==""){DA=0;}
   		 var totalamt=0;
   		if(discType=='Amount')
   		{
   			var subTotal = parseFloat(totValue)-parseFloat(disct);
   			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
               
   		}
   		else
   		{
   			if(disct>100)
   			{
   				       alert('Discount % Should be less then 100');
                           document.getElementById("Discount_"+i).value='';
                           document.getElementById("Discount_"+i).focus();                        
                           document.getElementById("basic_"+i).value='';
                           document.getElementById("TotalSpecial_"+i).value='';
                           cal_grandtotal(i);
                           return false;
   
   			}
   			else
   			{
   			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
   			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
   	     	}
               	
   		}
                   
          if(document.getElementById("hidBillingType_"+i).value!=0)
           {
             if(document.getElementById("hidBillingType_"+i).value=='Excisable' || document.getElementById("hidBillingType_"+i).value=='IncludeTax')
             {
             	var exciseid="inputVat_"+i;
             	var exciseval=document.getElementById(exciseid).value;
             	tax_rate2(exciseid,exciseval);
             }
             if(document.getElementById("hidBillingType_"+i).value=='NonExcisable')
             {
               var exciseid="exciseDuty_"+i;
             	var exciseval=document.getElementById(exciseid).value;
             	claculateExcise(exciseid,exciseval);
             }  
         }
           else
           {
           	document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
           	cal_grandtotal(i);
           }
   }
   function getsuperCharge(str,i){
   
   	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("surchargeper_"+i).value=xmlhttp.responseText;
   		document.getElementById("surchargeperDisp_"+i).value=xmlhttp.responseText;
   		var dfgd=xmlhttp.responseText;
   		//console.log('fgd '+xmlhttp.responseText);
   	}
   	}
   	xmlhttp.open("GET","getSuperCharge.php?taxid="+str,false);
   	xmlhttp.send();	
   
   }
   function isNumber(n) { return /^-?[\d.]+(?:e-?\d+)?$/.test(n); } 
</script>