Ultronprime commited on
Commit
63e1cc5
·
verified ·
1 Parent(s): 3f496fe

Update ui.js

Browse files
Files changed (1) hide show
  1. ui.js +28 -11
ui.js CHANGED
@@ -4,7 +4,8 @@ import { appState } from './state.js';
4
  import { attachAllListeners } from './events.js';
5
  import { getMonthlyProductionSummary, getMonthlyMaterialUsage } from './reportService.js';
6
 
7
- // ... (keep showToast, animateValue, renderKpiCards, renderCharts, renderModals, renderReport, renderProductInputs, renderProductionLog - they are unchanged) ...
 
8
 
9
  let productionChart = null;
10
  let inventoryChart = null;
@@ -148,7 +149,7 @@ function renderInventoryStatusChart() {
148
  let okCount = 0, warningCount = 0, criticalCount = 0;
149
  appState.materials.forEach(m => {
150
  if (m.currentStock <= m.reorderPoint) criticalCount++;
151
- else if (m.currentStock <= m.reorderPoint * 1.5) warningCount++; // Warning if stock is < 150% of reorder point
152
  else okCount++;
153
  });
154
 
@@ -228,16 +229,32 @@ function renderInventory() {
228
  if (!container) return;
229
  container.innerHTML = '';
230
  appState.materials.forEach(material => {
231
- // New progress bar logic: "Healthy" is 2x the reorder point.
232
- const healthyStockLevel = material.reorderPoint * 2;
233
- const stockHealth = Math.min((material.currentStock / healthyStockLevel) * 100, 100);
234
-
235
  let statusColor = 'var(--accent-green)';
236
- if (material.currentStock <= material.reorderPoint * 1.5) statusColor = 'var(--accent-yellow)';
237
  if (material.currentStock <= material.reorderPoint) statusColor = 'var(--accent-red)';
238
 
239
- // Removed the MAX display and the edit-max-stock icon
240
- const cardHTML = `<div class="dashboard-card p-4 border-l-4" style="border-left-color: ${statusColor}" data-material-name="${material.name}"><div class="flex justify-between items-start mb-1"><h3 class="font-medium text-sm">${material.name}</h3><div class="text-xs text-secondary flex items-center gap-3"><span class="font-semibold">Reorder at: ${material.reorderPoint}</span><i class="fas fa-plus-circle icon-btn restock-icon" title="Restock"></i></div></div><div class="flex justify-between items-baseline mb-2"><div class="text-2xl font-bold">${material.currentStock}</div><span class="text-sm text-secondary">${material.unit}</span></div><div class="w-full bg-dark rounded-full h-1.5"><div class="h-1.5 rounded-full" style="width: ${stockHealth}%; background-color: ${statusColor};"></div></div><div class="restock-form mt-2 hidden"></div></div>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  container.insertAdjacentHTML('beforeend', cardHTML);
242
  });
243
  }
@@ -275,8 +292,8 @@ function renderReorderList() {
275
  header.insertAdjacentHTML('beforeend', poButton);
276
 
277
  itemsToReorder.forEach(item => {
278
- const needed = item.reorderPoint; // Suggested order qty is now the reorder point itself
279
- const itemHTML = `<li class="p-3 rounded-md text-sm flex justify-between items-center" style="background-color: #f6e05e20;"><div class="flex-grow"><span class="font-semibold">${item.name}</span><span class="text-xs text-secondary block">Stock: ${item.currentStock} / Reorder: ${item.reorderPoint}</span></div><div class="text-right"><span class="font-bold">Order: ${needed}</span><span class="text-xs text-secondary ml-1">${item.unit}</span></div></li>`;
280
  list.insertAdjacentHTML('beforeend', itemHTML);
281
  });
282
  }
 
4
  import { attachAllListeners } from './events.js';
5
  import { getMonthlyProductionSummary, getMonthlyMaterialUsage } from './reportService.js';
6
 
7
+ // ... (keep all functions from showToast to renderProductionLog the same) ...
8
+ // The only function that needs changing is renderInventory()
9
 
10
  let productionChart = null;
11
  let inventoryChart = null;
 
149
  let okCount = 0, warningCount = 0, criticalCount = 0;
150
  appState.materials.forEach(m => {
151
  if (m.currentStock <= m.reorderPoint) criticalCount++;
152
+ else if (m.currentStock <= m.reorderPoint * 1.5) warningCount++; // Warning when getting close to reorder
153
  else okCount++;
154
  });
155
 
 
229
  if (!container) return;
230
  container.innerHTML = '';
231
  appState.materials.forEach(material => {
232
+ // The bar is "full" at 2x the reorder point. Capped at 100%.
233
+ const safeStockLevel = material.reorderPoint * 2;
234
+ const stockPercentage = Math.min((material.currentStock / safeStockLevel) * 100, 100);
235
+
236
  let statusColor = 'var(--accent-green)';
237
+ if (material.currentStock <= material.reorderPoint * 1.5) statusColor = 'var(--accent-yellow)';
238
  if (material.currentStock <= material.reorderPoint) statusColor = 'var(--accent-red)';
239
 
240
+ const cardHTML = `
241
+ <div class="dashboard-card p-4 border-l-4" style="border-left-color: ${statusColor}" data-material-name="${material.name}">
242
+ <div class="flex justify-between items-start mb-1">
243
+ <h3 class="font-medium text-sm">${material.name}</h3>
244
+ <div class="text-xs text-secondary flex items-center gap-3">
245
+ <i class="fas fa-plus-circle icon-btn restock-icon" title="Restock"></i>
246
+ <i class="fas fa-edit icon-btn edit-current-stock" title="Set Current Stock"></i>
247
+ </div>
248
+ </div>
249
+ <div class="flex justify-between items-baseline mb-2">
250
+ <div class="text-2xl font-bold current-stock-value">${material.currentStock}</div>
251
+ <span class="text-sm text-secondary">${material.unit}</span>
252
+ </div>
253
+ <div class="w-full bg-dark rounded-full h-1.5">
254
+ <div class="h-1.5 rounded-full" style="width: ${stockPercentage}%; background-color: ${statusColor};"></div>
255
+ </div>
256
+ <div class="restock-form mt-2 hidden"></div>
257
+ </div>`;
258
  container.insertAdjacentHTML('beforeend', cardHTML);
259
  });
260
  }
 
292
  header.insertAdjacentHTML('beforeend', poButton);
293
 
294
  itemsToReorder.forEach(item => {
295
+ const needed = (item.reorderPoint * 2) - item.currentStock;
296
+ const itemHTML = `<li class="p-3 rounded-md text-sm flex justify-between items-center" style="background-color: #f6e05e20;"><div class="flex-grow"><span class="font-semibold">${item.name}</span><span class="text-xs text-secondary block">Stock: ${item.currentStock} / Reorder at: ${item.reorderPoint}</span></div><div class="text-right"><span class="font-bold">Order ${needed}</span><span class="text-xs text-secondary ml-1">${item.unit}</span></div></li>`;
297
  list.insertAdjacentHTML('beforeend', itemHTML);
298
  });
299
  }