Skip to content

Commit

Permalink
map partner data to output
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekVigas committed Feb 7, 2024
1 parent b2367cf commit 90cdc89
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
34 changes: 30 additions & 4 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,33 @@ 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.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',
}
}

export function calculate(input: TaxFormUserInput): TaxForm {
/** Combine default vaules with user input */
return {
Expand Down Expand Up @@ -156,12 +184,10 @@ export function calculate(input: TaxFormUserInput): TaxForm {
},

get r034() {
return null
return mapPartnerChildBonus(input)
},

get r034a() {
return new Decimal(0)
},
r034a: new Decimal(parseInputNumber(input?.r034a ?? '0')),

/** SECTION Mortgage NAMES ARE WRONG TODO*/
// r037_uplatnuje_uroky: input?.r037_uplatnuje_uroky ?? false,
Expand Down
17 changes: 17 additions & 0 deletions src/lib/xml/xmlConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ export function convertToJson(taxForm: TaxForm): OutputJson {
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)
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/types/TaxForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export interface Child {
interface Partner {
priezviskoMeno: string
rodneCislo: string
m00: string
m01: string
m02: string
m03: string
m04: string
m05: string
m06: string
m07: string
m08: string
m09: string
m10: string
m11: string
m12: string
druhaOsobaPodalaDPvSR: string
dokladRocZuct: string
dokladVyskaDane: string
m00: boolean
m01: boolean
m02: boolean
m03: boolean
m04: boolean
m05: boolean
m06: boolean
m07: boolean
m08: boolean
m09: boolean
m10: boolean
m11: boolean
m12: boolean
druhaOsobaPodalaDPvSR: boolean
dokladRocZuct: boolean
dokladVyskaDane: boolean
}

export interface TaxForm {
Expand Down

0 comments on commit 90cdc89

Please sign in to comment.