Ultronprime commited on
Commit
0e58a60
·
verified ·
1 Parent(s): 5d19bfe

Create reportService.js

Browse files
Files changed (1) hide show
  1. reportService.js +35 -0
reportService.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // reportService.js - Logic for generating reports
2
+
3
+ import { appState } from './state.js';
4
+
5
+ const THIRTY_DAYS_AGO = new Date(new Date().setDate(new Date().getDate() - 30));
6
+
7
+ export function getMonthlyProductionSummary() {
8
+ const summary = {};
9
+ appState.productionLog
10
+ .filter(entry => new Date(entry.date) > THIRTY_DAYS_AGO)
11
+ .forEach(entry => {
12
+ if (!summary[entry.productName]) {
13
+ summary[entry.productName] = 0;
14
+ }
15
+ summary[entry.productName] += entry.quantity;
16
+ });
17
+ return summary;
18
+ }
19
+
20
+ export function getMonthlyMaterialUsage() {
21
+ const usage = {};
22
+ appState.productionLog
23
+ .filter(entry => new Date(entry.date) > THIRTY_DAYS_AGO)
24
+ .forEach(entry => {
25
+ const recipe = appState.productRecipes[entry.productName];
26
+ if (!recipe) return;
27
+ for (const materialName in recipe) {
28
+ if (!usage[materialName]) {
29
+ usage[materialName] = 0;
30
+ }
31
+ usage[materialName] += recipe[materialName] * entry.quantity;
32
+ }
33
+ });
34
+ return usage;
35
+ }