bundle.js 116 KB

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