automatisch auf verrechnet setzen
This commit is contained in:
parent
fdcc4ca3a6
commit
f2a6cfe0a4
@ -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"`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user