!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;d0;)n.removeChild(n.firstChild);for(let r=0;r{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.quantityt.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=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{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{this.toggleCategory(s.children[1],s.children[0].children[1])},s.children[1].style.display="none",t.appendChild(s);for(let t=0;t{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.style.display="flex"):"flex"===e.style.display&&(t.innerHTML='',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.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{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;i0;)t.removeChild(t.firstChild);for(let i=0;ie.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{for(let n=0;n{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{this.ingredient=merchant.ingredients[n].ingredient,this.displayIngredient()},e.appendChild(t)}for(let n=0;n{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{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;oa&&(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{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{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{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{controller.openSidebar("transactionDetails",s),r.classList.add("active")},t.appendChild(r);let a=0,d=0;for(let t=0;t{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;c0;)a.removeChild(a.firstChild);for(let c=0;c{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",l[c])},e.classList.add("choosable"),a.appendChild(e)}},remove:function(e){for(let n=0;ne.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{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{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;ne.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{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;de.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{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;te.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{let t=[];for(let n=0;n{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{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{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;ie.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{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 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{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{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{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;re.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{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{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{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{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;ie.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{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","$","{","}","(",")"];for(let n=0;nnew 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","$","{","}","(",")"];for(let n=0;ne.date>t.date?-1:1);let t={};for(let i=0;i=0;r--)if(this._transactions[r].date>=e){n=r;break}for(let r=0;r","$","{","}","(",")"];for(let n=0;n{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()}},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")}();