function calculateFull(str)
{  
	var $qty=$(str).closest('tr').find('td:eq(6)').find('input[type="text"]').val();
	var $rate=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $amt1=$rate*$qty;
	$amt=$amt1.toFixed(2);
	var $confac=$(str).closest('tr').find('td:eq(7)').find('input').val();
	if($confac=='') $confac=0;
	if($qty=='') $qty=0;
	var $secqty=$qty*$confac;
	var $sec_qty=$secqty.toFixed(4);
	//alert($sec_qty);
	$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val($sec_qty);
	$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($amt);	
	var $discount_val=$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(13)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
	
		if($discount_val>$amt1)
		{
			alert("Discount can not be greater then Amount");
			var $discounted_amt=$amt;
			var $discount_val=0;
			$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val(0);

		}else{
			var $discounted_amt=$amt-$discount_val;
		}
		
		$(str).closest('tr').find('td:eq(15)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($discounted_amt);
	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);
		if($discount_amt>$amt1)
		{
			alert("Discount can not be greater then Amount");
			$discounted_amt=$amt;
			$discount_amt=0;
			$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val(0);
		}else{
			var $discounted_amt=$amt-$discount_amt;
			$discounted_amt=$discounted_amt.toFixed(2);
			$discount_amt=$discount_amt.toFixed(2);
		}	
		
		$(str).closest('tr').find('td:eq(15)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($discounted_amt);		
	}
	var $tot_basic=0;
	$('.total_item_amount').each(function(){
		if($(this).val()!=''){
		$tot_basic+=parseFloat($(this).val());
		}
	})
	$tot_basic=$tot_basic.toFixed(2);
	$('input[name="basic_amt"]').val($tot_basic);
	//alert($tot_basic);
	cal_po_charges('')
}


function cal_po_charges(str)
{
	//var $basic=10000;
	var $basic=$('input[name="basic_amt"]').val();

	//alert($basic);
	if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	}

	
	if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#discnted_amt').val());
	}

	 //alert(str.id1);
if(str.id!=undefined)
{
	
	if(str.id=='discount_percent')
	{

		var $discount_amt=parseFloat(parseFloat($basic*(str.value))/100);
		$discount_amt=$discount_amt.toFixed(2);
		if(parseFloat($discount_amt)>parseFloat($basic))
		{
			alert("Discount can not be greater then Basic Amount");
			$("#"+str.id).val(0);
			var $discount_amt=0;
		}
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		//alert($discounted_amt);
		$('#discnted_amt').val($discounted_amt);
		$('#discount_amt').val($discount_amt);
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{

			$('#total_amt').val($discounted_amt);
		}
		else
		{
		
			//alert("dfdsf");
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
		
	}
	else if(str.id=='discount_amt')
	{

			
		if(str.value!=''){
		var $discount_amt=parseFloat(str.value);
		//alert($discount_amt);
		//alert($basic);
		if(parseFloat($basic)< parseFloat($discount_amt))
		{
			alert("Discount can not be greater then Basic Amount");
			$("#"+str.id).val(0);
			var $discount_amt=0;
		}
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($discounted_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
		}
	}
	

}
else
{


	if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	}
	else
	{
		var $discount_amt=parseFloat($('#discount_amt').val());
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		//alert("manoj");
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($discounted_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
	}
	}

//if($('#discnted_amt').val()=='' ){
//$('#discnted_amt').val($basic)
//}

var $distd_amt=$('#discnted_amt').val();

if(str.id!=undefined)
{
	if(str.id=='pkg_perc')
	{
		//alert($distd_amt)
		var $packging_amt=parseFloat(parseFloat($distd_amt*(str.value))/100).toFixed(2);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		var $pack_amt=parseFloat($distd_amt)+parseFloat($packging_amt);
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
		$('#pkg_charges').val(parseFloat($packging_amt).toFixed(2));
		
	}
	else if(str.id=='pkg_charges')
	{
		if(str.value=='')
			{ str.value=0; }

		var $packging_amt=parseFloat(str.value);
		var $pack_amt=parseFloat($distd_amt)+$packging_amt;
		//$pack_amt=parseFloat($pack_amt);
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
		var $pack_per=parseFloat(parseFloat($packging_amt*100)/$distd_amt).toFixed(2);
		//$pack_per=$pack_per.toFixed(2);
		$('#pkg_perc').val($pack_per);
	}
}
else
{

if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#discnted_amt').val());
	}
	else
	{
		var $packging_amt=parseFloat($('#pkg_charges').val());
		var $pack_amt=parseFloat($distd_amt)+$packging_amt;
		//$pack_amt=parseFloat($pack_amt);
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
	}

}
if($('#insurance_non_taxable').val()!='')
{
	if($('#pkg_charges').val()!='')
	{
	$('#total_amt').val((parseFloat($('#discnted_amt').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#insurance_non_taxable').val())).toFixed(2));
	}
	else
	{
		$('#total_amt').val((parseFloat($('#discnted_amt').val())+parseFloat($('#insurance_non_taxable').val())).toFixed(2));
	}
}
else
{
	if($('#pkg_charges').val()!='')
	{
	$('#total_amt').val((parseFloat($('#discnted_amt').val())+parseFloat($('#pkg_charges').val())).toFixed(2));
	}
	else
	{
			$('#total_amt').val((parseFloat($('#discnted_amt').val())).toFixed(2));
	}
}


	if($('#total_amt').val()=='')
	{

		$('#total_amt').val($basic)
	}
	var $tot_amt=$('#total_amt').val();
	if($('#excise').val()=='')
	{
		$('#excise_amt').val('0');
		$('#shecess_amt').val('0');
		$('#ecess_amt').val('0');
	}
	else{
	var $excise=$('#excise').val().split('**');
	var $excise_per=$excise[1];
	var $excise_amt=parseFloat(parseFloat($tot_amt*$excise_per)/100).toFixed(2);
	$('#excise_amt').val($excise_amt);
     if($('#ecess').val()!='' && $('#ecess').val()!='0')
     {
	var $ecess=$('#ecess').val().split('**');
	var $ecess_per=$ecess[1];
	var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100).toFixed(2);
	$('#ecess_amt').val($ecess_amt);
	}
	else
	$('#ecess_amt').val(0);	

     if($('#shecess').val()!='' && $('#shecess').val()!='0')
     {

		var $shecess=$('#shecess').val().split('**');
		var $shecess_per=$shecess[1];	
		var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100).toFixed(2);
		$('#shecess_amt').val($shecess_amt);
    }
    else
    {
      $('#shecess_amt').val(0);	
    }
	}
	var $tot_tax_amt=parseFloat($('#total_amt').val())+parseFloat($('#excise_amt').val())+parseFloat($('#ecess_amt').val())+parseFloat($('#shecess_amt').val())
	$tot_tax_amt=$tot_tax_amt.toFixed(2);
	$('#tot_tax_amt').val($tot_tax_amt);

	if($('#vat_cst').val()=='')
	{
	$('#vat_amt').val('0');
	$('#sur_amt').val('0');
	}
	else
	{
	var $vat_split=$('#vat_cst').val().split('**');
	var $vat_per=$vat_split[1];
	var $sur_per=$vat_split[2];
	$('#sur_per').val($sur_per);
	//alert($sur_per)
	//alert($vat_per)
	var $tot_tax_amt1=$('#tot_tax_amt').val();
	var $vat_amt=parseFloat(parseFloat($vat_per*$tot_tax_amt1)/100);
		$vat_amt=$vat_amt.toFixed(2);
		$('#vat_amt').val($vat_amt);
	var $sur_amt=parseFloat(parseFloat($sur_per*$vat_amt)/100);
		$sur_amt=$sur_amt.toFixed(2);
		$('#sur_amt').val($sur_amt);
	}
	if($('#entry_amt').val()=='')
	{
		$('#entry_amt').val('0');
	}
	if($('#insr_amt').val()=='')
	{
		$('#insr_amt').val('0');	
	}
	if($('#freight_amt').val()=='')
	{
		$('#freight_amt').val('0');
	}
	if($('#other_amt').val()=='')
	{
		$('#other_amt').val('0');
	}
	var $total_po_amt=parseFloat($('#tot_tax_amt').val())+parseFloat($('#entry_amt').val())+parseFloat($('#insr_amt').val())+parseFloat($('#freight_amt').val())+parseFloat($('#sur_amt').val())+parseFloat($('#vat_amt').val())+parseFloat($('#other_amt').val());
	$total_po_amt=$total_po_amt.toFixed(2);
	$('#total_po_amt').val($total_po_amt);
	var $round_split=$total_po_amt.split('.');
	//alert($round_split[1])
	if($round_split[1]>=50)
	 {
    	var $finalAmt=parseInt($round_split[0])+1;
    	$('#pluMin').val('+'); 
    	var $round_val=$finalAmt-$total_po_amt;

    	$round_val=$round_val.toFixed(2);
		$('#roundVal').val($round_val);
		$('#GrandTotal').val($finalAmt);	
     }
    else if($round_split[1]<50 && $round_split[1]!=00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
   // alert($finalAmt);
    $('#pluMin').val('-');
    
    var $round_val=$total_po_amt-$finalAmt;
    $round_val=$round_val.toFixed(2);
    $('#roundVal').val($round_val);
    $('#GrandTotal').val($finalAmt);
    }
    else if($round_split[1]==00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
    $('#pluMin').val('No round off');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }

}

// international vendors

function calculateFull_import(str)
{  
	var $qty=$(str).closest('tr').find('td:eq(6)').find('input[type="text"]').val();
	var $rate=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $amt1=$rate*$qty;
	$amt=$amt1.toFixed(2);
	var $confac=$(str).closest('tr').find('td:eq(7)').find('input').val();
	if($confac=='') $confac=0;
	if($qty=='') $qty=0;
	var $secqty=$qty*$confac;
	var $sec_qty=$secqty.toFixed(4);
	//alert($sec_qty);
	$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val($sec_qty);
	$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($amt);	
	var $discount_val=$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(13)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
	
		if($discount_val>$amt1)
		{
			alert("Discount can not be greater then Amount");
			var $discounted_amt=$amt;
			var $discount_val=0;
			$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val(0);

		}else{
			var $discounted_amt=$amt-$discount_val;
		}
		
		$(str).closest('tr').find('td:eq(15)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($discounted_amt);
	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);
		if($discount_amt>$amt1)
		{
			alert("Discount can not be greater then Amount");
			$discounted_amt=$amt;
			$discount_amt=0;
			$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val(0);
		}else{
			var $discounted_amt=$amt-$discount_amt;
			$discounted_amt=$discounted_amt.toFixed(2);
			$discount_amt=$discount_amt.toFixed(2);
		}	
		
		$(str).closest('tr').find('td:eq(15)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($discounted_amt);		
	}
	var $tot_basic=0;
	$('.total_item_amount').each(function(){
		if($(this).val()!=''){
		$tot_basic+=parseFloat($(this).val());
		}
	})
	$tot_basic=$tot_basic.toFixed(2);
	$('input[name="basic_amt"]').val($tot_basic);
	//alert($tot_basic);
	cal_po_charges_import('')
}

function cal_po_charges_import(str)
{

	var $basic=$('input[name="basic_amt"]').val();
	if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	$('#total_po_amt').val($basic);
	}
	

if(str.id!=undefined){
	if(str.id=='discount_percent')
	{
		var $discount_amt=parseFloat(parseFloat($basic*(str.value))/100);
		$discount_amt=$discount_amt.toFixed(2);
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		$('#discount_amt').val($discount_amt);
		$('#total_po_amt').val($discounted_amt);
		
	}
	else if(str.id=='discount_amt')
	{
		if(str.value=='')
			{ str.value=0; }
		var $discount_amt=parseFloat(str.value);
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		$('#total_po_amt').val($discounted_amt);
	}
}
else
{
if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	$('#total_po_amt').val($basic);
	}
	else
	{
		var $discount_amt=parseFloat($('#discount_amt').val());
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		$('#total_po_amt').val($discounted_amt);
	}
}

var $total_po_amt=$('#total_po_amt').val();
	var $round_split=$total_po_amt.split('.');
	//alert($round_split[1])
	if($round_split[1]>=50)
	 {
    	var $finalAmt=parseInt($round_split[0])+1;
    	$('#pluMin').val('+'); 
    	var $round_val=$finalAmt-$total_po_amt;

    	$round_val=$round_val.toFixed(2);
		$('#roundVal').val($round_val);
		$('#GrandTotal').val($finalAmt);	
     }
    else if($round_split[1]<50 && $round_split[1]!=00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
   // alert($finalAmt);
    $('#pluMin').val('-');
    
    var $round_val=$total_po_amt-$finalAmt;
    $round_val=$round_val.toFixed(2);
    $('#roundVal').val($round_val);
    $('#GrandTotal').val($finalAmt);
    }
    else if($round_split[1]==00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
    $('#pluMin').val('No round off');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }


}

// only for purchase bill book //

function cal_po_charges_billbook(str)
{
	//var $basic=10000;
	var $basic=$('input[name="basic_amt"]').val();
	//alert($basic);
	if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	}

	
	if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#discnted_amt').val());
	}
	 
if(str.id!=undefined)
{
	if(str.id=='discount_percent')
	{
		var $discount_amt=parseFloat(parseFloat($basic*(str.value))/100);
		$discount_amt=$discount_amt.toFixed(2);
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		$('#discount_amt').val($discount_amt);
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($discounted_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
		
}
else if(str.id=='discount_amt')
	{
			
		if(str.value!=''){
		var $discount_amt=parseFloat(str.value);
		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($discounted_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
		}
	}
}
else
{

	if($('#discount_percent').val()=='' && $('#discount_amt').val()=='')
	{
	$('#discnted_amt').val($basic);
	}
	else
	{
		var $discount_per=$('#discount_percent').val();
		var $discount_amt=parseFloat(parseFloat($basic*($discount_per))/100);

		var $discounted_amt=$basic-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$('#discnted_amt').val($discounted_amt);
		$('#discount_amt').val(parseFloat($discount_amt).toFixed(2));
		//alert("ddd");
		//var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		//$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($discounted_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($('#pkg_charges').val())+parseFloat($('#discnted_amt').val()));
		}
	}
	}

//if($('#discnted_amt').val()=='' ){
//$('#discnted_amt').val($basic)
//}

var $distd_amt=$('#discnted_amt').val();
if(str.id!=undefined){
	if(str.id=='pkg_perc')
	{
		//alert($distd_amt)
		var $packging_amt=parseFloat(parseFloat($distd_amt*(str.value))/100);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		var $pack_amt=parseFloat($distd_amt)+parseFloat($packging_amt);
	//	$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
		$('#pkg_charges').val(parseFloat($packging_amt).toFixed(2));
		
	}
	else if(str.id=='pkg_charges')
	{
		if(str.value=='')
			{ str.value=0; }

		var $packging_amt=parseFloat(str.value);
		var $pack_amt=parseFloat($distd_amt)+$packging_amt;
		//$pack_amt=parseFloat($pack_amt);
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
		var $pack_per=parseFloat(parseFloat($packging_amt*100)/$distd_amt).toFixed(2);
		//$pack_per=$pack_per.toFixed(2);
		$('#pkg_perc').val($pack_per);
	}
}
else
{

if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#discnted_amt').val());
	}
	else
	{
		var $pack_per=$('#pkg_perc').val();
		var $packging_amt=parseFloat(parseFloat($distd_amt*($pack_per))/100);
		//var $packging_amt=parseFloat($('#pkg_charges').val());
		var $pack_amt=parseFloat($distd_amt)+$packging_amt;
		//$pack_amt=parseFloat($pack_amt);
		$('#pkg_charges').val(parseFloat($packging_amt).toFixed(2));
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
	}

}
if($('#insurance_non_taxable').val()!='')
{
	if($('#pkg_charges').val()!='')
	{
	$('#total_amt').val(parseFloat($('#discnted_amt').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#insurance_non_taxable').val()));
	}
	else
	{
		$('#total_amt').val(parseFloat($('#discnted_amt').val())+parseFloat($('#insurance_non_taxable').val()));
	}
}
else
{
	if($('#pkg_charges').val()!='')
	{
	$('#total_amt').val(parseFloat($('#discnted_amt').val())+parseFloat($('#pkg_charges').val()));
	}
	else
	{
			$('#total_amt').val(parseFloat($('#discnted_amt').val()));
	}
}


	if($('#total_amt').val()=='')
	{
		$('#total_amt').val($basic)
	}
	var $tot_amt=$('#total_amt').val();
	if($('#excise').val()=='')
	{
		$('#excise_amt').val('0');
		$('#shecess_amt').val('0');
		$('#ecess_amt').val('0');
	}
	else{
	var $excise=$('#excise').val().split('**');
	var $excise_per=$excise[1];
	var $excise_amt=parseFloat(parseFloat($tot_amt*$excise_per)/100);
	$('#excise_amt').val($excise_amt);
    if($('#ecess').val()!='' && $('#ecess').val()!='0'){
	var $ecess=$('#ecess').val().split('**');
	var $ecess_per=$ecess[1];
	var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100).toFixed(2);
	$('#ecess_amt').val($ecess_amt);
    }
    else
    {
    $('#ecess_amt').val(0);	
    }
	if($('#shecess').val()!='' && $('#shecess').val()!='0')
	{
	var $shecess=$('#shecess').val().split('**');
	var $shecess_per=$shecess[1];
	var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100).toFixed(2);
	$('#shecess_amt').val($shecess_amt);
    }
    else
    {
    $('#shecess_amt').val(0);	
    }
	}
	var $tot_tax_amt=parseFloat($('#total_amt').val())+parseFloat($('#excise_amt').val())+parseFloat($('#ecess_amt').val())+parseFloat($('#shecess_amt').val())
	$tot_tax_amt=$tot_tax_amt.toFixed(2);
	$('#tot_tax_amt').val($tot_tax_amt);

	if($('#vat_cst').val()=='')
	{
	$('#vat_amt').val('0');
	$('#sur_amt').val('0');
	}
	else
	{
	var $vat_split=$('#vat_cst').val().split('**');
	var $vat_per=$vat_split[1];
	var $sur_per=$vat_split[2];
	$('#sur_per').val($sur_per);
	//alert($sur_per)
	//alert($vat_per)
	var $tot_tax_amt1=$('#tot_tax_amt').val();
	var $vat_amt=parseFloat(parseFloat($vat_per*$tot_tax_amt1)/100);
		$vat_amt=$vat_amt.toFixed(2);
		$('#vat_amt').val($vat_amt);
	var $sur_amt=parseFloat(parseFloat($sur_per*$vat_amt)/100);
		$sur_amt=$sur_amt.toFixed(2);
		$('#sur_amt').val($sur_amt);
	}
	if($('#entry_amt').val()=='')
	{
		$('#entry_amt').val('0');
	}
	if($('#insr_amt').val()=='')
	{
		$('#insr_amt').val('0');	
	}
	if($('#freight_amt').val()=='')
	{
		$('#freight_amt').val('0');
	}
	if($('#other_amt').val()=='')
	{
		$('#other_amt').val('0');
	}
	var $total_po_amt=parseFloat($('#tot_tax_amt').val())+parseFloat($('#entry_amt').val())+parseFloat($('#insr_amt').val())+parseFloat($('#freight_amt').val())+parseFloat($('#sur_amt').val())+parseFloat($('#vat_amt').val())+parseFloat($('#other_amt').val());
	$total_po_amt=$total_po_amt.toFixed(2);
	$('#total_po_amt').val($total_po_amt);
	var $round_split=$total_po_amt.split('.');
	//alert($round_split[1])
	if($round_split[1]>=50)
	 {
    	var $finalAmt=parseInt($round_split[0])+1;
    	$('#pluMin').val('+'); 
    	var $round_val=$finalAmt-$total_po_amt;

    	$round_val=$round_val.toFixed(2);
		$('#roundVal').val($round_val);
		$('#GrandTotal').val($finalAmt);	
     }
    else if($round_split[1]<50 && $round_split[1]!=00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
   // alert($finalAmt);
    $('#pluMin').val('-');
    
    var $round_val=$total_po_amt-$finalAmt;
    $round_val=$round_val.toFixed(2);
    $('#roundVal').val($round_val);
    $('#GrandTotal').val($finalAmt);
    }
    else if($round_split[1]==00)
    {
    	
    var $finalAmt=parseInt($round_split[0]);
    $('#pluMin').val('No round off');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }

}


/****************************  Purchase bill *******************************/

 function calculateAgainst2(str)
 {
 	var totAmount2 = 0;
	var count =document.getElementById("count").value;
	if(str=='bill')
	{
		var totalAmt =0;
		for(var h=0; h<count;h++)
		{
				if(billQty==''){billQty=0;}
				if(itemRate==''){itemRate=0;}
				var billQty=document.getElementById("qty_as_per_bill_"+h).value;
				var itemRate=document.getElementById("itemrate_"+h).value;
				var amtVal=parseFloat(billQty)*parseFloat(itemRate);
				document.getElementById("itemamount_"+h).value = amtVal;
				var discount = document.getElementById("Discount1_"+h).value;
				if(discount==''){discount=0;}
				var discount_type = document.getElementById("PerAmo_"+h).value;
				var totAmount = 0;
				if(discount_type=='Amount')
				{
				var basicAmt = parseFloat(amtVal)-parseFloat(discount);
				document.getElementById("NetRate1_"+h).value = basicAmt.toFixed(2);
				var convRate = document.getElementById("conv_rate_"+h).value;
					if(convRate!='')
					{
					var convAmt = parseFloat(basicAmt)*parseFloat(convRate);
					document.getElementById("basic_"+h).value = convAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(convAmt);
					}
					else
					{
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(basicAmt);
					}
				}
				else 
				{
				var midRes= (discount*amtVal)/100;
				var basicAmt = parseFloat(amtVal)-parseFloat(midRes);
				document.getElementById("NetRate1_"+h).value = basicAmt;
					var convRate = document.getElementById("conv_rate_"+h).value;
					if(convRate!='')
					{
					var convAmt = parseFloat(basicAmt)*parseFloat(convRate);
					document.getElementById("basic_"+h).value = convAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(convAmt);
					}
					else
					{
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(basicAmt);
					}
				}
			}
			document.getElementById("total_item_amount").value = totalAmt.toFixed(2);
		if(totalAmt==''){totalAmt=0;}
		}
			else
			{
				var totalAmt =0;
				for(var h=0; h<count;h++)
				{
					var recQty=document.getElementById("reciveqty_"+h).value;
					var itemRate=document.getElementById("itemrate_"+h).value;
					var amtVal=parseFloat(recQty)*parseFloat(itemRate);
					document.getElementById("itemamount_"+h).value = amtVal;
					var discount = document.getElementById("Discount1_"+h).value;
					if(discount==''){discount=0;}
					var discount_type = document.getElementById("PerAmo_"+h).value;
					if(discount_type=='Amount')
					{
					var basicAmt = parseFloat(amtVal)-parseFloat(discount);
					document.getElementById("NetRate1_"+h).value = basicAmt.toFixed(2);
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(basicAmt);
					}
					else 
					{
					var midRes= (discount*amtVal)/100;
					var basicAmt = parseFloat(amtVal)-parseFloat(midRes);
					document.getElementById("NetRate1_"+h).value = basicAmt.toFixed(2);
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totalAmt =  totalAmt+parseFloat(basicAmt);
					}
				}
			
		document.getElementById("total_item_amount").value = totalAmt.toFixed(2);
		if(totalAmt==''){totalAmt=0;}
		
		var biling_type = document.getElementById("hid_billing_type_"+h).value;
		var excisePer = document.getElementById("exciseDuty_"+h).value;
		
		
		
		if(biling_type=='1')
		{
		var totDutyAmt= 0;
		var totAmountCvd = 0;
		var ecestot=0;
		var ecesectot=0;
		var adddutytot=0;
		var basicAmount= document.getElementById("basic_"+h).value;
		
		var dutyPer = document.getElementById("exciseDuty_"+h).value;
		var dutyamt = (parseFloat(dutyPer)*parseFloat(basicAmount))/100;
		document.getElementById("dutyamount_"+h).value = dutyamt.toFixed(2);
		if(dutyamt==''){dutyamt=0;}
		var totDutyAmt = totDutyAmt+parseFloat(dutyamt);
		
		var grand_tot1= parseFloat(basicAmount)+parseFloat(dutyamt); 
		var cvdPer = document.getElementById("cvd_percentage").value;
		var cvd = grand_tot1*(cvdPer/100);
		var grand_tot=cvd.toFixed(2);
	 	document.getElementById("TotalSpecial_"+h).value=grand_tot;
		if(grand_tot==''){grand_tot=0;}
		var totAmountCvd = totAmountCvd+parseFloat(grand_tot);
		
		var c = document.getElementById("TotalSpecial_"+h).value; 
		var tot1= parseFloat(dutyamt)+parseFloat(c);
		var ecessPer = document.getElementById("ecess_percentage").value;
		var tot = tot1*(ecessPer/100);
		var final_eces=tot.toFixed(2);
		document.getElementById("customecess_"+h).value=final_eces;
		if(final_eces==''){final_eces=0;}
		var ecestot = ecestot+parseFloat(final_eces);
		
		var tot1= parseFloat(dutyamt)+parseFloat(c);
		var secEcessPer = document.getElementById("secess_percentage").value; 
		var tot = tot1*(secEcessPer/100);
		var final_eces1=tot.toFixed(2);
		document.getElementById("customsececess_"+h).value=final_eces1;
		if(final_eces1==''){final_eces1=0;}
		var ecesectot = ecesectot+parseFloat(final_eces1);
		
		var d = document.getElementById("customecess_"+h).value; 
		var e = document.getElementById("customsececess_"+h).value; 
		var tot12= parseFloat(basicAmount)+parseFloat(dutyamt)+parseFloat(c)+parseFloat(d)+parseFloat(e);
		var addPer = document.getElementById("add_percentage").value; 
		var tot1 = tot12*(addPer/100);
		var final_eces2=tot1.toFixed(2);
		document.getElementById("adduty_"+h).value=final_eces2;
		if(final_eces2==''){final_eces2=0;}
		var adddutytot = adddutytot+parseFloat(final_eces2);	
		}
		else
		{
			document.getElementById("exciseDuty_"+i).disabled=true;
			document.getElementById("dutyamount_"+i).disabled=true;
			document.getElementById("TotalSpecial_"+i).disabled=true;
			document.getElementById("customecess_"+i).disabled=true;
			document.getElementById("customsececess_"+i).disabled=true;
			document.getElementById("adduty_"+i).disabled=true;
			document.getElementById("exciseDuty_"+i).value='';
			document.getElementById("dutyamount_"+i).value='';
			document.getElementById("TotalSpecial_"+i).value='';
			document.getElementById("customecess_"+i).value='';
			document.getElementById("customsececess_"+i).value='';
			document.getElementById("adduty_"+i).value='';
		}
	}
		document.getElementById("total_item_amount").value = totalAmt.toFixed(2);
		if(totalAmt==''){totalAmt=0;}
		
		document.getElementById("custom_duty").value = totDutyAmt.toFixed(2);
		if(totDutyAmt==''){totDutyAmt=0;}

		document.getElementById("cvd_total").value = totAmountCvd.toFixed(2);
		if(totAmountCvd==''){totAmountCvd=0;}
				
		document.getElementById("custom_ecess").value = ecestot.toFixed(2);
		if(ecestot==''){ecestot=0;}
		 
		document.getElementById("custom_sec_ecess").value = ecesectot.toFixed(2);
		if(ecesectot==''){ecesectot=0;}
		
		document.getElementById("additionalCharges").value = adddutytot.toFixed(2);
		if(adddutytot==''){adddutytot=0;}
		
		var cdis_amt=document.getElementById("pkg_charges").value;
		if(cdis_amt==''){cdis_amt=0;}
		
		var othercharges=document.getElementById("TotalCharge2").value;
		if(othercharges==''){othercharges=0;}
			
		var othercharges1=document.getElementById("loading2").value;
		if(othercharges1==''){othercharges1=0;}
			
		var othercharges2=document.getElementById("misCharge").value;
		if(othercharges2==''){othercharges2=0;}
			
		var othercharges3=document.getElementById("clearing").value;
		if(othercharges3==''){othercharges3=0;}
		
		var othercharges4=document.getElementById("misCharge").value;
		if(othercharges4==''){othercharges4=0;}
			
		var othercharges5=document.getElementById("insurance").value;
		if(othercharges5==''){othercharges5=0;}
	
		var GrandTotalAmt = parseFloat(totalAmt)+parseFloat(totDutyAmt)+parseFloat(totAmountCvd)+parseFloat(ecestot)+parseFloat(ecesectot)+parseFloat(adddutytot)+parseFloat(cdis_amt)+parseFloat(othercharges)+parseFloat(othercharges1)+parseFloat(othercharges2)+parseFloat(othercharges3)+parseFloat(othercharges4)+parseFloat(othercharges5);
		if(GrandTotalAmt==''){GrandTotalAmt=0;}
		document.getElementById("GrandTotal").value = GrandTotalAmt.toFixed(2);
		document.getElementById("orig_grand_tot").value = GrandTotalAmt.toFixed(2);
		 }


 
 function calculateAgainst(str)
 {
	var totAmount=0;
	var count =document.getElementById("count").value;
	if(str=='bill')
	{
		for(var h=0; h<count;h++)
		{
				if(billQty==''){billQty=0;}
				if(itemRate==''){itemRate=0;}
				var billQty=document.getElementById("qty_as_per_bill_"+h).value;
				var itemRate=document.getElementById("itemrate_"+h).value;
				var amtVal=parseFloat(billQty)*parseFloat(itemRate);
				document.getElementById("itemamount_"+h).value = amtVal;
				var discount = document.getElementById("Discount1_"+h).value;
				if(discount==''){discount=0;}
				var discount_type = document.getElementById("PerAmo_"+h).value;
				if(discount_type=='Amount')
				{
				var basicAmt = parseFloat(amtVal)-parseFloat(discount);
				document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
				var totAmount =  totAmount+parseFloat(basicAmt);
				}
				else 
				{
				var midRes= (discount*amtVal)/100;
				var basicAmt = parseFloat(amtVal)-parseFloat(midRes);
				document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
				var totAmount =  totAmount+parseFloat(basicAmt);
				}
			}
			document.getElementById("total_item_amount").value = totAmount.toFixed(2);
			if(totAmount==''){totAmount=0;}
			var conv_amt=document.getElementById("tot_conv_amt").value;
			if(conv_amt==''){conv_amt=0;}
			var cdis_amt=document.getElementById("pkg_charges").value;
			if(cdis_amt==''){cdis_amt=0;}
			var othercharges=document.getElementById("custom_duty_new").value;
			if(othercharges==''){othercharges=0;}
			var othercharges1=document.getElementById("cvd_total_new").value;
			if(othercharges1==''){othercharges1=0;}
			var othercharges2=document.getElementById("custom_ecess_new").value;
			if(othercharges2==''){othercharges2=0;}
			var othercharges3=document.getElementById("custom_sec_ecess_new").value;
			if(othercharges3==''){othercharges3=0;}
			var othercharges4=document.getElementById("add_charges_new").value;
			if(othercharges4==''){othercharges4=0;}
			var othercharges5=document.getElementById("TotalCharge2").value;
			if(othercharges5==''){othercharges5=0;}
			var othercharges6=document.getElementById("insurance").value;
			if(othercharges6==''){othercharges6=0;}
			var othercharges7=document.getElementById("clearing").value;
			if(othercharges7==''){othercharges7=0;}
			var othercharges8=document.getElementById("misCharge").value;
			if(othercharges8==''){othercharges8=0;}
			var othercharges9=document.getElementById("loading2").value;
			if(othercharges9==''){othercharges9=0;}
			var GrandTotalAmt = parseFloat(totAmount)+parseFloat(conv_amt)+parseFloat(cdis_amt)+parseFloat(othercharges)+parseFloat(othercharges1)+parseFloat(othercharges2)+parseFloat(othercharges3)+parseFloat(othercharges4)+parseFloat(othercharges5)+parseFloat(othercharges6)+parseFloat(othercharges7)+parseFloat(othercharges8)+parseFloat(othercharges9);
			if(GrandTotalAmt==''){GrandTotalAmt=0;}
			document.getElementById("GrandTotal").value = GrandTotalAmt.toFixed(2);
			document.getElementById("orig_grand_tot").value = GrandTotalAmt.toFixed(2);
		}
			else
			{
				for(var h=0; h<count;h++)
				{
					var recQty=document.getElementById("reciveqty_"+h).value;
					var itemRate=document.getElementById("itemrate_"+h).value;
					var amtVal=parseFloat(recQty)*parseFloat(itemRate);
					document.getElementById("itemamount_"+h).value = amtVal;
					var discount = document.getElementById("Discount1_"+h).value;
					if(discount==''){discount=0;}
					var discount_type = document.getElementById("PerAmo_"+h).value;
					if(discount_type=='Amount')
					{
					var basicAmt = parseFloat(amtVal)-parseFloat(discount);
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totAmount =  totAmount+parseFloat(basicAmt);
					}
					else 
					{
					var midRes= (discount*amtVal)/100;
					var basicAmt = parseFloat(amtVal)-parseFloat(midRes);
					document.getElementById("basic_"+h).value = basicAmt.toFixed(2);
					var totAmount =  totAmount+parseFloat(basicAmt);
					}
				}
			
				document.getElementById("total_item_amount").value = totAmount.toFixed(2);
			if(totAmount==''){totAmount=0;}
			var conv_amt=document.getElementById("tot_conv_amt").value;
			if(conv_amt==''){conv_amt=0;}
			var cdis_amt=document.getElementById("pkg_charges").value;
			if(cdis_amt==''){cdis_amt=0;}
			var othercharges=document.getElementById("custom_duty_new").value;
			if(othercharges==''){othercharges=0;}
			var othercharges1=document.getElementById("cvd_total_new").value;
			if(othercharges1==''){othercharges1=0;}
			var othercharges2=document.getElementById("custom_ecess_new").value;
			if(othercharges2==''){othercharges2=0;}
			var othercharges3=document.getElementById("custom_sec_ecess_new").value;
			if(othercharges3==''){othercharges3=0;}
			var othercharges4=document.getElementById("add_charges_new").value;
			if(othercharges4==''){othercharges4=0;}
			var othercharges5=document.getElementById("TotalCharge2").value;
			if(othercharges5==''){othercharges5=0;}
			var othercharges6=document.getElementById("insurance").value;
			if(othercharges6==''){othercharges6=0;}
			var othercharges7=document.getElementById("clearing").value;
			if(othercharges7==''){othercharges7=0;}
			var othercharges8=document.getElementById("misCharge").value;
			if(othercharges8==''){othercharges8=0;}
			var othercharges9=document.getElementById("loading2").value;
			if(othercharges9==''){othercharges9=0;}
			var GrandTotalAmt = parseFloat(totAmount)+parseFloat(conv_amt)+parseFloat(cdis_amt)+parseFloat(othercharges)+parseFloat(othercharges1)+parseFloat(othercharges2)+parseFloat(othercharges3)+parseFloat(othercharges4)+parseFloat(othercharges5)+parseFloat(othercharges6)+parseFloat(othercharges7)+parseFloat(othercharges8)+parseFloat(othercharges9);
			if(GrandTotalAmt==''){GrandTotalAmt=0;}
			document.getElementById("GrandTotal").value = GrandTotalAmt.toFixed(2);
			document.getElementById("orig_grand_tot").value= GrandTotalAmt.toFixed(2);
		}
 }

	/****************************************************************************/	 