<?php ob_start();?>
<script>
var xmlHttp
function changestorename(str)
{

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="Store_Name.php";
	url=url+"?store_code="+str;
	xmlHttp.onreadystatechange=NumberChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function NumberChanged1()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("txtid").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
  
  
function openPopupProfile(i)
{
  	window.open("Search_item_MRN.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable =no");
}
 $(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
function Completetotal(id)
{
 	var  Item_Amount = document.getElementById('total_Item_Amount').value;
 	var  Charge_Amount = document.getElementById('Charge_Amount').value;
	var inclusive=document.getElementById('tax_suroct_value').value;
	var total_tax=document.getElementById('tax_chargeamount').value;
 	var Grand_Total = parseFloat(Item_Amount) + parseFloat(Charge_Amount)+parseFloat(total_tax)+parseFloat(inclusive);
  	document.getElementById('grandtotal').value =Grand_Total;
}

function calculate_short(id)
{
	var x = document.getElementById('reciveqty_'+id).value;
	var poqty = document.getElementById('poqty_'+id).value;
	var reject = document.getElementById('rejectqty_'+id).value;
	var rate = document.getElementById('itemrate_'+id).value;
	//var tot = document.getElementById('totalrate_'+id).value;
	//alert("total rate is : "+tot);

	if(x != '')
	{
		if(poqty >= x)
		{
			//alert(rate);
			if(reject >0){
				document.getElementById('rejectqty_'+id).disabled =false;
			}
			else{
				document.getElementById('short_accessid_'+id).value = parseInt(poqty)- parseInt(x);
				document.getElementById('rejectqty_'+id).disabled =true;
				document.getElementById('totalrate_'+id).value = parseInt(rate) * parseInt(x);
				//alert(document.getElementById('totalrate_'+id).value);
			}

		}
		else
		{
			alert("Received Quantity can not be greater than PO Quantity");
			return false;
		}
		return true;
	}
	else
	{
		document.getElementById('short_accessid_'+id).value = '0';
	}
}


//--------------  ADD Sub charges----------------------------------
function cal_surcharges(id)
{
	 
	   document.getElementById("hidden_percent_inclusivecharge").value=id;
}
 
function cal_surcharges1()
{
  
   var surcharge=document.getElementById("percent_inclusivecharge").value;
   var per=document.getElementById('percent_inclusive').value;
   var amount=document.getElementById('tax_chargeamount').value;
  var total=document.getElementById('total_Item_Amount').value;
  var   total_tax=document.getElementById('tax_chargeamount').value;
   	if(surcharge=="SUR"){  
		totals=(parseInt(per)*parseFloat(amount))/100;
 		var	 final=totals;
 	 }
	else if(surcharge=="OCT"){
 	   	totals=parseFloat(total)+parseFloat(total_tax);
	 	var 	final=(parseFloat(totals)*  parseFloat(per))/100;
		 }	
 
		document.getElementById('tax_suroct_value').value=final;
	  
}

 


function update_amount(id)
{
document.getElementById("item_total_rate_"+id).value= (document.getElementById("reciveqty_"+id).value) * (document.getElementById("itemprice_"+id).value);
 }
 function update_basic()
{
var  itemamount = 0;
   var table = document.getElementById("totalrow").value;
   for(i=1; i<=table; i++)
	{
 		var totalrate = document.getElementById('itemprice_'+i).value;
 			itemamount  =parseInt(itemamount)+  parseInt(totalrate);
			 
			document.getElementById('total_Item_Amount').value = itemamount;
 	}
	
}
 
function showitem_details(str)
{
if (str=="")
  {
  document.getElementById("txt_item_details").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("txt_item_details").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getitem_details.php?addmrn="+str,true);
xmlhttp.send();
}



function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function get_mrn_details(str)
{
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)
    {
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("orderid").innerHTML=data[0];
    document.getElementById("itemid").innerHTML=data[1];
    document.getElementById("amount_tax").innerHTML=data[2];
	
    }
  }

xmlhttp.open("GET","mrn_order_details.php?mrnno="+str,true);
xmlhttp.send();
}


function showmrn(str)
{
var site= document.getElementById('site').value;
//var store= document.getElementById('store').value;
//alert(site);
//alert(store);
//alert(site);
if (str=="")
  {
  document.getElementById("getmrn").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("getmrn").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_mrn.php?vendor="+str+"&site="+site,true);
xmlhttp.send();
}
function validate()
{
	var site=document.getElementById("site").value;
	var store=document.getElementById("store").value;
	var vendor=document.getElementById("vendor").value;
	var mrn_no=document.getElementById("mrn_no").value;
	var bill=document.getElementById("bill").value;
	var bill_date=document.getElementById("bill_date").value;
	var purchase_orderno=document.getElementById("purchase_orderno").value;
	var cash_credit=document.getElementById("cash_credit").value;
	var credit_days=document.getElementById("credit_days").value;
	if(site=='000')
	{
		alert("Please Select Site");
		document.getElementById("site").focus();
		return false;
	}
	if(store=='000')
	{
		alert("Please Select Store");
		document.getElementById("store").focus();
		return false;
	}
	if(vendor=='000')
	{
		alert("Please Select Vendor");
		document.getElementById("vendor").focus();
		return false;
	}
	if(mrn_no=='000')
	{
		alert("Please Select MRN Number");
		document.getElementById("mrn_no").focus();
		return false;
	}
	if(bill=='')
	{
		alert("Please Enter Bill Number");
		document.getElementById("bill").focus();
		return false;
	}
	if(bill_date=='')
	{
		alert("Please Enter Bill Date");
		document.getElementById("bill_date").focus();
		return false;
	}
	if(purchase_orderno=='')
	{
		alert("Please Enter Order Number");
		document.getElementById("purchase_orderno").focus();
		return false;
	}
	if(cash_credit=='000')
	{
		alert("Please Select Cash/Credit");
		document.getElementById("cash_credit").focus();
		return false;
	}
	if(credit_days=='')
	{
		alert("Please Enter Credit Days");
		document.getElementById("credit_days").focus();
		return false;
	}
	
}
function check()
{
	if(document.getElementById("ledger").value == '000')
	{
		alert("Please Select Ledger");
		document.getElementById("ledger").focus();
		return false;
	}
}
function calc_basicamt()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("basic_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("basic_amount").value=total_basic.toFixed(2);
}

function calc_total_excise_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("exciseValue_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("exciseValue").value=total_basic.toFixed(2);
}
function calc_total_ecess_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("ECessValue_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("ECessValue").value=total_basic.toFixed(2);
}
function calc_total_sah_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("SAHCessValue_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("SAHCessValue").value=total_basic.toFixed(2);
}
function calc_total_taxable_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("taxable_amt_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("taxable_amt").value=total_basic.toFixed(2);
}
function calc_total_tax_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("taxvalue_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("taxvalue").value=total_basic.toFixed(2);
}
function calc_total_total_amount()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value;
	
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("TotalSpecial_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("total_item_amount").value=total_basic.toFixed(2);
}
function claculateExcise(i,str)
{
	if(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("__");
    			    		
    		if(data[0]==1)
    		{    			
    	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("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		//document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("exciseId_"+i).innerHTML=data[1];
    		}	
    		else 
    		{
         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("exciseId_"+i).innerHTML=data[1];
    		}
    		}
  		}
		xmlhttp.open("GET","checkdata.php?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();	
		
	
	
	
}






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

function calamt(i)
{
var amt=parseFloat(document.getElementById('rate_'+i).value);
var qty=parseFloat(document.getElementById('reciveqty_'+i).value);
var amount=amt*qty;
document.getElementById('valuedata_'+i).value=amount.toFixed(2);	
}
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 calculateExciseDuty1()
{
	var basic=document.getElementById("basic_amount").value;
	var ExcisePercentage=document.getElementById("ExcisePercentage").value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue").value=exciseVal.toFixed(2);
}

function calculateECess(i)
{
	
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessPercentage=document.getElementById("ECessPercentage_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue_"+i).value=total.toFixed(2);
}
function calculateECess1()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").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 calculateSAHCess1()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").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 calculateTaxable1()
{
	var totalDiscountedPrice=document.getElementById("basic_amount").value;
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxable_amt").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 calculateVatCstValue()
{
	var taxable=document.getElementById("taxable_amt").value;
	var vatcstRate=document.getElementById("VatCstPerc").value;
	var VatCstAmount=taxable*(vatcstRate/100);
	document.getElementById("taxvalue").value=VatCstAmount.toFixed(2);
}
function tax_rate1(str)
{
var taxableAmount=document.getElementById("taxable_amt").value;
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_purchtax_val.php?taxid="+str+"&amt="+taxableAmount,true);
xmlhttp.send();
}
function tax_rate(str,i)
{
var billing_type=document.getElementById("hid_billing_type_"+i).value;

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


function cal_suroct(str)
{
	var total_tax=document.getElementById("taxvalue").value;
	var final_sur=total_tax*(str/100);
	document.getElementById("sur_oct_amt").value=final_sur.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_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(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 cal_grandtotal1()
{
	var basic=document.getElementById("basic_amount").value;
	var Totaltaxable=document.getElementById("taxable_amt").value;
	var vatcstAmt=document.getElementById("taxvalue").value;
	var suramt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;
	//var entry_tax=document.getElementById("entry_tax").value;
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	if(vatcstAmt==''){vatcstAmt=0;}
	if(suramt==''){suramt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	//if(entry_tax==''){entry_tax=0;}
	var grand_tot=parseFloat(Totaltaxable)+parseFloat(vatcstAmt)+parseFloat(suramt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges); 
	
	
	document.getElementById("grand_total").value=grand_tot.toFixed(2);
}

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);
}
}

</script>
<?php 
$PageSecurity = 4;
$PageName = 'Purchase Bill Book';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['ModifyOrderNumber']) and $_SESSION[UserType]=='SuperAdmin')  {
	$title = _('Modify Purchase BillBook') . ' ' . $_GET['ModifyOrderNumber'];
} else {
}
if(isset($_GET['issueid'])  && isset($_GET['issueid']) !='')
{

	$title = _('Update Issue Slip');
}
else
{
	$title = _('Purchase BillBook');
}
?>
<?php 
if($_REQUEST['Save']) 
{


for($cr=0; $cr<count($_REQUEST['item_id']); $cr++)
{
	$item_row[]=$_REQUEST['item_id'][$cr];
}
if(isset($item_row))
{
	$item=implode(',',$item_row);
}

for($str=1;$str<$_REQUEST['count_tax'];$str++)
	{
		$caption_val[$str] = $_REQUEST['caption_value'][$str];
		$percent[$str] = $_REQUEST['rate'][$str];
	}	
	
	$financial=date('Y')."-".(date('Y')+1);
	  $prefixcode="CLD9/PV";
	  $sql="select * from purchase_billbook where site = '".$_GET['site']."' order by id desc limit 0,1";
      
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	  $sqldata=DB_query("select locationname from locations where loccode='".$_GET['site']."'",$db);
	  $sqltext=DB_fetch_array($sqldata);
	   $sitename=$sqltext['locationname'];
	  $siteCode = $sitename;
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
		 if($siteCode!='')
				$val1= substr($myrow['purchase_bill'],0,18);
				$strChar1 = substr($myrow['purchase_bill'],0,9);
				$strChar = $strChar1."/".ucwords($_REQUEST['site'])."/".$financial."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			$strChar = $prefixcode."/".ucwords($_REQUEST['site'])."/".$financial."/";
		}
	  }
	  else
	  {
	  	$strChar = $prefixcode."/".ucwords($_REQUEST['site'])."/".$financial."/";
	  }
	  
	 $strFinal = $maxval+1;
	  $strBothFinal = $strChar.str_pad($strFinal,4,"0",STR_PAD_LEFT); 	

 $insert_sql="INSERT INTO purchase_billbook set
			  id='',  
			  site='".$_REQUEST['site']."',    
			  bill_book_no='".$strBothFinal."',
			  bill_book_date= '".FormatDateForSQL($_REQUEST['bill_book_date'])."', 
			  due_date='".FormatDateForSQL($_REQUEST['due_date'])."',  
			  vendor='".$_REQUEST['vendor']."',  
			  mrn_no='".$_REQUEST['mrn_no']."', 
			  cash_credit='".$_REQUEST['cash_credit']."',  
			  credit_days='".$_REQUEST['credit_days']."',  
			  mrnqty_ids='".$item."',  
			  ledger='".$_REQUEST['ledger']."', 
			  Excise_Effect ='".$_REQUEST['Excise_Effect']."', 
			  remarks='".$_REQUEST['remarks']."',  
			  total_item_amount='".$_REQUEST['total_item_amount']."',  
			  sur_oct_amt='".$_REQUEST['sur_oct_amt']."',  
			  freight='".$_REQUEST['freight']."',  
			  pkg_charges='".$_REQUEST['pkg_charges']."',  
			  add_charges='".$_REQUEST['add_charges']."',  
			  round_off='".$_REQUEST['round_off']."',  
			  GrandTotal='".$_REQUEST['GrandTotal']."',  
			  bill_status ='Pending', 
			  pending_amount='".$_REQUEST['grand_total1']."', 
			  form_type='".$_REQUEST['form_type']."', 
			  created_date='".FormatDateForSQL(date('d/m/Y'))."',  
			  created_by='".$_SESSION['UserID']."'  ";
$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
$insert_res=DB_query($insert_sql,$db);
  $Lastreq_id=DB_Last_Insert_ID($db,'purchase_billbook',$ErrMsg);
  
  for($i=1;$i<$_REQUEST['count'];$i++)
  {
		$data['purch_billbookid']=$Lastreq_id;
		$data['mst_productid']=$_REQUEST['item_id'][$i];
		$data['quantity']=$_REQUEST['quantity'][$i];
		$data['rate']=$_REQUEST['rate'][$i];
		$data['total_price']=$_REQUEST['total_price'][$i];
		$data['discount_type']=$_REQUEST['discount_type'][$i];
		$data['discount']=$_REQUEST['discount'][$i];
		$data['discount_amount']=$_REQUEST['discount_amount'][$i];
		$data['sub_total']=$_REQUEST['sub_total'][$i];
		$data['specialdiscount']=$_REQUEST['specialdiscount'][$i];
		$data['specialdiscount_amount']=$_REQUEST['specialdiscount_amount'][$i];
		$data['make']=$_REQUEST['make'][$i];
		$data['color']=$_REQUEST['color'][$i];
		$data['grade']=$_REQUEST['grade'][$i];
		$data['basic_amt']=$_REQUEST['basic_amt'][$i];
		$data['tax_type']=$_REQUEST['tax_type'][$i];
		$data['Excise_Duty']=$_REQUEST['Excise_Duty'][$i];
		$data['ExcisePercentage']=$_REQUEST['ExcisePercentage'][$i];
		$data['Excise_Duty_value']=$_REQUEST['Excise_Duty_value'][$i];
		$data['Edu_Cess_perc']=$_REQUEST['Edu_Cess_perc'][$i];
		$data['Edu_Cess']=$_REQUEST['Edu_Cess'][$i];
		$data['SHE_Cess_perc']=$_REQUEST['SHE_Cess_perc'][$i];
		$data['SHE_Cess']=$_REQUEST['SHE_Cess'][$i];
		$data['taxable_amt']=$_REQUEST['taxable_amt'][$i];
		$data['vat_cst']=$_REQUEST['vat_cst'][$i];
		$data['vat_cst_amt']=$_REQUEST['vat_cst_amt'][$i];
		$data['total_amount']=$_REQUEST['total_amount'][$i];
		$data['remarks']=$_REQUEST['item_remarks'][$i];
		$sql=$s->insertRecord('purchase_bill_details', $data);
		$result=DB_query($sql,$db,$ErrMsg);
  }
$update_mrn="Update addmrn set mrnstatus='closed' where id='".$_REQUEST['mrn_no']."'";
$update_res=DB_query($update_mrn,$db);
echo "<script>location.href='index.php?route=PurchBillBook_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Record Inserted Successfully!'),'success');

}
?>
<h2 align="center"><strong>Purchase Bill Book</strong></h2>
<form action="" method="post">
<h3 align="center"><font color="#FF0000">Please Enter All General Details First</font></h3>
<h3 align="center">General Details</h3>
<div align="center">
<table width="60%"  cellspacing="2" cellpadding="2" style="background:#CCCCCC; border: solid 1px #999999">
<tr>
<th width="19%"><strong>Site</strong></th>
<td width="27%"> 
<?php 
$sql = "select loccode, locationname from locations";
$result=DB_query($sql, $db);
?>
<select name="site" id="site"  class="select_purch" style="width:100%">  <!--onchange="showdata(this.value)"-->
<option value ="000">---Select Site---</option>
<?php
while($myrow=DB_fetch_array($result))
{ 
$p='';
if($myrow['loccode']==$_REQUEST['site'])
$p="selected";

?>
<option value="<?php echo $myrow['loccode']; ?>" <?php echo $p; ?>> <?php echo $myrow['locationname']; ?> </option>
<?php } ?>
</select></td>
<th width="23%" nowrap="nowrap">
 <strong>Purchase Voucher No  </strong></th>
<td width="31%"><input name="bill_book_no" type="text" value=""  style="width:100%" id="bill" readonly="true"/>
</td>

</tr>



<tr>
<th><strong>Vendor Name </strong></th>
<td><div id="vender">
	
	<?php
$sql = "select id,vendor_code, vendor_name from suppliers";
$result=DB_query($sql, $db);
?>
  <select name="vendor" id="vendor" onchange="showmrn(this.value)" class="select_purch"  style="width:100%">
    <option value="000">---Select Vendor---</option>
    <?php
while($myrow = DB_fetch_array($result))
{
?>
    <option value="<?php echo $myrow['id']; ?>" <?php echo($_REQUEST['vendor']==$myrow['id']?'selected':''); ?>><?php echo $myrow['vendor_name']; ?></option>
    <?php } ?>
  </select></div></td>
<th><strong>Cash/Credit</strong></th>
<td><select name="cash_credit" class="select_purch" style="width:100%" id="cash_credit">
  <option value="000">---Select Cash/Credit---</option>
  <option value="Cash">Cash</option>
  <option value="Credit" selected="selected">Credit</option>
</select></td>

</tr>


<tr>
<th><strong>MRN No</strong></th>
<td><?php 
$sql1 ="select id, MRNNo from addmrn where OrderFromSite='".$_REQUEST['site']."'  and ReceivedFrom='".$_REQUEST['vendor']."' and mrnstatus!='closed' ";
$result1=DB_query($sql1, $db);
?>
  <div id="getmrn">
    <select name="mrn_no" id="mrn_no"  onchange="get_mrn_details(this.value)" class="select_purch"  style="width:100%">
      <option value="000">---Select MRN---</option>
      <?php
while($myrow1=DB_fetch_array($result1))
{
$p='';
if($myrow1['id']==$_REQUEST['mrn_no'])
$p="selected";
?>
      <option value="<?php echo $myrow1['id']; ?>" <?php echo($_REQUEST['mrn_no']==$myrow1['id']?'selected':'');?>><?php echo $myrow1['MRNNo']; ?></option>
      <?php } ?>
    </select>
  </div></td> 
<th><strong>Credit Days</strong></th>
<td><input name="credit_days" type="text" value="<?php  echo $_REQUEST['credit_days'];?>"  style="width:100%" id="credit_days"/></td>
</tr><tr>
<th><strong>Due Date</strong></th>
<td><input type="text" name="due_date" id="due_date" class="datepicker" value="<?php echo $_REQUEST['due_date']; ?>"  style="width:100%" /></td>
<th><strong>Date</strong></th>
<td><input type="text" name="bill_book_date" id="bill_date" class="datepicker" value="<?php echo date('d/m/Y'); ?>"  style="width:100%" /></td>
<!-- <input type="text" name="textfield210" />-->

</tr>
<tr>
<th>Bill/Challan No</th>
<td><div id="orderid"><input type="text" name="bill_challan_no" id="documenttype" style="width:100%" /></div></td>	
	
</tr>

</table>






<fieldset><legend><strong>ITEM DETAILS <?php echo $type_row['Type'];?></strong></legend>

<div style="overflow:scroll; width:950px ; ">
	<div id="itemid">
<table width="100%" border="0" cellspacing="3" cellpadding="5">
  <tr>
    <th scope="col"><strong>ITEM CODE </strong></th>
    <th scope="col"><strong>DESCRIPTION</strong></th>
    <th scope="col"><strong>MAKE</strong></th>
    <th scope="col"><strong>GRADE</strong></th>
    <th scope="col"><strong>COLOR</strong></th>
    <th scope="col"><strong>UOM</strong></th>
    <th scope="col"><strong>PO QTY </strong></th>
    <th scope="col"><strong>QTY AS PER BILL </strong></th>
    <th scope="col"><strong>QTY ACCEPTED </strong></th>
    <th scope="col"><strong>SHORT QUANTITY </strong></th>
    <th scope="col"><strong>RATE</strong></th>
   <!-- <th scope="col"><strong>DISCOUNT TYPE </strong></th>
    <th scope="col"><strong>DISCOUNT</strong></th>
	<th scope="col"><strong>DISCOUNT AMOUNT</strong></th>-->
    <th scope="col"><strong>VALUE AFTER DISCOUNT </strong></th>
    <!--<th scope="col"><strong>TAX TYPE </strong></th>
    <th scope="col"><strong>TAX RATE </strong></th>
    <th scope="col"><strong>TAX VALUE </strong></th>
    <th scope="col"><strong>VALUE WITH TAX </strong></th>-->
    <th ><strong>Total Price</strong></th>
	<th ><strong>Discount Percent</strong></th>
	<th ><strong>Discount</strong></th>
	<th ><strong>Discount Amount</strong></th>
	<th ><strong>Sub Total</strong></th>
	<TH><strong>SPECIAL DISCOUNT</strong></TH>
	<TH><strong>SPECIAL DISCOUNT AMOUNT</strong></TH>
	<th ><strong>BASIC AMOUNT</strong></th>
	<th ><strong>Tax Type</strong></th>
	<th width="33%"><strong>Excise</strong></th>
	<th><strong>E-Cess</strong></th>
	<th><strong>SAH-E Cess</strong></th>
	<th><strong>Taxable Amount </strong></th>
	<th><strong>VAT/CST</strong></th>
	<th><strong>VAT/CST Amount</strong></th>
	<TH><strong>TOTAL AMOUNT</strong></TH>    
    <th scope="col"><strong>REMARKS</strong></th>
  </tr>
  </table>
  </div>
</div>

</fieldset>
<br />


<table border="1" cellspacing="1" cellpadding="2" width="100%">
<tr>
<td valign="top">
<table width="100%" align="left" style="border:solid 1px #999999; background:#CCCCCC">
<tr>
<th><strong>Ledger</strong></th>
<td>
<select name="ledger" id="ledger" style="width:220px">
<option value="000">---Select Ledger---</option>
<?php
$ledger_sql=DB_query("select AccountsID, AccountName from accountledger ORDER BY AccountName ASC",$db);
while($ledger_row=DB_fetch_array($ledger_sql))
{
?>
<option value="<?php echo $ledger_row['AccountsID'];?>"<?php echo ($ledger_row['AccountsID']==$_REQUEST['ledger']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<th><strong>Remarks If Any</strong></th>
<td>
<textarea name="remarks" id="remarks" rows="3" cols="25"><?php echo $_REQUEST['remarks'];?></textarea></td>
</tr>
  <tr>
    <th valign="top"><strong>Excise Effect</strong></th>
    <td valign="top"><select name='Excise_Effect' style="width:auto">
	<option value="0">---</option>
	<option value="RG-23A"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
		<option value="RG-23C"  <?php echo ( $mrn_row['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
		<option value="modvat"  <?php echo ( $mrn_row['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
 	</select>&nbsp;</td>
  </tr>
  <tr>
  <th>Form Type</th>
  <td><select  name="form_type" id="form_type" style="width:100%; height:20px;">
  <option value="">Select</option>
  <?php
 $formSql=DB_query("Select * from form_type_master",$db);
while($formRow=DB_fetch_array($formSql))
{
?>
  <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
  <?php }?>
</select></td>
  </tr>
  </table></td>
<td align="right" width="50%">
<table width="100%" border="0" cellspacing="2" cellpadding="2"  style="border:solid 1px #999999; background:#CCCCCC">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
                </tr>
               
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="freight" id="TotalCharge" style="width:100%;"/></td>
                </tr>
                <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges" id="packagingCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
				<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;" /></td>
				</tr>
				
                <tr>
                  <td><input type="button" name="grandbutton" value="Grand Total" onclick="cal_roundamt()"/></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" style="width:100%;" readonly="readonly" onfocus="cal_grandamount()" /></td>
                </tr>
              </table>
</td>
</tr>
</table>
<br />
<p align="center"><input type="submit" name="Save" value="Save" onclick="return check()"/></p>
</form>
<script language="javascript" type="text/javascript">
	
function showdata(str)
{

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)
    {
	var data=xmlhttp.responseText.split("__");	
	//alert(data);
	document.getElementById("vender").innerHTML=data[0];
    document.getElementById("hid-Godown-div").innerHTML=data[1];
	
    }
  }

xmlhttp.open("GET","purchasebillnogenerate.php?site="+str,true);
xmlhttp.send();
}	
function DiscountAmount(DA,i)
{
	
	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 = quantity*rate;
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("Discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(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 checkamount(str,i)
{
	
var k=parseFloat(document.getElementById("totalValue_"+i).value);

var t=parseFloat(str);
if(t>k)
{
alert("Discount Amount Not Greater Then Rate");
document.getElementById("Discount_"+i).value='';
document.getElementById("NetRate_"+i).value='';
document.getElementById("perc_"+i).value='';
document.getElementById("Discount_"+i).focus();	
}	
}
function checkspecialamt(str,i)
{
var k=parseFloat(document.getElementById("NetRate_"+i).value);

var t=parseFloat(str);
if(t>k)
{
alert("Special Discount Amount Not Greater Then Sub Total");
document.getElementById("SpecialDiscount_"+i).value='';
document.getElementById("Specialperc_"+i).value='';
document.getElementById("basic_"+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 checkExcisable(str,i)
{
 	
	if(str=='NonExcisable')
	{
		document.getElementById("ExcisePercentage_"+i).disabled=true;
		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("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 checkexiseflag(i)
{
	
if(document.getElementById("hid_billing_type_"+i).value=='')
	{
	alert("Must Select Tax Type");
	}	
	
}
function cal_totalamount()
{
	
	var total=0;
var t=document.getElementById("count").value;

for(var i=1;i<t;i++)
{
var amt=parseFloat(document.getElementById("TotalSpecial_"+i).value);
total=parseFloat(total)+amt;	
}	
document.getElementById("total_item_amount").value=total.toFixed(2);	
}
function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges);
	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)).toFixed(2);	
	 }
	
}

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

}

</script>


