data.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. window.dataObj = {
  2. display: function(){
  3. clearScreen();
  4. document.querySelector("#dataStrand").style.display = "flex";
  5. },
  6. populate: function(transactions){
  7. //Create object to store number of recipes sold
  8. let recipes = [];
  9. for(let recipe of merchant.recipes){
  10. recipes.push({
  11. id: recipe._id,
  12. name: recipe.name,
  13. quantity: 0,
  14. ingredients: recipe.ingredients
  15. });
  16. }
  17. //Populate number of recipes sold
  18. for(let transaction of transactions){
  19. for(let transactionRecipe of transaction.recipes){
  20. for(let recipeCounter of recipes){
  21. if(transactionRecipe === recipeCounter.id){
  22. recipeCounter.quantity++;
  23. }
  24. }
  25. }
  26. }
  27. //Create object to store amount of ingredients sold
  28. let ingredients = [];
  29. for(let item of merchant.inventory){
  30. ingredients.push({
  31. id: item.ingredient._id,
  32. name: item.ingredient.name,
  33. quantity: 0,
  34. quantityRemaining: item.quantity
  35. });
  36. }
  37. //Populate amount of ingredients sold
  38. for(let recipe of recipes){
  39. for(let recipeIngredient of recipe.ingredients){
  40. for(let newIngredient of ingredients){
  41. if(newIngredient.id === recipeIngredient.ingredient._id){
  42. newIngredient.quantity += recipeIngredient.quantity;
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. //Populate Ingredients table
  49. }
  50. }