!function(){var e={isPopulated:!1,display:function(){this.isPopulated||(this.drawRevenueCard(),this.drawRevenueGraph(),this.drawInventoryCheckCard(),this.drawPopularCard(),this.isPopulated=!0)},drawRevenueCard:function(){let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),1),n=new Date(e.getFullYear(),e.getMonth()-1,1),i=new Date((new Date).setMonth(e.getMonth()-1)),r=merchant.revenue(controller.transactionIndices(merchant.transactions,t)),l=merchant.revenue(controller.transactionIndices(merchant.transactions,n,i));document.getElementById("revenue").innerText="$"+r.toLocaleString("en");let d=(r-l)/l*100,a="";a=d>=0?"/shared/images/upArrow.png":"/shared/images/downArrow.png",document.querySelector("#revenueChange p").innerText=Math.abs(d).toFixed(2)+"% vs last month",document.querySelector("#revenueChange img").src=a},drawRevenueGraph:function(){let e=new Date;e.setMonth(e.getMonth()-1);let t=controller.transactionIndices(merchant.transactions,e),n=[],i=[],r=0,l=merchant.transactions[t[0]].date;for(let a=t[0];a0;)n.removeChild(n.firstChild);for(let r=0;r{l.value--,l.changed=!0},"bottle"===d.ingredient.specialUnit?(l.value=(d.quantity/d.ingredient.unitSize).toFixed(2),e.children[2].innerText="BOTTLES"):(l.value=d.ingredient.convert(d.quantity).toFixed(2),e.children[2].innerText=d.ingredient.unit.toUpperCase()),e.children[1].children[2].onclick=()=>{l.value++,l.changed=!0},l.onchange=()=>{l.changed=!0},n.appendChild(e)}document.getElementById("inventoryCheck").onclick=()=>{this.submitInventoryCheck()}},drawPopularCard:function(){let e=new Date;e.setDate(1);let t=merchant.ingredientsSold(controller.transactionIndices(merchant.transactions,e));if(!1!==t){t.sort((e,t)=>e.quantityt.quantity?-1:0);let e=[],n=[],i=[];for(let d=t.length<5?t.length-1:4;d>=0;d--){const r=t[d].ingredient.name,l=t[d].ingredient.convert(t[d].quantity),a=t[d].ingredient.unit;e.push(t[d].quantity),n.push(`${r}: ${l.toFixed(2)} ${a.toUpperCase()}`),0===d?i.push("rgb(255, 99, 107"):i.push("rgb(179, 191, 209")}let r={x:e,type:"bar",orientation:"h",text:n,textposition:"auto",hoverinfo:"none",marker:{color:i}},l={title:"MOST POPULAR INGREDIENTS",xaxis:{zeroline:!1,title:"QUANTITY"},yaxis:{showticklabels:!1}};Plotly.newPlot("popularIngredientsCard",[r],l)}else{document.getElementById("popularCanvas").style.display="none";let e=document.createElement("p");e.innerText="N/A",e.classList="notice",document.getElementById("popularIngredientsCard").appendChild(e)}},submitInventoryCheck:function(){let e=document.querySelectorAll("#inventoryCheckCard li"),t=[],n=[];for(let i=0;i=0))return void banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");{let r=e[i].ingredient;if(!0===e[i].children[1].children[1].changed){let l=0;l="bottle"===r.ingredient.specialUnit?parseFloat(e[i].children[1].children[1].value)*r.ingredient.unitSize:controller.convertToMain(r.ingredient.unit,parseFloat(e[i].children[1].children[1].value)),t.push({ingredient:r.ingredient,quantity:l}),n.push({id:r.ingredient.id,quantity:l}),e[i].children[1].children[1].changed=!1}}}if(n.length>0){let e=document.getElementById("loaderContainer");e.style.display="flex",fetch("/merchant/ingredients/update",{method:"PUT",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(n)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editIngredients(t),banner.createNotification("INGREDIENTS UPDATED"))}).catch(e=>{}).finally(()=>{e.style.display="none"})}}};var t={isPopulated:!1,ingredients:[],display:function(){this.isPopulated||(this.populateByProperty("category"),document.getElementById("ingredientSearch").oninput=()=>{this.search()},document.getElementById("ingredientClearButton").onclick=()=>{this.clearSorting()},document.getElementById("ingredientSelect").onchange=()=>{this.sort()},this.isPopulated=!0)},populateByProperty:function(e){let t;"category"===e?t=merchant.categorizeIngredients():"unit"===e&&(t=merchant.unitizeIngredients());let n=document.getElementById("categoryList"),i=document.getElementById("categoryDiv").content.children[0],r=document.getElementById("ingredient").content.children[0];for(this.ingredients=[];n.children.length>0;)n.removeChild(n.firstChild);for(let l=0;l{this.toggleCategory(e.children[1],e.children[0].children[1])},e.children[1].style.display="none",n.appendChild(e);for(let n=0;n{controller.openSidebar("ingredientDetails",i)},d._name=i.ingredient.name.toLowerCase(),d._unit=i.ingredient.unit.toLowerCase(),"bottle"===i.ingredient.specialUnit?d.children[2].innerText=(i.quantity/i.ingredient.unitSize).toFixed(2)+" BOTTLES":d.children[2].innerText=`${i.ingredient.convert(i.quantity).toFixed(2)} ${i.ingredient.unit.toUpperCase()}`,e.children[1].appendChild(d),this.ingredients.push(d)}}},displayIngredientsOnly:function(e){let t=document.getElementById("categoryList");for(;t.children.length>0;)t.removeChild(t.firstChild);for(let n=0;n',e.style.display="flex"):"flex"===e.style.display&&(t.innerHTML='',e.style.display="none")},search:function(){let e=document.getElementById("ingredientSearch").value.toLowerCase();if(document.getElementById("ingredientSelect").selectedIndex=0,""===e)return this.populateByProperty("category"),void(document.getElementById("ingredientClearButton").style.display="none");let t=[];for(let n=0;nt[e]>n[e]?1:-1);this.displayIngredientsOnly(t)},clearSorting:function(e){document.getElementById("ingredientSearch").value="",document.getElementById("ingredientSelect").selectedIndex=0,document.getElementById("ingredientClearButton").style.display="none",this.populateByProperty("category")}};var n={isPopulated:!1,recipeDivList:[],display:function(e){this.isPopulated||(this.populateRecipes(),"none"!==merchant.pos&&(document.getElementById("posUpdateRecipe").onclick=()=>{this.posUpdate(e)}),document.getElementById("recipeSearch").oninput=()=>{this.search()},document.getElementById("recipeClearButton").onclick=()=>{this.clearSorting()},this.isPopulated=!0)},populateRecipes:function(){let e=document.getElementById("recipeList"),t=document.getElementById("recipe").content.children[0];for(this.recipeDivList=[];e.children.length>0;)e.removeChild(e.firstChild);for(let n=0;n{controller.openSidebar("recipeDetails",merchant.recipes[n])},i._name=merchant.recipes[n].name,e.appendChild(i),i.children[0].innerText=merchant.recipes[n].name,i.children[1].innerText="$"+(merchant.recipes[n].price/100).toFixed(2),this.recipeDivList.push(i)}},search:function(){let e=document.getElementById("recipeSearch").value.toLowerCase(),t=document.getElementById("recipeList"),n=document.getElementById("recipeClearButton"),i=[];for(let r=0;r0;)t.removeChild(t.firstChild);for(let r=0;re.json()).then(t=>{let n=[];for(let r=0;r0&&merchant.editRecipes(n);let i=[];for(let e=0;e0&&merchant.editRecipes(i,!0)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var i={newData:!1,dateChange:!1,transactions:[],ingredient:{},recipe:{},display:function(e){if(document.getElementById("analDateBtn").onclick=()=>{this.changeDates(e)},0===this.transactions.length||!0===this.newData){let e=new Date;e.setMonth(e.getMonth()-1);const t=controller.transactionIndices(merchant.transactions,e);this.transactions=merchant.transactions.slice(t[0],t[1]+1)}let t=document.getElementById("analSlider");t.onchange=()=>{this.display(e)};let n=document.getElementById("analIngredientContent"),i=document.getElementById("analRecipeContent");t.checked?(n.style.display="none",i.style.display="flex",this.displayRecipes()):(n.style.display="flex",i.style.display="none",this.displayIngredients())},displayIngredients:function(){const e=document.getElementById("itemsList");for(;e.children.length>0;)e.removeChild(e.firstChild);for(let t=0;t{const e=document.getElementById("itemsList");for(let t=0;t0;)e.removeChild(e.firstChild);for(let t=0;t{let e=document.getElementById("analRecipeList");for(let t=0;ts?s=t[g]:t[g]t.to||""===t.from||""===t.to||t.to>new Date)return void banner.createError("INVALID DATE");let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/transaction/retrieve",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t.data);else{this.transactions=[];for(let i=0;i{banner.createError("ERROR: UNABLE TO DISPLAY THE DATA")}).finally(()=>{n.style.display="none"})}};var r={isFetched:!1,display:async function(e){if(!this.isFetched){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/order",{method:"GET",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=[];for(let i=0;i{this.submitFilter(e)},this.isFetched=!0}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE")}).finally(()=>{t.style.display="none"})}},populate:function(){let e=document.getElementById("orderList"),t=document.getElementById("order").content.children[0],n=document.getElementById("dateDropdownOrder"),i=document.getElementById("ingredientDropdown");n.style.display="none",i.style.display="none",document.getElementById("dateFilterBtnOrder").onclick=()=>{this.toggleDropdown(n)},document.getElementById("ingredientFilterBtn").onclick=()=>{this.toggleDropdown(i)};for(let r=0;r0;)e.removeChild(e.firstChild);for(let r=0;r{controller.openSidebar("orderDetails",merchant.orders[r])},e.appendChild(n)}},submitFilter:function(){event.preventDefault();let e={startDate:document.getElementById("orderFilDate1").valueAsDate,endDate:document.getElementById("orderFilDate2").valueAsDate,ingredients:[]};if(e.startDate>=e.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let t=document.getElementById("ingredientDropdown");for(let i=0;ie.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{let t=document.getElementById("orderList"),n=document.getElementById("order").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{controller.openSidebar("orderDetails",l)},t.appendChild(r)}}}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE ORDERS")}).finally(()=>{n.style.display="none"})},toggleDropdown:function(e){event.preventDefault();let t=e.parentElement.children[0].children[1].children[0].children[0];"none"===e.style.display?(e.style.display="block",t.setAttribute("points","18 15 12 9 6 15")):(e.style.display="none",t.setAttribute("points","6 9 12 15 18 9"))}};var l={isPopulated:!1,display:function(e){if(!this.isPopulated){let t=document.getElementById("transactionsList"),n=document.getElementById("dateDropdown"),i=document.getElementById("recipeDropDown"),r=document.getElementById("transaction").content.children[0],l=new Date,d=new Date(l.getFullYear(),l.getMonth()-1,l.getDate());for(document.getElementById("transFilDate1").valueAsDate=d,document.getElementById("transFilDate2").valueAsDate=l,n.style.display="none",i.style.display="none",document.getElementById("dateFilterBtn").onclick=()=>{this.toggleDropdown(n)},document.getElementById("recipeFilterBtn").onclick=()=>{this.toggleDropdown(i)};i.children.length>0;)i.removeChild(i.firstChild);for(let e=0;e0;)t.removeChild(t.firstChild);let a=0;for(;a{controller.openSidebar("transactionDetails",n)},t.appendChild(e);let i=0,l=0;for(let t=0;t{this.submitFilter(e)},this.isPopulated=!0}},submitFilter:function(e){event.preventDefault();let t={startDate:document.getElementById("transFilDate1").valueAsDate,endDate:document.getElementById("transFilDate2").valueAsDate,recipes:[]};if(t.startDate>=t.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let n=document.getElementById("recipeDropDown");for(let r=0;re.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=document.getElementById("transactionsList"),i=document.getElementById("transaction").content.children[0];for(;n.children.length>0;)n.removeChild(n.firstChild);for(let r=0;r{controller.openSidebar("transactionDetails",s)},n.appendChild(l)}}}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE TRANSACTIONS")}).finally(()=>{i.style.display="none"})},toggleDropdown:function(e){event.preventDefault();let t=e.parentElement.children[0].children[1].children[0].children[0];"none"===e.style.display?(e.style.display="block",t.setAttribute("points","18 15 12 9 6 15")):(e.style.display="none",t.setAttribute("points","6 9 12 15 18 9"))}};var d={ingredient:{},dailyUse:0,display:function(e){if(this.ingredient=e,"bottle"===this.ingredient.ingredient.specialUnit)try{let e=document.getElementById("ingredientUnitSizeLabel");e.parentElement.removeChild(e);let t=document.getElementById("bottleBorder");t.parentElement.removeChild(t)}catch(p){}document.getElementById("ingredientDetailsCategory").innerText=e.ingredient.category;let t=document.getElementById("detailsCategoryInput");t.value="",t.placeholder=e.ingredient.category,document.getElementById("ingredientDetailsName").innerText=e.ingredient.name;let n=document.getElementById("ingredientDetailsNameIn");n.value="",n.placeholder=e.ingredient.name;let i=document.getElementById("ingredientInput"),r=document.getElementById("ingredientStock");if(i.value="","bottle"===e.ingredient.specialUnit){let t=e.ingredient.convert(e.quantity);r.innerText=`${t.toFixed(2)} ${e.ingredient.unit.toUpperCase()}`,r.innerText=(e.quantity/e.ingredient.unitSize).toFixed(2)+" BOTTLES",i.placeholder=t.toFixed(2)}else r.innerText=`${e.ingredient.convert(e.quantity).toFixed(2)} ${e.ingredient.unit.toUpperCase()}`,i.placeholder=e.ingredient.convert(e.quantity).toFixed(2);let l=[],d=new Date;for(let y=1;y<31;y++){let t=new Date(d.getFullYear(),d.getMonth(),d.getDate()-y),n=new Date(d.getFullYear(),d.getMonth(),d.getDate()-y-1),i=controller.transactionIndices(merchant.transactions,n,t);!1===i?l.push(0):l.push(merchant.singleIngredientSold(i,e))}let a=0;for(let y=0;y0;)c.removeChild(c.firstChild);for(let y=0;y{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",o[y])},c.appendChild(e)}let h=document.getElementById("ingredientButtons"),g=[];for("other"!==this.ingredient.ingredient.unitType&&(g=merchant.units[this.ingredient.ingredient.unitType]);h.children.length>0;)h.removeChild(h.firstChild);for(let y=0;y{this.changeUnit(e,g[y])},h.appendChild(e),g[y]===this.ingredient.ingredient.unit&&e.classList.add("unitActive")}let u=document.querySelectorAll(".editAdd"),m=document.querySelectorAll(".editRemove");for(let y=0;y{this.editSubmit()},document.getElementById("editCancelButton").onclick=()=>{this.display(this.ingredient)},document.getElementById("editIngBtn").onclick=()=>{this.edit()},document.getElementById("removeIngBtn").onclick=()=>{this.remove()}},remove:function(){for(let t=0;te.json()).then(e=>{"string"==typeof e?banner.createError(e):(banner.createNotification("INGREDIENT REMOVED"),merchant.editIngredients([this.ingredient],!0))}).catch(e=>{}).finally(()=>{e.style.display="none"})},edit:function(){let e=document.querySelectorAll(".editAdd"),t=document.querySelectorAll(".editRemove");for(let n=0;ne.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editIngredients([this.ingredient]),this.display(this.ingredient),banner.createNotification("INGREDIENT UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{l.style.display="none"})},changeUnit:function(e,t){let n=document.querySelectorAll(".unitButton");for(let i=0;i{"string"==typeof e?banner.createError(e):banner.createNotification("INGREDIENT DEFAULT UNIT UPDATED")}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}};var a={display:function(e){const t=document.getElementById("unitSelector");document.getElementById("newIngName").value="",document.getElementById("newIngCategory").value="",document.getElementById("newIngQuantity").value=0,document.getElementById("bottleSizeLabel").style.display="none",t.value="g",t.onchange=()=>{this.unitChange()},document.getElementById("submitNewIng").onclick=()=>{this.submit(e)}},unitChange:function(){const e=document.getElementById("unitSelector"),t=document.getElementById("bottleSizeLabel");"bottle"===e.value?t.style.display="block":t.style.display="none"},submit:function(e){let t=document.getElementById("unitSelector"),n=document.querySelectorAll("#unitSelector option");const i=document.getElementById("newIngQuantity").value;let r=t.value,l={ingredient:{name:document.getElementById("newIngName").value,category:document.getElementById("newIngCategory").value,unitType:n[t.selectedIndex].getAttribute("type")},quantity:controller.convertToMain(r,i),defaultUnit:r};if("bottle"===r){const e=document.getElementById("bottleUnits").value,t=controller.convertToMain(e,document.getElementById("bottleSize").value);l.ingredient.unitType="volume",l.ingredient.unitSize=t,l.defaultUnit=e,l.ingredient.specialUnit=r,l.quantity=i*t}let d=document.getElementById("loaderContainer");d.style.display="flex",fetch("/ingredients/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(l)}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.editIngredients([{ingredient:new e(t.ingredient._id,t.ingredient.name,t.ingredient.category,t.ingredient.unitType,t.defaultUnit,merchant,t.ingredient.specialUnit,t.ingredient.unitSize),quantity:t.quantity}]),banner.createNotification("INGREDIENT CREATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{d.style.display="none"})}};var s={display:function(e){document.getElementById("sidebarDiv").classList.add("sidebarWide"),document.getElementById("newOrderIngredientList").style.display="flex";let t=document.getElementById("selectedIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("newOrderIngredients");for(;n.children.length>0;)n.removeChild(n.firstChild);for(let i=0;i{this.addIngredient(merchant.ingredients[i].ingredient,e)},n.appendChild(e)}document.getElementById("submitNewOrder").onclick=()=>{this.submit(e)}},addIngredient:function(e,t){t.style.display="none";let n=document.getElementById("selectedIngredient").content.children[0].cloneNode(!0);n.ingredient=e,n.children[0].children[1].onclick=()=>{this.removeIngredient(n,t)},"bottle"===e.specialUnit?n.children[0].children[0].innerText=e.name+" (BOTTLES)":n.children[0].children[0].innerText=`${e.name} (${e.unit.toUpperCase()})`,document.getElementById("selectedIngredientList").appendChild(n)},removeIngredient:function(e,t){e.parentElement.removeChild(e),t.style.display="block"},submit:function(e){let t=document.getElementById("newOrderDate").value,n=100*document.getElementById("orderTaxes").value,i=100*document.getElementById("orderFees").value,r=document.getElementById("selectedIngredientList").children;if(""===t)return void banner.createError("DATE IS REQUIRED FOR ORDERS");let l={name:document.getElementById("newOrderName").value,date:t,taxes:n,fees:i,ingredients:[]};for(let a=0;ae.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.name,t.date,t.taxes,t.fees,t.ingredients,merchant);merchant.editOrders([n]),merchant.editIngredients(n.ingredients,!1,!0),banner.createNotification("NEW ORDER CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{d.style.display="none"})}};var c={display:function(e){let t=document.querySelector("#recipeInputIngredients select"),n=merchant.categorizeIngredients();for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{this.changeRecipeCount()},document.getElementById("submitNewRecipe").onclick=()=>{this.submit(e)}},changeRecipeCount:function(){let e=document.getElementById("ingredientCount").value,t=document.getElementById("recipeInputIngredients"),n=t.children.length;if(e>n){let i=e-n;for(let e=0;e div");for(let r=0;re.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.name,t.price,t.ingredients,merchant);merchant.editRecipes([n]),banner.createNotification("RECIPE CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})}};var o={display:function(e){let t=document.getElementById("newTransactionRecipes"),n=document.getElementById("createTransaction").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{this.submit(e)}},submit:function(e){let t=document.getElementById("newTransactionRecipes"),n=document.getElementById("newTransactionDate").valueAsDate;if(n>new Date)return void banner.createError("CANNOT HAVE A DATE IN THE FUTURE");let i={date:n,recipes:[],ingredientUpdates:{}};for(let r=0;r0){i.recipes.push({recipe:n.id,quantity:e});for(let t=0;t0){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/transaction/create",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(i)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.date,t.recipes,merchant);merchant.editTransactions(n,i.ingredientUpdates),banner.createNotification("NEW TRANSACTION CREATED, INGREDIENTS UPDATED ACCORDINGLY")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}}};var h={display:function(e){document.getElementById("removeOrderBtn").onclick=()=>{this.remove(e)},document.getElementById("orderDetailName").innerText=e.name,document.getElementById("orderDetailDate").innerText=e.date.toLocaleDateString("en-US"),document.getElementById("orderDetailTax").innerText="$"+(e.taxes/100).toFixed(2),document.getElementById("orderDetailFee").innerText="$"+(e.fees/100).toFixed(2);let t=document.getElementById("orderIngredients");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("orderIngredient").content.children[0],i=0;for(let r=0;re.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{for(let t=0;t{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var g={recipe:{},display:function(e){this.recipe=e,document.getElementById("recipeName").style.display="block",document.getElementById("recipeNameIn").style.display="none",document.querySelector("#recipeDetails h1").innerText=e.name;let t=document.getElementById("recipeIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("recipeIngredient").content.children[0];for(let r=0;r{this.edit()},"none"===merchant.pos&&(document.getElementById("removeRecipeBtn").onclick=()=>{this.remove()}),document.getElementById("addRecIng").onclick=()=>{this.displayAddIngredient()},document.getElementById("recipeUpdate").onclick=()=>{this.update()}},edit:function(){let e=document.getElementById("recipeIngredientList");if("none"===merchant.pos){let e=document.getElementById("recipeName"),t=document.getElementById("recipeNameIn");e.style.display="none",t.style.display="block",t.value=this.recipe.name;let n=document.getElementById("recipePrice");n.children[1].style.display="none",n.children[2].style.display="block",n.children[2].value=parseFloat((this.recipe.price/100).toFixed(2))}for(let t=0;t{n.parentElement.removeChild(n)}}document.getElementById("addRecIng").style.display="flex",document.getElementById("recipeUpdate").style.display="flex"},update:function(){this.recipe.name=document.getElementById("recipeNameIn").value||this.recipe.name,this.recipe.price=Math.round(100*document.getElementById("recipePrice").children[2].value)||this.recipe.price,this.recipe.ingredients=[];let e=document.getElementById("recipeIngredientList").children;for(let i=0;ie.json()).then(e=>{"string"==typeof e?banner.createError(e):(window.merchant.editRecipes([this.recipe]),banner.createNotification("RECIPE UPDATE"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})},remove:function(){fetch("/merchant/recipes/remove/"+this.recipe.id,{method:"DELETE"}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editRecipes([this.recipe],!0),banner.createNotification("RECIPE REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")})},displayAddIngredient:function(){let e=document.getElementById("addRecIngredient").content.children[0].cloneNode(!0);e.name="new",document.getElementById("recipeIngredientList").appendChild(e);let t=window.merchant.categorizeIngredients();for(let n=0;n0;)t.removeChild(t.firstChild);for(let d=0;d{this.remove()})},remove:function(){let e=document.getElementById("loaderContainer");e.style.display="flex",fetch("/transaction/"+this.transaction.id,{method:"delete",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{let e={};for(let t=0;t{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}},m=class{constructor(e,t,n,i,r,l,d,a){this.id=e,this.name=t,this.category=n,this.unitType=i,this.unit=r,this.parent=l,d&&(this.specialUnit=d,this.unitSize=a)}convert(e){if("mass"===this.unitType)switch(this.unit){case"g":break;case"kg":e/=1e3;break;case"oz":e/=28.3495;break;case"lb":e/=453.5924}else if("volume"===this.unitType)switch(this.unit){case"ml":e*=1e3;break;case"l":break;case"tsp":e*=202.8842;break;case"tbsp":e*=67.6278;break;case"ozfl":e*=33.8141;break;case"cup":e*=4.1667;break;case"pt":e*=2.1134;break;case"qt":e*=1.0567;break;case"gal":e/=3.7854}else if("length"===this.unitType)switch(this.unit){case"mm":e*=1e3;break;case"cm":e*=100;break;case"m":break;case"in":e*=39.3701;break;case"ft":e*=3.2808}return e}},p=class{constructor(e,t,n,i,r){this.id=e,this.name=t,this.price=n,this.parent=r,this.ingredients=[];for(let l=0;le.date>t.date?-1:1));let r=Object.keys(t);for(let l=0;l{document.getElementById("max").style.display="flex",document.getElementById("min").style.display="none"},150)}}else{e.classList="menu menuMinimized";for(let e=0;e{this.closeMenu()}},closeMenu:function(){document.getElementById("menu").style.display="none",document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").onclick=()=>{this.openMenu()}},convertToMain:function(e,t){let n=0;if(merchant.units.mass.includes(e))switch(e){case"g":n=t;break;case"kg":n=1e3*t;break;case"oz":n=28.3495*t;break;case"lb":n=453.5924*t}else if(merchant.units.volume.includes(e))switch(e){case"ml":n=t/1e3;break;case"l":n=t;break;case"tsp":n=t/202.8842;break;case"tbsp":n=t/67.6278;break;case"ozfl":n=t/33.8141;break;case"cup":n=t/4.1667;break;case"pt":n=t/2.1134;break;case"qt":n=t/1.0567;break;case"gal":n=3.7854*t}else if(merchant.units.length.includes(e))switch(e){case"mm":n=t/1e3;break;case"cm":n=t/100;break;case"m":n=t;break;case"in":n=t/39.3701;break;case"ft":n=t/3.2808}else n=t;return n},updateData:function(d){switch(d){case"ingredient":e.isPopulated=!1,t.populateByProperty("category"),e.isPopulated=!1;break;case"recipe":l.isPopulated=!1,n.populateRecipes();break;case"order":r.populate();break;case"transaction":l.isPopulated=!1,l.display(y),i.newData=!0}},transactionIndices(e,t,n=new Date){let i=[];for(let r=0;r=0;r--)if(e[r].date>t){i.push(r);break}return!(i.length<2)&&i},convertPrice(e,t,n){if("mass"===e)switch(t){case"g":break;case"kg":n/=1e3;break;case"oz":n/=28.3495;break;case"lb":n/=453.5924}else if("volume"===e)switch(t){case"ml":n*=1e3;break;case"l":break;case"tsp":n*=202.8842;break;case"tbsp":n*=67.6278;break;case"ozfl":n*=33.8141;break;case"cup":n*=4.1667;break;case"pt":n*=2.1134;break;case"qt":n*=1.0567;break;case"gal":n/=3.7854}else if("length"===e)switch(t){case"mm":n*=1e3;break;case"cm":n*=100;break;case"m":break;case"in":n*=39.3701;break;case"ft":n*=3.2808}return n},reconvertPrice(e,t,n){if("mass"===e)switch(t){case"g":break;case"kg":n*=1e3;break;case"oz":n*=28.3495;break;case"lb":n*=453.5924}else if("volume"===e)switch(t){case"ml":n/=1e3;break;case"l":break;case"tsp":n/=202.8842;break;case"tbsp":n/=67.6278;break;case"ozfl":n/=33.8141;break;case"cup":n/=4.1667;break;case"pt":n/=2.1134;break;case"qt":n/=1.0567;break;case"gal":n*=3.7854}else if("length"===e)switch(t){case"mm":n/=1e3;break;case"cm":n/=100;break;case"m":break;case"in":n/=39.3701;break;case"ft":n/=3.2808}return n}},window.screen.availWidth>1e3&&window.screen.availWidth<=1400&&(this.changeMenu(),document.getElementById("menuShifter2").style.display="none"),controller.openStrand("home")}();