bundle.js 138 KB

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