bundle.js 140 KB

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