Skip to content

Commit

Permalink
Merge branch 'main' into feat/new-delegation-hnipp
Browse files Browse the repository at this point in the history
  • Loading branch information
magnearun authored Oct 30, 2024
2 parents 81e60a3 + 0947e07 commit 7341945
Show file tree
Hide file tree
Showing 97 changed files with 2,525 additions and 1,392 deletions.
6 changes: 3 additions & 3 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export REDIS_CLUSTER_IP=0.0.0.0

source_env_if_exists .envrc.private
if [[ "${IS_DEVCONTAINER:-}" == true ]]; then
source_env_if_exists .devcontainer/.envrc.private
source_env_if_exists .devcontainer/.envrc.private || true
fi

# Podman compatibility
# NOTE: Exits direnv if user is using docker.
source_env_if_exists .envrc.podman
source_env_if_exists .envrc.podman || true

source_env_if_exists .envrc.kube
source_env_if_exists .envrc.kube || true
4 changes: 4 additions & 0 deletions .envrc.kube
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ set-kubectx() {
if kubectx | grep -q "${AWS_PROFILE##islandis-}"; then
return
fi
if [[ -z "${AWS_PROFILE}" ]]; then
echo "No AWS_PROFILE set" >&2
return
fi
echo "Setting kube context..." >&2
AWS_ACCOUNT_ID="$(aws sts get-caller-identity | jq -r '.Account')"
kubectx "$(kubectx | grep "${AWS_ACCOUNT_ID}")"
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ codemagic.yaml
/libs/api/domains/university-gateway/ @island-is/origo
/libs/university-gateway/ @island-is/origo
/apps/web/screens/UniversitySearch/ @island-is/origo
/apps/web/screens/queries/UniversityGateway.ts @island-is/origo
/apps/web/components/ListViewCard/ @island-is/origo

/libs/application/templates/directorate-of-immigration/ @island-is/origo
Expand Down
260 changes: 260 additions & 0 deletions apps/financial-aid/backend/src/app/formatters/applicationPdfHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
import {
ApplicationState,
calcAge,
calcDifferenceInDate,
DirectTaxPayment,
Employment,
formatNationalId,
formatPhoneNumber,
getEmploymentStatus,
getHomeCircumstances,
getMonth,
getState,
HomeCircumstances,
} from '@island.is/financial-aid/shared/lib'
import { ApplicationModel } from '../modules/application'
import format from 'date-fns/format'

const localeForNumbers = 'de-DE'
const formatNumber = (num: number) => num.toLocaleString(localeForNumbers)

export const getHeader = (created: Date, state: ApplicationState) => {
const applicationState = getState[state]
const applicationCreated = created.toISOString()

const ageOfApplication = `Aldur umsóknar: ${calcDifferenceInDate(
applicationCreated,
)}`

return {
applicationState,
applicationCreated,
ageOfApplication,
}
}

export const getApplicationInfo = (application: ApplicationModel) => {
return [
{
title: 'Dagsetning umsóknar',
content: format(application.created, 'dd.MM.y · kk:mm'),
},
{
title: 'Fyrir tímabilið',
content:
getMonth(application.appliedDate.getMonth()) +
format(application.appliedDate, ' y'),
},
application.state === ApplicationState.APPROVED && {
title: 'Samþykkt aðstoð: ',
content: `${formatNumber(application.amount[0].finalAmount)} kr.`,
},
].filter(Boolean)
}

export const getApplicant = (application: ApplicationModel) => {
return [
{
title: 'Nafn',
content: application.name,
},
{
title: 'Kennitala',
content: formatNationalId(application.nationalId),
},
{
title: 'Sími',
content: formatPhoneNumber(application.phoneNumber ?? ''),
},
{
title: 'Netfang',
content: application.email,
},

{
title: 'Bankareikningur',
content: `${application.bankNumber}-${application.ledger}-${application.accountNumber}`,
},
{
title: 'Nota persónuafslátt',
content: application.usePersonalTaxCredit ? 'Já' : 'Nei',
},
]
}

export const getApplicantMoreInfo = (application: ApplicationModel) => {
return [
{
title: 'Búsetuform',
content:
getHomeCircumstances[
application.homeCircumstances as HomeCircumstances
],
other: application.homeCircumstancesCustom,
},
{
title: 'Atvinna',
content: getEmploymentStatus[application.employment as Employment],
other: application.employmentCustom,
},
{
title: 'Lánshæft nám',
content: application.student ? 'Já' : 'Nei',
other: application.studentCustom,
},
{
title: 'Hefur haft tekjur',
content: application.hasIncome ? 'Já' : 'Nei',
},
application.homeCircumstancesCustom && {
title: 'Búsetuform athugasemd',
content: application.homeCircumstancesCustom,
},
application.employmentCustom && {
title: 'Atvinnu athugasemd',
content: application.employmentCustom,
},
].filter(Boolean)
}

export const getNationalRegistryInfo = (application: ApplicationModel) => {
return [
{
title: 'Lögheimili',
content: application.streetName ?? '',
},
{
title: 'Póstnúmer',
content: application.postalCode ?? '',
},
{
title: 'Sveitarfélag',
content: application.city ?? '',
},
{
title: 'Ríkisfang',
content: 'Ísland',
},
{
title: 'Maki',
content: application.spouseNationalId ? 'Já' : 'Nei',
},
{
title: 'Aldur',
content: calcAge(application.nationalId) + ' ára',
},
]
}

export const getApplicantSpouse = (application: ApplicationModel) => {
return [
{
title: 'Nafn',
content: application.spouseName ?? '',
},
{
title: 'Kennitala',
content: application.spouseNationalId
? formatNationalId(application.spouseNationalId)
: '',
},
{
title: 'Sími',
content: formatPhoneNumber(application.spousePhoneNumber ?? ''),
},
{
title: 'Netfang',
content: application.spouseEmail ?? '',
},
]
}

export const getChildrenInfo = (application: ApplicationModel) => {
if (!application.children) {
return []
}

const allChildren = application.children.flatMap((child) => {
return [
{
title: 'Nafn',
content: child.name ?? '',
},
{
title: 'Kennitala',
content: formatNationalId(child.nationalId),
},
{
title: 'Aldur',
content: calcAge(child.nationalId) + ' ára',
},
{
title: 'Skólastofnun',
content: child.school ?? '',
},
{
title: 'Býr hjá umsækjanda?',
content: `${child.livesWithApplicant ? 'Já' : 'Nei'}`,
},
{
title: 'Býr hjá báðum foreldrum?',
content: `${child.livesWithBothParents ? 'Já' : 'Nei'}`,
},
]
})

return allChildren
}

export const getDirectTaxPayments = (directTaxPayments: DirectTaxPayment[]) => {
if (directTaxPayments && directTaxPayments.length === 0) {
return []
}
const totalSalary = directTaxPayments.reduce(
(n, { totalSalary }) => n + totalSalary,
0,
)

return [
{
title: 'Samtals heildarlaun',
content: formatNumber(totalSalary),
},
{
title: 'Meðaltal',
content: formatNumber(Math.floor(totalSalary / directTaxPayments.length)),
},
{
title: 'Persónuafsláttur meðaltal',
content: (
directTaxPayments.reduce(
(n, { personalAllowance }) => n + personalAllowance,
0,
) / directTaxPayments.length
).toLocaleString(localeForNumbers),
},
{
title: 'Samtals staðgreiðsla',
content: directTaxPayments
.reduce((n, { withheldAtSource }) => n + withheldAtSource, 0)
.toLocaleString(localeForNumbers),
},
]
}

export const groupDirectPayments = (directTaxPayments: DirectTaxPayment[]) => {
const grouped = directTaxPayments.reduce((acc, payment) => {
const monthNumber = parseInt(payment.month.toString()) - 1

const key = `${getMonth(
monthNumber < 0 ? 12 + monthNumber : monthNumber,
)} ${payment.year}`
if (!acc[key]) {
acc[key] = []
}
acc[key].push(payment)
return acc
}, {} as Record<string, DirectTaxPayment[]>)

return grouped
}
Loading

0 comments on commit 7341945

Please sign in to comment.