bundle.js 140 KB

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