Checkpoint: Modification de la page Factures avec sélection multiple et export PDF.
Nouvelles fonctionnalités : - Ajout du champ exportStatus dans la base de données (exported/not_exported/export_error) - Cases à cocher pour sélection multiple des factures - Case "Tout sélectionner" (sélectionne uniquement les factures avec score 100%) - Nouveau système de statuts : Exporté (vert), Non exporté (bleu), Erreur export (rouge) - Bouton "Exporter" avec compteur de factures sélectionnées - Validation stricte : seules les factures avec score de qualité 100% peuvent être exportées - Les factures non éligibles (score < 100%) sont grisées et non sélectionnables - Téléchargement automatique des PDFs des factures sélectionnées - Message d'information expliquant la règle des 100% La page affiche maintenant le statut d'export au lieu du statut de traitement, conformément aux spécifications.
This commit is contained in:
@@ -424,6 +424,49 @@ export const appRouter = router({
|
||||
return { success };
|
||||
}),
|
||||
|
||||
exportToPdf: protectedProcedure
|
||||
.input(z.object({ invoiceIds: z.array(z.number()) }))
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
// Validate that all invoices have quality score of 100
|
||||
const invoices = await Promise.all(
|
||||
input.invoiceIds.map(id => getInvoiceById(id))
|
||||
);
|
||||
|
||||
const invalidInvoices = invoices.filter(
|
||||
inv => !inv || inv.userId !== ctx.user.id || (inv.qualityScore || 0) < 100
|
||||
);
|
||||
|
||||
if (invalidInvoices.length > 0) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Toutes les factures doivent avoir un score de qualit\u00e9 de 100% pour \u00eatre export\u00e9es"
|
||||
});
|
||||
}
|
||||
|
||||
// Update export status
|
||||
for (const invoice of invoices) {
|
||||
if (invoice) {
|
||||
await updateInvoice(invoice.id, {
|
||||
exportStatus: "exported",
|
||||
exportedAt: new Date(),
|
||||
exportMode: "manual",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Return the file URLs for PDF generation on client side
|
||||
return {
|
||||
success: true,
|
||||
invoices: invoices.filter(Boolean).map(inv => ({
|
||||
id: inv!.id,
|
||||
fileUrl: inv!.fileUrl,
|
||||
supplierName: inv!.supplierName,
|
||||
invoiceNumber: inv!.invoiceNumber,
|
||||
invoiceDate: inv!.invoiceDate,
|
||||
}))
|
||||
};
|
||||
}),
|
||||
|
||||
exportInvoices: protectedProcedure
|
||||
.input(z.object({ invoiceIds: z.array(z.number()) }))
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
Reference in New Issue
Block a user