bundle.js 141 KB

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