homeflowjs 1.0.64 → 1.0.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { calculateRange
|
1
|
+
import { calculateRange } from "./stamp-duty-utils";
|
2
2
|
|
3
3
|
const countryRates = (price, firstTimeBuyer, additionalProperty, ukResident, country) => {
|
4
4
|
const countryConfig = {
|
@@ -18,16 +18,12 @@ const countryRates = (price, firstTimeBuyer, additionalProperty, ukResident, cou
|
|
18
18
|
if(additionalProperty) return 'additional_property_rate';
|
19
19
|
return countryConfig[country].base;
|
20
20
|
};
|
21
|
-
const bracketForPrice = +(cmsRates[getPriceBracketIndex(price, cmsRates)]['non_uk_resident_rate']);
|
22
|
-
|
23
|
-
const initalTotalRate = () => {
|
24
|
-
if (!ukResident && bracketForPrice) return +((price * (bracketForPrice / 100)).toFixed(2));
|
25
|
-
return 0;
|
26
|
-
}
|
27
21
|
|
28
22
|
const stampDutyRatesCalculation = cmsRates.reduce((accumulator, _, index) => {
|
23
|
+
// Minumun price from the 1st braket should be always 0
|
24
|
+
const minimunFallback = index === 0 ? 0 : Number.POSITIVE_INFINITY;
|
29
25
|
const percentageFromList = +(cmsRates[index][buyerStatusAsKeyOfObject()]) / 100;
|
30
|
-
const minimumPropertyPrice = cmsRates[index]['minimum_property_price'] ||
|
26
|
+
const minimumPropertyPrice = cmsRates[index]['minimum_property_price'] || minimunFallback;
|
31
27
|
const maxisumPropertyPrice = cmsRates[index]['maximum_property_price'] || Number.POSITIVE_INFINITY;
|
32
28
|
const rateIndex = `rate${index + 1}`;
|
33
29
|
const rateForTheBracket = calculateRange(price, minimumPropertyPrice, maxisumPropertyPrice, percentageFromList);
|
@@ -39,7 +35,7 @@ const countryRates = (price, firstTimeBuyer, additionalProperty, ukResident, cou
|
|
39
35
|
|
40
36
|
return accumulator;
|
41
37
|
}, {
|
42
|
-
totalRate:
|
38
|
+
totalRate: 0,
|
43
39
|
effectiveRate: 0,
|
44
40
|
});
|
45
41
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { calculateRange
|
1
|
+
import { calculateRange } from "./stamp-duty-utils";
|
2
2
|
|
3
3
|
const englishRates = (
|
4
4
|
price = 0,
|
@@ -8,7 +8,6 @@ const englishRates = (
|
|
8
8
|
isCompany
|
9
9
|
) => {
|
10
10
|
const englandRatesList = Homeflow.get('stamp_duty_england');
|
11
|
-
const bracketForPrice = +(englandRatesList[getPriceBracketIndex(price, englandRatesList)]['non_uk_resident_rate']);
|
12
11
|
|
13
12
|
const buyerStatusAsKeyOfObject = () => {
|
14
13
|
if(firstTimeBuyer) return 'first_time_buyer_rate';
|
@@ -24,15 +23,23 @@ const englishRates = (
|
|
24
23
|
*/
|
25
24
|
const initalTotalRate = () => {
|
26
25
|
if(isCompany && price > 500_000) return price * 0.17;
|
27
|
-
if (!ukResident && bracketForPrice && !isCompany) return +((price * (bracketForPrice / 100)).toFixed(2));
|
28
26
|
return 0;
|
29
27
|
}
|
30
28
|
|
31
29
|
const stampDutyRatesCalculation = englandRatesList.reduce((accumulator, _, index) => {
|
32
|
-
|
33
|
-
const
|
30
|
+
// Minumun price from the 1st braket should be always 0
|
31
|
+
const minimunFallback = index === 0 ? 0 : Number.POSITIVE_INFINITY;
|
32
|
+
const minimumPropertyPrice = englandRatesList[index]['minimum_property_price'] || minimunFallback;
|
34
33
|
const maxisumPropertyPrice = englandRatesList[index]['maximum_property_price'] || Number.POSITIVE_INFINITY;
|
35
34
|
const rateIndex = `rate${index + 1}`;
|
35
|
+
let percentageFromList = +(englandRatesList[index][buyerStatusAsKeyOfObject()]) / 100;
|
36
|
+
|
37
|
+
if (!ukResident && englandRatesList[index]?.['non_uk_resident_rate']) {
|
38
|
+
percentageFromList += (+(englandRatesList[index]?.['non_uk_resident_rate']) / 100);
|
39
|
+
}
|
40
|
+
|
41
|
+
percentageFromList = parseFloat(percentageFromList.toFixed(3));
|
42
|
+
|
36
43
|
const rateForTheBracket = isCompany
|
37
44
|
? 0
|
38
45
|
: calculateRange(price, minimumPropertyPrice, maxisumPropertyPrice, percentageFromList);
|
@@ -44,7 +51,6 @@ const englishRates = (
|
|
44
51
|
|
45
52
|
return accumulator;
|
46
53
|
}, {
|
47
|
-
// totalRate: (!ukResident && bracketForPrice) ? +((price * (bracketForPrice / 100)).toFixed(2)) : 0,
|
48
54
|
totalRate: initalTotalRate(),
|
49
55
|
effectiveRate: 0,
|
50
56
|
});
|
@@ -22,7 +22,10 @@ const stampDutyCalculator = ({
|
|
22
22
|
* Once the BE brings data for companies (isCompany)
|
23
23
|
* countryRates will need an update and then we can have just one method.
|
24
24
|
*/
|
25
|
-
if (
|
25
|
+
if (
|
26
|
+
country?.toLowerCase() === 'scotland'
|
27
|
+
|| country?.toLowerCase() === 'wales')
|
28
|
+
{
|
26
29
|
return countryRates(price, firstTimeBuyer, additionalProperty, ukResident, country);
|
27
30
|
}
|
28
31
|
|
@@ -12,8 +12,8 @@ export const getPriceBracketIndex = (price, arr) => {
|
|
12
12
|
|
13
13
|
arr.forEach((rates, index) => {
|
14
14
|
if (
|
15
|
-
(rates.
|
16
|
-
&& (rates.minimum_property_price
|
15
|
+
(+(rates.maximum_property_price) || Number.POSITIVE_INFINITY) > price
|
16
|
+
&& +(rates.minimum_property_price) < price
|
17
17
|
) bracketIndex = index;
|
18
18
|
});
|
19
19
|
|