bundle.js 131 KB

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