homeflowjs 0.7.0 → 0.7.1

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.
@@ -21,7 +21,8 @@ const hfInitialize = () => {
21
21
  Homeflow.dispatch = store.dispatch;
22
22
  Homeflow.subscribe = store.subscribe;
23
23
 
24
- initCookieConsent();
24
+ if (!Homeflow.get('disable_default_cookie_consent')) initCookieConsent();
25
+
25
26
  antiCSRF();
26
27
  recaptcha();
27
28
  bookingCalendar();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export { default as stampDutyCalculator } from './stamp-duty-calculator/stamp-duty-calculator';
2
+
1
3
  export const capitalizeFirstLetter = str => (
2
4
  str.charAt(0).toUpperCase() + str.slice(1)
3
5
  )
@@ -0,0 +1,113 @@
1
+ const englishRates = (price, firstTimeBuyer, additionalProperty) => {
2
+ let effectiveRate = 0;
3
+ let totalRate = 0;
4
+ let rate1 = 0;
5
+ let rate2 = 0;
6
+ let rate3 = 0;
7
+ let rate4 = 0;
8
+ let rate5 = 0;
9
+
10
+ // First time buyer
11
+ if (firstTimeBuyer) {
12
+ if (price - 300000 > 0) {
13
+ if ((price - 300000) > (500000 - 300000)) {
14
+ rate2 = (500000 - 300000) * 0.05;
15
+ } else {
16
+ rate2 = (price - 300000) * 0.05;
17
+ }
18
+ }
19
+ }
20
+
21
+ // Additional property
22
+ if (additionalProperty) {
23
+ // Rate 1
24
+ if (price > 125000) rate1 = 125000 * 0.03;
25
+ if (price <= 125000) {
26
+ rate1 = price * 0.03;
27
+ }
28
+
29
+ // Rate 2
30
+ if (price - 125000 > 0) {
31
+ if ((price - 125000) > (250000 - 125000)) {
32
+ rate2 = (250000 - 125000) * 0.05;
33
+ } else {
34
+ rate2 = (price - 125000) * 0.05;
35
+ }
36
+ }
37
+
38
+ // Rate 3
39
+ if (price - 250000 > 0) {
40
+ if ((price - 250000) > (925000 - 250000)) {
41
+ rate3 = (925000 - 250000) * 0.08;
42
+ } else {
43
+ rate3 = (price - 250000) * 0.08;
44
+ }
45
+ }
46
+
47
+ // Rate 4
48
+ if (price - 925000 > 0) {
49
+ if ((price - 925000) > (1500000 - 925000)) {
50
+ rate4 = (1500000 - 925000) * 0.13;
51
+ } else {
52
+ rate4 = (price - 925000) * 0.13;
53
+ }
54
+ }
55
+
56
+ // Rate 5
57
+ if (price - 1500000 > 0) {
58
+ rate5 = (price - 1500000);
59
+ rate5 *= 0.15;
60
+ }
61
+ }
62
+
63
+ if (!firstTimeBuyer && !additionalProperty) {
64
+ // Rate 2
65
+ if (price - 125000 > 0) {
66
+ if ((price - 125000) > (250000 - 125000)) {
67
+ rate2 = (250000 - 125000) * 0.02;
68
+ } else {
69
+ rate2 = (price - 125000) * 0.02;
70
+ }
71
+ }
72
+
73
+ // Rate 3
74
+ if (price - 250000 > 0) {
75
+ if ((price - 250000) > (925000 - 250000)) {
76
+ rate3 = (925000 - 250000) * 0.05;
77
+ } else {
78
+ rate3 = (price - 250000) * 0.05;
79
+ }
80
+ }
81
+
82
+ // Rate 4
83
+ if (price - 925000 > 0) {
84
+ if ((price - 925000) > (1500000 - 925000)) {
85
+ rate4 = (1500000 - 925000) * 0.10;
86
+ } else {
87
+ rate4 = (price - 925000) * 0.10;
88
+ }
89
+ }
90
+
91
+ // Rate 5
92
+ if (price - 1500000 > 0) {
93
+ rate5 = (price - 1500000);
94
+ rate5 *= 0.12;
95
+ }
96
+ }
97
+
98
+ totalRate = rate1 + rate2 + rate3 + rate4 + rate5;
99
+ effectiveRate = totalRate / price;
100
+ effectiveRate *= 100;
101
+
102
+ return {
103
+ rate1,
104
+ rate2,
105
+ rate3,
106
+ rate4,
107
+ rate5,
108
+ totalRate,
109
+ effectiveRate: Math.round(effectiveRate * 10) / 10,
110
+ };
111
+ };
112
+
113
+ export default englishRates;
@@ -0,0 +1,100 @@
1
+ const scottishRates = (price, firstTimeBuyer, additionalProperty) => {
2
+ let effectiveRate = 0;
3
+ let totalRate = 0;
4
+ const rate1 = 0;
5
+ let rate2 = 0;
6
+ let rate3 = 0;
7
+ let rate4 = 0;
8
+ let rate5 = 0;
9
+
10
+ if (firstTimeBuyer) {
11
+ // Rate 2
12
+ if (price - 175000 > 0) {
13
+ if ((price - 175000) > (250000 - 175000)) {
14
+ rate2 = (250000 - 175000) * 0.02;
15
+ } else {
16
+ rate2 = (price - 175000) * 0.02;
17
+ }
18
+ }
19
+
20
+ // Rate 3
21
+ if (price - 250000 > 0) {
22
+ if ((price - 250000) > (325000 - 250000)) {
23
+ rate3 = (325000 - 250000) * 0.05;
24
+ } else {
25
+ rate3 = (price - 250000) * 0.05;
26
+ }
27
+ }
28
+
29
+ // Rate 4
30
+ if (price - 325000 > 0) {
31
+ if ((price - 325000) > (750000 - 325000)) {
32
+ rate4 = (750000 - 325000) * 0.10;
33
+ } else {
34
+ rate4 = (price - 325000) * 0.10;
35
+ }
36
+ }
37
+
38
+ // Rate 5
39
+ if (price - 750000 > 0) {
40
+ rate5 = (price - 750000);
41
+ rate5 *= 0.12;
42
+ }
43
+ }
44
+
45
+ if (!firstTimeBuyer && !additionalProperty) {
46
+ // Rate 2
47
+ if (price - 145000 > 0) {
48
+ if ((price - 145000) > (250000 - 145000)) {
49
+ rate2 = (250000 - 145000) * 0.02;
50
+ } else {
51
+ rate2 = (price - 145000) * 0.02;
52
+ }
53
+ }
54
+
55
+ // Rate 3
56
+ if (price - 250000 > 0) {
57
+ if ((price - 250000) > (325000 - 250000)) {
58
+ rate3 = (325000 - 250000) * 0.05;
59
+ } else {
60
+ rate3 = (price - 250000) * 0.05;
61
+ }
62
+ }
63
+
64
+ // Rate 4
65
+ if (price - 325000 > 0) {
66
+ if ((price - 325000) > (750000 - 325000)) {
67
+ rate4 = (750000 - 325000) * 0.10;
68
+ } else {
69
+ rate4 = (price - 325000) * 0.10;
70
+ }
71
+ }
72
+
73
+ // Rate 5
74
+ if (price - 750000 > 0) {
75
+ rate5 = (price - 750000);
76
+ rate5 *= 0.12;
77
+ }
78
+ }
79
+
80
+ totalRate = rate1 + rate2 + rate3 + rate4 + rate5;
81
+ effectiveRate = totalRate / price;
82
+ effectiveRate *= 100;
83
+
84
+ if (additionalProperty) {
85
+ const ADS = price * 0.04;
86
+ totalRate += ADS;
87
+ }
88
+
89
+ return {
90
+ rate1,
91
+ rate2,
92
+ rate3,
93
+ rate4,
94
+ rate5,
95
+ totalRate,
96
+ effectiveRate: Math.round(effectiveRate * 10) / 10,
97
+ };
98
+ };
99
+
100
+ export default scottishRates;
@@ -0,0 +1,35 @@
1
+ import englishRates from './english-rates';
2
+ import scottishRates from './scottish-rates';
3
+ import welshRates from './welsh-rates';
4
+
5
+ /**
6
+ * We already have a DefaultStampDutyCalculator component,
7
+ * however this function is for when we need a way to figure out
8
+ * stamp duty rates without the DefaultStampDutyCalculator component.
9
+ * For example, if we want to build a custom React component with a
10
+ * different layout and/or styles to the DefaultStampDutyCalculator component.
11
+ */
12
+ const stampDutyCalculator = ({
13
+ price, country, firstTimeBuyer, additionalProperty,
14
+ }) => {
15
+ if (!price) {
16
+ return {
17
+ rate1: 0, rate2: 0, rate3: 0, rate4: 0, rate5: 0, totalRate: 0, effectiveRate: Math.round(0),
18
+ };
19
+ }
20
+
21
+ // Scotland
22
+ if (country === 'scotland') {
23
+ return scottishRates(price, firstTimeBuyer, additionalProperty);
24
+ }
25
+
26
+ // Wales
27
+ if (country === 'wales') {
28
+ return welshRates(price, additionalProperty);
29
+ }
30
+
31
+ // If country not is not specified use English rates by default
32
+ return englishRates(price, firstTimeBuyer, additionalProperty);
33
+ };
34
+
35
+ export default stampDutyCalculator;
@@ -0,0 +1,121 @@
1
+ const welshRates = (price, additionalProperty) => {
2
+ let effectiveRate = 0;
3
+ let totalRate = 0;
4
+ let rate1 = 0;
5
+ let rate2 = 0;
6
+ let rate3 = 0;
7
+ let rate4 = 0;
8
+ let rate5 = 0;
9
+ let rate6 = 0;
10
+
11
+ if (additionalProperty) {
12
+ // Rate 1
13
+ if (price > 180000) rate1 = 180000 * 0.04;
14
+ if (price <= 180000) {
15
+ rate1 = price * 0.04;
16
+ }
17
+
18
+ // Rate 2
19
+ if (price - 180000 > 0) {
20
+ if ((price - 180000) > (250000 - 180000)) {
21
+ rate2 = (250000 - 180000) * 0.075;
22
+ } else {
23
+ rate2 = (price - 180000) * 0.075;
24
+ }
25
+ }
26
+
27
+ // Rate 3
28
+ if (price - 250000 > 0) {
29
+ if ((price - 250000) > (400000 - 250000)) {
30
+ rate3 = (400000 - 250000) * 0.09;
31
+ } else {
32
+ rate3 = (price - 250000) * 0.09;
33
+ }
34
+ }
35
+
36
+ // Rate 4
37
+ if (price - 400000 > 0) {
38
+ if ((price - 400000) > (750000 - 400000)) {
39
+ rate4 = (750000 - 400000) * 1.15;
40
+ } else {
41
+ rate4 = (price - 400000) * 1.15;
42
+ }
43
+ }
44
+
45
+ // Rate 5
46
+ if (price - 750000 > 0) {
47
+ if ((price - 750000) > (1500000 - 750000)) {
48
+ rate5 = (1500000 - 750000) * 1.40;
49
+ } else {
50
+ rate5 = (price - 750000) * 1.40;
51
+ }
52
+ }
53
+
54
+ // Rate 6
55
+ if (price - 1500000 > 0) {
56
+ rate6 = (price - 1500000) * 1.16;
57
+ rate6 *= 1.16;
58
+ }
59
+ }
60
+
61
+ if (!additionalProperty) {
62
+ // Rate 2
63
+ if (price - 180000 > 0) {
64
+ if ((price - 180000) > (250000 - 180000)) {
65
+ rate2 = (250000 - 180000) * 0.035;
66
+ } else {
67
+ rate2 = (price - 180000) * 0.035;
68
+ }
69
+ }
70
+
71
+ // Rate 3
72
+ if (price - 250000 > 0) {
73
+ if ((price - 250000) > (400000 - 250000)) {
74
+ rate3 = (400000 - 250000) * 0.05;
75
+ } else {
76
+ rate3 = (price - 250000) * 0.05;
77
+ }
78
+ }
79
+
80
+ // Rate 4
81
+ if (price - 400000 > 0) {
82
+ if ((price - 400000) > (750000 - 400000)) {
83
+ rate4 = (750000 - 400000) * 0.75;
84
+ } else {
85
+ rate4 = (price - 400000) * 0.75;
86
+ }
87
+ }
88
+
89
+ // Rate 5
90
+ if (price - 750000 > 0) {
91
+ if ((price - 750000) > (1500000 - 750000)) {
92
+ rate5 = (1500000 - 750000) * 0.10;
93
+ } else {
94
+ rate5 = (price - 750000) * 0.10;
95
+ }
96
+ }
97
+
98
+ // Rate 6
99
+ if (price - 1500000 > 0) {
100
+ rate6 = (price - 1500000) * 0.12;
101
+ rate6 *= 0.12;
102
+ }
103
+ }
104
+
105
+ totalRate = rate1 + rate2 + rate3 + rate4 + rate5 + rate6;
106
+ effectiveRate = totalRate / price;
107
+ effectiveRate *= 100;
108
+
109
+ return {
110
+ rate1,
111
+ rate2,
112
+ rate3,
113
+ rate4,
114
+ rate5,
115
+ rate6,
116
+ totalRate,
117
+ effectiveRate: Math.round(effectiveRate * 10) / 10,
118
+ };
119
+ };
120
+
121
+ export default welshRates;