diff --git a/client/src/pages/InvoicesBAP.tsx b/client/src/pages/InvoicesBAP.tsx index ffb8c54..24d350a 100644 --- a/client/src/pages/InvoicesBAP.tsx +++ b/client/src/pages/InvoicesBAP.tsx @@ -284,6 +284,17 @@ export default function InvoicesBAP() { }, }); + const devalidateBAPMutation = trpc.invoices.devalidateBAP.useMutation({ + onSuccess: (data) => { + toast.success(`${data.processed} facture(s) dévalidée(s) BAP avec succès`); + setSelectedIds([]); + utils.invoices.list.invalidate(); + }, + onError: (error) => { + toast.error(error.message || "Erreur lors de la dévalidation BAP"); + }, + }); + const updateFieldMutation = trpc.invoices.update.useMutation({ onSuccess: () => { toast.success("Facture mise à jour"); @@ -556,8 +567,10 @@ export default function InvoicesBAP() {

Factures BAP

Factures non-abonnement (Abonnement = NON)

- {/* Barre d'actions : boutons sur une ligne dédiée avec retour à la ligne automatique */} -
+ {/* Barre d'actions : 2 lignes */} +
+ {/* Ligne 1 : Excel, ZIP, Valider tout en BAP, Importer */} +
- + + +
+ {/* Ligne 2 : Supprimer, Dévalider BAP, Relancer */} +
- +
diff --git a/server/routers.ts b/server/routers.ts index cf59dbe..172ec32 100644 --- a/server/routers.ts +++ b/server/routers.ts @@ -654,6 +654,24 @@ export const appRouter = router({ }; }), + // ── Dévalidation BAP ────────────────────────────────────── + devalidateBAP: protectedProcedure + .input(z.object({ invoiceIds: z.array(z.number()) })) + .mutation(async ({ input, ctx }) => { + let processed = 0; + for (const id of input.invoiceIds) { + const invoice = await getInvoiceById(id); + if (!invoice || invoice.userId !== ctx.user.id) continue; + await updateInvoice(id, { + bapValidated: 0, + bapValidatedAt: null, + exportStatus: "not_exported", + }); + processed++; + } + return { success: true, processed }; + }), + // ── Validation BAP en masse ────────────────────────────── validateBAPBulk: protectedProcedure .mutation(async ({ ctx }) => {