From f2a6cfe0a439861f8ae00750408dd7803c648a9e Mon Sep 17 00:00:00 2001 From: cay Date: Fri, 27 Mar 2026 12:40:23 +0000 Subject: [PATCH] automatisch auf verrechnet setzen --- routes/billing.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/routes/billing.js b/routes/billing.js index 3f94fff..f86e334 100644 --- a/routes/billing.js +++ b/routes/billing.js @@ -217,11 +217,18 @@ router.get('/export/csv', requireAdmin, async (req, res) => { `, [period]); // Alle offenen Rechnungen dieser Periode als bezahlt markieren - // COLLATE explizit setzen wegen möglichem Collation-Konflikt - await db.query( - "UPDATE invoices SET status='paid', paid_at=NOW() WHERE period=? COLLATE utf8mb4_unicode_ci AND status='open'", - [period] + // IDs zuerst laden um Collation-Probleme zu umgehen + const [openInvoices] = await db.query( + 'SELECT id FROM invoices WHERE CONVERT(period USING utf8mb4) = CONVERT(? USING utf8mb4) AND status = ?', + [period, 'open'] ); + if (openInvoices.length > 0) { + const ids = openInvoices.map(r => r.id); + await db.query( + `UPDATE invoices SET status='paid', paid_at=NOW() WHERE id IN (${ids.join(',')})`, + [] + ); + } res.setHeader('Content-Type', 'text/csv; charset=utf-8'); res.setHeader('Content-Disposition', `attachment; filename="SEPA_${period}.csv"`);