diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js
index a248c7a..bf84b07 100644
--- a/backend/controllers/falukantController.js
+++ b/backend/controllers/falukantController.js
@@ -56,6 +56,10 @@ class FalukantController {
if (!page) page = 1;
return this.service.moneyHistory(userId, page, filter);
});
+ this.moneyHistoryGraph = this._wrapWithUser((userId, req) => {
+ const { range } = req.body || {};
+ return this.service.moneyHistoryGraph(userId, range || '24h');
+ });
this.getStorage = this._wrapWithUser((userId, req) => this.service.getStorage(userId, req.params.branchId));
this.buyStorage = this._wrapWithUser((userId, req) => {
const { branchId, amount, stockTypeId } = req.body;
diff --git a/backend/routers/falukantRouter.js b/backend/routers/falukantRouter.js
index 8dc3aaa..618e20f 100644
--- a/backend/routers/falukantRouter.js
+++ b/backend/routers/falukantRouter.js
@@ -28,6 +28,7 @@ router.get('/inventory/?:branchId', falukantController.getInventory);
router.post('/sell/all', falukantController.sellAllProducts);
router.post('/sell', falukantController.sellProduct);
router.post('/moneyhistory', falukantController.moneyHistory);
+router.post('/moneyhistory/graph', falukantController.moneyHistoryGraph);
router.get('/storage/:branchId', falukantController.getStorage);
router.post('/storage', falukantController.buyStorage);
router.delete('/storage', falukantController.sellStorage);
diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js
index db10ee8..a88a60c 100644
--- a/backend/services/falukantService.js
+++ b/backend/services/falukantService.js
@@ -1802,6 +1802,62 @@ class FalukantService extends BaseService {
return { data: rows, total: count, currentPage: page, totalPages: Math.ceil(count / limit) };
}
+ /**
+ * Geldverlauf für Graphenansicht.
+ * range: 'today' | '24h' | 'week' | 'month' | 'year' | 'all'
+ */
+ async moneyHistoryGraph(hashedUserId, range = '24h') {
+ const u = await getFalukantUserOrFail(hashedUserId);
+
+ const where = { falukantUserId: u.id };
+ const now = new Date();
+ let start = null;
+
+ switch (range) {
+ case 'today': {
+ start = new Date();
+ start.setHours(0, 0, 0, 0);
+ break;
+ }
+ case '24h': {
+ start = new Date(now.getTime() - 24 * 60 * 60 * 1000);
+ break;
+ }
+ case 'week': {
+ start = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
+ break;
+ }
+ case 'month': {
+ start = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
+ break;
+ }
+ case 'year': {
+ start = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000);
+ break;
+ }
+ case 'all':
+ default:
+ start = null;
+ }
+
+ if (start) {
+ where.time = { [Op.gte]: start };
+ }
+
+ const rows = await MoneyFlow.findAll({
+ where,
+ order: [['time', 'ASC']]
+ });
+
+ return rows.map(r => ({
+ time: r.time,
+ moneyBefore: r.moneyBefore,
+ moneyAfter: r.moneyAfter,
+ changeValue: r.changeValue,
+ activity: r.activity
+ }));
+ }
+
async getStorage(hashedUserId, branchId) {
const user = await getFalukantUserOrFail(hashedUserId);
const branch = await getBranchOrFail(user.id, branchId);
diff --git a/frontend/src/dialogues/falukant/MoneyHistoryGraphDialog.vue b/frontend/src/dialogues/falukant/MoneyHistoryGraphDialog.vue
new file mode 100644
index 0000000..c3ce6ba
--- /dev/null
+++ b/frontend/src/dialogues/falukant/MoneyHistoryGraphDialog.vue
@@ -0,0 +1,150 @@
+
+