This commit is contained in:
2026-02-17 16:51:30 -06:00
parent 31f03b0d7c
commit 2d5be21bf2
6 changed files with 633 additions and 66 deletions

View File

@@ -1534,6 +1534,55 @@ app.post('/api/qbo/import-unpaid', async (req, res) => {
}
});
// Mark invoice as paid
app.patch('/api/invoices/:id/mark-paid', async (req, res) => {
const { id } = req.params;
const { paid_date } = req.body; // Optional: explizites Datum, sonst heute
try {
const dateToUse = paid_date || new Date().toISOString().split('T')[0];
const result = await pool.query(
'UPDATE invoices SET paid_date = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2 RETURNING *',
[dateToUse, id]
);
if (result.rows.length === 0) {
return res.status(404).json({ error: 'Invoice not found' });
}
console.log(`💰 Invoice #${result.rows[0].invoice_number} als bezahlt markiert (${dateToUse})`);
res.json(result.rows[0]);
} catch (error) {
console.error('Error marking invoice as paid:', error);
res.status(500).json({ error: 'Error marking invoice as paid' });
}
});
// Mark invoice as unpaid
app.patch('/api/invoices/:id/mark-unpaid', async (req, res) => {
const { id } = req.params;
try {
const result = await pool.query(
'UPDATE invoices SET paid_date = NULL, updated_at = CURRENT_TIMESTAMP WHERE id = $1 RETURNING *',
[id]
);
if (result.rows.length === 0) {
return res.status(404).json({ error: 'Invoice not found' });
}
console.log(`↩️ Invoice #${result.rows[0].invoice_number} als unbezahlt markiert`);
res.json(result.rows[0]);
} catch (error) {
console.error('Error marking invoice as unpaid:', error);
res.status(500).json({ error: 'Error marking invoice as unpaid' });
}
});
// Start server and browser