feat: Tab Einnahmen (bezahlt_am Zeitraum) + Bestellungen (created_at diesen Monat)

This commit is contained in:
2026-06-17 17:32:34 +02:00
parent f4302c8aad
commit d4fb2d7527
2 changed files with 125 additions and 27 deletions

View File

@@ -190,6 +190,14 @@ router.get('/overview', authenticate, (req, res) => {
base_cost: round2(getOrderBaseCost(o.id)),
}));
const paidOrdersOut = paidOrders.slice(0,50).map(o => ({
id: o.id, name: o.name, status: o.status,
bezahlt: o.bezahlt, abgeholt: o.abgeholt,
created_at: o.created_at, bezahlt_am: o.bezahlt_am,
revenue: round2(getOrderRevenue(o)),
base_cost: round2(getOrderBaseCost(o.id)),
}));
res.json({
totalRevenue: round2(totalRevenue),
openRevenue: round2(openRevenue),
@@ -202,9 +210,29 @@ router.get('/overview', authenticate, (req, res) => {
byStatus, byCategory, monthlyData, cumulativeData,
expenses: expenses.slice(0, 100),
recentOrders,
paidOrders: paidOrdersOut,
});
});
// Bestellungen nach created_at (für "Bestellungen diesen Monat" Tab)
router.get('/month-orders', authenticate, (req, res) => {
const { from, to } = req.query;
const u = uid(req);
let q = 'SELECT * FROM orders WHERE user_id=?';
const p = [u];
if (from) { q += ' AND DATE(created_at)>=?'; p.push(from); }
if (to) { q += ' AND DATE(created_at)<=?'; p.push(to); }
q += ' ORDER BY created_at DESC';
const orders = db.prepare(q).all(...p);
res.json(orders.map(o => ({
id: o.id, name: o.name, status: o.status,
bezahlt: o.bezahlt, abgeholt: o.abgeholt,
created_at: o.created_at, bezahlt_am: o.bezahlt_am,
revenue: round2(getOrderRevenue(o)),
base_cost: round2(getOrderBaseCost(o.id)),
})));
});
// Debug: rohe Auftragsdaten mit Revenue
router.get('/debug', authenticate, (req, res) => {
const u = uid(req);