bundle.js 115 KB

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