sent date

This commit is contained in:
2026-03-25 17:35:30 -05:00
parent 453f8654b7
commit a9173acc8d
3 changed files with 117 additions and 9 deletions

View File

@@ -894,8 +894,15 @@ router.post('/:id/send-email', async (req, res) => {
const stripeLink = invoice.stripe_payment_link_url || null;
const info = await sendInvoiceEmail(invoice, recipientEmail, customText, stripeLink, pdfBuffer);
// 4. (Optional) Status in der DB aktualisieren
await pool.query('UPDATE invoices SET email_status = $1 WHERE id = $2', ['sent', id]);
// 4. Status in der DB aktualisieren
await pool.query(
`UPDATE invoices
SET email_status = 'sent',
sent_dates = array_append(COALESCE(sent_dates, '{}'), CURRENT_DATE),
updated_at = CURRENT_TIMESTAMP
WHERE id = $1`,
[id]
);
res.json({ success: true, messageId: info.messageId });
@@ -1184,4 +1191,35 @@ async function recordStripePaymentInQbo(invoice, amount, methodLabel, stripeFee,
feeBooked: stripeFee > 0
};
}
// PATCH update sent dates only
router.patch('/:id/sent-dates', async (req, res) => {
const { id } = req.params;
const { sent_dates } = req.body;
if (!Array.isArray(sent_dates)) {
return res.status(400).json({ error: 'sent_dates must be an array of date strings.' });
}
// Validate each date
for (const d of sent_dates) {
if (!/^\d{4}-\d{2}-\d{2}$/.test(d)) {
return res.status(400).json({ error: `Invalid date format: ${d}. Expected YYYY-MM-DD.` });
}
}
try {
// Sort chronologically
const sorted = [...sent_dates].sort();
await pool.query(
'UPDATE invoices SET sent_dates = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2',
[sorted, id]
);
res.json({ success: true, sent_dates: sorted });
} catch (error) {
console.error('Error updating sent dates:', error);
res.status(500).json({ error: 'Failed to update sent dates.' });
}
});
module.exports = router;