Aushang PDF
This commit is contained in:
@@ -16,8 +16,9 @@ import { join } from "path"
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "astro:content";
|
||||
import { transport } from "#lib/mail.js";
|
||||
import { Attachment } from 'nodemailer/lib/mailer';
|
||||
import { BASE_URI } from "#lib/constants.js";
|
||||
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
||||
import { getAnsichtsausweis, getDatenblatt, getAushang } from "#lib/server/ausweis.js";
|
||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { s3Client } from "#lib/s3.js";
|
||||
import { createInvoice, getLexOfficeRechnung, getLexOfficeVoucherNumber } from "#lib/server/invoice.js";
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
getVerbrauchsausweisWohnenKomplett,
|
||||
} from "#lib/server/db.js";
|
||||
import { PDFDocument } from "pdf-lib";
|
||||
import * as fs from 'fs';
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
input: z.object({
|
||||
@@ -143,6 +145,16 @@ export const GET = defineApiRoute({
|
||||
ausweis.rechnung
|
||||
);
|
||||
|
||||
const pdfAushang = await getAushang(
|
||||
ausweis,
|
||||
ausweis.aufnahme,
|
||||
ausweis.aufnahme.objekt,
|
||||
ausweis.aufnahme.bilder,
|
||||
ausweis.aufnahme.objekt.benutzer,
|
||||
false,
|
||||
ausweis.rechnung
|
||||
);
|
||||
|
||||
// TODO: Das ist immer noch scheiße, LexOffice ist doof
|
||||
// Hier müssen wir warten, damit wir sichergehen können, dass die Rechnung bei LexOffice existiert.
|
||||
setTimeout(async () => {
|
||||
@@ -196,6 +208,17 @@ export const GET = defineApiRoute({
|
||||
|
||||
await s3Client.send(rechnungsCommand);
|
||||
|
||||
if (pdfAushang){
|
||||
const aushangCommand = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Aushang.pdf`,
|
||||
Body: pdfDatenblatt,
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
await s3Client.send(rechnungsCommand);
|
||||
}
|
||||
|
||||
// Falls Postversand angefragt wurde müssen wir die Dateien auf den Postserver hochladen
|
||||
if (post) {
|
||||
const dateiNameDruck = `1011000000000-AW_ID_${ausweis.id}.pdf`;
|
||||
@@ -212,6 +235,10 @@ export const GET = defineApiRoute({
|
||||
|
||||
await appendPdf(pdfDatenblatt);
|
||||
await appendPdf(pdfAusweis);
|
||||
|
||||
if (pdfAushang){
|
||||
await appendPdf(pdfAushang);
|
||||
}
|
||||
|
||||
const pdfBytes = await outputPdf.save();
|
||||
|
||||
@@ -317,31 +344,43 @@ export const GET = defineApiRoute({
|
||||
</p>`;
|
||||
}
|
||||
|
||||
const attachments: Attachment[] = [
|
||||
{
|
||||
filename: `ID_${ausweis.id}_Energieausweis.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfAusweis),
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
{
|
||||
filename: `ID_${ausweis.id}_Datenblatt.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfDatenblatt),
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
{
|
||||
filename: `ID_${ausweis.id}_Rechnung.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfRechnung),
|
||||
contentType: "application/pdf",
|
||||
}
|
||||
];
|
||||
|
||||
if (pdfAushang) {
|
||||
attachments.push({
|
||||
filename: `ID_${ausweis.id}_Aushang.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfAushang),
|
||||
contentType: "application/pdf",
|
||||
});
|
||||
}
|
||||
|
||||
await transport.sendMail({
|
||||
from: `"IBCornelsen" <info@online-energieausweis.org>`,
|
||||
to: rechnung.email || rechnung.benutzer.email,
|
||||
bcc: "info@online-energieausweis.org",
|
||||
subject: `Ihr Originalausweis vom Ingenieurbüro Cornelsen (ID: ${ausweis.id})`,
|
||||
html,
|
||||
attachments: [{
|
||||
filename: `ID_${ausweis.id}_Energieausweis.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfAusweis),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}, {
|
||||
filename: `ID_${ausweis.id}_Datenblatt.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfDatenblatt),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}, {
|
||||
filename: `ID_${ausweis.id}_Rechnung.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfRechnung),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}]
|
||||
attachments
|
||||
});
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
|
||||
Reference in New Issue
Block a user