bundle.js 115 KB

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