bundle.js 139 KB

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