Skip to content

Commit

Permalink
feature: update to 2023 tax specs
Browse files Browse the repository at this point in the history
  • Loading branch information
acalvo committed Sep 9, 2023
1 parent 06a6101 commit 2147bc9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
17 changes: 12 additions & 5 deletions src/components/net-salary-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,28 @@ export class NetSalaryCalculator extends LitElement {
@state()
payments = 12;

MAXIMUM_SS_ANNUAL_QUOTE = 4495.50 * 12;
SS_CONTRIBUTION_RATE = 0.0645;
netSalary = 0;

private setSalary(event: CustomEvent) {
this.salary = event.detail.salary;
}

private setIrpf(event: CustomEvent) {
this.irpf = event.detail.irpf;
this.irpf = event.detail.irpf / 100;
}

private setPayments(event: CustomEvent) {
this.payments = event.detail.payments;
}

willUpdate() {
const irpfContribution = this.salary * this.irpf;
const socialSecurityContribution = Math.min(this.salary, this.MAXIMUM_SS_ANNUAL_QUOTE) * this.SS_CONTRIBUTION_RATE;
this.netSalary = (this.salary - irpfContribution - socialSecurityContribution) / this.payments;
}

render() {
return html`
<div>
Expand All @@ -67,10 +77,7 @@ export class NetSalaryCalculator extends LitElement {
<hr>
<p>
Sueldo neto mensual:
<strong>${((1 - this.irpf / 100 - 0.0635) * this.salary / this.payments).toLocaleString('es', {
maximumFractionDigits: 2,
minimumFractionDigits: 2
})}&nbsp;€</strong>
<strong>${this.netSalary.toLocaleString('es', { style: 'currency', currency: 'EUR' })}</strong>
</p>
`;
}
Expand Down
70 changes: 35 additions & 35 deletions src/irpf-table.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
export default {
14000: [0],
15070: [5, 3, 0],
15830: [6, 4, 2, 0],
16880: [7, 5, 3, 0],
18150: [8, 6, 4, 0],
19540: [9, 7, 5, 2, 0],
21050: [10, 8, 7, 3, 0],
22760: [11, 10, 8, 5, 1, 0],
24070: [12, 11, 9, 6, 3, 0],
26080: [13, 12, 10, 8, 4, 0],
28330: [14, 13, 11, 9, 6, 2, 0],
30990: [15, 14, 13, 10, 8, 4, 0],
34210: [16, 15, 14, 12, 9, 6, 0],
38650: [17, 16, 15, 13, 11, 8, 0],
42060: [18, 17, 16, 15, 13, 10, 3],
45340: [19, 18, 17, 16, 15, 12, 5],
49170: [20, 19, 18, 17, 15, 13, 7],
52920: [21, 20, 20, 18, 17, 15, 9],
57270: [22, 21, 21, 19, 18, 16, 11],
60980: [23, 22, 22, 21, 19, 18, 12],
65050: [24, 23, 23, 22, 21, 19, 14],
69670: [25, 25, 24, 23, 22, 20, 16],
74950: [26, 26, 25, 24, 23, 22, 17],
80720: [27, 27, 26, 25, 24, 23, 19],
85740: [28, 28, 27, 26, 25, 24, 20],
91450: [29, 29, 28, 27, 27, 25, 22],
97970: [30, 30, 29, 29, 28, 27, 23],
105500: [31, 31, 30, 30, 29, 28, 25],
113490: [32, 32, 31, 31, 30, 29, 26],
122900: [33, 33, 32, 32, 31, 30, 28],
134030: [34, 34, 33, 33, 32, 32, 29],
146790: [35, 35, 34, 34, 33, 33, 31],
160770: [36, 36, 36, 35, 35, 34, 32],
177700: [37, 37, 37, 36, 36, 35, 33],
198600: [38, 38, 38, 37, 37, 36, 35],
220450: [39, 39, 39, 38, 38, 37, 36],
15220: [5, 3, 0],
15980: [6, 4, 1, 0],
17090: [7, 5, 3, 0],
18380: [8, 6, 4, 0],
19730: [9, 7, 5, 2, 0],
21260: [10, 8, 7, 3, 0],
23020: [11, 10, 8, 5, 1, 0],
24340: [12, 11, 9, 6, 3, 0],
26450: [13, 12, 10, 7, 4, 0],
28730: [14, 13, 11, 9, 6, 2, 0],
31440: [15, 14, 13, 10, 8, 4, 0],
34700: [16, 15, 14, 12, 9, 6, 0],
39200: [17, 16, 15, 13, 11, 8, 0],
42730: [18, 17, 16, 15, 13, 10, 2],
46060: [19, 18, 17, 16, 14, 12, 5],
49950: [20, 19, 18, 17, 15, 13, 7],
54440: [21, 20, 20, 18, 17, 15, 9],
58910: [22, 21, 21, 19, 18, 16, 11],
62530: [23, 22, 22, 21, 19, 18, 12],
66690: [24, 23, 23, 22, 21, 19, 14],
71430: [25, 25, 24, 23, 22, 20, 16],
76990: [26, 26, 25, 24, 23, 22, 17],
82800: [27, 27, 26, 25, 24, 23, 19],
87810: [28, 28, 27, 26, 25, 24, 20],
93650: [29, 29, 28, 27, 27, 25, 22],
100330: [30, 30, 29, 29, 28, 27, 23],
108030: [31, 31, 30, 30, 29, 28, 25],
116500: [32, 32, 31, 31, 30, 29, 26],
125820: [33, 33, 32, 32, 31, 30, 28],
137200: [34, 34, 33, 33, 32, 32, 29],
150220: [35, 35, 34, 34, 33, 33, 31],
164530: [36, 36, 36, 35, 35, 34, 32],
181840: [37, 37, 37, 36, 36, 35, 33],
203240: [38, 38, 38, 37, 37, 36, 35],
225470: [39, 39, 39, 38, 38, 37, 36],
Infinity: [40, 40, 40, 39, 39, 39, 37],
};
10 changes: 5 additions & 5 deletions test/net-salary-calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('net-salary-calculator', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(el.shadowRoot.innerHTML).contains('1394,17');
expect(el.shadowRoot.innerHTML).contains('1392,50');
});

it('40000 salary, automatic IPRF, 2 descendants, 14 payments', async () => {
Expand All @@ -63,7 +63,7 @@ describe('net-salary-calculator', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(el.shadowRoot.innerHTML).contains('2218,57');
expect(el.shadowRoot.innerHTML).contains('2215,71');
});

it('60000 salary, automatic IPRF, 4 descendants, 12 payments', async () => {
Expand All @@ -78,7 +78,7 @@ describe('net-salary-calculator', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(el.shadowRoot.innerHTML).contains('3732,50');
expect(el.shadowRoot.innerHTML).contains('3760,04');
});

it('80000 salary, 25% IPRF, 14 payments', async () => {
Expand All @@ -99,7 +99,7 @@ describe('net-salary-calculator', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(el.shadowRoot.innerHTML).contains('3922,86');
expect(el.shadowRoot.innerHTML).contains('4037,18');
});

it('1000000000 salary, automatic IRPF, 100 descendants, 12 payments', async () => {
Expand All @@ -114,7 +114,7 @@ describe('net-salary-calculator', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(el.shadowRoot.innerHTML).contains('47.208.333,33');
expect(el.shadowRoot.innerHTML).contains('52.499.710,04');
});
});
});

0 comments on commit 2147bc9

Please sign in to comment.