This commit is contained in:
Andreas Knuth 2026-02-24 16:46:54 -06:00
parent 29a37ad98a
commit ec3cd2b659
1 changed files with 15 additions and 5 deletions

View File

@ -292,6 +292,7 @@ async function syncInvoiceToQbo(invoiceId, client) {
} }
// Logo endpoints // Logo endpoints
app.get('/api/logo-info', async (req, res) => { app.get('/api/logo-info', async (req, res) => {
try { try {
@ -958,18 +959,27 @@ app.put('/api/invoices/:id', async (req, res) => {
await client.query('COMMIT'); await client.query('COMMIT');
// Auto QBO Sync (falls bereits in QBO) // Auto QBO: Export if not yet in QBO, Sync if already in QBO
let qboResult = null; let qboResult = null;
try { try {
// Prüfe ob Invoice schon in QBO
const checkRes = await client.query('SELECT qbo_id FROM invoices WHERE id = $1', [id]);
const hasQboId = !!checkRes.rows[0]?.qbo_id;
if (hasQboId) {
qboResult = await syncInvoiceToQbo(id, client); qboResult = await syncInvoiceToQbo(id, client);
if (qboResult.skipped) { } else {
console.log(` Invoice ${id} not synced to QBO: ${qboResult.reason}`); qboResult = await exportInvoiceToQbo(id, client);
}
} catch (qboErr) {
console.error(`⚠️ Auto QBO sync failed for Invoice ${id}:`, qboErr.message);
} }
res.json({ success: true, qbo_synced: !!qboResult?.success }); if (qboResult.skipped) {
console.log(` Invoice ${id}: ${qboResult.reason}`);
}
} catch (qboErr) {
console.error(`⚠️ Auto QBO failed for Invoice ${id}:`, qboErr.message);
}
res.json({ success: true, qbo_synced: !!qboResult?.success, qbo_id: qboResult?.qbo_id || null, qbo_doc_number: qboResult?.qbo_doc_number || null });
} catch (error) { } catch (error) {
await client.query('ROLLBACK'); await client.query('ROLLBACK');