Raw Materials Dashboard
Inventory Value by Category
All stock levels are OK.
';
} else {
reorderContainer.innerHTML = toReorder.sort((a,b) => a.Qty - b.Qty).map(m => `
${m.Qty.toLocaleString()}
`).join('');
}
renderChart();
}
function renderChart() {
const dataByCategory = materialsData.reduce((acc, m) => {
acc[m.Category] = (acc[m.Category] || 0) + m.Value;
return acc;
}, {});
const ctx = document.getElementById('rmd-category-chart').getContext('2d');
if(categoryChart) categoryChart.destroy();
categoryChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(dataByCategory),
datasets: [{
data: Object.values(dataByCategory),
backgroundColor: ['#0369a1', '#0ea5e9', '#64748b', '#f59e0b', '#94a3b8']
}]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } }
});
}
function renderMaterialsTable() {
const table = document.getElementById('materials-table');
const headers = ['SKU', 'Material Name', 'Category', 'Qty on Hand', 'Unit Cost ($)', 'Reorder Point', 'Status', 'Inventory Value ($)'];
table.innerHTML = `
${headers.map(h=>`| ${h} | `).join('')}Actions |
${materialsData.map(m => `
|
|
|
|
|
|
${m.Status} |
${formatCurrency(m.Value)} |
|
`).join('')}
`;
}
window.rmd_updateMaterial = (id, key, value) => { const m = materialsData.find(m=>m.id===id); if(m) m[key] = (typeof m[key]==='number')?parseFloat(value)||0:value; renderAll(); };
window.rmd_addMaterial = () => { materialsData.unshift({ id: Date.now(), SKU: 'NEW-SKU', Name: 'New Material', Category: CATEGORIES[0], Qty: 0, Cost: 0, ReorderPoint: 0 }); renderAll(); };
window.rmd_removeMaterial = (id) => { materialsData = materialsData.filter(m => m.id !== id); renderAll(); };
function initialize() {
materialsData = [
{ id: 1, SKU: 'MTL-001', Name: 'Sheet Steel 1mm', Category: 'Metals', Qty: 500, Cost: 15.50, ReorderPoint: 200 },
{ id: 2, SKU: 'MTL-002', Name: 'Aluminum Extrusion 2m', Category: 'Metals', Qty: 150, Cost: 25.00, ReorderPoint: 100 },
{ id: 3, SKU: 'PLS-001', Name: 'ABS Pellets (kg)', Category: 'Plastics', Qty: 2000, Cost: 3.20, ReorderPoint: 500 },
{ id: 4, SKU: 'ELE-001', Name: 'Microcontroller Unit', Category: 'Electronics', Qty: 85, Cost: 12.75, ReorderPoint: 100 },
{ id: 5, SKU: 'FAS-001', Name: 'M5 Bolt (box of 100)', Category: 'Fasteners', Qty: 45, Cost: 8.00, ReorderPoint: 50 },
{ id: 6, SKU: 'PKG-001', Name: 'Cardboard Box 12x12', Category: 'Packaging', Qty: 850, Cost: 0.75, ReorderPoint: 1000 },
{ id: 7, SKU: 'ELE-002', Name: 'Resistor Pack', Category: 'Electronics', Qty: 0, Cost: 0.10, ReorderPoint: 500 }
];
renderAll();
}
initialize();
});