Skip to content

Commit

Permalink
feature: update to 2024 tax specs
Browse files Browse the repository at this point in the history
  • Loading branch information
acalvo committed Oct 6, 2024
1 parent 2147bc9 commit 2cc5f70
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/components/irpf-selector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LitElement, PropertyValues, css, html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { inputCheckboxStyles, inputNumberStyles } from '../shared-styles';
import { IRPF_TABLE } from '../taxes-2024';
import { classMap } from 'lit/directives/class-map.js';
import irpfTable from '../irpf-table';

@customElement('irpf-selector')
export class IrpfSelector extends LitElement {
Expand Down Expand Up @@ -41,7 +41,7 @@ export class IrpfSelector extends LitElement {

willUpdate(changedProperties: PropertyValues<this>) {
if (this.automatic) {
const level = irpfTable[Object.keys(irpfTable).find((t) => Number(t) >= this.salary)];
const level = IRPF_TABLE[Object.keys(IRPF_TABLE).find((t) => Number(t) >= this.salary)];
this.irpf = level[this.descendants] ?? level[level.length - 1];
}
if (changedProperties.has('irpf')) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/net-salary-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './gross-salary-selector';
import './irpf-selector';
import './payments-selector';
import { LitElement, css, html } from 'lit';
import { MAXIMUM_SS_ANNUAL_QUOTE, SS_CONTRIBUTION_RATE } from '../taxes-2024';
import { customElement, state } from 'lit/decorators.js';

@customElement('net-salary-calculator')
Expand Down Expand Up @@ -41,8 +42,6 @@ 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) {
Expand All @@ -59,7 +58,7 @@ export class NetSalaryCalculator extends LitElement {

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

Expand Down
39 changes: 0 additions & 39 deletions src/irpf-table.ts

This file was deleted.

43 changes: 43 additions & 0 deletions src/taxes-2024.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const SS_CONTRIBUTION_RATE = 0.0647;

export const MAXIMUM_SS_ANNUAL_QUOTE = 4720.50 * 12;

export const IRPF_TABLE = {
14000: [0],
15410: [5, 3, 0],
16230: [6, 4, 1, 0],
17370: [7, 5, 3, 0],
18680: [8, 6, 4, 0],
19970: [9, 7, 5, 2, 0],
21520: [10, 8, 6, 3, 0],
23350: [11, 10, 8, 5, 1, 0],
24970: [12, 11, 9, 6, 3, 0],
26930: [13, 12, 10, 7, 4, 0],
29260: [14, 13, 11, 9, 6, 2, 0],
32010: [15, 14, 13, 10, 8, 4, 0],
35330: [16, 15, 14, 12, 9, 6, 0],
39900: [17, 16, 15, 13, 11, 8, 0],
43590: [18, 17, 16, 15, 13, 10, 2],
46980: [19, 18, 17, 16, 14, 12, 4],
50950: [20, 19, 18, 17, 15, 13, 7],
55350: [21, 20, 20, 18, 17, 15, 9],
59890: [22, 21, 21, 19, 18, 16, 11],
63800: [23, 22, 22, 21, 19, 18, 12],
68040: [24, 23, 23, 22, 21, 19, 14],
72840: [25, 25, 24, 23, 22, 20, 16],
78390: [26, 26, 25, 24, 23, 22, 17],
84410: [27, 27, 26, 25, 24, 23, 19],
89690: [28, 28, 27, 26, 25, 24, 20],
95680: [29, 29, 28, 27, 27, 25, 22],
102280: [30, 30, 29, 29, 28, 27, 23],
110120: [31, 31, 30, 30, 29, 28, 25],
118780: [32, 32, 31, 31, 30, 29, 26],
128700: [33, 33, 32, 32, 31, 30, 28],
139880: [34, 34, 33, 33, 32, 32, 29],
153200: [35, 35, 34, 34, 33, 33, 31],
167790: [36, 36, 36, 35, 35, 34, 32],
185460: [37, 37, 37, 36, 36, 35, 33],
207280: [38, 38, 38, 37, 37, 36, 35],
230150: [39, 39, 39, 38, 38, 37, 36],
Infinity: [40, 40, 40, 39, 39, 39, 37],
};
8 changes: 4 additions & 4 deletions test/irpf-selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('irpf-selector', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(detail.irpf).to.equal(21);
expect(irpfInput.value).to.equal('21');
expect(detail.irpf).to.equal(20);
expect(irpfInput.value).to.equal('20');
});

it('50000 salary, automatic irpf, 4 descendants', async () => {
Expand All @@ -50,8 +50,8 @@ describe('irpf-selector', () => {
while (el.isUpdatePending) {
await el.updateComplete;
}
expect(detail.irpf).to.equal(17);
expect(irpfInput.value).to.equal('17');
expect(detail.irpf).to.equal(15);
expect(irpfInput.value).to.equal('15');
});

it('50000 salary, 20% IRPF', async () => {
Expand Down
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('1392,50');
expect(el.shadowRoot.innerHTML).contains('1392,17');
});

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('2215,71');
expect(el.shadowRoot.innerHTML).contains('2215,14');
});

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('3760,04');
expect(el.shadowRoot.innerHTML).contains('3744,58');
});

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('4037,18');
expect(el.shadowRoot.innerHTML).contains('4023,93');
});

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('52.499.710,04');
expect(el.shadowRoot.innerHTML).contains('52.499.694,58');
});
});
});

0 comments on commit 2cc5f70

Please sign in to comment.