| 1 |
- !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;r<e.set.length;r++)e.set[r]>this.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[0]&&(this.xRange[0]=t[0],i=!0),t[1]>this.xRange[1]&&(this.xRange[1]=t[1],i=!0)),i?this.drawGraph():this.drawLine(e)}removeData(e){for(let t=0;t<this.data.length;t++)if(this.data[t].name===e){this.data.splice(t,1);break}this.drawGraph()}clearData(){this.max=0,this.data=[],this.xRange=[]}addTitle(e){this.top=this.canvas.clientHeight-.9*this.canvas.clientHeight,this.title=e}drawGraph(){this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.drawYAxis(),this.drawXAxis();for(let e=0;e<this.data.length;e++)this.drawLine(this.data[e]);if(this.title){this.context.font="25px Saira";let e=(this.right-this.left)/2-this.context.measureText(this.title).width/2;this.context.fillText(this.title,e,this.top-10)}}drawLine(e){for(let t=0;t<e.set.length-1;t++)this.context.beginPath(),this.context.moveTo(this.left+this.horizontalMultiplier*t,this.bottom-this.verticalMultiplier*e.set[t]),this.context.lineTo(this.left+this.horizontalMultiplier*(t+1),this.bottom-this.verticalMultiplier*e.set[t+1]),this.context.strokeStyle=this.colors[e.colorIndex],this.context.lineWidth=2,this.context.stroke();this.context.strokeStyle="black",this.data.length>1&&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;n<e;n+=Math.floor(e/10))this.context.fillText(t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"2-digit"}),this.left+this.horizontalMultiplier*n-20,this.bottom+15),0!==n&&(this.context.beginPath(),this.context.moveTo(this.left+this.horizontalMultiplier*n,this.bottom),this.context.lineTo(this.left+this.horizontalMultiplier*n,this.top),this.context.strokeStyle="#a5a5a5",this.context.stroke()),t.setDate(t.getDate()+Math.abs(e/10))}this.context.strokeStyle="black",this.context.setLineDash([])}drawYAxis(){this.context.beginPath(),this.context.moveTo(this.left,this.top),this.context.lineTo(this.left,this.bottom),this.context.lineWidth=2,this.context.stroke(),this.context.setLineDash([5,10]),this.context.font="10px Arial",this.context.lineWidth=1;let e=0,t=(this.bottom-this.top)/10,n=0;do{this.context.fillText(Math.round(e).toString(),this.left-20,this.bottom-n+3),this.context.beginPath(),this.context.moveTo(this.left,this.bottom-n),this.context.lineTo(this.right,this.bottom-n),this.context.strokeStyle="#a5a5a5",this.context.stroke(),n+=t,e+=this.max/10}while(n<=this.bottom-this.top);this.context.strokeStyle="black",this.context.setLineDash([])}drawLegend(e,t){let n;for(let i=0;i<this.data.length;i++)if(this.data[i].name===t){n=25*i;break}this.context.beginPath(),this.context.fillStyle=this.colors[e],this.context.fillRect(this.right+50,this.top+50+n,10,10),this.context.stroke(),this.context.font="15px Arial",this.context.fillText(t,this.right+65,this.top+60+n),this.context.fillStyle="black"}},HorizontalBarGraph:class{constructor(e){this.canvas=e,this.context=e.getContext("2d"),this.left=0,this.right=e.clientWidth,this.top=e.clientHeight-.99*e.clientHeight,this.bottom=e.clientHeight,this.data=[],this.max=0}addData(e){this.context.clearRect(0,0,this.canvas.width,this.canvas.height);for(let t=0;t<e.length;t++)e[t].num>this.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.data.length;t++){let n=this.top+t*e+5,i=(this.right-this.left)*(this.data[t].num/this.max);this.data[t].num>=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;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),l=e.children[1].children[1];e.ingredient=merchant.ingredients[t[r]],e.children[0].innerText=merchant.ingredients[t[r]].ingredient.name,e.children[1].children[0].onclick=()=>{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;n<t;n++)try{let t=r[0].quantity,n=0;for(let e=0;e<r.length;e++)r[e].quantity>t&&(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<e.length;r++){if(!(e[r].children[1].children[1].value>=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<t.length;l++){let e=i.cloneNode(!0);e.children[0].children[0].innerText=t[l].name,e.children[0].children[1].onclick=()=>{this.toggleCategory(e.children[1],e.children[0].children[1])},e.children[1].style.display="none",n.appendChild(e);for(let n=0;n<t[l].ingredients.length;n++){let i=t[l].ingredients[n],d=r.cloneNode(!0);d.children[0].innerText=i.ingredient.name,d.children[2].innerText=`${i.ingredient.convert(i.quantity).toFixed(2)} ${i.ingredient.unit.toUpperCase()}`,d.onclick=()=>{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.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(document.getElementById("ingredientSelect").selectedIndex=0,""===e)return this.populateByProperty("category"),void(document.getElementById("ingredientClearButton").style.display="none");let t=[];for(let n=0;n<this.ingredients.length;n++)this.ingredients[n]._name.includes(e)&&t.push(this.ingredients[n]);document.getElementById("ingredientClearButton").style.display="inline",this.displayIngredientsOnly(t)},sort:function(){let e=document.getElementById("ingredientSelect").value;if(""===e)return;if(document.getElementById("ingredientSearch").value="","category"===e)return void this.populateByProperty("category");if("unit"===e)return void this.populateByProperty("unit");document.getElementById("ingredientClearButton").style.display="inline";let t=this.ingredients.slice().sort((t,n)=>t[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<merchant.recipes.length;n++){let i=t.cloneNode(!0);i.onclick=()=>{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;r<this.recipeDivList.length;r++)this.recipeDivList[r]._name.toLowerCase().includes(e)&&i.push(this.recipeDivList[r]);for(;t.children.length>0;)t.removeChild(t.firstChild);for(let r=0;r<i.length;r++)t.appendChild(i[r]);n.style.display=""===e?"none":"inline"},clearSorting:function(){document.getElementById("recipeSearch").value="",this.search()},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=>{let n=[];for(let r=0;r<t.new.length;r++)n.push(new e(t.new[r]._id,t.new[r].name,t.new[r].price,merchant,[]));n.length>0&&merchant.editRecipes(n);let i=[];for(let e=0;e<t.removed.length;e++)for(let n=0;n<merchant.recipes.length;n++)if(t.removed[e]._id===merchant.recipes[n].id){i.push(merchant.recipes[n],!0);break}i.length>0&&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<t.length;i++)n.push(new e(t[i]._id,t[i].name,t[i].date,t[i].ingredients,merchant));merchant.editOrders(n),document.getElementById("orderSubmitForm").onsubmit=()=>{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;r<merchant.ingredients.length;r++){let e=document.createElement("input");e.type="checkbox",e.ingredient=merchant.ingredients[r].ingredient,i.appendChild(e);let t=document.createElement("label");t.innerText=merchant.ingredients[r].ingredient.name,t.for=e,i.appendChild(t);let n=document.createElement("br");i.appendChild(n)}for(;e.children.length>0;)e.removeChild(e.firstChild);for(let r=0;r<merchant.orders.length;r++){let n=t.cloneNode(!0),i=0;for(let e=0;e<merchant.orders[r].ingredients.length;e++)i+=merchant.orders[r].ingredients[e].quantity*merchant.orders[r].ingredients[e].price;n.children[0].innerText=merchant.orders[r].name,n.children[1].innerText=merchant.orders[r].ingredients.length+" items",n.children[2].innerText=new Date(merchant.orders[r].date).toLocaleDateString("en-US"),n.children[3].innerText="$"+(i/100).toFixed(2),n.order=merchant.orders[r],n.onclick=()=>{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;i<t.children.length;i+=3)t.children[i].checked&&e.ingredients.push(t.children[i].ingredient.id);if(0===e.ingredients.length)for(let i=0;i<merchant.ingredients.length;i++)e.ingredients.push(merchant.ingredients[i].ingredient.id);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/order",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(e)}).then(e=>e.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<e.length;i++){let r=n.cloneNode(!0),l=new Order(e[i]._id,e[i].name,e[i].date,e[i].ingredients,merchant),d=0;for(let e=0;e<l.ingredients.length;e++)d+=l.ingredients[e].price/100*l.ingredients[e].quantity;r.children[0].innerText=l.name,r.children[1].innerText=l.ingredients.length+" items",r.children[2].innerText=l.date.toLocaleDateString(),r.children[3].innerText="$"+d.toFixed(2),r.onclick=()=>{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;e<merchant.recipes.length;e++){let t=document.createElement("input");t.type="checkbox",t.recipe=merchant.recipes[e],i.appendChild(t);let n=document.createElement("label");n.innerText=merchant.recipes[e].name,n.for=t,i.appendChild(n);let r=document.createElement("br");i.appendChild(r)}for(;t.children.length>0;)t.removeChild(t.firstChild);let a=0;for(;a<merchant.transactions.length&&a<100;){let e=r.cloneNode(!0),n=merchant.transactions[a];e.onclick=()=>{controller.openSidebar("transactionDetails",n)},t.appendChild(e);let i=0,l=0;for(let t=0;t<merchant.transactions[a].recipes.length;t++)i+=merchant.transactions[a].recipes[t].quantity,l+=merchant.transactions[a].recipes[t].recipe.price*merchant.transactions[a].recipes[t].quantity;e.children[0].innerText=`${merchant.transactions[a].date.toLocaleDateString()} ${merchant.transactions[a].date.toLocaleTimeString()}`,e.children[1].innerText=i+" recipes sold",e.children[2].innerText="$"+(l/100).toFixed(2),a++}document.getElementById("transFormSubmit").onsubmit=()=>{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;r<n.children.length;r+=3)n.children[r].checked&&t.recipes.push(n.children[r].recipe.id);if(0===t.recipes.length)for(let r=0;r<merchant.recipes.length;r++)t.recipes.push(merchant.recipes[r].id);let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/transaction",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);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<t.length;r++){let l=i.cloneNode(!0),d=0,a=0,s=new e(t[r]._id,t[r].date,t[r].recipes,merchant);for(let e=0;e<s.recipes.length;e++)d+=s.recipes[e].quantity,a+=s.recipes[e].quantity*s.recipes[e].recipe.price;l.children[0].innerText=`${s.date.toLocaleDateString()} ${s.date.toLocaleTimeString()}`,l.children[1].innerText=d+" recipes sold",l.children[2].innerText="$"+(a/100).toFixed(2),l.onclick=()=>{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<merchant.ingredients.length;e++)for(let n=0;n<t.length;n++)if(merchant.ingredients[e].ingredient.id===t[n]._id){t.splice(n,1);break}for(let e=0;e<t.length;e++)t[e]={ingredient:t[e]};this.fakeMerchant=new e({name:"none",inventory:t,recipes:[]},[]),this.populateAddIngredients(!0)}}).catch(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<r.length;l++){let e=n.content.children[0].cloneNode(!0);e.children[0].children[0].innerText=r[l].name,e.children[0].children[1].onclick=()=>{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<r[l].ingredients.length;t++){let n=i.content.children[0].cloneNode(!0);n.children[0].children[0].innerText=r[l].ingredients[t].ingredient.name,n.children[0].children[1].onclick=()=>{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.fakeMerchant.ingredients.length;i++)if(this.fakeMerchant.ingredients[i].ingredient===e.ingredient){this.fakeMerchant.ingredients.splice(i,1),this.chosenIngredients.push(e.ingredient);break}let t=e.children[1].children[1],n=merchant.units[e.ingredient.unitType];for(let i=0;i<n.length;i++){let r=document.createElement("option");r.innerText=n[i].toUpperCase(),r.type=e.ingredient.unitType,r.value=n[i],t.appendChild(r)}e.children[0].children[1].innerText="-",e.children[0].children[1].onclick=()=>{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;n<this.chosenIngredients.length;n++)if(this.chosenIngredients[n]===e.ingredient){this.chosenIngredients.splice(n,1),this.fakeMerchant.ingredients.push({ingredient:e.ingredient});break}this.populateAddIngredients()},submit:function(){let e=document.getElementById("myIngredients").children,t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r].children[1].children[0].value,l=e[r].children[1].children[1].value;if(""===i)return void banner.createError("PLEASE ENTER A QUANTITY FOR EACH INGREDIENT YOU WANT TO ADD TO YOUR INVENTORY");i=controller.convertToMain(l,i);let d={ingredient:e[r].ingredient,quantity:i};d.ingredient.unit=l,t.push(d),n.push({id:e[r].ingredient.id,quantity:i,defaultUnit:l})}let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/merchant/ingredients/add",{method:"POST",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),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;g<i.length;g++)l+=i[g];this.dailyUse=l/i.length,document.getElementById("dailyUse").innerText=`${e.ingredient.convert(this.dailyUse).toFixed(2)} ${e.ingredient.unit}`;let d=document.getElementById("ingredientRecipeList"),a=merchant.getRecipesForIngredient(e.ingredient);for(;d.children.length>0;)d.removeChild(d.firstChild);for(let g=0;g<a.length;g++){let e=document.createElement("li");e.innerText=a[g].name,e.onclick=()=>{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<o.length;g++){let e=document.createElement("button");e.classList.add("unitButton"),e.innerText=o[g].toUpperCase(),e.onclick=()=>{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;n<e.recipes.length;n++)for(let t=0;t<e.recipes[n].ingredients.length;t++)if(this.ingredient.ingredient===e.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("/merchant/ingredients/remove/"+this.ingredient.ingredient.id,{method:"DELETE"}).then(e=>e.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<n.length;i++)n[i].classList.remove("unitActive");e.classList.add("unitActive"),controller.updateData("unit"),document.getElementById("ingredientStock").innerText=`${this.ingredient.ingredient.convert(this.ingredient.quantity).toFixed(2)} ${this.ingredient.ingredient.unit.toUpperCase()}`,document.getElementById("dailyUse").innerText=`${this.ingredient.ingredient.convert(this.dailyUse).toFixed(2)} ${this.ingredient.ingredient.unit}`},changeUnitDefault:function(){let e=document.getElementById("loaderContainer");e.style.display="flex";let t=this.ingredient.ingredient.id,n=this.ingredient.ingredient.unit;fetch(`/merchant/ingredients/update/${t}/${n}`,{method:"put",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>{"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<t.length;e++){let l=i.cloneNode(!0);l.children[0].children[0].innerText=t[e].name,l.children[0].children[1].onclick=()=>{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<t[e].ingredients.length;n++){let i=r.cloneNode(!0);i.children[0].children[0].innerText=t[e].ingredients[n].ingredient.name,i.children[0].children[1].onclick=()=>{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.unused.length;n++)if(this.unused[n]===e){this.unused.splice(n,1);break}e.children[0].children[1].innerText="-",e.children[0].children[1].onclick=()=>{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;s<t.children.length;s++){let i=t.children[s].children[1].children[0].value,r=t.children[s].children[1].children[1].value;new e(void 0,void 0,new Date,[],void 0),""!==i&&""!==r&&n.push({ingredient:t.children[s].ingredient.id,quantity:controller.convertToMain(t.children[s].ingredient.unit,parseFloat(i)),price:t.children[s].ingredient.convert(parseInt(100*r))})}let i=document.getElementById("orderTime").value,r=document.getElementById("orderDate").value,l="";""===i&&""===r?l=void 0:""===i&&""!==r?l=r:""!==i&&""===r?banner.createError("PLEASE ADD A DATE IF YOU WISH TO HAVE A TIME"):l=`${r}T${i}:00`;let d={name:document.getElementById("orderName").value,date:l,ingredients:n},a=document.getElementById("loaderContainer");a.style.display="flex",fetch("/order/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(d)}).then(e=>e.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<n.length;i++){let e=document.createElement("optgroup");e.label=n[i].name,t.appendChild(e);for(let t=0;t<n[i].ingredients.length;t++){let r=document.createElement("option");r.value=n[i].ingredients[t].ingredient.id,r.innerText=`${n[i].ingredients[t].ingredient.name} (${n[i].ingredients[t].ingredient.unit})`,e.appendChild(r)}}document.getElementById("ingredientCount").onclick=()=>{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<i;e++){let e=t.children[0].cloneNode(!0);e.children[2].children[0].value="",t.appendChild(e)}for(let n=0;n<e;n++)t.children[n].children[0].innerText="INGREDIENT "+(n+1)}else if(e<n){let i=n-e;for(let e=0;e<i;e++)t.removeChild(t.children[t.children.length-1])}},submit:function(e){let t={name:document.getElementById("newRecipeName").value,price:document.getElementById("newRecipePrice").value,ingredients:[]},n=document.querySelectorAll("#recipeInputIngredients > div");for(let r=0;r<n.length;r++)for(let e=0;e<merchant.ingredients.length;e++)if(merchant.ingredients[e].ingredient.id===n[r].children[1].children[0].value){t.ingredients.push({ingredient:n[r].children[1].children[0].value,quantity:controller.convertToMain(merchant.ingredients[e].ingredient.unit,n[r].children[2].children[0].value)});break}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(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<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:[]};for(let r=0;r<t.children.length;r++){let e=t.children[r].children[1].value;if(""!==e&&e>0)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;r<e.ingredients.length;r++){let l=n.cloneNode(!0),d=e.ingredients[r].quantity*e.ingredients[r].price/100;i+=d;let a=e.ingredients[r].ingredient,s=a.convert(e.ingredients[r].quantity).toFixed(2)+" "+a.unit.toUpperCase()+" x $"+(e.convertPrice(a.unitType,a.unit,e.ingredients[r].price)/100).toFixed(2);l.children[0].innerText=e.ingredients[r].ingredient.name,l.children[1].innerText=s,l.children[2].innerText="$"+d.toFixed(2),t.appendChild(l)}document.querySelector("#orderTotalPrice p").innerText="$"+i.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.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<e.ingredients.length;r++)ingredientDiv=n.cloneNode(!0),ingredientDiv.children[0].innerText=e.ingredients[r].ingredient.name,ingredientDiv.children[2].innerText=`${e.ingredients[r].ingredient.convert(e.ingredients[r].quantity).toFixed(2)} ${e.ingredients[r].ingredient.unit}`,ingredientDiv.ingredient=e.ingredients[r].ingredient,ingredientDiv.name=e.ingredients[r].ingredient.name,t.appendChild(ingredientDiv);document.getElementById("addRecIng").style.display="none";let i=document.getElementById("recipePrice");i.children[1].style.display="block",i.children[2].style.display="none",i.children[1].innerText="$"+(e.price/100).toFixed(2),document.getElementById("recipeUpdate").style.display="none",document.getElementById("editRecipeBtn").onclick=()=>{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<e.children.length;t++){let n=e.children[t];n.children[2].innerText=this.recipe.ingredients[t].ingredient.unit,n.children[1].style.display="block",n.children[1].value=this.recipe.ingredients[t].ingredient.convert(this.recipe.ingredients[t].quantity).toFixed(2),n.children[3].style.display="block",n.children[3].onclick=()=>{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;i<e.length;i++)if("new"===e[i].name){let t=e[i].children[0];this.recipe.ingredients.push({ingredient:t.options[t.selectedIndex].ingredient,quantity:controller.convertToMain(t.options[t.selectedIndex].ingredient.unit,e[i].children[1].value)})}else this.recipe.ingredients.push({ingredient:e[i].ingredient,quantity:controller.convertToMain(e[i].ingredient.unit,e[i].children[1].value)});let t={id:this.recipe.id,name:this.recipe.name,price:this.recipe.price,ingredients:[]};for(let i=0;i<this.recipe.ingredients.length;i++)t.ingredients.push({ingredient:this.recipe.ingredients[i].ingredient.id,quantity:this.recipe.ingredients[i].quantity});let n=document.getElementById("loaderContainer");n.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):(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;n<t.length;n++){let i=document.createElement("optgroup");i.label=t[n].name,e.children[0].appendChild(i);for(let e=0;e<t[n].ingredients.length;e++){let r=document.createElement("option");r.innerText=`${t[n].ingredients[e].ingredient.name} (${t[n].ingredients[e].ingredient.unit})`,r.ingredient=t[n].ingredients[e].ingredient,i.appendChild(r)}}}};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 d=0;d<e.recipes.length;d++){let l=n.cloneNode(!0),a=e.recipes[d].quantity*e.recipes[d].recipe.price;l.children[0].innerText=e.recipes[d].recipe.name,l.children[1].innerText=`${e.recipes[d].quantity} x $${parseFloat(e.recipes[d].recipe.price/100).toFixed(2)}`,l.children[2].innerText="$"+(a/100).toFixed(2),t.appendChild(l),i+=e.recipes[d].quantity,r+=a}let l=`${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e.date.getDay()]}, ${["January","Fecbruary","March","April","May","June","July","August","September","October","November","December"][e.date.getMonth()]} ${e.date.getDate()}, ${e.date.getFullYear()}`;document.getElementById("transactionDate").innerText=l,document.getElementById("transactionTime").innerText=e.date.toLocaleTimeString(),document.getElementById("totalRecipes").innerText=i+" recipes",document.getElementById("totalPrice").innerText="$"+(r/100).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=>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;l<i.length;l++)for(let e=0;e<r.ingredients.length;e++)if(i[l].ingredient===r.ingredients[e].ingredient.id){this.ingredients.push({ingredient:r.ingredients[e].ingredient,quantity:i[l].quantity});break}}},I=class{constructor(e,t,n,i){this.id=e,this.parent=i,this.date=new 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){this.recipes.push({recipe:i.recipes[e],quantity:n[r].quantity});break}}},b=class{constructor(e,t){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","foot"],other:["each"]};for(let n=0;n<e.inventory.length;n++)this.ingredients.push({ingredient:new f(e.inventory[n].ingredient._id,e.inventory[n].ingredient.name,e.inventory[n].ingredient.category,e.inventory[n].ingredient.unitType,e.inventory[n].defaultUnit,this),quantity:e.inventory[n].quantity});for(let n=0;n<e.recipes.length;n++)this.recipes.push(new E(e.recipes[n]._id,e.recipes[n].name,e.recipes[n].price,e.recipes[n].ingredients,this));for(let n=0;n<t.length;n++)this.transactions.push(new I(t[n]._id,t[n].date,t[n].recipes,this))}editIngredients(e,t=!1,n=!1){for(let i=0;i<e.length;i++){let r=!0;for(let l=0;l<merchant.ingredients.length;l++)if(merchant.ingredients[l].ingredient===e[i].ingredient){t?merchant.ingredients.splice(l,1):!t&&n?merchant.ingredients[l].quantity+=e[i].quantity:merchant.ingredients[l].quantity=e[i].quantity,r=!1;break}r&&merchant.ingredients.push({ingredient:e[i].ingredient,quantity:parseFloat(e[i].quantity),defaultUnit:e[i].defaultUnit})}controller.updateData("ingredient"),controller.closeSidebar()}editRecipes(e,t=!1){let n=!0;for(let i=0;i<e.length;i++){for(let r=0;r<this.recipes.length;r++)if(e[i]===this.recipes[r]){t?this.recipes.splice(r,1):this.recipes[r]=e[i],n=!1;break}n&&merchant.recipes.push(e[i])}controller.updateData("recipe"),controller.closeSidebar()}editOrders(e,t=!1){for(let n=0;n<e.length;n++){let i=!0;for(let r=0;r<this.orders.length;r++)if(e[n]===this.orders[r]){t?this.orders.splice(r,1):this.orders[r]=e[n],i=!1;break}i&&this.orders.push(e[n])}controller.updateData("order"),controller.closeSidebar()}editTransactions(e,t=!1){let n=!0;for(let i=0;i<this.transactions.length;i++)if(this.transactions[i]===e){t&&this.transactions.splice(i,1),n=!1;break}n&&(this.transactions.push(e),this.transactions.sort((e,t)=>e.date>t.date?1:-1)),controller.updateData("transaction"),controller.closeSidebar()}transactionIndices(e,t=new Date){let n=[];for(let i=0;i<this.transactions.length;i++)if(this.transactions[i].date>e){n.push(i);break}for(let i=this.transactions.length-1;i>=0;i--)if(this.transactions[i].date<t){n.push(i);break}return!(n.length<2)&&n}revenue(e){let t=0;for(let n=e[0];n<=e[1];n++)for(let e=0;e<this.transactions[n].recipes.length;e++)for(let i=0;i<this.recipes.length;i++)this.transactions[n].recipes[e].recipe===this.recipes[i]&&(t+=this.transactions[n].recipes[e].quantity*this.recipes[i].price);return t/100}ingredientsSold(e){if(!e)return!1;let t=this.recipesSold(e),n=[];for(let i=0;i<t.length;i++)for(let e=0;e<t[i].recipe.ingredients.length;e++){let r=!1;for(let l=0;l<n.length;l++)if(n[l].ingredient===t[i].recipe.ingredients[e].ingredient){r=!0,n[l].quantity+=t[i].quantity*t[i].recipe.ingredients[e].quantity;break}r||n.push({ingredient:t[i].recipe.ingredients[e].ingredient,quantity:t[i].quantity*t[i].recipe.ingredients[e].quantity})}return n}singleIngredientSold(e,t){let n=0;for(let i=e[0];i<e[1];i++)for(let e=0;e<this.transactions[i].recipes.length;e++)for(let r=0;r<this.transactions[i].recipes[e].recipe.ingredients.length;r++)if(this.transactions[i].recipes[e].recipe.ingredients[r].ingredient===t.ingredient){n+=this.transactions[i].recipes[e].recipe.ingredients[r].quantity;break}return n}recipesSold(e){let t=[];for(let n=e[0];n<=e[1];n++)for(let e=0;e<this.transactions[n].recipes.length;e++){let i=!1;for(let r=0;r<t.length;r++)if(t[r].recipe===this.transactions[n].recipes[e].recipe){i=!0,t[r].quantity+=this.transactions[n].recipes[e].quantity;break}i||t.push({recipe:this.transactions[n].recipes[e].recipe,quantity:this.transactions[n].recipes[e].quantity})}return t}graphDailyRevenue(e){if(!e)return!1;let t=new Array(30).fill(0),n=this.transactions[e[0]].date,i=0;for(let r=e[0];r<=e[1];r++){this.transactions[r].date.getDate()!==n.getDate()&&(n=this.transactions[r].date,i++);for(let e=0;e<this.transactions[r].recipes.length;e++)t[i]+=this.transactions[r].recipes[e].recipe.price/100*this.transactions[r].recipes[e].quantity}return t}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;for(let i=0;i<e.length;i++)if(this.ingredients[t].ingredient.unit===e[i].name){e[i].ingredients.push(this.ingredients[t]),n=!0;break}n||e.push({name:this.ingredients[t].ingredient.unit,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++)this.recipes[n].ingredients[i].ingredient===e&&t.push(this.recipes[n]);return t}},T=class{constructor(e,t,n,i,r){this.id=e,this.name=t,this.date=new Date(n),this.ingredients=[],this.parent=r;for(let l=0;l<i.length;l++)for(let e=0;e<r.ingredients.length;e++)i[l].ingredient===r.ingredients[e].ingredient.id&&this.ingredients.push({ingredient:r.ingredients[e].ingredient,quantity:i[l].quantity,price:i[l].price})}convertPrice(e,t,n){if("mass"===e)switch(t){case"g":break;case"kg":n*=1e3;break;case"oz":n*=28.3495;break;case"lb":n*=453.5924}else if("volume"===e)switch(t){case"ml":n/=1e3;break;case"l":break;case"tsp":n/=202.8842;break;case"tbsp":n/=67.6278;break;case"ozfl":n/=33.8141;break;case"cup":n/=4.1667;break;case"pt":n/=2.1134;break;case"qt":n/=1.0567;break;case"gal":n*=3.7854}else if("length"===e)switch(t){case"mm":n/=1e3;break;case"cm":n/=100;break;case"m":break;case"in":n/=39.3701;break;case"ft":n/=3.2808}return n}};merchant=new b(data.merchant,data.transactions),controller={openStrand:function(e){this.closeSidebar();let t=document.querySelectorAll(".strand");for(let i=0;i<t.length;i++)t[i].style.display="none";let n=document.querySelectorAll(".menuButton");for(let i=0;i<n.length-1;i++)n[i].classList="menuButton",n[i].disabled=!1;let s={};switch(e){case"home":s=document.getElementById("homeBtn"),document.getElementById("homeStrand").style.display="flex",i.display();break;case"ingredients":s=document.getElementById("ingredientsBtn"),document.getElementById("ingredientsStrand").style.display="flex",r.display();break;case"recipeBook":s=document.getElementById("recipeBookBtn"),document.getElementById("recipeBookStrand").style.display="flex",l.display(E);break;case"orders":s=document.getElementById("ordersBtn"),document.getElementById("ordersStrand").style.display="flex",d.display(T);break;case"transactions":s=document.getElementById("transactionsBtn"),document.getElementById("transactionsStrand").style.display="flex",a.display(I)}s.classList="menuButton active",s.disabled=!0,window.screen.availWidth<=1e3&&this.closeMenu()},openSidebar:function(e,t={}){switch(this.closeSidebar(),document.getElementById("sidebarDiv").classList="sidebar",document.getElementById(e).style.display="flex",e){case"ingredientDetails":o.display(t);break;case"addIngredients":s.display(b);break;case"newIngredient":c.display(f);break;case"recipeDetails":u.display(t);break;case"addRecipe":g.display(E);break;case"orderDetails":m.display(t);break;case"newOrder":h.display(T);break;case"transactionDetails":y.display(t);break;case"newTransaction":p.display(I)}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++)e.children[t].style.display="none";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")},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()}},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")}();
|