function quot_no_gen()
{
	var v1 = document.getElementById("bil_no").value.split("/");
	var v2 = document.getElementById("bill_dt").value.split("/");
	
	var year   = v2[2].slice(-2);
	var month  = v2[1];
	
	if(month <=3){
		var minusfield  = year - 1;
		var daterange 	= minusfield+'-'+year; 
	}else{
		var addfield  	= +year + +1;
		var daterange 	= year+'-'+addfield; 
	}
	var v3 = v1[0]+"/"+daterange+"/"+v1[2];
	document.getElementById("bil_no").value=v3.trim();
}
// JavaScript Document
function cour_wet_cal(){
	var cour_amnt_val  = $('#cour_amnt_val').val();
	var cour_wgt 	   = $('#cour_wgt').val();
	var cour_amt_for_1 = $('#cour_amt_for_1').val();
	//alert(cour_amnt_val);
	if(cour_wgt !='' && cour_amt_for_1 !='' )
	{
		if(document.getElementById("party_CNTRY").value == 1 && document.getElementById("party_STATE").value == 32)
		{
			var tot 			= Math.abs(cour_wgt*cour_amt_for_1).toFixed(2);
			var net_sale_amt 	= document.getElementById("bil_amt").value;
			var taxCal_net_cor 	= parseFloat((cour_wgt * cour_amt_for_1))+parseFloat(net_sale_amt);
	//		alert(taxCal_net_cor);
			
			document.getElementById("cour_amt").value				= tot;
//			document.getElementById("sgst_cor_net_tot").innerHTML 	= Math.abs(Math.round((taxCal_net_cor / 100) * 14)).toFixed(2);
//			document.getElementById("cgst_cor_net_tot").innerHTML 	= Math.abs(Math.round((taxCal_net_cor / 100) * 14)).toFixed(2);
			document.getElementById("sgst_cor_net_tot").innerHTML 	= Math.abs((taxCal_net_cor / 100) * 9).toFixed(2);
			document.getElementById("cgst_cor_net_tot").innerHTML 	= Math.abs((taxCal_net_cor / 100) * 9).toFixed(2);
			cour_amt_cal(tot,cour_amnt_val);
		}
		else if(document.getElementById("party_CNTRY").value == 1 && document.getElementById("party_STATE").value != 32)
		{
			var tot 			= Math.abs(cour_wgt*cour_amt_for_1).toFixed(2);
			var net_sale_amt 	= document.getElementById("bil_amt").value;
			var taxCal_net_cor 	= parseFloat((cour_wgt * cour_amt_for_1))+parseFloat(net_sale_amt);
	//		alert(taxCal_net_cor);
			
			document.getElementById("cour_amt").value				= tot;
//			document.getElementById("igst_cor_net_tot").innerHTML 	= Math.abs(Math.round((taxCal_net_cor / 100) * 28)).toFixed(2);
			document.getElementById("igst_cor_net_tot").innerHTML 	= Math.abs((taxCal_net_cor / 100) * 18).toFixed(2);
			cour_amt_cal(tot,cour_amnt_val);			
		}
		else
		{
			var tot 			= Math.abs(cour_wgt*cour_amt_for_1).toFixed(2);
			var net_sale_amt 	= document.getElementById("bil_amt").value;
			var taxCal_net_cor 	= parseFloat((cour_wgt * cour_amt_for_1))+parseFloat(net_sale_amt);
	//		alert(taxCal_net_cor);
			
			document.getElementById("cour_amt").value				= tot;
			document.getElementById("igst_cor_net_tot").innerHTML 	= Math.abs((taxCal_net_cor / 100) * 0).toFixed(2);
			cour_amt_cal(tot,cour_amnt_val);					
		}
	}else{
//		var tot = 0.00;
		var tot = Math.abs(cour_wgt*cour_amt_for_1).toFixed(2);
//		alert(tot);
		document.getElementById("cour_amt").value = tot;
		var courGSTtax = 0;
		cour_amt_cal(tot,cour_amnt_val);
	}
}
function cour_amt_cal(ids,ty_id)
{	
	if(ty_id==1)
	{	//alert("type 1")
		var cur_amt = parseFloat(ids);
		var bill_amt = document.getElementById("to_bil_amt").value;
		var tx_tot = document.getElementById("to_bil_amt_tx").value;
		
		if(ids!='NaN' && ids!='')
		{		
			var tot_cur = parseFloat(cur_amt)+parseFloat(tx_tot);
		}
		else
		{
			var tot_cur = parseFloat(ntx_tot);
		}
		document.getElementById("tot_bl_amt_tx").innerHTML=formatDollar(tot_cur);
		document.getElementById("to_bil_amt").value=tot_cur;
		document.getElementById("to_bil_amt_st").value=formatDollar(tot_cur);
		$("#num_word_tx").load("ajax/billing_AJAX.php?pg_id=1&key_word="+tot_cur,function(response)
		{});
	}
	else if(ty_id==2)
	{	
//		alert("type 2");
//		alert(document.getElementById('tax_p').value);
		
//		var tax_p  = document.getElementById('tax_p').value;

//		var tax_p = tax_p.split(",");

		var tax_p = 9 + 9;

		if(tax_p != '')
		{			
			var bil_amt = document.getElementById('bil_amt').value
			var tax_tmp = parseFloat(tax_p) * parseFloat(bil_amt);
			var tax_amt = tax_tmp / 100;
			var tot_bl = parseFloat(tax_amt);
		}
		else
		{
			var tot_bl = 0.00;
		}
	
		var cur_amt = parseFloat(ids);
		var ntx_tot = document.getElementById("to_bil_amt_ntx").value;
		
		
		if(ids!='NaN' && ids!='')
		{		
			var tot_cur = parseFloat(cur_amt)+parseFloat(ntx_tot)+parseFloat(tot_bl);
		}
		else
		{
			var tot_cur = parseFloat(ntx_tot)+parseFloat(tot_bl);
		}
		
		var courWgt 	= document.getElementById("cour_wgt").value;
		var courAmt 	= document.getElementById("cour_amt_for_1").value;
		var courGSTtax 	= ((courWgt * courAmt) / 100) * 18;
		//alert(courGSTtax);
		
		document.getElementById("tot_bl_amt").innerHTML	= formatDollar(Math.round(tot_cur+courGSTtax));
		document.getElementById("to_bil_amt").value		= Math.abs(tot_cur+courGSTtax).toFixed(2);	
		$("#num_word_ntx").load("ajax/billing_AJAX.php?pg_id=1&key_word="+Math.round(tot_cur+courGSTtax),function(response)
		{});	
	}
	
}

function abroad_cour_wet_cal()
{
	var cour_amnt_val  = $('#cour_amnt_val').val();
	var cour_wgt 	   = $('#cour_wgt').val();
	var cour_amt_for_1 = $('#cour_amt_for_1').val();

	var tot 			= Math.abs(cour_wgt*cour_amt_for_1).toFixed(2);
	var net_sale_amt 	= document.getElementById("bil_amt").value;
	//alert(net_sale_amt);
	var taxCal_net_cor 	= parseFloat((cour_wgt * cour_amt_for_1))+parseFloat(net_sale_amt);
	
	document.getElementById("cour_amt").value = tot;
	
	var courWgt 	= document.getElementById("cour_wgt").value;
	var courAmt 	= document.getElementById("cour_amt_for_1").value;
	var courGSTtax 	= ((courWgt * courAmt) / 100) * 18;	
	
	//alert(tot);
	
	document.getElementById("tot_bl_amt").innerHTML	= formatDollar((parseFloat(cour_wgt)*parseFloat(cour_amt_for_1))+parseFloat(net_sale_amt));
	document.getElementById("to_bil_amt").value		= Math.abs((parseFloat(cour_wgt)*parseFloat(cour_amt_for_1))+parseFloat(net_sale_amt)).toFixed(2);	
}

function reload_po_lst()
{
	var chkcnt = document.getElementById('cnt_typ').value;
	for(i=1;i<chkcnt; i++)
	{
		if(document.getElementById('biltype'+i).checked == true){ 	var biltype = document.getElementById('biltype'+i).value; }
	}
	
	var party_id = document.getElementById('co_cod').value;
	
	window.location = 'billing_add.php?biltype_id='+ biltype + '&party_id=' + party_id ;
}

function reload_page() //this is for reloadin the page when selecting the comapny code
{
		var chk = document.getElementsByName('category[]');
    var len = chk.length;
	//alert(len);
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			flag++;			
		}
		else
		{
			flag=0;
		}
	}
	else
	{
	for (var i = 0; i < len; i++)
	{
		if(document.checklist["category[]"][i].checked)
		{
			flag ++;			
		}
	}
	}
	if (flag <1)
	{
		alert ("Please Select the items");
		return false;
	}
	
	
	var chkcnt = document.getElementById('cnt_typ').value;
	for(i=1;i<chkcnt; i++)
	{
		if(document.getElementById('biltype'+i).checked == true){ 	var biltype = document.getElementById('biltype'+i).value; }
	}
	
	var party_id = document.getElementById('co_cod').value;
	
	var po_id = new Array();
	var chk = document.getElementsByName('category[]');
    var len = chk.length;
	//alert(len);
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			po_id[1] = document.getElementById('category1').value;
		}
		
	}
	else
	{
	for (var i = 0; i< len; i++)
	{
		
		if(document.checklist["category[]"][i].checked)
		{
			j=i+1;
			po_id[i] = document.getElementById('category'+j).value;
			//alert(i);alert(po_id[i])
		}
	}
	}	
	po_id=po_id.toString();
	
	window.location = 'billing_add.php?biltype_id='+ biltype + '&party_id=' + party_id + '&po_id=' + po_id;
}
function clr_fm()
{
	window.location = 'billing_add.php';
}
function form_rest() //this is for reset the forms
{
	var where_to= confirm("Do you really want to Reset the Data?");
	if (where_to== true)
	{
		window.location.reload();
	}
	else
	{
	 	return false;	
	}
}

function hid_bils(ids) // hide bill part when changing the bill type
{
	if(ids==2)
	{
		document.getElementById("non_tx_bill").style.display='none';
		document.getElementById("but_area").style.display='none';
	}
	else if(ids==1)
	{
		document.getElementById("tx_bill").style.display='none';
		document.getElementById("but_area").style.display='none';
	}
}

function hid_bils_1(ids) // hide bill part when changing the bill type
{
	if(ids==1)
	{
		document.getElementById("non_tx_bill").style.display='none';
		document.getElementById("but_area").style.display='none';
	}
	else if(ids==2)
	{
		document.getElementById("tx_bill").style.display='none';
		document.getElementById("but_area").style.display='none';
	}
}
function tot_bill(amt) //this is for calculating the bill amount when enter the advance
{
	var letters=/^\d+(?:\.\d+)?$/;
	if(letters.test(amt))
	{
		var bill_amt = document.getElementById('to_bil_amt').value
		var tot_amt = parseInt(bill_amt) - parseInt(amt); 
		var amount_fn = formatDollar(tot_amt);
		document.getElementById('tot_bil_span').innerHTML = amount_fn;
		document.getElementById('to_bil_amt_st').value = tot_amt;
	}
	else
	{
		var bill_amt = document.getElementById('to_bil_amt').value;
		var amount_fn = formatDollar(bill_amt);
		document.getElementById('tot_bil_span').innerHTML = amount_fn;
		document.getElementById('to_bil_amt_st').value = bill_amt;
	}
}

function formatDollar(num) {
    var p = num.toFixed(2).split(".");
    return p[0].split("").reverse().reduce(function(acc, num, i, orig) {
        return  num + (i && !(i % 3) ? "," : "") + acc;
    }, "") + "." + p[1];
}

function bil_tx(tax_p) //this is for calculating the tax amount when enter the tax percentage
{
	if(document.getElementById('cour_amt').value!='')
	{
		var cr_amt = document.getElementById('cour_amt').value;
	}
	else
	{
		var cr_amt = 0.00;
	}
	var letters=/^\d+(?:\.\d+)?$/;
	if(letters.test(tax_p))
	{
		var bil_amt = document.getElementById('bil_amt').value;
		var tax_tmp = parseFloat(tax_p) *parseFloat(bil_amt);
		var tax_amt = tax_tmp / 100;
		var amount_fn = formatDollar(tax_amt);
	
		document.getElementById('tax_cl').innerHTML = amount_fn;
		document.getElementById('fin_tax_amt').value = tax_amt;
		var tot_bl_amt = parseFloat(tax_amt) + parseFloat(bil_amt)
		var tot_bl = parseFloat(tax_amt) + parseFloat(bil_amt) + parseFloat(cr_amt);
		var tot_bl_for = formatDollar(tot_bl);
		document.getElementById('bl_amt_wo_cur').value = tot_bl_amt;
		document.getElementById('tot_bl_amt').innerHTML = tot_bl_for;
		var splt = amount_fn.split(".");
		if(splt[1]<50)
		{
			
			document.getElementById('rnd_amt').innerHTML = "(-)0."+splt[1];
			document.getElementById('round_amt').value = "(-)0."+splt[1];
		}
		if(splt[1]>=50)
		{
			var cals = parseFloat(1)-parseFloat("0."+splt[1]);
			document.getElementById('rnd_amt').innerHTML = "(+)"+parseFloat(cals).toFixed(2);
			document.getElementById('round_amt').value = "(+)"+parseFloat(cals).toFixed(2);
		}
		document.getElementById('to_bil_amt').value = Math.round(tot_bl);
		$("#num_word_ntx").load("ajax/billing_AJAX.php?pg_id=1&key_word="+Math.round(tot_bl),function(response)
		{});
	}
	else
	{
		document.getElementById('tax_cl').innerHTML = "0.00";
		var bil_amt = document.getElementById('bil_amt').value;
		bil_amt = parseFloat(bil_amt)+ parseFloat(cr_amt);
		var tot_bl_for = formatDollar(bil_amt);
		document.getElementById('tot_bl_amt').innerHTML = tot_bl_for;
		document.getElementById('bl_amt_wo_cur').value = parseFloat(bil_amt);
		document.getElementById('to_bil_amt').value = bil_amt;
		$("#num_word_ntx").load("ajax/billing_AJAX.php?pg_id=1&key_word="+bil_amt,function(response)
		{});
	}
}


function checkTheBox(ids)
{
	
	if(ids==1)
	{
		//bill_dt,advn_dt,advn_amt
		var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(document.getElementById('bill_dt').value=='')
		{
			alert('Please Enter Bill Date');  
			document.getElementById('bill_dt').focus();  
			return false; 
		}
		else if(letters.test(document.getElementById('bill_dt').value)==false)  
		{
			alert('Bill Date must be in the given Format');  
			document.getElementById('bill_dt').focus();  
			return false;  
		}
		
		var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(document.getElementById('advn_dt').value!='')
		{
			
			if(letters.test(document.getElementById('advn_dt').value)==false)  
			{
				alert('Bill Date must be in the given Format');  
				document.getElementById('advn_dt').focus();  
				return false;  
			}
			
			var letters=/^\d+(?:\.\d+)?$/;
			if(document.getElementById('advn_amt').value=='')
			{
				alert('Please Enter the Advance Amount');  
				document.getElementById('advn_amt').focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('advn_amt').value)==false)  
			{
				alert('Advance Amount Should have only Digits');  
				document.getElementById('advn_amt').focus();  
				return false;  
			}
		}
		
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('advn_amt').value!='')
		{
			if(letters.test(document.getElementById('advn_amt').value)==false)  
			{
				alert('Advance Amount Should have only Digits');  
				document.getElementById('advn_amt').focus();  
				return false;  
			}
			var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
			if(document.getElementById('advn_dt').value=='')
			{
				alert('Please Enter Advance Date');  
				document.getElementById('advn_dt').focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('advn_dt').value)==false)  
			{
				alert('Advance Date must be in the given Format');  
				document.getElementById('advn_dt').focus();  
				return false;  
			}
			
		}
	}
	else if(ids==2)
	{
		//bil_no,bill_dt,tax_p
		var letters= /([^\s])/;
		if(document.getElementById('bil_no').value=='')
		{
			alert('Please Enter Bill No');  
			document.getElementById('bil_no').focus();  
			return false; 
		}
		else if(letters.test(document.getElementById('bil_no').value)==false)  
		{
			alert('Bill No should not be empty');  
			document.getElementById('bil_no').focus();  
			return false;  
		}
		
		var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(document.getElementById('bill_dt').value=='')
		{
			alert('Please Enter Bill Date');  
			document.getElementById('bill_dt').focus();  
			return false; 
		}
		else if(letters.test(document.getElementById('bill_dt').value)==false)  
		{
			alert('Bill Date must be in the given Format');  
			document.getElementById('bill_dt').focus();  
			return false;  
		}
			
		
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('tax_p').value=='')
		{
			alert('Please Enter the Tax Percentage');  
			document.getElementById('tax_p').focus();  
			return false;  
		}
//		else if(letters.test(document.getElementById('tax_p').value)==false)  
//		{
//			alert('Tax Percentage Should have only Digits');  
//			document.getElementById('tax_p').focus();  
//			return false;  
//		}
		if(document.getElementById('cour_wgt').value=='')
		{
			alert('Please Enter Courier Weight');  
			document.getElementById('cour_wgt').focus();  
			return false;  
		}
		else if(document.getElementById('cour_wgt').value!='')
		{
			if(letters.test(document.getElementById('cour_wgt').value)==false)  
			{
				alert('Courier weight Should have only Digits');  
				document.getElementById('cour_wgt').focus();  
				return false;  
			}
		}
		
		if(document.getElementById('cour_amt_for_1').value=='')
		{
			alert('Please Enter Courier Amt/Kg');  
			document.getElementById('cour_amt_for_1').focus();  
			return false;  
		}
		else if(document.getElementById('cour_amt_for_1').value!='')
		{
			if(letters.test(document.getElementById('cour_amt_for_1').value)==false)  
			{
				alert('cour_amt Should have only Digits');  
				document.getElementById('cour_amt_for_1').focus();  
				return false;  
			}
		}
				
			
		
	}
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.checklist.submit();
	}
	else
	{
		return false;	
	}		
	
	
}