Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(income-plan): Use new temporary income plan calculation data #16933

Merged
merged 8 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Box, Button } from '@island.is/island-ui/core'

helgifr marked this conversation as resolved.
Show resolved Hide resolved
export const PrintScreen = () => {
return (
<Box display="flex" justifyContent="flexEnd">
helgifr marked this conversation as resolved.
Show resolved Hide resolved
<Button
variant="utility"
icon="print"
onClick={(e) => {
e.preventDefault()
window.print()
}}
/>
helgifr marked this conversation as resolved.
Show resolved Hide resolved
</Box>
)
}

export default PrintScreen
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { formatCurrency } from '@island.is/application/ui-components'
import {
AlertMessage,
Box,
Button,
SkeletonLoader,
Stack,
Table as T,
Expand All @@ -21,13 +20,20 @@ import {
} from '../../lib/incomePlanUtils'
import { incomePlanFormMessage } from '../../lib/messages'
import { SocialInsuranceTemporaryCalculationGroup } from '../../types/schema'
import { MONTHS } from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import { useFormContext } from 'react-hook-form'

export const TemporaryCalculationTable: FC<
React.PropsWithChildren<FieldBaseProps>
> = ({ application }) => {
const { formatMessage } = useLocale()

const { incomePlan } = getApplicationAnswers(application.answers)
const { watch } = useFormContext()
const temporaryCalculationMonth = watch('temporaryCalculation.month')
const monthIndex = MONTHS.findIndex(
(month) => month.value === temporaryCalculationMonth,
)
helgifr marked this conversation as resolved.
Show resolved Hide resolved
helgifr marked this conversation as resolved.
Show resolved Hide resolved
const { categorizedIncomeTypes, incomePlanConditions } =
getApplicationExternalData(application.externalData)

Expand Down Expand Up @@ -149,29 +155,27 @@ export const TemporaryCalculationTable: FC<

return (
<Box>
<Box display="flex" justifyContent="flexEnd">
<Button
variant="utility"
icon="print"
onClick={(e) => {
e.preventDefault()
window.print()
}}
/>
</Box>
<Box marginY={3}>
<Stack space={3}>
<T.Table>
<T.Head>
<T.Row>
<T.HeadData width="50%">
{formatMessage(incomePlanFormMessage.info.tableHeaderOne)}
{formatMessage(
incomePlanFormMessage.info.tableHeaderPaymentTypes,
)}
</T.HeadData>
<T.HeadData width="25%" align="right" box={{ paddingRight: 0 }}>
{formatMessage(incomePlanFormMessage.info.tableHeaderTwo)}
{formatMessage(
MONTHS.find(
({ value }) => value === temporaryCalculationMonth,
)?.label ?? MONTHS[0].label,
)}
</T.HeadData>
<T.HeadData width="25%" align="right">
{formatMessage(incomePlanFormMessage.info.tableHeaderThree)}
{formatMessage(incomePlanFormMessage.info.tableHeaderTotal, {
year: incomePlanConditions.incomePlanYear,
})}
</T.HeadData>
</T.Row>
</T.Head>
Expand All @@ -190,8 +194,7 @@ export const TemporaryCalculationTable: FC<
align="right"
box={{ paddingRight: 0 }}
>
{group.total &&
formatCurrency(Math.round(group.total / 12).toString())}
{group.monthTotals?.[monthIndex].amount}
helgifr marked this conversation as resolved.
Show resolved Hide resolved
</T.HeadData>
<T.HeadData width="25%" align="right">
{group.total && formatCurrency(group.total.toString())}
Expand All @@ -203,8 +206,7 @@ export const TemporaryCalculationTable: FC<
<T.Row key={`row-${rowIndex}`}>
<T.Data>{row.name}</T.Data>
<T.Data align="right" box={{ paddingRight: 0 }}>
{row.total &&
formatCurrency(Math.round(row.total / 12).toString())}
{row.months?.[monthIndex].amount}
helgifr marked this conversation as resolved.
Show resolved Hide resolved
</T.Data>
<T.Data align="right">
{row.total && formatCurrency(row.total.toString())}
Expand All @@ -221,13 +223,11 @@ export const TemporaryCalculationTable: FC<
<T.HeadData width="50%">
{formatMessage(incomePlanFormMessage.info.paidTableHeader)}
</T.HeadData>
<T.HeadData width="25%" align="right" box={{ paddingRight: 0 }}>
{formatCurrency(
Math.round(
data?.getTemporaryCalculations?.paidOut / 12,
).toString(),
)}
</T.HeadData>
<T.HeadData
width="25%"
align="right"
box={{ paddingRight: 0 }}
></T.HeadData>
<T.HeadData width="25%" align="right">
{formatCurrency(
data?.getTemporaryCalculations?.paidOut.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Review } from './Review'
export { TemporaryCalculationTable } from './TemporaryCalculationTable'
export { PrintScreen } from './PrintScreen'
helgifr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildForm,
buildMultiField,
buildSection,
buildSelectField,
buildSubSection,
buildSubmitField,
buildTableRepeaterField,
Expand Down Expand Up @@ -37,6 +38,7 @@ import {
getTypesOptions,
} from '../lib/incomePlanUtils'
import { incomePlanFormMessage } from '../lib/messages'
import { MONTHS } from '@island.is/application/templates/social-insurance-administration-core/lib/constants'

export const IncomePlanForm: Form = buildForm({
id: 'IncomePlanDraft',
Expand Down Expand Up @@ -625,6 +627,19 @@ export const IncomePlanForm: Form = buildForm({
title: incomePlanFormMessage.info.temporaryCalculationTitle,
description: incomePlanFormMessage.info.tableDescription,
children: [
buildCustomField({
title: '',
id: 'overviewPrint',
doesNotRequireAnswer: true,
component: 'PrintScreen',
}),
helgifr marked this conversation as resolved.
Show resolved Hide resolved
buildSelectField({
id: 'temporaryCalculation.month',
title: socialInsuranceAdministrationMessage.period.month,
width: 'half',
options: MONTHS,
defaultValue: 'January',
}),
buildCustomField({
id: 'temporaryCalculationTable',
title: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export const getApplicationAnswers = (answers: Application['answers']) => {
[],
) as IncomePlanRow[]

return { incomePlan }
const temporaryCalculationMonth = getValueViaPath(
answers,
'temporaryCalculation.month',
) as string

return {
incomePlan,
temporaryCalculationMonth,
}
}

export const getOneInstanceOfCategory = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,15 @@ export const incomePlanFormMessage: MessageDir = {
defaultMessage: 'Bráðabirgðaútreikningur',
description: 'Temporary calculation',
},
tableHeaderOne: {
id: 'ip.application:table.header.one',
tableHeaderPaymentTypes: {
id: 'ip.application:table.header.payment.type',
defaultMessage: 'Greiðslutegundir',
description: 'Payment types',
},
tableHeaderTwo: {
id: 'ip.application:table.header.two',
defaultMessage: 'Samtals á mánuði',
description: 'Montly total',
},
tableHeaderThree: {
id: 'ip.application:table.header.three',
defaultMessage: 'Samtals á ári',
description: 'Annual total',
tableHeaderTotal: {
id: 'ip.application:table.header.total',
defaultMessage: 'Samtals {year}',
description: 'Total {year}',
},
tableDescription: {
id: 'ip.application:table.description',
Expand Down