diff --git a/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/__test__/addPlannedFlightDetails.test.ts b/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/__test__/addPlannedFlightDetails.test.ts index 52997983e..702bf8da3 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/__test__/addPlannedFlightDetails.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/__test__/addPlannedFlightDetails.test.ts @@ -46,7 +46,7 @@ describe("addPlannedFlightDetails", () => { expect(getTotalCompensationClaim).toHaveBeenCalled(); expect(mockDoc.text).toHaveBeenCalledWith( - `Streitwert: ${mockCompensation}€`, + `Streitwert: ${mockCompensation} €`, ); }); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/addPlannedFlightDetails.ts b/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/addPlannedFlightDetails.ts index aaaa4c471..1ff561456 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/addPlannedFlightDetails.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/firstPage/claimData/addPlannedFlightDetails.ts @@ -41,5 +41,5 @@ export const addPlannedFlightDetails = ( doc .fontSize(12) .font(FONTS_BUNDESSANS_BOLD) - .text(`Streitwert: ${compensationByDistance}€`); + .text(`Streitwert: ${compensationByDistance} €`); }; diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/addNewPageInCaseMissingVerticalSpace.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/addNewPageInCaseMissingVerticalSpace.ts index 60bdeb7bc..004c2f615 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/addNewPageInCaseMissingVerticalSpace.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/addNewPageInCaseMissingVerticalSpace.ts @@ -1,7 +1,7 @@ import type PDFDocument from "pdfkit"; import { PDF_HEIGHT_SEIZE } from "~/services/pdf/createPdfKitDocument"; -const MAX_VERTICAL_SPACE = PDF_HEIGHT_SEIZE - 90; +export const MAX_VERTICAL_SPACE = PDF_HEIGHT_SEIZE - 50; export const addNewPageInCaseMissingVerticalSpace = ( doc: typeof PDFDocument, diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addCompensationAmount.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addCompensationAmount.test.ts index ea5be192d..0d5fb0fe0 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addCompensationAmount.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addCompensationAmount.test.ts @@ -41,7 +41,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(addOtherDetailsItinerary).toBeCalledTimes(1); }); @@ -50,7 +50,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(addDistanceInfo).toBeCalledTimes(1); }); @@ -59,7 +59,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(mockDoc.text).toHaveBeenCalledWith( DEMANDED_COMPENSATION_PAYMENT_TEXT, @@ -75,7 +75,7 @@ describe("addCompensationAmount", () => { isWeiterePersonen: YesNoAnswer.Enum.yes, }; - addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock); expect(mockDoc.text).toHaveBeenCalledWith( OTHER_PASSENGERS_DEMANDED_COMPENSATION_PAYMENT_TEXT, @@ -86,7 +86,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(1); }); @@ -95,7 +95,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(addMultiplePersonsInfo).toBeCalledTimes(1); }); @@ -104,7 +104,7 @@ describe("addCompensationAmount", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addCompensationAmount(mockDoc, mockStruct, userDataMock, 0); + addCompensationAmount(mockDoc, mockStruct, userDataMock); expect(addWitnessesInfo).toBeCalledTimes(1); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addDistanceInfo.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addDistanceInfo.test.ts index 328683ad2..72cd8074d 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addDistanceInfo.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addDistanceInfo.test.ts @@ -63,12 +63,11 @@ describe("addDistanceInfo", () => { isWeiterePersonen: YesNoAnswer.Enum.no, }; - addDistanceInfo(mockDoc, userDataWeiterePersonenMock, 0); + addDistanceInfo(mockDoc, userDataWeiterePersonenMock); expect(mockDoc.text).toHaveBeenCalledWith( `Die Distanz zwischen ${startAirportMock} und ${endAirportMock} beträgt nach Großkreismethode ca. ${distanceValueMock} km. ${ARTICLE_AIR_PASSENGER_REGULATION_TEXT} ${compensationValueMock} €.`, PDF_MARGIN_HORIZONTAL, - undefined, ); }); @@ -81,12 +80,11 @@ describe("addDistanceInfo", () => { isWeiterePersonen: YesNoAnswer.Enum.yes, }; - addDistanceInfo(mockDoc, userDataWeiterePersonenMock, 0); + addDistanceInfo(mockDoc, userDataWeiterePersonenMock); expect(mockDoc.text).toHaveBeenCalledWith( `Die Distanz zwischen ${startAirportMock} und ${endAirportMock} beträgt nach Großkreismethode ca. ${distanceValueMock} km. ${ARTICLE_AIR_PASSENGER_REGULATION_TEXT} ${compensationValueMock} € pro Person, insgesamt aus eigenem und abgetretenem Recht damit eine Gesamtsumme von ${compensationValueMock} €.`, PDF_MARGIN_HORIZONTAL, - undefined, ); }); @@ -94,7 +92,7 @@ describe("addDistanceInfo", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addDistanceInfo(mockDoc, userDataMock, 0); + addDistanceInfo(mockDoc, userDataMock); expect(addNewPageInCaseMissingVerticalSpace).toBeCalled(); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addOtherDetailsItinerary.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addOtherDetailsItinerary.test.ts index ccd7978a8..2bc73ca54 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addOtherDetailsItinerary.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/__test__/addOtherDetailsItinerary.test.ts @@ -13,12 +13,11 @@ describe("addOtherDetailsItinerary", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addOtherDetailsItinerary(mockDoc, 0, userDataMock.zusaetzlicheAngaben); + addOtherDetailsItinerary(mockDoc, userDataMock.zusaetzlicheAngaben); expect(mockDoc.text).toHaveBeenCalledWith( OTHER_DETAILS_ITINERARY, expect.anything(), - expect.anything(), ); expect(mockDoc.text).toHaveBeenCalledWith(userDataMock.zusaetzlicheAngaben); @@ -28,12 +27,11 @@ describe("addOtherDetailsItinerary", () => { const mockStruct = mockPdfKitDocumentStructure(); const mockDoc = mockPdfKitDocument(mockStruct); - addOtherDetailsItinerary(mockDoc, 0); + addOtherDetailsItinerary(mockDoc); expect(mockDoc.text).not.toHaveBeenCalledWith( OTHER_DETAILS_ITINERARY, expect.anything(), - expect.anything(), ); }); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addCompensationAmount.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addCompensationAmount.ts index 2102d6ce9..87245cf9d 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addCompensationAmount.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addCompensationAmount.ts @@ -17,20 +17,15 @@ export const addCompensationAmount = ( doc: typeof PDFDocument, documentStruct: PDFKit.PDFStructureElement, userData: FluggastrechtContext, - compensationStartYPosition: number, ) => { const compensationSect = doc.struct("Sect"); compensationSect.add( doc.struct("P", {}, () => { doc.font(FONTS_BUNDESSANS_REGULAR).fontSize(10); - addOtherDetailsItinerary( - doc, - compensationStartYPosition, - userData.zusaetzlicheAngaben, - ); + addOtherDetailsItinerary(doc, userData.zusaetzlicheAngaben); - addDistanceInfo(doc, userData, compensationStartYPosition); + addDistanceInfo(doc, userData); addNewPageInCaseMissingVerticalSpace(doc); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addDistanceInfo.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addDistanceInfo.ts index 194b11673..d1bf36f6c 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addDistanceInfo.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addDistanceInfo.ts @@ -5,8 +5,10 @@ import { calculateDistanceBetweenAirportsInKilometers } from "~/domains/fluggast import { getAirportNameByIataCode } from "~/domains/fluggastrechte/services/airports/getAirportNameByIataCode"; import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment"; import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations"; -import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument"; -import { getStartYPosition } from "./getStartYPosition"; +import { + PDF_MARGIN_HORIZONTAL, + PDF_WIDTH_SEIZE, +} from "~/services/pdf/createPdfKitDocument"; import { addNewPageInCaseMissingVerticalSpace } from "../../addNewPageInCaseMissingVerticalSpace"; export const ARTICLE_AIR_PASSENGER_REGULATION_TEXT = @@ -40,34 +42,19 @@ const getDistanceText = (userData: FluggastrechtContext): string => { return `${distanceText} pro Person, insgesamt aus eigenem und abgetretenem Recht damit eine Gesamtsumme von ${compensationTotalAmountValue} €.`; }; -const getYPositionDistanceText = ( - doc: typeof PDFDocument, - compensationStartYPosition: number, - zusaetzlicheAngaben?: string, -): number => { - // in case exist the zusaetzlicheAngaben should start to print from the last y position of the document, otherwise from the value compensationStartYPosition - return typeof zusaetzlicheAngaben !== "undefined" && - zusaetzlicheAngaben.length > 0 - ? doc.y - : getStartYPosition(compensationStartYPosition, doc.y); -}; - export const addDistanceInfo = ( doc: typeof PDFDocument, userData: FluggastrechtContext, - compensationStartYPosition: number, ) => { - addNewPageInCaseMissingVerticalSpace(doc); + const distanceText = getDistanceText(userData); + + const distanceTextHeight = doc.heightOfString(distanceText, { + width: PDF_WIDTH_SEIZE, + }); + + addNewPageInCaseMissingVerticalSpace(doc, distanceTextHeight); doc - .text( - getDistanceText(userData), - PDF_MARGIN_HORIZONTAL, - getYPositionDistanceText( - doc, - compensationStartYPosition, - userData.zusaetzlicheAngaben, - ), - ) + .text(distanceText, PDF_MARGIN_HORIZONTAL) .moveDown(MARGIN_BETWEEN_SECTIONS); }; diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addOtherDetailsItinerary.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addOtherDetailsItinerary.ts index 079e8c888..4bda380ed 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addOtherDetailsItinerary.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/addOtherDetailsItinerary.ts @@ -1,31 +1,39 @@ import type PDFDocument from "pdfkit"; import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations"; -import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument"; -import { getStartYPosition } from "./getStartYPosition"; +import { + PDF_MARGIN_HORIZONTAL, + PDF_WIDTH_SEIZE, +} from "~/services/pdf/createPdfKitDocument"; import { addNewPageInCaseMissingVerticalSpace } from "../../addNewPageInCaseMissingVerticalSpace"; export const OTHER_DETAILS_ITINERARY = "Weitere Angaben zum Reiseverlauf:"; export const addOtherDetailsItinerary = ( doc: typeof PDFDocument, - compensationStartYPosition: number, zusaetzlicheAngaben?: string, ) => { if ( typeof zusaetzlicheAngaben !== "undefined" && zusaetzlicheAngaben.length > 0 ) { + const otherDetailsItineraryHeight = doc.heightOfString( + OTHER_DETAILS_ITINERARY, + { + width: PDF_WIDTH_SEIZE, + }, + ); + const zusaetzlicheAngabenHeight = doc.heightOfString(zusaetzlicheAngaben, { - width: doc.widthOfString(zusaetzlicheAngaben), + width: PDF_WIDTH_SEIZE, }); - addNewPageInCaseMissingVerticalSpace(doc, zusaetzlicheAngabenHeight); + + addNewPageInCaseMissingVerticalSpace( + doc, + zusaetzlicheAngabenHeight + otherDetailsItineraryHeight, + ); doc - .text( - OTHER_DETAILS_ITINERARY, - PDF_MARGIN_HORIZONTAL, - getStartYPosition(compensationStartYPosition, doc.y), // start to print this text from this line - ) + .text(OTHER_DETAILS_ITINERARY, PDF_MARGIN_HORIZONTAL) .text(zusaetzlicheAngaben) .moveDown(MARGIN_BETWEEN_SECTIONS); } diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/getStartYPosition.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/getStartYPosition.ts deleted file mode 100644 index b2658348e..000000000 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/compensationAmount/getStartYPosition.ts +++ /dev/null @@ -1,7 +0,0 @@ -// check if should use the current Y position before to use the compensation start y position -export const getStartYPosition = ( - compensationStartYPosition: number, - currentYPosition: number, -) => { - return currentYPosition < 200 ? currentYPosition : compensationStartYPosition; -}; diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/createFactsOfCases.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/createFactsOfCases.ts index e4fd71803..8b414992b 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/createFactsOfCases.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/createFactsOfCases.ts @@ -35,19 +35,5 @@ export const createFactsOfCases = ( addNewPageInCaseMissingVerticalSpace(doc, COLUMN_HEIGHT * 4 + MARGIN_BOTTOM); const startTableY = doc.y; addTable(doc, documentStruct, startTableY, userData); - // Set tableEndYPosition based on the existence of `andereErsatzverbindungBeschreibung` - const tableEndYPosition = startTableY + COLUMN_HEIGHT * 4 + MARGIN_BOTTOM; - doc.moveDown(MARGIN_BETWEEN_SECTIONS); - const startCompensationYPosition = - typeof userData.andereErsatzverbindungBeschreibung !== "undefined" && - userData.andereErsatzverbindungBeschreibung.length >= 0 - ? doc.y - : tableEndYPosition; - - addCompensationAmount( - doc, - documentStruct, - userData, - startCompensationYPosition, - ); + addCompensationAmount(doc, documentStruct, userData); }; diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addDetailedReason.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addDetailedReason.test.ts index 7e49a3b56..a1b340535 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addDetailedReason.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addDetailedReason.test.ts @@ -7,6 +7,7 @@ import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument"; import { YesNoAnswer } from "~/services/validation/YesNoAnswer"; import { addDetailedReason, + ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT, ATTACHMENT_CONFIRM_BOOKING_TEXT, CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT, CONFIRM_BOOKING_TEXT, @@ -58,7 +59,7 @@ describe("addDetailedReason", () => { ); expect(mockDoc.text).toHaveBeenCalledWith( - ATTACHMENT_CONFIRM_BOOKING_TEXT, + ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT, PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT, ); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addMultiplePersonsText.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addMultiplePersonsText.test.ts index ba8dbc7a7..72927ce14 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addMultiplePersonsText.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/__test__/addMultiplePersonsText.test.ts @@ -142,9 +142,13 @@ describe("addMultiplePersonsText", () => { addMultiplePersonsText(mockDoc, userDataWeiterePersonenMock); expect(mockDoc.text).toHaveBeenCalledWith( - "1. Die klagende Partei Test Test", + "1. ", + expect.anything(), + undefined, expect.anything(), ); + + expect(mockDoc.text).toHaveBeenCalledWith("Die klagende Partei Test Test"); }); it("should have the text for persons names given weiter personen", () => { @@ -164,6 +168,7 @@ describe("addMultiplePersonsText", () => { strasseHausnummer: "strasseHausnummer", ort: "ort", plz: "plz", + telefonnummer: "telefonnummer", }, { vorname: "vorname2", @@ -173,18 +178,35 @@ describe("addMultiplePersonsText", () => { plz: "plz", buchungsnummer: "123456", }, + { + vorname: "vorname3", + nachname: "nachname3", + strasseHausnummer: "strasseHausnummer", + ort: "ort", + plz: "plz", + }, ], isWeiterePersonen: YesNoAnswer.Values.yes, }; addMultiplePersonsText(mockDoc, userDataWeiterePersonenMock); + expect(mockDoc.text).toHaveBeenCalledWith("2. ", expect.anything()); + + expect(mockDoc.text).toHaveBeenCalledWith( + "Vorname nachname, strasseHausnummer, plz ort, Telefonnummer telefonnummer", + ); + + expect(mockDoc.text).toHaveBeenCalledWith("3. ", expect.anything()); + expect(mockDoc.text).toHaveBeenCalledWith( - "2. Vorname nachname, strasseHausnummer, plz ort", + "Vorname2 nachname2, strasseHausnummer, plz ort, abweichende Buchungsnummer: 123456", ); + expect(mockDoc.text).toHaveBeenCalledWith("4. ", expect.anything()); + expect(mockDoc.text).toHaveBeenCalledWith( - "3. Vorname2 nachname2, strasseHausnummer, plz ort, abweichende Buchungsnummer: 123456", + "Vorname3 nachname3, strasseHausnummer, plz ort", ); }); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addDetailedReason.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addDetailedReason.ts index 99b463322..3c13a541d 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addDetailedReason.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addDetailedReason.ts @@ -13,6 +13,8 @@ export const CONFIRM_BOOKING_TEXT = "Eine bestätigte Buchung liegt vor."; export const CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT = "Bestätigte Buchungen der klagenden Partei und der weiteren Fluggäste liegen vor."; export const ATTACHMENT_CONFIRM_BOOKING_TEXT = + "Beweis: Anlage Buchungsbetätigung"; +export const ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT = "Beweis: Anlage Buchungsbestätigungen"; export const PLAINTIFF_ON_TIME_TEXT = "Die klagende Partei war pünktlich zum Check-in und Boarding."; @@ -20,14 +22,21 @@ export const PLAINTIFF_ON_TIME_MULTIPLE_PERSONS_TEXT = "Die klagende Partei und die weiteren Fluggäste waren pünktlich zum Check-in und Boarding."; export const MARGIN_RIGHT = 10; -const getConfirmationBookingText = ({ +const getConfirmationBookingTexts = ({ isWeiterePersonen, }: FluggastrechtContext) => { if (isWeiterePersonen === "yes") { - return CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT; + return { + confirmationBooking: CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT, + attachmentConfirmationBooking: + ATTACHMENT_CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT, + }; } - return CONFIRM_BOOKING_TEXT; + return { + confirmationBooking: CONFIRM_BOOKING_TEXT, + attachmentConfirmationBooking: ATTACHMENT_CONFIRM_BOOKING_TEXT, + }; }; export const addDetailedReason = ( @@ -36,16 +45,20 @@ export const addDetailedReason = ( userData: FluggastrechtContext, ) => { const detailedReasonSect = doc.struct("Sect"); + + const { attachmentConfirmationBooking, confirmationBooking } = + getConfirmationBookingTexts(userData); + detailedReasonSect.add( doc.struct("P", {}, () => { doc .font(FONTS_BUNDESSANS_REGULAR) .fontSize(10) - .text(getConfirmationBookingText(userData)) + .text(confirmationBooking) .moveDown(0.5) .font(FONTS_BUNDESSANS_BOLD) .text( - ATTACHMENT_CONFIRM_BOOKING_TEXT, + attachmentConfirmationBooking, PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT, ) .font(FONTS_BUNDESSANS_REGULAR) diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addMultiplePersonsText.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addMultiplePersonsText.ts index e0645ab74..24a933fe6 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addMultiplePersonsText.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/detailedReason/addMultiplePersonsText.ts @@ -2,7 +2,11 @@ import type PDFDocument from "pdfkit"; import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context"; import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations"; import type { FluggastrechtBereichType } from "~/domains/fluggastrechte/vorabcheck/context"; -import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument"; +import { + FONTS_BUNDESSANS_BOLD, + FONTS_BUNDESSANS_REGULAR, + PDF_MARGIN_HORIZONTAL, +} from "~/services/pdf/createPdfKitDocument"; import { arrayIsNonEmpty } from "~/util/array"; import { getFullPlaintiffName } from "../../../getFullPlaintiffName"; @@ -23,6 +27,14 @@ const getTextBookingNumber = (buchungsnummer?: string) => { return `, abweichende Buchungsnummer: ${buchungsnummer}`; }; +const getTextTelefonNumber = (telefonnummer?: string) => { + if (typeof telefonnummer === "undefined" || telefonnummer.length === 0) { + return ""; + } + + return `, Telefonnummer ${telefonnummer}`; +}; + export const addMultiplePersonsText = ( doc: typeof PDFDocument, userData: FluggastrechtContext, @@ -39,9 +51,13 @@ export const addMultiplePersonsText = ( `Folgende Personen waren von dieser ${bereichMappingText[userData.bereich as FluggastrechtBereichType] ?? ""} betroffen:`, PDF_MARGIN_HORIZONTAL, ) + .font(FONTS_BUNDESSANS_BOLD) + .text("1. ", PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT - 5, undefined, { + continued: true, + }) + .font(FONTS_BUNDESSANS_REGULAR) .text( - `1. Die klagende Partei ${getFullPlaintiffName(userData.anrede, userData.title, userData.vorname, userData.nachname)}`, - PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT - 5, + `Die klagende Partei ${getFullPlaintiffName(userData.anrede, userData.title, userData.vorname, userData.nachname)}`, ); userData.weiterePersonen.forEach( @@ -55,12 +71,19 @@ export const addMultiplePersonsText = ( strasseHausnummer, ort, plz, + telefonnummer, }, index, ) => { - doc.text( - `${index + 2}. ${getFullPlaintiffName(anrede, title, vorname, nachname)}, ${strasseHausnummer}, ${plz} ${ort}${getTextBookingNumber(buchungsnummer)}`, - ); + doc + .font(FONTS_BUNDESSANS_BOLD) + .text(`${index + 2}. `, { + continued: true, + }) + .font(FONTS_BUNDESSANS_REGULAR) + .text( + `${getFullPlaintiffName(anrede, title, vorname, nachname)}, ${strasseHausnummer}, ${plz} ${ort}${getTextTelefonNumber(telefonnummer)}${getTextBookingNumber(buchungsnummer)}`, + ); }, ); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/__test__/addTableInfo.test.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/__test__/addTableInfo.test.ts index 17a828e40..fa472c6c9 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/__test__/addTableInfo.test.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/__test__/addTableInfo.test.ts @@ -29,14 +29,8 @@ describe("addTableInfo", () => { const mockDoc = mockPdfKitDocument(mockStruct); const andereErsatzverbindungBeschreibung = "Sample description"; - const tableEndYPosition = 100; - addTableInfo( - mockDoc, - mockStruct, - andereErsatzverbindungBeschreibung, - tableEndYPosition, - ); + addTableInfo(mockDoc, mockStruct, andereErsatzverbindungBeschreibung); expect(mockDoc.struct).toHaveBeenCalledWith("Sect"); @@ -47,7 +41,6 @@ describe("addTableInfo", () => { expect(mockDoc.text).toHaveBeenCalledWith( andereErsatzverbindungBeschreibung, PDF_MARGIN_HORIZONTAL, - 100, ); }); @@ -56,14 +49,8 @@ describe("addTableInfo", () => { const mockDoc = mockPdfKitDocument(mockStruct); const andereErsatzverbindungBeschreibung = "Sample description"; - const tableEndYPosition = 100; - addTableInfo( - mockDoc, - mockStruct, - andereErsatzverbindungBeschreibung, - tableEndYPosition, - ); + addTableInfo(mockDoc, mockStruct, andereErsatzverbindungBeschreibung); expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(1); }); diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTable.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTable.ts index 1a672cf93..f643e3a60 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTable.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTable.ts @@ -21,13 +21,13 @@ export function addTable( tableSect.add(table); // Add the table to the section documentStruct.add(tableSect); // Add the section to the parent structure doc.fill("black"); // Fill black due next pages of the table - - // Set tableEndYPosition based on the existence of `andereErsatzverbindungBeschreibung` + // Get end position of the table generated const tableEndYPosition = startTableY + COLUMN_HEIGHT * 4 + MARGIN_BOTTOM; + // reset the position of the table + doc.y = tableEndYPosition; addTableInfo( doc, documentStruct, userData.andereErsatzverbindungBeschreibung ?? "", - tableEndYPosition, ); } diff --git a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTableInfo.ts b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTableInfo.ts index d938e6709..8a958bc19 100644 --- a/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTableInfo.ts +++ b/app/domains/fluggastrechte/services/pdf/sections/reason/factsOfCases/table/addTableInfo.ts @@ -1,25 +1,28 @@ +import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations"; import { FONTS_BUNDESSANS_REGULAR, PDF_MARGIN_HORIZONTAL, - PDF_MARGIN_VERTICAL, + PDF_WIDTH_SEIZE, } from "~/services/pdf/createPdfKitDocument"; -import { COLUMN_HEIGHT } from "./tableConfigurations"; import { addNewPageInCaseMissingVerticalSpace } from "../../addNewPageInCaseMissingVerticalSpace"; export function addTableInfo( doc: PDFKit.PDFDocument, documentStruct: PDFKit.PDFStructureElement, andereErsatzverbindungBeschreibung: string, - tableEndYPosition: number, ) { + if (andereErsatzverbindungBeschreibung.length === 0) { + return; + } + const tableInfoHeight = doc.heightOfString( - andereErsatzverbindungBeschreibung ?? "", + andereErsatzverbindungBeschreibung, { - width: doc.widthOfString(andereErsatzverbindungBeschreibung ?? ""), + width: PDF_WIDTH_SEIZE, }, ); - addNewPageInCaseMissingVerticalSpace(doc, tableInfoHeight + COLUMN_HEIGHT); + addNewPageInCaseMissingVerticalSpace(doc, tableInfoHeight); const reasonSect = doc.struct("Sect"); reasonSect.add( @@ -27,13 +30,10 @@ export function addTableInfo( doc .fontSize(10) .font(FONTS_BUNDESSANS_REGULAR) - .text( - andereErsatzverbindungBeschreibung ?? "", - PDF_MARGIN_HORIZONTAL, - // in case the current doc.y position is same the vertical margin, the document jump to a new page, so it should start the current doc.y position - doc.y === PDF_MARGIN_VERTICAL ? doc.y : tableEndYPosition, - ); + .text(andereErsatzverbindungBeschreibung, PDF_MARGIN_HORIZONTAL) + .moveDown(MARGIN_BETWEEN_SECTIONS); }), ); + documentStruct.add(reasonSect); } diff --git a/app/services/pdf/createPdfKitDocument.ts b/app/services/pdf/createPdfKitDocument.ts index 8e84c01c0..a943a0b3c 100644 --- a/app/services/pdf/createPdfKitDocument.ts +++ b/app/services/pdf/createPdfKitDocument.ts @@ -9,6 +9,7 @@ export const FONTS_BUNDESSANS_BOLD = "BundesSansWebBold"; export const PDF_MARGIN_VERTICAL = 50; export const PDF_MARGIN_HORIZONTAL = 70; export const PDF_HEIGHT_SEIZE = 780; +export const PDF_WIDTH_SEIZE = 460; export const LINE_GAP_GLOBAL = 2; const bundesSansWebRegular = await readRelativeFileToBuffer(