fix: PDF A4 portrait, total sans slash, bouton SharePoint FreePro
This commit is contained in:
@@ -2268,6 +2268,52 @@ export const appRouter = router({
|
||||
await deleteFreeproImport(input.id);
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
/** Exporte la ventilation FreePro vers SharePoint */
|
||||
exportToSharePoint: protectedProcedure
|
||||
.input(z.object({ id: z.number(), pdfBase64: z.string() }))
|
||||
.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" });
|
||||
|
||||
// Récupérer les paramètres SharePoint depuis importSettings
|
||||
const settings = await getImportSettingsByUser(ctx.user.id);
|
||||
const tenantId = (settings as any)?.azureTenantId || '';
|
||||
const clientId = (settings as any)?.azureClientId || '';
|
||||
const clientSecret = (settings as any)?.azureClientSecret || '';
|
||||
const sharepointUrl = (settings as any)?.exportFolder || '';
|
||||
|
||||
if (!tenantId || !clientId || !clientSecret) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Credentials Azure AD non configurés dans les paramètres d'export" });
|
||||
}
|
||||
if (!sharepointUrl) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "URL SharePoint non configurée dans le dossier d'export" });
|
||||
}
|
||||
|
||||
// Construire le nom du fichier
|
||||
const [moisStr, anneeStr] = data.import.moisLabel.split('/');
|
||||
const moisPad = moisStr.padStart(2, '0');
|
||||
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');
|
||||
|
||||
const { uploadToSharePoint } = await import('./sharepoint');
|
||||
const result = await uploadToSharePoint(
|
||||
{ tenantId, clientId, clientSecret, sharepointUrl },
|
||||
pdfBuffer,
|
||||
fileName
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: result.error || 'Erreur upload SharePoint' });
|
||||
}
|
||||
|
||||
return { success: true, webUrl: result.webUrl, fileName };
|
||||
}),
|
||||
}),
|
||||
});
|
||||
export type AppRouter = typeof appRouter;
|
||||
|
||||
Reference in New Issue
Block a user