Dateien nach "backend/src/routes" hochladen

This commit is contained in:
2026-05-26 13:33:38 +02:00
parent 56f206b7d9
commit 3f785d3d9e

View File

@@ -89,16 +89,28 @@ router.get('/stats', authenticate, (req, res) => {
const totalOrders = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=?').get(uid).c; const totalOrders = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=?').get(uid).c;
const bezahltOrders = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=? AND bezahlt=1').get(uid).c; const bezahltOrders = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=? AND bezahlt=1').get(uid).c;
const totalRevenue = db.prepare(` // Revenue: Gesamt-Festpreis hat Priorität, sonst Summe der Positions-Festpreise
SELECT COALESCE(SUM(oi.custom_price*oi.stueckzahl),0) s const paidOrders = db.prepare('SELECT * FROM orders WHERE user_id=? AND bezahlt=1').all(uid);
FROM orders o JOIN order_items oi ON oi.order_id=o.id let totalRevenue = 0;
WHERE o.user_id=? AND o.bezahlt=1 AND oi.custom_price IS NOT NULL for (const o of paidOrders) {
`).get(uid).s; if (o.custom_price != null) {
const offeneRevenue = db.prepare(` totalRevenue += parseFloat(o.custom_price);
SELECT COALESCE(SUM(oi.custom_price*oi.stueckzahl),0) s } else {
FROM orders o JOIN order_items oi ON oi.order_id=o.id const sum = db.prepare('SELECT COALESCE(SUM(custom_price*stueckzahl),0) s FROM order_items WHERE order_id=? AND custom_price IS NOT NULL').get(o.id).s;
WHERE o.user_id=? AND o.bezahlt=0 AND oi.custom_price IS NOT NULL AND o.status!='warteliste' totalRevenue += sum;
`).get(uid).s; }
}
const openOrders = db.prepare("SELECT * FROM orders WHERE user_id=? AND bezahlt=0 AND status!='warteliste'").all(uid);
let offeneRevenue = 0;
for (const o of openOrders) {
if (o.custom_price != null) {
offeneRevenue += parseFloat(o.custom_price);
} else {
const sum = db.prepare('SELECT COALESCE(SUM(custom_price*stueckzahl),0) s FROM order_items WHERE order_id=? AND custom_price IS NOT NULL').get(o.id).s;
offeneRevenue += sum;
}
}
const thisMonth = new Date(); const thisMonth = new Date();
thisMonth.setDate(1); thisMonth.setHours(0,0,0,0); thisMonth.setDate(1); thisMonth.setHours(0,0,0,0);
const ordersThisMonth = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=? AND created_at>=?').get(uid, thisMonth.toISOString()).c; const ordersThisMonth = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=? AND created_at>=?').get(uid, thisMonth.toISOString()).c;