function calculateFull(str)
{  
	var $discount_val=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(10)').find('select').val();
	var $totalp=$(str).closest('tr').find('td:eq(9)').find('input[type="text"]').val();
	//alert($discount_val);
	if($discount_type=='Amount')
	{
		if($discount_val>$totalp)
		{
			alert("Discount amount cannot greater than total price");
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');
			return false;
		}

	}
	if($discount_type=='PercentAmt')	
	{
		if($discount_val>100)
		{
			alert("Discount % should be less than 100%");
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');
			return false;
		}
	}


	var $qty=$(str).closest('tr').find('td:eq(7)').find('input[type="text"]').val();

	var $rate=$(str).closest('tr').find('td:eq(8)').find('input[type="text"]').val();
	var $amt=$rate*$qty;
	$amt=$amt.toFixed(2);
	$(str).closest('tr').find('td:eq(9)').find('input[type="text"]').val($amt);	
	var $discount_val=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(10)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
		var $discounted_amt=$amt-$discount_val;
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val($discounted_amt);
	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);		
		var $discounted_amt=$amt-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$discount_amt=$discount_amt.toFixed(2);
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(13)').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());
	}
	 
if(str.id!=undefined)
{
	if(str.id=='discount_percent')
	{
		var x= parseFloat($('#discount_percent').val());
		if(x>100 ||x==100)
		{
			alert("dicount shoud be less than 100 % ");
			$('#discount_percent').val('');
			$('#discount_amt').val('');

			return false;
		}


		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($('#discount_amt').val());
			var total_item_amount= parseFloat($('#basic_amt').val());

			
			if(discount_amt>total_item_amount )
			{
				alert("Discount amount should be less than basic amount  ");
				$('#discount_percent').val('');
				$('#discount_amt').val('');
		
		
				return false;
			}


		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_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);
		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($packging_amt);
		
	}
	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);
		$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()));
	}
	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.toFixed(2));

	if($('#ecess').val()=='')
	{
		$('#ecess_amt').val(0);
	}
	else
	{
		if($('#ecess').val()!=''){
		var $ecess=$('#ecess').val().split('**');
		var $ecess_per=$ecess[1];
	    }
	    else
	    {
	    $ecess_per=0;	
	    }
		if($ecess_per=='') $ecess_per=0;
		var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100);
		if($ecess_amt=='') $ecess_amt=0;
		$('#ecess_amt').val($ecess_amt.toFixed(2));	
	}
	if($('#shecess').val()=='')
	{

		$('#shecess_amt').val(0);
	}
	else
	{
		if($('#shecess').val()!=''){
		var $shecess=$('#shecess').val().split('**');
		var $shecess_per=$shecess[1]; }
		else {
			var $shecess_per=0;
		}
		if($shecess_per=='') $shecess_per=0;
		var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100);
		if($shecess_amt=='') $shecess_amt=0;
		$('#shecess_amt').val($shecess_amt.toFixed(2));
	}
	
	
	}
	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('');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }

}

// international vendors

function calculateFull_import(str)
{  
	var $qty=$(str).closest('tr').find('td:eq(7)').find('input[type="text"]').val();
	var $rate=$(str).closest('tr').find('td:eq(8)').find('input[type="text"]').val();
	var $amt=$rate*$qty;
	$amt=$amt.toFixed(2);
	$(str).closest('tr').find('td:eq(9)').find('input[type="text"]').val($amt);	
	var $discount_val=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(10)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
		var $discounted_amt=$amt-$discount_val;
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val($discounted_amt);
	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);		
		var $discounted_amt=$amt-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$discount_amt=$discount_amt.toFixed(2);
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(13)').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 x= parseFloat($('#discount_percent').val());
	if(x>100 ||x==100)
	{
		alert("dicount shoud be less than 100 % ");
		$('#discount_percent').val('');
		return false;

	}


	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('');
    $('#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($discount_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()));
		}
	}
	}

//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($packging_amt);
		
	}
	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);
		//$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($packging_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()));
	}
	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);
	document.getElementById("excise_amt").value = $excise_amt.toFixed(2);
    if($('#ecess').val()!=0){
	var $ecess=$('#ecess').val().split('**');
	var $ecess_per=$ecess[1];
    }
    else
    {
    $ecess_per=0;	
    }
    if($ecess_per=='') $ecess_per=0;
	var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100);
	//$('#ecess_amt').val($ecess_amt);
	document.getElementById("ecess_amt").value= $ecess_amt.toFixed(2);
	 if($('#ecess').val()!=0){
	var $shecess=$('#shecess').val().split('**');
	var $shecess_per=$shecess[1];
    }
    else
    {
    var $shecess_per=0;	
    }
    if($shecess_per=='') $shecess_per=0;
	var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100);
	
	document.getElementById('shecess_amt').value = $shecess_amt.toFixed(2);
	}
	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('');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }

}

function cal_po_charges_billbook_import(str)
{
	//var $basic=10000;
	var $basic=$('input[name="basic_amt"]').val();
	
	if($('#discount_percent').val()=='0' && $('#discount_amt').val()=='0')
	{
	$('#discnted_amt').val($basic);
	}
   
   if($('#curr_per').val()=='')
	{
	$('#conv_amt').val($('#discnted_amt').val());
	}
	
	if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#conv_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($('#curr_per').val()=='')
			{
			$('#conv_amt').val($('$discounted_amt').val());
			var $conv_amt=$discounted_amt;
			}
			else
			{
			$('#conv_amt').val(parseFloat($('#curr_per').val())*parseFloat($('#discnted_amt').val()));
			var $conv_amt=parseFloat($('#curr_per').val())*parseFloat($('#discnted_amt').val());	
			}


		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($conv_amt);
		}
		else
		{
			$('#total_amt').val($conv_amt);
		}
		
	}
	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($('#curr_per').val()=='')
			{
			$('#conv_amt').val($discounted_amt);
					var $conv_amt=$discounted_amt;
			}
		 else
		 {
		 $('#conv_amt').val(parseFloat($('#curr_per').val())+parseFloat($('#discnted_amt').val()));	
		 	var $conv_amt=parseFloat($('#curr_per').val())+parseFloat($('#discnted_amt').val());
		 }	
		if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($conv_amt);
		}
		else
		{
			$('#total_amt').val($conv_amt);
		}
		}
	}
  }
  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($discount_amt);
		//var $discount_per=parseFloat(parseFloat($discount_amt*100)/$basic);
		//$discount_per=$discount_per.toFixed(2);
		$('#discount_percent').val($discount_per);

		 if($('#curr_per').val()=='')
			{
			$('#conv_amt').val($discounted_amt);
					 $conv_amt=$discounted_amt;
			}
		 else
		 {
		 $('#conv_amt').val(parseFloat($('#curr_per').val())+parseFloat($('#discnted_amt').val()));	
		 	var $conv_amt=parseFloat($('#curr_per').val())+parseFloat($('#discnted_amt').val());
		 }	
		 if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
		{
			$('#total_amt').val($conv_amt);
		}
		else
		{
			$('#total_amt').val(parseFloat($conv_amt));
		}
	
	}
	
  }
  var $distd_amt=$('#discnted_amt').val();


if(str.id!=undefined){

	if(str.id=='curr_per')
	{
		//alert($distd_amt)
		var $conv_amt=parseFloat($distd_amt)*parseFloat(str.value);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		//var $pack_amt=parseFloat($distd_amt)+parseFloat($packging_amt);
	//	$pack_amt=$pack_amt.toFixed(2);
		$('#conv_amt').val($conv_amt);
		
		
	}
	
}
else
{

if($('#curr_per').val()=='' )
	{
	$('#conv_amt').val($('#discnted_amt').val());
	}
	else
	{
		var $curr_per=$('#curr_per').val();
		var $conv_amt=parseFloat($distd_amt)*parseFloat($curr_per);
		//var $packging_amt=parseFloat($('#pkg_charges').val());
		//var $pack_amt=parseFloat($distd_amt)+$packging_amt;
		//$pack_amt=parseFloat($pack_amt);
		$('#conv_amt').val($conv_amt);
		
	}

}
var $distd2_amt=$('#conv_amt').val();

if(str.id!=undefined){

	if(str.id=='exchange_per')
	{
		//alert($distd_amt)
		var $exchange_amt1=parseFloat(parseFloat($distd2_amt*(str.value))/100);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		//var $exchange_amt=parseFloat($distd2_amt)+parseFloat($exchange_amt1);
	//	$pack_amt=$pack_amt.toFixed(2);
		$('#exchange_charges').val($exchange_amt1);
		
		
	}
	
}
else
{

if($('#exchange_per').val()=='' )
	{
	$('#exchange_charges').val($('#conv_amt').val());
	}
	else
	{
		var $exchange_per=$('#exchange_per').val();
		var $exchange_per_amt=parseFloat(parseFloat($distd2_amt*($exchange_per))/100);
		//var $packging_amt=parseFloat($('#pkg_charges').val());
		//var $exchange_amt=parseFloat($distd2_amt)+$exchange_per_amt;
		//$pack_amt=parseFloat($pack_amt);
		$('#exchange_charges').val($exchange_per_amt);
		
	}

}
var $distd1_amt=parseFloat($('#conv_amt').val())+parseFloat($('#exchange_charges').val());
if(str.id!=undefined){

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

		var $packging_amt=parseFloat(str.value);
		var $pack_amt=parseFloat($distd1_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);
		//$pack_per=$pack_per.toFixed(2);
		$('#pkg_perc').val($pack_per);
	}
}
else
{

if($('#pkg_perc').val()=='' && $('#pkg_charges').val()=='')
	{
	$('#total_amt').val($('#distd1_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($packging_amt);
		$pack_amt=$pack_amt.toFixed(2);
		$('#total_amt').val($pack_amt);
	}

}

if($('#fright_charges').val()!='')
{
	
	$('#total_amt').val(parseFloat($('#conv_amt').val())+parseFloat($('#exchange_charges').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#insurance_non_taxable').val())+parseFloat($('#fright_charges').val()));
	
}
else
{
	$('#total_amt').val(parseFloat($('#conv_amt').val())+parseFloat($('#exchange_charges').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#insurance_non_taxable').val()));
}
	
	if($('#insurance_non_taxable').val()=='')
	{
		$('#insurance_non_taxable').val('0');
	}

if($('#insurance_non_taxable').val()!='')
{
	$('#total_amt').val(parseFloat($('#conv_amt').val())+parseFloat($('#exchange_charges').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#insurance_non_taxable').val())+parseFloat($('#fright_charges').val()));
}
else
{
	$('#total_amt').val(parseFloat($('#conv_amt').val())+parseFloat($('#exchange_charges').val())+parseFloat($('#pkg_charges').val())+parseFloat($('#fright_charges').val()));
}
var $distd21_amt=parseFloat($('#conv_amt').val())+parseFloat($('#pkg_charges').val())
               +parseFloat($('#fright_charges').val())+parseFloat($('#exchange_charges').val());

if(str.id!=undefined){

	if(str.id=='bcd_per')
	{
		//alert($distd_amt)
		var $bcd_per_amt1=parseFloat(parseFloat($distd21_amt*(str.value))/100);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		//var $bcd_amt=parseFloat($distd21_amt)+parseFloat($bcd_per_amt1);
	//	$pack_amt=$pack_amt.toFixed(2);
		$('#bcd_amt').val($bcd_per_amt1);
		
		
	}
	
}
else
{

if($('#bcd_per').val()=='' )
	{
	$('#bcd_amt').val($('#distd21_amt').val());
	}
	else
	{
		var $bcd_per=$('#exchange_per').val();
		var $bcd_per_amt1=parseFloat(parseFloat($distd21_amt*($bcd_per))/100);
		//var $packging_amt=parseFloat($('#pkg_charges').val());
		//var $bcd_amt=parseFloat($distd21_amt)+$bcd_per_amt1;
		//$pack_amt=parseFloat($pack_amt);
		$('#bcd_amt').val($bcd_per_amt1);
		
	}

}
 if($('#bcd_per').val()=='')
	{
		$('#bcd_amt').val('0');
	}         
var $totalallamt=parseFloat($('#exchange_charges').val())+parseFloat($('#pkg_charges').val())
               +parseFloat($('#fright_charges').val())+parseFloat($('#bcd_amt').val());
	if($('#total_amt').val()=='')
	{
		$tot_amt=$basic;
	}
	 $tot_amt=$totalallamt;
	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);
	document.getElementById("excise_amt").value = $excise_amt.toFixed(2);
    if($('#ecess').val()!=0){
	var $ecess=$('#ecess').val().split('**');
	var $ecess_per=$ecess[1];
    }
    else
    {
    var $ecess_per=0;	
    }
	if($ecess_per=='') $ecess_per=0;
	var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100);
	//$('#ecess_amt').val($ecess_amt);
	if($ecess_amt=='')
		$ecess_amt=0;
	document.getElementById("ecess_amt").value= $ecess_amt.toFixed(2);
	 if($('#shecess').val()!=0){
	var $shecess=$('#shecess').val().split('**');
	var $shecess_per=$shecess[1];
     }
     else
     {
     var $shecess_per=0;	
     }
	if($shecess_per=='') $shecess_per=0;

	var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100);
	if($shecess_amt=='')
		$shecess_amt=0;
	document.getElementById('shecess_amt').value = $shecess_amt.toFixed(2);
	}

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

   if($('#total_amt').val()=='')
	{
		$tot_amt=$basic;
	}
	 $tot_amt=$totalallamt;
	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);
	document.getElementById("excise_amt").value = $excise_amt.toFixed(2);
    if($('#ecess').val()!=0){
	var $ecess=$('#ecess').val().split('**');
	var $ecess_per=$ecess[1];
    }
    else
    {
    var $ecess_per=0;	
    }
	if($ecess_per=='') $ecess_per=0;
	var $ecess_amt=parseFloat(parseFloat($excise_amt*$ecess_per)/100);
	//$('#ecess_amt').val($ecess_amt);
	if($ecess_amt=='') $ecess_amt=0;
	document.getElementById("ecess_amt").value= $ecess_amt.toFixed(2);
	 if($('#shecess').val()!=0){
	var $shecess=$('#shecess').val().split('**');
	var $shecess_per=$shecess[1];}else
	{
		var $shecess_per=0;
	}
	if($shecess_per=='') $shecess_per=0;
	var $shecess_amt=parseFloat(parseFloat($excise_amt*$shecess_per)/100);
	if($shecess_amt=='') $shecess_amt=0;
	document.getElementById('shecess_amt').value = $shecess_amt.toFixed(2);
	}

	var $tot_tax_amt=parseFloat($('#total_amt').val())+parseFloat($('#excise_amt').val())+parseFloat($('#ecess_amt').val())+parseFloat($('#shecess_amt').val())+parseFloat($('#bcd_amt').val())+parseFloat($('#octrio_amt').val())+parseFloat($('#mischarge_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=$('#bcd_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);
	}
	
	 var $distd23_amt=parseFloat($('#vat_amt').val())+parseFloat($('#sur_amt').val())+parseFloat($('#tot_tax_amt').val());
if(str.id!=undefined){

	if(str.id=='adc_per')
	{
		//alert($distd_amt)
		var $adc_per_amt1=parseFloat(parseFloat($distd23_amt*(str.value))/100);
		//$packging_amt=$packging_amt.toFixed(2);
		//alert($packging_amt);
		//var $adc_amt=parseFloat($distd23_amt)+parseFloat($adc_per_amt1);
	//	$pack_amt=$pack_amt.toFixed(2);
		$('#adc_amt').val($adc_per_amt1);
		
		
	}
	
}
else
{

if($('#adc_per').val()=='' )
	{
	$('#adc_amt').val($('#distd23_amt').val());
	}
	else
	{
		var $acd_per=$('#adc_per').val();
		var $acd_per_amt1=parseFloat(parseFloat($distd23_amt*($acd_per))/100);
		//var $packging_amt=parseFloat($('#pkg_charges').val());
		//var $acd_amt=parseFloat($distd23_amt)+$acd_per_amt1;
		//$pack_amt=parseFloat($pack_amt);
		$('#adc_amt').val($acd_per_amt1);
		
	}

}
 if($('#adc_per').val()=='')
	{
		$('#adc_amt').val('0');
	}         
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($('#octrio_amt').val()=='')
	{
		$('#octrio_amt').val('0');
	}
	if($('#mischarge_amt').val()=='')
	{
		$('#mischarge_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($('#adc_amt').val());
	$total_po_amt=$total_po_amt.toFixed(2);
	$('#total_po_amt').val($total_po_amt);
	//alert($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('');
    $('#roundVal').val('0.00');
    $('#GrandTotal').val($finalAmt);
    }
	
}


function calculateFull_itemwise(str)
{  
   
	var $qty=$(str).closest('tr').find('td:eq(6)').find('input[type="text"]').val();
	var $rate=$(str).closest('tr').find('td:eq(8)').find('input[type="text"]').val();
	if($rate=='') $rate=0;
	if($qty=='') $qty=0;
	var $amt=parseFloat($qty)*parseFloat($rate);
	$(str).closest('tr').find('td:eq(9)').find('input[type="text"]').val($amt);
	var $discount_val=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(10)').find('select').val();
	var $totalp=$(str).closest('tr').find('td:eq(9)').find('input[type="text"]').val();
	//alert($rate);
	//alert($discount_val);
	//alert($totalp);
	//alert($discount_type);
	if($discount_type=='Amount')
	{
		if($discount_val>$amt)
		{
			alert("Discount amount cannot greater than total price");
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');
			$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val('');	
			$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val('');
		    $(str).closest('tr').find('td:eq(20)').find('input[type="text"]').val('');	
		    basic_calculation();		
			return false;
		}

	}
	if($discount_type=='PercentAmt')	
	{
		if($discount_val>100)
		{
			alert("Discount % should be less than 100%");
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');
			//$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val('');
			$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val('');	
			$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val('');
		    $(str).closest('tr').find('td:eq(20)').find('input[type="text"]').val('');	
		    basic_calculation();
			return false;
		}
	}
   	
	var $discount_val=$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(10)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
		var $discounted_amt=$amt-$discount_val;
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val($discounted_amt);		

	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);		
		var $discounted_amt=$amt-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$discount_amt=$discount_amt.toFixed(2);
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val($discounted_amt);	
	
	}
	
	//alert($tot_basic);
	/*cal_po_charges('')*/
	//$exciseflag=$(str).closest('tr').find('td:eq(12)'.find('select').val();
	//	alert($exciseflag);

  /*  var $exciseflag=$(str).closest('tr').find('td:eq(14)').find('select').val();
  
   if($exciseflag=='' || $exciseflag=='NonExcisable')
   {
   	$(str).closest('tr').find('td:eq(15)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').attr('disabled', true);   	
   	$(str).closest('tr').find('td:eq(17)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(19)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').attr('disabled', true); 
   	$totalexiseamt=0;
   }
   else
   {
   	$(str).closest('tr').find('td:eq(15)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(17)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(19)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').attr('disabled', false); 
    $excise_val=$(str).closest('tr').find('td:eq(15)').find('select').val();
    if($excise_val!='')
    {
     // alert($excise_val);
    
     $exciserate=$excise_val.split("#");
     var $ttamt=$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val();
     var $pkgamt=$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val();
     var $tpkgamt=parseFloat($ttamt)+parseFloat($pkgamt);
     $exciseamt=parseFloat($tpkgamt)*parseFloat($exciserate[1]/100);
     $ecess_val=$(str).closest('tr').find('td:eq(17)').find('select').val();     
     if($ecess_val!='' && $ecess_val!='#')
     {
      $ecessrate=$ecess_val.split("#");
      $ecessamt=parseFloat($exciseamt)*parseFloat($ecessrate[1]/100);
     }
     else
     {
      $ecessamt=0;
     }
     $shecess_val=$(str).closest('tr').find('td:eq(19)').find('select').val();
     if($shecess_val!='' && $shecess_val!='#' )
     {
      $shesrate=$shecess_val.split("#");
      $shecessamt=parseFloat($exciseamt)*parseFloat($shesrate[1]/100);
     }
     else
     {
      $shecessamt=0;
     }
     


    }
    else
    {
    $exciseamt=0;
    $ecessamt=0;
    $shecessamt=0;
    }
    $totalexiseamt=parseFloat($exciseamt)+parseFloat($ecessamt)+parseFloat($shecessamt);
    $(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($exciseamt.toFixed(2));
	$(str).closest('tr').find('td:eq(19)').find('input[type="text"]').val($ecessamt.toFixed(2));
	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').val($shecessamt.toFixed(2));
	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').val($totalexiseamt.toFixed(2));		

   }  */
        var $discount_item=$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val();
        var $pkgcharge=$(str).closest('tr').find('td:eq(14)').find('input[type="text"]').val();
        if($pkgcharge=='') $pkgcharge=0;
        if($discount_item=='') $discount_item=0;

        var $taxable=parseFloat($discount_item)+parseFloat($pkgcharge);
        $(str).closest('tr').find('td:eq(15)').find('input[type="text"]').val($taxable.toFixed(2));
        var $freight=$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val();
        var $vatper=$(str).closest('tr').find('td:eq(17)').find('input[type="text"]').val();
		if($vatper=='') $vatper=0;
		if($freight=='') $freight=0;
		
		var $distotal=parseFloat($taxable)+parseFloat($freight);
		var $totalamt=parseFloat($distotal)*parseFloat($vatper)/100;
		//var $totalamt=parseFloat($distotal)*parseFloat($vatper)/100;
		$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').val($totalamt1);
		
        var $surcharge=$(str).closest('tr').find('td:eq(19)').find('input[type="text"]').val();
       
        if($surcharge=='') $surcharge=0;
        //var $suramt=parseFloat($totalamt)*parseFloat($surcharge)/100;
        var $totalamount=parseFloat($taxable)+parseFloat($freight)+parseFloat($totalamt)+parseFloat($surcharge);
		//$(str).closest('tr').find('td:eq(25)').find('input[type="text"]').val($totalamt.toFixed(2));
       // $(str).closest('tr').find('td:eq(27)').find('input[type="text"]').val($suramt.toFixed(2));  
		$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').val($totalamount.toFixed(2));	


	basic_calculation();

	
}

function calculateFull_itemwise_pur(str)
{  
	
    if(document.getElementById("bill_id").checked==true)
	var $qty=$(str).closest('tr').find('td:eq(5)').find('input[type="text"]').val();
    else
    var $qty=$(str).closest('tr').find('td:eq(6)').find('input[type="text"]').val();	
	var $rate=$(str).closest('tr').find('td:eq(7)').find('input[type="text"]').val();
	if($rate=='') $rate=0;
	if($qty=='') $qty=0;
	var $amt=parseFloat($qty)*parseFloat($rate);
	$(str).closest('tr').find('td:eq(8)').find('input[type="text"]').val($amt);
	var $discount_val=$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(9)').find('select').val();
	var $totalp=$(str).closest('tr').find('td:eq(7)').find('input[type="text"]').val();
	//alert($discount_val);
	//alert($totalp);
	//alert($discount_type);
	if($discount_type=='Amount')
	{
		if($discount_val>$amt)
		{
			alert("Discount amount cannot greater than total price");
			$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val('');
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');	
			$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val('');
		    $(str).closest('tr').find('td:eq(28)').find('input[type="text"]').val('');	
		    basic_calculation();		
			return false;
		}

	}
	if($discount_type=='PercentAmt')	
	{
		if($discount_val>100)
		{
			alert("Discount % should be less than 100%");
			$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val('');
			$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val('');
			$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val('');			
		    $(str).closest('tr').find('td:eq(28)').find('input[type="text"]').val('');	
		    basic_calculation();
			return false;
		}
	}
   	
	var $discount_val=$(str).closest('tr').find('td:eq(10)').find('input[type="text"]').val();
	var $discount_type=$(str).closest('tr').find('td:eq(9)').find('select').val();
	//alert($discount_type)
	if($discount_type=='Amount')
	{
		var $discounted_amt=$amt-$discount_val;
		$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val($discount_val);
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discounted_amt);		

	}
	else if($discount_type=='PercentAmt')
	{
		var $discount_amt=parseFloat(parseFloat($amt*$discount_val)/100);		
		var $discounted_amt=$amt-$discount_amt;
		$discounted_amt=$discounted_amt.toFixed(2);
		$discount_amt=$discount_amt.toFixed(2);
		$(str).closest('tr').find('td:eq(11)').find('input[type="text"]').val($discount_amt);
		$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val($discounted_amt);	
	
	}
	
	//alert($tot_basic);
	/*cal_po_charges('')*/
	//$exciseflag=$(str).closest('tr').find('td:eq(12)'.find('select').val();
	//	alert($exciseflag);

   var $exciseflag=$(str).closest('tr').find('td:eq(14)').find('select').val();
  
   if($exciseflag=='' || $exciseflag=='NonExcisable')
   {
   	$(str).closest('tr').find('td:eq(15)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').attr('disabled', true);   	
   	$(str).closest('tr').find('td:eq(17)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(19)').find('select').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').attr('disabled', true);
   	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').attr('disabled', true); 
   	$totalexiseamt=0;
   }
   else
   {
   	$(str).closest('tr').find('td:eq(15)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(16)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(17)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(19)').find('select').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').attr('disabled', false);
   	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').attr('disabled', false); 
    $excise_val=$(str).closest('tr').find('td:eq(15)').find('select').val();
    if($excise_val!='')
    {
    //alert($excise_val);
    
     $exciserate=$excise_val.split("#");
     var $ttamt=$(str).closest('tr').find('td:eq(12)').find('input[type="text"]').val();
     var $pkgamt=$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val();
     //alert($pkgamt);
     if($pkgamt!='') 
     {
       var $tpkgamt=parseFloat($ttamt)+parseFloat($pkgamt);
     }
     else
     {
     	var $tpkgamt=0;
     }
    // alert($tpkgamt);
     if($tpkgamt=='') $tpkgamt=0;
     $exciseamt=parseFloat($tpkgamt)*parseFloat($exciserate[1]/100);
     $ecess_val=$(str).closest('tr').find('td:eq(17)').find('select').val();   
     //alert($ecess_val);  
     //alert($exciseamt);
     if($ecess_val!='' && $ecess_val!='#')
     {
      $ecessrate=$ecess_val.split("#");
      $ecessamt=parseFloat($exciseamt)*parseFloat($ecessrate[1]/100);
     }
     else
     {
      $ecessamt=0;
     }
     $shecess_val=$(str).closest('tr').find('td:eq(19)').find('select').val();
     if($shecess_val!='' && $shecess_val!='#' )
     {
      $shesrate=$shecess_val.split("#");
      $shecessamt=parseFloat($exciseamt)*parseFloat($shesrate[1]/100);
     }
     else
     {
      $shecessamt=0;
     }
     


    }
    else
    {
    $exciseamt=0;
    $ecessamt=0;
    $shecessamt=0;
    }
    $totalexiseamt=parseFloat($exciseamt)+parseFloat($ecessamt)+parseFloat($shecessamt);
    $(str).closest('tr').find('td:eq(16)').find('input[type="text"]').val($exciseamt.toFixed(2));
	$(str).closest('tr').find('td:eq(18)').find('input[type="text"]').val($ecessamt.toFixed(2));
	$(str).closest('tr').find('td:eq(20)').find('input[type="text"]').val($shecessamt.toFixed(2));
	$(str).closest('tr').find('td:eq(21)').find('input[type="text"]').val($totalexiseamt.toFixed(2));		

   }
     	var $vatper=$(str).closest('tr').find('td:eq(23)').find('input[type="text"]').val();
     	//alert($vatper);
		var $freight=$(str).closest('tr').find('td:eq(22)').find('input[type="text"]').val();
		var $pkgcharge=$(str).closest('tr').find('td:eq(13)').find('input[type="text"]').val();
		if($vatper=='') $vatper=0;
		if($freight=='') $freight=0;
		if($pkgcharge=='') $pkgcharge=0;
		var $distotal=parseFloat($discounted_amt)+parseFloat($freight)+parseFloat($totalexiseamt)+parseFloat($pkgcharge);
		var $totalamt=parseFloat($distotal)*parseFloat($vatper)/100;
		//alert($totalamt);
		//alert($vatper);
        var $surcharge=$(str).closest('tr').find('td:eq(26)').find('input[type="text"]').val();      
        if($surcharge=='') $surcharge=0;
        var $suramt=parseFloat($totalamt)*parseFloat($surcharge)/100;
        var $totalamount=parseFloat($distotal)+parseFloat($totalamt)+parseFloat($suramt);
		//$(str).closest('tr').find('td:eq(24)').find('input[type="text"]').val($totalamt.toFixed(2));
		$(str).closest('tr').find('td:eq(25)').find('input[type="text"]').val($totalamt.toFixed(2));
        $(str).closest('tr').find('td:eq(27)').find('input[type="text"]').val($suramt.toFixed(2));  
		$(str).closest('tr').find('td:eq(28)').find('input[type="text"]').val($totalamount.toFixed(2));	


	basic_calculation();

	
}




function basic_calculation()
{
	//alert("manoj");
	var sumOfArea=0;
	var sumOfArea1=0;
	var sumOfArea2=0;
    var sumOfArea3=0;
    var sumOfArea4=0;
    var sumOfArea5=0;
    var sumOfAreapkg=0;
    var sumOfAreasurcharge=0;

    $('#tableDataProduction').find('input[type="text"][class="basic"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea= sumOfArea + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea= sumOfArea;	
    }
    });
   
    $('#tableDataProduction').find('input[type="text"][class="pkgamt"]').each(function(){
    if($(this).val()!='')
    {
    sumOfAreapkg= sumOfAreapkg + parseFloat($(this).val());   
    }
    else
    {
    sumOfAreapkg= sumOfAreapkg;	
    }
    });

   /* $('#tableDataProduction').find('input[type="text"][class="excise"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea1= sumOfArea1 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea1= sumOfArea1;	
    }
    });

     $('#tableDataProduction').find('input[type="text"][class="ecess"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea2= sumOfArea2 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea2= sumOfArea2;	
    }
    });

     $('#tableDataProduction').find('input[type="text"][class="shecess"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea3= sumOfArea3 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea3= sumOfArea3;	
    }
    });  */

     $('#tableDataProduction').find('input[type="text"][class="freight"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea4= sumOfArea4 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea4= sumOfArea4;	
    }
    }); 

     $('#tableDataProduction').find('input[type="text"][class="vat"]').each(function(){
    if($(this).val()!='')
    {
    sumOfArea5= sumOfArea5 + parseFloat($(this).val());   
    }
    else
    {
    sumOfArea5= sumOfArea5;	
    }
    }); 

    $('#tableDataProduction').find('input[type="text"][class="surcharge"]').each(function(){
    if($(this).val()!='')
    {
    sumOfAreasurcharge= sumOfAreasurcharge + parseFloat($(this).val());   
    }
    else
    {
    sumOfAreasurcharge= sumOfAreasurcharge;	
    }
    }); 

	$tot_basic=sumOfArea.toFixed(2);
	//alert(sumOfArea);
	$('input[name="basic_amt"]').val($tot_basic);
	$('input[name="excise_amt"]').val(sumOfArea1.toFixed(2));
	$('input[name="ecess_amt"]').val(sumOfArea2.toFixed(2));
	$('input[name="shecess_amt"]').val(sumOfArea3.toFixed(2));
	$('input[name="Freight"]').val(sumOfArea4.toFixed(2));
	$('input[name="vat_amt"]').val(sumOfArea5.toFixed(2));
	$('input[name="pkg_charges"]').val(sumOfAreapkg.toFixed(2));
	$('input[name="surcharge_amt"]').val(sumOfAreasurcharge.toFixed(2));
	cal_grandtotal();
}

