bundle.js 138 KB

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