fix: PDF généré côté serveur (pdf-lib) - 1 page A4 portrait garantie
This commit is contained in:
@@ -2269,9 +2269,33 @@ export const appRouter = router({
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
/** Génère le PDF côté serveur et le retourne en base64 */
|
||||
generatePdf: protectedProcedure
|
||||
.input(z.object({ id: z.number() }))
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const data = await getFreeproImportWithLines(input.id);
|
||||
if (!data) throw new TRPCError({ code: "NOT_FOUND" });
|
||||
if (data.import.userId !== ctx.user.id)
|
||||
throw new TRPCError({ code: "FORBIDDEN" });
|
||||
|
||||
const { generateFreeproPdf } = await import('./freeproPdfService');
|
||||
const pdfBytes = await generateFreeproPdf(
|
||||
{ mois: data.import.moisLabel, refPiece: data.import.refPiece || '' },
|
||||
data.lines.map(l => ({
|
||||
structure: l.structure || '',
|
||||
type: l.type || '',
|
||||
montantCentimes: l.montantCentimes,
|
||||
}))
|
||||
);
|
||||
const base64 = Buffer.from(pdfBytes).toString('base64');
|
||||
const [mm, yyyy] = data.import.moisLabel.split('/');
|
||||
const fileName = `FreePro - ventilation facture ${mm.padStart(2,'0')}.${yyyy.slice(2)}.pdf`;
|
||||
return { base64, fileName };
|
||||
}),
|
||||
|
||||
/** Exporte la ventilation FreePro vers SharePoint */
|
||||
exportToSharePoint: protectedProcedure
|
||||
.input(z.object({ id: z.number(), pdfBase64: z.string() }))
|
||||
.input(z.object({ id: z.number(), pdfBase64: z.string().optional() }))
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const data = await getFreeproImportWithLines(input.id);
|
||||
if (!data) throw new TRPCError({ code: "NOT_FOUND" });
|
||||
@@ -2298,8 +2322,17 @@ export const appRouter = router({
|
||||
const anneeCourt = anneeStr.slice(2);
|
||||
const fileName = `FreePro - ventilation facture ${moisPad}.${anneeCourt}.pdf`;
|
||||
|
||||
// Convertir le PDF base64 en buffer
|
||||
const pdfBuffer = Buffer.from(input.pdfBase64, 'base64');
|
||||
// Générer le PDF côté serveur
|
||||
const { generateFreeproPdf } = await import('./freeproPdfService');
|
||||
const pdfBytes = await generateFreeproPdf(
|
||||
{ mois: data.import.moisLabel, refPiece: data.import.refPiece || '' },
|
||||
data.lines.map(l => ({
|
||||
structure: l.structure || '',
|
||||
type: l.type || '',
|
||||
montantCentimes: l.montantCentimes,
|
||||
}))
|
||||
);
|
||||
const pdfBuffer = Buffer.from(pdfBytes);
|
||||
|
||||
const { uploadToSharePoint } = await import('./sharepoint');
|
||||
const result = await uploadToSharePoint(
|
||||
|
||||
Reference in New Issue
Block a user