File size: 1,137 Bytes
0e58a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// reportService.js - Logic for generating reports

import { appState } from './state.js';

const THIRTY_DAYS_AGO = new Date(new Date().setDate(new Date().getDate() - 30));

export function getMonthlyProductionSummary() {
    const summary = {};
    appState.productionLog
        .filter(entry => new Date(entry.date) > THIRTY_DAYS_AGO)
        .forEach(entry => {
            if (!summary[entry.productName]) {
                summary[entry.productName] = 0;
            }
            summary[entry.productName] += entry.quantity;
        });
    return summary;
}

export function getMonthlyMaterialUsage() {
    const usage = {};
    appState.productionLog
        .filter(entry => new Date(entry.date) > THIRTY_DAYS_AGO)
        .forEach(entry => {
            const recipe = appState.productRecipes[entry.productName];
            if (!recipe) return;
            for (const materialName in recipe) {
                if (!usage[materialName]) {
                    usage[materialName] = 0;
                }
                usage[materialName] += recipe[materialName] * entry.quantity;
            }
        });
    return usage;
}