Skip to content

Commit

Permalink
Child bonus partner (#841)
Browse files Browse the repository at this point in the history
* danovy bonus na deti partner

* clean up ts

* add all required inputs

* remove debug

* map partner data to output

* add riadok 116a

* add calc for partner bonus

* fix validation of rodne cislo

* fix 116a ak nie je partner

* skip partner bonus if not in tesst spec

* fix cypress for partner child bonus
  • Loading branch information
MarekVigas authored Feb 7, 2024
1 parent 60a1603 commit cd05a9f
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 37 deletions.
14 changes: 12 additions & 2 deletions cypress/e2e/executeCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,22 @@ const executeTestCase = (testCase: string) => {
cy.get('[data-test="add-child"]').click()
}
})
next()
cy.url().then(url => {
if (input.partner_bonus_na_deti) {

} else {
if (!url.includes('/dochodok')) {
getInput('partner_bonus_na_deti', '-no').click()
next()
}
}
});
} else {
getInput('hasChildren', '-no').click()
next()
}

next()

/** SECTION Dochodok */
assertUrl('/dochodok')

Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ describe('Children page', () => {
withChildrenInput.children?.[0]?.rodneCislo ?? '',
)

next()
getInput('partner_bonus_na_deti', '-no').click()

next()
assertUrl('/dochodok')
})
Expand Down Expand Up @@ -524,6 +527,8 @@ describe('Children page', () => {
// Remove 2rd child
cy.get('[data-test="remove-child-2"]').click()

next()
getInput('partner_bonus_na_deti', '-no').click()
next()
assertUrl('/dochodok')
})
Expand Down
58 changes: 53 additions & 5 deletions src/lib/calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Decimal from 'decimal.js'
import { validatePartnerBonusForm } from './validatePartnerBonusForm'
import { Summary } from '../types/Summary'
import { optionWithValue } from '../components/FormComponents'
import { ChildrenUserInput } from '../types/PageUserInputs'

const NEZDANITELNA_CAST_ZAKLADU = new Decimal(4922.82)
// NEZDANITELNA_CAST_JE_NULA_AK_JE_ZAKLAD_DANE_VYSSI_AKO
Expand Down Expand Up @@ -83,6 +84,34 @@ const makeMapChild =
}
}

const mapPartnerChildBonus = (input: ChildrenUserInput) => {
const wholeYear = input.partner_bonus_na_deti_od === '0' && input.partner_bonus_na_deti_do === '11'
const monthFrom = Number.parseInt(input.partner_bonus_na_deti_od, 10)
const monthTo = Number.parseInt(input.partner_bonus_na_deti_do, 10)

return {
priezviskoMeno: input.r034_priezvisko_a_meno,
rodneCislo: input.r034_rodne_cislo ? input.r034_rodne_cislo.replace(/\D/g, '') : '',
m00: wholeYear,
m01: !wholeYear && monthFrom === 0,
m02: !wholeYear && monthFrom <= 1 && monthTo >= 1,
m03: !wholeYear && monthFrom <= 2 && monthTo >= 2,
m04: !wholeYear && monthFrom <= 3 && monthTo >= 3,
m05: !wholeYear && monthFrom <= 4 && monthTo >= 4,
m06: !wholeYear && monthFrom <= 5 && monthTo >= 5,
m07: !wholeYear && monthFrom <= 6 && monthTo >= 6,
m08: !wholeYear && monthFrom <= 7 && monthTo >= 7,
m09: !wholeYear && monthFrom <= 8 && monthTo >= 8,
m10: !wholeYear && monthFrom <= 9 && monthTo >= 9,
m11: !wholeYear && monthFrom <= 10 && monthTo >= 10,
m12: !wholeYear && monthTo === 11,
druhaOsobaPodalaDPvSR: input.partner_bonus_na_deti_typ_prijmu === '1' || input.partner_bonus_na_deti_typ_prijmu === '2',
dokladRocZuct: input.partner_bonus_na_deti_typ_prijmu === '3',
dokladVyskaDane: input.partner_bonus_na_deti_typ_prijmu === '4',
pocetMesiacov: monthTo - monthFrom + 1
}
}

export function calculate(input: TaxFormUserInput): TaxForm {
/** Combine default vaules with user input */
return {
Expand Down Expand Up @@ -151,14 +180,16 @@ export function calculate(input: TaxFormUserInput): TaxForm {
return input.children.map((child) => mapChild(child))
},

get r034() {
return null
get partner_bonus_na_deti() {
return input.partner_bonus_na_deti
},

get r034a() {
return new Decimal(0)
get r034() {
return mapPartnerChildBonus(input)
},

r034a: new Decimal(parseInputNumber(input?.r034a ?? '0')),

/** SECTION Mortgage NAMES ARE WRONG TODO*/
// r037_uplatnuje_uroky: input?.r037_uplatnuje_uroky ?? false,
// r037_zaplatene_uroky: new Decimal(
Expand Down Expand Up @@ -401,6 +432,18 @@ export function calculate(input: TaxFormUserInput): TaxForm {
get r116_dan() {
return round(this.r090.plus(this.r105))
},
get r116a(){
if (this.partner_bonus_na_deti) {
if (this.r034.pocetMesiacov === 12) {
return this.r034a.plus(this.r038).plus(this.r045)
} else {
const partner = round(this.r034a.dividedBy(12)).times(this.r034.pocetMesiacov)
return this.r038.plus(this.r045).plus(partner)
}
} else {
return new Decimal(0)
}
},
get danovyBonusNaDieta() {
const months = [
Months.January,
Expand Down Expand Up @@ -449,7 +492,12 @@ export function calculate(input: TaxFormUserInput): TaxForm {
}
}

let zakladDane = this.r038.plus(this.r045)
let zakladDane
if (this.partner_bonus_na_deti){
zakladDane = this.r116a
} else {
zakladDane = this.r038.plus(this.r045)
}

zakladDane = zakladDane.toDecimalPlaces(2, Decimal.ROUND_UP)
const percentLimit = getPercentualnyLimitNaDeti(monthGroup[0].count)
Expand Down
5 changes: 5 additions & 0 deletions src/lib/initialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export const makeEmptyChild = (): ChildInput => ({

export const childrenUserInputInitialValues: ChildrenUserInput = {
hasChildren: undefined,
partner_bonus_na_deti: undefined,
partner_bonus_na_deti_typ_prijmu: "0",
partner_bonus_na_deti_od: "",
partner_bonus_na_deti_do: "",
r034a: '',
children: [makeEmptyChild()]
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/xml/outputBasis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ const sampleSchema: OutputJson = {
r114: '',
r115: '',
r116: '',
r116a: '',
r117: '',
r118: '',
r119: '',
Expand Down
23 changes: 22 additions & 1 deletion src/lib/xml/xmlConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,28 @@ export function convertToJson(taxForm: TaxForm): OutputJson {
]),
)
}) as Dieta[]
if (taxForm.partner_bonus_na_deti) {
form.dokument.telo.uplatnujemPar33Ods8 = boolToString(taxForm.partner_bonus_na_deti)
form.dokument.telo.r34a = decimalToString(taxForm.r034a)
form.dokument.telo.r34.priezviskoMeno = taxForm.r034.priezviskoMeno
form.dokument.telo.r34.rodneCislo = taxForm.r034.rodneCislo
form.dokument.telo.r34.m00 = boolToString(taxForm.r034.m00)
form.dokument.telo.r34.m01 = boolToString(taxForm.r034.m01)
form.dokument.telo.r34.m02 = boolToString(taxForm.r034.m02)
form.dokument.telo.r34.m03 = boolToString(taxForm.r034.m03)
form.dokument.telo.r34.m04 = boolToString(taxForm.r034.m04)
form.dokument.telo.r34.m05 = boolToString(taxForm.r034.m05)
form.dokument.telo.r34.m06 = boolToString(taxForm.r034.m06)
form.dokument.telo.r34.m07 = boolToString(taxForm.r034.m07)
form.dokument.telo.r34.m08 = boolToString(taxForm.r034.m08)
form.dokument.telo.r34.m09 = boolToString(taxForm.r034.m09)
form.dokument.telo.r34.m10 = boolToString(taxForm.r034.m10)
form.dokument.telo.r34.m11 = boolToString(taxForm.r034.m11)
form.dokument.telo.r34.dokladRocZuct = boolToString(taxForm.r034.dokladRocZuct)
form.dokument.telo.r34.dokladVyskaDane = boolToString(taxForm.r034.dokladVyskaDane)
form.dokument.telo.r34.druhaOsobaPodalaDPvSR = boolToString(taxForm.r034.druhaOsobaPodalaDPvSR)
}
}
form.dokument.telo.r34a = decimalToString(taxForm.r034a)

/** SECTION Mortgage */
// if (taxForm.r037_uplatnuje_uroky) {
Expand Down Expand Up @@ -128,6 +148,7 @@ export function convertToJson(taxForm: TaxForm): OutputJson {
form.dokument.telo.r106 = '0.00'
form.dokument.telo.r115 = '0.00'
form.dokument.telo.r116 = roundDecimal(taxForm.r116_dan)
form.dokument.telo.r116a = decimalToString(taxForm.r116a)
form.dokument.telo.r117 = decimalToString(taxForm.r117)

form.dokument.telo.r118 = roundDecimal(taxForm.r118)
Expand Down
Loading

0 comments on commit cd05a9f

Please sign in to comment.