win-superpower2 / reportService.js
Ultronprime's picture
Create reportService.js
0e58a60 verified
raw
history blame
1.14 kB
// 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;
}