bundle.js 131 KB

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