update
This commit is contained in:
49
server.js
49
server.js
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user