bundle.js 132 KB

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