Dateien nach "backend/src/routes" hochladen
This commit is contained in:
@@ -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 bezahltOrders = db.prepare('SELECT COUNT(*) c FROM orders WHERE user_id=? AND bezahlt=1').get(uid).c;
|
||||
const totalRevenue = db.prepare(`
|
||||
SELECT COALESCE(SUM(oi.custom_price*oi.stueckzahl),0) s
|
||||
FROM orders o JOIN order_items oi ON oi.order_id=o.id
|
||||
WHERE o.user_id=? AND o.bezahlt=1 AND oi.custom_price IS NOT NULL
|
||||
`).get(uid).s;
|
||||
const offeneRevenue = db.prepare(`
|
||||
SELECT COALESCE(SUM(oi.custom_price*oi.stueckzahl),0) s
|
||||
FROM orders o JOIN order_items oi ON oi.order_id=o.id
|
||||
WHERE o.user_id=? AND o.bezahlt=0 AND oi.custom_price IS NOT NULL AND o.status!='warteliste'
|
||||
`).get(uid).s;
|
||||
// Revenue: Gesamt-Festpreis hat Priorität, sonst Summe der Positions-Festpreise
|
||||
const paidOrders = db.prepare('SELECT * FROM orders WHERE user_id=? AND bezahlt=1').all(uid);
|
||||
let totalRevenue = 0;
|
||||
for (const o of paidOrders) {
|
||||
if (o.custom_price != null) {
|
||||
totalRevenue += 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;
|
||||
totalRevenue += sum;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user