How to calculate Rent with VAT?

Raj90
Tera Guru

Hi All,

1. Rent with VAT = Rent w/o VAT * with Tax VAT

   find_real_file.png

2.   Rent with VAT = 550 * 7.7% = 592.00

 

   find_real_file.png

3. Rent with VAT = 550

     find_real_file.png

Anyone having knowledge on this please help me.

Thanks

Raj

1 ACCEPTED SOLUTION

H again,

The decimal separator i cannot manipulate. Thats the browser that determines that.

In Google Chrome i get:
find_real_file.png

And in Firefox i get:

find_real_file.png

Opposite group separators and decimal deparators
I have edited the script to take care of this but i cannot change the way its displayed

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	if(newValue == 'no'){ //Check the value of the "No" choice and adjust this if its not correct (maybe it "No" or something like that)
		
		g_form.setValue('u_rent_with_vat', g_form.getValue('u_rent'));
		
	}else{
		
		var decimal_separator = g_user_decimal_separator; //We get decimal separator
		var group_separator = g_user_grouping_separator; //Group separator - can be 1.000,50 as an example then the group separator is .
		
		var re = new RegExp(RegExp.quote(group_separator),"g"); //Because we cannot just replace . through regex then we need to add \ before the . char
		
		var rent = g_form.getValue('u_rent');
		//rent is a currency field so format is currency;amount : USD;50.50
		var currency = rent.split(';')[0]; //to get current currency
		
		rent = parseFloat(rent.split(';')[1].replace(re, '').replace(decimal_separator, '.'));
		var calculatedValue = ((rent / 100) * parseFloat(newValue)) + rent;
		
		g_form.setValue('u_rent_with_vat', currency + ';' + calculatedValue);
	}
	
}

RegExp.quote = function(str) {
	return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
	};
	

 

View solution in original post

14 REPLIES 14

Simon Christens
Kilo Sage

Hi

Depending on the value of "With Tax VAT" then you can do this (In this example the value of "With Tax VAT" is 7.7 or 7,7 depending on your delimiter which is country specific)

if(with_tax_vat == "no"){

rent_with_vat = rent_without_vat;

}else{

rent_with_vat = (rent_without_vat / 100 * with_tax_vat) + rent_wihtout_vat;

}

So in your example

rent_with_vat = (550 / 100 * 7.7 or 7,7) + 550; //Result: 592.35

Hi Simon,

Thank you for answering my question.

 

With tax vat = vat = 7,7%  

Rent with VAT = Rent w/o VAT * with Tax VAT

Could you please tell me where can i write this code.

 

Thanks

Raj

 

Hi Raj

Where do you have these fields ?
Is it in a table, a Catalog item or?

When so you want the Rent with VAT to be calculated ?
When the record is saved ? On change of a field ?

On form:

find_real_file.png

 I tried onChange client script, it's not working.

 

  onChange:

               function onChange(control, oldValue, newValue, isLoading, isTemplate) {
                if (isLoading || newValue === '') {
               return;
               }

       var rent = g_form.getValue('u_rent');
       var vat = g_form.getValue('u_with_tax_tva');

       if(vat = "no"){

          rent_with_vat = rent;

      }else{

     rent_with_vat = (rent / 100 * vat) + rent;

     }

    g_form.setValue('u_rent_with_vat',rent_with_vat);

  
     }

 

Thanks

 

Raj