@novha/calc-engines 2.0.3 → 4.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.
- package/dist/corporate/germany/GermanyCorporateTaxService.js +3 -0
- package/dist/corporate/germany/GermanyCorporateTaxServiceImpl.js +56 -0
- package/dist/corporate/germany/domain/types.js +3 -0
- package/dist/corporate/uk/UKCorporateTaxService.js +3 -0
- package/dist/corporate/uk/UKCorporateTaxServiceImpl.js +70 -0
- package/dist/corporate/uk/domain/types.js +3 -0
- package/dist/corporate/usa/USACorporateTaxService.js +3 -0
- package/dist/corporate/usa/USACorporateTaxServiceImpl.js +29 -0
- package/dist/corporate/usa/domain/types.js +3 -0
- package/dist/income-tax/germany/GermanyIncomeTaxService.js +3 -0
- package/dist/income-tax/germany/GermanyIncomeTaxServiceImpl.js +86 -0
- package/dist/income-tax/germany/domain/types.js +3 -0
- package/dist/income-tax/uk/UKIncomeTaxService.js +3 -0
- package/dist/income-tax/uk/UKIncomeTaxServiceImpl.js +96 -0
- package/dist/income-tax/uk/domain/types.js +3 -0
- package/dist/income-tax/usa/USAIncomeTaxService.js +3 -0
- package/dist/income-tax/usa/USAIncomeTaxServiceImpl.js +87 -0
- package/dist/income-tax/usa/domain/types.js +3 -0
- package/dist/index.js +23 -2
- package/dist/mortgage/germany/GermanyMortgageService.js +3 -0
- package/dist/mortgage/germany/GermanyMortgageServiceImpl.js +80 -0
- package/dist/mortgage/germany/domain/types.js +3 -0
- package/dist/mortgage/uk/UKMortgageService.js +3 -0
- package/dist/mortgage/uk/UKMortgageServiceImpl.js +99 -0
- package/dist/mortgage/uk/domain/types.js +3 -0
- package/dist/mortgage/usa/USAMortgageService.js +3 -0
- package/dist/mortgage/usa/USAMortgageServiceImpl.js +92 -0
- package/dist/mortgage/usa/domain/types.js +3 -0
- package/dist/types/corporate/germany/GermanyCorporateTaxService.d.ts +4 -0
- package/dist/types/corporate/germany/GermanyCorporateTaxServiceImpl.d.ts +8 -0
- package/dist/types/corporate/germany/domain/types.d.ts +24 -0
- package/dist/types/corporate/uk/UKCorporateTaxService.d.ts +4 -0
- package/dist/types/corporate/uk/UKCorporateTaxServiceImpl.d.ts +10 -0
- package/dist/types/corporate/uk/domain/types.d.ts +32 -0
- package/dist/types/corporate/usa/USACorporateTaxService.d.ts +4 -0
- package/dist/types/corporate/usa/USACorporateTaxServiceImpl.d.ts +8 -0
- package/dist/types/corporate/usa/domain/types.d.ts +15 -0
- package/dist/types/income-tax/germany/GermanyIncomeTaxService.d.ts +4 -0
- package/dist/types/income-tax/germany/GermanyIncomeTaxServiceImpl.d.ts +12 -0
- package/dist/types/income-tax/germany/domain/types.d.ts +23 -0
- package/dist/types/income-tax/uk/UKIncomeTaxService.d.ts +4 -0
- package/dist/types/income-tax/uk/UKIncomeTaxServiceImpl.d.ts +12 -0
- package/dist/types/income-tax/uk/domain/types.d.ts +27 -0
- package/dist/types/income-tax/usa/USAIncomeTaxService.d.ts +4 -0
- package/dist/types/income-tax/usa/USAIncomeTaxServiceImpl.d.ts +11 -0
- package/dist/types/income-tax/usa/domain/types.d.ts +30 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/mortgage/germany/GermanyMortgageService.d.ts +4 -0
- package/dist/types/mortgage/germany/GermanyMortgageServiceImpl.d.ts +7 -0
- package/dist/types/mortgage/germany/domain/types.d.ts +42 -0
- package/dist/types/mortgage/uk/UKMortgageService.d.ts +4 -0
- package/dist/types/mortgage/uk/UKMortgageServiceImpl.d.ts +9 -0
- package/dist/types/mortgage/uk/domain/types.d.ts +49 -0
- package/dist/types/mortgage/usa/USAMortgageService.d.ts +4 -0
- package/dist/types/mortgage/usa/USAMortgageServiceImpl.d.ts +8 -0
- package/dist/types/mortgage/usa/domain/types.d.ts +44 -0
- package/package.json +1 -1
- package/src/corporate/germany/GermanyCorporateTaxService.ts +5 -0
- package/src/corporate/germany/GermanyCorporateTaxServiceImpl.ts +64 -0
- package/src/corporate/germany/domain/types.ts +20 -0
- package/src/corporate/uk/UKCorporateTaxService.ts +5 -0
- package/src/corporate/uk/UKCorporateTaxServiceImpl.ts +82 -0
- package/src/corporate/uk/domain/types.ts +38 -0
- package/src/corporate/usa/USACorporateTaxService.ts +5 -0
- package/src/corporate/usa/USACorporateTaxServiceImpl.ts +35 -0
- package/src/corporate/usa/domain/types.ts +15 -0
- package/src/income-tax/germany/GermanyIncomeTaxService.ts +5 -0
- package/src/income-tax/germany/GermanyIncomeTaxServiceImpl.ts +121 -0
- package/src/income-tax/germany/domain/types.ts +27 -0
- package/src/income-tax/uk/UKIncomeTaxService.ts +5 -0
- package/src/income-tax/uk/UKIncomeTaxServiceImpl.ts +133 -0
- package/src/income-tax/uk/domain/types.ts +31 -0
- package/src/income-tax/usa/USAIncomeTaxService.ts +5 -0
- package/src/income-tax/usa/USAIncomeTaxServiceImpl.ts +113 -0
- package/src/income-tax/usa/domain/types.ts +24 -0
- package/src/index.ts +63 -0
- package/src/mortgage/germany/GermanyMortgageService.ts +5 -0
- package/src/mortgage/germany/GermanyMortgageServiceImpl.ts +111 -0
- package/src/mortgage/germany/domain/types.ts +49 -0
- package/src/mortgage/uk/UKMortgageService.ts +5 -0
- package/src/mortgage/uk/UKMortgageServiceImpl.ts +140 -0
- package/src/mortgage/uk/domain/types.ts +58 -0
- package/src/mortgage/usa/USAMortgageService.ts +5 -0
- package/src/mortgage/usa/USAMortgageServiceImpl.ts +134 -0
- package/src/mortgage/usa/domain/types.ts +52 -0
- package/test/australia-income-tax.test.ts +10 -10
- package/test/germany-corporate-tax.test.ts +77 -0
- package/test/germany-income-tax.test.ts +114 -0
- package/test/germany-mortgage.test.ts +105 -0
- package/test/uk-corporate-tax.test.ts +119 -0
- package/test/uk-income-tax.test.ts +146 -0
- package/test/uk-mortgage.test.ts +154 -0
- package/test/usa-corporate-tax.test.ts +59 -0
- package/test/usa-income-tax.test.ts +138 -0
- package/test/usa-mortgage.test.ts +97 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UKIncomeTaxService } from "./UKIncomeTaxService";
|
|
2
|
+
import { ComputedIncomeTaxValues, IncomeTaxRules } from "./domain/types";
|
|
3
|
+
export declare class UKIncomeTaxServiceImpl implements UKIncomeTaxService {
|
|
4
|
+
private _income;
|
|
5
|
+
private _rules;
|
|
6
|
+
constructor(income: number, rules: IncomeTaxRules);
|
|
7
|
+
calculateNetIncome(): ComputedIncomeTaxValues;
|
|
8
|
+
private computePersonalAllowance;
|
|
9
|
+
private computeTaxBrackets;
|
|
10
|
+
private computeNationalInsurance;
|
|
11
|
+
private round;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BracketAllocation, TaxBracket } from "../../domain/types";
|
|
2
|
+
export interface IncomeTaxRules {
|
|
3
|
+
taxBrackets: TaxBracket[];
|
|
4
|
+
personalAllowance: PersonalAllowanceRules;
|
|
5
|
+
nationalInsurance: NationalInsuranceRules;
|
|
6
|
+
}
|
|
7
|
+
export interface PersonalAllowanceRules {
|
|
8
|
+
amount: number;
|
|
9
|
+
taperThreshold: number;
|
|
10
|
+
taperRate: number;
|
|
11
|
+
}
|
|
12
|
+
export interface NationalInsuranceRules {
|
|
13
|
+
primaryThreshold: number;
|
|
14
|
+
upperEarningsLimit: number;
|
|
15
|
+
mainRate: number;
|
|
16
|
+
upperRate: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ComputedIncomeTaxValues {
|
|
19
|
+
grossIncome: number;
|
|
20
|
+
incomeTax: number;
|
|
21
|
+
nationalInsurance: number;
|
|
22
|
+
personalAllowance: number;
|
|
23
|
+
totalDeductions: number;
|
|
24
|
+
netIncome: number;
|
|
25
|
+
effectiveTaxRate: number;
|
|
26
|
+
taxBracketBreakdown: BracketAllocation[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { USAIncomeTaxService } from "./USAIncomeTaxService";
|
|
2
|
+
import { ComputedIncomeTaxValues, IncomeTaxRules } from "./domain/types";
|
|
3
|
+
export declare class USAIncomeTaxServiceImpl implements USAIncomeTaxService {
|
|
4
|
+
private _income;
|
|
5
|
+
private _rules;
|
|
6
|
+
constructor(income: number, rules: IncomeTaxRules);
|
|
7
|
+
calculateNetIncome(): ComputedIncomeTaxValues;
|
|
8
|
+
private computeTaxBrackets;
|
|
9
|
+
private computeFICA;
|
|
10
|
+
private round;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BracketAllocation, TaxBracket } from "../../domain/types";
|
|
2
|
+
export interface IncomeTaxRules {
|
|
3
|
+
taxBrackets: TaxBracket[];
|
|
4
|
+
standardDeduction: {
|
|
5
|
+
amount: number;
|
|
6
|
+
};
|
|
7
|
+
fica: FICAContributionRules;
|
|
8
|
+
}
|
|
9
|
+
export interface FICAContributionRules {
|
|
10
|
+
socialSecurity: {
|
|
11
|
+
rate: number;
|
|
12
|
+
wageBase: number;
|
|
13
|
+
};
|
|
14
|
+
medicare: {
|
|
15
|
+
rate: number;
|
|
16
|
+
additionalRate: number;
|
|
17
|
+
additionalThreshold: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ComputedIncomeTaxValues {
|
|
21
|
+
grossIncome: number;
|
|
22
|
+
incomeTax: number;
|
|
23
|
+
socialSecurity: number;
|
|
24
|
+
medicare: number;
|
|
25
|
+
standardDeduction: number;
|
|
26
|
+
totalDeductions: number;
|
|
27
|
+
netIncome: number;
|
|
28
|
+
effectiveTaxRate: number;
|
|
29
|
+
taxBracketBreakdown: BracketAllocation[];
|
|
30
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,5 +23,23 @@ export { AustraliaMortgageServiceImpl as AustraliaMortgageService } from './mort
|
|
|
23
23
|
export { MortgageRules as AustraliaMortgageRules, MortgageInput as AustraliaMortgageInput, MortgageOutput as AustraliaMortgageOutput, } from './mortgage/australia/domain/types';
|
|
24
24
|
export { AustraliaCorporateTaxServiceImpl as AustraliaCorporateTaxService } from './corporate/australia/AustraliaCorporateTaxServiceImpl';
|
|
25
25
|
export { Input as AustraliaCorporateTaxInput, Rules as AustraliaCorporateTaxRules, Result as AustraliaCorporateTaxResult, } from './corporate/australia/domain/types';
|
|
26
|
+
export { UKIncomeTaxServiceImpl as UKIncomeTaxService } from './income-tax/uk/UKIncomeTaxServiceImpl';
|
|
27
|
+
export { ComputedIncomeTaxValues as UKComputedIncomeTaxValues, IncomeTaxRules as UKIncomeTaxRules, } from './income-tax/uk/domain/types';
|
|
28
|
+
export { UKCorporateTaxServiceImpl as UKCorporateTaxService } from './corporate/uk/UKCorporateTaxServiceImpl';
|
|
29
|
+
export { Input as UKCorporateTaxInput, Rules as UKCorporateTaxRules, Result as UKCorporateTaxResult, } from './corporate/uk/domain/types';
|
|
30
|
+
export { UKMortgageServiceImpl as UKMortgageService } from './mortgage/uk/UKMortgageServiceImpl';
|
|
31
|
+
export { MortgageRules as UKMortgageRules, MortgageInput as UKMortgageInput, MortgageOutput as UKMortgageOutput, } from './mortgage/uk/domain/types';
|
|
32
|
+
export { USAIncomeTaxServiceImpl as USAIncomeTaxService } from './income-tax/usa/USAIncomeTaxServiceImpl';
|
|
33
|
+
export { ComputedIncomeTaxValues as USAComputedIncomeTaxValues, IncomeTaxRules as USAIncomeTaxRules, } from './income-tax/usa/domain/types';
|
|
34
|
+
export { USAMortgageServiceImpl as USAMortgageService } from './mortgage/usa/USAMortgageServiceImpl';
|
|
35
|
+
export { MortgageRules as USAMortgageRules, MortgageInput as USAMortgageInput, MortgageOutput as USAMortgageOutput, } from './mortgage/usa/domain/types';
|
|
36
|
+
export { USACorporateTaxServiceImpl as USACorporateTaxService } from './corporate/usa/USACorporateTaxServiceImpl';
|
|
37
|
+
export { Input as USACorporateTaxInput, Rules as USACorporateTaxRules, Result as USACorporateTaxResult, } from './corporate/usa/domain/types';
|
|
38
|
+
export { GermanyIncomeTaxServiceImpl as GermanyIncomeTaxService } from './income-tax/germany/GermanyIncomeTaxServiceImpl';
|
|
39
|
+
export { ComputedIncomeTaxValues as GermanyComputedIncomeTaxValues, IncomeTaxRules as GermanyIncomeTaxRules, } from './income-tax/germany/domain/types';
|
|
40
|
+
export { GermanyMortgageServiceImpl as GermanyMortgageService } from './mortgage/germany/GermanyMortgageServiceImpl';
|
|
41
|
+
export { MortgageRules as GermanyMortgageRules, MortgageInput as GermanyMortgageInput, MortgageOutput as GermanyMortgageOutput, } from './mortgage/germany/domain/types';
|
|
42
|
+
export { GermanyCorporateTaxServiceImpl as GermanyCorporateTaxService } from './corporate/germany/GermanyCorporateTaxServiceImpl';
|
|
43
|
+
export { Input as GermanyCorporateTaxInput, Rules as GermanyCorporateTaxRules, Result as GermanyCorporateTaxResult, } from './corporate/germany/domain/types';
|
|
26
44
|
export { IncomeTaxCalculatorSchema } from './income-tax/domain/types';
|
|
27
45
|
export * from './income-tax/domain/types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GermanyMortgageService } from "./GermanyMortgageService";
|
|
2
|
+
import { MortgageInput, MortgageOutput, MortgageRules } from "./domain/types";
|
|
3
|
+
export declare class GermanyMortgageServiceImpl implements GermanyMortgageService {
|
|
4
|
+
calculate(input: MortgageInput, rules: MortgageRules): MortgageOutput;
|
|
5
|
+
private calculateAmortizationSchedule;
|
|
6
|
+
private calculatePayment;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OtherFees } from "../../domain/types";
|
|
2
|
+
export interface MortgageRules {
|
|
3
|
+
loanConstraints: LoanConstraints;
|
|
4
|
+
interest: InterestRules;
|
|
5
|
+
landTransferTax: LandTransferTaxRules;
|
|
6
|
+
notaryFeeRate: number;
|
|
7
|
+
registrationFeeRate: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LoanConstraints {
|
|
10
|
+
maxLtvPercent: number;
|
|
11
|
+
maxAmortizationYears: number;
|
|
12
|
+
}
|
|
13
|
+
export interface InterestRules {
|
|
14
|
+
compounding: 'MONTHLY';
|
|
15
|
+
}
|
|
16
|
+
export interface LandTransferTaxRules {
|
|
17
|
+
rate: number;
|
|
18
|
+
}
|
|
19
|
+
export interface AmortizationScheduleItem {
|
|
20
|
+
year: number;
|
|
21
|
+
principal: number;
|
|
22
|
+
interest: number;
|
|
23
|
+
balance: number;
|
|
24
|
+
}
|
|
25
|
+
export interface MortgageInput {
|
|
26
|
+
propertyPrice: number;
|
|
27
|
+
downPayment: number;
|
|
28
|
+
annualInterestRate: number;
|
|
29
|
+
amortizationYears: number;
|
|
30
|
+
}
|
|
31
|
+
export interface MortgageOutput {
|
|
32
|
+
loanAmount: number;
|
|
33
|
+
totalMortgage: number;
|
|
34
|
+
monthlyPayment: number;
|
|
35
|
+
totalInterestPaid: number;
|
|
36
|
+
totalPaid: number;
|
|
37
|
+
landTransferTax: number;
|
|
38
|
+
notaryFees: number;
|
|
39
|
+
registrationFees: number;
|
|
40
|
+
amortizationSchedule: AmortizationScheduleItem[];
|
|
41
|
+
otherFees: OtherFees;
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UKMortgageService } from "./UKMortgageService";
|
|
2
|
+
import { MortgageInput, MortgageOutput, MortgageRules } from "./domain/types";
|
|
3
|
+
export declare class UKMortgageServiceImpl implements UKMortgageService {
|
|
4
|
+
calculate(input: MortgageInput, rules: MortgageRules): MortgageOutput;
|
|
5
|
+
private calculateStampDuty;
|
|
6
|
+
private applyStampDutyBrackets;
|
|
7
|
+
private calculateAmortizationSchedule;
|
|
8
|
+
private calculatePayment;
|
|
9
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OtherFees } from "../../domain/types";
|
|
2
|
+
export interface MortgageRules {
|
|
3
|
+
loanConstraints: LoanConstraints;
|
|
4
|
+
interest: InterestRules;
|
|
5
|
+
stampDuty: StampDutyRules;
|
|
6
|
+
}
|
|
7
|
+
export interface LoanConstraints {
|
|
8
|
+
maxLtvPercent: number;
|
|
9
|
+
maxAmortizationYears: number;
|
|
10
|
+
}
|
|
11
|
+
export interface InterestRules {
|
|
12
|
+
compounding: 'MONTHLY';
|
|
13
|
+
}
|
|
14
|
+
export interface StampDutyBracket {
|
|
15
|
+
upTo?: number;
|
|
16
|
+
above?: number;
|
|
17
|
+
rate: number;
|
|
18
|
+
}
|
|
19
|
+
export interface StampDutyRules {
|
|
20
|
+
standardBrackets: StampDutyBracket[];
|
|
21
|
+
firstTimeBuyer: FirstTimeBuyerStampDuty;
|
|
22
|
+
}
|
|
23
|
+
export interface FirstTimeBuyerStampDuty {
|
|
24
|
+
brackets: StampDutyBracket[];
|
|
25
|
+
maxEligiblePropertyPrice: number;
|
|
26
|
+
}
|
|
27
|
+
export interface AmortizationScheduleItem {
|
|
28
|
+
year: number;
|
|
29
|
+
principal: number;
|
|
30
|
+
interest: number;
|
|
31
|
+
balance: number;
|
|
32
|
+
}
|
|
33
|
+
export interface MortgageInput {
|
|
34
|
+
propertyPrice: number;
|
|
35
|
+
downPayment: number;
|
|
36
|
+
annualInterestRate: number;
|
|
37
|
+
amortizationYears: number;
|
|
38
|
+
isFirstTimeBuyer: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface MortgageOutput {
|
|
41
|
+
loanAmount: number;
|
|
42
|
+
totalMortgage: number;
|
|
43
|
+
monthlyPayment: number;
|
|
44
|
+
totalInterestPaid: number;
|
|
45
|
+
totalPaid: number;
|
|
46
|
+
stampDuty: number;
|
|
47
|
+
amortizationSchedule: AmortizationScheduleItem[];
|
|
48
|
+
otherFees: OtherFees;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { USAMortgageService } from "./USAMortgageService";
|
|
2
|
+
import { MortgageInput, MortgageOutput, MortgageRules } from "./domain/types";
|
|
3
|
+
export declare class USAMortgageServiceImpl implements USAMortgageService {
|
|
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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Breakdown } from "../domain/types";
|
|
2
|
+
import { GermanyCorporateTaxService } from "./GermanyCorporateTaxService";
|
|
3
|
+
import { Input, Result, Rules } from "./domain/types";
|
|
4
|
+
|
|
5
|
+
export class GermanyCorporateTaxServiceImpl implements GermanyCorporateTaxService {
|
|
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 {
|
|
19
|
+
corporateTax: 0,
|
|
20
|
+
solidaritySurcharge: 0,
|
|
21
|
+
tradeTax: 0,
|
|
22
|
+
totalTax: 0,
|
|
23
|
+
effectiveTaxRate: 0,
|
|
24
|
+
breakdowns: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const corporateTax = income * this._rules.corporateIncomeTax.rate;
|
|
29
|
+
const solidaritySurcharge = corporateTax * this._rules.solidaritySurcharge.rate;
|
|
30
|
+
const tradeTax =
|
|
31
|
+
income * this._rules.tradeTax.multiplier * this._rules.tradeTax.assessmentRate;
|
|
32
|
+
const totalTax = corporateTax + solidaritySurcharge + tradeTax;
|
|
33
|
+
|
|
34
|
+
const breakdowns: Breakdown[] = [
|
|
35
|
+
{
|
|
36
|
+
from: '0',
|
|
37
|
+
to: 'All',
|
|
38
|
+
rate: this._rules.corporateIncomeTax.rate,
|
|
39
|
+
amount: corporateTax,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
from: 'Corp Tax',
|
|
43
|
+
to: 'Solidarity',
|
|
44
|
+
rate: this._rules.solidaritySurcharge.rate,
|
|
45
|
+
amount: solidaritySurcharge,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
from: '0',
|
|
49
|
+
to: 'Trade',
|
|
50
|
+
rate: this._rules.tradeTax.multiplier * this._rules.tradeTax.assessmentRate,
|
|
51
|
+
amount: tradeTax,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
corporateTax,
|
|
57
|
+
solidaritySurcharge,
|
|
58
|
+
tradeTax,
|
|
59
|
+
totalTax,
|
|
60
|
+
effectiveTaxRate: (totalTax / income) * 100,
|
|
61
|
+
breakdowns,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Breakdown } from "../../domain/types";
|
|
2
|
+
|
|
3
|
+
export interface Rules {
|
|
4
|
+
corporateIncomeTax: { rate: number };
|
|
5
|
+
solidaritySurcharge: { rate: number };
|
|
6
|
+
tradeTax: { multiplier: number; assessmentRate: number };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Input {
|
|
10
|
+
taxableIncome: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Result {
|
|
14
|
+
corporateTax: number;
|
|
15
|
+
solidaritySurcharge: number;
|
|
16
|
+
tradeTax: number;
|
|
17
|
+
totalTax: number;
|
|
18
|
+
effectiveTaxRate: number;
|
|
19
|
+
breakdowns: Breakdown[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Breakdown } from "../domain/types";
|
|
2
|
+
import { UKCorporateTaxService } from "./UKCorporateTaxService";
|
|
3
|
+
import { Input, MarginalReliefRule, Result, Rules } from "./domain/types";
|
|
4
|
+
|
|
5
|
+
export class UKCorporateTaxServiceImpl implements UKCorporateTaxService {
|
|
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
|
+
const { smallProfits, main, marginalRelief } = this._rules.regimes;
|
|
17
|
+
|
|
18
|
+
let tax = 0;
|
|
19
|
+
let breakdowns: Breakdown[] = [];
|
|
20
|
+
|
|
21
|
+
if (income <= 0) {
|
|
22
|
+
return { corporateTax: 0, effectiveTaxRate: 0, breakdowns: [] };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (income <= marginalRelief.lowerLimit) {
|
|
26
|
+
tax = income * smallProfits.rate;
|
|
27
|
+
breakdowns = [{
|
|
28
|
+
from: '0',
|
|
29
|
+
to: `${marginalRelief.lowerLimit}`,
|
|
30
|
+
rate: smallProfits.rate,
|
|
31
|
+
amount: tax,
|
|
32
|
+
}];
|
|
33
|
+
} else if (income >= marginalRelief.upperLimit) {
|
|
34
|
+
tax = income * main.rate;
|
|
35
|
+
breakdowns = [{
|
|
36
|
+
from: '0',
|
|
37
|
+
to: 'Above',
|
|
38
|
+
rate: main.rate,
|
|
39
|
+
amount: tax,
|
|
40
|
+
}];
|
|
41
|
+
} else {
|
|
42
|
+
tax = this.applyMarginalRelief(income, marginalRelief);
|
|
43
|
+
breakdowns = this.buildMarginalReliefBreakdowns(income, tax, marginalRelief);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
corporateTax: tax,
|
|
48
|
+
effectiveTaxRate: income > 0 ? (tax / income) * 100 : 0,
|
|
49
|
+
breakdowns,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private applyMarginalRelief(income: number, rules: MarginalReliefRule): number {
|
|
54
|
+
const grossTax = income * rules.mainRate;
|
|
55
|
+
const relief = rules.standardFraction * (rules.upperLimit - income);
|
|
56
|
+
return grossTax - relief;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private buildMarginalReliefBreakdowns(
|
|
60
|
+
income: number,
|
|
61
|
+
tax: number,
|
|
62
|
+
rules: MarginalReliefRule,
|
|
63
|
+
): Breakdown[] {
|
|
64
|
+
const grossTax = income * rules.mainRate;
|
|
65
|
+
const relief = rules.standardFraction * (rules.upperLimit - income);
|
|
66
|
+
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
from: '0',
|
|
70
|
+
to: 'Above',
|
|
71
|
+
rate: rules.mainRate,
|
|
72
|
+
amount: grossTax,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
from: `${rules.lowerLimit}`,
|
|
76
|
+
to: `${rules.upperLimit}`,
|
|
77
|
+
rate: -(rules.standardFraction),
|
|
78
|
+
amount: -relief,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Breakdown } from "../../domain/types";
|
|
2
|
+
|
|
3
|
+
export interface FlatTaxRule {
|
|
4
|
+
type: 'flat';
|
|
5
|
+
rate: number;
|
|
6
|
+
conditions?: {
|
|
7
|
+
maxIncome?: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface MarginalReliefRule {
|
|
12
|
+
type: 'marginal_relief';
|
|
13
|
+
mainRate: number;
|
|
14
|
+
smallProfitsRate: number;
|
|
15
|
+
upperLimit: number;
|
|
16
|
+
lowerLimit: number;
|
|
17
|
+
standardFraction: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type TaxRule = FlatTaxRule | MarginalReliefRule;
|
|
21
|
+
|
|
22
|
+
export interface Rules {
|
|
23
|
+
regimes: {
|
|
24
|
+
smallProfits: FlatTaxRule;
|
|
25
|
+
main: FlatTaxRule;
|
|
26
|
+
marginalRelief: MarginalReliefRule;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Input {
|
|
31
|
+
taxableIncome: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Result {
|
|
35
|
+
corporateTax: number;
|
|
36
|
+
effectiveTaxRate: number;
|
|
37
|
+
breakdowns: Breakdown[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Breakdown } from "../domain/types";
|
|
2
|
+
import { USACorporateTaxService } from "./USACorporateTaxService";
|
|
3
|
+
import { Input, Result, Rules } from "./domain/types";
|
|
4
|
+
|
|
5
|
+
export class USACorporateTaxServiceImpl implements USACorporateTaxService {
|
|
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
|
+
}
|