bundle.js 140 KB

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