bundle.js 142 KB

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