bundle.js 129 KB

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