bundle.js 115 KB

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