update add report

This commit is contained in:
2026-02-17 09:53:13 -06:00
parent df1be3b823
commit eb19b2785e
6 changed files with 158 additions and 16 deletions

View File

@@ -1272,6 +1272,41 @@ app.post('/api/invoices/:id/export', async (req, res) => {
}
});
app.get('/api/qbo/overdue', async (req, res) => {
try {
// Datum vor 30 Tagen berechnen
const date = new Date();
date.setDate(date.getDate() - 30);
const dateStr = date.toISOString().split('T')[0];
console.log(`🔍 Suche in QBO nach unbezahlten Rechnungen fällig vor ${dateStr}...`);
// Query: Offene Rechnungen, deren Fälligkeitsdatum älter als 30 Tage ist
const query = `SELECT DocNumber, TxnDate, DueDate, Balance, CustomerRef, TotalAmt FROM Invoice WHERE Balance > '0' AND DueDate < '${dateStr}' ORDERBY DueDate ASC`;
const oauthClient = getOAuthClient();
const companyId = oauthClient.getToken().realmId;
const baseUrl = process.env.QBO_ENVIRONMENT === 'production'
? 'https://quickbooks.api.intuit.com'
: 'https://sandbox-quickbooks.api.intuit.com';
// makeQboApiCall kümmert sich um den Refresh, falls nötig!
const response = await makeQboApiCall({
url: `${baseUrl}/v3/company/${companyId}/query?query=${encodeURI(query)}`,
method: 'GET'
});
const data = response.getJson ? response.getJson() : response.json;
const invoices = data.QueryResponse?.Invoice || [];
console.log(`${invoices.length} überfällige Rechnungen gefunden.`);
res.json(invoices);
} catch (error) {
console.error("QBO Report Error:", error);
res.status(500).json({ error: error.message });
}
});
// Start server and browser
async function startServer() {
await initBrowser();