Ultronprime commited on
Commit
e2f2b65
·
verified ·
1 Parent(s): 336631c

Update services.js

Browse files
Files changed (1) hide show
  1. services.js +6 -5
services.js CHANGED
@@ -8,7 +8,6 @@ export function handleUpdateStock(productName, quantity) {
8
  const recipe = appState.productRecipes[productName];
9
  if (!recipe) { showToast(`Error: No recipe found for ${productName}.`, 'error'); return; }
10
 
11
- // Check if there are enough materials
12
  for (const materialName in recipe) {
13
  const required = recipe[materialName] * quantity;
14
  const material = appState.materials.find(m => m.name === materialName);
@@ -18,7 +17,6 @@ export function handleUpdateStock(productName, quantity) {
18
  }
19
  }
20
 
21
- // Deduct materials
22
  for (const materialName in recipe) {
23
  const required = recipe[materialName] * quantity;
24
  appState.materials.find(m => m.name === materialName).currentStock -= required;
@@ -30,9 +28,12 @@ export function handleUpdateStock(productName, quantity) {
30
  refreshUI();
31
  showToast(`Produced ${quantity}x ${productName}.`, 'success');
32
 
33
- // Clear input field after production
34
- const productCard = document.querySelector(`.product-card[data-product-name="${productName}"]`);
35
- if(productCard) productCard.querySelector('input').value = '0';
 
 
 
36
  }
37
 
38
  export function handleRestock(materialName, quantity) {
 
8
  const recipe = appState.productRecipes[productName];
9
  if (!recipe) { showToast(`Error: No recipe found for ${productName}.`, 'error'); return; }
10
 
 
11
  for (const materialName in recipe) {
12
  const required = recipe[materialName] * quantity;
13
  const material = appState.materials.find(m => m.name === materialName);
 
17
  }
18
  }
19
 
 
20
  for (const materialName in recipe) {
21
  const required = recipe[materialName] * quantity;
22
  appState.materials.find(m => m.name === materialName).currentStock -= required;
 
28
  refreshUI();
29
  showToast(`Produced ${quantity}x ${productName}.`, 'success');
30
 
31
+ document.querySelectorAll('.dashboard-card').forEach(card => {
32
+ const h3 = card.querySelector('h3');
33
+ if (h3 && h3.textContent === productName) {
34
+ card.querySelector('input').value = '0';
35
+ }
36
+ });
37
  }
38
 
39
  export function handleRestock(materialName, quantity) {