debug: debug3 monthlyData+cumulativeData direkt prüfen
This commit is contained in:
@@ -236,6 +236,51 @@ router.get('/month-orders', authenticate, (req, res) => {
|
||||
})));
|
||||
});
|
||||
|
||||
// Debug3: monthlyData direkt ausgeben
|
||||
router.get('/debug3', authenticate, (req, res) => {
|
||||
const { from, to } = req.query;
|
||||
const u = uid(req);
|
||||
|
||||
const allOrders = db.prepare('SELECT * FROM orders WHERE user_id=? ORDER BY created_at DESC').all(u);
|
||||
|
||||
const inRange = (dateStr) => {
|
||||
if (!dateStr) return !from && !to;
|
||||
const d = dateStr.slice(0, 10);
|
||||
if (from && d < from) return false;
|
||||
if (to && d > to) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
const filteredOrders = allOrders.filter(o => {
|
||||
if (!from && !to) return true;
|
||||
if (o.bezahlt) return inRange(o.bezahlt_am || o.created_at);
|
||||
return inRange(o.created_at);
|
||||
});
|
||||
|
||||
const buckets = {};
|
||||
for (const o of filteredOrders) {
|
||||
const dateStr = o.bezahlt ? (o.bezahlt_am || o.created_at) : o.created_at;
|
||||
const key = dateStr?.slice(0,7);
|
||||
if (!key) continue;
|
||||
if (!buckets[key]) buckets[key] = { month:key, revenue:0, base_cost:0, expenses:0 };
|
||||
if (o.bezahlt) {
|
||||
const rev = getOrderRevenue(o);
|
||||
const cost = getOrderBaseCost(o.id);
|
||||
buckets[key].revenue += rev;
|
||||
buckets[key].base_cost += cost;
|
||||
}
|
||||
}
|
||||
|
||||
const monthlyData = Object.values(buckets).sort((a,b)=>a.month.localeCompare(b.month));
|
||||
let cum = 0;
|
||||
const cumulativeData = monthlyData.map(m => {
|
||||
cum += m.revenue - m.base_cost - m.expenses;
|
||||
return { month:m.month, value:round2(cum), revenue:m.revenue, base_cost:m.base_cost };
|
||||
});
|
||||
|
||||
res.json({ monthlyData, cumulativeData });
|
||||
});
|
||||
|
||||
// Debug2: monthlyData mit base_cost prüfen
|
||||
router.get('/debug2', authenticate, (req, res) => {
|
||||
const { from, to } = req.query;
|
||||
|
||||
Reference in New Issue
Block a user