bundle.js 128 KB

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