@novha/calc-engines 7.0.0 → 8.0.0

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.
Files changed (196) hide show
  1. package/dist/capital-gains/brazil/BrazilCapitalGainsService.js +3 -0
  2. package/dist/capital-gains/brazil/BrazilCapitalGainsServiceImpl.js +56 -0
  3. package/dist/capital-gains/brazil/domain/types.js +3 -0
  4. package/dist/capital-gains/index.js +14 -2
  5. package/dist/capital-gains/india/IndiaCapitalGainsService.js +3 -0
  6. package/dist/capital-gains/india/IndiaCapitalGainsServiceImpl.js +58 -0
  7. package/dist/capital-gains/india/domain/types.js +3 -0
  8. package/dist/capital-gains/japan/JapanCapitalGainsService.js +3 -0
  9. package/dist/capital-gains/japan/JapanCapitalGainsServiceImpl.js +41 -0
  10. package/dist/capital-gains/japan/domain/types.js +3 -0
  11. package/dist/capital-gains/spain/SpainCapitalGainsService.js +3 -0
  12. package/dist/capital-gains/spain/SpainCapitalGainsServiceImpl.js +56 -0
  13. package/dist/capital-gains/spain/domain/types.js +3 -0
  14. package/dist/corporate/brazil/BrazilCorporateTaxService.js +3 -0
  15. package/dist/corporate/brazil/BrazilCorporateTaxServiceImpl.js +33 -0
  16. package/dist/corporate/brazil/domain/types.js +3 -0
  17. package/dist/corporate/index.js +10 -2
  18. package/dist/corporate/india/IndiaCorporateTaxService.js +3 -0
  19. package/dist/corporate/india/IndiaCorporateTaxServiceImpl.js +29 -0
  20. package/dist/corporate/india/domain/types.js +3 -0
  21. package/dist/corporate/japan/JapanCorporateTaxService.js +3 -0
  22. package/dist/corporate/japan/JapanCorporateTaxServiceImpl.js +29 -0
  23. package/dist/corporate/japan/domain/types.js +3 -0
  24. package/dist/corporate/spain/SpainCorporateTaxService.js +3 -0
  25. package/dist/corporate/spain/SpainCorporateTaxServiceImpl.js +29 -0
  26. package/dist/corporate/spain/domain/types.js +3 -0
  27. package/dist/income-tax/brazil/BrazilIncomeTaxService.js +3 -0
  28. package/dist/income-tax/brazil/BrazilIncomeTaxServiceImpl.js +78 -0
  29. package/dist/income-tax/brazil/domain/types.js +3 -0
  30. package/dist/income-tax/index.js +14 -2
  31. package/dist/income-tax/india/IndiaIncomeTaxService.js +3 -0
  32. package/dist/income-tax/india/IndiaIncomeTaxServiceImpl.js +75 -0
  33. package/dist/income-tax/india/domain/types.js +3 -0
  34. package/dist/income-tax/japan/JapanIncomeTaxService.js +3 -0
  35. package/dist/income-tax/japan/JapanIncomeTaxServiceImpl.js +75 -0
  36. package/dist/income-tax/japan/domain/types.js +3 -0
  37. package/dist/income-tax/spain/SpainIncomeTaxService.js +3 -0
  38. package/dist/income-tax/spain/SpainIncomeTaxServiceImpl.js +62 -0
  39. package/dist/income-tax/spain/domain/types.js +3 -0
  40. package/dist/inheritance-tax/index.js +8 -2
  41. package/dist/inheritance-tax/japan/JapanInheritanceTaxService.js +3 -0
  42. package/dist/inheritance-tax/japan/JapanInheritanceTaxServiceImpl.js +53 -0
  43. package/dist/inheritance-tax/japan/domain/types.js +3 -0
  44. package/dist/inheritance-tax/spain/SpainInheritanceTaxService.js +3 -0
  45. package/dist/inheritance-tax/spain/SpainInheritanceTaxServiceImpl.js +51 -0
  46. package/dist/inheritance-tax/spain/domain/types.js +3 -0
  47. package/dist/mortgage/brazil/BrazilMortgageService.js +3 -0
  48. package/dist/mortgage/brazil/BrazilMortgageServiceImpl.js +76 -0
  49. package/dist/mortgage/brazil/domain/types.js +3 -0
  50. package/dist/mortgage/index.js +14 -2
  51. package/dist/mortgage/india/IndiaMortgageService.js +3 -0
  52. package/dist/mortgage/india/IndiaMortgageServiceImpl.js +76 -0
  53. package/dist/mortgage/india/domain/types.js +3 -0
  54. package/dist/mortgage/japan/JapanMortgageService.js +3 -0
  55. package/dist/mortgage/japan/JapanMortgageServiceImpl.js +76 -0
  56. package/dist/mortgage/japan/domain/types.js +3 -0
  57. package/dist/mortgage/spain/SpainMortgageService.js +3 -0
  58. package/dist/mortgage/spain/SpainMortgageServiceImpl.js +96 -0
  59. package/dist/mortgage/spain/domain/types.js +3 -0
  60. package/dist/types/capital-gains/brazil/BrazilCapitalGainsService.d.ts +4 -0
  61. package/dist/types/capital-gains/brazil/BrazilCapitalGainsServiceImpl.d.ts +10 -0
  62. package/dist/types/capital-gains/brazil/domain/types.d.ts +11 -0
  63. package/dist/types/capital-gains/index.d.ts +9 -1
  64. package/dist/types/capital-gains/india/IndiaCapitalGainsService.d.ts +4 -0
  65. package/dist/types/capital-gains/india/IndiaCapitalGainsServiceImpl.d.ts +9 -0
  66. package/dist/types/capital-gains/india/domain/types.d.ts +9 -0
  67. package/dist/types/capital-gains/japan/JapanCapitalGainsService.d.ts +4 -0
  68. package/dist/types/capital-gains/japan/JapanCapitalGainsServiceImpl.d.ts +9 -0
  69. package/dist/types/capital-gains/japan/domain/types.d.ts +6 -0
  70. package/dist/types/capital-gains/spain/SpainCapitalGainsService.d.ts +4 -0
  71. package/dist/types/capital-gains/spain/SpainCapitalGainsServiceImpl.d.ts +10 -0
  72. package/dist/types/capital-gains/spain/domain/types.d.ts +11 -0
  73. package/dist/types/corporate/brazil/BrazilCorporateTaxService.d.ts +4 -0
  74. package/dist/types/corporate/brazil/BrazilCorporateTaxServiceImpl.d.ts +8 -0
  75. package/dist/types/corporate/brazil/domain/types.d.ts +19 -0
  76. package/dist/types/corporate/index.d.ts +9 -1
  77. package/dist/types/corporate/india/IndiaCorporateTaxService.d.ts +4 -0
  78. package/dist/types/corporate/india/IndiaCorporateTaxServiceImpl.d.ts +8 -0
  79. package/dist/types/corporate/india/domain/types.d.ts +15 -0
  80. package/dist/types/corporate/japan/JapanCorporateTaxService.d.ts +4 -0
  81. package/dist/types/corporate/japan/JapanCorporateTaxServiceImpl.d.ts +8 -0
  82. package/dist/types/corporate/japan/domain/types.d.ts +15 -0
  83. package/dist/types/corporate/spain/SpainCorporateTaxService.d.ts +4 -0
  84. package/dist/types/corporate/spain/SpainCorporateTaxServiceImpl.d.ts +8 -0
  85. package/dist/types/corporate/spain/domain/types.d.ts +15 -0
  86. package/dist/types/income-tax/brazil/BrazilIncomeTaxService.d.ts +4 -0
  87. package/dist/types/income-tax/brazil/BrazilIncomeTaxServiceImpl.d.ts +11 -0
  88. package/dist/types/income-tax/brazil/domain/types.d.ts +18 -0
  89. package/dist/types/income-tax/index.d.ts +9 -1
  90. package/dist/types/income-tax/india/IndiaIncomeTaxService.d.ts +4 -0
  91. package/dist/types/income-tax/india/IndiaIncomeTaxServiceImpl.d.ts +10 -0
  92. package/dist/types/income-tax/india/domain/types.d.ts +16 -0
  93. package/dist/types/income-tax/japan/JapanIncomeTaxService.d.ts +4 -0
  94. package/dist/types/income-tax/japan/JapanIncomeTaxServiceImpl.d.ts +10 -0
  95. package/dist/types/income-tax/japan/domain/types.d.ts +16 -0
  96. package/dist/types/income-tax/spain/SpainIncomeTaxService.d.ts +4 -0
  97. package/dist/types/income-tax/spain/SpainIncomeTaxServiceImpl.d.ts +10 -0
  98. package/dist/types/income-tax/spain/domain/types.d.ts +16 -0
  99. package/dist/types/inheritance-tax/index.d.ts +5 -1
  100. package/dist/types/inheritance-tax/japan/JapanInheritanceTaxService.d.ts +4 -0
  101. package/dist/types/inheritance-tax/japan/JapanInheritanceTaxServiceImpl.d.ts +9 -0
  102. package/dist/types/inheritance-tax/japan/domain/types.d.ts +21 -0
  103. package/dist/types/inheritance-tax/spain/SpainInheritanceTaxService.d.ts +4 -0
  104. package/dist/types/inheritance-tax/spain/SpainInheritanceTaxServiceImpl.d.ts +9 -0
  105. package/dist/types/inheritance-tax/spain/domain/types.d.ts +19 -0
  106. package/dist/types/mortgage/brazil/BrazilMortgageService.d.ts +4 -0
  107. package/dist/types/mortgage/brazil/BrazilMortgageServiceImpl.d.ts +7 -0
  108. package/dist/types/mortgage/brazil/domain/types.d.ts +39 -0
  109. package/dist/types/mortgage/index.d.ts +9 -1
  110. package/dist/types/mortgage/india/IndiaMortgageService.d.ts +4 -0
  111. package/dist/types/mortgage/india/IndiaMortgageServiceImpl.d.ts +7 -0
  112. package/dist/types/mortgage/india/domain/types.d.ts +39 -0
  113. package/dist/types/mortgage/japan/JapanMortgageService.d.ts +4 -0
  114. package/dist/types/mortgage/japan/JapanMortgageServiceImpl.d.ts +7 -0
  115. package/dist/types/mortgage/japan/domain/types.d.ts +39 -0
  116. package/dist/types/mortgage/spain/SpainMortgageService.d.ts +4 -0
  117. package/dist/types/mortgage/spain/SpainMortgageServiceImpl.d.ts +8 -0
  118. package/dist/types/mortgage/spain/domain/types.d.ts +44 -0
  119. package/package.json +1 -1
  120. package/src/capital-gains/brazil/BrazilCapitalGainsService.ts +5 -0
  121. package/src/capital-gains/brazil/BrazilCapitalGainsServiceImpl.ts +69 -0
  122. package/src/capital-gains/brazil/domain/types.ts +15 -0
  123. package/src/capital-gains/index.ts +40 -0
  124. package/src/capital-gains/india/IndiaCapitalGainsService.ts +5 -0
  125. package/src/capital-gains/india/IndiaCapitalGainsServiceImpl.ts +64 -0
  126. package/src/capital-gains/india/domain/types.ts +12 -0
  127. package/src/capital-gains/japan/JapanCapitalGainsService.ts +5 -0
  128. package/src/capital-gains/japan/JapanCapitalGainsServiceImpl.ts +47 -0
  129. package/src/capital-gains/japan/domain/types.ts +9 -0
  130. package/src/capital-gains/spain/SpainCapitalGainsService.ts +5 -0
  131. package/src/capital-gains/spain/SpainCapitalGainsServiceImpl.ts +69 -0
  132. package/src/capital-gains/spain/domain/types.ts +15 -0
  133. package/src/corporate/brazil/BrazilCorporateTaxService.ts +5 -0
  134. package/src/corporate/brazil/BrazilCorporateTaxServiceImpl.ts +40 -0
  135. package/src/corporate/brazil/domain/types.ts +16 -0
  136. package/src/corporate/index.ts +45 -1
  137. package/src/corporate/india/IndiaCorporateTaxService.ts +5 -0
  138. package/src/corporate/india/IndiaCorporateTaxServiceImpl.ts +35 -0
  139. package/src/corporate/india/domain/types.ts +15 -0
  140. package/src/corporate/japan/JapanCorporateTaxService.ts +5 -0
  141. package/src/corporate/japan/JapanCorporateTaxServiceImpl.ts +35 -0
  142. package/src/corporate/japan/domain/types.ts +15 -0
  143. package/src/corporate/spain/SpainCorporateTaxService.ts +5 -0
  144. package/src/corporate/spain/SpainCorporateTaxServiceImpl.ts +35 -0
  145. package/src/corporate/spain/domain/types.ts +15 -0
  146. package/src/income-tax/brazil/BrazilIncomeTaxService.ts +5 -0
  147. package/src/income-tax/brazil/BrazilIncomeTaxServiceImpl.ts +91 -0
  148. package/src/income-tax/brazil/domain/types.ts +21 -0
  149. package/src/income-tax/index.ts +40 -0
  150. package/src/income-tax/india/IndiaIncomeTaxService.ts +5 -0
  151. package/src/income-tax/india/IndiaIncomeTaxServiceImpl.ts +87 -0
  152. package/src/income-tax/india/domain/types.ts +16 -0
  153. package/src/income-tax/japan/JapanIncomeTaxService.ts +5 -0
  154. package/src/income-tax/japan/JapanIncomeTaxServiceImpl.ts +87 -0
  155. package/src/income-tax/japan/domain/types.ts +16 -0
  156. package/src/income-tax/spain/SpainIncomeTaxService.ts +5 -0
  157. package/src/income-tax/spain/SpainIncomeTaxServiceImpl.ts +75 -0
  158. package/src/income-tax/spain/domain/types.ts +16 -0
  159. package/src/inheritance-tax/index.ts +24 -0
  160. package/src/inheritance-tax/japan/JapanInheritanceTaxService.ts +5 -0
  161. package/src/inheritance-tax/japan/JapanInheritanceTaxServiceImpl.ts +67 -0
  162. package/src/inheritance-tax/japan/domain/types.ts +25 -0
  163. package/src/inheritance-tax/spain/SpainInheritanceTaxService.ts +5 -0
  164. package/src/inheritance-tax/spain/SpainInheritanceTaxServiceImpl.ts +65 -0
  165. package/src/inheritance-tax/spain/domain/types.ts +23 -0
  166. package/src/mortgage/brazil/BrazilMortgageService.ts +5 -0
  167. package/src/mortgage/brazil/BrazilMortgageServiceImpl.ts +101 -0
  168. package/src/mortgage/brazil/domain/types.ts +46 -0
  169. package/src/mortgage/index.ts +49 -1
  170. package/src/mortgage/india/IndiaMortgageService.ts +5 -0
  171. package/src/mortgage/india/IndiaMortgageServiceImpl.ts +101 -0
  172. package/src/mortgage/india/domain/types.ts +46 -0
  173. package/src/mortgage/japan/JapanMortgageService.ts +5 -0
  174. package/src/mortgage/japan/JapanMortgageServiceImpl.ts +101 -0
  175. package/src/mortgage/japan/domain/types.ts +46 -0
  176. package/src/mortgage/spain/SpainMortgageService.ts +5 -0
  177. package/src/mortgage/spain/SpainMortgageServiceImpl.ts +130 -0
  178. package/src/mortgage/spain/domain/types.ts +52 -0
  179. package/test/brazil-capital-gains.test.ts +65 -0
  180. package/test/brazil-corporate-tax.test.ts +63 -0
  181. package/test/brazil-income-tax.test.ts +85 -0
  182. package/test/brazil-mortgage.test.ts +70 -0
  183. package/test/india-capital-gains.test.ts +71 -0
  184. package/test/india-corporate-tax.test.ts +54 -0
  185. package/test/india-income-tax.test.ts +78 -0
  186. package/test/india-mortgage.test.ts +70 -0
  187. package/test/japan-capital-gains.test.ts +55 -0
  188. package/test/japan-corporate-tax.test.ts +54 -0
  189. package/test/japan-income-tax.test.ts +76 -0
  190. package/test/japan-inheritance-tax.test.ts +74 -0
  191. package/test/japan-mortgage.test.ts +69 -0
  192. package/test/spain-capital-gains.test.ts +66 -0
  193. package/test/spain-corporate-tax.test.ts +54 -0
  194. package/test/spain-income-tax.test.ts +84 -0
  195. package/test/spain-inheritance-tax.test.ts +78 -0
  196. package/test/spain-mortgage.test.ts +70 -0
@@ -0,0 +1,39 @@
1
+ import { OtherFees } from "../../domain/types";
2
+ export interface MortgageRules {
3
+ loanConstraints: LoanConstraints;
4
+ interest: InterestRules;
5
+ acquisitionTax: AcquisitionTaxRules;
6
+ }
7
+ export interface LoanConstraints {
8
+ maxLtvPercent: number;
9
+ maxAmortizationYears: number;
10
+ }
11
+ export interface InterestRules {
12
+ compounding: 'MONTHLY';
13
+ }
14
+ export interface AcquisitionTaxRules {
15
+ rate: number;
16
+ }
17
+ export interface AmortizationScheduleItem {
18
+ year: number;
19
+ principal: number;
20
+ interest: number;
21
+ balance: number;
22
+ }
23
+ export interface MortgageInput {
24
+ propertyPrice: number;
25
+ downPayment: number;
26
+ annualInterestRate: number;
27
+ amortizationYears: number;
28
+ isFirstTimeBuyer: boolean;
29
+ }
30
+ export interface MortgageOutput {
31
+ loanAmount: number;
32
+ totalMortgage: number;
33
+ monthlyPayment: number;
34
+ totalInterestPaid: number;
35
+ totalPaid: number;
36
+ acquisitionTax: number;
37
+ amortizationSchedule: AmortizationScheduleItem[];
38
+ otherFees: OtherFees;
39
+ }
@@ -0,0 +1,4 @@
1
+ import { MortgageInput, MortgageOutput, MortgageRules } from "./domain/types";
2
+ export interface SpainMortgageService {
3
+ calculate(input: MortgageInput, rules: MortgageRules): MortgageOutput;
4
+ }
@@ -0,0 +1,8 @@
1
+ import { SpainMortgageService } from "./SpainMortgageService";
2
+ import { MortgageInput, MortgageOutput, MortgageRules } from "./domain/types";
3
+ export declare class SpainMortgageServiceImpl implements SpainMortgageService {
4
+ calculate(input: MortgageInput, rules: MortgageRules): MortgageOutput;
5
+ private calculateTransferTax;
6
+ private calculateAmortizationSchedule;
7
+ private calculatePayment;
8
+ }
@@ -0,0 +1,44 @@
1
+ import { OtherFees } from "../../domain/types";
2
+ export interface MortgageRules {
3
+ loanConstraints: LoanConstraints;
4
+ interest: InterestRules;
5
+ transferTax: TransferTaxRules;
6
+ }
7
+ export interface LoanConstraints {
8
+ maxLtvPercent: number;
9
+ maxAmortizationYears: number;
10
+ }
11
+ export interface InterestRules {
12
+ compounding: 'MONTHLY';
13
+ }
14
+ export interface TransferTaxBracket {
15
+ upTo?: number;
16
+ above?: number;
17
+ rate: number;
18
+ }
19
+ export interface TransferTaxRules {
20
+ brackets: TransferTaxBracket[];
21
+ }
22
+ export interface AmortizationScheduleItem {
23
+ year: number;
24
+ principal: number;
25
+ interest: number;
26
+ balance: number;
27
+ }
28
+ export interface MortgageInput {
29
+ propertyPrice: number;
30
+ downPayment: number;
31
+ annualInterestRate: number;
32
+ amortizationYears: number;
33
+ isFirstTimeBuyer: boolean;
34
+ }
35
+ export interface MortgageOutput {
36
+ loanAmount: number;
37
+ totalMortgage: number;
38
+ monthlyPayment: number;
39
+ totalInterestPaid: number;
40
+ totalPaid: number;
41
+ transferTax: number;
42
+ amortizationSchedule: AmortizationScheduleItem[];
43
+ otherFees: OtherFees;
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novha/calc-engines",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ import { Result } from "../domain/types";
2
+
3
+ export interface BrazilCapitalGainsService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,69 @@
1
+ import { Breakdown, Result } from "../domain/types";
2
+ import { BrazilCapitalGainsService } from "./BrazilCapitalGainsService";
3
+ import { CapitalGainsBracket, Input, Rules } from "./domain/types";
4
+
5
+ export class BrazilCapitalGainsServiceImpl implements BrazilCapitalGainsService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const gain = this._input.capitalGain;
16
+
17
+ if (gain <= 0) {
18
+ return {
19
+ taxableGain: 0,
20
+ capitalGainTax: 0,
21
+ socialContributions: 0,
22
+ netInvestmentIncomeTax: 0,
23
+ totalTax: 0,
24
+ effectiveRate: 0,
25
+ breakdowns: [],
26
+ };
27
+ }
28
+
29
+ const { tax, breakdowns } = this.applyBrackets(gain, this._rules.brackets);
30
+
31
+ return {
32
+ taxableGain: gain,
33
+ capitalGainTax: tax,
34
+ socialContributions: 0,
35
+ netInvestmentIncomeTax: 0,
36
+ totalTax: tax,
37
+ effectiveRate: (tax / gain) * 100,
38
+ breakdowns,
39
+ };
40
+ }
41
+
42
+ private applyBrackets(
43
+ gain: number,
44
+ brackets: CapitalGainsBracket[],
45
+ ): { tax: number; breakdowns: Breakdown[] } {
46
+ let tax = 0;
47
+ const breakdowns: Breakdown[] = [];
48
+
49
+ for (const bracket of brackets) {
50
+ if (gain <= bracket.from) break;
51
+
52
+ const upper = bracket.to ?? gain;
53
+ const taxable = Math.min(upper, gain) - bracket.from;
54
+
55
+ if (taxable > 0) {
56
+ const bracketTax = taxable * bracket.rate;
57
+ tax += bracketTax;
58
+ breakdowns.push({
59
+ from: `${bracket.from}`,
60
+ to: `${bracket.to ?? 'Above'}`,
61
+ rate: bracket.rate,
62
+ amount: bracketTax,
63
+ });
64
+ }
65
+ }
66
+
67
+ return { tax, breakdowns };
68
+ }
69
+ }
@@ -0,0 +1,15 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface CapitalGainsBracket {
4
+ from: number;
5
+ to: number | null;
6
+ rate: number;
7
+ }
8
+
9
+ export interface Rules {
10
+ brackets: CapitalGainsBracket[];
11
+ }
12
+
13
+ export interface Input {
14
+ capitalGain: number;
15
+ }
@@ -48,6 +48,34 @@ import {
48
48
  } from './germany/domain/types';
49
49
  import { Result } from './domain/types';
50
50
 
51
+ // Capital Gains - Brazil
52
+ import { BrazilCapitalGainsServiceImpl as BrazilCapitalGainsService } from './brazil/BrazilCapitalGainsServiceImpl';
53
+ import {
54
+ Input as BrazilCapitalGainsInput,
55
+ Rules as BrazilCapitalGainsRules
56
+ } from './brazil/domain/types';
57
+
58
+ // Capital Gains - Spain
59
+ import { SpainCapitalGainsServiceImpl as SpainCapitalGainsService } from './spain/SpainCapitalGainsServiceImpl';
60
+ import {
61
+ Input as SpainCapitalGainsInput,
62
+ Rules as SpainCapitalGainsRules
63
+ } from './spain/domain/types';
64
+
65
+ // Capital Gains - India
66
+ import { IndiaCapitalGainsServiceImpl as IndiaCapitalGainsService } from './india/IndiaCapitalGainsServiceImpl';
67
+ import {
68
+ Input as IndiaCapitalGainsInput,
69
+ Rules as IndiaCapitalGainsRules
70
+ } from './india/domain/types';
71
+
72
+ // Capital Gains - Japan
73
+ import { JapanCapitalGainsServiceImpl as JapanCapitalGainsService } from './japan/JapanCapitalGainsServiceImpl';
74
+ import {
75
+ Input as JapanCapitalGainsInput,
76
+ Rules as JapanCapitalGainsRules
77
+ } from './japan/domain/types';
78
+
51
79
  export {
52
80
  CanadaCapitalGainsService,
53
81
  CanadaCapitalGainsInput,
@@ -70,5 +98,17 @@ export {
70
98
  GermanyCapitalGainsService,
71
99
  GermanyCapitalGainsInput,
72
100
  GermanyCapitalGainsRules,
101
+ BrazilCapitalGainsService,
102
+ BrazilCapitalGainsInput,
103
+ BrazilCapitalGainsRules,
104
+ SpainCapitalGainsService,
105
+ SpainCapitalGainsInput,
106
+ SpainCapitalGainsRules,
107
+ IndiaCapitalGainsService,
108
+ IndiaCapitalGainsInput,
109
+ IndiaCapitalGainsRules,
110
+ JapanCapitalGainsService,
111
+ JapanCapitalGainsInput,
112
+ JapanCapitalGainsRules,
73
113
  Result
74
114
  };
@@ -0,0 +1,5 @@
1
+ import { Result } from "../domain/types";
2
+
3
+ export interface IndiaCapitalGainsService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,64 @@
1
+ import { Breakdown, Result } from "../domain/types";
2
+ import { IndiaCapitalGainsService } from "./IndiaCapitalGainsService";
3
+ import { Input, Rules } from "./domain/types";
4
+
5
+ export class IndiaCapitalGainsServiceImpl implements IndiaCapitalGainsService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const gain = this._input.capitalGain;
16
+
17
+ if (gain <= 0) {
18
+ return {
19
+ taxableGain: 0,
20
+ capitalGainTax: 0,
21
+ socialContributions: 0,
22
+ netInvestmentIncomeTax: 0,
23
+ totalTax: 0,
24
+ effectiveRate: 0,
25
+ breakdowns: [],
26
+ };
27
+ }
28
+
29
+ const isLongTerm = this._input.holdingPeriodMonths >= 12;
30
+ const breakdowns: Breakdown[] = [];
31
+ let tax = 0;
32
+
33
+ if (isLongTerm) {
34
+ const taxableGain = Math.max(0, gain - this._rules.longTermExemption);
35
+ tax = taxableGain * this._rules.longTermRate;
36
+ if (taxableGain > 0) {
37
+ breakdowns.push({
38
+ from: `${this._rules.longTermExemption}`,
39
+ to: 'Above',
40
+ rate: this._rules.longTermRate,
41
+ amount: tax,
42
+ });
43
+ }
44
+ } else {
45
+ tax = gain * this._rules.shortTermRate;
46
+ breakdowns.push({
47
+ from: '0',
48
+ to: 'All',
49
+ rate: this._rules.shortTermRate,
50
+ amount: tax,
51
+ });
52
+ }
53
+
54
+ return {
55
+ taxableGain: gain,
56
+ capitalGainTax: tax,
57
+ socialContributions: 0,
58
+ netInvestmentIncomeTax: 0,
59
+ totalTax: tax,
60
+ effectiveRate: gain > 0 ? (tax / gain) * 100 : 0,
61
+ breakdowns,
62
+ };
63
+ }
64
+ }
@@ -0,0 +1,12 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface Rules {
4
+ shortTermRate: number;
5
+ longTermRate: number;
6
+ longTermExemption: number;
7
+ }
8
+
9
+ export interface Input {
10
+ capitalGain: number;
11
+ holdingPeriodMonths: number;
12
+ }
@@ -0,0 +1,5 @@
1
+ import { Result } from "../domain/types";
2
+
3
+ export interface JapanCapitalGainsService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,47 @@
1
+ import { Breakdown, Result } from "../domain/types";
2
+ import { JapanCapitalGainsService } from "./JapanCapitalGainsService";
3
+ import { Input, Rules } from "./domain/types";
4
+
5
+ export class JapanCapitalGainsServiceImpl implements JapanCapitalGainsService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const gain = this._input.capitalGain;
16
+
17
+ if (gain <= 0) {
18
+ return {
19
+ taxableGain: 0,
20
+ capitalGainTax: 0,
21
+ socialContributions: 0,
22
+ netInvestmentIncomeTax: 0,
23
+ totalTax: 0,
24
+ effectiveRate: 0,
25
+ breakdowns: [],
26
+ };
27
+ }
28
+
29
+ const tax = gain * this._rules.flatRate;
30
+ const breakdowns: Breakdown[] = [{
31
+ from: '0',
32
+ to: 'All',
33
+ rate: this._rules.flatRate,
34
+ amount: tax,
35
+ }];
36
+
37
+ return {
38
+ taxableGain: gain,
39
+ capitalGainTax: tax,
40
+ socialContributions: 0,
41
+ netInvestmentIncomeTax: 0,
42
+ totalTax: tax,
43
+ effectiveRate: (tax / gain) * 100,
44
+ breakdowns,
45
+ };
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface Rules {
4
+ flatRate: number;
5
+ }
6
+
7
+ export interface Input {
8
+ capitalGain: number;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { Result } from "../domain/types";
2
+
3
+ export interface SpainCapitalGainsService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,69 @@
1
+ import { Breakdown, Result } from "../domain/types";
2
+ import { SpainCapitalGainsService } from "./SpainCapitalGainsService";
3
+ import { CapitalGainsBracket, Input, Rules } from "./domain/types";
4
+
5
+ export class SpainCapitalGainsServiceImpl implements SpainCapitalGainsService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const gain = this._input.capitalGain;
16
+
17
+ if (gain <= 0) {
18
+ return {
19
+ taxableGain: 0,
20
+ capitalGainTax: 0,
21
+ socialContributions: 0,
22
+ netInvestmentIncomeTax: 0,
23
+ totalTax: 0,
24
+ effectiveRate: 0,
25
+ breakdowns: [],
26
+ };
27
+ }
28
+
29
+ const { tax, breakdowns } = this.applyBrackets(gain, this._rules.brackets);
30
+
31
+ return {
32
+ taxableGain: gain,
33
+ capitalGainTax: tax,
34
+ socialContributions: 0,
35
+ netInvestmentIncomeTax: 0,
36
+ totalTax: tax,
37
+ effectiveRate: (tax / gain) * 100,
38
+ breakdowns,
39
+ };
40
+ }
41
+
42
+ private applyBrackets(
43
+ gain: number,
44
+ brackets: CapitalGainsBracket[],
45
+ ): { tax: number; breakdowns: Breakdown[] } {
46
+ let tax = 0;
47
+ const breakdowns: Breakdown[] = [];
48
+
49
+ for (const bracket of brackets) {
50
+ if (gain <= bracket.from) break;
51
+
52
+ const upper = bracket.to ?? gain;
53
+ const taxable = Math.min(upper, gain) - bracket.from;
54
+
55
+ if (taxable > 0) {
56
+ const bracketTax = taxable * bracket.rate;
57
+ tax += bracketTax;
58
+ breakdowns.push({
59
+ from: `${bracket.from}`,
60
+ to: `${bracket.to ?? 'Above'}`,
61
+ rate: bracket.rate,
62
+ amount: bracketTax,
63
+ });
64
+ }
65
+ }
66
+
67
+ return { tax, breakdowns };
68
+ }
69
+ }
@@ -0,0 +1,15 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface CapitalGainsBracket {
4
+ from: number;
5
+ to: number | null;
6
+ rate: number;
7
+ }
8
+
9
+ export interface Rules {
10
+ brackets: CapitalGainsBracket[];
11
+ }
12
+
13
+ export interface Input {
14
+ capitalGain: number;
15
+ }
@@ -0,0 +1,5 @@
1
+ import { Result } from "./domain/types";
2
+
3
+ export interface BrazilCorporateTaxService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,40 @@
1
+ import { Breakdown } from "../domain/types";
2
+ import { BrazilCorporateTaxService } from "./BrazilCorporateTaxService";
3
+ import { Input, Result, Rules } from "./domain/types";
4
+
5
+ export class BrazilCorporateTaxServiceImpl implements BrazilCorporateTaxService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const income = this._input.taxableIncome;
16
+
17
+ if (income <= 0) {
18
+ return { corporateTax: 0, effectiveTaxRate: 0, breakdowns: [] };
19
+ }
20
+
21
+ const irpjBase = income * this._rules.irpj.baseRate;
22
+ const surcharge = income > this._rules.irpj.surchargeThreshold
23
+ ? (income - this._rules.irpj.surchargeThreshold) * this._rules.irpj.surchargeRate
24
+ : 0;
25
+ const csll = income * this._rules.csll.rate;
26
+ const corporateTax = irpjBase + surcharge + csll;
27
+
28
+ const breakdowns: Breakdown[] = [
29
+ { from: '0', to: 'All', rate: this._rules.irpj.baseRate, amount: irpjBase },
30
+ { from: `${this._rules.irpj.surchargeThreshold}`, to: 'Surcharge', rate: this._rules.irpj.surchargeRate, amount: surcharge },
31
+ { from: '0', to: 'CSLL', rate: this._rules.csll.rate, amount: csll },
32
+ ];
33
+
34
+ return {
35
+ corporateTax,
36
+ effectiveTaxRate: (corporateTax / income) * 100,
37
+ breakdowns,
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,16 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface Rules {
4
+ irpj: { baseRate: number; surchargeRate: number; surchargeThreshold: number };
5
+ csll: { rate: number };
6
+ }
7
+
8
+ export interface Input {
9
+ taxableIncome: number;
10
+ }
11
+
12
+ export interface Result {
13
+ corporateTax: number;
14
+ effectiveTaxRate: number;
15
+ breakdowns: Breakdown[];
16
+ }
@@ -47,6 +47,34 @@ import {
47
47
  Result as CanadaCorporateTaxResult,
48
48
  } from './canada/domain/types';
49
49
 
50
+ import { BrazilCorporateTaxServiceImpl as BrazilCorporateTaxService } from './brazil/BrazilCorporateTaxServiceImpl';
51
+ import {
52
+ Input as BrazilCorporateTaxInput,
53
+ Rules as BrazilCorporateTaxRules,
54
+ Result as BrazilCorporateTaxResult,
55
+ } from './brazil/domain/types';
56
+
57
+ import { SpainCorporateTaxServiceImpl as SpainCorporateTaxService } from './spain/SpainCorporateTaxServiceImpl';
58
+ import {
59
+ Input as SpainCorporateTaxInput,
60
+ Rules as SpainCorporateTaxRules,
61
+ Result as SpainCorporateTaxResult,
62
+ } from './spain/domain/types';
63
+
64
+ import { IndiaCorporateTaxServiceImpl as IndiaCorporateTaxService } from './india/IndiaCorporateTaxServiceImpl';
65
+ import {
66
+ Input as IndiaCorporateTaxInput,
67
+ Rules as IndiaCorporateTaxRules,
68
+ Result as IndiaCorporateTaxResult,
69
+ } from './india/domain/types';
70
+
71
+ import { JapanCorporateTaxServiceImpl as JapanCorporateTaxService } from './japan/JapanCorporateTaxServiceImpl';
72
+ import {
73
+ Input as JapanCorporateTaxInput,
74
+ Rules as JapanCorporateTaxRules,
75
+ Result as JapanCorporateTaxResult,
76
+ } from './japan/domain/types';
77
+
50
78
  export {
51
79
  USACorporateTaxService,
52
80
  USACorporateTaxInput,
@@ -75,5 +103,21 @@ export {
75
103
  CanadaCorporateTaxService,
76
104
  CanadaCorporateTaxInput,
77
105
  CanadaCorporateTaxRules,
78
- CanadaCorporateTaxResult
106
+ CanadaCorporateTaxResult,
107
+ BrazilCorporateTaxService,
108
+ BrazilCorporateTaxInput,
109
+ BrazilCorporateTaxRules,
110
+ BrazilCorporateTaxResult,
111
+ SpainCorporateTaxService,
112
+ SpainCorporateTaxInput,
113
+ SpainCorporateTaxRules,
114
+ SpainCorporateTaxResult,
115
+ IndiaCorporateTaxService,
116
+ IndiaCorporateTaxInput,
117
+ IndiaCorporateTaxRules,
118
+ IndiaCorporateTaxResult,
119
+ JapanCorporateTaxService,
120
+ JapanCorporateTaxInput,
121
+ JapanCorporateTaxRules,
122
+ JapanCorporateTaxResult
79
123
  };
@@ -0,0 +1,5 @@
1
+ import { Result } from "./domain/types";
2
+
3
+ export interface IndiaCorporateTaxService {
4
+ calculate(): Result;
5
+ }
@@ -0,0 +1,35 @@
1
+ import { Breakdown } from "../domain/types";
2
+ import { IndiaCorporateTaxService } from "./IndiaCorporateTaxService";
3
+ import { Input, Result, Rules } from "./domain/types";
4
+
5
+ export class IndiaCorporateTaxServiceImpl implements IndiaCorporateTaxService {
6
+ private _input: Input;
7
+ private _rules: Rules;
8
+
9
+ constructor(input: Input, rules: Rules) {
10
+ this._input = input;
11
+ this._rules = rules;
12
+ }
13
+
14
+ calculate(): Result {
15
+ const income = this._input.taxableIncome;
16
+
17
+ if (income <= 0) {
18
+ return { corporateTax: 0, effectiveTaxRate: 0, breakdowns: [] };
19
+ }
20
+
21
+ const tax = income * this._rules.regime.rate;
22
+ const breakdowns: Breakdown[] = [{
23
+ from: '0',
24
+ to: 'All',
25
+ rate: this._rules.regime.rate,
26
+ amount: tax,
27
+ }];
28
+
29
+ return {
30
+ corporateTax: tax,
31
+ effectiveTaxRate: (tax / income) * 100,
32
+ breakdowns,
33
+ };
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ import { Breakdown } from "../../domain/types";
2
+
3
+ export interface Rules {
4
+ regime: { type: 'flat'; rate: number };
5
+ }
6
+
7
+ export interface Input {
8
+ taxableIncome: number;
9
+ }
10
+
11
+ export interface Result {
12
+ corporateTax: number;
13
+ effectiveTaxRate: number;
14
+ breakdowns: Breakdown[];
15
+ }