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 6d1e0229f4f0..b85a2c4a9810 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 @@ -125,7 +125,7 @@ export const expandAnswers = ( data: (answers.assets.bankAccounts?.data ?? []).map((account) => { return { assetNumber: account.assetNumber ?? '', - amount: account.amount ?? '', + propertyValuation: account.propertyValuation ?? '', exchangeRateOrInterest: account.exchangeRateOrInterest ?? '', foreignBankAccount: account?.foreignBankAccount ?? [], deceasedShare: account.deceasedShare ?? '', 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 0518923f92a4..67d443dfd1a2 100644 --- a/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx +++ b/libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx @@ -109,62 +109,70 @@ export const CalculateShare: FC> = ({ const updateShareCalculations = useCallback(() => { const bankAccounts: CalcShared = ( (answers.assets as unknown as EstateAssets)?.bankAccounts?.data ?? [] - ).map((item) => { - const propertyValuation = valueToNumber(item.amount) - const exchangeRateOrInterest = valueToNumber(item.exchangeRateOrInterest) - const deceasedShare = valueToNumber(item.deceasedShare) - const value = propertyValuation + exchangeRateOrInterest - const { shareValue, deceasedShareValue } = getShareValue( - value, - deceasedShare, - ) - const deduction = deceasedWasInCohabitation ? value - shareValue : 0 - return { - value, - deduction, - shareValue, - deceasedShareValue, - deceasedShare, - } - }) + ) + .filter((item) => !!item.enabled) + .map((item) => { + const propertyValuation = valueToNumber(item.propertyValuation) + const exchangeRateOrInterest = valueToNumber( + item.exchangeRateOrInterest, + ) + const deceasedShare = valueToNumber(item.deceasedShare) + const value = propertyValuation + exchangeRateOrInterest + const { shareValue, deceasedShareValue } = getShareValue( + value, + deceasedShare, + ) + const deduction = deceasedWasInCohabitation ? value - shareValue : 0 + return { + value, + deduction, + shareValue, + deceasedShareValue, + deceasedShare, + } + }) const claims: CalcShared = ( (answers.assets as unknown as EstateAssets)?.claims?.data ?? [] - ).map((item) => { - const value = valueToNumber(item.propertyValuation) - const deceasedShare = valueToNumber(item.deceasedShare) - const { shareValue, deceasedShareValue } = getShareValue( - value, - deceasedShare, - ) - const deduction = deceasedWasInCohabitation ? value - shareValue : 0 - return { - value, - deduction, - shareValue, - deceasedShareValue, - deceasedShare, - } - }) + ) + .filter((item) => !!item.enabled) + .map((item) => { + const value = valueToNumber(item.propertyValuation) + const deceasedShare = valueToNumber(item.deceasedShare) + const { shareValue, deceasedShareValue } = getShareValue( + value, + deceasedShare, + ) + const deduction = deceasedWasInCohabitation ? value - shareValue : 0 + return { + value, + deduction, + shareValue, + deceasedShareValue, + deceasedShare, + } + }) const guns: CalcShared = ( (answers.assets as unknown as EstateAssets)?.guns?.data ?? [] - ).map((item) => { - const value = valueToNumber(item.propertyValuation) - const deceasedShare = valueToNumber(item.deceasedShare) - const { shareValue, deceasedShareValue } = getShareValue( - value, - deceasedShare, - ) - const deduction = deceasedWasInCohabitation ? value - shareValue : 0 - return { - value, - deduction, - shareValue, - deceasedShareValue, - deceasedShare, - } - }) + ) + .filter((item) => !!item.enabled) + .map((item) => { + const value = valueToNumber(item.propertyValuation) + const deceasedShare = valueToNumber(item.deceasedShare) + const { shareValue, deceasedShareValue } = getShareValue( + value, + deceasedShare, + ) + const deduction = deceasedWasInCohabitation ? value - shareValue : 0 + return { + value, + deduction, + shareValue, + deceasedShareValue, + deceasedShare, + } + }) const inventory: CalcShared = [ (answers.assets as unknown as EstateAssets)?.inventory ?? [], @@ -246,41 +254,45 @@ export const CalculateShare: FC> = ({ const stocks: CalcShared = ( (answers.assets as unknown as EstateAssets)?.stocks?.data ?? [] - ).map((item) => { - const value = valueToNumber(item.value) - const deceasedShare = valueToNumber(item.deceasedShare) - const { shareValue, deceasedShareValue } = getShareValue( - value, - deceasedShare, - ) - const deduction = deceasedWasInCohabitation ? value - shareValue : 0 - return { - value, - deduction, - shareValue, - deceasedShareValue, - deceasedShare, - } - }) + ) + .filter((item) => !!item.enabled) + .map((item) => { + const value = valueToNumber(item.value) + const deceasedShare = valueToNumber(item.deceasedShare) + const { shareValue, deceasedShareValue } = getShareValue( + value, + deceasedShare, + ) + const deduction = deceasedWasInCohabitation ? value - shareValue : 0 + return { + value, + deduction, + shareValue, + deceasedShareValue, + deceasedShare, + } + }) const vehicles: CalcShared = ( (answers.assets as unknown as EstateAssets)?.vehicles?.data ?? [] - ).map((item) => { - const value = valueToNumber(item.propertyValuation) - const deceasedShare = valueToNumber(item.deceasedShare) - const { shareValue, deceasedShareValue } = getShareValue( - value, - deceasedShare, - ) - const deduction = deceasedWasInCohabitation ? value - shareValue : 0 - return { - value, - deduction, - shareValue, - deceasedShareValue, - deceasedShare, - } - }) + ) + .filter((item) => !!item.enabled) + .map((item) => { + const value = valueToNumber(item.propertyValuation) + const deceasedShare = valueToNumber(item.deceasedShare) + const { shareValue, deceasedShareValue } = getShareValue( + value, + deceasedShare, + ) + const deduction = deceasedWasInCohabitation ? value - shareValue : 0 + return { + value, + deduction, + shareValue, + deceasedShareValue, + deceasedShare, + } + }) setShareValues({ bankAccounts: { diff --git a/libs/application/templates/inheritance-report/src/fields/Overview/OverviewAssets/rows.ts b/libs/application/templates/inheritance-report/src/fields/Overview/OverviewAssets/rows.ts index 3c3f95e507e3..15b4ae039315 100644 --- a/libs/application/templates/inheritance-report/src/fields/Overview/OverviewAssets/rows.ts +++ b/libs/application/templates/inheritance-report/src/fields/Overview/OverviewAssets/rows.ts @@ -54,7 +54,9 @@ export const getRealEstateDataRow = (answers: FormValue): RowType[] => { } export const getVehiclesDataRow = (answers: FormValue): RowType[] => { - const values = (answers.assets as unknown as EstateAssets)?.vehicles?.data + const values = ( + answers.assets as unknown as EstateAssets + )?.vehicles?.data.filter((item) => item.enabled) const data = (values ?? []).map((item) => { const propertyValuation = roundedValueToNumber(item.propertyValuation) @@ -86,7 +88,9 @@ export const getVehiclesDataRow = (answers: FormValue): RowType[] => { } export const getGunsDataRow = (answers: FormValue): RowType[] => { - const values = (answers.assets as unknown as EstateAssets)?.guns?.data + const values = (answers.assets as unknown as EstateAssets)?.guns?.data.filter( + (item) => item.enabled, + ) const data = (values ?? []).map((item) => { const propertyValuation = roundedValueToNumber(item.propertyValuation) @@ -147,7 +151,9 @@ export const getInventoryDataRow = (answers: FormValue): RowType[] => { } export const getStocksDataRow = (answers: FormValue): RowType[] => { - const values = (answers.assets as unknown as EstateAssets)?.stocks?.data + const values = ( + answers.assets as unknown as EstateAssets + )?.stocks?.data.filter((item) => item.enabled) const data = (values ?? []).map((item) => { const items: RowItemsType = [ @@ -190,7 +196,7 @@ export const getBankAccountsDataRow = (answers: FormValue): RowType[] => { )?.bankAccounts?.data.filter((item) => item.enabled) const data = (values ?? []).map((item) => { - const propertyValuation = roundedValueToNumber(item.amount) + const propertyValuation = roundedValueToNumber(item.propertyValuation) const isForeign = item.foreignBankAccount?.length 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 b2c3d8b511ab..77c632a533ac 100644 --- a/libs/application/templates/inheritance-report/src/forms/sections/assets.ts +++ b/libs/application/templates/inheritance-report/src/forms/sections/assets.ts @@ -345,7 +345,7 @@ export const assets = buildSection({ [ESTATE_INHERITANCE]: m.bankAccountCapital, [PREPAID_INHERITANCE]: m.bankAccountCapitalPrePaid, }, - id: 'amount', + id: 'propertyValuation', required: true, currency: true, }, @@ -376,7 +376,7 @@ export const assets = buildSection({ fromExternalData: 'bankAccounts', skipPushRight: true, repeaterButtonText: m.bankAccountRepeaterButton, - sumField: 'amount', + sumField: 'propertyValuation', sumField2: 'exchangeRateOrInterest', }, ), diff --git a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts index 054423f72638..5367d8ab67a3 100644 --- a/libs/application/templates/inheritance-report/src/lib/dataSchema.ts +++ b/libs/application/templates/inheritance-report/src/lib/dataSchema.ts @@ -221,7 +221,7 @@ export const inheritanceReportSchema = z.object({ .object({ foreignBankAccount: z.array(z.enum([YES])).optional(), assetNumber: z.string().refine((v) => v), - amount: z.string().refine((v) => v), + propertyValuation: z.string().refine((v) => v), exchangeRateOrInterest: z.string().refine((v) => v), enabled: z.boolean(), ...deceasedShare, diff --git a/libs/application/templates/inheritance-report/src/types.ts b/libs/application/templates/inheritance-report/src/types.ts index 8eef0a622cf3..0fea471f2a48 100644 --- a/libs/application/templates/inheritance-report/src/types.ts +++ b/libs/application/templates/inheritance-report/src/types.ts @@ -115,6 +115,7 @@ export interface GunsData extends DeceasedShare { description: string propertyValuation: string taxFreeInheritance: number + enabled?: boolean } export interface Money extends DeceasedShare { @@ -129,6 +130,7 @@ export interface ClaimsData extends DeceasedShare { issuer: string nationalId: string taxFreeInheritance: number + enabled?: boolean } export interface Claims { @@ -148,6 +150,7 @@ export interface StocksData extends DeceasedShare { rateOfExchange: string exchangeRateOrInterest: string taxFreeInheritance: number + enabled?: boolean } export interface Stocks { @@ -160,6 +163,7 @@ export interface VehiclesData extends DeceasedShare { description: string propertyValuation: string taxFreeInheritance: number + enabled?: boolean } export interface Vehicles { @@ -203,7 +207,7 @@ export interface BankAccountsData extends DeceasedShare { exchangeRateOrInterest: string propertyNumber: string assetNumber: string - amount: string + propertyValuation: string foreignBankAccount?: ('yes' | 'no')[] taxFreeInheritance: number enabled?: boolean