bundle.js 112 KB

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