bundle.js 197 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763
  1. <<<<<<< HEAD
  2. !function(){var e={isPopulated:!1,display:function(){this.isPopulated||(this.drawRevenueCard(),this.drawRevenueGraph(),this.drawInventoryCheckCard(),this.drawPopularCard(),this.isPopulated=!0)},drawRevenueCard:function(){let e=new Date,t=new Date(e.getFullYear(),e.getMonth(),1),n=new Date(e.getFullYear(),e.getMonth()-1,1),i=new Date((new Date).setMonth(e.getMonth()-1));const r=merchant.getRevenue(t),s=merchant.getRevenue(n,i);document.getElementById("revenue").innerText="$"+r.toFixed(2);let a=(r-s)/s*100,d="";d=a>=0?"/shared/images/upArrow.png":"/shared/images/downArrow.png",document.querySelector("#revenueChange p").innerText=Math.abs(a).toFixed(2)+"% vs last month",document.querySelector("#revenueChange img").src=d},drawRevenueGraph:function(){let e=new Date;e.setMonth(e.getMonth()-1);let t=[],n=[],i=0;const r=merchant.getTransactions(e);let s=r.length>0?r[0].date:void 0;for(let d=0;d<r.length;d++){r[d].date.getDate()!==s.getDate()&&(t.push(i/100),i=0,n.push(s),s=r[d].date);for(let e=0;e<r[d].recipes.length;e++){const t=r[d].recipes[e];i+=t.recipe.price*t.quantity}}const a={x:n,y:t,mode:"lines+markers",line:{color:"rgb(255, 99, 107)"}};Plotly.newPlot("graphCard",[a],{title:"REVENUE",xaxis:{title:"DATE"},yaxis:{title:"$"}})},drawInventoryCheckCard:function(){let e;e=merchant.ingredients.length<5?merchant.ingredients.length:5;let t=[];for(let r=0;r<e;r++){let e=Math.floor(Math.random()*merchant.ingredients.length);t.includes(e)?r--:t[r]=e}let n=document.querySelector("#inventoryCheckCard ul"),i=document.getElementById("ingredientCheck").content.children[0];for(;n.children.length>0;)n.removeChild(n.firstChild);for(let r=0;r<t.length;r++){let e=i.cloneNode(!0),s=e.children[1].children[1];const a=merchant.ingredients[t[r]];e.ingredient=a,e.children[0].innerText=a.ingredient.name,e.children[1].children[0].onclick=()=>{s.value--,s.changed=!0},"bottle"===a.ingredient.specialUnit?(s.value=a.quantity.toFixed(2),e.children[2].innerText="BOTTLES"):(s.value=a.quantity.toFixed(2),e.children[2].innerText=a.ingredient.unit.toUpperCase()),e.children[1].children[2].onclick=()=>{s.value++,s.changed=!0},s.onchange=()=>{s.changed=!0},n.appendChild(e)}document.getElementById("inventoryCheck").onclick=()=>{this.submitInventoryCheck()}},drawPopularCard:function(){let e=new Date;e.setDate(1);const t=merchant.getIngredientsSold(e);if(!1!==t){t.sort((e,t)=>e.quantity<t.quantity?1:e.quantity>t.quantity?-1:0);let e=[],n=[],i=[];for(let a=t.length<5?t.length-1:4;a>=0;a--){const r=t[a].ingredient.name,s=t[a].quantity,d=t[a].ingredient.unit;e.push(t[a].quantity),n.push(`${r}: ${s.toFixed(2)} ${d.toUpperCase()}`),0===a?i.push("rgb(255, 99, 107"):i.push("rgb(179, 191, 209")}let r={x:e,type:"bar",orientation:"h",text:n,textposition:"auto",hoverinfo:"none",marker:{color:i}},s={title:"MOST POPULAR INGREDIENTS",xaxis:{zeroline:!1,title:"QUANTITY"},yaxis:{showticklabels:!1}};Plotly.newPlot("popularIngredientsCard",[r],s)}else{document.getElementById("popularCanvas").style.display="none";let e=document.createElement("p");e.innerText="N/A",e.classList="notice",document.getElementById("popularIngredientsCard").appendChild(e)}},submitInventoryCheck:function(){let e=document.querySelectorAll("#inventoryCheckCard li"),t=[],n=[];for(let i=0;i<e.length;i++){if(!(e[i].children[1].children[1].value>=0))return void banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");{let r=e[i].ingredient;if(!0===e[i].children[1].children[1].changed){let s=0;s="bottle"===r.ingredient.specialUnit?parseFloat(e[i].children[1].children[1].value)*r.ingredient.unitSize:controller.convertToMain(r.ingredient.unit,parseFloat(e[i].children[1].children[1].value)),t.push({ingredient:r.ingredient,quantity:s}),n.push({id:r.ingredient.id,quantity:s}),e[i].children[1].children[1].changed=!1}}}if(n.length>0){let e=document.getElementById("loaderContainer");e.style.display="flex",fetch("/merchant/ingredients/update",{method:"PUT",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(n)}).then(e=>e.json()).then(e=>{if("string"==typeof e)banner.createError(e);else{for(let e=0;e<t.length;e++)merchant.updateIngredient(t[e].ingredient,t[e].quantity);banner.createNotification("INGREDIENTS UPDATED")}}).catch(e=>{}).finally(()=>{e.style.display="none"})}}};var t={isPopulated:!1,ingredients:[],display:function(){this.isPopulated||(document.getElementById("ingredientSearch").oninput=()=>{this.search()},this.populateByProperty(),this.isPopulated=!0)},populateByProperty:function(){let e;e=merchant.categorizeIngredients();let t=document.getElementById("categoryList"),n=document.getElementById("categoryDiv").content.children[0],i=document.getElementById("ingredient").content.children[0];for(this.ingredients=[];t.children.length>0;)t.removeChild(t.firstChild);for(let r=0;r<e.length;r++){let s=n.cloneNode(!0);s.children[0].children[0].innerText=e[r].name.toUpperCase(),s.children[0].onclick=()=>{this.toggleCategory(s.children[1],s.children[0].children[1])},s.children[1].style.display="none",t.appendChild(s);for(let t=0;t<e[r].ingredients.length;t++){let n=e[r].ingredients[t],a=i.cloneNode(!0);a.children[0].innerText=n.ingredient.name,a.onclick=()=>{controller.openSidebar("ingredientDetails",n),a.classList.add("active")},a._name=n.ingredient.name.toLowerCase(),a._unit=n.ingredient.unit.toLowerCase(),"bottle"===n.ingredient.specialUnit?a.children[2].innerText=n.quantity.toFixed(2)+" BOTTLES":a.children[2].innerText=`${n.quantity.toFixed(2)} ${n.ingredient.unit.toUpperCase()}`,s.children[1].appendChild(a),this.ingredients.push(a)}}},displayIngredientsOnly:function(e){let t=document.getElementById("categoryList");for(;t.children.length>0;)t.removeChild(t.firstChild);for(let n=0;n<e.length;n++)t.appendChild(e[n])},toggleCategory:function(e,t){"none"===e.style.display?(t.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"></polyline></svg>',e.style.display="flex"):"flex"===e.style.display&&(t.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>',e.style.display="none")},search:function(){let e=document.getElementById("ingredientSearch").value.toLowerCase();if(""===e)return void this.populateByProperty();let t=[];for(let n=0;n<this.ingredients.length;n++)this.ingredients[n]._name.includes(e)&&t.push(this.ingredients[n]);this.displayIngredientsOnly(t)}};var n={isPopulated:!1,recipeDivList:[],display:function(e){this.isPopulated||(this.populateRecipes(),"none"!==merchant.pos&&(document.getElementById("posUpdateRecipe").onclick=()=>{this.posUpdate(e)}),document.getElementById("recipeSearch").oninput=()=>{this.search()},this.populateRecipes(),this.isPopulated=!0)},populateRecipes:function(){let e=document.getElementById("recipeList"),t=document.getElementById("recipe").content.children[0];for(this.recipeDivList=[];e.children.length>0;)e.removeChild(e.firstChild);for(let n=0;n<merchant.recipes.length;n++){let i=t.cloneNode(!0);i.onclick=()=>{controller.openSidebar("recipeDetails",merchant.recipes[n]),i.classList.add("active")},i._name=merchant.recipes[n].name,e.appendChild(i),i.children[0].innerText=merchant.recipes[n].name,i.children[1].innerText="$"+merchant.recipes[n].price.toFixed(2),this.recipeDivList.push(i)}},search:function(){let e=document.getElementById("recipeSearch").value.toLowerCase(),t=document.getElementById("recipeList"),n=[];for(let i=0;i<this.recipeDivList.length;i++)this.recipeDivList[i]._name.toLowerCase().includes(e)&&n.push(this.recipeDivList[i]);for(;t.children.length>0;)t.removeChild(t.firstChild);for(let i=0;i<n.length;i++)t.appendChild(n[i])},posUpdate:function(e){let t=document.getElementById("loaderContainer");t.style.display="flex";let n="/recipe/update/"+merchant.pos;fetch(n,{method:"GET",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{for(let n=0;n<t.new.length;n++){const i=new e(t.new[n]._id,t.new[n].name,t.new[n].price,merchant,[]);merchant.addRecipe(i)}for(let e=0;e<t.removed.length;e++)for(let n=0;n<merchant.recipes.length;n++)if(merchant.recipes[n].id===t.removed[e]._id){merchant.removeRecipe(merchant.recipes[n]);break}this.display()}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var i={newData:!1,dateChange:!1,transactions:[],ingredient:{},recipe:{},display:function(e){if(document.getElementById("analDateBtn").onclick=()=>{this.changeDates(e)},0===this.transactions.length||!0===this.newData){let e=new Date;e.setMonth(e.getMonth()-1),this.transactions=merchant.getTransactions(e)}let t=document.getElementById("analSlider");t.onchange=()=>{this.display(e)};let n=document.getElementById("analIngredientContent"),i=document.getElementById("analRecipeContent");t.checked?(n.style.display="none",i.style.display="flex",this.displayRecipes()):(n.style.display="flex",i.style.display="none",this.displayIngredients())},displayIngredients:function(){const e=document.getElementById("itemsList");for(;e.children.length>0;)e.removeChild(e.firstChild);for(let t=0;t<merchant.ingredients.length;t++){let n=document.createElement("li");n.classList.add("choosable"),n.item=merchant.ingredients[t],n.innerText=merchant.ingredients[t].ingredient.name,n.onclick=()=>{const e=document.getElementById("itemsList");for(let t=0;t<e.children.length;t++)e.children[t].classList.remove("active");n.classList.add("active"),this.ingredient=merchant.ingredients[t],this.ingredientDisplay()},e.appendChild(n)}this.dateChange&&0!==Object.keys(this.ingredient).length&&this.ingredientDisplay(),this.dateChange=!1},displayRecipes:function(){let e=document.getElementById("analRecipeList");for(;e.children.length>0;)e.removeChild(e.firstChild);for(let t=0;t<merchant.recipes.length;t++){let n=document.createElement("li");n.classList.add("choosable"),n.recipe=merchant.recipes[t],n.innerText=merchant.recipes[t].name,n.onclick=()=>{let e=document.getElementById("analRecipeList");for(let t=0;t<e.children.length;t++)e.children[t].classList.remove("active");n.classList.add("active"),this.recipe=merchant.recipes[t],this.recipeDisplay()},e.appendChild(n)}this.dateChange&&0!==Object.keys(this.recipe).length&&this.recipeDisplay(),this.dateChange=!1},ingredientDisplay:function(){let e=[];for(let u=0;u<merchant.recipes.length;u++)for(let t=0;t<merchant.recipes[u].ingredients.length;t++)if(merchant.recipes[u].ingredients[t].ingredient===this.ingredient.ingredient){e.push({recipe:merchant.recipes[u],quantity:merchant.recipes[u].ingredients[t].quantity});break}let t=[],n=[],i=this.transactions.length>0?this.transactions[0].date:void 0,r=0;for(let u=0;u<this.transactions.length;u++){i.getDate()!==this.transactions[u].date.getDate()&&(t.push(r),n.push(i),r=0,i=this.transactions[u].date);for(let t=0;t<this.transactions[u].recipes.length;t++)for(let n=0;n<e.length;n++)if(this.transactions[u].recipes[t].recipe===e[n].recipe)for(let e=0;e<this.transactions[u].recipes[t].recipe.ingredients.length;e++){const n=this.transactions[u].recipes[t].recipe.ingredients[e];if(n.ingredient===this.ingredient.ingredient){r+=n.quantity*this.transactions[u].recipes[t].quantity;break}}u===this.transactions.length-1&&(t.push(r),n.push(i))}let s={x:n,y:t,mode:"lines+markers",line:{color:"rgb(255, 99, 107)"}};const a={title:this.ingredient.ingredient.name.toUpperCase(),xaxis:{title:"DATE"},yaxis:{title:`QUANTITY (${this.ingredient.ingredient.unit.toUpperCase()})`}};Plotly.newPlot("itemUseGraph",[s],a);let d=0,l=0,c=t.length>0?t[0]:0;for(let u=0;u<t.length;u++)d+=t[u],t[u]>l?l=t[u]:t[u]<c&&(c=t[u]);document.getElementById("analMinUse").innerText=`${c.toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analAvgUse").innerText=`${(d/t.length).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analMaxUse").innerText=`${l.toFixed(2)} ${this.ingredient.ingredient.unit}`;let o=[0,0,0,0,0,0,0],h=[0,0,0,0,0,0,0];for(let u=0;u<t.length;u++)o[n[u].getDay()]+=t[u],h[n[u].getDay()]++;document.getElementById("analDayOne").innerText=`${(o[0]/h[0]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDayTwo").innerText=`${(o[1]/h[1]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDayThree").innerText=`${(o[2]/h[2]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDayFour").innerText=`${(o[3]/h[3]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDayFive").innerText=`${(o[4]/h[4]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDaySix").innerText=`${(o[5]/h[5]).toFixed(2)} ${this.ingredient.ingredient.unit}`,document.getElementById("analDaySeven").innerText=`${(o[6]/h[6]).toFixed(2)} ${this.ingredient.ingredient.unit}`},recipeDisplay:function(){let e,t=[],n=[],i=0;this.transactions.length>0&&(e=this.transactions[0].date);for(let d=0;d<this.transactions.length;d++){e.getDate()!==this.transactions[d].date.getDate()&&(t.push(i),i=0,n.push(e),e=this.transactions[d].date);for(let e=0;e<this.transactions[d].recipes.length;e++){const t=this.transactions[d].recipes[e];t.recipe===this.recipe&&(i+=t.quantity)}d===this.transactions.length-1&&(t.push(i),n.push(e))}const r={x:n,y:t,mode:"lines+markers",line:{color:"rgb(255, 99, 107"}},s={title:this.recipe.name.toUpperCase(),xaxis:{title:"DATE"},yaxis:{title:"Quantity"}};Plotly.newPlot("recipeSalesGraph",[r],s);let a=0;for(let d=0;d<t.length;d++)a+=t[d];document.getElementById("recipeAvgUse").innerText=(a/t.length).toFixed(2),document.getElementById("recipeAvgRevenue").innerText="$"+(a/t.length*this.recipe.price/100).toFixed(2)},changeDates:function(e){let t={from:document.getElementById("analStartDate").valueAsDate,to:document.getElementById("analEndDate").valueAsDate};if(t.from>t.to||""===t.from||""===t.to||t.to>new Date)return void banner.createError("INVALID DATE");let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/transaction/retrieve",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t.data);else{this.transactions=[];for(let i=0;i<t.length;i++)this.transactions.push(new e(t[i]._id,new Date(t[i].date),t[i].recipes,merchant));let n=document.getElementById("analSlider").checked;n&&0!==Object.keys(this.recipe).length?this.recipeDisplay():n||0===Object.keys(this.ingredient).length||this.ingredientDisplay(),this.dateChange=!0}}).catch(e=>{banner.createError("ERROR: UNABLE TO DISPLAY THE DATA")}).finally(()=>{n.style.display="none"})}};var r={orders:[],display:function(){document.getElementById("orderFilterBtn").onclick=()=>{controller.openSidebar("orderFilter")},document.getElementById("newOrderBtn").onclick=()=>{controller.openSidebar("newOrder")};let e=document.getElementById("orderList"),t=document.getElementById("order").content.children[0];for(;e.children.length>0;)e.removeChild(e.firstChild);for(let n=0;n<this.orders.length;n++){let i=t.cloneNode(!0);i.order=this.orders[n],i.children[0].innerText=this.orders[n].name,i.children[1].innerText=this.orders[n].ingredients.length+" ingredients",i.children[2].innerText=this.orders[n].date.toLocaleDateString("en-US"),i.children[3].innerText="$"+this.orders[n].getTotalCost().toFixed(2),i.onclick=()=>{controller.openSidebar("orderDetails",this.orders[n]),i.classList.add("active")},e.appendChild(i)}},getOrders:function(e){let t=document.getElementById("loaderContainer");return t.style.display="flex",fetch("/order",{method:"get",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>e.json()).then(t=>{if("string"!=typeof t){let n=[];for(let i=0;i<t.length;i++)n.push(new e(t[i]._id,t[i].name,t[i].date,t[i].taxes,t[i].fees,t[i].ingredients,merchant));return 0===merchant.orders.length&&merchant.setOrders(n),n}banner.createError(t)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var s={transactions:[],display:function(e){document.getElementById("filterTransactionsButton").onclick=()=>{controller.openSidebar("transactionFilter")},document.getElementById("newTransactionButton").onclick=()=>{controller.openSidebar("newTransaction")},this.populateTransactions(this.transactions),this.isPopulated=!0},populateTransactions:function(e){let t=document.getElementById("transactionsList"),n=document.getElementById("transaction").content.children[0];for(;t.children.length>0;)t.removeChild(t.firstChild);let i=0;for(;i<e.length&&i<100;){let r=n.cloneNode(!0),s=e[i];r.onclick=()=>{controller.openSidebar("transactionDetails",s),r.classList.add("active")},t.appendChild(r);let a=0,d=0;for(let t=0;t<e[i].recipes.length;t++)a+=e[i].recipes[t].quantity,d+=e[i].recipes[t].recipe.price*e[i].recipes[t].quantity;r.children[0].innerText=`${e[i].date.toLocaleDateString()} ${e[i].date.toLocaleTimeString()}`,r.children[1].innerText=a+" recipes sold",r.children[2].innerText="$"+d.toFixed(2),i++}}};var a={dailyUse:0,display:function(e){document.getElementById("editIngBtn").onclick=()=>{controller.openSidebar("editIngredient",e)},document.getElementById("removeIngBtn").onclick=()=>{this.remove(e)},document.getElementById("ingredientDetailsCategory").innerText=e.ingredient.category,document.getElementById("ingredientDetailsName").innerText=e.ingredient.name,document.getElementById("ingredientStock").innerText=e.getQuantityDisplay();let t=[],n=new Date;for(let c=1;c<31;c++){let i=new Date(n.getFullYear(),n.getMonth(),n.getDate()-c),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-c-1);t.push(merchant.getSingleIngredientSold(e,r,i))}let i=0;for(let c=0;c<t.length;c++)i+=t[c];let r=i/t.length;const s=document.getElementById("dailyUse");"bottle"===e.ingredient.specialUnit?s.innerText=r.toFixed(2)+" BOTTLES":s.innerText=`${r.toFixed(2)} ${e.ingredient.unit.toUpperCase()}`;let a=document.getElementById("ingredientRecipeList"),d=document.getElementById("ingredientRecipe").content.children[0],l=merchant.getRecipesForIngredient(e.ingredient);for(;a.children.length>0;)a.removeChild(a.firstChild);for(let c=0;c<l.length;c++){let e=d.cloneNode(!0);e.children[0].innerText=l[c].name,e.onclick=()=>{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",l[c])},e.classList.add("choosable"),a.appendChild(e)}},remove:function(e){for(let n=0;n<merchant.recipes.length;n++)for(let t=0;t<merchant.recipes[n].ingredients.length;t++)if(e.ingredient===merchant.recipes[n].ingredients[t].ingredient)return void banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/ingredients/remove/"+e.ingredient.id,{method:"delete"}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.removeIngredient(e),controller.openStrand("ingredients"),banner.createNotification("INGREDIENT REMOVED"))}).catch(e=>{}).finally(()=>{t.style.display="none"})}};var d={display:function(e){const t=document.getElementById("unitSelector");document.getElementById("newIngName").value="",document.getElementById("newIngCategory").value="",document.getElementById("newIngQuantity").value=0,document.getElementById("bottleSizeLabel").style.display="none",t.value="g",t.onchange=()=>{this.unitChange()},document.getElementById("submitNewIng").onclick=()=>{this.submit(e)}},unitChange:function(){const e=document.getElementById("unitSelector"),t=document.getElementById("bottleSizeLabel");"bottle"===e.value?t.style.display="block":t.style.display="none"},submit:function(e){let n=document.getElementById("unitSelector"),i=document.querySelectorAll("#unitSelector option");const r=parseFloat(document.getElementById("newIngQuantity").value);let s=n.value,a={ingredient:{name:document.getElementById("newIngName").value,category:document.getElementById("newIngCategory").value,unitType:i[n.selectedIndex].getAttribute("type")},quantity:r,defaultUnit:s};"bottle"===s&&(a.ingredient.unitType="volume",a.ingredient.unitSize=document.getElementById("bottleSize").value,a.defaultUnit=document.getElementById("bottleUnits").value,a.ingredient.specialUnit=s,a.quantity=r);let d=document.getElementById("loaderContainer");d.style.display="flex",fetch("/ingredients/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(a)}).then(e=>e.json()).then(n=>{if("string"==typeof n)banner.createError(n);else{const i=new e(n.ingredient._id,n.ingredient.name,n.ingredient.category,n.ingredient.unitType,n.defaultUnit,merchant,n.ingredient.specialUnit,n.ingredient.unitSize);merchant.addIngredient(i,n.quantity),t.display(),controller.closeSidebar(),banner.createNotification("INGREDIENT CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{d.style.display="none"})}},l=class{constructor(e,t,n,i,r,s,a,d){return this.isSanitaryString(t)?this.isSanitaryString(n)?(this._id=e,this._name=t,this._category=n,this._unitType=i,this._unit=r,this._parent=s,void(a&&(this._specialUnit=a,this._unitSize=d))):(banner.createError("CATEGORY CONTAINS ILLEGAL CHARACTERS"),!1):(banner.createError("NAME CONTAINS ILLEGAL CHARCTERS"),!1)}get id(){return this._id}get name(){return this._name}set name(e){if(!this.isSanitaryString(e))return!1;this._name=e}get category(){return this._category}set category(e){if(!this.isSanitaryString(e))return!1;this._category=e}get unitType(){return this._unitType}get unit(){return this._unit}set unit(e){this._unit=e}get parent(){return this._parent}get specialUnit(){return this._specialUnit}get unitSize(){switch(this._unit){case"g":return this._unitSize;case"kg":return this._unitSize/1e3;case"oz":return this._unitSize/28.3495;case"lb":return this._unitSize/453.5924;case"ml":return 1e3*this._unitSize;case"l":return this._unitSize;case"tsp":return 202.8842*this._unitSize;case"tbsp":return 67.6278*this._unitSize;case"ozfl":return 33.8141*this._unitSize;case"cup":return 4.1667*this._unitSize;case"pt":return 2.1134*this._unitSize;case"qt":return 1.0567*this._unitSize;case"gal":return this._unitSize/3.7854;case"mm":return 1e3*this._unitSize;case"cm":return 100*this._unitSize;case"m":return this._unitSize;case"in":return 39.3701*this._unitSize;case"ft":return 3.2808*this._unitSize;default:return this._unitSize}}set unitSize(e){if(e<0)return!1;this._unitSize=e}getNameAndUnit(){return"bottle"===this._specialUnit?this._name+" (BOTTLES)":`${this._name} (${this._unit.toUpperCase()})`}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}};var c={display:function(e){let t=document.getElementById("unitButtons"),n=document.getElementById("editIngQuantityLabel"),i=document.getElementById("editSpecialLabel");for(;t.children.length>0;)t.removeChild(t.firstChild);document.getElementById("editIngTitle").innerText=e.ingredient.name,document.getElementById("editIngName").value=e.ingredient.name,document.getElementById("editIngCategory").value=e.ingredient.category,n.innerText=`CURRENT STOCK (${e.ingredient.unit.toUpperCase()})`,document.getElementById("editIngSubmit").onclick=()=>{this.submit(e)};const r=merchant.units[e.ingredient.unitType];for(let a=0;a<r.length;a++){let n=document.createElement("button");n.classList.add("unitButton"),n.innerText=r[a].toUpperCase(),n.onclick=()=>{this.changeUnit(n)},t.appendChild(n),r[a]===e.ingredient.unit&&n.classList.add("unitActive")}if("bottle"===e.ingredient.specialUnit){n.innerText="CURRENT STOCK (BOTTLES):",i.style.display="flex",i.innerText=`BOTTLE SIZE (${e.ingredient.unit.toUpperCase()}):`;let t=document.createElement("input");t.id="editIngSpecialSize",t.type="number",t.min="0",t.step="0.01",t.value=e.ingredient.unitSize.toFixed(2),i.appendChild(t)}else i.style.display="none";let s=document.createElement("input");s.id="editIngQuantity",s.type="number",s.min="0",s.step="0.01",s.value=e.quantity.toFixed(2),n.appendChild(s)},changeUnit(e){let t=document.getElementById("unitButtons");for(let n=0;n<t.children.length;n++)t.children[n].classList.remove("unitActive");e.classList.add("unitActive")},submit(e){const t=parseFloat(document.getElementById("editIngQuantityLabel").children[0].value);let n={id:e.ingredient.id,name:document.getElementById("editIngName").value,category:document.getElementById("editIngCategory").value};if("bottle"===e.ingredient.specialUnit){let i=e.convertToBase(parseFloat(document.getElementById("editSpecialLabel").children[0].value));n.quantity=t*i,n.unitSize=i}else n.quantity=e.convertToBase(t);let i=document.getElementById("unitButtons");for(let s=0;s<i.children.length;s++)if(i.children[s].classList.contains("unitActive")){n.unit=i.children[s].innerText.toLowerCase();break}let r=document.getElementById("loaderContainer");r.style.display="flex",fetch("/ingredients/update",{method:"put",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(n)}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(e.ingredient.name=t.ingredient.name,e.ingredient.category=t.ingredient.category,e.ingredient.unitSize=t.ingredient.unitSize,e.ingredient.unit=t.unit,merchant.updateIngredient(e,t.quantity),controller.openStrand("ingredients"),banner.createNotification("INGREDIENT UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{r.style.display="none"})}};var o={display:function(e){document.getElementById("sidebarDiv").classList.add("sidebarWide"),document.getElementById("newOrderIngredientList").style.display="flex";let t=document.getElementById("selectedIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("newOrderIngredients");for(;n.children.length>0;)n.removeChild(n.firstChild);for(let i=0;i<merchant.ingredients.length;i++){let e=document.createElement("button");e.classList="choosable",e.innerText=merchant.ingredients[i].ingredient.name,e.onclick=()=>{this.addIngredient(merchant.ingredients[i],e)},n.appendChild(e)}document.getElementById("submitNewOrder").onclick=()=>{this.submit(e)}},addIngredient:function(e,t){t.style.display="none";let n=document.getElementById("selectedIngredient").content.children[0].cloneNode(!0);n.ingredient=e,n.children[0].children[1].onclick=()=>{this.removeIngredient(n,t)},"bottle"===e.ingredient.specialUnit?n.children[0].children[0].innerText=e.ingredient.name+" (BOTTLES)":n.children[0].children[0].innerText=`${e.ingredient.name} (${e.ingredient.unit.toUpperCase()})`,document.getElementById("selectedIngredientList").appendChild(n)},removeIngredient:function(e,t){e.parentElement.removeChild(e),t.style.display="block"},submit:function(e){let t=document.getElementById("newOrderDate").value,n=100*document.getElementById("orderTaxes").value,i=100*document.getElementById("orderFees").value,r=document.getElementById("selectedIngredientList").children;if(""===t)return void banner.createError("DATE IS REQUIRED FOR ORDERS");let s={name:document.getElementById("newOrderName").value,date:t,taxes:n,fees:i,ingredients:[]};for(let d=0;d<r.length;d++){let e=r[d].children[1].children[0].value,t=r[d].children[1].children[1].value;if(""===e||""===t)return void banner.createError("MUST PROVIDE QUANTITY AND PRICE PER UNIT FOR ALL INGREDIENTS");(e<0||t<0)&&banner.createError("QUANTITY AND PRICE MUST BE NON-NEGATIVE NUMBERS"),"bottle"===r[d].ingredient.ingredient.specialUnit?s.ingredients.push({ingredient:r[d].ingredient.ingredient.id,quantity:e*r[d].ingredient.ingredient.unitSize,pricePerUnit:this.convertPrice(r[d].ingredient.ingredient,100*t)}):s.ingredients.push({ingredient:r[d].ingredient.ingredient.id,quantity:r[d].ingredient.convertToBase(e),pricePerUnit:this.convertPrice(r[d].ingredient.ingredient,100*t)})}let a=document.getElementById("loaderContainer");a.style.display="flex",fetch("/order/create",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(s)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=new e(t._id,t.name,t.date,t.taxes,t.fees,t.ingredients,merchant);merchant.addOrder(n,!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}}};var h={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)}},changeIngredientCount:function(e){let t=document.getElementById("ingredientCount").value,n=document.getElementById("recipeInputIngredients"),i=document.getElementById("recipeInputIngredient").content.children[0],r=n.children.length;if(t>r){let s=t-r;for(let t=0;t<s;t++){let s=i.cloneNode(!0);s.children[0].innnerText="INGREDIENT "+(t+r),s.children[2].children[0].value=0;for(let t=0;t<e.length;t++){let n=document.createElement("optgroup");n.label=e[t].name;for(let i=0;i<e[t].ingredients.length;i++){let r=document.createElement("option");r.innerText=e[t].ingredients[i].ingredient.getNameAndUnit(),r.ingredient=e[t].ingredients[i],n.appendChild(r)}s.children[1].children[0].appendChild(n)}n.appendChild(s)}for(let e=0;e<t;e++)n.children[e].children[0].innerText="INGREDIENT "+(e+1)}else if(t<r){let e=r-t;for(let t=0;t<e;t++)n.removeChild(n.children[n.children.length-1])}},submit:function(e){let t={name:document.getElementById("newRecipeName").value,price:document.getElementById("newRecipePrice").value,ingredients:[]},n=document.getElementById("recipeInputIngredients").children;for(let r=0;r<n.length;r++){let e=n[r].children[1].children[0],i=e.options[e.selectedIndex].ingredient;t.ingredients.push({ingredient:i.ingredient.id,quantity:i.convertToBase(n[r].children[2].children[0].value)})}let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/recipe/create",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{if("string"==typeof t)banner.createError(t);else{let n=[];for(let e=0;e<t.ingredients.length;e++)for(let i=0;i<merchant.ingredients.length;i++)if(merchant.ingredients[i].ingredient.id===t.ingredients[e].ingredient){n.push({ingredient:merchant.ingredients[i].ingredient,quantity:t.ingredients[e].quantity});break}merchant.addRecipe(new e(t._id,t.name,t.price,n,merchant)),banner.createNotification("RECIPE CREATED"),controller.openStrand("recipeBook")}}).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("editRecipeName");"none"===merchant.pos?t.value=e.name:(document.getElementById("editRecipeNoName").innertext=e.name,t.parentNode.style.display="none");let n=document.getElementById("editRecipeIngList");for(;n.children.length>0;)n.removeChild(n.firstChild);let i=document.getElementById("editRecipeIng").content.children[0];for(let r=0;r<e.ingredients.length;r++){let t=i.cloneNode(!0);t.children[0].onclick=()=>{t.parentNode.removeChild(t)},t.children[1].innerText=e.ingredients[r].ingredient.getNameAndUnit(),t.children[2].style.display="none",t.children[3].value=e.ingredients[r].quantity,t.ingredient=e.ingredients[r],n.appendChild(t)}document.getElementById("addRecIng").onclick=()=>{this.newIngredient()},document.getElementById("editRecipePrice").value=e.price,document.getElementById("editRecipeSubmit").onclick=()=>{this.submit(e)},document.getElementById("editRecipeCancel").onclick=()=>{controller.openSidebar("recipeDetails",e)}},newIngredient:function(){let e=document.getElementById("editRecipeIngList"),t=document.getElementById("editRecipeIng").content.children[0].cloneNode(!0);t.children[0].onclick=()=>{t.parentNode.removeChild(t)},t.children[1].style.display="none",t.children[3].value="0.00";let n=merchant.categorizeIngredients();for(let i=0;i<n.length;i++){let e=document.createElement("optgroup");e.label=n[i].name;for(let t=0;t<n[i].ingredients.length;t++){let r=document.createElement("option");r.innerText=n[i].ingredients[t].ingredient.getNameAndUnit(),r.ingredient=n[i].ingredients[t],e.appendChild(r)}t.children[2].appendChild(e)}e.appendChild(t)},submit:function(e){let t={id:e.id,name:e.name,price:100*document.getElementById("editRecipePrice").value,ingredients:[]};"none"===merchant.pos&&(t.name=document.getElementById("editRecipeName").value);let n=document.getElementById("editRecipeIngList").children;for(let r=0;r<n.length;r++){const e=parseFloat(n[r].children[3].value);if("none"===n[r].children[1].style.display){let i=n[r].children[2],s=i.options[i.selectedIndex].ingredient;t.ingredients.push({ingredient:s.ingredient.id,quantity:s.convertToBase(e)})}else t.ingredients.push({ingredient:n[r].ingredient.ingredient.id,quantity:n[r].ingredient.convertToBase(e)})}let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/recipe/update",{method:"put",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(e=>{"string"==typeof e?banner.createError(e):(merchant.updateRecipe(e),controller.openStrand("recipeBook"),banner.createNotification("RECIPE UPDATED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE")}).finally(()=>{i.style.display="none"})}};var g={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:[],ingredientUpdates:{}};for(let r=0;r<t.children.length;r++){let e=t.children[r].children[1].value;const n=t.children[r].recipe;if(""!==e&&e>0){i.recipes.push({recipe:n.id,quantity:e});for(let t=0;t<n.ingredients.length;t++){let r=n.ingredients[t];i.ingredientUpdates[r.ingredient.id]?i.ingredientUpdates[r.ingredient.id]+=r.convertToBase(r.quantity)*e:i.ingredientUpdates[r.ingredient.id]=r.convertToBase(r.quantity)*e}}else if(e<0)return void banner.createError("CANNOT HAVE NEGATIVE VALUES")}if(i.recipes.length>0){let 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{const n=new e(t._id,t.date,t.recipes,merchant);merchant.addTransaction(n),controller.openStrand("transactions",merchant.getTransactions()),banner.createNotification("TRANSACTION CREATED")}}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}}};var p={display:function(e){document.getElementById("removeOrderBtn").onclick=()=>{this.remove(e)},document.getElementById("orderDetailName").innerText=e.name,document.getElementById("orderDetailDate").innerText=e.date.toLocaleDateString("en-US"),document.getElementById("orderDetailTax").innerText="$"+e.taxes.toFixed(2),document.getElementById("orderDetailFee").innerText="$"+e.fees.toFixed(2);let t=document.getElementById("orderIngredients");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("orderIngredient").content.children[0];for(let i=0;i<e.ingredients.length;i++){let r=n.cloneNode(!0);const s=e.ingredients[i].ingredient;r.children[0].innerText=e.ingredients[i].ingredient.name,r.children[2].innerText="$"+e.ingredients[i].cost().toFixed(2),r.onclick=()=>{controller.openStrand("ingredients"),controller.openSidebar("ingredientDetails",merchant.getIngredient(e.ingredients[i].ingredient.id))};let a=r.children[1];"bottle"===s.specialUnit?a.innerText=`${e.ingredients[i].quantity.toFixed(2)} bottles x $${e.ingredients.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 m={display:function(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()-30),i=document.getElementById("orderFilterIngredients");for(document.getElementById("orderFilterDateFrom").valueAsDate=n,document.getElementById("orderFilterDateTo").valueAsDate=t;i.children.length>0;)i.removeChild(i.firstChild);for(let r=0;r<merchant.ingredients.length;r++){let e=document.createElement("div");e.classList.add("choosable"),e.ingredient=merchant.ingredients[r].ingredient.id,e.onclick=()=>{this.toggleActive(e)},i.appendChild(e);let t=document.createElement("p");t.innerText=merchant.ingredients[r].ingredient.name,e.appendChild(t)}document.getElementById("orderFilterSubmit").onclick=()=>{this.submit(e)}},toggleActive:function(e){e.classList.contains("active")?e.classList.remove("active"):e.classList.add("active")},submit:function(e){let t={startDate:document.getElementById("orderFilterDateFrom").valueAsDate,endDate:document.getElementById("orderFilterDateTo").valueAsDate,ingredients:[]};if(t.startDate>=t.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let n=document.getElementById("orderFilterIngredients").children;for(let r=0;r<n.length;r++)n[r].classList.contains("active")&&t.ingredients.push(n[r].ingredient);if(0===t.ingredients.length)for(let r=0;r<merchant.ingredients.length;r++)t.ingredients.push(merchant.ingredients[r].ingredient.id);let i=document.getElementById("loaderContainer");i.style.display="flex",fetch("/order",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(t)}).then(e=>e.json()).then(t=>{let n=[];if("string"==typeof t)banner.createError(t);else if(0===t.length)banner.createError("NO ORDERS MATCH YOUR SEARCH");else for(let i=0;i<t.length;i++)n.push(new e(t[i]._id,t[i].name,t[i].date,t[i].taxes,t[i].fees,t[i].ingredients,merchant));controller.openStrand("orders",n)}).catch(e=>{banner.createError("UNABLE TO DISPLAY THE ORDERS")}).finally(()=>{i.style.display="none"})}};var y={display:function(e){document.getElementById("editRecipeBtn").onclick=()=>{controller.openSidebar("editRecipe",e)},document.getElementById("recipeName").innerText=e.name,"none"===merchant.pos&&(document.getElementById("removeRecipeBtn").onclick=()=>{this.remove(e)});let t=document.getElementById("recipeIngredientList");for(;t.children.length>0;)t.removeChild(t.firstChild);let n=document.getElementById("recipeIngredient").content.children[0];for(let i=0;i<e.ingredients.length;i++){let r=n.cloneNode(!0);r.children[0].innerText=e.ingredients[i].ingredient.name,r.children[1].innerText=""+e.ingredients[i].getQuantityDisplay(),r.onclick=()=>{controller.openStrand("ingredients"),controller.openSidebar("ingredientDetails",merchant.getIngredient(e.ingredients[i].ingredient.id))},t.appendChild(r)}document.getElementById("recipePrice").children[1].innerText="$"+e.price.toFixed(2)},remove:function(e){let t=document.getElementById("loaderContainer");t.style.display="flex",fetch("/recipe/remove/"+e.id,{method:"delete"}).then(e=>e.json()).then(t=>{"string"==typeof t?banner.createError(t):(merchant.removeRecipe(e),banner.createNotification("RECIPE REMOVED"),controller.openStrand("recipeBook"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{t.style.display="none"})}};var E={transaction:{},display:function(e){this.transaction=e;let t=document.getElementById("transactionRecipes"),n=document.getElementById("transactionRecipe").content.children[0],i=0,r=0;for(;t.children.length>0;)t.removeChild(t.firstChild);for(let a=0;a<e.recipes.length;a++){let s=n.cloneNode(!0),d=e.recipes[a].quantity*e.recipes[a].recipe.price;s.children[0].innerText=e.recipes[a].recipe.name,s.children[1].innerText=`${e.recipes[a].quantity} x $${e.recipes[a].recipe.price.toFixed(2)}`,s.children[2].innerText="$"+d.toFixed(2),s.onclick=()=>{controller.openStrand("recipeBook"),controller.openSidebar("recipeDetails",e.recipes[a].recipe)},t.appendChild(s),i+=e.recipes[a].quantity,r+=d}let s=`${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e.date.getDay()]}, ${["January","February","March","April","May","June","July","August","September","October","November","December"][e.date.getMonth()]} ${e.date.getDate()}, ${e.date.getFullYear()}`;document.getElementById("transactionDate").innerText=s,document.getElementById("transactionTime").innerText=e.date.toLocaleTimeString(),document.getElementById("totalRecipes").innerText=i+" recipes",document.getElementById("totalPrice").innerText="$"+r.toFixed(2),"none"===merchant.pos&&(document.getElementById("removeTransBtn").onclick=()=>{this.remove()})},remove:function(){let e=document.getElementById("loaderContainer");e.style.display="flex",fetch("/transaction/"+this.transaction.id,{method:"delete",headers:{"Content-Type":"application/json;charset=utf-8"}}).then(e=>{"string"==typeof e?banner.createError(e):(merchant.removeTransaction(this.transaction),controller.openStrand("transactions",merchant.getTransactions()),banner.createNotification("TRANSACTION REMOVED"))}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{e.style.display="none"})}};class f{constructor(e,t){return t<0?(banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1):t%1!=0?(banner.createError("RECIPES WITHIN A TRANSACTION MUST BE WHOLE NUMBERS"),!1):(this._recipe=e,void(this._quantity=t))}get recipe(){return this._recipe}get quantity(){return this._quantity}}var I=class{constructor(e,t,n,i){if((t=new Date(t))>new Date)return banner.createError("DATE CANNOT BE SET TO THE FUTURE"),!1;this._id=e,this._parent=i,this._date=t,this._recipes=[];for(let r=0;r<n.length;r++)for(let e=0;e<i.recipes.length;e++)if(n[r].recipe===i.recipes[e].id){const t=new f(i.recipes[e],n[r].quantity);this._recipes.push(t);break}}get id(){return this._id}get parent(){return this._parent}get date(){return this._date}get recipes(){return this._recipes}};var T={display:function(){let e=new Date,t=new Date(e);t.setMonth(e.getMonth()-1),document.getElementById("transFilterDateStart").valueAsDate=t,document.getElementById("transFilterDateEnd").valueAsDate=e;let n=document.getElementById("transFilterRecipeList");for(;n.children.length>0;)n.removeChild(n.firstChild);for(let i=0;i<merchant.recipes.length;i++){let e=document.createElement("div");e.innerText=merchant.recipes[i].name,e.recipe=merchant.recipes[i],e.classList.add("choosable"),e.onclick=()=>{this.toggleActive(e)},n.appendChild(e)}document.getElementById("transFilterSubmit").onclick=()=>{this.submit()}},toggleActive:function(e){e.classList.contains("active")?e.classList.remove("active"):e.classList.add("active")},submit:function(){let e={startDate:document.getElementById("transFilterDateStart").valueAsDate,endDate:document.getElementById("transFilterDateEnd").valueAsDate,recipes:[]};if(e.startDate>=e.endDate)return void banner.createError("START DATE CANNOT BE AFTER END DATE");let t=document.getElementById("transFilterRecipeList").children;for(let i=0;i<t.length;i++)t[i].classList.contains("active")&&e.recipes.push(t[i].recipe.id);if(0===e.recipes.length)for(let i=0;i<merchant.recipes.length;i++)e.recipes.push(merchant.recipes[i].id);let n=document.getElementById("loaderContainer");n.style.display="flex",fetch("/transaction",{method:"post",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify(e)}).then(e=>e.json()).then(e=>{let t=[];if("string"==typeof e)banner.createError(e);else if(0===e.length)banner.createError("NO TRANSACTIONS MATCH YOUR SEARCH");else for(let n=0;n<e.length;n++)t.push(new I(e[n]._id,e[n].date,e[n].recipes,merchant));controller.openStrand("transactions",t)}).catch(e=>{banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE")}).finally(()=>{n.style.display="none"})}};class _{constructor(e,t){if(t<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;this._quantity=t,this._ingredient=e}get ingredient(){return this._ingredient}get quantity(){if("bottle"===this._ingredient.specialUnit)return this._quantity/this._ingredient._unitSize;switch(this._ingredient.unit){case"g":return this._quantity;case"kg":return this._quantity/1e3;case"oz":return this._quantity/28.3495;case"lb":return this._quantity/453.5924;case"ml":return 1e3*this._quantity;case"l":return this._quantity;case"tsp":return 202.8842*this._quantity;case"tbsp":return 67.6278*this._quantity;case"ozfl":return 33.8141*this._quantity;case"cup":return 4.1667*this._quantity;case"pt":return 2.1134*this._quantity;case"qt":return 1.0567*this._quantity;case"gal":return this._quantity/3.7854;case"mm":return 1e3*this._quantity;case"cm":return 100*this._quantity;case"m":return this._quantity;case"in":return 39.3701*this._quantity;case"ft":return 3.2808*this._quantity;default:return this._quantity}}updateQuantity(e){this._quantity+=this.convertToBase(e)}convertToBase(e){switch(this._ingredient.unit){case"g":return e;case"kg":return 1e3*e;case"oz":return 28.3495*e;case"lb":return 453.5924*e;case"ml":return e/1e3;case"l":return e;case"tsp":return e/202.8842;case"tbsp":return e/67.6278;case"ozfl":return e/33.8141;case"cup":return e/4.1667;case"pt":return e/2.1134;case"qt":return e/1.0567;case"gal":return 3.7854*e;case"mm":return e/1e3;case"cm":return e/100;case"m":return e;case"in":return e/39.3701;case"ft":return e/3.2808;default:return e}}getQuantityDisplay(){return"bottle"===this._ingredient.specialUnit?this.quantity.toFixed(2)+" BOTTLES":`${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`}}class B{constructor(e,t){if(t<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;this._ingredient=e,this._quantity=t}get ingredient(){return this._ingredient}get quantity(){if("bottle"===this._ingredient.specialUnit)return this._quantity/this._ingredient.unitSize;switch(this._ingredient.unit){case"g":return this._quantity;case"kg":return this._quantity/1e3;case"oz":return this._quantity/28.3495;case"lb":return this._quantity/453.5924;case"ml":return 1e3*this._quantity;case"l":return this._quantity;case"tsp":return 202.8842*this._quantity;case"tbsp":return 67.6278*this._quantity;case"ozfl":return 33.8141*this._quantity;case"cup":return 4.1667*this._quantity;case"pt":return 2.1134*this._quantity;case"qt":return 1.0567*this._quantity;case"gal":return this._quantity/3.7854;case"mm":return 1e3*this._quantity;case"cm":return 100*this._quantity;case"m":return this._quantity;case"in":return 39.3701*this._quantity;case"ft":return 3.2808*this._quantity;default:return this._quantity}}set quantity(e){if(e<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;this_quantity=this.convertToBase(e)}getQuantityDisplay(){return"bottle"===this._ingredient.specialUnit?this.quantity.toFixed(2)+" BOTTLES":`${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`}convertToBase(e){switch(this._ingredient.unit){case"g":return e;case"kg":return 1e3*e;case"oz":return 28.3495*e;case"lb":return 453.5924*e;case"ml":return e/1e3;case"l":return e;case"tsp":return e/202.8842;case"tbsp":return e/67.6278;case"ozfl":return e/33.8141;case"cup":return e/4.1667;case"pt":return e/2.1134;case"qt":return e/1.0567;case"gal":return 3.7854*e;case"mm":return e/1e3;case"cm":return e/100;case"m":return e;case"in":return e/39.3701;case"ft":return e/3.2808;default:return e}}}var b=class{constructor(e,t,n,i,r){if(n<0)return banner.createError("PRICE CANNOT BE A NEGATIVE NUMBER"),!1;if(!this.isSanitaryString(t))return banner.createError("NAME CONTAINS ILLEGAL CHARACTERS"),!1;this._id=e,this._name=t,this._price=n,this._parent=r,this._ingredients=[];for(let s=0;s<i.length;s++){const e=new B(i[s].ingredient,i[s].quantity);this._ingredients.push(e)}}get id(){return this._id}get name(){return this._name}set name(e){if(!this.isSanitaryString(e))return!1;this._name=e}get price(){return this._price/100}set price(e){if(e<0)return!1;this._price=e}get parent(){return this._parent}get ingredients(){return this._ingredients}addIngredient(e,t){if(t<0)return banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER"),!1;let n=new B(e,t);this._ingredients.push(n),this._parent.modules.recipeBook.isPopulated=!1,this._parent.modules.analytics.isPopulated=!1}removeIngredients(){this._ingredients=[]}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}};class S{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 v=class{constructor(e,t,n,i,r,s,a){if(!this.isSanitaryString(t))return!1;if(i<0)return!1;if(this._id=e,this._name=t,this._date=new Date(n),this._taxes=i,this._fees=r,this._ingredients=[],this._parent=a,n>new Date)return!1;for(let d=0;d<s.length;d++)for(let e=0;e<merchant.ingredients.length;e++)if(merchant.ingredients[e].ingredient.id===s[d].ingredient){this._ingredients.push(new S(merchant.ingredients[e].ingredient,s[d].quantity,s[d].pricePerUnit));break}this._parent.modules.ingredients.isPopulated=!1}get id(){return this._id}get name(){return this._name}get date(){return this._date}get taxes(){return this._taxes/100}get fees(){return this._fees/100}get parent(){return this._parent}get ingredients(){return this._ingredients}getIngredientCost(){let e=0;for(let t=0;t<this._ingredients.length;t++)e+=this._ingredients[t].cost();return e}getTotalCost(){return this.getIngredientCost()+this.taxes+this.fees}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}};merchant=new class{constructor(e,t,n){this._modules=n,this._name=e.name,this._pos=e.pos,this._ingredients=[],this._recipes=[],this._transactions=[],this._orders=[],this._units={mass:["g","kg","oz","lb"],volume:["ml","l","tsp","tbsp","ozfl","cup","pt","qt","gal"],length:["mm","cm","m","in","ft"],other:["each","bottle"]};for(let i=0;i<e.inventory.length;i++){const t=new n.Ingredient(e.inventory[i].ingredient._id,e.inventory[i].ingredient.name,e.inventory[i].ingredient.category,e.inventory[i].ingredient.unitType,e.inventory[i].defaultUnit,this,e.inventory[i].ingredient.specialUnit,e.inventory[i].ingredient.unitSize),r=new _(t,e.inventory[i].quantity);this._ingredients.push(r)}for(let i=0;i<e.recipes.length;i++){let t=[];for(let n=0;n<e.recipes[i].ingredients.length;n++){const r=e.recipes[i].ingredients[n];for(let e=0;e<this._ingredients.length;e++)if(r.ingredient===this._ingredients[e].ingredient.id){t.push({ingredient:this._ingredients[e].ingredient,quantity:r.quantity});break}}this._recipes.push(new this._modules.Recipe(e.recipes[i]._id,e.recipes[i].name,e.recipes[i].price,t,this))}for(let i=0;i<t.length;i++)this._transactions.push(new n.Transaction(t[i]._id,t[i].date,t[i].recipes,this))}get modules(){return this._modules}get name(){return this._name}set name(e){return this.isSanitaryString(e)&&(this._name=e),!1}get pos(){return this._pos}get ingredients(){return this._ingredients}addIngredient(e,t){const n=new _(e,t);this._ingredients.push(n),this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1}removeIngredient(e){const t=this._ingredients.indexOf(e);if(void 0===t)return!1;this._ingredients.splice(t,1),this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1}updateIngredient(e,t){const n=this._ingredients.indexOf(e);if(void 0===n)return!1;this._ingredients[n].quantity=t,this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1}getIngredient(e){for(let t=0;t<this._ingredients.length;t++)if(this._ingredients[t].ingredient.id===e)return this._ingredients[t]}get recipes(){return this._recipes}addRecipe(e){this._recipes.push(e),this._modules.recipeBook.isPopulated=!1}removeRecipe(e){const t=this._recipes.indexOf(e);if(void 0===t)return!1;this._recipes.splice(t,1),this._modules.recipeBook.isPopulated=!1}updateRecipe(e){for(let t=0;t<this._recipes.length;t++)if(this._recipes[t].id===e._id){this._recipes[t].name=e.name,this._recipes[t].price=e.price,this._recipes[t].removeIngredients();for(let n=0;n<e.ingredients.length;n++)for(let i=0;i<this._ingredients.length;i++)if(this._ingredients[i].ingredient.id===e.ingredients[n].ingredient){this._recipes[t].addIngredient(this._ingredients[i].ingredient,e.ingredients[n].quantity);break}break}this._modules.recipeBook.isPopulated=!1}getTransactions(e=0,t=new Date){if(merchant._transactions.length<=0)return[];0===e&&(e=this._transactions[this._transactions.length-1].date);const{start:n,end:i}=this.getTransactionIndices(e,t);return this._transactions.slice(n,i+1)}addTransaction(e){this._transactions.push(e),this._transactions.sort((e,t)=>e.date>t.date?-1:1);let t={};for(let i=0;i<e.recipes.length;i++){const n=e.recipes[i];for(let e=0;e<n.recipe.ingredients.length;e++){const i=n.recipe.ingredients[e];t[i.ingredient.id]?t[i.ingredient.id]+=n.quantity*i.quantity:t[i.ingredient.id]=n.quantity*i.quantity}}const n=Object.keys(t);for(let i=0;i<n.length;i++)for(let e=0;e<this._ingredients.length;e++)n[i]===this._ingredients[e].ingredient.id&&this._ingredients[e].updateQuantity(-t[n[i]]);this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1,this._modules.analytics.newData=!0}removeTransaction(e){const t=this._transactions.indexOf(e);if(void 0===t)return!1;this._transactions.splice(t,1);let n={};for(let r=0;r<e.recipes.length;r++){const t=e.recipes[r];for(let e=0;e<t.recipe.ingredients.length;e++){const i=t.recipe.ingredients[e];n[i.ingredient.id]?n[i.ingredient.id]+=i.quantity*t.quantity:n[i.ingredient.id]=i.quantity*t.quantity}}const i=Object.keys(n);for(let r=0;r<i.length;r++)for(let e=0;e<this._ingredients.length;e++)if(i[r]===this._ingredients[e].ingredient.id){this._ingredients[e].updateQuantity(n[i[r]]);break}this._modules.home.isPopulated=!1,this._modules.ingredients.isPopulated=!1,this._modules.analytics.newData=!0}get orders(){return this._orders}addOrder(e,t=!1){if(this._orders.push(e),t)for(let n=0;n<e.ingredients.length;n++)for(let t=0;t<this._ingredients.length;t++)if(e.ingredients[n].ingredient===this._ingredients[t].ingredient){this._ingredients[t].updateQuantity(e.ingredients[n].quantity);break}this._modules.ingredients.isPopulated=!1,this._modules.orders.isPopulated=!1}setOrders(e){this._orders=e}removeOrder(e){const t=this._orders.indexOf(e);if(void 0===t)return!1;this._orders.splice(t,1);for(let n=0;n<e.ingredients.length;n++)for(let t=0;t<this._ingredients.length;t++)if(e.ingredients[n].ingredient===this._ingredients[t].ingredient){this._ingredients[t].updateQuantity(-e.ingredients[n].quantity);break}this._modules.ingredients.isPopulated=!1,this._modules.orders.isPopulated=!1}get units(){return this._units}getRevenue(e,t=new Date){0===e&&(e=this._transactions[0].date);const{start:n,end:i}=this.getTransactionIndices(e,t);let r=0;for(let s=n;s<=i;s++)for(let e=0;e<this._transactions[s].recipes.length;e++)for(let t=0;t<this.recipes.length;t++)this._transactions[s].recipes[e].recipe===this.recipes[t]&&(r+=this._transactions[s].recipes[e].quantity*this.recipes[t].price);return r/100}getIngredientsSold(e=0,t=new Date){(e=0)&&(e=this._ingredients[0].date);let n=this.getRecipesSold(e,t),i=[];for(let r=0;r<n.length;r++)for(let e=0;e<n[r].recipe.ingredients.length;e++){let t=!1;for(let s=0;s<i.length;s++)i[s].ingredient===n[r].recipe.ingredients[e].ingredient&&(t=!0,i[s].quantity+=n[r].quantity*n[r].recipe.ingredients[e].quantity);t||i.push({ingredient:n[r].recipe.ingredients[e].ingredient,quantity:n[r].quantity*n[r].recipe.ingredients[e].quantity})}return i}getSingleIngredientSold(e,t=0,n=new Date){0===t&&(t=this._transactions[0].date);const{start:i,end:r}=this.getTransactionIndices(t,n);let s=0;for(let a=i;a<r;a++)for(let t=0;t<this._transactions[a].recipes.length;t++)for(let n=0;n<this._transactions[a].recipes[t].recipe.ingredients.length;n++)if(this._transactions[a].recipes[t].recipe.ingredients[n].ingredient===e.ingredient){s+=this._transactions[a].recipes[t].recipe.ingredients[n].quantity;break}return s}getRecipesSold(e=0,t=new Date){(e=0)&&(e=this._transactions[0].date);const{start:n,end:i}=this.getTransactionIndices(e,t);let r=[];for(let s=n;s<=i;s++)for(let e=0;e<this._transactions[s].recipes.length;e++){let t=!1;for(let n=0;n<r.length;n++)if(r[n].recipe===this._transactions[s].recipes[e].recipe){t=!0,r[n].quantity+=this._transactions[s].recipes[e].quantity;break}t||r.push({recipe:this._transactions[s].recipes[e].recipe,quantity:this._transactions[s].recipes[e].quantity})}return r}categorizeIngredients(){let e=[];for(let t=0;t<this.ingredients.length;t++){let n=!1;for(let i=0;i<e.length;i++)if(this.ingredients[t].ingredient.category===e[i].name){e[i].ingredients.push(this.ingredients[t]),n=!0;break}n||e.push({name:this.ingredients[t].ingredient.category,ingredients:[this.ingredients[t]]})}return e}unitizeIngredients(){let e=[];for(let t=0;t<this.ingredients.length;t++){let n=!1;const i=this.ingredients[t].ingredient;for(let r=0;r<e.length;r++)if(i.unit===e[r].name||i.specialUnit===e[r].name){e[r].ingredients.push(this.ingredients[t]),n=!0;break}if(!n){let n="";n="bottle"===i.specialUnit?"bottle":i.unit,e.push({name:n,ingredients:[this.ingredients[t]]})}}return e}getRecipesForIngredient(e){let t=[];for(let n=0;n<this._recipes.length;n++)for(let i=0;i<this._recipes[n].ingredients.length;i++)if(this._recipes[n].ingredients[i].ingredient===e){t.push(this._recipes[n]);break}return t}getTransactionIndices(e,t){let n,i;t.setDate(t.getDate()+1);for(let r=this._transactions.length-1;r>=0;r--)if(this._transactions[r].date>=e){n=r;break}for(let r=0;r<this._transactions.length;r++)if(this._transactions[r].date<t){i=r;break}return void 0!==n&&{start:i,end:n}}isSanitaryString(e){let t=["\\","<",">","$","{","}","(",")"];for(let n=0;n<t.length;n++)if(e.includes(t[n]))return!1;return!0}}(data.merchant,data.transactions,{home:e,ingredients:t,transactions:s,recipeBook:n,analytics:i,orders:r,Ingredient:l,Recipe:b,Transaction:I}),controller={openStrand:function(a,d){this.closeSidebar();let l=document.querySelectorAll(".strand");for(let e=0;e<l.length;e++)l[e].style.display="none";let c=document.querySelectorAll(".menuButton");for(let e=0;e<c.length-1;e++)c[e].classList="menuButton",c[e].disabled=!1;let o={};switch(a){case"home":o=document.getElementById("homeBtn"),document.getElementById("homeStrand").style.display="flex",e.display();break;case"ingredients":o=document.getElementById("ingredientsBtn"),document.getElementById("ingredientsStrand").style.display="flex",t.display();break;case"recipeBook":o=document.getElementById("recipeBookBtn"),document.getElementById("recipeBookStrand").style.display="flex",n.display(b);break;case"analytics":o=document.getElementById("analyticsBtn"),document.getElementById("analyticsStrand").style.display="flex",i.display(I);break;case"orders":o=document.getElementById("ordersBtn"),document.getElementById("ordersStrand").style.display="flex",r.orders=d,r.display(v);break;case"transactions":o=document.getElementById("transactionsBtn"),document.getElementById("transactionsStrand").style.display="flex",s.transactions=d,s.display(I)}o.classList="menuButton active",o.disabled=!0,window.screen.availWidth<=1e3&&this.closeMenu()},openSidebar:function(e,n={}){switch(this.closeSidebar(),document.getElementById("sidebarDiv").classList="sidebar",document.getElementById(e).style.display="flex",e){case"ingredientDetails":a.display(n,t);break;case"newIngredient":d.display(l);break;case"editIngredient":c.display(n);break;case"recipeDetails":y.display(n);break;case"editRecipe":u.display(n);break;case"addRecipe":h.display(b);break;case"orderDetails":p.display(n);break;case"orderFilter":m.display(v);break;case"newOrder":o.display(v);break;case"transactionDetails":E.display(n);break;case"transactionFilter":T.display();break;case"newTransaction":g.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++)if("none"!==e.children[t].style.display){e.children[t].style.display="none";let n=[];switch(e.children[t].id){case"ingredientDetails":n=document.querySelectorAll(".ingredient");break;case"transactionDetails":n=document.getElementById("transactionsList").children;break;case"recipeDetails":n=document.getElementById("recipeList").children;break;case"orderDetails":n=document.getElementById("orderList").children}for(let e=0;e<n.length;e++)n[e].classList.remove("active")}e.classList="sidebarHide",window.screen.availWidth<=1e3&&(document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").style.display="block",document.getElementById("sidebarCloser").style.display="none")},changeMenu:function(){let e=document.querySelector(".menu"),t=document.querySelectorAll(".menuButton");if(e.classList.contains("menuMinimized")){if(e.classList.contains("menuMinimized")){e.classList="menu";for(let e=0;e<t.length;e++)t[e].children[1].style.display="block";setTimeout(()=>{document.getElementById("max").style.display="flex",document.getElementById("min").style.display="none"},150)}}else{e.classList="menu menuMinimized";for(let e=0;e<t.length;e++)t[e].children[1].style.display="none";document.getElementById("max").style.display="none",document.getElementById("min").style.display="flex"}},openMenu:function(){document.getElementById("menu").style.display="flex",document.querySelector(".contentBlock").style.display="none",document.getElementById("mobileMenuSelector").onclick=()=>{this.closeMenu()}},closeMenu:function(){document.getElementById("menu").style.display="none",document.querySelector(".contentBlock").style.display="flex",document.getElementById("mobileMenuSelector").onclick=()=>{this.openMenu()}},reconvertPrice(e,t,n){if("mass"===e)switch(t){case"g":break;case"kg":n*=1e3;break;case"oz":n*=28.3495;break;case"lb":n*=453.5924}else if("volume"===e)switch(t){case"ml":n/=1e3;break;case"l":break;case"tsp":n/=202.8842;break;case"tbsp":n/=67.6278;break;case"ozfl":n/=33.8141;break;case"cup":n/=4.1667;break;case"pt":n/=2.1134;break;case"qt":n/=1.0567;break;case"gal":n*=3.7854}else if("length"===e)switch(t){case"mm":n/=1e3;break;case"cm":n/=100;break;case"m":break;case"in":n/=39.3701;break;case"ft":n/=3.2808}return n}},window.screen.availWidth>1e3&&window.screen.availWidth<=1400&&(this.changeMenu(),document.getElementById("menuShifter2").style.display="none"),document.getElementById("homeBtn").onclick=()=>{controller.openStrand("home")},document.getElementById("ingredientsBtn").onclick=()=>{controller.openStrand("ingredients")},document.getElementById("recipeBookBtn").onclick=()=>{controller.openStrand("recipeBook")},document.getElementById("analyticsBtn").onclick=()=>{controller.openStrand("analytics")},document.getElementById("ordersBtn").onclick=async()=>{0===merchant.orders.length&&merchant.setOrders(await r.getOrders(v)),controller.openStrand("orders",merchant.orders)},document.getElementById("transactionsBtn").onclick=()=>{controller.openStrand("transactions",merchant.getTransactions())},controller.openStrand("home")}();
  3. =======
  4. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  5. class Ingredient{
  6. constructor(id, name, category, unitType, unit, parent, specialUnit = undefined, unitSize = undefined){
  7. if(!this.isSanitaryString(name)){
  8. banner.createError("NAME CONTAINS ILLEGAL CHARCTERS");
  9. return false;
  10. }
  11. if(!this.isSanitaryString(category)){
  12. banner.createError("CATEGORY CONTAINS ILLEGAL CHARACTERS");
  13. return false;
  14. }
  15. this._id = id;
  16. this._name = name;
  17. this._category = category;
  18. this._unitType = unitType;
  19. this._unit = unit;
  20. this._parent = parent;
  21. if(specialUnit){
  22. this._specialUnit = specialUnit;
  23. this._unitSize = unitSize;
  24. }
  25. }
  26. get id(){
  27. return this._id;
  28. }
  29. get name(){
  30. return this._name;
  31. }
  32. set name(name){
  33. if(!this.isSanitaryString(name)){
  34. return false;
  35. }
  36. this._name = name;
  37. }
  38. get category(){
  39. return this._category;
  40. }
  41. set category(category){
  42. if(!this.isSanitaryString(category)){
  43. return false;
  44. }
  45. this._category = category;
  46. }
  47. get unitType(){
  48. return this._unitType;
  49. }
  50. get unit(){
  51. return this._unit;
  52. }
  53. set unit(unit){
  54. this._unit = unit;
  55. }
  56. get parent(){
  57. return this._parent;
  58. }
  59. get specialUnit(){
  60. return this._specialUnit;
  61. }
  62. get unitSize(){
  63. switch(this._unit){
  64. case "g":return this._unitSize;
  65. case "kg": return this._unitSize / 1000;
  66. case "oz": return this._unitSize / 28.3495;
  67. case "lb": return this._unitSize / 453.5924;
  68. case "ml": return this._unitSize * 1000;
  69. case "l": return this._unitSize;
  70. case "tsp": return this._unitSize * 202.8842;
  71. case "tbsp": return this._unitSize * 67.6278;
  72. case "ozfl": return this._unitSize * 33.8141;
  73. case "cup": return this._unitSize * 4.1667;
  74. case "pt": return this._unitSize * 2.1134;
  75. case "qt": return this._unitSize * 1.0567;
  76. case "gal": return this._unitSize / 3.7854;
  77. case "mm": return this._unitSize * 1000;
  78. case "cm": return this._unitSize * 100;
  79. case "m": return this._unitSize;
  80. case "in": return this._unitSize * 39.3701;
  81. case "ft": return this._unitSize * 3.2808;
  82. default: return this._unitSize;
  83. }
  84. }
  85. set unitSize(unitSize){
  86. if(unitSize < 0){
  87. return false;
  88. }
  89. this._unitSize = unitSize;
  90. }
  91. getNameAndUnit(){
  92. if(this._specialUnit === "bottle"){
  93. return `${this._name} (BOTTLES)`;
  94. }
  95. return `${this._name} (${this._unit.toUpperCase()})`;
  96. }
  97. isSanitaryString(str){
  98. let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
  99. for(let i = 0; i < disallowed.length; i++){
  100. if(str.includes(disallowed[i])){
  101. return false;
  102. }
  103. }
  104. return true;
  105. }
  106. }
  107. module.exports = Ingredient;
  108. },{}],2:[function(require,module,exports){
  109. class MerchantIngredient{
  110. constructor(ingredient, quantity){
  111. if(quantity < 0){
  112. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  113. return false;
  114. }
  115. this._quantity = quantity;
  116. this._ingredient = ingredient;
  117. }
  118. get ingredient(){
  119. return this._ingredient;
  120. }
  121. get quantity(){
  122. if(this._ingredient.specialUnit === "bottle"){
  123. return this._quantity / this._ingredient._unitSize;
  124. }
  125. switch(this._ingredient.unit){
  126. case "g":return this._quantity;
  127. case "kg": return this._quantity / 1000;
  128. case "oz": return this._quantity / 28.3495;
  129. case "lb": return this._quantity / 453.5924;
  130. case "ml": return this._quantity * 1000;
  131. case "l": return this._quantity;
  132. case "tsp": return this._quantity * 202.8842;
  133. case "tbsp": return this._quantity * 67.6278;
  134. case "ozfl": return this._quantity * 33.8141;
  135. case "cup": return this._quantity * 4.1667;
  136. case "pt": return this._quantity * 2.1134;
  137. case "qt": return this._quantity * 1.0567;
  138. case "gal": return this._quantity / 3.7854;
  139. case "mm": return this._quantity * 1000;
  140. case "cm": return this._quantity * 100;
  141. case "m": return this._quantity;
  142. case "in": return this._quantity * 39.3701;
  143. case "ft": return this._quantity * 3.2808;
  144. default: return this._quantity;
  145. }
  146. }
  147. updateQuantity(quantity){
  148. this._quantity += this.convertToBase(quantity);
  149. }
  150. convertToBase(quantity){
  151. switch(this._ingredient.unit){
  152. case "g": return quantity;
  153. case "kg": return quantity * 1000;
  154. case "oz": return quantity * 28.3495;
  155. case "lb": return quantity * 453.5924;
  156. case "ml": return quantity / 1000;
  157. case "l": return quantity;
  158. case "tsp": return quantity / 202.8842;
  159. case "tbsp": return quantity / 67.6278;
  160. case "ozfl": return quantity / 33.8141;
  161. case "cup": return quantity / 4.1667;
  162. case "pt": return quantity / 2.1134;
  163. case "qt": return quantity / 1.0567;
  164. case "gal": return quantity * 3.7854;
  165. case "mm": return quantity / 1000;
  166. case "cm": return quantity / 100;
  167. case "m": return quantity;
  168. case "in": return quantity / 39.3701;
  169. case "ft": return quantity / 3.2808;
  170. default: return quantity;
  171. }
  172. }
  173. getQuantityDisplay(){
  174. if(this._ingredient.specialUnit === "bottle"){
  175. return `${this.quantity.toFixed(2)} BOTTLES`;
  176. }
  177. return `${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`;
  178. }
  179. }
  180. class Merchant{
  181. constructor(oldMerchant, transactions, modules){
  182. this._modules = modules;
  183. this._name = oldMerchant.name;
  184. this._pos = oldMerchant.pos;
  185. this._ingredients = [];
  186. this._recipes = [];
  187. this._transactions = [];
  188. this._orders = [];
  189. this._units = {
  190. mass: ["g", "kg", "oz", "lb"],
  191. volume: ["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"],
  192. length: ["mm", "cm", "m", "in", "ft"],
  193. other: ["each", "bottle"]
  194. }
  195. //populate ingredients
  196. for(let i = 0; i < oldMerchant.inventory.length; i++){
  197. const ingredient = new modules.Ingredient(
  198. oldMerchant.inventory[i].ingredient._id,
  199. oldMerchant.inventory[i].ingredient.name,
  200. oldMerchant.inventory[i].ingredient.category,
  201. oldMerchant.inventory[i].ingredient.unitType,
  202. oldMerchant.inventory[i].defaultUnit,
  203. this,
  204. oldMerchant.inventory[i].ingredient.specialUnit,
  205. oldMerchant.inventory[i].ingredient.unitSize
  206. );
  207. const merchantIngredient = new MerchantIngredient(
  208. ingredient,
  209. oldMerchant.inventory[i].quantity,
  210. );
  211. this._ingredients.push(merchantIngredient);
  212. }
  213. //populate recipes
  214. for(let i = 0; i < oldMerchant.recipes.length; i++){
  215. let ingredients = [];
  216. for(let j = 0; j < oldMerchant.recipes[i].ingredients.length; j++){
  217. const ingredient = oldMerchant.recipes[i].ingredients[j];
  218. for(let k = 0; k < this._ingredients.length; k++){
  219. if(ingredient.ingredient === this._ingredients[k].ingredient.id){
  220. ingredients.push({
  221. ingredient: this._ingredients[k].ingredient,
  222. quantity: ingredient.quantity
  223. });
  224. break;
  225. }
  226. }
  227. }
  228. this._recipes.push(new this._modules.Recipe(
  229. oldMerchant.recipes[i]._id,
  230. oldMerchant.recipes[i].name,
  231. oldMerchant.recipes[i].price,
  232. ingredients,
  233. this
  234. ));
  235. }
  236. //populate transactions
  237. for(let i = 0; i < transactions.length; i++){
  238. this._transactions.push(new modules.Transaction(
  239. transactions[i]._id,
  240. transactions[i].date,
  241. transactions[i].recipes,
  242. this
  243. ));
  244. }
  245. }
  246. get modules(){
  247. return this._modules;
  248. }
  249. get name(){
  250. return this._name;
  251. }
  252. set name(name){
  253. if(this.isSanitaryString(name)){
  254. this._name = name;
  255. }
  256. return false;
  257. }
  258. get pos(){
  259. return this._pos;
  260. }
  261. get ingredients(){
  262. return this._ingredients;
  263. }
  264. addIngredient(ingredient, quantity){
  265. const merchantIngredient = new MerchantIngredient(ingredient, quantity);
  266. this._ingredients.push(merchantIngredient);
  267. this._modules.home.isPopulated = false;
  268. this._modules.ingredients.isPopulated = false;
  269. }
  270. removeIngredient(ingredient){
  271. const index = this._ingredients.indexOf(ingredient);
  272. if(index === undefined){
  273. return false;
  274. }
  275. this._ingredients.splice(index, 1);
  276. this._modules.home.isPopulated = false;
  277. this._modules.ingredients.isPopulated = false;
  278. }
  279. updateIngredient(ingredient, quantity){
  280. const index = this._ingredients.indexOf(ingredient);
  281. if(index === undefined){
  282. return false;
  283. }
  284. this._ingredients[index].quantity = quantity;
  285. this._modules.home.isPopulated = false;
  286. this._modules.ingredients.isPopulated = false;
  287. }
  288. getIngredient(id){
  289. for(let i = 0; i < this._ingredients.length; i++){
  290. if(this._ingredients[i].ingredient.id === id){
  291. return this._ingredients[i];
  292. }
  293. }
  294. }
  295. get recipes(){
  296. return this._recipes;
  297. }
  298. addRecipe(recipe){
  299. this._recipes.push(recipe);
  300. this._modules.recipeBook.isPopulated = false;
  301. }
  302. removeRecipe(recipe){
  303. const index = this._recipes.indexOf(recipe);
  304. if(index === undefined){
  305. return false;
  306. }
  307. this._recipes.splice(index, 1);
  308. this._modules.recipeBook.isPopulated = false;
  309. }
  310. /*
  311. recipe = {
  312. name: required,
  313. price: required,
  314. ingredients: [{
  315. ingredient: id of ingredient,
  316. quantity: quantity of ingredient
  317. }]
  318. }
  319. */
  320. updateRecipe(recipe){
  321. for(let i = 0; i < this._recipes.length; i++){
  322. if(this._recipes[i].id === recipe._id){
  323. this._recipes[i].name = recipe.name;
  324. this._recipes[i].price = recipe.price;
  325. this._recipes[i].removeIngredients();
  326. for(let j = 0; j < recipe.ingredients.length; j++){
  327. for(let k = 0; k < this._ingredients.length; k++){
  328. if(this._ingredients[k].ingredient.id === recipe.ingredients[j].ingredient){
  329. this._recipes[i].addIngredient(
  330. this._ingredients[k].ingredient,
  331. recipe.ingredients[j].quantity
  332. );
  333. break;
  334. }
  335. }
  336. }
  337. break;
  338. }
  339. }
  340. this._modules.recipeBook.isPopulated = false;
  341. }
  342. getTransactions(from = 0, to = new Date()){
  343. if(merchant._transactions.length <= 0){
  344. return [];
  345. }
  346. if(from === 0){
  347. from = this._transactions[this._transactions.length-1].date;
  348. }
  349. const {start, end} = this.getTransactionIndices(from, to);
  350. return this._transactions.slice(start, end + 1);
  351. }
  352. addTransaction(transaction){
  353. this._transactions.push(transaction);
  354. this._transactions.sort((a, b)=>{
  355. if(a.date > b.date){
  356. return -1;
  357. }
  358. return 1;
  359. });
  360. let ingredients = {};
  361. for(let i = 0; i < transaction.recipes.length; i++){
  362. const recipe = transaction.recipes[i];
  363. for(let j = 0; j < recipe.recipe.ingredients.length; j++){
  364. const ingredient = recipe.recipe.ingredients[j];
  365. if(ingredients[ingredient.ingredient.id]){
  366. ingredients[ingredient.ingredient.id] += recipe.quantity * ingredient.quantity;
  367. }else{
  368. ingredients[ingredient.ingredient.id] = recipe.quantity * ingredient.quantity;
  369. }
  370. }
  371. }
  372. const keys = Object.keys(ingredients);
  373. for(let i = 0; i < keys.length; i++){
  374. for(let j = 0; j < this._ingredients.length; j++){
  375. if(keys[i] === this._ingredients[j].ingredient.id){
  376. this._ingredients[j].updateQuantity(-ingredients[keys[i]]);
  377. }
  378. }
  379. }
  380. this._modules.home.isPopulated = false;
  381. this._modules.ingredients.isPopulated = false;
  382. this._modules.analytics.newData = true;
  383. }
  384. removeTransaction(transaction){
  385. const index = this._transactions.indexOf(transaction);
  386. if(index === undefined){
  387. return false;
  388. }
  389. this._transactions.splice(index, 1);
  390. let ingredients = {};
  391. for(let i = 0; i < transaction.recipes.length; i++){
  392. const recipe = transaction.recipes[i];
  393. for(let j = 0; j < recipe.recipe.ingredients.length; j++){
  394. const ingredient = recipe.recipe.ingredients[j];
  395. if(ingredients[ingredient.ingredient.id]){
  396. ingredients[ingredient.ingredient.id] += ingredient.quantity * recipe.quantity;
  397. }else{
  398. ingredients[ingredient.ingredient.id] = ingredient.quantity * recipe.quantity;
  399. }
  400. }
  401. }
  402. const keys = Object.keys(ingredients);
  403. for(let i = 0; i < keys.length; i++){
  404. for(let j = 0; j < this._ingredients.length; j++){
  405. if(keys[i] === this._ingredients[j].ingredient.id){
  406. this._ingredients[j].updateQuantity(ingredients[keys[i]]);
  407. break;
  408. }
  409. }
  410. }
  411. this._modules.home.isPopulated = false;
  412. this._modules.ingredients.isPopulated = false;
  413. this._modules.analytics.newData = true;
  414. }
  415. get orders(){
  416. return this._orders;
  417. }
  418. addOrder(order, isNew = false){
  419. this._orders.push(order);
  420. if(isNew){
  421. for(let i = 0; i < order.ingredients.length; i++){
  422. for(let j = 0; j < this._ingredients.length; j++){
  423. if(order.ingredients[i].ingredient === this._ingredients[j].ingredient){
  424. this._ingredients[j].updateQuantity(order.ingredients[i].quantity);
  425. break;
  426. }
  427. }
  428. }
  429. }
  430. this._modules.ingredients.isPopulated = false;
  431. this._modules.orders.isPopulated = false;
  432. }
  433. setOrders(orders){
  434. this._orders = orders
  435. }
  436. removeOrder(order){
  437. const index = this._orders.indexOf(order);
  438. if(index === undefined){
  439. return false;
  440. }
  441. this._orders.splice(index, 1);
  442. for(let i = 0; i < order.ingredients.length; i++){
  443. for(let j = 0; j < this._ingredients.length; j++){
  444. if(order.ingredients[i].ingredient === this._ingredients[j].ingredient){
  445. this._ingredients[j].updateQuantity(-order.ingredients[i].quantity);
  446. break;
  447. }
  448. }
  449. }
  450. this._modules.ingredients.isPopulated = false;
  451. this._modules.orders.isPopulated = false;
  452. }
  453. get units(){
  454. return this._units;
  455. }
  456. getRevenue(from, to = new Date()){
  457. if(from === 0){
  458. from = this._transactions[0].date;
  459. }
  460. const {start, end} = this.getTransactionIndices(from, to);
  461. let total = 0;
  462. for(let i = start; i <= end; i++){
  463. for(let j = 0; j < this._transactions[i].recipes.length; j++){
  464. for(let k = 0; k < this.recipes.length; k++){
  465. if(this._transactions[i].recipes[j].recipe === this.recipes[k]){
  466. total += this._transactions[i].recipes[j].quantity * this.recipes[k].price;
  467. }
  468. }
  469. }
  470. }
  471. return total / 100;
  472. }
  473. /*
  474. Gets the quantity of each ingredient sold between two dates (dateRange)
  475. Inputs:
  476. dateRange: list containing a start date and an end date
  477. Return:
  478. [{
  479. ingredient: Ingredient object,
  480. quantity: quantity of ingredient sold in default unit
  481. }]
  482. */
  483. getIngredientsSold(from = 0, to = new Date()){
  484. if(from = 0){
  485. from = this._ingredients[0].date;
  486. }
  487. let recipes = this.getRecipesSold(from, to);
  488. let ingredientList = [];
  489. for(let i = 0; i < recipes.length; i++){
  490. for(let j = 0; j < recipes[i].recipe.ingredients.length; j++){
  491. let exists = false;
  492. for(let k = 0; k < ingredientList.length; k++){
  493. if(ingredientList[k].ingredient === recipes[i].recipe.ingredients[j].ingredient){
  494. exists = true;
  495. ingredientList[k].quantity += recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity;
  496. }
  497. }
  498. if(!exists){
  499. ingredientList.push({
  500. ingredient: recipes[i].recipe.ingredients[j].ingredient,
  501. quantity: recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity
  502. });
  503. }
  504. }
  505. }
  506. return ingredientList;
  507. }
  508. /*
  509. Gets the quantity of a single ingredient sold between two dates
  510. Inputs:
  511. ingredient = MerchantIngredient object to find
  512. from = start Date
  513. to = end Date
  514. return: quantity sold in default unit
  515. */
  516. getSingleIngredientSold(ingredient, from = 0, to = new Date()){
  517. if(from === 0){
  518. from = this._transactions[0].date;
  519. }
  520. const {start, end} = this.getTransactionIndices(from, to);
  521. let total = 0;
  522. for(let i = start; i < end; i++){
  523. for(let j = 0; j < this._transactions[i].recipes.length; j++){
  524. for(let k = 0; k < this._transactions[i].recipes[j].recipe.ingredients.length; k++){
  525. if(this._transactions[i].recipes[j].recipe.ingredients[k].ingredient === ingredient.ingredient){
  526. total += this._transactions[i].recipes[j].recipe.ingredients[k].quantity;
  527. break;
  528. }
  529. }
  530. }
  531. }
  532. return total;
  533. }
  534. /*
  535. Gets the number of recipes sold between two dates (dateRange)
  536. Inputs:
  537. dateRange: array containing a start date and an end date
  538. Return:
  539. [{
  540. recipe: a recipe object
  541. quantity: quantity of the recipe sold
  542. }]
  543. */
  544. getRecipesSold(from = 0, to = new Date()){
  545. if(from = 0){
  546. from = this._transactions[0].date;
  547. }
  548. const {start, end} = this.getTransactionIndices(from, to);
  549. let recipeList = [];
  550. for(let i = start; i <= end; i++){
  551. for(let j = 0; j < this._transactions[i].recipes.length; j++){
  552. let exists = false;
  553. for(let k = 0; k < recipeList.length; k++){
  554. if(recipeList[k].recipe === this._transactions[i].recipes[j].recipe){
  555. exists = true;
  556. recipeList[k].quantity += this._transactions[i].recipes[j].quantity;
  557. break;
  558. }
  559. }
  560. if(!exists){
  561. recipeList.push({
  562. recipe: this._transactions[i].recipes[j].recipe,
  563. quantity: this._transactions[i].recipes[j].quantity
  564. });
  565. }
  566. }
  567. }
  568. return recipeList;
  569. }
  570. /*
  571. Groups all of the merchant's ingredients by their category
  572. Return: [{
  573. name: category name,
  574. ingredients: [MerchantIngredient Object]
  575. }]
  576. */
  577. categorizeIngredients(){
  578. let ingredientsByCategory = [];
  579. for(let i = 0; i < this.ingredients.length; i++){
  580. let categoryExists = false;
  581. for(let j = 0; j < ingredientsByCategory.length; j++){
  582. if(this.ingredients[i].ingredient.category === ingredientsByCategory[j].name){
  583. ingredientsByCategory[j].ingredients.push(this.ingredients[i]);
  584. categoryExists = true;
  585. break;
  586. }
  587. }
  588. if(!categoryExists){
  589. ingredientsByCategory.push({
  590. name: this.ingredients[i].ingredient.category,
  591. ingredients: [this.ingredients[i]]
  592. });
  593. }
  594. }
  595. return ingredientsByCategory;
  596. }
  597. unitizeIngredients(){
  598. let ingredientsByUnit = [];
  599. for(let i = 0; i < this.ingredients.length; i++){
  600. let unitExists = false;
  601. const innerIngredient = this.ingredients[i].ingredient;
  602. for(let j = 0; j < ingredientsByUnit.length; j++){
  603. if(innerIngredient.unit === ingredientsByUnit[j].name || innerIngredient.specialUnit === ingredientsByUnit[j].name){
  604. ingredientsByUnit[j].ingredients.push(this.ingredients[i]);
  605. unitExists = true;
  606. break;
  607. }
  608. }
  609. if(!unitExists){
  610. let unit = "";
  611. if(innerIngredient.specialUnit === "bottle"){
  612. unit = "bottle";
  613. }else{
  614. unit = innerIngredient.unit;
  615. }
  616. ingredientsByUnit.push({
  617. name: unit,
  618. ingredients: [this.ingredients[i]]
  619. });
  620. }
  621. }
  622. return ingredientsByUnit;
  623. }
  624. getRecipesForIngredient(ingredient){
  625. let recipes = [];
  626. for(let i = 0; i < this._recipes.length; i++){
  627. for(let j = 0; j < this._recipes[i].ingredients.length; j++){
  628. if(this._recipes[i].ingredients[j].ingredient === ingredient){
  629. recipes.push(this._recipes[i]);
  630. break;
  631. }
  632. }
  633. }
  634. return recipes;
  635. }
  636. getTransactionIndices(from, to){
  637. let start, end;
  638. to.setDate(to.getDate() + 1);
  639. for(let i = this._transactions.length - 1; i >= 0; i--){
  640. if(this._transactions[i].date >= from){
  641. start = i;
  642. break;
  643. }
  644. }
  645. for(let i = 0; i < this._transactions.length; i++){
  646. if(this._transactions[i].date < to){
  647. end = i;
  648. break;
  649. }
  650. }
  651. if(start === undefined){
  652. return false;
  653. }
  654. //these are switched due to the order of the transactions in the merchant
  655. return {start: end, end: start};
  656. }
  657. isSanitaryString(str){
  658. let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
  659. for(let i = 0; i < disallowed.length; i++){
  660. if(str.includes(disallowed[i])){
  661. return false;
  662. }
  663. }
  664. return true;
  665. }
  666. }
  667. module.exports = Merchant;
  668. },{}],3:[function(require,module,exports){
  669. class OrderIngredient{
  670. constructor(ingredient, quantity, pricePerUnit){
  671. if(quantity < 0){
  672. return false;
  673. }
  674. this._ingredient = ingredient;
  675. this._quantity = quantity;
  676. this._pricePerUnit = pricePerUnit;
  677. }
  678. get ingredient(){
  679. return this._ingredient;
  680. }
  681. get quantity(){
  682. if(this._ingredient.specialUnit === "bottle"){
  683. return this._quantity / this._ingredient.unitSize;
  684. }
  685. switch(this._ingredient.unit){
  686. case "g":return this._quantity;
  687. case "kg": return this._quantity / 1000;
  688. case "oz": return this._quantity / 28.3495;
  689. case "lb": return this._quantity / 453.5924;
  690. case "ml": return this._quantity * 1000;
  691. case "l": return this._quantity;
  692. case "tsp": return this._quantity * 202.8842;
  693. case "tbsp": return this._quantity * 67.6278;
  694. case "ozfl": return this._quantity * 33.8141;
  695. case "cup": return this._quantity * 4.1667;
  696. case "pt": return this._quantity * 2.1134;
  697. case "qt": return this._quantity * 1.0567;
  698. case "gal": return this._quantity / 3.7854;
  699. case "mm": return this._quantity * 1000;
  700. case "cm": return this._quantity * 100;
  701. case "m": return this._quantity;
  702. case "in": return this._quantity * 39.3701;
  703. case "ft": return this._quantity * 3.2808;
  704. default: return this._quantity;
  705. }
  706. }
  707. updateQuantity(quantity){
  708. if(quantity < 0){
  709. return false;
  710. }
  711. this._quantity += this.convertToBase(quantity);
  712. }
  713. convertToBase(quantity){
  714. switch(this._ingredient.unit){
  715. case "g": return quantity;
  716. case "kg": return quantity * 1000;
  717. case "oz": return quantity * 28.3495;
  718. case "lb": return quantity * 453.5924;
  719. case "ml": return quantity / 1000;
  720. case "l": return quantity;
  721. case "tsp": return quantity / 202.8842;
  722. case "tbsp": return quantity / 67.6278;
  723. case "ozfl": return quantity / 33.8141;
  724. case "cup": return quantity / 4.1667;
  725. case "pt": return quantity / 2.1134;
  726. case "qt": return quantity / 1.0567;
  727. case "gal": return quantity * 3.7854;
  728. case "mm": return quantity / 1000;
  729. case "cm": return quantity / 100;
  730. case "m": return quantity;
  731. case "in": return quantity / 39.3701;
  732. case "ft": return quantity / 3.2808;
  733. default: return quantity;
  734. }
  735. }
  736. get pricePerUnit(){
  737. if(this._ingredient.specialUnit === "bottle"){
  738. return (this._pricePerUnit * this._ingredient.unitSize) / 100;
  739. }
  740. switch(this._ingredient.unit){
  741. case "g": return this._pricePerUnit / 100;
  742. case "kg": return (this._pricePerUnit * 1000) / 100;
  743. case "oz": return (this._pricePerUnit * 28.3495) / 100;
  744. case "lb": return (this._pricePerUnit * 453.5924) / 100;
  745. case "ml": return (this._pricePerUnit / 1000) / 100;
  746. case "l": return this._pricePerUnit / 100;
  747. case "tsp": return (this._pricePerUnit / 202.8842) / 100;
  748. case "tbsp": return (this._pricePerUnit / 67.6278) / 100;
  749. case "ozfl": return (this._pricePerUnit / 33.8141) / 100;
  750. case "cup": return (this._pricePerUnit / 4.1667) / 100;
  751. case "pt": return (this._pricePerUnit / 2.1134) / 100;
  752. case "qt": return (this._pricePerUnit / 1.0567) / 100;
  753. case "gal": return (this._pricePerUnit * 3.7854) / 100;
  754. case "mm": return (this._pricePerUnit / 1000) / 100;
  755. case "cm": return (this._pricePerUnit / 100) / 100;
  756. case "m": return this._pricePerUnit / 100;
  757. case "in": return (this._pricePerUnit / 39.3701) / 100;
  758. case "ft": return (this._pricePerUnit / 3.2808) / 100;
  759. }
  760. }
  761. cost(){
  762. return (this._quantity * this._pricePerUnit) / 100;
  763. }
  764. }
  765. /*
  766. Order Object
  767. id = id of order in the database
  768. name = name/id of order, if any
  769. date = Date Object for when the order was created
  770. taxes = User entered taxes associated with the order
  771. fees = User entered fees associated with the order
  772. ingredients = [{
  773. ingredient: Ingredient Object,
  774. quantity: quantity of ingredient sold,
  775. pricePerUnit: price of purchase (per base unit)
  776. }]
  777. parent = the merchant that it belongs to
  778. */
  779. class Order{
  780. constructor(id, name, date, taxes, fees, ingredients, parent){
  781. if(!this.isSanitaryString(name)){
  782. return false;
  783. }
  784. if(taxes < 0){
  785. return false;
  786. }
  787. this._id = id;
  788. this._name = name;
  789. this._date = new Date(date);
  790. this._taxes = taxes;
  791. this._fees = fees;
  792. this._ingredients = [];
  793. this._parent = parent;
  794. if(date > new Date()){
  795. return false;
  796. }
  797. for(let i = 0; i < ingredients.length; i++){
  798. for(let j = 0; j < merchant.ingredients.length; j++){
  799. if(merchant.ingredients[j].ingredient.id === ingredients[i].ingredient){
  800. this._ingredients.push(new OrderIngredient(
  801. merchant.ingredients[j].ingredient,
  802. ingredients[i].quantity,
  803. ingredients[i].pricePerUnit
  804. ));
  805. break;
  806. }
  807. }
  808. }
  809. this._parent.modules.ingredients.isPopulated = false;
  810. }
  811. get id(){
  812. return this._id;
  813. }
  814. get name(){
  815. return this._name;
  816. }
  817. get date(){
  818. return this._date;
  819. }
  820. get taxes(){
  821. return this._taxes / 100;
  822. }
  823. get fees(){
  824. return this._fees / 100;
  825. }
  826. get parent(){
  827. return this._parent;
  828. }
  829. get ingredients(){
  830. return this._ingredients;
  831. }
  832. getIngredientCost(){
  833. let sum = 0;
  834. for(let i = 0; i < this._ingredients.length; i++){
  835. sum += this._ingredients[i].cost();
  836. }
  837. return sum;
  838. }
  839. getTotalCost(){
  840. return (this.getIngredientCost() + this.taxes + this.fees);
  841. }
  842. isSanitaryString(str){
  843. let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
  844. for(let i = 0; i < disallowed.length; i++){
  845. if(str.includes(disallowed[i])){
  846. return false;
  847. }
  848. }
  849. return true;
  850. }
  851. }
  852. module.exports = Order;
  853. },{}],4:[function(require,module,exports){
  854. class RecipeIngredient{
  855. constructor(ingredient, quantity){
  856. if(quantity < 0){
  857. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  858. return false;
  859. }
  860. this._ingredient = ingredient;
  861. this._quantity = quantity;
  862. }
  863. get ingredient(){
  864. return this._ingredient;
  865. }
  866. get quantity(){
  867. if(this._ingredient.specialUnit === "bottle"){
  868. return this._quantity / this._ingredient.unitSize;
  869. }
  870. switch(this._ingredient.unit){
  871. case "g":return this._quantity;
  872. case "kg": return this._quantity / 1000;
  873. case "oz": return this._quantity / 28.3495;
  874. case "lb": return this._quantity / 453.5924;
  875. case "ml": return this._quantity * 1000;
  876. case "l": return this._quantity;
  877. case "tsp": return this._quantity * 202.8842;
  878. case "tbsp": return this._quantity * 67.6278;
  879. case "ozfl": return this._quantity * 33.8141;
  880. case "cup": return this._quantity * 4.1667;
  881. case "pt": return this._quantity * 2.1134;
  882. case "qt": return this._quantity * 1.0567;
  883. case "gal": return this._quantity / 3.7854;
  884. case "mm": return this._quantity * 1000;
  885. case "cm": return this._quantity * 100;
  886. case "m": return this._quantity;
  887. case "in": return this._quantity * 39.3701;
  888. case "ft": return this._quantity * 3.2808;
  889. default: return this._quantity;
  890. }
  891. }
  892. set quantity(quantity){
  893. if(quantity < 0){
  894. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  895. return false;
  896. }
  897. this_quantity = this.convertToBase(quantity);
  898. }
  899. getQuantityDisplay(){
  900. if(this._ingredient.specialUnit === "bottle"){
  901. return `${this.quantity.toFixed(2)} BOTTLES`;
  902. }
  903. return `${this.quantity.toFixed(2)} ${this._ingredient.unit.toUpperCase()}`;
  904. }
  905. convertToBase(quantity){
  906. switch(this._ingredient.unit){
  907. case "g": return quantity;
  908. case "kg": return quantity * 1000;
  909. case "oz": return quantity * 28.3495;
  910. case "lb": return quantity * 453.5924;
  911. case "ml": return quantity / 1000;
  912. case "l": return quantity;
  913. case "tsp": return quantity / 202.8842;
  914. case "tbsp": return quantity / 67.6278;
  915. case "ozfl": return quantity / 33.8141;
  916. case "cup": return quantity / 4.1667;
  917. case "pt": return quantity / 2.1134;
  918. case "qt": return quantity / 1.0567;
  919. case "gal": return quantity * 3.7854;
  920. case "mm": return quantity / 1000;
  921. case "cm": return quantity / 100;
  922. case "m": return quantity;
  923. case "in": return quantity / 39.3701;
  924. case "ft": return quantity / 3.2808;
  925. default: return quantity;
  926. }
  927. }
  928. }
  929. /*
  930. Recipe Object
  931. id = database id of recipe
  932. name = name of recipe
  933. price = price of recipe in cents
  934. ingredients = [{
  935. ingredient: Ingredient Object,
  936. quantity: quantity of the ingredient within the recipe (stored as base unit, i.e grams)
  937. }]
  938. parent = merchant that it belongs to
  939. */
  940. class Recipe{
  941. constructor(id, name, price, ingredients, parent){
  942. if(price < 0){
  943. banner.createError("PRICE CANNOT BE A NEGATIVE NUMBER");
  944. return false;
  945. }
  946. if(!this.isSanitaryString(name)){
  947. banner.createError("NAME CONTAINS ILLEGAL CHARACTERS");
  948. return false;
  949. }
  950. this._id = id;
  951. this._name = name;
  952. this._price = price;
  953. this._parent = parent;
  954. this._ingredients = [];
  955. for(let i = 0; i < ingredients.length; i++){
  956. const recipeIngredient = new RecipeIngredient(
  957. ingredients[i].ingredient,
  958. ingredients[i].quantity
  959. );
  960. this._ingredients.push(recipeIngredient);
  961. }
  962. }
  963. get id(){
  964. return this._id;
  965. }
  966. get name(){
  967. return this._name;
  968. }
  969. set name(name){
  970. if(!this.isSanitaryString(name)){
  971. return false;
  972. }
  973. this._name = name;
  974. }
  975. get price(){
  976. return this._price / 100;
  977. }
  978. set price(price){
  979. if(price < 0){
  980. return false;
  981. }
  982. this._price = price;
  983. }
  984. get parent(){
  985. return this._parent;
  986. }
  987. get ingredients(){
  988. return this._ingredients;
  989. }
  990. addIngredient(ingredient, quantity){
  991. if(quantity < 0){
  992. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  993. return false;
  994. }
  995. let recipeIngredient = new RecipeIngredient(ingredient, quantity);
  996. this._ingredients.push(recipeIngredient);
  997. this._parent.modules.recipeBook.isPopulated = false;
  998. this._parent.modules.analytics.isPopulated = false;
  999. }
  1000. removeIngredients(){
  1001. this._ingredients = [];
  1002. }
  1003. isSanitaryString(str){
  1004. let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
  1005. for(let i = 0; i < disallowed.length; i++){
  1006. if(str.includes(disallowed[i])){
  1007. return false;
  1008. }
  1009. }
  1010. return true;
  1011. }
  1012. }
  1013. module.exports = Recipe;
  1014. },{}],5:[function(require,module,exports){
  1015. class TransactionRecipe{
  1016. constructor(recipe, quantity){
  1017. if(quantity < 0){
  1018. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  1019. return false;
  1020. }
  1021. if(quantity % 1 !== 0){
  1022. banner.createError("RECIPES WITHIN A TRANSACTION MUST BE WHOLE NUMBERS");
  1023. return false;
  1024. }
  1025. this._recipe = recipe;
  1026. this._quantity = quantity;
  1027. }
  1028. get recipe(){
  1029. return this._recipe;
  1030. }
  1031. get quantity(){
  1032. return this._quantity;
  1033. }
  1034. }
  1035. class Transaction{
  1036. constructor(id, date, recipes, parent){
  1037. date = new Date(date);
  1038. if(date > new Date()){
  1039. banner.createError("DATE CANNOT BE SET TO THE FUTURE");
  1040. return false;
  1041. }
  1042. this._id = id;
  1043. this._parent = parent;
  1044. this._date = date;
  1045. this._recipes = [];
  1046. for(let i = 0; i < recipes.length; i++){
  1047. for(let j = 0; j < parent.recipes.length; j++){
  1048. if(recipes[i].recipe === parent.recipes[j].id){
  1049. const transactionRecipe = new TransactionRecipe(
  1050. parent.recipes[j],
  1051. recipes[i].quantity
  1052. )
  1053. this._recipes.push(transactionRecipe);
  1054. break;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. get id(){
  1060. return this._id;
  1061. }
  1062. get parent(){
  1063. return this._parent;
  1064. }
  1065. get date(){
  1066. return this._date;
  1067. }
  1068. get recipes(){
  1069. return this._recipes;
  1070. }
  1071. }
  1072. module.exports = Transaction;
  1073. },{}],6:[function(require,module,exports){
  1074. const home = require("./strands/home.js");
  1075. const ingredients = require("./strands/ingredients.js");
  1076. const recipeBook = require("./strands/recipeBook.js");
  1077. const analytics = require("./strands/analytics.js");
  1078. const orders = require("./strands/orders.js");
  1079. const transactions = require("./strands/transactions.js");
  1080. const ingredientDetails = require("./sidebars/ingredientDetails.js");
  1081. const newIngredient = require("./sidebars/newIngredient.js");
  1082. const editIngredient = require("./sidebars/editIngredient.js");
  1083. const newOrder = require("./sidebars/newOrder.js");
  1084. const newRecipe = require("./sidebars/newRecipe.js");
  1085. const editRecipe = require("./sidebars/editRecipe.js");
  1086. const newTransaction = require("./sidebars/newTransaction.js");
  1087. const orderDetails = require("./sidebars/orderDetails.js");
  1088. const orderFilter = require("./sidebars/orderFilter.js");
  1089. const recipeDetails = require("./sidebars/recipeDetails.js");
  1090. const transactionDetails = require("./sidebars/transactionDetails.js");
  1091. const transactionFilter = require("./sidebars/transactionFilter.js");
  1092. const Merchant = require("./classes/Merchant.js");
  1093. const Ingredient = require("./classes/Ingredient.js");
  1094. const Recipe = require("./classes/Recipe.js");
  1095. const Order = require("./classes/Order.js");
  1096. const Transaction = require("./classes/Transaction.js");
  1097. merchant = new Merchant(data.merchant, data.transactions, {
  1098. home: home,
  1099. ingredients: ingredients,
  1100. transactions: transactions,
  1101. recipeBook: recipeBook,
  1102. analytics: analytics,
  1103. orders: orders,
  1104. Ingredient: Ingredient,
  1105. Recipe: Recipe,
  1106. Transaction: Transaction
  1107. });
  1108. controller = {
  1109. openStrand: function(strand, data = undefined){
  1110. this.closeSidebar();
  1111. let strands = document.querySelectorAll(".strand");
  1112. for(let i = 0; i < strands.length; i++){
  1113. strands[i].style.display = "none";
  1114. }
  1115. let buttons = document.querySelectorAll(".menuButton");
  1116. for(let i = 0; i < buttons.length - 1; i++){
  1117. buttons[i].classList = "menuButton";
  1118. buttons[i].disabled = false;
  1119. }
  1120. let activeButton = {};
  1121. switch(strand){
  1122. case "home":
  1123. activeButton = document.getElementById("homeBtn");
  1124. document.getElementById("homeStrand").style.display = "flex";
  1125. home.display();
  1126. break;
  1127. case "ingredients":
  1128. activeButton = document.getElementById("ingredientsBtn");
  1129. document.getElementById("ingredientsStrand").style.display = "flex";
  1130. ingredients.display();
  1131. break;
  1132. case "recipeBook":
  1133. activeButton = document.getElementById("recipeBookBtn");
  1134. document.getElementById("recipeBookStrand").style.display = "flex";
  1135. recipeBook.display(Recipe);
  1136. break;
  1137. case "analytics":
  1138. activeButton = document.getElementById("analyticsBtn");
  1139. document.getElementById("analyticsStrand").style.display = "flex";
  1140. analytics.display(Transaction);
  1141. break;
  1142. case "orders":
  1143. activeButton = document.getElementById("ordersBtn");
  1144. document.getElementById("ordersStrand").style.display = "flex";
  1145. orders.orders = data;
  1146. orders.display(Order);
  1147. break;
  1148. case "transactions":
  1149. activeButton = document.getElementById("transactionsBtn");
  1150. document.getElementById("transactionsStrand").style.display = "flex";
  1151. transactions.transactions = data;
  1152. transactions.display(Transaction);
  1153. break;
  1154. }
  1155. activeButton.classList = "menuButton active";
  1156. activeButton.disabled = true;
  1157. if(window.screen.availWidth <= 1000){
  1158. this.closeMenu();
  1159. }
  1160. },
  1161. /*
  1162. Open a specific sidebar
  1163. Input:
  1164. sidebar: the outermost element of the sidebar (must contain class sidebar)
  1165. */
  1166. openSidebar: function(sidebar, data = {}){
  1167. this.closeSidebar();
  1168. document.getElementById("sidebarDiv").classList = "sidebar";
  1169. document.getElementById(sidebar).style.display = "flex";
  1170. switch(sidebar){
  1171. case "ingredientDetails":
  1172. ingredientDetails.display(data, ingredients);
  1173. break;
  1174. case "newIngredient":
  1175. newIngredient.display(Ingredient);
  1176. break;
  1177. case "editIngredient":
  1178. editIngredient.display(data);
  1179. break;
  1180. case "recipeDetails":
  1181. recipeDetails.display(data);
  1182. break;
  1183. case "editRecipe":
  1184. editRecipe.display(data);
  1185. break;
  1186. case "addRecipe":
  1187. newRecipe.display(Recipe);
  1188. break;
  1189. case "orderDetails":
  1190. orderDetails.display(data);
  1191. break;
  1192. case "orderFilter":
  1193. orderFilter.display(Order);
  1194. break;
  1195. case "newOrder":
  1196. newOrder.display(Order);
  1197. break;
  1198. case "transactionDetails":
  1199. transactionDetails.display(data);
  1200. break;
  1201. case "transactionFilter":
  1202. transactionFilter.display();
  1203. break;
  1204. case "newTransaction":
  1205. newTransaction.display(Transaction);
  1206. break;
  1207. }
  1208. if(window.screen.availWidth <= 1000){
  1209. document.querySelector(".contentBlock").style.display = "none";
  1210. document.getElementById("mobileMenuSelector").style.display = "none";
  1211. document.getElementById("sidebarCloser").style.display = "block";
  1212. }
  1213. },
  1214. closeSidebar: function(){
  1215. let sidebar = document.getElementById("sidebarDiv");
  1216. for(let i = 0; i < sidebar.children.length; i++){
  1217. if(sidebar.children[i].style.display !== "none"){
  1218. sidebar.children[i].style.display = "none";
  1219. let choosables = [];
  1220. switch(sidebar.children[i].id){
  1221. case "ingredientDetails":
  1222. choosables = document.querySelectorAll(".ingredient");
  1223. break;
  1224. case "transactionDetails":
  1225. choosables = document.getElementById("transactionsList").children;
  1226. break;
  1227. case "recipeDetails":
  1228. choosables = document.getElementById("recipeList").children;
  1229. break;
  1230. case "orderDetails":
  1231. choosables = document.getElementById("orderList").children;
  1232. break;
  1233. }
  1234. for(let i = 0; i < choosables.length; i++){
  1235. choosables[i].classList.remove("active");
  1236. }
  1237. }
  1238. }
  1239. sidebar.classList = "sidebarHide";
  1240. if(window.screen.availWidth <= 1000){
  1241. document.querySelector(".contentBlock").style.display = "flex";
  1242. document.getElementById("mobileMenuSelector").style.display = "block";
  1243. document.getElementById("sidebarCloser").style.display = "none";
  1244. }
  1245. },
  1246. changeMenu: function(){
  1247. let menu = document.querySelector(".menu");
  1248. let buttons = document.querySelectorAll(".menuButton");
  1249. if(!menu.classList.contains("menuMinimized")){
  1250. menu.classList = "menu menuMinimized";
  1251. for(let i = 0; i < buttons.length; i++){
  1252. buttons[i].children[1].style.display = "none";
  1253. }
  1254. document.getElementById("max").style.display = "none";
  1255. document.getElementById("min").style.display = "flex";
  1256. }else if(menu.classList.contains("menuMinimized")){
  1257. menu.classList = "menu";
  1258. for(let i = 0; i < buttons.length; i++){
  1259. buttons[i].children[1].style.display = "block";
  1260. }
  1261. setTimeout(()=>{
  1262. document.getElementById("max").style.display = "flex";
  1263. document.getElementById("min").style.display = "none";
  1264. }, 150);
  1265. }
  1266. },
  1267. openMenu: function(){
  1268. document.getElementById("menu").style.display = "flex";
  1269. document.querySelector(".contentBlock").style.display = "none";
  1270. document.getElementById("mobileMenuSelector").onclick = ()=>{this.closeMenu()};
  1271. },
  1272. closeMenu: function(){
  1273. document.getElementById("menu").style.display = "none";
  1274. document.querySelector(".contentBlock").style.display = "flex";
  1275. document.getElementById("mobileMenuSelector").onclick = ()=>{this.openMenu()};
  1276. },
  1277. /*
  1278. Converts the price of unit back to the price per default unit
  1279. unitType = type of the unit (i.e. mass, volume)
  1280. unit = exact unit to convert to
  1281. price = price of the ingredient per unit in cents
  1282. */
  1283. reconvertPrice(unitType, unit, price){
  1284. if(unitType === "mass"){
  1285. switch(unit){
  1286. case "g": break;
  1287. case "kg": price *= 1000; break;
  1288. case "oz": price *= 28.3495; break;
  1289. case "lb": price *= 453.5924; break;
  1290. }
  1291. }else if(unitType === "volume"){
  1292. switch(unit){
  1293. case "ml": price /= 1000; break;
  1294. case "l": break;
  1295. case "tsp": price /= 202.8842; break;
  1296. case "tbsp": price /= 67.6278; break;
  1297. case "ozfl": price /= 33.8141; break;
  1298. case "cup": price /= 4.1667; break;
  1299. case "pt": price /= 2.1134; break;
  1300. case "qt": price /= 1.0567; break;
  1301. case "gal": price *= 3.7854; break;
  1302. }
  1303. }else if(unitType === "length"){
  1304. switch(unit){
  1305. case "mm": price /= 1000; break;
  1306. case "cm": price /= 100; break;
  1307. case "m": break;
  1308. case "in": price /= 39.3701; break;
  1309. case "ft": price /= 3.2808; break;
  1310. }
  1311. }
  1312. return price;
  1313. }
  1314. }
  1315. if(window.screen.availWidth > 1000 && window.screen.availWidth <= 1400){
  1316. this.changeMenu();
  1317. document.getElementById("menuShifter2").style.display = "none";
  1318. }
  1319. //Add click listeners for menu buttons
  1320. document.getElementById("homeBtn").onclick = ()=>{controller.openStrand("home")};
  1321. document.getElementById("ingredientsBtn").onclick = ()=>{controller.openStrand("ingredients")};
  1322. document.getElementById("recipeBookBtn").onclick = ()=>{controller.openStrand("recipeBook")};
  1323. document.getElementById("analyticsBtn").onclick = ()=>{controller.openStrand("analytics")};
  1324. document.getElementById("ordersBtn").onclick = async ()=>{
  1325. if(merchant.orders.length === 0){
  1326. merchant.setOrders(await orders.getOrders(Order));
  1327. }
  1328. controller.openStrand("orders", merchant.orders);
  1329. }
  1330. document.getElementById("transactionsBtn").onclick = ()=>{controller.openStrand("transactions", merchant.getTransactions())};
  1331. controller.openStrand("home");
  1332. },{"./classes/Ingredient.js":1,"./classes/Merchant.js":2,"./classes/Order.js":3,"./classes/Recipe.js":4,"./classes/Transaction.js":5,"./sidebars/editIngredient.js":7,"./sidebars/editRecipe.js":8,"./sidebars/ingredientDetails.js":9,"./sidebars/newIngredient.js":10,"./sidebars/newOrder.js":11,"./sidebars/newRecipe.js":12,"./sidebars/newTransaction.js":13,"./sidebars/orderDetails.js":14,"./sidebars/orderFilter.js":15,"./sidebars/recipeDetails.js":16,"./sidebars/transactionDetails.js":17,"./sidebars/transactionFilter.js":18,"./strands/analytics.js":19,"./strands/home.js":20,"./strands/ingredients.js":21,"./strands/orders.js":22,"./strands/recipeBook.js":23,"./strands/transactions.js":24}],7:[function(require,module,exports){
  1333. let editIngredient = {
  1334. display: function(ingredient){
  1335. let buttonList = document.getElementById("unitButtons");
  1336. let quantLabel = document.getElementById("editIngQuantityLabel");
  1337. let specialLabel = document.getElementById("editSpecialLabel");
  1338. //Clear any existing data
  1339. while(buttonList.children.length > 0){
  1340. buttonList.removeChild(buttonList.firstChild);
  1341. }
  1342. //Populate basic fields
  1343. document.getElementById("editIngTitle").innerText = ingredient.ingredient.name;
  1344. document.getElementById("editIngName").value = ingredient.ingredient.name;
  1345. document.getElementById("editIngCategory").value = ingredient.ingredient.category;
  1346. quantLabel.innerText = `CURRENT STOCK (${ingredient.ingredient.unit.toUpperCase()})`;
  1347. document.getElementById("editIngSubmit").onclick = ()=>{this.submit(ingredient)};
  1348. //Populate the unit buttons
  1349. const units = merchant.units[ingredient.ingredient.unitType];
  1350. for(let i = 0; i < units.length; i++){
  1351. let button = document.createElement("button");
  1352. button.classList.add("unitButton");
  1353. button.innerText = units[i].toUpperCase();
  1354. button.onclick = ()=>{this.changeUnit(button)};
  1355. buttonList.appendChild(button);
  1356. if(units[i] === ingredient.ingredient.unit){
  1357. button.classList.add("unitActive");
  1358. }
  1359. }
  1360. //Make any changes for special ingredients
  1361. if(ingredient.ingredient.specialUnit === "bottle"){
  1362. quantLabel.innerText = "CURRENT STOCK (BOTTLES):";
  1363. specialLabel.style.display = "flex";
  1364. specialLabel.innerText = `BOTTLE SIZE (${ingredient.ingredient.unit.toUpperCase()}):`;
  1365. let sizeInput = document.createElement("input");
  1366. sizeInput.id = "editIngSpecialSize";
  1367. sizeInput.type = "number";
  1368. sizeInput.min = "0";
  1369. sizeInput.step = "0.01";
  1370. sizeInput.value = ingredient.ingredient.unitSize.toFixed(2);
  1371. specialLabel.appendChild(sizeInput);
  1372. }else{
  1373. specialLabel.style.display = "none";
  1374. }
  1375. let quantInput = document.createElement("input");
  1376. quantInput.id = "editIngQuantity";
  1377. quantInput.type = "number";
  1378. quantInput.min = "0";
  1379. quantInput.step = "0.01";
  1380. quantInput.value = ingredient.quantity.toFixed(2);
  1381. quantLabel.appendChild(quantInput);
  1382. },
  1383. changeUnit(button){
  1384. let buttons = document.getElementById("unitButtons");
  1385. for(let i = 0; i < buttons.children.length; i++){
  1386. buttons.children[i].classList.remove("unitActive");
  1387. }
  1388. button.classList.add("unitActive");
  1389. },
  1390. submit(ingredient){
  1391. const quantity = parseFloat(document.getElementById("editIngQuantityLabel").children[0].value);
  1392. let data = {
  1393. id: ingredient.ingredient.id,
  1394. name: document.getElementById("editIngName").value,
  1395. category: document.getElementById("editIngCategory").value
  1396. }
  1397. //Add data based on unit type
  1398. if(ingredient.ingredient.specialUnit === "bottle"){
  1399. let unitSize = ingredient.convertToBase(parseFloat(document.getElementById("editSpecialLabel").children[0].value));
  1400. data.quantity = quantity * unitSize;
  1401. data.unitSize = unitSize;
  1402. }else{
  1403. data.quantity = ingredient.convertToBase(quantity);
  1404. }
  1405. //Get the measurement unit
  1406. let units = document.getElementById("unitButtons");
  1407. for(let i = 0; i < units.children.length; i++){
  1408. if(units.children[i].classList.contains("unitActive")){
  1409. data.unit = units.children[i].innerText.toLowerCase();
  1410. break;
  1411. }
  1412. }
  1413. let loader = document.getElementById("loaderContainer");
  1414. loader.style.display = "flex";
  1415. fetch("/ingredients/update", {
  1416. method: "put",
  1417. headers: {
  1418. "Content-Type": "application/json;charset=utf-8"
  1419. },
  1420. body: JSON.stringify(data)
  1421. })
  1422. .then(response => response.json())
  1423. .then((response)=>{
  1424. if(typeof(response) === "string"){
  1425. banner.createError(response);
  1426. }else{
  1427. ingredient.ingredient.name = response.ingredient.name;
  1428. ingredient.ingredient.category = response.ingredient.category;
  1429. ingredient.ingredient.unitSize = response.ingredient.unitSize;
  1430. ingredient.ingredient.unit = response.unit;
  1431. merchant.updateIngredient(ingredient, response.quantity);
  1432. controller.openStrand("ingredients");
  1433. banner.createNotification("INGREDIENT UPDATED");
  1434. }
  1435. })
  1436. .catch((err)=>{
  1437. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1438. })
  1439. .finally(()=>{
  1440. loader.style.display = "none";
  1441. });
  1442. }
  1443. }
  1444. module.exports = editIngredient;
  1445. },{}],8:[function(require,module,exports){
  1446. let editRecipe = {
  1447. display: function(recipe){
  1448. let nameInput = document.getElementById("editRecipeName");
  1449. if(merchant.pos === "none"){
  1450. nameInput.value = recipe.name;
  1451. }else{
  1452. document.getElementById("editRecipeNoName").innertext = recipe.name;
  1453. nameInput.parentNode.style.display = "none";
  1454. }
  1455. //Populate ingredients
  1456. let ingredientList = document.getElementById("editRecipeIngList");
  1457. while(ingredientList.children.length > 0){
  1458. ingredientList.removeChild(ingredientList.firstChild);
  1459. }
  1460. let template = document.getElementById("editRecipeIng").content.children[0];
  1461. for(let i = 0; i < recipe.ingredients.length; i++){
  1462. let ingredientDiv = template.cloneNode(true);
  1463. ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
  1464. ingredientDiv.children[1].innerText = recipe.ingredients[i].ingredient.getNameAndUnit();
  1465. ingredientDiv.children[2].style.display = "none";
  1466. ingredientDiv.children[3].value = recipe.ingredients[i].quantity;
  1467. ingredientDiv.ingredient = recipe.ingredients[i];
  1468. ingredientList.appendChild(ingredientDiv);
  1469. }
  1470. document.getElementById("addRecIng").onclick = ()=>{this.newIngredient()};
  1471. document.getElementById("editRecipePrice").value = recipe.price;
  1472. document.getElementById("editRecipeSubmit").onclick = ()=>{this.submit(recipe)};
  1473. document.getElementById("editRecipeCancel").onclick = ()=>{controller.openSidebar("recipeDetails", recipe)};
  1474. },
  1475. newIngredient: function(){
  1476. let ingredientList = document.getElementById("editRecipeIngList");
  1477. let ingredientDiv = document.getElementById("editRecipeIng").content.children[0].cloneNode(true);
  1478. ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
  1479. ingredientDiv.children[1].style.display = "none";
  1480. ingredientDiv.children[3].value = "0.00";
  1481. //Populate selector
  1482. let categories = merchant.categorizeIngredients();
  1483. for(let i = 0; i < categories.length; i++){
  1484. let group = document.createElement("optgroup");
  1485. group.label = categories[i].name;
  1486. for(let j = 0; j < categories[i].ingredients.length; j++){
  1487. let option = document.createElement("option");
  1488. option.innerText = categories[i].ingredients[j].ingredient.getNameAndUnit();
  1489. option.ingredient = categories[i].ingredients[j];
  1490. group.appendChild(option);
  1491. }
  1492. ingredientDiv.children[2].appendChild(group);
  1493. }
  1494. ingredientList.appendChild(ingredientDiv);
  1495. },
  1496. submit: function(recipe){
  1497. let data = {
  1498. id: recipe.id,
  1499. name: recipe.name,
  1500. price: document.getElementById("editRecipePrice").value * 100,
  1501. ingredients: []
  1502. }
  1503. if(merchant.pos === "none"){
  1504. data.name = document.getElementById("editRecipeName").value;
  1505. }
  1506. let ingredients = document.getElementById("editRecipeIngList").children;
  1507. for(let i = 0; i < ingredients.length; i++){
  1508. const quantity = parseFloat(ingredients[i].children[3].value);
  1509. if(ingredients[i].children[1].style.display === "none"){
  1510. let selector = ingredients[i].children[2];
  1511. let ingredient = selector.options[selector.selectedIndex].ingredient;
  1512. data.ingredients.push({
  1513. ingredient: ingredient.ingredient.id,
  1514. quantity: ingredient.convertToBase(quantity)
  1515. });
  1516. }else{
  1517. data.ingredients.push({
  1518. ingredient: ingredients[i].ingredient.ingredient.id,
  1519. quantity: ingredients[i].ingredient.convertToBase(quantity)
  1520. });
  1521. }
  1522. }
  1523. let loader = document.getElementById("loaderContainer");
  1524. loader.style.display = "flex";
  1525. fetch("/recipe/update", {
  1526. method: "put",
  1527. headers: {
  1528. "Content-Type": "application/json;charset=utf-8"
  1529. },
  1530. body: JSON.stringify(data)
  1531. })
  1532. .then(response => response.json())
  1533. .then((response)=>{
  1534. if(typeof(response) === "string"){
  1535. banner.createError(response);
  1536. }else{
  1537. merchant.updateRecipe(response);
  1538. controller.openStrand("recipeBook");
  1539. banner.createNotification("RECIPE UPDATED");
  1540. }
  1541. })
  1542. .catch((err)=>{
  1543. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1544. })
  1545. .finally(()=>{
  1546. loader.style.display = "none";
  1547. });
  1548. }
  1549. }
  1550. module.exports = editRecipe;
  1551. },{}],9:[function(require,module,exports){
  1552. let ingredientDetails = {
  1553. dailyUse: 0,
  1554. display: function(ingredient){
  1555. document.getElementById("editIngBtn").onclick = ()=>{controller.openSidebar("editIngredient", ingredient)};
  1556. document.getElementById("removeIngBtn").onclick = ()=>{this.remove(ingredient)};
  1557. document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
  1558. document.getElementById("ingredientDetailsName").innerText = ingredient.ingredient.name;
  1559. document.getElementById("ingredientStock").innerText = ingredient.getQuantityDisplay();
  1560. //Calculate and display average daily use
  1561. let quantities = [];
  1562. let now = new Date();
  1563. for(let i = 1; i < 31; i++){
  1564. let endDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i)
  1565. let startDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i - 1);
  1566. quantities.push(merchant.getSingleIngredientSold(ingredient, startDay, endDay));
  1567. }
  1568. let sum = 0;
  1569. for(let i = 0; i < quantities.length; i++){
  1570. sum += quantities[i];
  1571. }
  1572. let dailyUse = sum / quantities.length;
  1573. const dailyUseDiv = document.getElementById("dailyUse");
  1574. if(ingredient.ingredient.specialUnit === "bottle"){
  1575. dailyUseDiv.innerText = `${dailyUse.toFixed(2)} BOTTLES`;
  1576. }else{
  1577. dailyUseDiv.innerText = `${dailyUse.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1578. }
  1579. //Show recipes that this ingredient is a part of
  1580. let recipeList = document.getElementById("ingredientRecipeList");
  1581. let template = document.getElementById("ingredientRecipe").content.children[0];
  1582. let recipes = merchant.getRecipesForIngredient(ingredient.ingredient);
  1583. while(recipeList.children.length > 0){
  1584. recipeList.removeChild(recipeList.firstChild);
  1585. }
  1586. for(let i = 0; i < recipes.length; i++){
  1587. let recipeDiv = template.cloneNode(true);
  1588. recipeDiv.children[0].innerText = recipes[i].name;
  1589. recipeDiv.onclick = ()=>{
  1590. controller.openStrand("recipeBook");
  1591. controller.openSidebar("recipeDetails", recipes[i]);
  1592. }
  1593. recipeDiv.classList.add("choosable");
  1594. recipeList.appendChild(recipeDiv);
  1595. }
  1596. },
  1597. remove: function(ingredient){
  1598. for(let i = 0; i < merchant.recipes.length; i++){
  1599. for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
  1600. if(ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
  1601. banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");
  1602. return;
  1603. }
  1604. }
  1605. }
  1606. let loader = document.getElementById("loaderContainer");
  1607. loader.style.display = "flex";
  1608. fetch(`/ingredients/remove/${ingredient.ingredient.id}`, {
  1609. method: "delete",
  1610. })
  1611. .then((response) => response.json())
  1612. .then((response)=>{
  1613. if(typeof(response) === "string"){
  1614. banner.createError(response);
  1615. }else{
  1616. merchant.removeIngredient(ingredient);
  1617. controller.openStrand("ingredients");
  1618. banner.createNotification("INGREDIENT REMOVED");
  1619. }
  1620. })
  1621. .catch((err)=>{})
  1622. .finally(()=>{
  1623. loader.style.display = "none";
  1624. });
  1625. }
  1626. }
  1627. module.exports = ingredientDetails;
  1628. },{}],10:[function(require,module,exports){
  1629. let newIngredient = {
  1630. display: function(Ingredient){
  1631. const selector = document.getElementById("unitSelector");
  1632. document.getElementById("newIngName").value = "";
  1633. document.getElementById("newIngCategory").value = "";
  1634. document.getElementById("newIngQuantity").value = 0;
  1635. document.getElementById("bottleSizeLabel").style.display = "none";
  1636. selector.value = "g";
  1637. selector.onchange = ()=>{this.unitChange()};
  1638. document.getElementById("submitNewIng").onclick = ()=>{this.submit(Ingredient)};
  1639. },
  1640. unitChange: function(){
  1641. const select = document.getElementById("unitSelector");
  1642. const bottleLabel = document.getElementById("bottleSizeLabel");
  1643. if(select.value === "bottle"){
  1644. bottleLabel.style.display = "block";
  1645. }else{
  1646. bottleLabel.style.display = "none";
  1647. }
  1648. },
  1649. submit: function(Ingredient){
  1650. let unitSelector = document.getElementById("unitSelector");
  1651. let options = document.querySelectorAll("#unitSelector option");
  1652. const quantityValue = parseFloat(document.getElementById("newIngQuantity").value);
  1653. let unit = unitSelector.value;
  1654. let newIngredient = {
  1655. ingredient: {
  1656. name: document.getElementById("newIngName").value,
  1657. category: document.getElementById("newIngCategory").value,
  1658. unitType: options[unitSelector.selectedIndex].getAttribute("type")
  1659. },
  1660. quantity: quantityValue,
  1661. defaultUnit: unit
  1662. }
  1663. //Change the ingredient if it is a special unit type (ie "bottle")
  1664. if(unit === "bottle"){
  1665. newIngredient.ingredient.unitType = "volume";
  1666. newIngredient.ingredient.unitSize = document.getElementById("bottleSize").value;
  1667. newIngredient.defaultUnit = document.getElementById("bottleUnits").value;
  1668. newIngredient.ingredient.specialUnit = unit;
  1669. newIngredient.quantity = quantityValue;
  1670. }
  1671. let loader = document.getElementById("loaderContainer");
  1672. loader.style.display = "flex";
  1673. fetch("/ingredients/create", {
  1674. method: "POST",
  1675. headers: {
  1676. "Content-Type": "application/json;charset=utf-8"
  1677. },
  1678. body: JSON.stringify(newIngredient)
  1679. })
  1680. .then((response) => response.json())
  1681. .then((response)=>{
  1682. if(typeof(response) === "string"){
  1683. banner.createError(response);
  1684. }else{
  1685. const ingredient = new Ingredient(
  1686. response.ingredient._id,
  1687. response.ingredient.name,
  1688. response.ingredient.category,
  1689. response.ingredient.unitType,
  1690. response.defaultUnit,
  1691. merchant,
  1692. response.ingredient.specialUnit,
  1693. response.ingredient.unitSize
  1694. )
  1695. merchant.addIngredient(ingredient, response.quantity);
  1696. controller.openStrand("ingredients");
  1697. banner.createNotification("INGREDIENT CREATED");
  1698. }
  1699. })
  1700. .catch((err)=>{
  1701. console.log(err);
  1702. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1703. })
  1704. .finally(()=>{
  1705. loader.style.display = "none";
  1706. });
  1707. },
  1708. }
  1709. module.exports = newIngredient;
  1710. },{}],11:[function(require,module,exports){
  1711. let newOrder = {
  1712. display: function(Order){
  1713. document.getElementById("sidebarDiv").classList.add("sidebarWide");
  1714. document.getElementById("newOrderIngredientList").style.display = "flex";
  1715. let selectedList = document.getElementById("selectedIngredientList");
  1716. while(selectedList.children.length > 0){
  1717. selectedList.removeChild(selectedList.firstChild);
  1718. }
  1719. let ingredientList = document.getElementById("newOrderIngredients");
  1720. while(ingredientList.children.length > 0){
  1721. ingredientList.removeChild(ingredientList.firstChild);
  1722. }
  1723. for(let i = 0; i < merchant.ingredients.length; i++){
  1724. let ingredient = document.createElement("button");
  1725. ingredient.classList = "choosable";
  1726. ingredient.innerText = merchant.ingredients[i].ingredient.name;
  1727. ingredient.onclick = ()=>{this.addIngredient(merchant.ingredients[i], ingredient)};
  1728. ingredientList.appendChild(ingredient);
  1729. }
  1730. document.getElementById("submitNewOrder").onclick = ()=>{this.submit(Order)};
  1731. },
  1732. addIngredient: function(ingredient, element){
  1733. element.style.display = "none";
  1734. let div = document.getElementById("selectedIngredient").content.children[0].cloneNode(true);
  1735. div.ingredient = ingredient;
  1736. div.children[0].children[1].onclick = ()=>{this.removeIngredient(div, element)};
  1737. //Display units depending on the whether it is a special unit
  1738. if(ingredient.ingredient.specialUnit === "bottle"){
  1739. div.children[0].children[0].innerText = `${ingredient.ingredient.name} (BOTTLES)`;
  1740. }else{
  1741. div.children[0].children[0].innerText = `${ingredient.ingredient.name} (${ingredient.ingredient.unit.toUpperCase()})`;
  1742. }
  1743. document.getElementById("selectedIngredientList").appendChild(div);
  1744. },
  1745. removeIngredient: function(selectedElement, element){
  1746. selectedElement.parentElement.removeChild(selectedElement);
  1747. element.style.display = "block";
  1748. },
  1749. submit: function(Order){
  1750. let date = document.getElementById("newOrderDate").value;
  1751. let taxes = document.getElementById("orderTaxes").value * 100;
  1752. let fees = document.getElementById("orderFees").value * 100;
  1753. let ingredients = document.getElementById("selectedIngredientList").children;
  1754. if(date === ""){
  1755. banner.createError("DATE IS REQUIRED FOR ORDERS");
  1756. return;
  1757. }
  1758. let data = {
  1759. name: document.getElementById("newOrderName").value,
  1760. date: date,
  1761. taxes: taxes,
  1762. fees: fees,
  1763. ingredients: []
  1764. }
  1765. for(let i = 0; i < ingredients.length; i++){
  1766. let quantity = ingredients[i].children[1].children[0].value;
  1767. let price = ingredients[i].children[1].children[1].value;
  1768. if(quantity === "" || price === ""){
  1769. banner.createError("MUST PROVIDE QUANTITY AND PRICE PER UNIT FOR ALL INGREDIENTS");
  1770. return;
  1771. }
  1772. if(quantity < 0 || price < 0){
  1773. banner.createError("QUANTITY AND PRICE MUST BE NON-NEGATIVE NUMBERS");
  1774. }
  1775. if(ingredients[i].ingredient.ingredient.specialUnit === "bottle"){
  1776. data.ingredients.push({
  1777. ingredient: ingredients[i].ingredient.ingredient.id,
  1778. quantity: quantity * ingredients[i].ingredient.ingredient.unitSize,
  1779. pricePerUnit: this.convertPrice(ingredients[i].ingredient.ingredient, price * 100)
  1780. });
  1781. }else{
  1782. data.ingredients.push({
  1783. ingredient: ingredients[i].ingredient.ingredient.id,
  1784. quantity: ingredients[i].ingredient.convertToBase(quantity),
  1785. pricePerUnit: this.convertPrice(ingredients[i].ingredient.ingredient, price * 100)
  1786. });
  1787. }
  1788. }
  1789. let loader = document.getElementById("loaderContainer");
  1790. loader.style.display = "flex";
  1791. fetch("/order/create", {
  1792. method: "post",
  1793. headers: {
  1794. "Content-Type": "application/json;charset=utf-8"
  1795. },
  1796. body: JSON.stringify(data)
  1797. })
  1798. .then((response)=>response.json())
  1799. .then((response)=>{
  1800. if(typeof(response) === "string"){
  1801. banner.createError(response);
  1802. }else{
  1803. let order = new Order(
  1804. response._id,
  1805. response.name,
  1806. response.date,
  1807. response.taxes,
  1808. response.fees,
  1809. response.ingredients,
  1810. merchant
  1811. );
  1812. merchant.addOrder(order, true);
  1813. controller.openStrand("orders", merchant.orders);
  1814. banner.createNotification("NEW ORDER CREATED");
  1815. }
  1816. })
  1817. .catch((err)=>{
  1818. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1819. })
  1820. .finally(()=>{
  1821. loader.style.display = "none";
  1822. });
  1823. },
  1824. convertPrice: function(ingredient, price){
  1825. if(ingredient.specialUnit === "bottle"){
  1826. return price / ingredient.unitSize;
  1827. }
  1828. switch(ingredient.unit){
  1829. case "g": return price;
  1830. case "kg": return price / 1000;
  1831. case "oz": return price / 28.3495;
  1832. case "lb": return price / 453.5924;
  1833. case "ml": return price * 1000;
  1834. case "l": return price;
  1835. case "tsp": return price * 202.8842;
  1836. case "tbsp": return price * 67.6278;
  1837. case "ozfl": return price * 33.8141;
  1838. case "cup": return price * 4.1667;
  1839. case "pt": return price * 2.1134;
  1840. case "qt": return price * 1.0567;
  1841. case "gal": return price / 3.7854;
  1842. case "mm": return price * 1000;
  1843. case "cm": return price * 100;
  1844. case "m": return price;
  1845. case "in": return price * 39.3701;
  1846. case "ft": return price * 3.2808;
  1847. }
  1848. }
  1849. }
  1850. module.exports = newOrder;
  1851. },{}],12:[function(require,module,exports){
  1852. let newRecipe = {
  1853. display: function(Recipe){
  1854. document.getElementById("newRecipeName").value = "";
  1855. document.getElementById("newRecipePrice").value = "";
  1856. document.getElementById("ingredientCount").value = 1;
  1857. let categories = merchant.categorizeIngredients();
  1858. let ingredientsSelect = document.getElementById("recipeInputIngredients");
  1859. while(ingredientsSelect.children.length > 0){
  1860. ingredientsSelect.removeChild(ingredientsSelect.firstChild);
  1861. }
  1862. this.changeIngredientCount(categories);
  1863. document.getElementById("ingredientCount").onchange = ()=>{this.changeIngredientCount(categories)};
  1864. document.getElementById("submitNewRecipe").onclick = ()=>{this.submit(Recipe)};
  1865. },
  1866. //Updates the number of ingredient inputs displayed for new recipes
  1867. changeIngredientCount: function(categories){
  1868. let newCount = document.getElementById("ingredientCount").value;
  1869. let ingredientsDiv = document.getElementById("recipeInputIngredients");
  1870. let template = document.getElementById("recipeInputIngredient").content.children[0];
  1871. let oldCount = ingredientsDiv.children.length;
  1872. if(newCount > oldCount){
  1873. let newDivs = newCount - oldCount;
  1874. for(let i = 0; i < newDivs; i++){
  1875. let newNode = template.cloneNode(true);
  1876. newNode.children[0].innnerText = `INGREDIENT ${i + oldCount}`;
  1877. newNode.children[2].children[0].value = 0;
  1878. for(let j = 0; j < categories.length; j++){
  1879. let optgroup = document.createElement("optgroup");
  1880. optgroup.label = categories[j].name;
  1881. for(let k = 0; k < categories[j].ingredients.length; k++){
  1882. let option = document.createElement("option");
  1883. option.innerText = categories[j].ingredients[k].ingredient.getNameAndUnit();
  1884. option.ingredient = categories[j].ingredients[k];
  1885. optgroup.appendChild(option);
  1886. }
  1887. newNode.children[1].children[0].appendChild(optgroup);
  1888. }
  1889. ingredientsDiv.appendChild(newNode);
  1890. }
  1891. for(let i = 0; i < newCount; i++){
  1892. ingredientsDiv.children[i].children[0].innerText = `INGREDIENT ${i + 1}`;
  1893. }
  1894. }else if(newCount < oldCount){
  1895. let newDivs = oldCount - newCount;
  1896. for(let i = 0; i < newDivs; i++){
  1897. ingredientsDiv.removeChild(ingredientsDiv.children[ingredientsDiv.children.length-1]);
  1898. }
  1899. }
  1900. },
  1901. submit: function(Recipe){
  1902. let newRecipe = {
  1903. name: document.getElementById("newRecipeName").value,
  1904. price: document.getElementById("newRecipePrice").value,
  1905. ingredients: []
  1906. }
  1907. let inputs = document.getElementById("recipeInputIngredients").children;
  1908. for(let i = 0; i < inputs.length; i++){
  1909. let sel = inputs[i].children[1].children[0];
  1910. let ingredient = sel.options[sel.selectedIndex].ingredient;
  1911. newRecipe.ingredients.push({
  1912. ingredient: ingredient.ingredient.id,
  1913. quantity: ingredient.convertToBase(inputs[i].children[2].children[0].value)
  1914. });
  1915. }
  1916. let loader = document.getElementById("loaderContainer");
  1917. loader.style.display = "flex";
  1918. fetch("/recipe/create", {
  1919. method: "POST",
  1920. headers: {
  1921. "Content-Type": "application/json;charset=utf-8"
  1922. },
  1923. body: JSON.stringify(newRecipe)
  1924. })
  1925. .then((response) => response.json())
  1926. .then((response)=>{
  1927. if(typeof(response) === "string"){
  1928. banner.createError(response);
  1929. }else{
  1930. let ingredients = [];
  1931. for(let i = 0; i < response.ingredients.length; i++){
  1932. for(let j = 0; j < merchant.ingredients.length; j++){
  1933. if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
  1934. ingredients.push({
  1935. ingredient: merchant.ingredients[j].ingredient,
  1936. quantity: response.ingredients[i].quantity
  1937. });
  1938. break;
  1939. }
  1940. }
  1941. }
  1942. merchant.addRecipe(new Recipe(
  1943. response._id,
  1944. response.name,
  1945. response.price,
  1946. ingredients,
  1947. merchant
  1948. ));
  1949. banner.createNotification("RECIPE CREATED");
  1950. controller.openStrand("recipeBook");
  1951. }
  1952. })
  1953. .catch((err)=>{
  1954. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1955. })
  1956. .finally(()=>{
  1957. loader.style.display = "none";
  1958. });
  1959. },
  1960. }
  1961. module.exports = newRecipe;
  1962. },{}],13:[function(require,module,exports){
  1963. let newTransaction = {
  1964. display: function(Transaction){
  1965. let recipeList = document.getElementById("newTransactionRecipes");
  1966. let template = document.getElementById("createTransaction").content.children[0];
  1967. while(recipeList.children.length > 0){
  1968. recipeList.removeChild(recipeList.firstChild);
  1969. }
  1970. for(let i = 0; i < merchant.recipes.length; i++){
  1971. let recipeDiv = template.cloneNode(true);
  1972. recipeDiv.recipe = merchant.recipes[i];
  1973. recipeList.appendChild(recipeDiv);
  1974. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  1975. }
  1976. document.getElementById("submitNewTransaction").onclick = ()=>{this.submit(Transaction)};
  1977. },
  1978. submit: function(Transaction){
  1979. let recipeDivs = document.getElementById("newTransactionRecipes");
  1980. let date = document.getElementById("newTransactionDate").valueAsDate;
  1981. if(date > new Date()){
  1982. banner.createError("CANNOT HAVE A DATE IN THE FUTURE");
  1983. return;
  1984. }
  1985. let data = {
  1986. date: date,
  1987. recipes: [],
  1988. ingredientUpdates: {}
  1989. };
  1990. for(let i = 0; i < recipeDivs.children.length; i++){
  1991. let quantity = recipeDivs.children[i].children[1].value;
  1992. const recipe = recipeDivs.children[i].recipe;
  1993. if(quantity !== "" && quantity > 0){
  1994. data.recipes.push({
  1995. recipe: recipe.id,
  1996. quantity: quantity
  1997. });
  1998. for(let j = 0; j < recipe.ingredients.length; j++){
  1999. let ingredient = recipe.ingredients[j];
  2000. if(data.ingredientUpdates[ingredient.ingredient.id]){
  2001. data.ingredientUpdates[ingredient.ingredient.id] += ingredient.convertToBase(ingredient.quantity) * quantity;
  2002. }else{
  2003. data.ingredientUpdates[ingredient.ingredient.id] = ingredient.convertToBase(ingredient.quantity) * quantity;
  2004. }
  2005. }
  2006. }else if(quantity < 0){
  2007. banner.createError("CANNOT HAVE NEGATIVE VALUES");
  2008. return;
  2009. }
  2010. }
  2011. if(data.recipes.length > 0){
  2012. let loader = document.getElementById("loaderContainer");
  2013. loader.style.display = "flex";
  2014. fetch("/transaction/create", {
  2015. method: "post",
  2016. headers: {
  2017. "Content-Type": "application/json;charset=utf-8"
  2018. },
  2019. body: JSON.stringify(data)
  2020. })
  2021. .then(response => response.json())
  2022. .then((response)=>{
  2023. if(typeof(response) === "string"){
  2024. banner.createError(response);
  2025. }else{
  2026. const transaction = new Transaction(
  2027. response._id,
  2028. response.date,
  2029. response.recipes,
  2030. merchant
  2031. );
  2032. merchant.addTransaction(transaction);
  2033. controller.openStrand("transactions", merchant.getTransactions());
  2034. banner.createNotification("TRANSACTION CREATED");
  2035. }
  2036. })
  2037. .catch((err)=>{
  2038. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2039. })
  2040. .finally(()=>{
  2041. loader.style.display = "none";
  2042. });
  2043. }
  2044. }
  2045. }
  2046. module.exports = newTransaction;
  2047. },{}],14:[function(require,module,exports){
  2048. let orderDetails = {
  2049. display: function(order){
  2050. document.getElementById("removeOrderBtn").onclick = ()=>{this.remove(order)};
  2051. document.getElementById("orderDetailName").innerText = order.name;
  2052. document.getElementById("orderDetailDate").innerText = order.date.toLocaleDateString("en-US");
  2053. document.getElementById("orderDetailTax").innerText = `$${order.taxes.toFixed(2)}`;
  2054. document.getElementById("orderDetailFee").innerText = `$${order.fees.toFixed(2)}`;
  2055. let ingredientList = document.getElementById("orderIngredients");
  2056. while(ingredientList.children.length > 0){
  2057. ingredientList.removeChild(ingredientList.firstChild);
  2058. }
  2059. let template = document.getElementById("orderIngredient").content.children[0];
  2060. for(let i = 0; i < order.ingredients.length; i++){
  2061. let ingredientDiv = template.cloneNode(true);
  2062. const ingredient = order.ingredients[i].ingredient;
  2063. ingredientDiv.children[0].innerText = order.ingredients[i].ingredient.name;
  2064. ingredientDiv.children[2].innerText = `$${order.ingredients[i].cost().toFixed(2)}`;
  2065. ingredientDiv.onclick = ()=>{
  2066. controller.openStrand("ingredients");
  2067. controller.openSidebar("ingredientDetails", merchant.getIngredient(order.ingredients[i].ingredient.id));
  2068. }
  2069. let ingredientDisplay = ingredientDiv.children[1];
  2070. if(ingredient.specialUnit === "bottle"){
  2071. ingredientDisplay.innerText = `${order.ingredients[i].quantity.toFixed(2)} bottles x $${order.ingredients.pricePerUnit.toFixed(2)}`;
  2072. }else{
  2073. ingredientDisplay.innerText = `${order.ingredients[i].quantity.toFixed(2)} ${ingredient.unit.toUpperCase()} X $${order.ingredients[i].pricePerUnit.toFixed(2)}`;
  2074. }
  2075. ingredientList.appendChild(ingredientDiv);
  2076. }
  2077. document.getElementById("orderDetailTotal").innerText = `$${order.getIngredientCost().toFixed(2)}`;
  2078. document.querySelector("#orderTotalPrice p").innerText = `$${order.getTotalCost().toFixed(2)}`;
  2079. },
  2080. remove: function(order){
  2081. let loader = document.getElementById("loaderContainer");
  2082. loader.style.display = "flex";
  2083. fetch(`/order/${order.id}`, {
  2084. method: "DELETE",
  2085. headers: {
  2086. "Content-Type": "application/json;charset=utf-8"
  2087. }
  2088. })
  2089. .then((response) => response.json())
  2090. .then((response)=>{
  2091. if(typeof(response) === "string"){
  2092. banner.createError(response);
  2093. }else{
  2094. merchant.removeOrder(order);
  2095. controller.openStrand("orders", merchant.orders);
  2096. banner.createNotification("ORDER REMOVED");
  2097. }
  2098. })
  2099. .catch((err)=>{
  2100. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2101. })
  2102. .finally(()=>{
  2103. loader.style.display = "none";
  2104. });
  2105. }
  2106. }
  2107. module.exports = orderDetails;
  2108. },{}],15:[function(require,module,exports){
  2109. let orderFilter = {
  2110. display: function(Order){
  2111. let now = new Date();
  2112. let past = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
  2113. let ingredientList = document.getElementById("orderFilterIngredients");
  2114. document.getElementById("orderFilterDateFrom").valueAsDate = past;
  2115. document.getElementById("orderFilterDateTo").valueAsDate = now;
  2116. while(ingredientList.children.length > 0){
  2117. ingredientList.removeChild(ingredientList.firstChild);
  2118. }
  2119. for(let i = 0; i < merchant.ingredients.length; i++){
  2120. let element = document.createElement("div");
  2121. element.classList.add("choosable");
  2122. element.ingredient = merchant.ingredients[i].ingredient.id;
  2123. element.onclick = ()=>{this.toggleActive(element)};
  2124. ingredientList.appendChild(element);
  2125. let text = document.createElement("p");
  2126. text.innerText = merchant.ingredients[i].ingredient.name;
  2127. element.appendChild(text);
  2128. }
  2129. document.getElementById("orderFilterSubmit").onclick = ()=>{this.submit(Order)};
  2130. },
  2131. toggleActive: function(element){
  2132. if(element.classList.contains("active")){
  2133. element.classList.remove("active");
  2134. }else{
  2135. element.classList.add("active");
  2136. }
  2137. },
  2138. submit: function(Order){
  2139. let data = {
  2140. startDate: document.getElementById("orderFilterDateFrom").valueAsDate,
  2141. endDate: document.getElementById("orderFilterDateTo").valueAsDate,
  2142. ingredients: []
  2143. }
  2144. if(data.startDate >= data.endDate){
  2145. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2146. return;
  2147. }
  2148. let ingredients = document.getElementById("orderFilterIngredients").children;
  2149. for(let i = 0; i < ingredients.length; i++){
  2150. if(ingredients[i].classList.contains("active")){
  2151. data.ingredients.push(ingredients[i].ingredient);
  2152. }
  2153. }
  2154. if(data.ingredients.length === 0){
  2155. for(let i = 0; i < merchant.ingredients.length; i++){
  2156. data.ingredients.push(merchant.ingredients[i].ingredient.id);
  2157. }
  2158. }
  2159. let loader = document.getElementById("loaderContainer");
  2160. loader.style.display = "flex";
  2161. fetch("/order", {
  2162. method: "post",
  2163. headers: {
  2164. "Content-Type": "application/json;charset=utf-8"
  2165. },
  2166. body: JSON.stringify(data)
  2167. })
  2168. .then(response => response.json())
  2169. .then((response)=>{
  2170. let orders = [];
  2171. if(typeof(response) === "string"){
  2172. banner.createError(response);
  2173. }else if(response.length === 0){
  2174. banner.createError("NO ORDERS MATCH YOUR SEARCH");
  2175. }else{
  2176. for(let i = 0; i < response.length; i++){
  2177. orders.push(new Order(
  2178. response[i]._id,
  2179. response[i].name,
  2180. response[i].date,
  2181. response[i].taxes,
  2182. response[i].fees,
  2183. response[i].ingredients,
  2184. merchant
  2185. ));
  2186. }
  2187. }
  2188. controller.openStrand("orders", orders);
  2189. })
  2190. .catch((err)=>{
  2191. banner.createError("UNABLE TO DISPLAY THE ORDERS");
  2192. })
  2193. .finally(()=>{
  2194. loader.style.display = "none";
  2195. });
  2196. }
  2197. }
  2198. module.exports = orderFilter;
  2199. },{}],16:[function(require,module,exports){
  2200. let recipeDetails = {
  2201. display: function(recipe){
  2202. document.getElementById("editRecipeBtn").onclick = ()=>{controller.openSidebar("editRecipe", recipe)};
  2203. document.getElementById("recipeName").innerText = recipe.name;
  2204. if(merchant.pos === "none"){
  2205. document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove(recipe)};
  2206. }
  2207. //ingredient list
  2208. let ingredientsDiv = document.getElementById("recipeIngredientList");
  2209. while(ingredientsDiv.children.length > 0){
  2210. ingredientsDiv.removeChild(ingredientsDiv.firstChild);
  2211. }
  2212. let template = document.getElementById("recipeIngredient").content.children[0];
  2213. for(let i = 0; i < recipe.ingredients.length; i++){
  2214. let recipeDiv = template.cloneNode(true);
  2215. recipeDiv.children[0].innerText = recipe.ingredients[i].ingredient.name;
  2216. recipeDiv.children[1].innerText = `${recipe.ingredients[i].getQuantityDisplay()}`;
  2217. recipeDiv.onclick = ()=>{
  2218. controller.openStrand("ingredients");
  2219. controller.openSidebar("ingredientDetails", merchant.getIngredient(recipe.ingredients[i].ingredient.id));
  2220. }
  2221. ingredientsDiv.appendChild(recipeDiv);
  2222. }
  2223. document.getElementById("recipePrice").children[1].innerText = `$${recipe.price.toFixed(2)}`;
  2224. },
  2225. remove: function(recipe){
  2226. let loader = document.getElementById("loaderContainer");
  2227. loader.style.display = "flex";
  2228. fetch(`/recipe/remove/${recipe.id}`, {
  2229. method: "delete"
  2230. })
  2231. .then((response) => response.json())
  2232. .then((response)=>{
  2233. if(typeof(response) === "string"){
  2234. banner.createError(response);
  2235. }else{
  2236. merchant.removeRecipe(recipe);
  2237. banner.createNotification("RECIPE REMOVED");
  2238. controller.openStrand("recipeBook");
  2239. }
  2240. })
  2241. .catch((err)=>{
  2242. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2243. })
  2244. .finally(()=>{
  2245. loader.style.display = "none";
  2246. });
  2247. }
  2248. }
  2249. module.exports = recipeDetails;
  2250. },{}],17:[function(require,module,exports){
  2251. let transactionDetails = {
  2252. transaction: {},
  2253. display: function(transaction){
  2254. this.transaction = transaction;
  2255. let recipeList = document.getElementById("transactionRecipes");
  2256. let template = document.getElementById("transactionRecipe").content.children[0];
  2257. let totalRecipes = 0;
  2258. let totalPrice = 0;
  2259. while(recipeList.children.length > 0){
  2260. recipeList.removeChild(recipeList.firstChild);
  2261. }
  2262. for(let i = 0; i < transaction.recipes.length; i++){
  2263. let recipe = template.cloneNode(true);
  2264. let price = transaction.recipes[i].quantity * transaction.recipes[i].recipe.price;
  2265. recipe.children[0].innerText = transaction.recipes[i].recipe.name;
  2266. recipe.children[1].innerText = `${transaction.recipes[i].quantity} x $${transaction.recipes[i].recipe.price.toFixed(2)}`;
  2267. recipe.children[2].innerText = `$${price.toFixed(2)}`;
  2268. recipe.onclick = ()=>{
  2269. controller.openStrand("recipeBook");
  2270. controller.openSidebar("recipeDetails", transaction.recipes[i].recipe);
  2271. }
  2272. recipeList.appendChild(recipe);
  2273. totalRecipes += transaction.recipes[i].quantity;
  2274. totalPrice += price;
  2275. }
  2276. let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2277. let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  2278. let dateString = `${days[transaction.date.getDay()]}, ${months[transaction.date.getMonth()]} ${transaction.date.getDate()}, ${transaction.date.getFullYear()}`;
  2279. document.getElementById("transactionDate").innerText = dateString;
  2280. document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
  2281. document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
  2282. document.getElementById("totalPrice").innerText = `$${totalPrice.toFixed(2)}`;
  2283. if(merchant.pos === "none"){
  2284. document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
  2285. }
  2286. },
  2287. remove: function(){
  2288. let loader = document.getElementById("loaderContainer");
  2289. loader.style.display = "flex";
  2290. fetch(`/transaction/${this.transaction.id}`, {
  2291. method: "delete",
  2292. headers: {
  2293. "Content-Type": "application/json;charset=utf-8"
  2294. },
  2295. })
  2296. .then((response)=>{
  2297. if(typeof(response) === "string"){
  2298. banner.createError(response);
  2299. }else{
  2300. merchant.removeTransaction(this.transaction);
  2301. controller.openStrand("transactions", merchant.getTransactions());
  2302. banner.createNotification("TRANSACTION REMOVED");
  2303. }
  2304. })
  2305. .catch((err)=>{
  2306. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2307. })
  2308. .finally(()=>{
  2309. loader.style.display = "none";
  2310. });
  2311. },
  2312. }
  2313. module.exports = transactionDetails;
  2314. },{}],18:[function(require,module,exports){
  2315. let transactionFilter = {
  2316. display: function(){
  2317. //Set default dates
  2318. let today = new Date();
  2319. let monthAgo = new Date(today);
  2320. monthAgo.setMonth(today.getMonth() - 1);
  2321. document.getElementById("transFilterDateStart").valueAsDate = monthAgo;
  2322. document.getElementById("transFilterDateEnd").valueAsDate = today;
  2323. //populate recipes
  2324. let recipeList = document.getElementById("transFilterRecipeList");
  2325. while(recipeList.children.length > 0){
  2326. recipeList.removeChild(recipeList.firstChild);
  2327. }
  2328. for(let i = 0; i < merchant.recipes.length; i++){
  2329. let recipe = document.createElement("div");
  2330. recipe.innerText = merchant.recipes[i].name;
  2331. recipe.recipe = merchant.recipes[i];
  2332. recipe.classList.add("choosable");
  2333. recipe.onclick = ()=>{this.toggleActive(recipe)};
  2334. recipeList.appendChild(recipe);
  2335. }
  2336. //Submit button
  2337. document.getElementById("transFilterSubmit").onclick = ()=>{this.submit()};
  2338. },
  2339. toggleActive: function(element){
  2340. if(element.classList.contains("active")){
  2341. element.classList.remove("active");
  2342. }else{
  2343. element.classList.add("active");
  2344. }
  2345. },
  2346. submit: function(){
  2347. let data = {
  2348. startDate: document.getElementById("transFilterDateStart").valueAsDate,
  2349. endDate: document.getElementById("transFilterDateEnd").valueAsDate,
  2350. recipes: []
  2351. }
  2352. if(data.startDate >= data.endDate){
  2353. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2354. return;
  2355. }
  2356. let recipes = document.getElementById("transFilterRecipeList").children;
  2357. for(let i = 0; i < recipes.length; i++){
  2358. if(recipes[i].classList.contains("active")){
  2359. data.recipes.push(recipes[i].recipe.id);
  2360. }
  2361. }
  2362. if(data.recipes.length === 0){
  2363. for(let i = 0; i < merchant.recipes.length; i++){
  2364. data.recipes.push(merchant.recipes[i].id);
  2365. }
  2366. }
  2367. let loader = document.getElementById("loaderContainer");
  2368. loader.style.display = "flex";
  2369. fetch("/transaction", {
  2370. method: "post",
  2371. headers: {
  2372. "Content-Type": "application/json;charset=utf-8"
  2373. },
  2374. body: JSON.stringify(data)
  2375. })
  2376. .then(response => response.json())
  2377. .then((response)=>{
  2378. let transactions = [];
  2379. if(typeof(response) === "string"){
  2380. banner.createError(response);
  2381. }else if(response.length === 0){
  2382. banner.createError("NO TRANSACTIONS MATCH YOUR SEARCH");
  2383. }else{
  2384. for(let i = 0; i < response.length; i++){
  2385. transactions.push(new Transaction(
  2386. response[i]._id,
  2387. response[i].date,
  2388. response[i].recipes,
  2389. merchant
  2390. ));
  2391. }
  2392. }
  2393. controller.openStrand("transactions", transactions);
  2394. })
  2395. .catch((err)=>{
  2396. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2397. })
  2398. .finally(()=>{
  2399. loader.style.display = "none";
  2400. });
  2401. }
  2402. }
  2403. module.exports = transactionFilter;
  2404. },{}],19:[function(require,module,exports){
  2405. let analytics = {
  2406. newData: false,
  2407. dateChange: false,
  2408. transactions: [],
  2409. ingredient: {},
  2410. recipe: {},
  2411. display: function(Transaction){
  2412. document.getElementById("analDateBtn").onclick = ()=>{this.changeDates(Transaction)};
  2413. if(this.transactions.length === 0 || this.newData === true){
  2414. let startDate = new Date();
  2415. startDate.setMonth(startDate.getMonth() - 1);
  2416. this.transactions = merchant.getTransactions(startDate);
  2417. }
  2418. let slider = document.getElementById("analSlider");
  2419. slider.onchange = ()=>{this.display(Transaction)};
  2420. let ingredientContent = document.getElementById("analIngredientContent");
  2421. let recipeContent = document.getElementById("analRecipeContent");
  2422. if(slider.checked){
  2423. ingredientContent.style.display = "none";
  2424. recipeContent.style.display = "flex";
  2425. this.displayRecipes();
  2426. }else{
  2427. ingredientContent.style.display = "flex";
  2428. recipeContent.style.display = "none"
  2429. this.displayIngredients();
  2430. }
  2431. },
  2432. displayIngredients: function(){
  2433. const itemsList = document.getElementById("itemsList");
  2434. while(itemsList.children.length > 0){
  2435. itemsList.removeChild(itemsList.firstChild);
  2436. }
  2437. for(let i = 0; i < merchant.ingredients.length; i++){
  2438. let li = document.createElement("li");
  2439. li.classList.add("choosable");
  2440. li.item = merchant.ingredients[i];
  2441. li.innerText = merchant.ingredients[i].ingredient.name;
  2442. li.onclick = ()=>{
  2443. const itemsList = document.getElementById("itemsList");
  2444. for(let i = 0; i < itemsList.children.length; i++){
  2445. itemsList.children[i].classList.remove("active");
  2446. }
  2447. li.classList.add("active");
  2448. this.ingredient = merchant.ingredients[i];
  2449. this.ingredientDisplay();
  2450. };
  2451. itemsList.appendChild(li);
  2452. }
  2453. if(this.dateChange && Object.keys(this.ingredient).length !== 0){
  2454. this.ingredientDisplay();
  2455. }
  2456. this.dateChange = false;
  2457. },
  2458. displayRecipes: function(){
  2459. let recipeList = document.getElementById("analRecipeList");
  2460. while(recipeList.children.length > 0){
  2461. recipeList.removeChild(recipeList.firstChild);
  2462. }
  2463. for(let i = 0; i < merchant.recipes.length; i++){
  2464. let li = document.createElement("li");
  2465. li.classList.add("choosable");
  2466. li.recipe = merchant.recipes[i];
  2467. li.innerText = merchant.recipes[i].name;
  2468. li.onclick = ()=>{
  2469. let recipeList = document.getElementById("analRecipeList");
  2470. for(let i = 0; i < recipeList.children.length; i++){
  2471. recipeList.children[i].classList.remove("active");
  2472. }
  2473. li.classList.add("active");
  2474. this.recipe = merchant.recipes[i];
  2475. this.recipeDisplay();
  2476. }
  2477. recipeList.appendChild(li);
  2478. }
  2479. if(this.dateChange && Object.keys(this.recipe).length !== 0){
  2480. this.recipeDisplay();
  2481. }
  2482. this.dateChange = false;
  2483. },
  2484. ingredientDisplay: function(){
  2485. //Get list of recipes that contain the ingredient
  2486. let containingRecipes = [];
  2487. for(let i = 0; i < merchant.recipes.length; i++){
  2488. for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
  2489. if(merchant.recipes[i].ingredients[j].ingredient === this.ingredient.ingredient){
  2490. containingRecipes.push({
  2491. recipe: merchant.recipes[i],
  2492. quantity: merchant.recipes[i].ingredients[j].quantity
  2493. });
  2494. break;
  2495. }
  2496. }
  2497. }
  2498. //Create Graph
  2499. let quantities = [];
  2500. let dates = [];
  2501. let currentDate = (this.transactions.length > 0) ? this.transactions[0].date : undefined;
  2502. let currentQuantity = 0;
  2503. for(let i = 0; i < this.transactions.length; i++){
  2504. if(currentDate.getDate() !== this.transactions[i].date.getDate()){
  2505. quantities.push(currentQuantity);
  2506. dates.push(currentDate);
  2507. currentQuantity = 0;
  2508. currentDate = this.transactions[i].date;
  2509. }
  2510. for(let j = 0; j < this.transactions[i].recipes.length; j++){
  2511. for(let k = 0; k < containingRecipes.length; k++){
  2512. if(this.transactions[i].recipes[j].recipe === containingRecipes[k].recipe){
  2513. for(let l = 0; l < this.transactions[i].recipes[j].recipe.ingredients.length; l++){
  2514. const transIngredient = this.transactions[i].recipes[j].recipe.ingredients[l];
  2515. if(transIngredient.ingredient === this.ingredient.ingredient){
  2516. currentQuantity += transIngredient.quantity * this.transactions[i].recipes[j].quantity;
  2517. break;
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. if(i === this.transactions.length - 1){
  2524. quantities.push(currentQuantity);
  2525. dates.push(currentDate);
  2526. }
  2527. }
  2528. let trace = {
  2529. x: dates,
  2530. y: quantities,
  2531. mode: "lines+markers",
  2532. line: {
  2533. color: "rgb(255, 99, 107)"
  2534. }
  2535. }
  2536. const layout = {
  2537. title: this.ingredient.ingredient.name.toUpperCase(),
  2538. xaxis: {
  2539. title: "DATE"
  2540. },
  2541. yaxis: {
  2542. title: `QUANTITY (${this.ingredient.ingredient.unit.toUpperCase()})`,
  2543. }
  2544. }
  2545. Plotly.newPlot("itemUseGraph", [trace], layout);
  2546. //Create use cards
  2547. let sum = 0;
  2548. let max = 0;
  2549. let min = (quantities.length > 0) ? quantities[0] : 0;
  2550. for(let i = 0; i < quantities.length; i++){
  2551. sum += quantities[i];
  2552. if(quantities[i] > max){
  2553. max = quantities[i];
  2554. }else if(quantities[i] < min){
  2555. min = quantities[i];
  2556. }
  2557. }
  2558. document.getElementById("analMinUse").innerText = `${min.toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2559. document.getElementById("analAvgUse").innerText = `${(sum / quantities.length).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2560. document.getElementById("analMaxUse").innerText = `${max.toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2561. let dayUse = [0, 0, 0, 0, 0, 0, 0];
  2562. let dayCount = [0, 0, 0, 0, 0, 0, 0];
  2563. for(let i = 0; i < quantities.length; i++){
  2564. dayUse[dates[i].getDay()] += quantities[i];
  2565. dayCount[dates[i].getDay()]++;
  2566. }
  2567. document.getElementById("analDayOne").innerText = `${(dayUse[0] / dayCount[0]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2568. document.getElementById("analDayTwo").innerText = `${(dayUse[1] / dayCount[1]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2569. document.getElementById("analDayThree").innerText = `${(dayUse[2] / dayCount[2]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2570. document.getElementById("analDayFour").innerText = `${(dayUse[3] / dayCount[3]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2571. document.getElementById("analDayFive").innerText = `${(dayUse[4] / dayCount[4]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2572. document.getElementById("analDaySix").innerText = `${(dayUse[5] / dayCount[5]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2573. document.getElementById("analDaySeven").innerText = `${(dayUse[6] / dayCount[6]).toFixed(2)} ${this.ingredient.ingredient.unit}`;
  2574. },
  2575. recipeDisplay: function(){
  2576. let quantities = [];
  2577. let dates = [];
  2578. let currentDate;
  2579. let quantity = 0;
  2580. if(this.transactions.length > 0){
  2581. currentDate = this.transactions[0].date;
  2582. }
  2583. for(let i = 0; i < this.transactions.length; i++){
  2584. if(currentDate.getDate() !== this.transactions[i].date.getDate()){
  2585. quantities.push(quantity);
  2586. quantity = 0;
  2587. dates.push(currentDate);
  2588. currentDate = this.transactions[i].date;
  2589. }
  2590. for(let j = 0; j < this.transactions[i].recipes.length; j++){
  2591. const recipe = this.transactions[i].recipes[j];
  2592. if(recipe.recipe === this.recipe){
  2593. quantity += recipe.quantity;
  2594. }
  2595. }
  2596. if(i === this.transactions.length - 1){
  2597. quantities.push(quantity);
  2598. dates.push(currentDate);
  2599. }
  2600. }
  2601. const trace = {
  2602. x: dates,
  2603. y: quantities,
  2604. mode: "lines+markers",
  2605. line: {
  2606. color: "rgb(255, 99, 107"
  2607. }
  2608. }
  2609. const layout = {
  2610. title: this.recipe.name.toUpperCase(),
  2611. xaxis: {
  2612. title: "DATE"
  2613. },
  2614. yaxis: {
  2615. title: "Quantity"
  2616. }
  2617. }
  2618. Plotly.newPlot("recipeSalesGraph", [trace], layout);
  2619. let sum = 0;
  2620. for(let i = 0; i < quantities.length; i++){
  2621. sum += quantities[i];
  2622. }
  2623. document.getElementById("recipeAvgUse").innerText = (sum / quantities.length).toFixed(2);
  2624. document.getElementById("recipeAvgRevenue").innerText = `$${(((sum / quantities.length) * this.recipe.price) / 100).toFixed(2)}`;
  2625. },
  2626. changeDates: function(Transaction){
  2627. let dates = {
  2628. from: document.getElementById("analStartDate").valueAsDate,
  2629. to: document.getElementById("analEndDate").valueAsDate
  2630. }
  2631. if(dates.from > dates.to || dates.from === "" || dates.to === "" || dates.to > new Date()){
  2632. banner.createError("INVALID DATE");
  2633. return;
  2634. }
  2635. let loader = document.getElementById("loaderContainer");
  2636. loader.style.display = "flex";
  2637. fetch("/transaction/retrieve", {
  2638. method: "post",
  2639. headers: {
  2640. "Content-Type": "application/json;charset=utf-8"
  2641. },
  2642. body: JSON.stringify(dates)
  2643. })
  2644. .then(response => response.json())
  2645. .then((response)=>{
  2646. if(typeof(response) === "string"){
  2647. banner.createError(response.data);
  2648. }else{
  2649. this.transactions = [];
  2650. for(let i = 0; i < response.length; i++){
  2651. this.transactions.push(new Transaction(
  2652. response[i]._id,
  2653. new Date(response[i].date),
  2654. response[i].recipes,
  2655. merchant
  2656. ));
  2657. }
  2658. let isRecipe = document.getElementById("analSlider").checked;
  2659. if(isRecipe && Object.keys(this.recipe).length !== 0){
  2660. this.recipeDisplay();
  2661. }else if(!isRecipe && Object.keys(this.ingredient).length !== 0){
  2662. this.ingredientDisplay();
  2663. }
  2664. this.dateChange = true;
  2665. }
  2666. })
  2667. .catch((err)=>{
  2668. banner.createError("ERROR: UNABLE TO DISPLAY THE DATA");
  2669. })
  2670. .finally(()=>{
  2671. loader.style.display = "none";
  2672. });
  2673. }
  2674. }
  2675. module.exports = analytics;
  2676. },{}],20:[function(require,module,exports){
  2677. let home = {
  2678. isPopulated: false,
  2679. display: function(){
  2680. if(!this.isPopulated){
  2681. this.drawRevenueCard();
  2682. this.drawRevenueGraph();
  2683. this.drawInventoryCheckCard();
  2684. this.drawPopularCard();
  2685. this.isPopulated = true;
  2686. }
  2687. },
  2688. drawRevenueCard: function(){
  2689. let today = new Date();
  2690. let firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
  2691. let firstOfLastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
  2692. let lastMonthToDay = new Date(new Date().setMonth(today.getMonth() - 1));
  2693. const revenueThisMonth = merchant.getRevenue(firstOfMonth);
  2694. const revenueLastMonthToDay = merchant.getRevenue(firstOfLastMonth, lastMonthToDay);
  2695. document.getElementById("revenue").innerText = `$${revenueThisMonth.toFixed(2)}`;
  2696. let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
  2697. let img = "";
  2698. if(revenueChange >= 0){
  2699. img = "/shared/images/upArrow.png";
  2700. }else{
  2701. img = "/shared/images/downArrow.png";
  2702. }
  2703. document.querySelector("#revenueChange p").innerText = `${Math.abs(revenueChange).toFixed(2)}% vs last month`;
  2704. document.querySelector("#revenueChange img").src = img;
  2705. },
  2706. drawRevenueGraph: function(){
  2707. let monthAgo = new Date();
  2708. monthAgo.setMonth(monthAgo.getMonth() - 1);
  2709. let revenue = [];
  2710. let dates = [];
  2711. let dayRevenue = 0;
  2712. const transactions = merchant.getTransactions(monthAgo);
  2713. let currentDate = (transactions.length > 0) ? transactions[0].date : undefined;
  2714. for(let i = 0; i < transactions.length; i++){
  2715. if(transactions[i].date.getDate() !== currentDate.getDate()){
  2716. revenue.push(dayRevenue / 100);
  2717. dayRevenue = 0;
  2718. dates.push(currentDate);
  2719. currentDate = transactions[i].date;
  2720. }
  2721. for(let j = 0; j < transactions[i].recipes.length; j++){
  2722. const recipe = transactions[i].recipes[j];
  2723. dayRevenue += recipe.recipe.price * recipe.quantity;
  2724. }
  2725. }
  2726. const trace = {
  2727. x: dates,
  2728. y: revenue,
  2729. mode: "lines+markers",
  2730. line: {
  2731. color: "rgb(255, 99, 107)"
  2732. }
  2733. }
  2734. const layout = {
  2735. title: "REVENUE",
  2736. xaxis: {
  2737. title: "DATE"
  2738. },
  2739. yaxis: {
  2740. title: "$"
  2741. }
  2742. }
  2743. Plotly.newPlot("graphCard", [trace], layout);
  2744. },
  2745. drawInventoryCheckCard: function(){
  2746. let num;
  2747. if(merchant.ingredients.length < 5){
  2748. num = merchant.ingredients.length;
  2749. }else{
  2750. num = 5;
  2751. }
  2752. let rands = [];
  2753. for(let i = 0; i < num; i++){
  2754. let rand = Math.floor(Math.random() * merchant.ingredients.length);
  2755. if(rands.includes(rand)){
  2756. i--;
  2757. }else{
  2758. rands[i] = rand;
  2759. }
  2760. }
  2761. let ul = document.querySelector("#inventoryCheckCard ul");
  2762. let template = document.getElementById("ingredientCheck").content.children[0];
  2763. while(ul.children.length > 0){
  2764. ul.removeChild(ul.firstChild);
  2765. }
  2766. for(let i = 0; i < rands.length; i++){
  2767. let ingredientCheck = template.cloneNode(true);
  2768. let input = ingredientCheck.children[1].children[1];
  2769. const ingredient = merchant.ingredients[rands[i]];
  2770. ingredientCheck.ingredient = ingredient;
  2771. ingredientCheck.children[0].innerText = ingredient.ingredient.name;
  2772. ingredientCheck.children[1].children[0].onclick = ()=>{
  2773. input.value--;
  2774. input.changed = true;
  2775. };
  2776. if(ingredient.ingredient.specialUnit === "bottle"){
  2777. input.value = ingredient.quantity.toFixed(2);
  2778. ingredientCheck.children[2].innerText = "BOTTLES";
  2779. }else{
  2780. input.value = ingredient.quantity.toFixed(2);
  2781. ingredientCheck.children[2].innerText = ingredient.ingredient.unit.toUpperCase();
  2782. }
  2783. ingredientCheck.children[1].children[2].onclick = ()=>{
  2784. input.value++;
  2785. input.changed = true;
  2786. }
  2787. input.onchange = ()=>{input.changed = true};
  2788. ul.appendChild(ingredientCheck);
  2789. }
  2790. document.getElementById("inventoryCheck").onclick = ()=>{this.submitInventoryCheck()};
  2791. },
  2792. drawPopularCard: function(){
  2793. let thisMonth = new Date();
  2794. thisMonth.setDate(1);
  2795. const ingredientList = merchant.getIngredientsSold(thisMonth);
  2796. if(ingredientList !== false){
  2797. ingredientList.sort((a, b)=>{
  2798. if(a.quantity < b.quantity){
  2799. return 1;
  2800. }
  2801. if(a.quantity > b.quantity){
  2802. return -1;
  2803. }
  2804. return 0;
  2805. });
  2806. let quantities = [];
  2807. let labels = [];
  2808. let colors = [];
  2809. let count = (ingredientList.length < 5) ? ingredientList.length - 1 : 4;
  2810. for(let i = count; i >= 0; i--){
  2811. const ingredientName = ingredientList[i].ingredient.name;
  2812. const ingredientQuantity = ingredientList[i].quantity;
  2813. const unitName = ingredientList[i].ingredient.unit;
  2814. quantities.push(ingredientList[i].quantity);
  2815. labels.push(`${ingredientName}: ${ingredientQuantity.toFixed(2)} ${unitName.toUpperCase()}`);
  2816. if(i === 0){
  2817. colors.push("rgb(255, 99, 107");
  2818. }else{
  2819. colors.push("rgb(179, 191, 209");
  2820. }
  2821. }
  2822. let trace = {
  2823. x: quantities,
  2824. type: "bar",
  2825. orientation: "h",
  2826. text: labels,
  2827. textposition: "auto",
  2828. hoverinfo: "none",
  2829. marker: {
  2830. color: colors
  2831. }
  2832. }
  2833. let layout = {
  2834. title: "MOST POPULAR INGREDIENTS",
  2835. xaxis: {
  2836. zeroline: false,
  2837. title: "QUANTITY"
  2838. },
  2839. yaxis: {
  2840. showticklabels: false
  2841. }
  2842. }
  2843. Plotly.newPlot("popularIngredientsCard", [trace], layout);
  2844. }else{
  2845. document.getElementById("popularCanvas").style.display = "none";
  2846. let notice = document.createElement("p");
  2847. notice.innerText = "N/A";
  2848. notice.classList = "notice";
  2849. document.getElementById("popularIngredientsCard").appendChild(notice);
  2850. }
  2851. },
  2852. //Need to change the updating of ingredients
  2853. //should update the ingredient directly, then send that. Maybe...
  2854. submitInventoryCheck: function(){
  2855. let lis = document.querySelectorAll("#inventoryCheckCard li");
  2856. let changes = [];
  2857. let fetchData = [];
  2858. for(let i = 0; i < lis.length; i++){
  2859. if(lis[i].children[1].children[1].value >= 0){
  2860. let merchIngredient = lis[i].ingredient;
  2861. if(lis[i].children[1].children[1].changed === true){
  2862. let value = 0;
  2863. if(merchIngredient.ingredient.specialUnit === "bottle"){
  2864. value = parseFloat(lis[i].children[1].children[1].value) * merchIngredient.ingredient.unitSize;
  2865. }else{
  2866. value = controller.convertToMain(merchIngredient.ingredient.unit, parseFloat(lis[i].children[1].children[1].value));
  2867. }
  2868. changes.push({
  2869. ingredient: merchIngredient.ingredient,
  2870. quantity: value
  2871. });
  2872. fetchData.push({
  2873. id: merchIngredient.ingredient.id,
  2874. quantity: value
  2875. });
  2876. lis[i].children[1].children[1].changed = false;
  2877. }
  2878. }else{
  2879. banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");
  2880. return;
  2881. }
  2882. }
  2883. if(fetchData.length > 0){
  2884. let loader = document.getElementById("loaderContainer");
  2885. loader.style.display = "flex";
  2886. fetch("/merchant/ingredients/update", {
  2887. method: "PUT",
  2888. headers: {
  2889. "Content-Type": "application/json;charset=utf-8"
  2890. },
  2891. body: JSON.stringify(fetchData)
  2892. })
  2893. .then(response => response.json())
  2894. .then((response)=>{
  2895. if(typeof(response) === "string"){
  2896. banner.createError(response);
  2897. }else{
  2898. for(let i = 0; i < changes.length; i++){
  2899. merchant.updateIngredient(changes[i].ingredient, changes[i].quantity);
  2900. }
  2901. banner.createNotification("INGREDIENTS UPDATED");
  2902. }
  2903. })
  2904. .catch((err)=>{})
  2905. .finally(()=>{
  2906. loader.style.display = "none";
  2907. });
  2908. }
  2909. }
  2910. }
  2911. module.exports = home;
  2912. },{}],21:[function(require,module,exports){
  2913. let ingredients = {
  2914. isPopulated: false,
  2915. ingredients: [],
  2916. display: function(){
  2917. if(!this.isPopulated){
  2918. document.getElementById("ingredientSearch").oninput = ()=>{this.search()};
  2919. this.populateByProperty();
  2920. this.isPopulated = true;
  2921. }
  2922. },
  2923. populateByProperty: function(){
  2924. let categories;
  2925. categories = merchant.categorizeIngredients();
  2926. let ingredientStrand = document.getElementById("categoryList");
  2927. let categoryTemplate = document.getElementById("categoryDiv").content.children[0];
  2928. let ingredientTemplate = document.getElementById("ingredient").content.children[0];
  2929. this.ingredients = [];
  2930. while(ingredientStrand.children.length > 0){
  2931. ingredientStrand.removeChild(ingredientStrand.firstChild);
  2932. }
  2933. for(let i = 0; i < categories.length; i++){
  2934. let categoryDiv = categoryTemplate.cloneNode(true);
  2935. categoryDiv.children[0].children[0].innerText = categories[i].name.toUpperCase();
  2936. categoryDiv.children[0].onclick = ()=>{
  2937. this.toggleCategory(categoryDiv.children[1], categoryDiv.children[0].children[1]);
  2938. };
  2939. categoryDiv.children[1].style.display = "none";
  2940. ingredientStrand.appendChild(categoryDiv);
  2941. for(let j = 0; j < categories[i].ingredients.length; j++){
  2942. let ingredient = categories[i].ingredients[j];
  2943. let ingredientDiv = ingredientTemplate.cloneNode(true);
  2944. ingredientDiv.children[0].innerText = ingredient.ingredient.name;
  2945. ingredientDiv.onclick = ()=>{
  2946. controller.openSidebar("ingredientDetails", ingredient);
  2947. ingredientDiv.classList.add("active");
  2948. };
  2949. ingredientDiv._name = ingredient.ingredient.name.toLowerCase();
  2950. ingredientDiv._unit = ingredient.ingredient.unit.toLowerCase();
  2951. if(ingredient.ingredient.specialUnit === "bottle"){
  2952. ingredientDiv.children[2].innerText = `${ingredient.quantity.toFixed(2)} BOTTLES`
  2953. }else{
  2954. ingredientDiv.children[2].innerText = `${ingredient.quantity.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  2955. }
  2956. categoryDiv.children[1].appendChild(ingredientDiv);
  2957. this.ingredients.push(ingredientDiv);
  2958. }
  2959. }
  2960. },
  2961. displayIngredientsOnly: function(ingredients){
  2962. let ingredientDiv = document.getElementById("categoryList");
  2963. while(ingredientDiv.children.length > 0){
  2964. ingredientDiv.removeChild(ingredientDiv.firstChild);
  2965. }
  2966. for(let i = 0; i < ingredients.length; i++){
  2967. ingredientDiv.appendChild(ingredients[i]);
  2968. }
  2969. },
  2970. toggleCategory: function(div, button){
  2971. if(div.style.display === "none"){
  2972. button.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>';
  2973. div.style.display = "flex";
  2974. }else if(div.style.display === "flex"){
  2975. button.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>';
  2976. div.style.display = "none";
  2977. }
  2978. },
  2979. search: function(){
  2980. let input = document.getElementById("ingredientSearch").value.toLowerCase();
  2981. if(input === ""){
  2982. this.populateByProperty();
  2983. return;
  2984. }
  2985. let matchingIngredients = [];
  2986. for(let i = 0; i < this.ingredients.length; i++){
  2987. if(this.ingredients[i]._name.includes(input)){
  2988. matchingIngredients.push(this.ingredients[i]);
  2989. }
  2990. }
  2991. this.displayIngredientsOnly(matchingIngredients);
  2992. }
  2993. }
  2994. module.exports = ingredients;
  2995. },{}],22:[function(require,module,exports){
  2996. let orders = {
  2997. orders: [],
  2998. display: function(){
  2999. document.getElementById("orderFilterBtn").onclick = ()=>{controller.openSidebar("orderFilter")};
  3000. document.getElementById("newOrderBtn").onclick = ()=>{controller.openSidebar("newOrder")};
  3001. let orderList = document.getElementById("orderList");
  3002. let template = document.getElementById("order").content.children[0];
  3003. while(orderList.children.length > 0){
  3004. orderList.removeChild(orderList.firstChild);
  3005. }
  3006. for(let i = 0; i < this.orders.length; i++){
  3007. let orderDiv = template.cloneNode(true);
  3008. orderDiv.order = this.orders[i];
  3009. orderDiv.children[0].innerText = this.orders[i].name;
  3010. orderDiv.children[1].innerText = `${this.orders[i].ingredients.length} ingredients`;
  3011. orderDiv.children[2].innerText = this.orders[i].date.toLocaleDateString("en-US");
  3012. orderDiv.children[3].innerText = `$${this.orders[i].getTotalCost().toFixed(2)}`;
  3013. orderDiv.onclick = ()=>{
  3014. controller.openSidebar("orderDetails", this.orders[i]);
  3015. orderDiv.classList.add("active");
  3016. }
  3017. orderList.appendChild(orderDiv);
  3018. }
  3019. },
  3020. getOrders: function(Order){
  3021. let loader = document.getElementById("loaderContainer");
  3022. loader.style.display = "flex";
  3023. return fetch("/order", {
  3024. method: "get",
  3025. headers: {
  3026. "Content-Type": "application/json;charset=utf-8"
  3027. }
  3028. })
  3029. .then(response => response.json())
  3030. .then((response)=>{
  3031. if(typeof(response) === "string"){
  3032. banner.createError(response);
  3033. }else{
  3034. let orders = [];
  3035. for(let i = 0; i < response.length; i++){
  3036. orders.push(new Order(
  3037. response[i]._id,
  3038. response[i].name,
  3039. response[i].date,
  3040. response[i].taxes,
  3041. response[i].fees,
  3042. response[i].ingredients,
  3043. merchant
  3044. ));
  3045. }
  3046. if(merchant.orders.length === 0){
  3047. merchant.setOrders(orders);
  3048. }
  3049. return orders;
  3050. }
  3051. })
  3052. .catch((err)=>{
  3053. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  3054. })
  3055. .finally(()=>{
  3056. loader.style.display = "none";
  3057. });
  3058. }
  3059. }
  3060. module.exports = orders;
  3061. },{}],23:[function(require,module,exports){
  3062. let recipeBook = {
  3063. isPopulated: false,
  3064. recipeDivList: [],
  3065. display: function(Recipe){
  3066. if(!this.isPopulated){
  3067. this.populateRecipes();
  3068. if(merchant.pos !== "none"){
  3069. document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate(Recipe)};
  3070. }
  3071. document.getElementById("recipeSearch").oninput = ()=>{this.search()};
  3072. this.populateRecipes();
  3073. this.isPopulated = true;
  3074. }
  3075. },
  3076. populateRecipes: function(){
  3077. let recipeList = document.getElementById("recipeList");
  3078. let template = document.getElementById("recipe").content.children[0];
  3079. this.recipeDivList = [];
  3080. while(recipeList.children.length > 0){
  3081. recipeList.removeChild(recipeList.firstChild);
  3082. }
  3083. for(let i = 0; i < merchant.recipes.length; i++){
  3084. let recipeDiv = template.cloneNode(true);
  3085. recipeDiv.onclick = ()=>{
  3086. controller.openSidebar("recipeDetails", merchant.recipes[i]);
  3087. recipeDiv.classList.add("active");
  3088. }
  3089. recipeDiv._name = merchant.recipes[i].name;
  3090. recipeList.appendChild(recipeDiv);
  3091. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  3092. recipeDiv.children[1].innerText = `$${merchant.recipes[i].price.toFixed(2)}`;
  3093. this.recipeDivList.push(recipeDiv);
  3094. }
  3095. },
  3096. search: function(){
  3097. let input = document.getElementById("recipeSearch").value.toLowerCase();
  3098. let recipeList = document.getElementById("recipeList");
  3099. let matchingRecipes = [];
  3100. for(let i = 0; i < this.recipeDivList.length; i++){
  3101. if(this.recipeDivList[i]._name.toLowerCase().includes(input)){
  3102. matchingRecipes.push(this.recipeDivList[i]);
  3103. }
  3104. }
  3105. while(recipeList.children.length > 0){
  3106. recipeList.removeChild(recipeList.firstChild);
  3107. }
  3108. for(let i = 0; i < matchingRecipes.length; i++){
  3109. recipeList.appendChild(matchingRecipes[i]);
  3110. }
  3111. },
  3112. posUpdate: function(Recipe){
  3113. let loader = document.getElementById("loaderContainer");
  3114. loader.style.display = "flex";
  3115. let url = `/recipe/update/${merchant.pos}`;
  3116. fetch(url, {
  3117. method: "GET",
  3118. headers: {
  3119. "Content-Type": "application/json;charset=utf-8"
  3120. },
  3121. })
  3122. .then(response => response.json())
  3123. .then((response)=>{
  3124. if(typeof(response) === "string"){
  3125. banner.createError(response);
  3126. }else{
  3127. for(let i = 0; i < response.new.length; i++){
  3128. const recipe = new Recipe(
  3129. response.new[i]._id,
  3130. response.new[i].name,
  3131. response.new[i].price,
  3132. merchant,
  3133. []
  3134. );
  3135. merchant.addRecipe(recipe);
  3136. }
  3137. for(let i = 0; i < response.removed.length; i++){
  3138. for(let j = 0; j < merchant.recipes.length; j++){
  3139. if(merchant.recipes[j].id === response.removed[i]._id){
  3140. merchant.removeRecipe(merchant.recipes[j]);
  3141. break;
  3142. }
  3143. }
  3144. }
  3145. this.display();
  3146. }
  3147. })
  3148. .catch((err)=>{
  3149. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  3150. })
  3151. .finally(()=>{
  3152. loader.style.display = "none";
  3153. });
  3154. }
  3155. }
  3156. module.exports = recipeBook;
  3157. },{}],24:[function(require,module,exports){
  3158. let transactions = {
  3159. transactions: [],
  3160. display: function(Transaction){
  3161. document.getElementById("filterTransactionsButton").onclick = ()=>{controller.openSidebar("transactionFilter")};
  3162. document.getElementById("newTransactionButton").onclick = ()=>{controller.openSidebar("newTransaction")};
  3163. this.populateTransactions(this.transactions);
  3164. this.isPopulated = true;
  3165. },
  3166. populateTransactions: function(transactions){
  3167. let transactionsList = document.getElementById("transactionsList");
  3168. let template = document.getElementById("transaction").content.children[0];
  3169. while(transactionsList.children.length > 0){
  3170. transactionsList.removeChild(transactionsList.firstChild);
  3171. }
  3172. let i = 0;
  3173. while(i < transactions.length && i < 100){
  3174. let transactionDiv = template.cloneNode(true);
  3175. let transaction = transactions[i];
  3176. transactionDiv.onclick = ()=>{
  3177. controller.openSidebar("transactionDetails", transaction);
  3178. transactionDiv.classList.add("active");
  3179. }
  3180. transactionsList.appendChild(transactionDiv);
  3181. let totalRecipes = 0;
  3182. let totalPrice = 0;
  3183. for(let j = 0; j < transactions[i].recipes.length; j++){
  3184. totalRecipes += transactions[i].recipes[j].quantity;
  3185. totalPrice += transactions[i].recipes[j].recipe.price * transactions[i].recipes[j].quantity;
  3186. }
  3187. transactionDiv.children[0].innerText = `${transactions[i].date.toLocaleDateString()} ${transactions[i].date.toLocaleTimeString()}`;
  3188. transactionDiv.children[1].innerText = `${totalRecipes} recipes sold`;
  3189. transactionDiv.children[2].innerText = `$${totalPrice.toFixed(2)}`;
  3190. i++;
  3191. }
  3192. }
  3193. }
  3194. module.exports = transactions;
  3195. },{}]},{},[6]);
  3196. >>>>>>> development