!function(){var e,t,n=(e=function(e,t){e.exports={LineGraph:class{constructor(e){this.canvas=e,this.context=e.getContext("2d"),this.left=e.clientWidth-.95*e.clientWidth,this.right=1*e.clientWidth,this.top=e.clientHeight-1*e.clientHeight,this.bottom=.85*e.clientHeight,this.data=[],this.max=0,this.xRange=[],this.colors=[],this.colorIndex=0;for(let t=0;t<100;t++){let e=Math.floor(200*Math.random()),t=Math.floor(200*Math.random()),n=Math.floor(200*Math.random());this.colors.push(`rgb(${e}, ${t}, ${n})`)}}addData(e,t,n){e={set:e,colorIndex:this.colorIndex,name:n},this.colorIndex++,this.data.push(e);let i=!1;for(let r=0;rthis.max&&(this.max=e.set[r],this.verticalMultiplier=(this.bottom-this.top)/this.max,this.horizontalMultiplier=(this.right-this.left)/(e.set.length-1),i=!0);0===this.xRange.length?(this.xRange=t,i=!0):(t[0]this.xRange[1]&&(this.xRange[1]=t[1],i=!0)),i?this.drawGraph():this.drawLine(e)}removeData(e){for(let t=0;t1&&this.drawLegend(e.colorIndex,e.name)}drawXAxis(){if(this.context.beginPath(),this.context.moveTo(this.left,this.bottom),this.context.lineTo(this.right,this.bottom),this.context.lineWidth=4,this.context.stroke(),this.context.setLineDash([5,10]),this.context.font="10px Arial",this.context.lineWidth=1,"[object Date]"===Object.prototype.toString.call(this.xRange[0])){let e=Math.abs(Math.floor((Date.UTC(this.xRange[0].getFullYear(),this.xRange[0].getMonth(),this.xRange[0].getDate())-Date.UTC(this.xRange[1].getFullYear(),this.xRange[1].getMonth(),this.xRange[1].getDate()))/864e5))+1,t=new Date(this.xRange[0]);for(let n=0;nthis.max&&(this.max=e[t].num),this.data.push(e[t]);this.drawGraph()}drawGraph(){let e=(this.bottom-this.top)/this.data.length-2;for(let t=0;t=this.max?this.context.fillStyle="rgb(255, 99, 107)":this.context.fillStyle="rgb(179, 191, 209)",this.context.beginPath(),this.context.fillRect(this.left,n,i,e-5),this.context.stroke();let r=15;this.context.font="12px Saira",this.context.fillStyle="black",this.context.fillText(this.data[t].label,r,this.top+t*e+e/1.5)}}}}},function(n){return t||e(t={exports:{},parent:n},t.exports),t.exports});var i={isPopulated:!1,graph:{},display:function(){this.isPopulated||(this.drawRevenueCard(),this.drawRevenueGraph(),this.drawInventoryCheckCard(),this.drawPopularCard(),this.isPopulated=!0)},drawRevenueCard:function(){let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),1),n=new Date(e.getFullYear(),e.getMonth()-1,1),i=new Date((new Date).setMonth(e.getMonth()-1)),r=merchant.revenue(merchant.transactionIndices(t)),l=merchant.revenue(merchant.transactionIndices(n,i));document.getElementById("revenue").innerText="$"+r.toLocaleString("en");let d=(r-l)/l*100,a="";a=d>=0?"/shared/images/upArrow.png":"/shared/images/downArrow.png",document.querySelector("#revenueChange p").innerText=Math.abs(d).toFixed(2)+"% vs last month",document.querySelector("#revenueChange img").src=a},drawRevenueGraph:function(){let e=document.getElementById("graphCanvas"),t=new Date;e.height=e.parentElement.clientHeight,e.width=e.parentElement.clientWidth;let i=n({}).LineGraph;this.graph=new i(e),this.graph.addTitle("Revenue");let r=new Date(t);r.setDate(t.getDate()-29);let l=merchant.graphDailyRevenue(merchant.transactionIndices(r));if(l)this.graph.addData(l,[r,new Date],"Revenue");else{document.getElementById("graphCanvas").style.display="none";let e=document.createElement("h1");e.innerText="NO DATA YET",e.classList="notice",document.getElementById("graphCard").appendChild(e)}},drawInventoryCheckCard:function(){let e;e=merchant.ingredients.length<5?merchant.ingredients.length:5;let t=[];for(let r=0;r0;)n.removeChild(n.firstChild);for(let r=0;r{l.value--},l.value=merchant.ingredients[t[r]].quantity.toFixed(2),e.children[1].children[2].onclick=()=>{l.value++},e.children[2].innerText=merchant.ingredients[t[r]].ingredient.unit.toUpperCase(),n.appendChild(e)}document.getElementById("inventoryCheck").onclick=()=>{this.submitInventoryCheck()}},drawPopularCard:function(){let e=[],t=new Date,i=new Date(t.getFullYear(),t.getMonth(),1),r=merchant.ingredientsSold(merchant.transactionIndices(i));if(!1!==r){window.ingredientList=[...r];let t=r.length<5?r.length:5;for(let n=0;nt&&(t=r[e].quantity,n=e);e.push({num:t,label:r[n].ingredient.name+": "+r[n].ingredient.convert(r[n].quantity).toFixed(2)+" "+r[n].ingredient.unit}),r.splice(n,1)}catch(l){break}let i=document.getElementById("popularCanvas");i.width=.8*i.parentElement.offsetWidth,i.height=.8*i.parentElement.offsetHeight,new(0,n({}).HorizontalBarGraph)(i).addData(e)}else{document.getElementById("popularCanvas").style.display="none";let e=document.createElement("p");e.innerText="N/A",e.classList="notice",document.getElementById("popularIngredientsCard").appendChild(e)}},submitInventoryCheck:function(){let e=document.querySelectorAll("#inventoryCheckCard li"),t=[],n=[];for(let r=0;r=0))return void banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");{let i=e[r].ingredient,l=parseFloat(e[r].children[1].children[1].value);l!==i.quantity&&(t.push({id:i.ingredient.id,ingredient:i.ingredient,quantity:l}),n.push({id:i.ingredient.id,quantity:l}))}}let i=document.getElementById("loaderContainer");i.style.display="flex",n.length>0&&fetch("/merchant/ingredients/update",{method:"PUT",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(n)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editIngredients(t),banner.createNotification("INGREDIENTS UPDATED"))}).catch(e=>{}).finally(()=>{i.style.display="none"})}};var r={isPopulated:!1,ingredients:[],display:function(){this.isPopulated||(this.populateByProperty("category"),document.getElementById("ingredientSearch").oninput=()=>{this.search()},document.getElementById("ingredientClearButton").onclick=()=>{this.clearSorting()},document.getElementById("ingredientSelect").onchange=()=>{this.sort()},this.isPopulated=!0)},populateByProperty:function(e){let t;"category"===e?t=merchant.categorizeIngredients():"unit"===e&&(t=merchant.unitizeIngredients());let n=document.getElementById("categoryList"),i=document.getElementById("categoryDiv").content.children[0],r=document.getElementById("ingredient").content.children[0];for(this.ingredients=[];n.children.length>0;)n.removeChild(n.firstChild);for(let l=0;l{this.toggleCategory(e.children[1],e.children[0].children[1])},e.children[1].style.display="none",n.appendChild(e);for(let n=0;n{controller.openSidebar("ingredientDetails",i)},d._name=i.ingredient.name.toLowerCase(),d._unit=i.ingredient.unit.toLowerCase(),e.children[1].appendChild(d),this.ingredients.push(d)}}},displayIngredientsOnly:function(e){let t=document.getElementById("categoryList");for(;t.children.length>0;)t.removeChild(t.firstChild);for(let n=0;n',e.style.display="flex"):"flex"===e.style.display&&(t.innerHTML='',e.style.display="none")},search:function(){let e=document.getElementById("ingredientSearch").value.toLowerCase();if(document.getElementById("ingredientSelect").selectedIndex=0,""===e)return this.populateByProperty("category"),void(document.getElementById("ingredientClearButton").style.display="none");let t=[];for(let n=0;nt[e]>n[e]?1:-1);this.displayIngredientsOnly(t)},clearSorting:function(e){document.getElementById("ingredientSearch").value="",document.getElementById("ingredientSelect").selectedIndex=0,document.getElementById("ingredientClearButton").style.display="none",this.populateByProperty("category")}};var l={isPopulated:!1,recipeDivList:[],display:function(e){this.isPopulated||(this.populateRecipes(),"none"!==merchant.pos&&(document.getElementById("posUpdateRecipe").onclick=()=>{this.posUpdate(e)}),document.getElementById("recipeSearch").oninput=()=>{this.search()},document.getElementById("recipeClearButton").onclick=()=>{this.clearSorting()},this.isPopulated=!0)},populateRecipes:function(){let e=document.getElementById("recipeList"),t=document.getElementById("recipe").content.children[0];for(this.recipeDivList=[];e.children.length>0;)e.removeChild(e.firstChild);for(let n=0;n{controller.openSidebar("recipeDetails",merchant.recipes[n])},i._name=merchant.recipes[n].name,e.appendChild(i),i.children[0].innerText=merchant.recipes[n].name,i.children[1].innerText="$"+(merchant.recipes[n].price/100).toFixed(2),this.recipeDivList.push(i)}},search:function(){let e=document.getElementById("recipeSearch").value.toLowerCase(),t=document.getElementById("recipeList"),n=document.getElementById("recipeClearButton"),i=[];for(let r=0;r0;)t.removeChild(t.firstChild);for(let r=0;re.json()).then(t=>{let n=[];for(let r=0;r0&&merchant.editRecipes(n);let i=[];for(let e=0;e0&&merchant.editRecipes(i,!0)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var d={isFetched:!1,display:async function(e){if(!this.isFetched){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/order",{method:"GET",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=[];for(let i=0;i{this.submitFilter(e)},this.isFetched=!0}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE")}).finally(()=>{t.style.display="none"})}},populate:function(){let e=document.getElementById("orderList"),t=document.getElementById("order").content.children[0],n=document.getElementById("dateDropdownOrder"),i=document.getElementById("ingredientDropdown");n.style.display="none",i.style.display="none",document.getElementById("dateFilterBtnOrder").onclick=()=>{this.toggleDropdown(n)},document.getElementById("ingredientFilterBtn").onclick=()=>{this.toggleDropdown(i)};for(let r=0;r0;)e.removeChild(e.firstChild);for(let r=0;r{controller.openSidebar("orderDetails",merchant.orders[r])},e.appendChild(n)}},submitFilter:function(){event.preventDefault();let e={startDate:document.getElementById("orderFilDate1").valueAsDate,endDate:document.getElementById("orderFilDate2").valueAsDate,ingredients:[]};if(e.startDate>=e.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let t=document.getElementById("ingredientDropdown");for(let i=0;ie.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{let t=document.getElementById("orderList"),n=document.getElementById("order").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{controller.openSidebar("orderDetails",l)},t.appendChild(r)}}}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE ORDERS")}).finally(()=>{n.style.display="none"})},toggleDropdown:function(e){event.preventDefault();let t=e.parentElement.children[0].children[1].children[0].children[0];"none"===e.style.display?(e.style.display="block",t.setAttribute("points","18 15 12 9 6 15")):(e.style.display="none",t.setAttribute("points","6 9 12 15 18 9"))}};var a={isPopulated:!1,display:function(e){if(!this.isPopulated){let t=document.getElementById("transactionsList"),n=document.getElementById("dateDropdown"),i=document.getElementById("recipeDropDown"),r=document.getElementById("transaction").content.children[0],l=new Date,d=new Date(l.getFullYear(),l.getMonth()-1,l.getDate());for(document.getElementById("transFilDate1").valueAsDate=d,document.getElementById("transFilDate2").valueAsDate=l,n.style.display="none",i.style.display="none",document.getElementById("dateFilterBtn").onclick=()=>{this.toggleDropdown(n)},document.getElementById("recipeFilterBtn").onclick=()=>{this.toggleDropdown(i)};i.children.length>0;)i.removeChild(i.firstChild);for(let e=0;e0;)t.removeChild(t.firstChild);let a=0;for(;a{controller.openSidebar("transactionDetails",n)},t.appendChild(e);let i=0,l=0;for(let t=0;t{this.submitFilter(e)},this.isPopulated=!0}},submitFilter:function(e){event.preventDefault();let t={startDate:document.getElementById("transFilDate1").valueAsDate,endDate:document.getElementById("transFilDate2").valueAsDate,recipes:[]};if(t.startDate>=t.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let n=document.getElementById("recipeDropDown");for(let r=0;re.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=document.getElementById("transactionsList"),i=document.getElementById("transaction").content.children[0];for(;n.children.length>0;)n.removeChild(n.firstChild);for(let r=0;r{controller.openSidebar("transactionDetails",s)},n.appendChild(l)}}}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE TRANSACTIONS")}).finally(()=>{i.style.display="none"})},toggleDropdown:function(e){event.preventDefault();let t=e.parentElement.children[0].children[1].children[0].children[0];"none"===e.style.display?(e.style.display="block",t.setAttribute("points","18 15 12 9 6 15")):(e.style.display="none",t.setAttribute("points","6 9 12 15 18 9"))}};var s={isPopulated:!1,fakeMerchant:{},chosenIngredients:[],display:function(e){if(!this.isPopulated){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/ingredients").then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{for(let e=0;e{banner.createError("UNABLE TO RETRIEVE DATA")}).finally(()=>{t.style.display="none"}),this.isPopulated=!0}},populateAddIngredients:function(e=!1){let t=document.getElementById("addIngredientList"),n=document.getElementById("addIngredientsCategory"),i=document.getElementById("addIngredientsIngredient"),r=this.fakeMerchant.categorizeIngredients();for(;t.children.length>0;)t.removeChild(t.firstChild);for(let l=0;l{this.toggleAddIngredient(e)},e.children[1].style.display="none",e.children[0].children[1].children[1].style.display="none",t.appendChild(e);for(let t=0;t{this.addOne(n)},n.ingredient=r[l].ingredients[t].ingredient,e.children[1].appendChild(n)}}if(e){let e=document.getElementById("myIngredients");for(;e.children.length>0;)e.removeChild(e.firstChild)}document.getElementById("addIngredientsBtn").onclick=()=>{this.submit()},document.getElementById("openNewIngredient").onclick=()=>{controller.openSidebar("newIngredient")}},toggleAddIngredient:function(e){let t=e.children[0].children[1],n=e.children[1];"none"===n.style.display?(n.style.display="flex",t.children[0].style.display="none",t.children[1].style.display="block"):(n.style.display="none",t.children[0].style.display="block",t.children[1].style.display="none")},addOne:function(e){e.parentElement.removeChild(e),document.getElementById("myIngredients").appendChild(e),document.getElementById("myIngredientsDiv").style.display="flex",e.children[1].style.display="flex";for(let i=0;i{this.removeOne(e)}},removeOne:function(e){e.parentElement.removeChild(e),e.children[1].style.display="none";let t=e.children[0].children[1];for(;t.children.length>0;)t.removeChild(t.firstChild);e.children[0].children[1].innerText="+",e.children[0].children[1].onclick=()=>{this.addOne(e)},0===document.getElementById("myIngredients").children.length&&(document.getElementById("myIngredientsDiv").style.display="none");for(let n=0;ne.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editIngredients(t),this.isPopulated=!1,banner.createNotification("ALL INGREDIENTS ADDED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})}};var o={ingredient:{},dailyUse:0,display:function(e){this.ingredient=e,document.getElementById("editIngBtn").onclick=()=>{this.edit()},document.getElementById("removeIngBtn").onclick=()=>{this.remove(merchant)},document.querySelector("#ingredientDetails p").innerText=e.ingredient.category,document.querySelector("#ingredientDetails h1").innerText=e.ingredient.name;let t=document.getElementById("ingredientStock");t.innerText=`${e.ingredient.convert(e.quantity).toFixed(2)} ${e.ingredient.unit.toUpperCase()}`,t.style.display="block";let n=document.getElementById("ingredientInput");n.value=e.ingredient.convert(e.quantity).toFixed(2),n.style.display="none";let i=[],r=new Date;for(let g=1;g<31;g++){let t=new Date(r.getFullYear(),r.getMonth(),r.getDate()-g),n=new Date(r.getFullYear(),r.getMonth(),r.getDate()-g-1),l=merchant.transactionIndices(n,t);!1===l?i.push(0):i.push(merchant.singleIngredientSold(l,e))}let l=0;for(let g=0;g0;)d.removeChild(d.firstChild);for(let g=0;g{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",a[g])},d.appendChild(e)}let s=document.getElementById("ingredientButtons"),o=[],c=document.getElementById("displayUnitLabel"),h=document.getElementById("defaultUnit");for("other"!==this.ingredient.ingredient.unitType?(o=merchant.units[this.ingredient.ingredient.unitType],c.style.display="block",h.style.display="block"):(c.style.display="none",h.style.display="none");s.children.length>0;)s.removeChild(s.firstChild);for(let g=0;g{this.changeUnit(e,o[g])},s.appendChild(e),o[g]===this.ingredient.ingredient.unit&&e.classList.add("unitActive")}document.getElementById("defaultUnit").onclick=()=>{this.changeUnitDefault()},document.getElementById("editSubmitButton").onclick=()=>{this.editSubmit()}},remove:function(e){for(let n=0;ne.json()).then(t=>{"string"==typeof t?banner.createError(t):(banner.createNotification("INGREDIENT REMOVED"),e.editIngredients([this.ingredient],!0))}).catch(e=>{}).finally(()=>{t.style.display="none"})},edit:function(){document.getElementById("ingredientStock").style.display="none",document.getElementById("ingredientInput").style.display="block",document.getElementById("editSubmitButton").style.display="block"},editSubmit:function(){this.ingredient.quantity=controller.convertToMain(this.ingredient.ingredient.unit,Number(document.getElementById("ingredientInput").value));let e=[{id:this.ingredient.ingredient.id,quantity:controller.convertToMain(this.ingredient.ingredient.unit,this.ingredient.quantity)}],t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/merchant/ingredients/update",{method:"PUT",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(e)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editIngredients([this.ingredient]),banner.createNotification("INGREDIENT UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})},changeUnit:function(e,t){this.ingredient.ingredient.unit=t;let n=document.querySelectorAll(".unitButton");for(let i=0;i{"string"==typeof e?banner.createError(e):banner.createNotification("INGREDIENT DEFAULT UNIT UPDATED")}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}};var c={display:function(e){document.getElementById("newIngName").value="",document.getElementById("newIngCategory").value="",document.getElementById("newIngQuantity").value=0,document.getElementById("submitNewIng").onclick=()=>{this.submit(e)}},submit:function(e){let t=document.getElementById("unitSelector"),n=document.querySelectorAll("#unitSelector option"),i=t.value,r={ingredient:{name:document.getElementById("newIngName").value,category:document.getElementById("newIngCategory").value,unitType:n[t.selectedIndex].getAttribute("type")},quantity:controller.convertToMain(i,document.getElementById("newIngQuantity").value),defaultUnit:i},l=document.getElementById("loaderContainer");l.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(t=>{"string"==typeof t?banner.createError(t):(merchant.editIngredients([{ingredient:new e(t.ingredient._id,t.ingredient.name,t.ingredient.category,t.ingredient.unitType,t.defaultUnit,merchant),quantity:t.quantity}]),banner.createNotification("INGREDIENT CREATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{l.style.display="none"})}};var h={isPopulated:!1,unused:[],display:function(e){if(!this.isPopulated){let t=merchant.categorizeIngredients(),n=document.getElementById("newOrderCategories"),i=document.getElementById("addIngredientsCategory").content.children[0],r=document.getElementById("newOrderIngredient").content.children[0];for(let e=0;e{this.toggleAddIngredient(l)},l.children[0].children[1].children[1].style.display="none",l.children[1].style.display="none",n.appendChild(l);for(let n=0;n{this.addOne(i,l.children[1])},i.ingredient=t[e].ingredients[n].ingredient,this.unused.push(t[e].ingredients[n]),l.children[1].appendChild(i)}}document.getElementById("submitNewOrder").onclick=()=>{this.submit(e)},this.isPopulated=!0}},addOne:function(e,t){for(let n=0;n{this.removeOne(e,t)},e.children[1].style.display="flex",t.removeChild(e),document.getElementById("newOrderAdded").appendChild(e)},removeOne:function(e,t){this.unused.push(e.ingredient),e.children[1].style.display="none",e.children[0].children[1].innerText="+",e.children[0].children[1].onclick=()=>{this.addOne(e,t)},e.parentElement.removeChild(e),t.appendChild(e)},toggleAddIngredient:function(e){let t=e.children[0].children[1],n=e.children[1];"none"===n.style.display?(n.style.display="flex",t.children[0].style.display="none",t.children[1].style.display="block"):(n.style.display="none",t.children[0].style.display="block",t.children[1].style.display="none")},submit:function(e){let t=document.getElementById("newOrderAdded"),n=[];for(let s=0;se.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.name,t.date,t.ingredients,merchant);merchant.editOrders([n]),merchant.editIngredients(n.ingredients,!1,!0),banner.createNotification("ORDER CREATED")}}).catch(e=>{banner.createError("SOEMTHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{a.style.display="none"})}};var g={display:function(e){let t=document.querySelector("#recipeInputIngredients select"),n=merchant.categorizeIngredients();for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{this.changeRecipeCount()},document.getElementById("submitNewRecipe").onclick=()=>{this.submit(e)}},changeRecipeCount:function(){let e=document.getElementById("ingredientCount").value,t=document.getElementById("recipeInputIngredients"),n=t.children.length;if(e>n){let i=e-n;for(let e=0;e div");for(let r=0;re.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.name,t.price,t.ingredients,merchant);merchant.editRecipes([n]),banner.createNotification("RECIPE CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})}};var p={display:function(e){let t=document.getElementById("newTransactionRecipes"),n=document.getElementById("createTransaction").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i{this.submit(e)}},submit:function(e){let t=document.getElementById("newTransactionRecipes"),n=document.getElementById("newTransactionDate").valueAsDate;if(n>new Date)return void banner.createError("CANNOT HAVE A DATE IN THE FUTURE");let i={date:n,recipes:[]};for(let r=0;r0)i.recipes.push({recipe:t.children[r].recipe.id,quantity:e});else if(e<0)return void banner.createError("CANNOT HAVE NEGATIVE VALUES")}if(i.recipes.length>0){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/transaction/create",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(i)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.date,t.recipes,merchant);merchant.editTransactions(n),banner.createNotification("NEW TRANSACTION CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}}};var m={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("orderDetailTime").innerText=e.date.toLocaleTimeString("en-US");let t=document.getElementById("orderIngredients");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("orderIngredient").content.children[0],i=0;for(let r=0;re.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.editOrders([e],!0),banner.createNotification("ORDER REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var u={recipe:{},display:function(e){this.recipe=e,document.getElementById("recipeName").style.display="block",document.getElementById("recipeNameIn").style.display="none",document.querySelector("#recipeDetails h1").innerText=e.name;let t=document.getElementById("recipeIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("recipeIngredient").content.children[0];for(let r=0;r{this.edit()},"none"===merchant.pos&&(document.getElementById("removeRecipeBtn").onclick=()=>{this.remove()}),document.getElementById("addRecIng").onclick=()=>{this.displayAddIngredient()},document.getElementById("recipeUpdate").onclick=()=>{this.update()}},edit:function(){let e=document.getElementById("recipeIngredientList");if("none"===merchant.pos){let e=document.getElementById("recipeName"),t=document.getElementById("recipeNameIn");e.style.display="none",t.style.display="block",t.value=this.recipe.name;let n=document.getElementById("recipePrice");n.children[1].style.display="none",n.children[2].style.display="block",n.children[2].value=parseFloat((this.recipe.price/100).toFixed(2))}for(let t=0;t{n.parentElement.removeChild(n)}}document.getElementById("addRecIng").style.display="flex",document.getElementById("recipeUpdate").style.display="flex"},update:function(){this.recipe.name=document.getElementById("recipeNameIn").value||this.recipe.name,this.recipe.price=Math.round(100*document.getElementById("recipePrice").children[2].value)||this.recipe.price,this.recipe.ingredients=[];let e=document.getElementById("recipeIngredientList").children;for(let i=0;ie.json()).then(e=>{"string"==typeof e?banner.createError(e):(window.merchant.editRecipes([this.recipe]),banner.createNotification("RECIPE UPDATE"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})},remove:function(){fetch("/merchant/recipes/remove/"+this.recipe.id,{method:"DELETE"}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editRecipes([this.recipe],!0),banner.createNotification("RECIPE REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")})},displayAddIngredient:function(){let e=document.getElementById("addRecIngredient").content.children[0].cloneNode(!0);e.name="new",document.getElementById("recipeIngredientList").appendChild(e);let t=window.merchant.categorizeIngredients();for(let n=0;n0;)t.removeChild(t.firstChild);for(let d=0;d{this.remove()})},remove:function(){let e=document.getElementById("loaderContainer");e.style.display="flex",fetch("/transaction/"+this.transaction.id,{method:"delete",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.editTransactions(this.transaction,!0),banner.createNotification("TRANSACTION REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}},f=class{constructor(e,t,n,i,r,l){this.id=e,this.name=t,this.category=n,this.unitType=i,this.unit=r,this.parent=l}convert(e){if("mass"===this.unitType)switch(this.unit){case"g":break;case"kg":e/=1e3;break;case"oz":e/=28.3495;break;case"lb":e/=453.5924}else if("volume"===this.unitType)switch(this.unit){case"ml":e*=1e3;break;case"l":break;case"tsp":e*=202.8842;break;case"tbsp":e*=67.6278;break;case"ozfl":e*=33.8141;break;case"cup":e*=4.1667;break;case"pt":e*=2.1134;break;case"qt":e*=1.0567;break;case"gal":e/=3.7854}else if("length"===this.unitType)switch(this.unit){case"mm":e*=1e3;break;case"cm":e*=100;break;case"m":break;case"in":e*=39.3701;break;case"ft":e*=3.2808}return e}},E=class{constructor(e,t,n,i,r){this.id=e,this.name=t,this.price=n,this.parent=r,this.ingredients=[];for(let l=0;le.date>t.date?1:-1)),controller.updateData("transaction"),controller.closeSidebar()}transactionIndices(e,t=new Date){let n=[];for(let i=0;ie){n.push(i);break}for(let i=this.transactions.length-1;i>=0;i--)if(this.transactions[i].date{document.getElementById("max").style.display="flex",document.getElementById("min").style.display="none"},150)}}else{e.classList="menu menuMinimized";for(let e=0;e{this.closeMenu()}},closeMenu:function(){document.getElementById("menu").style.display="none",document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").onclick=()=>{this.openMenu()}},convertToMain:function(e,t){let n=0;if(merchant.units.mass.includes(e))switch(e){case"g":n=t;break;case"kg":n=1e3*t;break;case"oz":n=28.3495*t;break;case"lb":n=453.5924*t}else if(merchant.units.volume.includes(e))switch(e){case"ml":n=t/1e3;break;case"l":n=t;break;case"tsp":n=t/202.8842;break;case"tbsp":n=t/67.6278;break;case"ozfl":n=t/33.8141;break;case"cup":n=t/4.1667;break;case"pt":n=t/2.1134;break;case"qt":n=t/1.0567;break;case"gal":n=3.7854*t}else if(merchant.units.length.includes(e))switch(e){case"mm":n=t/1e3;break;case"cm":n=t/100;break;case"m":n=t;break;case"in":n=t/39.3701;break;case"ft":n=t/3.2808}else n=t;return n},updateData:function(e){switch(e){case"ingredient":i.drawInventoryCheckCard(),r.populateByProperty("category"),s.isPopulated=!1;break;case"recipe":a.isPopulated=!1,l.populateRecipes();break;case"order":d.populate();break;case"transaction":a.isPopulated=!1,a.display(I);break;case"unit":i.isPopulated=!1,r.populateByProperty("category")}}},window.screen.availWidth>1e3&&window.screen.availWidth<=1400&&(this.changeMenu(),document.getElementById("menuShifter2").style.display="none"),controller.openStrand("home")}();