Merge branch 'dashboard' into dev

This commit is contained in:
Moritz Utcke
2025-04-21 20:25:20 -03:00
2 changed files with 26 additions and 3 deletions

View File

@@ -281,6 +281,24 @@ export async function createInvoice(
};
}
export async function getLexOfficeVoucherNumber(rechnung: Rechnung) {
const request = await fetch(
`https://api.lexoffice.io/v1/invoices/${rechnung.lex_office_id}`,
{
method: "GET",
headers: {
Accept: `application/json`,
Authorization: `Bearer ${LEX_OFFICE_API_KEY}`,
"Content-Type": "application/json",
},
}
);
const response = await request.json();
return response["voucherNumber"]
}
/**

View File

@@ -20,7 +20,7 @@ import { BASE_URI } from "#lib/constants.js";
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { s3Client } from "#lib/s3.js";
import { createInvoice, getLexOfficeRechnung } from "#lib/server/invoice.js";
import { createInvoice, getLexOfficeRechnung, getLexOfficeVoucherNumber } from "#lib/server/invoice.js";
import { tryCatch } from "#lib/tryCatch.js";
import SFTPClient from 'ssh2-sftp-client';
import {
@@ -95,6 +95,7 @@ export const GET = defineApiRoute({
});
}
let voucherNumber: string = "";
if (!rechnung.lex_office_id) {
const [result, error] = await tryCatch(
createInvoice(ausweis, rechnung)
@@ -109,7 +110,9 @@ export const GET = defineApiRoute({
});
}
const { id, voucherNumber } = result;
const { id, voucherNumber: lexOfficeVoucherNumber } = result;
voucherNumber = lexOfficeVoucherNumber;
await prisma.rechnung.update({
where: {
@@ -119,6 +122,8 @@ export const GET = defineApiRoute({
lex_office_id: id,
},
});
} else {
voucherNumber = await getLexOfficeVoucherNumber(rechnung)
}
const pdfAusweis = await getAnsichtsausweis(
@@ -283,7 +288,7 @@ export const GET = defineApiRoute({
<tr><td>IBAN</td><td>:<td>\t DE81 2004 0000 0348 6008 00</td>
<tr><td>BIC</td><td>:</td><td>\t COBADEFFXXX</td>
<tr><td>Betrag</td><td>:</td><td>\t <b>${rechnung.betrag}€</b></td>
<tr><td>Verwendungszweck</td><td>:</td><td>\t <b>${rechnung.lex_office_id}</b></td>
<tr><td>Verwendungszweck</td><td>:</td><td>\t <b>${voucherNumber}</b></td>
</table>
<br>