bundle.js 115 KB

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