diff --git a/__tests__/iban.test.ts b/__tests__/iban.test.ts index e69739ee..97adcf3c 100644 --- a/__tests__/iban.test.ts +++ b/__tests__/iban.test.ts @@ -4,157 +4,34 @@ import { TaxForm } from '../src/types/TaxForm' describe('iban', () => { describe('#validate', () => { - describe('mozeZiadatVyplatitDanovyBonus', () => { + describe('mozeZiadatVratitPreplatkyBonusyUroky', () => { const taxFormMock = { - mozeZiadatVyplatitDanovyBonus: true, - mozeZiadatVratitDanovyPreplatok: false, + mozeZiadatVratitPreplatkyBonusyUroky: true, } as TaxForm testValidation(makeValidate(taxFormMock), [ { - input: { ziadamVyplatitDanovyBonus: undefined }, - expected: ['ziadamVyplatitDanovyBonus'], + input: { ziadamVyplatitDanovyBonusUrokPreplatok: undefined }, + expected: ['ziadamVyplatitDanovyBonusUrokPreplatok'], }, - { input: { ziadamVyplatitDanovyBonus: false }, expected: [] }, { - input: { ziadamVyplatitDanovyBonus: true }, - expected: ['iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: true, - iban: 'a', - }, - expected: ['iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: true, - iban: 'SK6807200002891987426353', - }, - expected: [], - }, - ]) - }) - - describe('mozeZiadatVratitDanovyPreplatok', () => { - const taxFormMock = { - mozeZiadatVyplatitDanovyBonus: false, - mozeZiadatVratitDanovyPreplatok: true, - } as TaxForm - - testValidation(makeValidate(taxFormMock), [ - { - input: { ziadamVratitDanovyPreplatok: undefined }, - expected: ['ziadamVratitDanovyPreplatok'], - }, - { input: { ziadamVratitDanovyPreplatok: false }, expected: [] }, - { - input: { ziadamVratitDanovyPreplatok: true }, - expected: ['iban'], - }, - { - input: { - ziadamVratitDanovyPreplatok: true, - iban: 'a', - }, - expected: ['iban'], - }, - { - input: { - ziadamVratitDanovyPreplatok: true, - iban: 'SK6807200002891987426353', - }, - expected: [], - }, - ]) - }) - - describe('mozeZiadatVyplatitDanovyBonus && mozeZiadatVratitDanovyPreplatok', () => { - const taxFormMock = { - mozeZiadatVyplatitDanovyBonus: true, - mozeZiadatVratitDanovyPreplatok: true, - } as TaxForm - - testValidation(makeValidate(taxFormMock), [ - { - input: { - ziadamVyplatitDanovyBonus: undefined, - ziadamVratitDanovyPreplatok: undefined, - }, - expected: [ - 'ziadamVyplatitDanovyBonus', - 'ziadamVratitDanovyPreplatok', - ], - }, - { - input: { - ziadamVyplatitDanovyBonus: undefined, - ziadamVratitDanovyPreplatok: false, - }, - expected: ['ziadamVyplatitDanovyBonus'], - }, - { - input: { - ziadamVyplatitDanovyBonus: false, - ziadamVratitDanovyPreplatok: undefined, - }, - expected: ['ziadamVratitDanovyPreplatok'], - }, - { - input: { - ziadamVyplatitDanovyBonus: false, - ziadamVratitDanovyPreplatok: false, - }, + input: { ziadamVyplatitDanovyBonusUrokPreplatok: false }, expected: [], }, { - input: { - ziadamVyplatitDanovyBonus: undefined, - ziadamVratitDanovyPreplatok: true, - }, - expected: ['ziadamVyplatitDanovyBonus', 'iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: true, - ziadamVratitDanovyPreplatok: undefined, - }, - expected: ['ziadamVratitDanovyPreplatok', 'iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: true, - ziadamVratitDanovyPreplatok: false, - }, - expected: ['iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: false, - ziadamVratitDanovyPreplatok: true, - }, - expected: ['iban'], - }, - { - input: { - ziadamVyplatitDanovyBonus: true, - ziadamVratitDanovyPreplatok: true, - }, + input: { ziadamVyplatitDanovyBonusUrokPreplatok: true }, expected: ['iban'], }, { input: { - ziadamVyplatitDanovyBonus: true, - ziadamVratitDanovyPreplatok: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, iban: 'a', }, expected: ['iban'], }, { input: { - ziadamVyplatitDanovyBonus: true, - ziadamVratitDanovyPreplatok: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, iban: 'SK6807200002891987426353', }, expected: [], diff --git a/__tests__/routes.test.ts b/__tests__/routes.test.ts index 3b6997d1..c3a97f8b 100644 --- a/__tests__/routes.test.ts +++ b/__tests__/routes.test.ts @@ -51,7 +51,7 @@ describe('routes', () => { it('should return routes with children, with iban', () => { expect( getOrderedRoutes({ - mozeZiadatVyplatitDanovyBonus: true, + mozeZiadatVratitPreplatkyBonusyUroky: true, } as TaxForm), ).toStrictEqual([ homeRoute, @@ -75,7 +75,7 @@ describe('routes', () => { it('should return routes without children, with iban', () => { expect( getOrderedRoutes({ - mozeZiadatVyplatitDanovyBonus: true, + mozeZiadatVratitPreplatkyBonusyUroky: true, } as TaxForm), ).toStrictEqual([ homeRoute, @@ -114,7 +114,7 @@ describe('routes', () => { it('should be correct when eligible for refund', () => { const { nextRoute } = getRoutes('/suhrn', { - mozeZiadatVyplatitDanovyBonus: true, + mozeZiadatVratitPreplatkyBonusyUroky: true, } as TaxForm) expect(nextRoute()).toBe('/iban') }) @@ -137,7 +137,7 @@ describe('routes', () => { it('should be correct when eligible for refund', () => { const { previousRoute } = getRoutes('/vysledky', { - mozeZiadatVyplatitDanovyBonus: true, + mozeZiadatVratitPreplatkyBonusyUroky: true, } as TaxForm) expect(previousRoute()).toBe('/iban') }) diff --git a/__tests__/testCases/bugReport6Input.ts b/__tests__/testCases/bugReport6Input.ts index 3d4b218e..f3c7dcf2 100644 --- a/__tests__/testCases/bugReport6Input.ts +++ b/__tests__/testCases/bugReport6Input.ts @@ -58,9 +58,8 @@ export const bugReport6Input: E2eTestUserInput = { r142_obchMeno: '', XIIoddiel_suhlasZaslUdaje: false, iban: 'SK6807200002891987426353', - ziadamVyplatitDanovyBonus: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, datum: '', partner_spolocna_domacnost: true, r006_titul_za: '', - ziadamVratitDanovyPreplatok: true, } diff --git a/__tests__/testCases/withBonusInput.ts b/__tests__/testCases/withBonusInput.ts index fb59678a..2b265894 100644 --- a/__tests__/testCases/withBonusInput.ts +++ b/__tests__/testCases/withBonusInput.ts @@ -48,7 +48,7 @@ export const withBonusInput: E2eTestUserInput = { hasChildren: true, /** SECTION Danovy bonus */ - ziadamVyplatitDanovyBonus: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, iban: 'SK6807200002891987426353', expectNgoDonationValue: false, diff --git a/__tests__/testCases/withEmploymentBonusInput.ts b/__tests__/testCases/withEmploymentBonusInput.ts index 72fa0fc2..60d8f485 100644 --- a/__tests__/testCases/withEmploymentBonusInput.ts +++ b/__tests__/testCases/withEmploymentBonusInput.ts @@ -41,8 +41,7 @@ export const withEmploymentBonusInput: E2eTestUserInput = { }, ], datum: '22.02.2020', - ziadamVyplatitDanovyBonus: false, - ziadamVratitDanovyPreplatok: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, iban: 'SK6807200002891987426353', expectNgoDonationValue: false, diff --git a/__tests__/testCases/withTaxReturnInput.ts b/__tests__/testCases/withTaxReturnInput.ts index f7b96336..053121cd 100644 --- a/__tests__/testCases/withTaxReturnInput.ts +++ b/__tests__/testCases/withTaxReturnInput.ts @@ -19,7 +19,7 @@ export const withTaxReturnInput: E2eTestUserInput = { children: [], /** SECTION Danovy preplatok */ - ziadamVratitDanovyPreplatok: true, + ziadamVyplatitDanovyBonusUrokPreplatok: true, iban: 'SK6807200002891987426353', expectNgoDonationValue: true, diff --git a/cypress/e2e/executeCase.ts b/cypress/e2e/executeCase.ts index e6ac0255..946b51cd 100644 --- a/cypress/e2e/executeCase.ts +++ b/cypress/e2e/executeCase.ts @@ -351,54 +351,32 @@ const executeTestCase = (testCase: string) => { const taxForm = calculate(input) - if (taxForm.mozeZiadatVyplatitDanovyBonus) { + if (taxForm.mozeZiadatVratitPreplatkyBonusyUroky) { /** SECTION IBAN */ assertUrl('/iban') cy.contains( - 'Žiadam o vyplatenie daňového bonusu alebo rozdielu daňového bonusu', + 'Chcete požiadať o vyplatenie daňových bonusov alebo preplatkov vo výške', ) cy.get('[data-test=ineligible-message]').should('not.exist') - if (input.ziadamVyplatitDanovyBonus) { - getInput('ziadamVyplatitDanovyBonus', '-yes').click() + if (input.ziadamVyplatitDanovyBonusUrokPreplatok) { + getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click() typeToInput('iban', input) } else { - getInput('ziadamVyplatitDanovyBonus', '-no').click() + getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click() } - next() - } - - if (taxForm.mozeZiadatVratitDanovyBonusUroky) { - /** SECTION IBAN */ - assertUrl('/iban') - - cy.contains('Žiadam o vyplatenie daňového bonusu na zaplatené úroky') - cy.get('[data-test=ineligible-message]').should('not.exist') - - if (input.ziadamVratitDanovyBonusUroky) { - getInput('ziadamVratitDanovyBonusUroky', '-yes').click() - typeToInput('iban', input) - } else { - getInput('ziadamVratitDanovyBonusUroky', '-no').click() + if (taxForm.mozeZiadatVyplatitDanovyBonus) { + cy.contains('Daňový bonus: ') } - next() - } - - if (taxForm.mozeZiadatVratitDanovyPreplatok) { - /** SECTION IBAN */ - assertUrl('/iban') - - cy.contains('Žiadam o vrátenie daňového preplatku') - cy.get('[data-test=ineligible-message]').should('not.exist') + if (taxForm.mozeZiadatVratitDanovyBonusUroky) { + cy.contains('Daňový bonus na zaplatené úroky: ') + } - if (input.ziadamVratitDanovyPreplatok) { - getInput('ziadamVratitDanovyPreplatok', '-yes').click() - typeToInput('iban', input) - } else { - getInput('ziadamVratitDanovyPreplatok', '-no').click() + if (taxForm.mozeZiadatVratitDanovyPreplatok) { + cy.contains('Daňový preplatok: ') } next() diff --git a/cypress/e2e/pages.spec.ts b/cypress/e2e/pages.spec.ts index b0a24c7e..1225d82e 100644 --- a/cypress/e2e/pages.spec.ts +++ b/cypress/e2e/pages.spec.ts @@ -902,7 +902,7 @@ describe('IBAN page', () => { getError().should('have.length', 1) - getInput('ziadamVyplatitDanovyBonus', '-no').click() + getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-no').click() next() getError().should('have.length', 0) @@ -910,7 +910,7 @@ describe('IBAN page', () => { cy.get('.govuk-back-link').click() getError().should('have.length', 0) - getInput('ziadamVyplatitDanovyBonus', '-yes').click() + getInput('ziadamVyplatitDanovyBonusUrokPreplatok', '-yes').click() getInput('iban').should('exist') next() diff --git a/src/lib/calculation.ts b/src/lib/calculation.ts index f7348365..0d10d003 100644 --- a/src/lib/calculation.ts +++ b/src/lib/calculation.ts @@ -732,6 +732,13 @@ export function calculate(input: TaxFormUserInput): TaxForm { get mozeZiadatVratitDanovyBonusUroky() { return this.r127.gt(0) }, + get mozeZiadatVratitPreplatkyBonusyUroky() { + return ( + this.mozeZiadatVyplatitDanovyBonus || + this.mozeZiadatVratitDanovyPreplatok || + this.mozeZiadatVratitDanovyBonusUroky + ) + }, get r127() { return round(Decimal.max(this.r126.minus(this.r118), 0)) }, @@ -849,9 +856,8 @@ export function calculate(input: TaxFormUserInput): TaxForm { }, /** SECTION Danovy bonus */ - ziadamVyplatitDanovyBonus: input?.ziadamVyplatitDanovyBonus ?? false, - ziadamVratitDanovyPreplatok: input?.ziadamVratitDanovyPreplatok ?? false, - ziadamVratitDanovyBonusUroky: input?.ziadamVratitDanovyBonusUroky ?? false, + ziadamVyplatitDanovyBonusUrokPreplatok: + input?.ziadamVyplatitDanovyBonusUrokPreplatok ?? false, iban: input?.iban ? input?.iban.replace(/\s/g, '') : '', datum: input.datum, diff --git a/src/lib/initialValues.ts b/src/lib/initialValues.ts index 6fc9137c..7006543f 100644 --- a/src/lib/initialValues.ts +++ b/src/lib/initialValues.ts @@ -117,7 +117,7 @@ export const twoPercentInitialValues: TwoPercentUserInput = { export const taxBonusInitialInput: TaxBonusUserInput = { iban: '', - ziadamVyplatitDanovyBonus: undefined, + ziadamVyplatitDanovyBonusUrokPreplatok: undefined, } export const initTaxFormUserInputValues: TaxFormUserInput = { diff --git a/src/lib/routes.ts b/src/lib/routes.ts index bedbedfd..98e4257d 100644 --- a/src/lib/routes.ts +++ b/src/lib/routes.ts @@ -29,10 +29,7 @@ export type Route = export const getOrderedRoutes = (taxForm: TaxForm): ReadonlyArray => { const getIbanRoute = (): Route[] => { - const isIbanRequired = - taxForm.mozeZiadatVyplatitDanovyBonus || - taxForm.mozeZiadatVratitDanovyPreplatok || - taxForm.mozeZiadatVratitDanovyBonusUroky + const isIbanRequired = taxForm.mozeZiadatVratitPreplatkyBonusyUroky return isIbanRequired ? ['/iban'] : [] } diff --git a/src/lib/xml/xmlConverter.ts b/src/lib/xml/xmlConverter.ts index e97add64..1ae4a746 100644 --- a/src/lib/xml/xmlConverter.ts +++ b/src/lib/xml/xmlConverter.ts @@ -214,27 +214,21 @@ export function convertToJson(taxForm: TaxForm): OutputJson { form.dokument.telo.r153 = taxForm.employed || taxForm.dohoda ? '5' : '4' - const maDanovyBonus = - taxForm.mozeZiadatVyplatitDanovyBonus && taxForm.ziadamVyplatitDanovyBonus - const maDanovyBonusUroky = - taxForm.mozeZiadatVratitDanovyBonusUroky && - taxForm.ziadamVratitDanovyBonusUroky - const maDanovyPreplatok = - taxForm.mozeZiadatVratitDanovyPreplatok && - taxForm.ziadamVratitDanovyPreplatok - - if (maDanovyBonus || maDanovyPreplatok || maDanovyBonusUroky) { + if ( + taxForm.mozeZiadatVratitPreplatkyBonusyUroky && + taxForm.ziadamVyplatitDanovyBonusUrokPreplatok + ) { form.dokument.telo.danovyPreplatokBonus.bankovyUcet.IBAN = taxForm.iban form.dokument.telo.danovyPreplatokBonus.datum = taxForm.datum form.dokument.telo.danovyPreplatokBonus.sposobPlatby.ucet = '1' - if (taxForm.ziadamVyplatitDanovyBonus) { + if (taxForm.mozeZiadatVyplatitDanovyBonus) { form.dokument.telo.danovyPreplatokBonus.vyplatitDanovyBonus = '1' } - if (taxForm.ziadamVratitDanovyPreplatok) { + if (taxForm.mozeZiadatVratitDanovyPreplatok) { form.dokument.telo.danovyPreplatokBonus.vratitDanPreplatok = '1' } - if (taxForm.ziadamVratitDanovyBonusUroky) { + if (taxForm.mozeZiadatVratitDanovyBonusUroky) { form.dokument.telo.danovyPreplatokBonus.vyplatitDanovyBonusUroky = '1' } } diff --git a/src/pages/iban.tsx b/src/pages/iban.tsx index ae21c7bf..41487947 100644 --- a/src/pages/iban.tsx +++ b/src/pages/iban.tsx @@ -5,6 +5,7 @@ import { Form, FormikProps } from 'formik' import { ErrorSummary } from '../components/ErrorSummary' import { BooleanRadio, FormWrapper, Input } from '../components/FormComponents' import { + formatCurrency, formatIban, validateIbanCountry, validateIbanFormat, @@ -22,11 +23,35 @@ const Iban: Page = ({ previousRoute, nextRoute, }) => { - if ( - !taxForm.mozeZiadatVyplatitDanovyBonus && - !taxForm.mozeZiadatVratitDanovyPreplatok && - !taxForm.mozeZiadatVratitDanovyBonusUroky - ) { + const danovyBonus = taxForm.r121 + const danovyBonusUroky = taxForm.r127 + const danovyPreplatok = taxForm.r136_danovy_preplatok + const spolu = danovyBonus.plus(danovyBonusUroky).plus(danovyPreplatok) + + const Preplatky = ( + + ) + + if (!taxForm.mozeZiadatVratitPreplatkyBonusyUroky) { return ( <>

@@ -51,17 +76,12 @@ const Iban: Page = ({ initialValues={taxFormUserInput} validate={makeValidate(taxForm)} onSubmit={(values) => { - const userInput = - values.ziadamVyplatitDanovyBonus || - values.ziadamVratitDanovyPreplatok || - values.ziadamVratitDanovyBonusUroky - ? values - : { - ...taxBonusInitialInput, - ziadamVyplatitDanovyBonus: false, - ziadamVratitDanovyPreplatok: false, - ziadamVratitDanovyBonusUroky: false, - } + const userInput = values.ziadamVyplatitDanovyBonusUrokPreplatok + ? values + : { + ...taxBonusInitialInput, + ziadamVyplatitDanovyBonusziadamVyplatitDanovyBonus: false, + } setTaxFormUserInput(userInput) router.push(nextRoute) }} @@ -72,30 +92,17 @@ const Iban: Page = ({

errors={errors} /> - {taxForm.mozeZiadatVyplatitDanovyBonus && ( - - )} - - {taxForm.mozeZiadatVratitDanovyPreplatok && ( - - )} - - {taxForm.mozeZiadatVratitDanovyBonusUroky && ( + {taxForm.mozeZiadatVratitPreplatkyBonusyUroky && ( )} - {(values.ziadamVyplatitDanovyBonus || - values.ziadamVratitDanovyPreplatok || - values.ziadamVratitDanovyBonusUroky) && ( + {values.ziadamVyplatitDanovyBonusUrokPreplatok && ( > = {} if ( - taxForm.mozeZiadatVyplatitDanovyBonus && - typeof values.ziadamVyplatitDanovyBonus === 'undefined' - ) { - errors.ziadamVyplatitDanovyBonus = 'Vyznačte odpoveď na daňový bonus' - } - - if ( - taxForm.mozeZiadatVratitDanovyPreplatok && - typeof values.ziadamVratitDanovyPreplatok === 'undefined' + taxForm.mozeZiadatVratitPreplatkyBonusyUroky && + typeof values.ziadamVyplatitDanovyBonusUrokPreplatok === 'undefined' ) { - errors.ziadamVratitDanovyPreplatok = - 'Vyznačte odpoveď na daňový preplatok' + errors.ziadamVyplatitDanovyBonusUrokPreplatok = + 'Vyznačte odpoveď na daňový bonus alebo preplatok' } - if ( - taxForm.mozeZiadatVratitDanovyBonusUroky && - typeof values.ziadamVratitDanovyBonusUroky === 'undefined' - ) { - errors.ziadamVratitDanovyBonusUroky = 'Vyznačte odpoveď na daňový bonus' - } - - if ( - values.ziadamVyplatitDanovyBonus || - values.ziadamVratitDanovyPreplatok || - values.ziadamVratitDanovyBonusUroky - ) { + if (values.ziadamVyplatitDanovyBonusUrokPreplatok) { if (!values.iban || values.iban === '') { // Medzinárodné bankové číslo účtu (angl. International Bank Account Number, skr. IBAN) errors.iban = 'Zadajte váš IBAN' diff --git a/src/types/PageUserInputs.ts b/src/types/PageUserInputs.ts index 5a81174a..46f41aba 100644 --- a/src/types/PageUserInputs.ts +++ b/src/types/PageUserInputs.ts @@ -129,10 +129,7 @@ export type TwoPercentUserInput = Pick< export type TaxBonusUserInput = Pick< TaxFormUserInput, - | 'ziadamVyplatitDanovyBonus' - | 'ziadamVratitDanovyPreplatok' - | 'ziadamVratitDanovyBonusUroky' - | 'iban' + 'ziadamVyplatitDanovyBonusUrokPreplatok' | 'iban' > export type IncomeSourceCountryUserInput = Pick< diff --git a/src/types/TaxForm.ts b/src/types/TaxForm.ts index 6b5d60ee..b8de6656 100644 --- a/src/types/TaxForm.ts +++ b/src/types/TaxForm.ts @@ -242,11 +242,10 @@ export interface TaxForm { /** SECTION Danovy bonus */ mozeZiadatVyplatitDanovyBonus: boolean - ziadamVyplatitDanovyBonus: boolean mozeZiadatVratitDanovyPreplatok: boolean - ziadamVratitDanovyPreplatok: boolean mozeZiadatVratitDanovyBonusUroky: boolean - ziadamVratitDanovyBonusUroky: boolean + mozeZiadatVratitPreplatkyBonusyUroky: boolean + ziadamVyplatitDanovyBonusUrokPreplatok: boolean iban: string /** Helper properties from input, that are not part of taxForm */ diff --git a/src/types/TaxFormUserInput.ts b/src/types/TaxFormUserInput.ts index c03f2b44..2baec663 100644 --- a/src/types/TaxFormUserInput.ts +++ b/src/types/TaxFormUserInput.ts @@ -132,6 +132,7 @@ export interface TaxFormUserInput { ziadamVyplatitDanovyBonus?: boolean ziadamVratitDanovyPreplatok?: boolean ziadamVratitDanovyBonusUroky?: boolean + ziadamVyplatitDanovyBonusUrokPreplatok?: boolean iban?: string /** Musi byt sucastou user inputu, aj ked sa generuje automaticky, inac by