bundle.js 116 KB

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