| 1 |
- !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));const r=merchant.getRevenue(t),s=merchant.getRevenue(n,i);document.getElementById("revenue").innerText="$"+r.toFixed(2);let a=(r-s)/s*100,d="";d=a>=0?"/shared/images/upArrow.png":"/shared/images/downArrow.png",document.querySelector("#revenueChange p").innerText=Math.abs(a).toFixed(2)+"% vs last month",document.querySelector("#revenueChange img").src=d},drawRevenueGraph:function(){let e=new Date;e.setMonth(e.getMonth()-1);let t=[],n=[],i=0;const r=merchant.getTransactions(e);let s=r.length>0?r[0].date:void 0;for(let d=0;d<r.length;d++){r[d].date.getDate()!==s.getDate()&&(t.push(i/100),i=0,n.push(s),s=r[d].date);for(let e=0;e<r[d].recipes.length;e++){const t=r[d].recipes[e];i+=t.recipe.price*t.quantity}}const a={x:n,y:t,mode:"lines+markers",line:{color:"rgb(255, 99, 107)"}};Plotly.newPlot("graphCard",[a],{title:"REVENUE",xaxis:{title:"DATE"},yaxis:{title:"$"}})},drawInventoryCheckCard:function(){let e;e=merchant.ingredients.length<5?merchant.ingredients.length:5;let t=[];for(let r=0;r<e;r++){let e=Math.floor(Math.random()*merchant.ingredients.length);t.includes(e)?r--:t[r]=e}let n=document.querySelector("#inventoryCheckCard ul"),i=document.getElementById("ingredientCheck").content.children[0];for(;n.children.length>0;)n.removeChild(n.firstChild);for(let r=0;r<t.length;r++){let e=i.cloneNode(!0),s=e.children[1].children[1];const a=merchant.ingredients[t[r]];e.ingredient=a,e.children[0].innerText=a.ingredient.name,e.children[1].children[0].onclick=()=>{s.value--,s.changed=!0},"bottle"===a.ingredient.specialUnit?(s.value=a.quantity.toFixed(2),e.children[2].innerText="BOTTLES"):(s.value=a.quantity.toFixed(2),e.children[2].innerText=a.ingredient.unit.toUpperCase()),e.children[1].children[2].onclick=()=>{s.value++,s.changed=!0},s.onchange=()=>{s.changed=!0},n.appendChild(e)}document.getElementById("inventoryCheck").onclick=()=>{this.submitInventoryCheck()}},drawPopularCard:function(){let e=new Date;e.setDate(1);const t=merchant.getIngredientsSold(e);if(!1!==t){t.sort((e,t)=>e.quantity<t.quantity?1:e.quantity>t.quantity?-1:0);let e=[],n=[],i=[];for(let a=t.length<5?t.length-1:4;a>=0;a--){const r=t[a].ingredient.name,s=t[a].quantity,d=t[a].ingredient.unit;e.push(t[a].quantity),n.push(`${r}: ${s.toFixed(2)} ${d.toUpperCase()}`),0===a?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}},s={title:"MOST POPULAR INGREDIENTS",xaxis:{zeroline:!1,title:"QUANTITY"},yaxis:{showticklabels:!1}};Plotly.newPlot("popularIngredientsCard",[r],s)}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=[];for(let n=0;n<e.length;n++){if(!(e[n].children[1].children[1].value>=0))return void banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");if(!0===e[n].children[1].children[1].changed){let i=e[n].ingredient;t.push({id:i.ingredient.id,quantity:e[n].children[1].children[1].value}),e[n].children[1].children[1].changed=!1}}if(t.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(t)}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{for(let t=0;t<e.length;t++)merchant.removeIngredient(merchant.getIngredient(e[t].ingredient._id)),merchant.addIngredient(e[t].ingredient,e[t].quantity,e[t].defaultUnit);banner.createNotification("INGREDIENTS UPDATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}}};var t={isPopulated:!1,ingredients:[],display:function(){this.isPopulated||(document.getElementById("ingredientSearch").oninput=()=>{this.search()},this.populateByProperty(),this.isPopulated=!0)},populateByProperty:function(){let e;e=merchant.categorizeIngredients();let t=document.getElementById("categoryList"),n=document.getElementById("categoryDiv").content.children[0],i=document.getElementById("ingredient").content.children[0];for(this.ingredients=[];t.children.length>0;)t.removeChild(t.firstChild);for(let r=0;r<e.length;r++){let s=n.cloneNode(!0);s.children[0].children[0].innerText=e[r].name.toUpperCase(),s.children[0].onclick=()=>{this.toggleCategory(s.children[1],s.children[0].children[1])},s.children[1].style.display="none",t.appendChild(s);for(let t=0;t<e[r].ingredients.length;t++){let n=e[r].ingredients[t],a=i.cloneNode(!0);a.children[0].innerText=n.ingredient.name,a.onclick=()=>{controller.openSidebar("ingredientDetails",n),a.classList.add("active")},a._name=n.ingredient.name.toLowerCase(),a._unit=n.ingredient.unit.toLowerCase(),"bottle"===n.ingredient.specialUnit?a.children[2].innerText=n.quantity.toFixed(2)+" BOTTLES":a.children[2].innerText=`${n.quantity.toFixed(2)} ${n.ingredient.unit.toUpperCase()}`,s.children[1].appendChild(a),this.ingredients.push(a)}}},displayIngredientsOnly:function(e){let t=document.getElementById("categoryList");for(;t.children.length>0;)t.removeChild(t.firstChild);for(let n=0;n<e.length;n++)t.appendChild(e[n])},toggleCategory:function(e,t){"none"===e.style.display?(t.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"></polyline></svg>',e.style.display="flex"):"flex"===e.style.display&&(t.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>',e.style.display="none")},search:function(){let e=document.getElementById("ingredientSearch").value.toLowerCase();if(""===e)return void this.populateByProperty();let t=[];for(let n=0;n<this.ingredients.length;n++)this.ingredients[n]._name.includes(e)&&t.push(this.ingredients[n]);this.displayIngredientsOnly(t)}};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()},this.populateRecipes(),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<merchant.recipes.length;n++){let i=t.cloneNode(!0);i.onclick=()=>{controller.openSidebar("recipeDetails",merchant.recipes[n]),i.classList.add("active")},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.toFixed(2),this.recipeDivList.push(i)}},search:function(){let e=document.getElementById("recipeSearch").value.toLowerCase(),t=document.getElementById("recipeList"),n=[];for(let i=0;i<this.recipeDivList.length;i++)this.recipeDivList[i]._name.toLowerCase().includes(e)&&n.push(this.recipeDivList[i]);for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i<n.length;i++)t.appendChild(n[i])},posUpdate:function(e){let t=document.getElementById("loaderContainer");t.style.display="flex";let n="/recipe/update/"+merchant.pos;fetch(n,{method:"GET",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{for(let n=0;n<t.new.length;n++){const i=new e(t.new[n]._id,t.new[n].name,t.new[n].price,merchant,[]);merchant.addRecipe(i)}for(let e=0;e<t.removed.length;e++)for(let n=0;n<merchant.recipes.length;n++)if(merchant.recipes[n].id===t.removed[e]._id){merchant.removeRecipe(merchant.recipes[n]);break}this.display()}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var i={isPopulated:!1,ingredient:void 0,recipe:void 0,transactionsByDate:[],display:function(e){if(!this.isPopulated){document.getElementById("analRecipeContent").style.display="none";let t=new Date,n=new Date(t.getFullYear(),t.getMonth()-1,t.getDate());document.getElementById("analStartDate").valueAsDate=n,document.getElementById("analEndDate").valueAsDate=t;let i=document.getElementById("analSlider");i.onclick=()=>{this.switchDisplay()},i.checked=!1,document.getElementById("analDateBtn").onclick=()=>{this.newDates(e)},this.populateButtons(),merchant.ingredients.length>0&&(this.ingredient=merchant.ingredients[0].ingredient),merchant.recipes.length>0&&(this.recipe=merchant.recipes[0]),this.newDates(e),this.isPopulated=!0}},populateButtons:function(){let e=document.getElementById("analIngredientList"),t=document.getElementById("analRecipeList");for(let n=0;n<merchant.ingredients.length;n++){let t=document.createElement("button");t.innerText=merchant.ingredients[n].ingredient.name,t.classList.add("choosable"),t.onclick=()=>{this.ingredient=merchant.ingredients[n].ingredient,this.displayIngredient()},e.appendChild(t)}for(let n=0;n<merchant.recipes.length;n++){let e=document.createElement("button");e.innerText=merchant.recipes[n].name,e.classList.add("choosable"),e.onclick=()=>{this.recipe=merchant.recipes[n],this.displayRecipe()},t.appendChild(e)}},getData:function(e,t,n){let i=document.getElementById("loaderContainer");return i.style.display="flex",fetch(`/transactions/${e.toISOString()}/${t.toISOString()}`).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{this.transactionsByDate=[];for(let t=0;t<e.length;t++){const i=new Date(e[t].date);let r={date:i,transactions:[]};for(let s=0;s<e[t].transactions.length;s++)r.transactions.push(new n(e[t].transactions[s]._id,i,e[t].transactions[s].recipes,merchant));this.transactionsByDate.push(r)}}}).catch(e=>{banner.createError("UNABLE TO UPDATE THE PAGE")}).finally(()=>{i.style.display="none"})},displayIngredient:function(e){if(void 0===this.ingredient||0===this.transactionsByDate.length)return;let t=[],n=[];for(let o=0;o<this.transactionsByDate.length;o++){t.push(this.transactionsByDate[o].date);let e=0;for(let t=0;t<this.transactionsByDate[o].transactions.length;t++)e+=this.transactionsByDate[o].transactions[t].getIngredientQuantity(this.ingredient);n.push(e)}let i={x:t,y:n,mode:"lines+markers",line:{color:"rgb(255, 99, 107)"}};const r={title:this.ingredient.name.toUpperCase(),xaxis:{title:"DATE"},yaxis:{title:`QUANTITY (${this.ingredient.unit.toUpperCase()})`}};Plotly.newPlot("itemUseGraph",[i],r);let s=n[0],a=n[0],d=0;for(let o=0;o<n.length;o++)n[o]<s&&(s=n[o]),n[o]>a&&(a=n[o]),d+=n[o];document.getElementById("analMinUse").innerText=`${s.toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analAvgUse").innerText=`${(d/n.length).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analMaxUse").innerText=`${a.toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;let l=[0,0,0,0,0,0,0],c=[0,0,0,0,0,0,0];for(let o=0;o<n.length;o++)l[t[o].getDay()]+=n[o],c[t[o].getDay()]++;document.getElementById("analDayOne").innerText=`${(l[0]/c[0]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDayTwo").innerText=`${(l[1]/c[1]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDayThree").innerText=`${(l[2]/c[2]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDayFour").innerText=`${(l[3]/c[3]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDayFive").innerText=`${(l[4]/c[4]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDaySix").innerText=`${(l[5]/c[5]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`,document.getElementById("analDaySeven").innerText=`${(l[6]/c[6]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`},displayRecipe:function(){if(void 0===this.recipes||0===this.transactionsByDate.length)return;let e=[],t=[];for(let s=0;s<this.transactionsByDate.length;s++){e.push(this.transactionsByDate[s].date);let n=0;for(let e=0;e<this.transactionsByDate[s].transactions.length;e++){const t=this.transactionsByDate[s].transactions[e];for(let e=0;e<t.recipes.length;e++)t.recipes[e].recipe===this.recipe&&(n+=t.recipes[e].quantity)}t.push(n)}const n={x:e,y:t,mode:"lines+markers",line:{color:"rgb(255, 99, 107)"}},i={title:this.recipe.name.toUpperCase(),xaxis:{title:"DATE"},yaxis:{title:"QUANTITY"}};Plotly.newPlot("recipeSalesGraph",[n],i);let r=0;for(let s=0;s<t.length;s++)r+=t[s];r/=t.length,document.getElementById("recipeAvgUse").innerText=r.toFixed(2),document.getElementById("recipeAvgRevenue").innerText="$"+(r*this.recipe.price).toFixed(2)},switchDisplay:function(){const e=document.getElementById("analSlider");let t=document.getElementById("analIngredientContent"),n=document.getElementById("analRecipeContent");!0===e.checked?(t.style.display="none",n.style.display="flex",this.displayRecipe()):(t.style.display="flex",n.style.display="none",this.displayIngredient())},newDates:async function(e){const t=document.getElementById("analStartDate").valueAsDate,n=document.getElementById("analEndDate").valueAsDate;await this.getData(t,n,e),!0===document.getElementById("analSlider").checked?this.displayRecipe():this.displayIngredient()}};var r={display:function(){document.getElementById("orderFilterBtn").onclick=()=>{controller.openSidebar("orderFilter")},document.getElementById("newOrderBtn").onclick=()=>{controller.openSidebar("newOrder")};let e=document.getElementById("orderList"),t=document.getElementById("order").content.children[0];for(;e.children.length>0;)e.removeChild(e.firstChild);for(let n=0;n<merchant.orders.length;n++){let i=t.cloneNode(!0);i.order=merchant.orders[n],i.children[0].innerText=merchant.orders[n].name,i.children[1].innerText=merchant.orders[n].ingredients.length+" ingredients",i.children[2].innerText=merchant.orders[n].date.toLocaleDateString("en-US"),i.children[3].innerText="$"+merchant.orders[n].getTotalCost().toFixed(2),i.onclick=()=>{controller.openSidebar("orderDetails",merchant.orders[n]),i.classList.add("active")},e.appendChild(i)}},getOrders:function(e){let t=document.getElementById("loaderContainer");return 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){let n=[];for(let i=0;i<t.length;i++)n.push(new e(t[i]._id,t[i].name,t[i].date,t[i].taxes,t[i].fees,t[i].ingredients,merchant));return 0===merchant.orders.length&&merchant.setOrders(n),n}banner.createError(t)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var s={transactions:[],display:function(e){document.getElementById("filterTransactionsButton").onclick=()=>{controller.openSidebar("transactionFilter")},document.getElementById("newTransactionButton").onclick=()=>{controller.openSidebar("newTransaction")},this.populateTransactions(this.transactions),this.isPopulated=!0},populateTransactions:function(e){let t=document.getElementById("transactionsList"),n=document.getElementById("transaction").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);let i=0;for(;i<e.length&&i<100;){let r=n.cloneNode(!0),s=e[i];r.onclick=()=>{controller.openSidebar("transactionDetails",s),r.classList.add("active")},t.appendChild(r);let a=0,d=0;for(let t=0;t<e[i].recipes.length;t++)a+=e[i].recipes[t].quantity,d+=e[i].recipes[t].recipe.price*e[i].recipes[t].quantity;r.children[0].innerText=`${e[i].date.toLocaleDateString()} ${e[i].date.toLocaleTimeString()}`,r.children[1].innerText=a+" recipes sold",r.children[2].innerText="$"+d.toFixed(2),i++}}};var a={dailyUse:0,display:function(e){document.getElementById("editIngBtn").onclick=()=>{controller.openSidebar("editIngredient",e)},document.getElementById("removeIngBtn").onclick=()=>{this.remove(e)},document.getElementById("ingredientDetailsCategory").innerText=e.ingredient.category,document.getElementById("ingredientDetailsName").innerText=e.ingredient.name,document.getElementById("ingredientStock").innerText=e.getQuantityDisplay();let t=[],n=new Date;for(let c=1;c<31;c++){let i=new Date(n.getFullYear(),n.getMonth(),n.getDate()-c),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-c-1);t.push(merchant.getSingleIngredientSold(e,r,i))}let i=0;for(let c=0;c<t.length;c++)i+=t[c];let r=i/t.length;const s=document.getElementById("dailyUse");"bottle"===e.ingredient.specialUnit?s.innerText=r.toFixed(2)+" BOTTLES":s.innerText=`${r.toFixed(2)} ${e.ingredient.unit.toUpperCase()}`;let a=document.getElementById("ingredientRecipeList"),d=document.getElementById("ingredientRecipe").content.children[0],l=merchant.getRecipesForIngredient(e.ingredient);for(;a.children.length>0;)a.removeChild(a.firstChild);for(let c=0;c<l.length;c++){let e=d.cloneNode(!0);e.children[0].innerText=l[c].name,e.onclick=()=>{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",l[c])},e.classList.add("choosable"),a.appendChild(e)}},remove:function(e){for(let n=0;n<merchant.recipes.length;n++)for(let t=0;t<merchant.recipes[n].ingredients.length;t++)if(e.ingredient===merchant.recipes[n].ingredients[t].ingredient)return void banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/ingredients/remove/"+e.ingredient.id,{method:"delete"}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.removeIngredient(e),controller.openStrand("ingredients"),banner.createNotification("INGREDIENT REMOVED"))}).catch(e=>{}).finally(()=>{t.style.display="none"})}};var d={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)},document.getElementById("ingredientFileUpload").addEventListener("click",()=>{controller.openModal("ingredientSpreadsheet")})},unitChange:function(){const e=document.getElementById("unitSelector"),t=document.getElementById("bottleSizeLabel");"bottle"===e.value?t.style.display="block":t.style.display="none"},submit:function(){let e=document.getElementById("unitSelector"),t=document.querySelectorAll("#unitSelector option");const n=parseFloat(document.getElementById("newIngQuantity").value);let i=e.value,r={ingredient:{name:document.getElementById("newIngName").value,category:document.getElementById("newIngCategory").value,unitType:t[e.selectedIndex].getAttribute("type")},quantity:n,defaultUnit:i};"bottle"===i&&(r.ingredient.unitType="volume",r.ingredient.unitSize=document.getElementById("bottleSize").value,r.defaultUnit=document.getElementById("bottleUnits").value,r.ingredient.specialUnit=i,r.quantity=n);let s=document.getElementById("loaderContainer");s.style.display="flex",fetch("/ingredients/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(r)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.addIngredient(e.ingredient,e.quantity,e.defaultUnit),controller.openStrand("ingredients"),banner.createNotification("INGREDIENT CREATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{s.style.display="none"})},submitSpreadsheet:function(){event.preventDefault(),controller.closeModal();const e=document.getElementById("spreadsheetInput").files[0];let t=new FormData;t.append("ingredients",e);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/ingredients/create/spreadsheet",{method:"post",body:t}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else for(let t=0;t<e.length;t++)merchant.addIngredient(e[t].ingredient,e[t].quantity,e[t].defaultUnit),controller.openStrand("ingredients")}).catch(e=>{banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE")}).finally(()=>{n.style.display="none"})}};var l={display:function(e){let t=document.getElementById("unitButtons"),n=document.getElementById("editIngQuantityLabel"),i=document.getElementById("editSpecialLabel");for(;t.children.length>0;)t.removeChild(t.firstChild);document.getElementById("editIngTitle").innerText=e.ingredient.name,document.getElementById("editIngName").value=e.ingredient.name,document.getElementById("editIngCategory").value=e.ingredient.category,n.innerText=`CURRENT STOCK (${e.ingredient.unit.toUpperCase()})`,document.getElementById("editIngSubmit").onclick=()=>{this.submit(e)};const r=merchant.units[e.ingredient.unitType];for(let a=0;a<r.length;a++){let n=document.createElement("button");n.classList.add("unitButton"),n.innerText=r[a].toUpperCase(),n.onclick=()=>{this.changeUnit(n)},t.appendChild(n),r[a]===e.ingredient.unit&&n.classList.add("unitActive")}if("bottle"===e.ingredient.specialUnit){n.innerText="CURRENT STOCK (BOTTLES):",i.style.display="flex",i.innerText=`BOTTLE SIZE (${e.ingredient.unit.toUpperCase()}):`;let t=document.createElement("input");t.id="editIngSpecialSize",t.type="number",t.min="0",t.step="0.01",t.value=e.ingredient.unitSize.toFixed(2),i.appendChild(t)}else i.style.display="none";let s=document.createElement("input");s.id="editIngQuantity",s.type="number",s.min="0",s.step="0.01",s.value=e.quantity.toFixed(2),n.appendChild(s)},changeUnit(e){let t=document.getElementById("unitButtons");for(let n=0;n<t.children.length;n++)t.children[n].classList.remove("unitActive");e.classList.add("unitActive")},submit(e){const t=parseFloat(document.getElementById("editIngQuantityLabel").children[0].value);let n={id:e.ingredient.id,name:document.getElementById("editIngName").value,category:document.getElementById("editIngCategory").value};if("bottle"===e.ingredient.specialUnit){let i=e.convertToBase(parseFloat(document.getElementById("editSpecialLabel").children[0].value));n.quantity=t*i,n.unitSize=i}else n.quantity=t;let i=document.getElementById("unitButtons");for(let s=0;s<i.children.length;s++)if(i.children[s].classList.contains("unitActive")){n.unit=i.children[s].innerText.toLowerCase();break}let r=document.getElementById("loaderContainer");r.style.display="flex",fetch("/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.removeIngredient(merchant.getIngredient(e.ingredient._id)),merchant.addIngredient(e.ingredient,e.quantity,e.unit),controller.openStrand("ingredients"),banner.createNotification("INGREDIENT UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{r.style.display="none"})}};var c={display:function(e){document.getElementById("sidebarDiv").classList.add("sidebarWide"),document.getElementById("newOrderIngredientList").style.display="flex",document.getElementById("orderFileUpload").addEventListener("click",()=>{controller.openModal("orderSpreadsheet")});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<merchant.ingredients.length;i++){let e=document.createElement("button");e.classList="choosable",e.innerText=merchant.ingredients[i].ingredient.name,e.onclick=()=>{this.addIngredient(merchant.ingredients[i],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.ingredient.specialUnit?n.children[0].children[0].innerText=e.ingredient.name+" (BOTTLES)":n.children[0].children[0].innerText=`${e.ingredient.name} (${e.ingredient.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 s={name:document.getElementById("newOrderName").value,date:t,taxes:n,fees:i,ingredients:[]};for(let d=0;d<r.length;d++){let e=r[d].children[1].children[0].value,t=r[d].children[1].children[1].value;if(""===e||""===t)return void banner.createError("MUST PROVIDE QUANTITY AND PRICE PER UNIT FOR ALL INGREDIENTS");(e<0||t<0)&&banner.createError("QUANTITY AND PRICE MUST BE NON-NEGATIVE NUMBERS"),"bottle"===r[d].ingredient.ingredient.specialUnit?s.ingredients.push({ingredient:r[d].ingredient.ingredient.id,quantity:e*r[d].ingredient.ingredient.unitSize,pricePerUnit:this.convertPrice(r[d].ingredient.ingredient,100*t)}):s.ingredients.push({ingredient:r[d].ingredient.ingredient.id,quantity:r[d].ingredient.convertToBase(e),pricePerUnit:this.convertPrice(r[d].ingredient.ingredient,100*t)})}let a=document.getElementById("loaderContainer");a.style.display="flex",fetch("/order/create",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(s)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.addOrder(e,!0),controller.openStrand("orders",merchant.orders),banner.createNotification("NEW ORDER CREATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{a.style.display="none"})},convertPrice:function(e,t){if("bottle"===e.specialUnit)return t/e.unitSize;switch(e.unit){case"g":return t;case"kg":return t/1e3;case"oz":return t/28.3495;case"lb":return t/453.5924;case"ml":return 1e3*t;case"l":return t;case"tsp":return 202.8842*t;case"tbsp":return 67.6278*t;case"ozfl":return 33.8141*t;case"cup":return 4.1667*t;case"pt":return 2.1134*t;case"qt":return 1.0567*t;case"gal":return t/3.7854;case"mm":return 1e3*t;case"cm":return 100*t;case"m":return t;case"in":return 39.3701*t;case"ft":return 3.2808*t}},submitSpreadsheet:function(){event.preventDefault(),controller.closeModal();const e=document.getElementById("spreadsheetInput").files[0];let t=new FormData;t.append("orders",e);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/orders/create/spreadsheet",{method:"post",body:t}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{for(let t=0;t<e.length;t++)merchant.addOrder(e[t],!0);banner.createNotification("ORDER CREATED AND INGREDIENTS UPDATED SUCCESSFULLY"),controller.openStrand("orders")}}).catch(e=>{banner.createError("UNABLE TO DISPLAY NEW ORDER. PLEASE REFRESH THE PAGE.")}).finally(()=>{n.style.display="none"})}};var o={display:function(e){document.getElementById("newRecipeName").value="",document.getElementById("newRecipePrice").value="",document.getElementById("ingredientCount").value=1;let t=merchant.categorizeIngredients(),n=document.getElementById("recipeInputIngredients");for(;n.children.length>0;)n.removeChild(n.firstChild);this.changeIngredientCount(t),document.getElementById("ingredientCount").onchange=()=>{this.changeIngredientCount(t)},document.getElementById("submitNewRecipe").onclick=()=>{this.submit(e)},document.getElementById("recipeFileUpload").onclick=()=>{controller.openModal("recipeSpreadsheet")}},changeIngredientCount:function(e){let t=document.getElementById("ingredientCount").value,n=document.getElementById("recipeInputIngredients"),i=document.getElementById("recipeInputIngredient").content.children[0],r=n.children.length;if(t>r){let s=t-r;for(let t=0;t<s;t++){let s=i.cloneNode(!0);s.children[0].innnerText="INGREDIENT "+(t+r),s.children[2].children[0].value=0;for(let t=0;t<e.length;t++){let n=document.createElement("optgroup");n.label=e[t].name;for(let i=0;i<e[t].ingredients.length;i++){let r=document.createElement("option");r.innerText=e[t].ingredients[i].ingredient.getNameAndUnit(),r.ingredient=e[t].ingredients[i],n.appendChild(r)}s.children[1].children[0].appendChild(n)}n.appendChild(s)}for(let e=0;e<t;e++)n.children[e].children[0].innerText="INGREDIENT "+(e+1)}else if(t<r){let e=r-t;for(let t=0;t<e;t++)n.removeChild(n.children[n.children.length-1])}},submit:function(e){let t={name:document.getElementById("newRecipeName").value,price:document.getElementById("newRecipePrice").value,ingredients:[]},n=document.getElementById("recipeInputIngredients").children;for(let r=0;r<n.length;r++){let e=n[r].children[1].children[0],i=e.options[e.selectedIndex].ingredient;t.ingredients.push({ingredient:i.ingredient.id,quantity:i.convertToBase(n[r].children[2].children[0].value)})}let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/recipe/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{let t=[];for(let n=0;n<e.ingredients.length;n++)for(let i=0;i<merchant.ingredients.length;i++)if(merchant.ingredients[i].ingredient.id===e.ingredients[n].ingredient){t.push({ingredient:merchant.ingredients[i].ingredient,quantity:e.ingredients[n].quantity});break}merchant.addRecipe(e._id,e.name,e.price,t),banner.createNotification("RECIPE CREATED"),controller.openStrand("recipeBook")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})},submitSpreadsheet:function(){event.preventDefault(),controller.closeModal();const e=document.getElementById("spreadsheetInput").files[0];let t=new FormData;t.append("recipes",e);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/recipes/create/spreadsheet",{method:"post",body:t}).then(e=>e.json()).then(e=>{if("String"==typeof e)banner.createError(e);else{for(let t=0;t<e.length;t++)merchant.addRecipe(e[t]._id,e[t].name,e[t].price,e[t].ingredients);banner.createNotification("ALL INGREDIENTS SUCCESSFULLY CREATED"),controller.openStrand("recipeBook")}}).catch(e=>{banner.createError("UNABLE TO DISPLAY NEW RECIPES. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})}};var h={display:function(e){let t=document.getElementById("editRecipeName");"none"===merchant.pos?t.value=e.name:(document.getElementById("editRecipeNoName").innertext=e.name,t.parentNode.style.display="none");let n=document.getElementById("editRecipeIngList");for(;n.children.length>0;)n.removeChild(n.firstChild);let i=document.getElementById("editRecipeIng").content.children[0];for(let r=0;r<e.ingredients.length;r++){let t=i.cloneNode(!0);t.children[0].onclick=()=>{t.parentNode.removeChild(t)},t.children[1].innerText=e.ingredients[r].ingredient.getNameAndUnit(),t.children[2].style.display="none",t.children[3].value=e.ingredients[r].quantity,t.ingredient=e.ingredients[r],n.appendChild(t)}document.getElementById("addRecIng").onclick=()=>{this.newIngredient()},document.getElementById("editRecipePrice").value=e.price,document.getElementById("editRecipeSubmit").onclick=()=>{this.submit(e)},document.getElementById("editRecipeCancel").onclick=()=>{controller.openSidebar("recipeDetails",e)}},newIngredient:function(){let e=document.getElementById("editRecipeIngList"),t=document.getElementById("editRecipeIng").content.children[0].cloneNode(!0);t.children[0].onclick=()=>{t.parentNode.removeChild(t)},t.children[1].style.display="none",t.children[3].value="0.00";let n=merchant.categorizeIngredients();for(let i=0;i<n.length;i++){let e=document.createElement("optgroup");e.label=n[i].name;for(let t=0;t<n[i].ingredients.length;t++){let r=document.createElement("option");r.innerText=n[i].ingredients[t].ingredient.getNameAndUnit(),r.ingredient=n[i].ingredients[t],e.appendChild(r)}t.children[2].appendChild(e)}e.appendChild(t)},submit:function(e){let t={id:e.id,name:e.name,price:100*document.getElementById("editRecipePrice").value,ingredients:[]};"none"===merchant.pos&&(t.name=document.getElementById("editRecipeName").value);let n=document.getElementById("editRecipeIngList").children;for(let r=0;r<n.length;r++){const e=parseFloat(n[r].children[3].value);if("none"===n[r].children[1].style.display){let i=n[r].children[2],s=i.options[i.selectedIndex].ingredient;t.ingredients.push({ingredient:s.ingredient.id,quantity:s.convertToBase(e)})}else t.ingredients.push({ingredient:n[r].ingredient.ingredient.id,quantity:n[r].ingredient.convertToBase(e)})}let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/recipe/update",{method:"put",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.updateRecipe(e),controller.openStrand("recipeBook"),banner.createNotification("RECIPE UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})}};var u={display:function(e){let t=document.getElementById("newTransactionRecipes"),n=document.getElementById("createTransaction").content.children[0];for(document.getElementById("transactionFileUpload").addEventListener("click",()=>{controller.openModal("transactionSpreadsheet")});t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i<merchant.recipes.length;i++){let e=n.cloneNode(!0);e.recipe=merchant.recipes[i],t.appendChild(e),e.children[0].innerText=merchant.recipes[i].name}document.getElementById("submitNewTransaction").onclick=()=>{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;r<t.children.length;r++){let e=t.children[r].children[1].value;const n=t.children[r].recipe;if(""!==e&&e>0){i.recipes.push({recipe:n.id,quantity:e});for(let t=0;t<n.ingredients.length;t++){let r=n.ingredients[t];i.ingredientUpdates[r.ingredient.id]?i.ingredientUpdates[r.ingredient.id]+=r.convertToBase(r.quantity)*e:i.ingredientUpdates[r.ingredient.id]=r.convertToBase(r.quantity)*e}}else if(e<0)return void banner.createError("CANNOT HAVE NEGATIVE VALUES")}if(i.recipes.length>0){let e=document.getElementById("loaderContainer");e.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(e=>{"string"==typeof e?banner.createError(e):(merchant.addTransaction(e),controller.openStrand("transactions",merchant.getTransactions()),banner.createNotification("TRANSACTION CREATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}},submitSpreadsheet:function(){event.preventDefault(),controller.closeModal();const e=document.getElementById("spreadsheetInput").files[0];let t=new FormData;t.append("transactions",e);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/transactions/create/spreadsheet",{method:"post",body:t}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{for(let t=0;t<e.recipes.length;t++)e.recipes[t].recipe=e.recipes[t].recipe._id;merchant.addTransaction(e),controller.openStrand("transactions",merchant.transactions),banner.createNotification("TRANSACTION SUCCESSFULLY CREATED. INGREDIENTS UPDATED")}}).catch(e=>{banner.createError("UNABLE TO DISPLAY NEW TRANSACTIONS. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})}};var g={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.toFixed(2),document.getElementById("orderDetailFee").innerText="$"+e.fees.toFixed(2);let t=document.getElementById("orderIngredients");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("orderIngredient").content.children[0];for(let i=0;i<e.ingredients.length;i++){let r=n.cloneNode(!0);const s=e.ingredients[i].ingredient;r.children[0].innerText=e.ingredients[i].ingredient.name,r.children[2].innerText="$"+e.ingredients[i].cost().toFixed(2),r.onclick=()=>{controller.openStrand("ingredients"),controller.openSidebar("ingredientDetails",merchant.getIngredient(e.ingredients[i].ingredient.id))};let a=r.children[1];"bottle"===s.specialUnit?a.innerText=`${e.ingredients[i].quantity.toFixed(2)} bottles x $${e.ingredients[i].pricePerUnit.toFixed(2)}`:a.innerText=`${e.ingredients[i].quantity.toFixed(2)} ${s.unit.toUpperCase()} X $${e.ingredients[i].pricePerUnit.toFixed(2)}`,t.appendChild(r)}document.getElementById("orderDetailTotal").innerText="$"+e.getIngredientCost().toFixed(2),document.querySelector("#orderTotalPrice p").innerText="$"+e.getTotalCost().toFixed(2)},remove:function(e){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/order/"+e.id,{method:"DELETE",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.removeOrder(e),controller.openStrand("orders",merchant.orders),banner.createNotification("ORDER REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var p={display:function(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-30),i=document.getElementById("orderFilterIngredients");for(document.getElementById("orderFilterDateFrom").valueAsDate=n,document.getElementById("orderFilterDateTo").valueAsDate=t;i.children.length>0;)i.removeChild(i.firstChild);for(let r=0;r<merchant.ingredients.length;r++){let e=document.createElement("div");e.classList.add("choosable"),e.ingredient=merchant.ingredients[r].ingredient.id,e.onclick=()=>{this.toggleActive(e)},i.appendChild(e);let t=document.createElement("p");t.innerText=merchant.ingredients[r].ingredient.name,e.appendChild(t)}document.getElementById("orderFilterSubmit").onclick=()=>{this.submit(e)}},toggleActive:function(e){e.classList.contains("active")?e.classList.remove("active"):e.classList.add("active")},submit:function(e){let t={startDate:document.getElementById("orderFilterDateFrom").valueAsDate,endDate:document.getElementById("orderFilterDateTo").valueAsDate,ingredients:[]};if(t.startDate>=t.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let n=document.getElementById("orderFilterIngredients").children;for(let r=0;r<n.length;r++)n[r].classList.contains("active")&&t.ingredients.push(n[r].ingredient);if(0===t.ingredients.length)for(let r=0;r<merchant.ingredients.length;r++)t.ingredients.push(merchant.ingredients[r].ingredient.id);let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/order",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{let n=[];if("string"==typeof t)banner.createError(t);else if(0===t.length)banner.createError("NO ORDERS MATCH YOUR SEARCH");else for(let i=0;i<t.length;i++)n.push(new e(t[i]._id,t[i].name,t[i].date,t[i].taxes,t[i].fees,t[i].ingredients,merchant));controller.openStrand("orders",n)}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE ORDERS")}).finally(()=>{i.style.display="none"})}};var m={display:function(e){document.getElementById("editRecipeBtn").onclick=()=>{controller.openSidebar("editRecipe",e)},document.getElementById("recipeName").innerText=e.name,"none"===merchant.pos&&(document.getElementById("removeRecipeBtn").onclick=()=>{this.remove(e)});let t=document.getElementById("recipeIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("recipeIngredient").content.children[0];for(let i=0;i<e.ingredients.length;i++){let r=n.cloneNode(!0);r.children[0].innerText=e.ingredients[i].ingredient.name,r.children[1].innerText=""+e.ingredients[i].getQuantityDisplay(),r.onclick=()=>{controller.openStrand("ingredients"),controller.openSidebar("ingredientDetails",merchant.getIngredient(e.ingredients[i].ingredient.id))},t.appendChild(r)}document.getElementById("recipePrice").children[1].innerText="$"+e.price.toFixed(2)},remove:function(e){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/recipe/remove/"+e.id,{method:"delete"}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.removeRecipe(e),banner.createNotification("RECIPE REMOVED"),controller.openStrand("recipeBook"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var y={transaction:{},display:function(e){this.transaction=e;let t=document.getElementById("transactionRecipes"),n=document.getElementById("transactionRecipe").content.children[0],i=0,r=0;for(;t.children.length>0;)t.removeChild(t.firstChild);for(let a=0;a<e.recipes.length;a++){let s=n.cloneNode(!0),d=e.recipes[a].quantity*e.recipes[a].recipe.price;s.children[0].innerText=e.recipes[a].recipe.name,s.children[1].innerText=`${e.recipes[a].quantity} x $${e.recipes[a].recipe.price.toFixed(2)}`,s.children[2].innerText="$"+d.toFixed(2),s.onclick=()=>{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",e.recipes[a].recipe)},t.appendChild(s),i+=e.recipes[a].quantity,r+=d}let s=`${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e.date.getDay()]}, ${["January","February","March","April","May","June","July","August","September","October","November","December"][e.date.getMonth()]} ${e.date.getDate()}, ${e.date.getFullYear()}`;document.getElementById("transactionDate").innerText=s,document.getElementById("transactionTime").innerText=e.date.toLocaleTimeString(),document.getElementById("totalRecipes").innerText=i+" recipes",document.getElementById("totalPrice").innerText="$"+r.toFixed(2),"none"===merchant.pos&&(document.getElementById("removeTransBtn").onclick=()=>{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=>{"string"==typeof e?banner.createError(e):(merchant.removeTransaction(this.transaction),controller.openStrand("transactions",merchant.getTransactions()),banner.createNotification("TRANSACTION REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}};var E={display:function(){let e=new Date,t=new Date(e);t.setMonth(e.getMonth()-1),document.getElementById("transFilterDateStart").valueAsDate=t,document.getElementById("transFilterDateEnd").valueAsDate=e;let n=document.getElementById("transFilterRecipeList");for(;n.children.length>0;)n.removeChild(n.firstChild);for(let i=0;i<merchant.recipes.length;i++){let e=document.createElement("div");e.innerText=merchant.recipes[i].name,e.recipe=merchant.recipes[i],e.classList.add("choosable"),e.onclick=()=>{this.toggleActive(e)},n.appendChild(e)}document.getElementById("transFilterSubmit").onclick=()=>{this.submit()}},toggleActive:function(e){e.classList.contains("active")?e.classList.remove("active"):e.classList.add("active")},submit:function(){let e={startDate:document.getElementById("transFilterDateStart").valueAsDate,endDate:document.getElementById("transFilterDateEnd").valueAsDate,recipes:[]};if(e.startDate>=e.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let t=document.getElementById("transFilterRecipeList").children;for(let i=0;i<t.length;i++)t[i].classList.contains("active")&&e.recipes.push(t[i].recipe.id);if(0===e.recipes.length)for(let i=0;i<merchant.recipes.length;i++)e.recipes.push(merchant.recipes[i].id);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/transaction",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(e)}).then(e=>e.json()).then(e=>{let t=[];if("string"==typeof e)banner.createError(e);else if(0===e.length)banner.createError("NO TRANSACTIONS MATCH YOUR SEARCH");else for(let n=0;n<e.length;n++)t.push(new Transaction(e[n]._id,e[n].date,e[n].recipes,merchant));controller.openStrand("transactions",t)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})}};class f{constructor(e,t,n){if(t<0)return!1;this._ingredient=e,this._quantity=t,this._pricePerUnit=n}get ingredient(){return this._ingredient}get quantity(){if("bottle"===this._ingredient.specialUnit)return this._quantity/this._ingredient.unitSize;switch(this._ingredient.unit){case"g":return this._quantity;case"kg":return this._quantity/1e3;case"oz":return this._quantity/28.3495;case"lb":return this._quantity/453.5924;case"ml":return 1e3*this._quantity;case"l":return this._quantity;case"tsp":return 202.8842*this._quantity;case"tbsp":return 67.6278*this._quantity;case"ozfl":return 33.8141*this._quantity;case"cup":return 4.1667*this._quantity;case"pt":return 2.1134*this._quantity;case"qt":return 1.0567*this._quantity;case"gal":return this._quantity/3.7854;case"mm":return 1e3*this._quantity;case"cm":return 100*this._quantity;case"m":return this._quantity;case"in":return 39.3701*this._quantity;case"ft":return 3.2808*this._quantity;default:return this._quantity}}updateQuantity(e){if(e<0)return!1;this._quantity+=this.convertToBase(e)}convertToBase(e){switch(this._ingredient.unit){case"g":return e;case"kg":return 1e3*e;case"oz":return 28.3495*e;case"lb":return 453.5924*e;case"ml":return e/1e3;case"l":return e;case"tsp":return e/202.8842;case"tbsp":return e/67.6278;case"ozfl":return e/33.8141;case"cup":return e/4.1667;case"pt":return e/2.1134;case"qt":return e/1.0567;case"gal":return 3.7854*e;case"mm":return e/1e3;case"cm":return e/100;case"m":return e;case"in":return e/39.3701;case"ft":return e/3.2808;default:return e}}get pricePerUnit(){if("bottle"===this._ingredient.specialUnit)return this._pricePerUnit*this._ingredient.unitSize/100;switch(this._ingredient.unit){case"g":return this._pricePerUnit/100;case"kg":return 1e3*this._pricePerUnit/100;case"oz":return 28.3495*this._pricePerUnit/100;case"lb":return 453.5924*this._pricePerUnit/100;case"ml":return this._pricePerUnit/1e3/100;case"l":return this._pricePerUnit/100;case"tsp":return this._pricePerUnit/202.8842/100;case"tbsp":return this._pricePerUnit/67.6278/100;case"ozfl":return this._pricePerUnit/33.8141/100;case"cup":return this._pricePerUnit/4.1667/100;case"pt":return this._pricePerUnit/2.1134/100;case"qt":return this._pricePerUnit/1.0567/100;case"gal":return 3.7854*this._pricePerUnit/100;case"mm":return this._pricePerUnit/1e3/100;case"cm":return this._pricePerUnit/100/100;case"m":return this._pricePerUnit/100;case"in":return this._pricePerUnit/39.3701/100;case"ft":return this._pricePerUnit/3.2808/100}}cost(){return this._quantity*this._pricePerUnit/100}}var I=class{constructor(e,t,n,i,r,s,a){if(i<0)return!1;if(this._id=e,this._name=t,this._date=new Date(n),this._taxes=i,this._fees=r,this._ingredients=[],this._parent=a,n>new Date)return!1;for(let d=0;d<s.length;d++)for(let e=0;e<merchant.ingredients.length;e++)if(merchant.ingredients[e].ingredient.id===s[d].ingredient){this._ingredients.push(new f(merchant.ingredients[e].ingredient,s[d].quantity,s[d].pricePerUnit));break}this._parent.modules.ingredients.isPopulated=!1}get id(){return this._id}get name(){return this._name}get date(){return this._date}get taxes(){return this._taxes/100}get fees(){return this._fees/100}get parent(){return this._parent}get ingredients(){return this._ingredients}getIngredientCost(){let e=0;for(let t=0;t<this._ingredients.length;t++)e+=this._ingredients[t].cost();return e}getTotalCost(){return this.getIngredientCost()+this.taxes+this.fees}};class T{constructor(e,t){if(t<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;this._ingredient=e,this._quantity=t}get ingredient(){return this._ingredient}get quantity(){if("bottle"===this._ingredient.specialUnit)return this._quantity/this._ingredient.unitSize;switch(this._ingredient.unit){case"g":return this._quantity;case"kg":return this._quantity/1e3;case"oz":return this._quantity/28.3495;case"lb":return this._quantity/453.5924;case"ml":return 1e3*this._quantity;case"l":return this._quantity;case"tsp":return 202.8842*this._quantity;case"tbsp":return 67.6278*this._quantity;case"ozfl":return 33.8141*this._quantity;case"cup":return 4.1667*this._quantity;case"pt":return 2.1134*this._quantity;case"qt":return 1.0567*this._quantity;case"gal":return this._quantity/3.7854;case"mm":return 1e3*this._quantity;case"cm":return 100*this._quantity;case"m":return this._quantity;case"in":return 39.3701*this._quantity;case"ft":return 3.2808*this._quantity;default:return this._quantity}}set quantity(e){if(e<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;this_quantity=this.convertToBase(e)}getQuantityDisplay(){return"bottle"===this._ingredient.specialUnit?this.quantity.toFixed(2)+" BOTTLES":`${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`}convertToBase(e){switch(this._ingredient.unit){case"g":return e;case"kg":return 1e3*e;case"oz":return 28.3495*e;case"lb":return 453.5924*e;case"ml":return e/1e3;case"l":return e;case"tsp":return e/202.8842;case"tbsp":return e/67.6278;case"ozfl":return e/33.8141;case"cup":return e/4.1667;case"pt":return e/2.1134;case"qt":return e/1.0567;case"gal":return 3.7854*e;case"mm":return e/1e3;case"cm":return e/100;case"m":return e;case"in":return e/39.3701;case"ft":return e/3.2808;default:return e}}}var B=class{constructor(e,t,n,i,r){if(n<0)return banner.createError("PRICE CANNOT BE A NEGATIVE NUMBER"),!1;if(!this.isSanitaryString(t))return banner.createError("NAME CONTAINS ILLEGAL CHARACTERS"),!1;this._id=e,this._name=t,this._price=n,this._parent=r,this._ingredients=[];for(let s=0;s<i.length;s++){const e=r.getIngredient(i[s].ingredient),t=new T(e.ingredient,i[s].quantity);this._ingredients.push(t)}}get id(){return this._id}get name(){return this._name}set name(e){if(!this.isSanitaryString(e))return!1;this._name=e}get price(){return this._price/100}set price(e){if(e<0)return!1;this._price=e}get parent(){return this._parent}get ingredients(){return this._ingredients}addIngredient(e,t){if(t<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;let n=new T(e,t);this._ingredients.push(n),this._parent.modules.recipeBook.isPopulated=!1,this._parent.modules.analytics.isPopulated=!1}removeIngredients(){this._ingredients=[]}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}};class _{constructor(e,t){return t<0?(banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1):t%1!=0?(banner.createError("RECIPES WITHIN A TRANSACTION MUST BE WHOLE NUMBERS"),!1):(this._recipe=e,void(this._quantity=t))}get recipe(){return this._recipe}get quantity(){return this._quantity}}var S=class{constructor(e,t,n,i){if((t=new Date(t))>new Date)return banner.createError("DATE CANNOT BE SET TO THE FUTURE"),!1;this._id=e,this._parent=i,this._date=t,this._recipes=[];for(let r=0;r<n.length;r++)for(let e=0;e<i.recipes.length;e++)if(n[r].recipe===i.recipes[e].id){const t=new _(i.recipes[e],n[r].quantity);this._recipes.push(t);break}}get id(){return this._id}get parent(){return this._parent}get date(){return this._date}get recipes(){return this._recipes}getIngredientQuantity(e){let t=0;for(let n=0;n<this._recipes.length;n++){const i=this._recipes[n].recipe;for(let n=0;n<i.ingredients.length;n++)i.ingredients[n].ingredient===e&&(t+=i.ingredients[n].quantity)}return t}};class b{constructor(e,t){this._quantity=t,this._ingredient=e}get ingredient(){return this._ingredient}get quantity(){if("bottle"===this._ingredient.specialUnit)return this._quantity/this._ingredient._unitSize;switch(this._ingredient.unit){case"g":return this._quantity;case"kg":return this._quantity/1e3;case"oz":return this._quantity/28.3495;case"lb":return this._quantity/453.5924;case"ml":return 1e3*this._quantity;case"l":return this._quantity;case"tsp":return 202.8842*this._quantity;case"tbsp":return 67.6278*this._quantity;case"ozfl":return 33.8141*this._quantity;case"cup":return 4.1667*this._quantity;case"pt":return 2.1134*this._quantity;case"qt":return 1.0567*this._quantity;case"gal":return this._quantity/3.7854;case"mm":return 1e3*this._quantity;case"cm":return 100*this._quantity;case"m":return this._quantity;case"in":return 39.3701*this._quantity;case"ft":return 3.2808*this._quantity;default:return this._quantity}}updateQuantity(e){this._quantity+=this.convertToBase(e)}convertToBase(e){switch(this._ingredient.unit){case"g":return e;case"kg":return 1e3*e;case"oz":return 28.3495*e;case"lb":return 453.5924*e;case"ml":return e/1e3;case"l":return e;case"tsp":return e/202.8842;case"tbsp":return e/67.6278;case"ozfl":return e/33.8141;case"cup":return e/4.1667;case"pt":return e/2.1134;case"qt":return e/1.0567;case"gal":return 3.7854*e;case"mm":return e/1e3;case"cm":return e/100;case"m":return e;case"in":return e/39.3701;case"ft":return e/3.2808;default:return e}}getQuantityDisplay(){return"bottle"===this._ingredient.specialUnit?this.quantity.toFixed(2)+" BOTTLES":`${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`}}var v=class{constructor(e,t,n,i,r,s,a,d){return this.isSanitaryString(t)?this.isSanitaryString(n)?(this._id=e,this._name=t,this._category=n,this._unitType=i,this._unit=r,this._parent=s,void(a&&(this._specialUnit=a,this._unitSize=d))):(banner.createError("CATEGORY CONTAINS ILLEGAL CHARACTERS"),!1):(banner.createError("NAME CONTAINS ILLEGAL CHARCTERS"),!1)}get id(){return this._id}get name(){return this._name}set name(e){if(!this.isSanitaryString(e))return!1;this._name=e}get category(){return this._category}set category(e){if(!this.isSanitaryString(e))return!1;this._category=e}get unitType(){return this._unitType}get unit(){return this._unit}set unit(e){this._unit=e}get parent(){return this._parent}get specialUnit(){return this._specialUnit}get unitSize(){switch(this._unit){case"g":return this._unitSize;case"kg":return this._unitSize/1e3;case"oz":return this._unitSize/28.3495;case"lb":return this._unitSize/453.5924;case"ml":return 1e3*this._unitSize;case"l":return this._unitSize;case"tsp":return 202.8842*this._unitSize;case"tbsp":return 67.6278*this._unitSize;case"ozfl":return 33.8141*this._unitSize;case"cup":return 4.1667*this._unitSize;case"pt":return 2.1134*this._unitSize;case"qt":return 1.0567*this._unitSize;case"gal":return this._unitSize/3.7854;case"mm":return 1e3*this._unitSize;case"cm":return 100*this._unitSize;case"m":return this._unitSize;case"in":return 39.3701*this._unitSize;case"ft":return 3.2808*this._unitSize;default:return this._unitSize}}set unitSize(e){if(e<0)return!1;this._unitSize=e}getNameAndUnit(){return"bottle"===this._specialUnit?this._name+" (BOTTLES)":`${this._name} (${this._unit.toUpperCase()})`}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}};merchant=new class{constructor(e,t,n){this._modules=n,this._name=e.name,this._pos=e.pos,this._ingredients=[],this._recipes=[],this._transactions=[],this._orders=[],this._units={mass:["g","kg","oz","lb"],volume:["ml","l","tsp","tbsp","ozfl","cup","pt","qt","gal"],length:["mm","cm","m","in","ft"],other:["each","bottle"]};for(let i=0;i<e.inventory.length;i++){const t=new n.Ingredient(e.inventory[i].ingredient._id,e.inventory[i].ingredient.name,e.inventory[i].ingredient.category,e.inventory[i].ingredient.unitType,e.inventory[i].defaultUnit,this,e.inventory[i].ingredient.specialUnit,e.inventory[i].ingredient.unitSize),r=new b(t,e.inventory[i].quantity);this._ingredients.push(r)}for(let i=0;i<e.recipes.length;i++){let t=[];for(let n=0;n<e.recipes[i].ingredients.length;n++){const r=e.recipes[i].ingredients[n];for(let e=0;e<this._ingredients.length;e++)if(r.ingredient===this._ingredients[e].ingredient.id){t.push({ingredient:this._ingredients[e].ingredient.id,quantity:r.quantity});break}}this._recipes.push(new this._modules.Recipe(e.recipes[i]._id,e.recipes[i].name,e.recipes[i].price,t,this))}for(let i=0;i<t.length;i++)this._transactions.push(new n.Transaction(t[i]._id,t[i].date,t[i].recipes,this))}get modules(){return this._modules}get name(){return this._name}set name(e){return this.isSanitaryString(e)&&(this._name=e),!1}get pos(){return this._pos}get ingredients(){return this._ingredients}addIngredient(e,t,n){const i=new this._modules.Ingredient(e._id,e.name,e.category,e.unitType,n,this,e.specialUnit,e.unitSize),r=new b(i,t);this._ingredients.push(r),this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1}removeIngredient(e){const t=this._ingredients.indexOf(e);if(void 0===t)return!1;this._ingredients.splice(t,1),this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1}getIngredient(e){for(let t=0;t<this._ingredients.length;t++)if(this._ingredients[t].ingredient.id===e)return this._ingredients[t]}get recipes(){return this._recipes}addRecipe(e,t,n,i){let r=new B(e,t,n,i,this);this._recipes.push(r),this._modules.recipeBook.isPopulated=!1}removeRecipe(e){const t=this._recipes.indexOf(e);if(void 0===t)return!1;this._recipes.splice(t,1),this._modules.recipeBook.isPopulated=!1}updateRecipe(e){for(let t=0;t<this._recipes.length;t++)if(this._recipes[t].id===e._id){this._recipes[t].name=e.name,this._recipes[t].price=e.price,this._recipes[t].removeIngredients();for(let n=0;n<e.ingredients.length;n++)for(let i=0;i<this._ingredients.length;i++)if(this._ingredients[i].ingredient.id===e.ingredients[n].ingredient){this._recipes[t].addIngredient(this._ingredients[i].ingredient,e.ingredients[n].quantity);break}break}this._modules.recipeBook.isPopulated=!1}get transactions(){return this._transactions}getTransactions(e=0,t=new Date){if(merchant._transactions.length<=0)return[];0===e&&(e=this._transactions[this._transactions.length-1].date);const{start:n,end:i}=this.getTransactionIndices(e,t);return this._transactions.slice(n,i+1)}addTransaction(e){e=new S(e._id,e.date,e.recipes,this),this._transactions.push(e),this._transactions.sort((e,t)=>e.date>t.date?-1:1);let t={};for(let i=0;i<e.recipes.length;i++){const n=e.recipes[i];for(let e=0;e<n.recipe.ingredients.length;e++){const i=n.recipe.ingredients[e];t[i.ingredient.id]?t[i.ingredient.id]+=n.quantity*i.quantity:t[i.ingredient.id]=n.quantity*i.quantity}}const n=Object.keys(t);for(let i=0;i<n.length;i++)for(let e=0;e<this._ingredients.length;e++)n[i]===this._ingredients[e].ingredient.id&&this._ingredients[e].updateQuantity(-t[n[i]]);this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1,this._modules.analytics.newData=!0}removeTransaction(e){const t=this._transactions.indexOf(e);if(void 0===t)return!1;this._transactions.splice(t,1);let n={};for(let r=0;r<e.recipes.length;r++){const t=e.recipes[r];for(let e=0;e<t.recipe.ingredients.length;e++){const i=t.recipe.ingredients[e];n[i.ingredient.id]?n[i.ingredient.id]+=i.quantity*t.quantity:n[i.ingredient.id]=i.quantity*t.quantity}}const i=Object.keys(n);for(let r=0;r<i.length;r++)for(let e=0;e<this._ingredients.length;e++)if(i[r]===this._ingredients[e].ingredient.id){this._ingredients[e].updateQuantity(n[i[r]]);break}this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1,this._modules.analytics.newData=!0}get orders(){return this._orders}addOrder(e,t=!1){let n=new I(e._id,e.name,e.date,e.taxes,e.fees,e.ingredients,this);if(this._orders.push(n),t)for(let i=0;i<n.ingredients.length;i++)for(let e=0;e<this._ingredients.length;e++)if(n.ingredients[i].ingredient===this._ingredients[e].ingredient){this._ingredients[e].updateQuantity(n.ingredients[i].quantity);break}this._modules.ingredients.isPopulated=!1,this._modules.orders.isPopulated=!1}setOrders(e){this._orders=e}removeOrder(e){const t=this._orders.indexOf(e);if(void 0===t)return!1;this._orders.splice(t,1);for(let n=0;n<e.ingredients.length;n++)for(let t=0;t<this._ingredients.length;t++)if(e.ingredients[n].ingredient===this._ingredients[t].ingredient){this._ingredients[t].updateQuantity(-e.ingredients[n].quantity);break}this._modules.ingredients.isPopulated=!1,this._modules.orders.isPopulated=!1}get units(){return this._units}getRevenue(e,t=new Date){0===e&&(e=this._transactions[0].date);const{start:n,end:i}=this.getTransactionIndices(e,t);let r=0;for(let s=n;s<=i;s++)for(let e=0;e<this._transactions[s].recipes.length;e++)for(let t=0;t<this.recipes.length;t++)this._transactions[s].recipes[e].recipe===this.recipes[t]&&(r+=this._transactions[s].recipes[e].quantity*this.recipes[t].price);return r/100}getIngredientsSold(e=0,t=new Date){(e=0)&&(e=this._ingredients[0].date);let n=this.getRecipesSold(e,t),i=[];for(let r=0;r<n.length;r++)for(let e=0;e<n[r].recipe.ingredients.length;e++){let t=!1;for(let s=0;s<i.length;s++)i[s].ingredient===n[r].recipe.ingredients[e].ingredient&&(t=!0,i[s].quantity+=n[r].quantity*n[r].recipe.ingredients[e].quantity);t||i.push({ingredient:n[r].recipe.ingredients[e].ingredient,quantity:n[r].quantity*n[r].recipe.ingredients[e].quantity})}return i}getSingleIngredientSold(e,t=0,n=new Date){0===t&&(t=this._transactions[0].date);const{start:i,end:r}=this.getTransactionIndices(t,n);let s=0;for(let a=i;a<r;a++)for(let t=0;t<this._transactions[a].recipes.length;t++)for(let n=0;n<this._transactions[a].recipes[t].recipe.ingredients.length;n++)if(this._transactions[a].recipes[t].recipe.ingredients[n].ingredient===e.ingredient){s+=this._transactions[a].recipes[t].recipe.ingredients[n].quantity;break}return s}getRecipesSold(e=0,t=new Date){(e=0)&&(e=this._transactions[0].date);const{start:n,end:i}=this.getTransactionIndices(e,t);let r=[];for(let s=n;s<=i;s++)for(let e=0;e<this._transactions[s].recipes.length;e++){let t=!1;for(let n=0;n<r.length;n++)if(r[n].recipe===this._transactions[s].recipes[e].recipe){t=!0,r[n].quantity+=this._transactions[s].recipes[e].quantity;break}t||r.push({recipe:this._transactions[s].recipes[e].recipe,quantity:this._transactions[s].recipes[e].quantity})}return r}categorizeIngredients(){let e=[];for(let t=0;t<this.ingredients.length;t++){let n=!1;for(let i=0;i<e.length;i++)if(this.ingredients[t].ingredient.category===e[i].name){e[i].ingredients.push(this.ingredients[t]),n=!0;break}n||e.push({name:this.ingredients[t].ingredient.category,ingredients:[this.ingredients[t]]})}return e}unitizeIngredients(){let e=[];for(let t=0;t<this.ingredients.length;t++){let n=!1;const i=this.ingredients[t].ingredient;for(let r=0;r<e.length;r++)if(i.unit===e[r].name||i.specialUnit===e[r].name){e[r].ingredients.push(this.ingredients[t]),n=!0;break}if(!n){let n="";n="bottle"===i.specialUnit?"bottle":i.unit,e.push({name:n,ingredients:[this.ingredients[t]]})}}return e}getRecipesForIngredient(e){let t=[];for(let n=0;n<this._recipes.length;n++)for(let i=0;i<this._recipes[n].ingredients.length;i++)if(this._recipes[n].ingredients[i].ingredient===e){t.push(this._recipes[n]);break}return t}getTransactionIndices(e,t){let n,i;t.setDate(t.getDate()+1);for(let r=this._transactions.length-1;r>=0;r--)if(this._transactions[r].date>=e){n=r;break}for(let r=0;r<this._transactions.length;r++)if(this._transactions[r].date<t){i=r;break}return void 0!==n&&{start:i,end:n}}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}}(data.merchant,data.transactions,{home:e,ingredients:t,transactions:s,recipeBook:n,analytics:i,orders:r,Ingredient:v,Recipe:B,Transaction:S}),controller={openStrand:function(a,d){this.closeSidebar();let l=document.querySelectorAll(".strand");for(let e=0;e<l.length;e++)l[e].style.display="none";let c=document.querySelectorAll(".menuButton");for(let e=0;e<c.length-1;e++)c[e].classList="menuButton",c[e].disabled=!1;let o={};switch(a){case"home":o=document.getElementById("homeBtn"),document.getElementById("homeStrand").style.display="flex",e.display();break;case"ingredients":o=document.getElementById("ingredientsBtn"),document.getElementById("ingredientsStrand").style.display="flex",t.display();break;case"recipeBook":o=document.getElementById("recipeBookBtn"),document.getElementById("recipeBookStrand").style.display="flex",n.display(B);break;case"analytics":o=document.getElementById("analyticsBtn"),document.getElementById("analyticsStrand").style.display="flex",i.display(S);break;case"orders":o=document.getElementById("ordersBtn"),document.getElementById("ordersStrand").style.display="flex",r.orders=d,r.display(I);break;case"transactions":o=document.getElementById("transactionsBtn"),document.getElementById("transactionsStrand").style.display="flex",s.transactions=d,s.display(S)}o.classList="menuButton active",o.disabled=!0,window.screen.availWidth<=1e3&&this.closeMenu()},openSidebar:function(e,n={}){switch(this.closeSidebar(),document.getElementById("sidebarDiv").classList="sidebar",document.getElementById(e).style.display="flex",e){case"ingredientDetails":a.display(n,t);break;case"newIngredient":d.display(v);break;case"editIngredient":l.display(n);break;case"recipeDetails":m.display(n);break;case"editRecipe":h.display(n);break;case"addRecipe":o.display(B);break;case"orderDetails":g.display(n);break;case"orderFilter":p.display(I);break;case"newOrder":c.display(I);break;case"transactionDetails":y.display(n);break;case"transactionFilter":E.display();break;case"newTransaction":u.display(S)}window.screen.availWidth<=1e3&&(document.querySelector(".contentBlock").style.display="none",document.getElementById("mobileMenuSelector").style.display="none",document.getElementById("sidebarCloser").style.display="block")},closeSidebar:function(){let e=document.getElementById("sidebarDiv");for(let t=0;t<e.children.length;t++)if("none"!==e.children[t].style.display){e.children[t].style.display="none";let n=[];switch(e.children[t].id){case"ingredientDetails":n=document.querySelectorAll(".ingredient");break;case"transactionDetails":n=document.getElementById("transactionsList").children;break;case"recipeDetails":n=document.getElementById("recipeList").children;break;case"orderDetails":n=document.getElementById("orderList").children}for(let e=0;e<n.length;e++)n[e].classList.remove("active")}e.classList="sidebarHide",window.screen.availWidth<=1e3&&(document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").style.display="block",document.getElementById("sidebarCloser").style.display="none")},openModal:function(e){document.getElementById("modal").style.display="flex",document.getElementById("modalClose").addEventListener("click",this.closeModal);let t={};switch(e){case"ingredientSpreadsheet":(t=document.getElementById("modalSpreadsheetUpload")).style.display="flex",document.getElementById("modalSpreadsheetTitle").innerText="ingredients",document.getElementById("spreadsheetDownload").href="/ingredients/download/spreadsheet",t.onsubmit=d.submitSpreadsheet;break;case"recipeSpreadsheet":(t=document.getElementById("modalSpreadsheetUpload")).style.display="flex",document.getElementById("modalSpreadsheetTitle").innerText="recipes",document.getElementById("spreadsheetDownload").href="/recipes/download/spreadsheet",t.onsubmit=o.submitSpreadsheet;break;case"orderSpreadsheet":(t=document.getElementById("modalSpreadsheetUpload")).style.display="flex",document.getElementById("modalSpreadsheetTitle").innerText="orders",document.getElementById("spreadsheetDownload").href="/orders/download/spreadsheet",t.onsubmit=c.submitSpreadsheet;break;case"transactionSpreadsheet":(t=document.getElementById("modalSpreadsheetUpload")).style.display="flex",document.getElementById("modalSpreadsheetTitle").innerText="transactions",document.getElementById("spreadsheetDownload").href="/transactions/download/spreadsheet",t.onsubmit=u.submitSpreadsheet}},closeModal:function(){let e=document.getElementById("modal"),t=document.getElementById("modalContent");for(let n=0;n<t.children.length;n++)t.children[n].style.display="none";e.style.display="none"},changeMenu:function(){let e=document.querySelector(".menu"),t=document.querySelectorAll(".menuButton");if(e.classList.contains("menuMinimized")){if(e.classList.contains("menuMinimized")){e.classList="menu";for(let e=0;e<t.length;e++)t[e].children[1].style.display="block";setTimeout(()=>{document.getElementById("max").style.display="flex",document.getElementById("min").style.display="none"},150)}}else{e.classList="menu menuMinimized";for(let e=0;e<t.length;e++)t[e].children[1].style.display="none";document.getElementById("max").style.display="none",document.getElementById("min").style.display="flex"}},openMenu:function(){document.getElementById("menu").style.display="flex",document.querySelector(".contentBlock").style.display="none",document.getElementById("mobileMenuSelector").onclick=()=>{this.closeMenu()}},closeMenu:function(){document.getElementById("menu").style.display="none",document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").onclick=()=>{this.openMenu()}},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"),document.getElementById("homeBtn").onclick=()=>{controller.openStrand("home")},document.getElementById("ingredientsBtn").onclick=()=>{controller.openStrand("ingredients")},document.getElementById("recipeBookBtn").onclick=()=>{controller.openStrand("recipeBook")},document.getElementById("analyticsBtn").onclick=()=>{controller.openStrand("analytics")},document.getElementById("ordersBtn").onclick=async()=>{0===merchant.orders.length&&merchant.setOrders(await r.getOrders(I)),controller.openStrand("orders",merchant.orders)},document.getElementById("transactionsBtn").onclick=()=>{controller.openStrand("transactions",merchant.getTransactions())},controller.openStrand("home")}();
|