diff --git a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/utils/mappers.ts b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/utils/mappers.ts index 9a17c660c61e..772018808d1f 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/utils/mappers.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/inheritance-report/utils/mappers.ts @@ -92,6 +92,7 @@ export const expandAnswers = ( caseNumber: string } => { return { + applicationFor: answers.applicationFor ?? '', applicant: answers.applicant, executors: { executor: { diff --git a/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx b/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx index b2d8da4456eb..ed9c36f38bc4 100644 --- a/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx +++ b/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx @@ -461,7 +461,7 @@ export const CalculateShare: FC> = ({ title={m.netProperty} value={roundedValueToNumber(netTotal)} /> - + {deceasedWasInCohabitation && ( + ) : customField.id === 'taxFreeInheritance' && - currentHeir?.relation !== - PrePaidHeirsRelationTypes.SPOUSE ? null : ( + ((values.applicationFor === PREPAID_INHERITANCE && + currentHeir?.relation !== RelationSpouse) || + values.applicationFor === ESTATE_INHERITANCE) ? null : ( { return x.relation @@ -66,7 +67,7 @@ export const HeirsAndPartitionRepeater: FC< hasForeignCitizenship && birthDate ? intervalToDuration({ start: new Date(birthDate), end: new Date() }) ?.years - : kennitala.info(member.nationalId)?.age + : info(member.nationalId)?.age return ( (memberAge ?? 0) < 18 && (member?.nationalId || birthDate) && @@ -78,7 +79,7 @@ export const HeirsAndPartitionRepeater: FC< const hasEstateMemberUnder18withoutRep = values.estate?.estateMembers?.some( (member: EstateMember) => { const advocateAge = - member.advocate && kennitala.info(member.advocate.nationalId)?.age + member.advocate && info(member.advocate.nationalId)?.age return ( hasEstateMemberUnder18 && member?.advocate?.nationalId && @@ -106,34 +107,29 @@ export const HeirsAndPartitionRepeater: FC< return [true, null] }) - const { clearErrors } = useFormContext() - const externalData = application.externalData.syslumennOnEntry?.data as { relationOptions: string[] inheritanceReportInfos: Array } - const estateData = - answers.applicationFor === PREPAID_INHERITANCE - ? undefined - : getEstateDataFromApplication(application) - - const inheritanceTaxFreeLimit = - answers.applicationFor === PREPAID_INHERITANCE - ? 0 - : externalData?.inheritanceReportInfos?.[0]?.inheritanceTax - ?.taxExemptionLimit ?? DEFAULT_TAX_FREE_LIMIT - - const relations = - answers.applicationFor === PREPAID_INHERITANCE - ? PrePaidHeirsRelations.map((relation) => ({ - value: relation.value, - label: formatMessage(relation.label), - })) - : externalData?.relationOptions?.map((relation) => ({ - value: relation, - label: relation, - })) || [] + const estateData = isPrePaidApplication + ? undefined + : getEstateDataFromApplication(application) + + const inheritanceTaxFreeLimit = isPrePaidApplication + ? 0 + : externalData?.inheritanceReportInfos?.[0]?.inheritanceTax + ?.taxExemptionLimit ?? DEFAULT_TAX_FREE_LIMIT + + const relations = isPrePaidApplication + ? PrePaidHeirsRelations.map((relation) => ({ + value: formatMessage(relation.label), + label: formatMessage(relation.label), + })) + : externalData?.relationOptions?.map((relation) => ({ + value: relation, + label: relation, + })) || [] const error = ((errors as any)?.heirs?.data || (errors as any)?.heirs?.total) ?? [] @@ -177,11 +173,10 @@ export const HeirsAndPartitionRepeater: FC< const updateValues = useCallback( (updateIndex: string, value: number, index?: number) => { - const isPrePaid = answers.applicationFor === PREPAID_INHERITANCE const numValue = isNaN(value) ? 0 : value const percentage = numValue > 0 ? numValue / 100 : 0 const heirs = getValues()?.heirs?.data as EstateMember[] - let currentHeir = isPrePaid + let currentHeir = isPrePaidApplication ? heirs[index ?? 0] : (getValueViaPath(answers, updateIndex) as EstateMember) @@ -195,20 +190,15 @@ export const HeirsAndPartitionRepeater: FC< // currently we can only check if heir is spouse by relation string value... const spouse = (heirs ?? []).filter( - (heir) => - heir.enabled && - (heir.relation === 'Maki' || - heir.relation.toLowerCase() === 'spouse'), + (heir) => heir.enabled && heir.relation === RelationSpouse, ) let isSpouse = false // it is not possible to select more than one spouse but for now we will check for it anyway if (spouse.length > 0) { - if (isPrePaid) { - isSpouse = - currentHeir?.relation === 'Maki' || - currentHeir?.relation.toLowerCase() === 'spouse' + if (isPrePaidApplication) { + isSpouse = currentHeir?.relation === RelationSpouse } else { spouse.forEach((currentSpouse) => { isSpouse = @@ -217,7 +207,7 @@ export const HeirsAndPartitionRepeater: FC< } } - const netPropertyForExchange = isPrePaid + const netPropertyForExchange = isPrePaidApplication ? getPrePaidTotalValueFromApplication(application) : valueToNumber(getValueViaPath(answers, 'netPropertyForExchange')) @@ -268,11 +258,6 @@ export const HeirsAndPartitionRepeater: FC< initialLoad() }, [heirsRelations, initialLoad]) - useEffect(() => { - initialLoad() - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) - useEffect(() => { if (!hasEstateMemberUnder18) { clearErrors(heirAgeValidation) @@ -297,24 +282,21 @@ export const HeirsAndPartitionRepeater: FC< (estateData as any)?.inheritanceReportInfo?.heirs && !(application.answers as any)?.heirs?.hasModified ) { - // Keeping this in for now, it may not be needed, will find out later const heirsData = (estateData as any)?.inheritanceReportInfo?.heirs?.map( (heir: any) => { return { ...heir, - phone: heir.phone ? formatPhoneNumber(heir.phone) : '', //Remove all non-digit characters and keep the last 7 digits + phone: heir.phone ? formatPhoneNumber(heir.phone) : '', initial: true, enabled: true, } }, ) - // ran into a problem with "append", as it appeared to be getting called multiple times - // despite checking on the length of the fields - // so now using "replace" instead, for the initial setup + // ran into a problem with "append" as it appeared to be called multiple times + // using "replace" instead, for the initial setup replace(heirsData) setValue('heirs.hasModified', true) } - // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return ( @@ -595,7 +577,6 @@ export const HeirsAndPartitionRepeater: FC< [] as JSX.Element[], )} {fields.map((member: GenericFormField, index) => { - console.log(error, 'errrrrr') if (member.initial) return null return ( diff --git a/libs/application/templates/inheritance-report/src/fields/HeirsOverview/index.tsx b/libs/application/templates/inheritance-report/src/fields/HeirsOverview/index.tsx index b46ca5a60094..c3fa6e5ec163 100644 --- a/libs/application/templates/inheritance-report/src/fields/HeirsOverview/index.tsx +++ b/libs/application/templates/inheritance-report/src/fields/HeirsOverview/index.tsx @@ -5,16 +5,27 @@ import { FieldBaseProps } from '@island.is/application/types' import { InheritanceReport } from '../../lib/dataSchema' import { m } from '../../lib/messages' import { formatCurrency } from '@island.is/application/ui-components' +import { format as formatNationalId } from 'kennitala' +import { + ESTATE_INHERITANCE, + PREPAID_INHERITANCE, + RelationSpouse, +} from '../../lib/constants' export const HeirsOverview: FC> = ({ application, }) => { - const heirs = (application.answers as InheritanceReport).heirs?.data + const { answers } = application + const heirs = (answers as InheritanceReport).heirs?.data const { formatMessage } = useLocale() return ( {heirs?.map((heir, index) => { + const showTaxFree = + answers.applicationFor === ESTATE_INHERITANCE || + (answers.applicationFor === PREPAID_INHERITANCE && + heir.relation === RelationSpouse) if (!heir.enabled) return null return ( @@ -25,7 +36,7 @@ export const HeirsOverview: FC> = ({ {formatMessage(m.nationalId)} - {heir.nationalId} + {formatNationalId(heir.nationalId ?? '')} {formatMessage(m.name)} @@ -55,24 +66,45 @@ export const HeirsOverview: FC> = ({ - - {formatMessage(m.taxFreeInheritance)} - - {formatCurrency(String(heir.taxFreeInheritance || '0'))} - - {formatMessage(m.inheritanceAmount)} {formatCurrency(String(heir.inheritance || '0'))} + {showTaxFree ? ( + + + {formatMessage(m.taxFreeInheritance)} + + + {formatCurrency(String(heir.taxFreeInheritance || '0'))} + + + ) : ( + + + {formatMessage(m.taxableInheritance)} + + + {formatCurrency(String(heir.taxableInheritance || '0'))} + + + )} - - - {formatMessage(m.taxableInheritance)} - - {formatCurrency(String(heir.taxableInheritance || '0'))} - - + + {showTaxFree && ( + + + {formatMessage(m.taxableInheritance)} + + + {formatCurrency(String(heir.taxableInheritance || '0'))} + + + )} {formatMessage(m.inheritanceTax)} @@ -90,7 +122,7 @@ export const HeirsOverview: FC> = ({ {formatMessage(m.advocateNationalId)} - {heir.advocate.nationalId} + {formatNationalId(heir.advocate.nationalId)} {formatMessage(m.advocateName)} diff --git a/libs/application/templates/inheritance-report/src/forms/form.ts b/libs/application/templates/inheritance-report/src/forms/form.ts index f2ea9423ec97..eff072326647 100644 --- a/libs/application/templates/inheritance-report/src/forms/form.ts +++ b/libs/application/templates/inheritance-report/src/forms/form.ts @@ -1,13 +1,5 @@ -import { - YES, - buildCheckboxField, - buildForm, - buildMultiField, - buildSection, - buildSubmitField, -} from '@island.is/application/core' -import { m } from '../lib/messages' -import { DefaultEvents, Form, FormModes } from '@island.is/application/types' +import { buildForm } from '@island.is/application/core' +import { Form, FormModes } from '@island.is/application/types' import { assets } from './sections/assets' import { debtsAndFuneralCost } from './sections/debtsAndFuneralCost' import { heirs } from './sections/heirs' @@ -19,7 +11,6 @@ import { preSelection } from './sections/applicationTypeSelection' import { prePaidHeirs } from './sections/prepaidInheritance/heirs' import { inheritanceExecutor } from './sections/prepaidInheritance/inheritanceExecutor' import { inheritance } from './sections/prepaidInheritance/inheritance' -import { prepaidOverview } from './sections/prepaidInheritance/overview' import { finalStep } from './sections/finalStep' import { prePaidApplicant } from './sections/prepaidInheritance/applicant' @@ -35,7 +26,6 @@ export const prepaidInheritanceForm: Form = buildForm({ inheritance, assets, prePaidHeirs, - prepaidOverview, finalStep, ], }) diff --git a/libs/application/templates/inheritance-report/src/forms/prerequisites.ts b/libs/application/templates/inheritance-report/src/forms/prerequisites.ts index 4553132dc521..52d7119c5e8a 100644 --- a/libs/application/templates/inheritance-report/src/forms/prerequisites.ts +++ b/libs/application/templates/inheritance-report/src/forms/prerequisites.ts @@ -22,12 +22,14 @@ export const getForm = (): Form => children: [ buildMultiField({ title: m.preDataCollectionApplicationFor, + description: m.preDataCollectionApplicationFoDescription, children: [ buildRadioField({ id: 'applicationFor', title: '', largeButtons: true, backgroundColor: 'blue', + required: true, options: [ { value: ESTATE_INHERITANCE, diff --git a/libs/application/templates/inheritance-report/src/forms/sections/applicationTypeSelection.ts b/libs/application/templates/inheritance-report/src/forms/sections/applicationTypeSelection.ts index bd94b718869a..10ffd1e7f6fd 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/applicationTypeSelection.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/applicationTypeSelection.ts @@ -48,7 +48,7 @@ export const preSelection = buildSection({ application.externalData.syslumennOnEntry?.data as { inheritanceReportInfos: Array } - ).inheritanceReportInfos[0].caseNumber + ).inheritanceReportInfos[0]?.caseNumber }, options: (application) => { return ( diff --git a/libs/application/templates/inheritance-report/src/forms/sections/assets.ts b/libs/application/templates/inheritance-report/src/forms/sections/assets.ts index 9b245f151b43..fa399ae78f89 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/assets.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/assets.ts @@ -33,7 +33,9 @@ export const assets = buildSection({ description: (application) => application.answers.applicationFor === PREPAID_INHERITANCE ? m.propertiesDescriptionPrePaid - : m.propertiesDescription + ' ' + m.continueWithoutAssets, + : m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutAssets.defaultMessage, children: [ buildDescriptionField({ id: 'realEstateTitle', @@ -175,7 +177,9 @@ export const assets = buildSection({ id: 'vehicles', title: m.propertiesTitle, description: - m.propertiesDescription + ' ' + m.continueWithoutVehicles, + m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutVehicles.defaultMessage, children: [ buildDescriptionField({ id: 'vehiclesTitle', @@ -310,7 +314,9 @@ export const assets = buildSection({ id: 'estateBankInfo', title: m.propertiesTitle, description: - m.propertiesDescription + ' ' + m.continueWithoutBankAccounts, + m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutBankAccounts.defaultMessage, children: [ buildDescriptionField({ id: 'estateBankInfoTitle', @@ -463,7 +469,9 @@ export const assets = buildSection({ description: (application) => application.answers.applicationFor === PREPAID_INHERITANCE ? m.propertiesDescriptionPrePaid - : m.propertiesDescription + ' ' + m.continueWithoutBankAccounts, + : m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutBankAccounts.defaultMessage, children: [ buildDescriptionField({ id: 'stocksTitle', @@ -549,7 +557,9 @@ export const assets = buildSection({ description: (application) => application.answers.applicationFor === PREPAID_INHERITANCE ? m.propertiesDescriptionPrePaid - : m.propertiesDescription + ' ' + m.continueWithoutBankAccounts, + : m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutBankAccounts.defaultMessage, children: [ buildDescriptionField({ id: 'moneyTitle', @@ -630,7 +640,9 @@ export const assets = buildSection({ description: (application) => application.answers.applicationFor === PREPAID_INHERITANCE ? m.propertiesDescriptionPrePaid - : m.propertiesDescription + ' ' + m.continueWithoutBankAccounts, + : m.propertiesDescription.defaultMessage + + ' ' + + m.continueWithoutBankAccounts.defaultMessage, children: [ buildDescriptionField({ id: 'otherAssetsTitle', @@ -676,7 +688,6 @@ export const assets = buildSection({ buildSubSection({ id: 'assetOverview', title: m.assetOverview, - condition: (answers) => answers.applicationFor !== PREPAID_INHERITANCE, children: [ buildCustomField({ title: m.assetOverview, diff --git a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/heirs.ts b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/heirs.ts index 2bd8d8f92df7..49aa3ce4705e 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/heirs.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/heirs.ts @@ -8,6 +8,7 @@ import { buildTextField, } from '@island.is/application/core' import { m } from '../../../lib/messages' +import { prepaidOverview } from './overview' export const prePaidHeirs = buildSection({ id: 'heirs', @@ -117,5 +118,6 @@ export const prePaidHeirs = buildSection({ }), ], }), + prepaidOverview, ], }) diff --git a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/inheritanceExecutor.ts b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/inheritanceExecutor.ts index 90377cf923b9..f66bfb20b3a6 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/inheritanceExecutor.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/inheritanceExecutor.ts @@ -9,19 +9,15 @@ import { YES, } from '@island.is/application/core' import { m } from '../../../lib/messages' -import { format as formatNationalId } from 'kennitala' -import { Application, UserProfile } from '@island.is/api/schema' -import { removeCountryCode } from '@island.is/application/ui-components' export const inheritanceExecutor = buildSection({ id: 'inheritanceExecutor', - title: 'Arflátar', + title: m.grantors, children: [ buildMultiField({ id: 'inheritanceExecutor', - title: 'Arflátar', - description: - 'Lorem ipsum foo bar beep boop meep morp lorem ipsum foo bar beep boop meep morp lorem ipsum foo bar beep boop meep morp.', + title: m.grantors, + description: m.grantorsDescription, children: [ buildDescriptionField({ id: 'description.executors.executor', diff --git a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/overview.ts b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/overview.ts index 1c8ade9c302f..511a00205550 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/overview.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/prepaidInheritance/overview.ts @@ -4,202 +4,173 @@ import { buildDividerField, buildKeyValueField, buildMultiField, - buildSection, buildSubSection, getValueViaPath, } from '@island.is/application/core' import { m } from '../../../lib/messages' import { formatCurrency } from '@island.is/application/ui-components' import { InheritanceReport } from '../../../lib/dataSchema' -import { roundedValueToNumber, valueToNumber } from '../../../lib/utils/helpers' +import { + roundedValueToNumber, + showTaxFreeInOverview, + valueToNumber, +} from '../../../lib/utils/helpers' import { calculateTotalAssets } from '../../../lib/utils/calculateTotalAssets' -export const prepaidOverview = buildSection({ +export const prepaidOverview = buildSubSection({ id: 'prepaidOverview', title: m.overview, children: [ - buildSubSection({ - id: 'assetOverview', - title: m.assetOverview, + buildMultiField({ + id: 'heirsOverview', + title: m.overviewHeirsTitle, + description: m.overviewHeirsDescription, children: [ + buildDividerField({}), + buildDescriptionField({ + id: 'overviewAssetsTitle', + title: m.properties, + titleVariant: 'h3', + space: 'gutter', + marginBottom: 'gutter', + }), + buildKeyValueField({ + label: m.netProperty, + display: 'flex', + value: ({ answers }) => + formatCurrency( + String(roundedValueToNumber(calculateTotalAssets(answers))), + ), + }), + buildDescriptionField({ + id: 'space', + title: '', + space: 'gutter', + }), + buildDividerField({}), buildCustomField({ - title: m.assetOverview, - description: m.assetOverviewDescription, - id: 'overviewAssets', + title: '', + id: 'overviewHeirs', doesNotRequireAnswer: true, - component: 'OverviewAssets', + component: 'HeirsOverview', }), - ], - }), - buildSubSection({ - id: 'heirsOverview', - title: m.overviewHeirsTitle, - children: [ - buildMultiField({ - id: 'heirsOverview', - title: m.overviewHeirsTitle, - description: m.overviewHeirsDescription, - children: [ - buildDescriptionField({ - id: 'overviewAssetsTitle', - title: m.properties, - titleVariant: 'h3', - space: 'gutter', - marginBottom: 'gutter', - }), - buildDividerField({}), - buildKeyValueField({ - label: m.totalValueOfAssets, - display: 'flex', - value: ({ answers }) => - formatCurrency( - String(roundedValueToNumber(calculateTotalAssets(answers))), - ), - }), - buildDescriptionField({ - id: 'space', - title: '', - space: 'gutter', - }), - buildDividerField({}), - buildDescriptionField({ - id: 'overviewHeirsTitle', - title: m.heirs, - titleVariant: 'h3', - space: 'gutter', - marginBottom: 'gutter', - }), - buildCustomField({ - title: '', - id: 'overviewHeirs', - doesNotRequireAnswer: true, - component: 'HeirsOverview', - }), - buildDividerField({}), - buildDescriptionField({ - id: 'overviewTotalInheritance', - title: m.overviewTotalInheritance, - titleVariant: 'h3', - space: 'gutter', - marginBottom: 'gutter', - }), - buildKeyValueField({ - label: m.heirsInheritanceRate, - display: 'flex', - value: ({ answers }) => - String(getValueViaPath(answers, 'heirs.total')), - }), - buildDescriptionField({ - id: 'heirs_space1', - title: '', - space: 'gutter', - }), - buildKeyValueField({ - label: m.inheritanceAmount, - display: 'flex', - value: ({ answers }) => { - const total = ( - answers as InheritanceReport - )?.heirs?.data?.reduce( - (sum, heir) => sum + valueToNumber(heir.inheritance), - 0, - ) + buildDividerField({}), + buildDescriptionField({ + id: 'overviewTotalInheritance', + title: m.overviewTotalInheritance, + titleVariant: 'h3', + space: 'gutter', + marginBottom: 'gutter', + }), + buildKeyValueField({ + label: m.heirsInheritanceRate, + display: 'flex', + value: ({ answers }) => + String(getValueViaPath(answers, 'heirs.total')), + }), + buildDescriptionField({ + id: 'heirs_space1', + title: '', + space: 'gutter', + }), + buildKeyValueField({ + label: m.inheritanceAmount, + display: 'flex', + value: ({ answers }) => { + const total = (answers as InheritanceReport)?.heirs?.data?.reduce( + (sum, heir) => sum + valueToNumber(heir.inheritance), + 0, + ) - return formatCurrency(String(total ?? '0')) - }, - }), - buildDescriptionField({ - id: 'heirs_space2', - title: '', - space: 'gutter', - }), - buildKeyValueField({ - label: m.taxFreeInheritance, - display: 'flex', - value: ({ answers }) => { - const total = ( - answers as InheritanceReport - )?.heirs?.data?.reduce( - (sum, heir) => sum + valueToNumber(heir.taxFreeInheritance), - 0, - ) + return formatCurrency(String(total ?? '0')) + }, + }), + buildDescriptionField({ + id: 'heirs_space2', + title: '', + space: 'gutter', + }), + buildKeyValueField({ + label: m.taxFreeInheritance, + display: 'flex', + condition: showTaxFreeInOverview, + value: ({ answers }) => { + const total = (answers as InheritanceReport)?.heirs?.data?.reduce( + (sum, heir) => sum + valueToNumber(heir.taxFreeInheritance), + 0, + ) - return formatCurrency(String(total ?? '0')) - }, - }), - buildDescriptionField({ - id: 'heirs_space3', - title: '', - space: 'gutter', - }), - buildKeyValueField({ - label: m.taxableInheritance, - display: 'flex', - value: ({ answers }) => { - const total = ( - answers as InheritanceReport - )?.heirs?.data?.reduce( - (sum, heir) => sum + valueToNumber(heir.taxableInheritance), - 0, - ) + return formatCurrency(String(total ?? '0')) + }, + }), + buildDescriptionField({ + id: 'heirs_space3', + title: '', + space: 'gutter', + condition: showTaxFreeInOverview, + }), + buildKeyValueField({ + label: m.taxableInheritance, + display: 'flex', + value: ({ answers }) => { + const total = (answers as InheritanceReport)?.heirs?.data?.reduce( + (sum, heir) => sum + valueToNumber(heir.taxableInheritance), + 0, + ) - return formatCurrency(String(total ?? '0')) - }, - }), - buildDescriptionField({ - id: 'heirs_space4', - title: '', - space: 'gutter', - }), - buildKeyValueField({ - label: m.inheritanceTax, - display: 'flex', - value: ({ answers }) => { - const total = ( - answers as InheritanceReport - )?.heirs?.data?.reduce( - (sum, heir) => sum + valueToNumber(heir.inheritanceTax), - 0, - ) + return formatCurrency(String(total ?? '0')) + }, + }), + buildDescriptionField({ + id: 'heirs_space4', + title: '', + space: 'gutter', + }), + buildKeyValueField({ + label: m.inheritanceTax, + display: 'flex', + value: ({ answers }) => { + const total = (answers as InheritanceReport)?.heirs?.data?.reduce( + (sum, heir) => sum + valueToNumber(heir.inheritanceTax), + 0, + ) - return formatCurrency(String(total ?? '0')) - }, - }), - buildDividerField({}), - buildDescriptionField({ - id: 'overviewAdditionalInfo', - title: m.heirAdditionalInfo, - titleVariant: 'h3', - space: 'gutter', - marginBottom: 'gutter', - }), - buildKeyValueField({ - label: m.info, - value: ({ answers }) => - getValueViaPath(answers, 'heirsAdditionalInfo'), - }), - buildDescriptionField({ - id: 'heirs_space5', - title: '', - space: 'gutter', - }), - buildKeyValueField({ - label: m.fileUploadOtherDocumentsPrePaid, - value: ({ answers }) => { - const files = getValueViaPath( - answers, - 'heirsAdditionalInfoFilesOtherDocuments', - ) - return files.map((file: any) => file.name).join(', ') - }, - }), - buildCustomField({ - title: '', - id: 'overviewPrint', - doesNotRequireAnswer: true, - component: 'PrintScreen', - }), - ], + return formatCurrency(String(total ?? '0')) + }, + }), + buildDividerField({}), + buildDescriptionField({ + id: 'overviewAdditionalInfo', + title: m.heirAdditionalInfo, + titleVariant: 'h3', + space: 'gutter', + marginBottom: 'gutter', + }), + buildKeyValueField({ + label: m.info, + value: ({ answers }) => + getValueViaPath(answers, 'heirsAdditionalInfo'), + }), + buildDescriptionField({ + id: 'heirs_space5', + title: '', + space: 'gutter', + }), + buildKeyValueField({ + label: m.fileUploadOtherDocumentsPrePaid, + value: ({ answers }) => { + const files = getValueViaPath( + answers, + 'heirsAdditionalInfoFilesOtherDocuments', + ) + return files.map((file: any) => file.name).join(', ') + }, + }), + buildCustomField({ + title: '', + id: 'overviewPrint', + doesNotRequireAnswer: true, + component: 'PrintScreen', }), ], }), diff --git a/libs/application/templates/inheritance-report/src/lib/InheritanceReportTemplate.ts b/libs/application/templates/inheritance-report/src/lib/InheritanceReportTemplate.ts index 8b31f6cfd59a..f6c0854ebefc 100644 --- a/libs/application/templates/inheritance-report/src/lib/InheritanceReportTemplate.ts +++ b/libs/application/templates/inheritance-report/src/lib/InheritanceReportTemplate.ts @@ -18,6 +18,7 @@ import { m } from './messages' import { inheritanceReportSchema } from './dataSchema' import { ApiActions, + ESTATE_INHERITANCE, InheritanceReportEvent, PREPAID_INHERITANCE, Roles, @@ -37,6 +38,10 @@ const InheritanceReportTemplate: ApplicationTemplate< ? m.prerequisitesTitle.defaultMessage + ' - ' + m.applicationNamePrepaid.defaultMessage + : answers.applicationFor === ESTATE_INHERITANCE + ? m.prerequisitesTitle.defaultMessage + + ' - ' + + m.applicationNameEstate.defaultMessage : m.prerequisitesTitle.defaultMessage, institution: m.institution, dataSchema: inheritanceReportSchema, @@ -129,10 +134,10 @@ const InheritanceReportTemplate: ApplicationTemplate< status: 'approved', progress: 1, lifecycle: EphemeralStateLifeCycle, - /*onEntry: defineTemplateApi({ + onEntry: defineTemplateApi({ action: ApiActions.completeApplication, throwOnError: true, - }),*/ + }), roles: [ { id: Roles.ESTATE_INHERITANCE_APPLICANT, diff --git a/libs/application/templates/inheritance-report/src/lib/constants.ts b/libs/application/templates/inheritance-report/src/lib/constants.ts index 7567ad223dff..796e0cf6dcb5 100644 --- a/libs/application/templates/inheritance-report/src/lib/constants.ts +++ b/libs/application/templates/inheritance-report/src/lib/constants.ts @@ -18,6 +18,8 @@ export enum PrePaidHeirsRelationTypes { OTHER = 'other', } +export const RelationSpouse = 'Maki' + export const PrePaidHeirsRelations = [ { value: PrePaidHeirsRelationTypes.SPOUSE, diff --git a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts index 885c4487f192..8c0c5801cb48 100644 --- a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts +++ b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts @@ -9,6 +9,11 @@ import { } from './utils/helpers' import { m } from './messages' import { NO, YES } from '@island.is/application/core' +import { + ESTATE_INHERITANCE, + PREPAID_INHERITANCE, + RelationSpouse, +} from './constants' const deceasedShare = { deceasedShare: z.string().nonempty().optional(), @@ -167,6 +172,8 @@ export const inheritanceReportSchema = z.object({ }, ), + applicationFor: z.enum([ESTATE_INHERITANCE, PREPAID_INHERITANCE]), + /* assets */ assets: z.object({ realEstate: assetWithShare, @@ -567,8 +574,7 @@ export const inheritanceReportSchema = z.object({ (v) => { if (v.length > 0) { const count = v.filter( - (x) => - x.enabled && (x.relation === 'Maki' || x.relation === 'Spouse'), + (x) => x.enabled && x.relation === RelationSpouse, )?.length return count <= 1 } diff --git a/libs/application/templates/inheritance-report/src/lib/messages.ts b/libs/application/templates/inheritance-report/src/lib/messages.ts index 28081cad37bd..a7ebde5021bc 100644 --- a/libs/application/templates/inheritance-report/src/lib/messages.ts +++ b/libs/application/templates/inheritance-report/src/lib/messages.ts @@ -45,6 +45,12 @@ export const m = defineMessages({ defaultMessage: 'Tegund umsóknar', description: 'Get application for', }, + preDataCollectionApplicationFoDescription: { + id: 'ir.application:preDataCollectionApplicationFoDescription#markdown', + defaultMessage: + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a ex magna. Aenean varius dui eget consectetur posuere. Pellentesque dignissim nunc id euismod porttitor. Curabitur ut ante pellentesque, rutrum purus in, vestibulum elit. Donec egestas lacus justo.', + description: 'Get application for', + }, preDataCollectionApplicationForPrepaid: { id: 'ir.application:preDataCollectionApplicationForPrepaid', defaultMessage: 'Fyrirframgreiddur arfur', @@ -66,6 +72,11 @@ export const m = defineMessages({ defaultMessage: 'Fyrirframgreiddur arfur', description: '', }, + applicationNameEstate: { + id: 'ir.application:applicationNameEstate', + defaultMessage: 'Dánarbú', + description: '', + }, institutionName: { id: 'ir.application:institution.name', defaultMessage: 'Sýslumenn', @@ -1463,6 +1474,16 @@ export const m = defineMessages({ defaultMessage: 'Skiptastjóri', description: '', }, + grantors: { + id: 'ir.application:grantors', + defaultMessage: 'Arflátar', + description: '', + }, + grantorsDescription: { + id: 'ir.application:grantorsDescription', + defaultMessage: 'Lorem ipsum foo bar beep boop meep morp.', + description: '', + }, grantor: { id: 'ir.application:grantor', defaultMessage: 'Arfláti', @@ -1685,12 +1706,12 @@ export const m = defineMessages({ description: '', }, includeSpousePrePaid: { - id: 'id.application:includeSpouse', + id: 'ir.application:includeSpouse', defaultMessage: 'Ráðstafa úr sameign hjúskaps', description: '', }, includeSpousePrePaidDescription: { - id: 'id.application:includeSpouseDescription', + id: 'ir.application:includeSpouseDescription', defaultMessage: 'Ef arfláti er í gift/ur og ráðstafa á úr sameign, þarf maki að vera með sem arfláti', description: '', diff --git a/libs/application/templates/inheritance-report/src/lib/utils/helpers.ts b/libs/application/templates/inheritance-report/src/lib/utils/helpers.ts index 108cbb84f09c..c5769bedce58 100644 --- a/libs/application/templates/inheritance-report/src/lib/utils/helpers.ts +++ b/libs/application/templates/inheritance-report/src/lib/utils/helpers.ts @@ -8,9 +8,10 @@ import { import { InheritanceReportInfo } from '@island.is/clients/syslumenn' import { parsePhoneNumberFromString } from 'libphonenumber-js' import { MessageDescriptor } from 'react-intl' -import { boolean, ZodTypeAny } from 'zod' +import { ZodTypeAny } from 'zod' import { Answers } from '../../types' import { ESTATE_INHERITANCE } from '../constants' +import { InheritanceReport } from '../dataSchema' export const currencyStringToNumber = (str: string) => { if (!str) { @@ -89,15 +90,17 @@ export const getPrePaidTotalValueFromApplication = ( const money = valueToNumber( getValueViaPath(answers, 'assets.money.value', '0'), ) - const vehicleTotal = - getValueViaPath(answers, 'assets.vehicles.total', 0) ?? 0 + const stocksTotal = + getValueViaPath(answers, 'assets.stocks.total', 0) ?? 0 const realEstateTotal = getValueViaPath(answers, 'assets.realEstate.total', 0) ?? 0 - const otherTotal = + const otherAssetsTotal = getValueViaPath(answers, 'assets.otherAssets.total', 0) ?? 0 const bankAccountTotal = getValueViaPath(answers, 'assets.bankAccounts.total', 0) ?? 0 - return money + vehicleTotal + realEstateTotal + otherTotal + bankAccountTotal + return ( + money + stocksTotal + realEstateTotal + otherAssetsTotal + bankAccountTotal + ) } export const customZodError = ( @@ -201,3 +204,11 @@ export const shouldShowCustomSpouseShare = (answers: FormValue) => export const roundedValueToNumber = (value: unknown) => Math.round(valueToNumber(value)) + +export const showTaxFreeInOverview = (answers: FormValue) => { + const total = (answers as InheritanceReport)?.heirs?.data?.reduce( + (sum, heir) => sum + valueToNumber(heir.taxFreeInheritance), + 0, + ) + return !!total && total > 0 +}