Skip to content

Commit

Permalink
feat(j-s): Confirmed subpoena stamp (#15871)
Browse files Browse the repository at this point in the history
* Checkpoint

* Cleanup

* Rename

* Refactor

* Remove unused code

* Fix lint

* Make confirmation smaller

* Use correct date

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
oddsson and kodiakhq[bot] authored Sep 6, 2024
1 parent 535fd14 commit d8fa83a
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { formatDate, lowercase } from '@island.is/judicial-system/formatters'

import {
calculatePt,
Confirmation,
drawTextWithEllipsisPDFKit,
IndictmentConfirmation,
smallFontSize,
} from './pdfHelpers'
import { PDFKitCoatOfArms } from './PDFKitCoatOfArms'

export const createConfirmedIndictment = async (
confirmation: IndictmentConfirmation,
confirmation: Confirmation,
indictmentPDF: Buffer,
): Promise<Buffer> => {
const pdfDoc = await PDFDocument.load(indictmentPDF)
Expand Down
2 changes: 1 addition & 1 deletion apps/judicial-system/backend/src/app/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
formatPostponedCourtDateEmailNotification,
stripHtmlTags,
} from './formatters'
export { IndictmentConfirmation } from './pdfHelpers'
export { Confirmation } from './pdfHelpers'
export { getRequestPdfAsBuffer, getRequestPdfAsString } from './requestPdf'
export { getRulingPdfAsBuffer, getRulingPdfAsString } from './rulingPdf'
export { createCaseFilesRecord } from './caseFilesRecordPdf'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
addNormalPlusJustifiedText,
addNormalPlusText,
addNormalText,
IndictmentConfirmation,
Confirmation,
setTitle,
} from './pdfHelpers'

Expand Down Expand Up @@ -52,7 +52,7 @@ const roman = (num: number) => {
export const createIndictment = async (
theCase: Case,
formatMessage: FormatMessage,
confirmation?: IndictmentConfirmation,
confirmation?: Confirmation,
): Promise<Buffer> => {
const doc = new PDFDocument({
size: 'A4',
Expand Down
106 changes: 101 additions & 5 deletions apps/judicial-system/backend/src/app/formatters/pdfHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatDate, lowercase } from '@island.is/judicial-system/formatters'
import { coatOfArms } from './coatOfArms'
import { policeStar } from './policeStar'

export interface IndictmentConfirmation {
export interface Confirmation {
actor: string
title?: string
institution: string
Expand All @@ -22,6 +22,10 @@ export const largeFontSize = 18
export const hugeFontSize = 26
export const giganticFontSize = 33

const lightGray = '#FAFAFA'
const darkGray = '#CBCBCB'
const gold = '#ADA373'

const setFont = (doc: PDFKit.PDFDocument, font?: string) => {
if (font) {
doc.font(font)
Expand Down Expand Up @@ -106,13 +110,105 @@ export const addPoliceStar = (doc: PDFKit.PDFDocument) => {
doc.scale(25).translate(-270, -70)
}

export const addConfirmation = (
doc: PDFKit.PDFDocument,
confirmation: Confirmation,
) => {
const pageMargin = calculatePt(18)
const shaddowHeight = calculatePt(70)
const coatOfArmsWidth = calculatePt(105)
const coatOfArmsX = pageMargin + calculatePt(8)
const titleHeight = calculatePt(24)
const titleX = coatOfArmsX + coatOfArmsWidth + calculatePt(8)
const institutionWidth = calculatePt(160)
const confirmedByWidth = institutionWidth + calculatePt(48)
const shaddowWidth = institutionWidth + confirmedByWidth + coatOfArmsWidth
const titleWidth = institutionWidth + confirmedByWidth

// Draw the shadow
doc
.rect(pageMargin, pageMargin + calculatePt(8), shaddowWidth, shaddowHeight)
.fill(lightGray)
.stroke()

// Draw the coat of arms
doc
.rect(coatOfArmsX, pageMargin, coatOfArmsWidth, shaddowHeight)
.fillAndStroke('white', darkGray)

addCoatOfArms(doc, calculatePt(49), calculatePt(24))

// Draw the title
doc
.rect(coatOfArmsX + coatOfArmsWidth, pageMargin, titleWidth, titleHeight)
.fillAndStroke(lightGray, darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc
.fontSize(calculatePt(smallFontSize))
.text('Réttarvörslugátt', titleX, pageMargin + calculatePt(9))
doc.font('Times-Roman')
// The X value here is approx. 8px after the title
doc.text('Rafræn staðfesting', calculatePt(210), pageMargin + calculatePt(9))
doc.text(
formatDate(confirmation.date) || '',
shaddowWidth - calculatePt(24),
pageMargin + calculatePt(9),
)

// Draw the institution
doc
.rect(
coatOfArmsX + coatOfArmsWidth,
pageMargin + titleHeight,
institutionWidth,
shaddowHeight - titleHeight,
)
.fillAndStroke('white', darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc.text('Dómstóll', titleX, pageMargin + titleHeight + calculatePt(10))
doc.font('Times-Roman')
drawTextWithEllipsis(
doc,
confirmation.institution,
titleX,
pageMargin + titleHeight + calculatePt(22),
institutionWidth - calculatePt(16),
)

// Draw the actor
doc
.rect(
coatOfArmsX + coatOfArmsWidth + institutionWidth,
pageMargin + titleHeight,
confirmedByWidth,
shaddowHeight - titleHeight,
)
.fillAndStroke('white', darkGray)
doc.fill('black')
doc.font('Times-Bold')
doc.text(
'Samþykktaraðili',
titleX + institutionWidth,
pageMargin + titleHeight + calculatePt(10),
)
doc.font('Times-Roman')
doc.text(
`${confirmation.actor}${
confirmation.title ? `, ${lowercase(confirmation.title)}` : ''
}`,
titleX + institutionWidth,
pageMargin + titleHeight + calculatePt(22),
)

doc.fillColor('black')
}

export const addIndictmentConfirmation = (
doc: PDFKit.PDFDocument,
confirmation: IndictmentConfirmation,
confirmation: Confirmation,
) => {
const lightGray = '#FAFAFA'
const darkGray = '#CBCBCB'
const gold = '#ADA373'
const pageMargin = calculatePt(18)
const shaddowHeight = calculatePt(90)
const coatOfArmsWidth = calculatePt(105)
Expand Down
15 changes: 15 additions & 0 deletions apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { subpoena as strings } from '../messages'
import { Case } from '../modules/case'
import { Defendant } from '../modules/defendant'
import {
addConfirmation,
addEmptyLines,
addFooter,
addHugeHeading,
Expand Down Expand Up @@ -49,6 +50,11 @@ export const createSubpoena = (
doc.on('data', (chunk) => sinc.push(chunk))

setTitle(doc, formatMessage(strings.title))

if (dateLog) {
addEmptyLines(doc, 5)
}

addNormalText(doc, `${theCase.court?.name}`, 'Times-Bold', true)

addNormalRightAlignedText(
Expand Down Expand Up @@ -148,6 +154,15 @@ export const createSubpoena = (

addFooter(doc)

if (dateLog) {
addConfirmation(doc, {
actor: theCase.judge?.name || '',
title: theCase.judge?.title,
institution: theCase.judge?.institution?.name || '',
date: dateLog.created,
})
}

doc.end()

return new Promise<Buffer>((resolve) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
prosecutorRule,
publicProsecutorStaffRule,
} from '../../guards'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { UserService } from '../user'
import { CreateCaseDto } from './dto/createCase.dto'
import { TransitionCaseDto } from './dto/transitionCase.dto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
import { AwsS3Service } from '../aws-s3'
import { CourtService } from '../court'
import { Defendant, DefendantService } from '../defendant'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { EventLog, EventLogService } from '../event-log'
import { CaseFile, FileService } from '../file'
import { IndictmentCount } from '../indictment-count'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CaseDecision,
CaseState,
CaseType,
DateType,
getIndictmentVerdictAppealDeadline,
IndictmentCaseReviewDecision,
InstitutionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
restrictionCases,
} from '@island.is/judicial-system/types'

import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { DeliverDto } from './dto/deliver.dto'
import { DeliverCancellationNoticeDto } from './dto/deliverCancellationNotice.dto'
import { InternalCasesDto } from './dto/internalCases.dto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { AwsS3Service } from '../aws-s3'
import { CourtDocumentFolder, CourtService } from '../court'
import { courtSubtypes } from '../court/court.service'
import { Defendant, DefendantService } from '../defendant'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { CaseFile, FileService } from '../file'
import { IndictmentCount, IndictmentCountService } from '../indictment-count'
import { Institution } from '../institution'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {

import { nowFactory } from '../../factories'
import { defenderRule, prisonSystemStaffRule } from '../../guards'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { User } from '../user'
import { TransitionCaseDto } from './dto/transitionCase.dto'
import { UpdateCaseDto } from './dto/updateCase.dto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
} from '@island.is/judicial-system/types'

import {
Confirmation,
createCaseFilesRecord,
createIndictment,
createSubpoena,
getCourtRecordPdfAsBuffer,
getCustodyNoticePdfAsBuffer,
getRequestPdfAsBuffer,
getRulingPdfAsBuffer,
IndictmentConfirmation,
} from '../../formatters'
import { AwsS3Service } from '../aws-s3'
import { Defendant } from '../defendant'
Expand Down Expand Up @@ -206,7 +206,7 @@ export class PdfService {
)
}

let confirmation: IndictmentConfirmation | undefined = undefined
let confirmation: Confirmation | undefined = undefined

if (hasIndictmentCaseBeenSubmittedToCourt(theCase.state)) {
if (theCase.indictmentHash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {
restrictionCases,
} from '@island.is/judicial-system/types'

import {
CaseCompletedGuard,
CaseTypeGuard,
CaseWriteGuard,
} from '../../../case'
import { CaseTypeGuard, CaseWriteGuard } from '../../../case'
import { LimitedAccessFileController } from '../../limitedAccessFile.controller'

describe('LimitedAccessFileController - Create presigned post guards', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ import {
} from '../../formatters'
import { notifications } from '../../messages'
import { type Case, DateLog } from '../case'
import { ExplanatoryComment } from '../case/models/explanatoryComment.model'
import { CourtService } from '../court'
import { type Defendant, DefendantService } from '../defendant'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { type User } from '@island.is/judicial-system/types'
import { CaseState, NotificationType } from '@island.is/judicial-system/types'

import { type Case } from '../case'
import { CaseEvent, EventService } from '../event'
import { EventService } from '../event'
import { SendNotificationResponse } from './models/sendNotification.response'

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { render, screen } from '@testing-library/react'

import {
CaseDecision,
CaseFileCategory,
CaseType,
} from '@island.is/judicial-system-web/src/graphql/schema'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useRouter } from 'next/router'
import { Box, Option, Select, Text } from '@island.is/island-ui/core'
import * as constants from '@island.is/judicial-system/consts'
import { formatDate } from '@island.is/judicial-system/formatters'
import { isCompletedCase } from '@island.is/judicial-system/types'
import { core, titles } from '@island.is/judicial-system-web/messages'
import {
BlueBox,
Expand Down

0 comments on commit d8fa83a

Please sign in to comment.