fix
This commit is contained in:
parent
29a37ad98a
commit
ec3cd2b659
20
server.js
20
server.js
|
|
@ -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 {
|
||||||
qboResult = await syncInvoiceToQbo(id, client);
|
// 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);
|
||||||
|
} else {
|
||||||
|
qboResult = await exportInvoiceToQbo(id, client);
|
||||||
|
}
|
||||||
|
|
||||||
if (qboResult.skipped) {
|
if (qboResult.skipped) {
|
||||||
console.log(`ℹ️ Invoice ${id} not synced to QBO: ${qboResult.reason}`);
|
console.log(`ℹ️ Invoice ${id}: ${qboResult.reason}`);
|
||||||
}
|
}
|
||||||
} catch (qboErr) {
|
} catch (qboErr) {
|
||||||
console.error(`⚠️ Auto QBO sync failed for Invoice ${id}:`, qboErr.message);
|
console.error(`⚠️ Auto QBO failed for Invoice ${id}:`, qboErr.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ success: true, qbo_synced: !!qboResult?.success });
|
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');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue