|
|
@@ -1,10 +1,26 @@
|
|
|
<div id="ingredientDetails">
|
|
|
- <button class="sidebarIconButton" onclick="closeSidebar()">
|
|
|
- <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
- <line x1="5" y1="12" x2="19" y2="12"></line>
|
|
|
- <polyline points="12 5 19 12 12 19"></polyline>
|
|
|
- </svg>
|
|
|
- </button>
|
|
|
+ <div class="sidebarIconButtons">
|
|
|
+ <button onclick="closeSidebar()">
|
|
|
+ <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
+ <line x1="5" y1="12" x2="19" y2="12"></line>
|
|
|
+ <polyline points="12 5 19 12 12 19"></polyline>
|
|
|
+ </svg>
|
|
|
+ </button>
|
|
|
+
|
|
|
+ <button>
|
|
|
+ <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
+ <path d="M12 20h9"></path>
|
|
|
+ <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path>
|
|
|
+ </svg>
|
|
|
+ </button>
|
|
|
+
|
|
|
+ <button onclick="ingredientDetailsComp.remove()">
|
|
|
+ <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
|
+ <polyline points="3 6 5 6 21 6"></polyline>
|
|
|
+ <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
|
|
+ </svg>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
|
|
|
<p></p>
|
|
|
<h1></h1>
|
|
|
@@ -19,4 +35,61 @@
|
|
|
<label>Average Daily Use (30 days)
|
|
|
<p id="dailyUse"></p>
|
|
|
</label>
|
|
|
+
|
|
|
+ <script>
|
|
|
+ let ingredientDetailsComp = {
|
|
|
+ ingredient: {},
|
|
|
+
|
|
|
+ display: function(ingredient, category){
|
|
|
+ this.ingredient = ingredient;
|
|
|
+
|
|
|
+ sidebar = document.querySelector("#ingredientDetails");
|
|
|
+ openSidebar(sidebar);
|
|
|
+
|
|
|
+ document.querySelector("#ingredientDetails p").innerText = category.name;
|
|
|
+ document.querySelector("#ingredientDetails h1").innerText = ingredient.name;
|
|
|
+ document.querySelector("#ingredientStock").innerText = `${ingredient.quantity} ${ingredient.unit}`;
|
|
|
+
|
|
|
+ let quantities = [];
|
|
|
+ let now = new Date();
|
|
|
+ for(let i = 1; i < 31; i++){
|
|
|
+ let endDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i)
|
|
|
+ let startDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i - 1);
|
|
|
+ quantities.push(ingredientSold(dateIndices(startDay, endDay), ingredient.id));
|
|
|
+ }
|
|
|
+
|
|
|
+ let sum = 0;
|
|
|
+ for(let quantity of quantities){
|
|
|
+ sum += quantity;
|
|
|
+ }
|
|
|
+
|
|
|
+ document.querySelector("#dailyUse").innerText = `${(sum/quantities.length).toFixed(2)} ${ingredient.unit}`;
|
|
|
+ },
|
|
|
+
|
|
|
+ remove: function(){
|
|
|
+ for(let i = 0; i < merchant.recipes.length; i++){
|
|
|
+ for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
|
|
|
+ if(this.ingredient.id === merchant.recipes[i].ingredients[j].ingredient._id){
|
|
|
+ banner.createError("Must remove ingredient from all recipes before removing");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fetch(`/merchant/ingredients/remove/${this.ingredient.id}`, {
|
|
|
+ method: "DELETE",
|
|
|
+ })
|
|
|
+ .then((response) => response.json())
|
|
|
+ .then((response)=>{
|
|
|
+ if(typeof(response) === "string"){
|
|
|
+ banner.createError(response);
|
|
|
+ }else{
|
|
|
+ banner.createNotification("Ingredient removed");
|
|
|
+ updateInventory([this.ingredient], true);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err)=>{});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
</div>
|