fix
This commit is contained in:
parent
29a37ad98a
commit
ec3cd2b659
24
server.js
24
server.js
|
|
@ -292,6 +292,7 @@ async function syncInvoiceToQbo(invoiceId, client) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// Logo endpoints
|
||||
app.get('/api/logo-info', async (req, res) => {
|
||||
try {
|
||||
|
|
@ -958,18 +959,27 @@ app.put('/api/invoices/:id', async (req, res) => {
|
|||
|
||||
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;
|
||||
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);
|
||||
if (qboResult.skipped) {
|
||||
console.log(`ℹ️ Invoice ${id} not synced to QBO: ${qboResult.reason}`);
|
||||
}
|
||||
} catch (qboErr) {
|
||||
console.error(`⚠️ Auto QBO sync failed for Invoice ${id}:`, qboErr.message);
|
||||
} else {
|
||||
qboResult = await exportInvoiceToQbo(id, client);
|
||||
}
|
||||
|
||||
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) {
|
||||
await client.query('ROLLBACK');
|
||||
|
|
|
|||
Loading…
Reference in New Issue