Skip to content

Commit

Permalink
Merge branch 'main' into fix/delegation-index
Browse files Browse the repository at this point in the history
  • Loading branch information
magnearun authored Oct 30, 2024
2 parents d9b2391 + 0947e07 commit cd7d144
Show file tree
Hide file tree
Showing 268 changed files with 6,112 additions and 2,603 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
node_modules/
dist/
scripts/ci/
/cache*
/cache*
cache/
.git/
log/
*.log
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
2 changes: 2 additions & 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 Expand Up @@ -383,6 +384,7 @@ codemagic.yaml
/scripts/postinstall.js @island-is/devops @island-is/core
/scripts/codegen.js @island-is/devops @island-is/core
/charts/ @island-is/devops
.dockerignore @island-is/devops


# System tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ export class ApplicationController {
async delete(
@Param('id', new ParseUUIDPipe()) id: string,
@CurrentUser() user: User,
@CurrentLocale() locale: Locale,
) {
const { nationalId } = user
const existingApplication =
Expand All @@ -1097,6 +1098,53 @@ export class ApplicationController {
)
}

const template = await getApplicationTemplateByTypeId(
existingApplication.typeId,
)
if (template === null) {
throw new BadRequestException(
`No application template exists for type: ${existingApplication.typeId}`,
)
}

let onDeleteActions = new ApplicationTemplateHelper(
existingApplication,
template,
).getOnDeleteStateAPIAction()
if (onDeleteActions) {
const namespaces = await getApplicationTranslationNamespaces(
existingApplication,
)
if (!Array.isArray(onDeleteActions)) {
onDeleteActions = [onDeleteActions]
}

const intl = await this.intlService.useIntl(namespaces, locale)
const deletingApplication = await this.templateApiActionRunner.run(
existingApplication,
onDeleteActions,
user,
locale,
intl.formatMessage,
)

for (const api of onDeleteActions) {
const result =
deletingApplication.externalData[api.externalDataId || api.action]

this.logger.debug(
`Performing action ${api.action} on ${JSON.stringify(
template.name,
)} ended with ${result.status}`,
)

if (result.status === 'failure' && api.throwOnError) {
const reason = result.reason ?? 'Unknown error'
throw new TemplateApiError(reason, 500)
}
}
}

// delete charge in FJS
await this.applicationChargeService.deleteCharge(existingApplication)

Expand All @@ -1111,5 +1159,12 @@ export class ApplicationController {
)

await this.applicationService.delete(existingApplication.id)

this.auditService.audit({
auth: user,
action: 'delete',
resources: existingApplication.id,
meta: { type: existingApplication.typeId },
})
}
}
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 cd7d144

Please sign in to comment.