bundle.js 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125
  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 = ()=>{
  1319. this.toggleCategory(categoryDiv.children[1], categoryDiv.children[0].children[1]);
  1320. };
  1321. categoryDiv.children[1].style.display = "none";
  1322. ingredientStrand.appendChild(categoryDiv);
  1323. for(let j = 0; j < categories[i].ingredients.length; j++){
  1324. let ingredient = categories[i].ingredients[j];
  1325. let ingredientDiv = ingredientTemplate.cloneNode(true);
  1326. ingredientDiv.children[0].innerText = ingredient.ingredient.name;
  1327. ingredientDiv.children[2].innerText = `${ingredient.ingredient.convert(ingredient.quantity).toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1328. ingredientDiv.onclick = ()=>{controller.openSidebar("ingredientDetails", ingredient)};
  1329. ingredientDiv._name = ingredient.ingredient.name.toLowerCase();
  1330. ingredientDiv._unit = ingredient.ingredient.unit.toLowerCase();
  1331. categoryDiv.children[1].appendChild(ingredientDiv);
  1332. this.ingredients.push(ingredientDiv);
  1333. }
  1334. }
  1335. },
  1336. displayIngredientsOnly: function(ingredients){
  1337. let ingredientDiv = document.getElementById("categoryList");
  1338. while(ingredientDiv.children.length > 0){
  1339. ingredientDiv.removeChild(ingredientDiv.firstChild);
  1340. }
  1341. for(let i = 0; i < ingredients.length; i++){
  1342. ingredientDiv.appendChild(ingredients[i]);
  1343. }
  1344. },
  1345. toggleCategory: function(div, button){
  1346. if(div.style.display === "none"){
  1347. 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>';
  1348. div.style.display = "flex";
  1349. }else if(div.style.display === "flex"){
  1350. 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>';
  1351. div.style.display = "none";
  1352. }
  1353. },
  1354. search: function(){
  1355. let input = document.getElementById("ingredientSearch").value.toLowerCase();
  1356. document.getElementById("ingredientSelect").selectedIndex = 0;
  1357. if(input === ""){
  1358. this.populateByProperty("category");
  1359. document.getElementById("ingredientClearButton").style.display = "none";
  1360. return;
  1361. }
  1362. let matchingIngredients = [];
  1363. for(let i = 0; i < this.ingredients.length; i++){
  1364. if(this.ingredients[i]._name.includes(input)){
  1365. matchingIngredients.push(this.ingredients[i]);
  1366. }
  1367. }
  1368. document.getElementById("ingredientClearButton").style.display = "inline";
  1369. this.displayIngredientsOnly(matchingIngredients);
  1370. },
  1371. sort: function(){
  1372. let sortType = document.getElementById("ingredientSelect").value;
  1373. if(sortType === ""){
  1374. return;
  1375. }
  1376. document.getElementById("ingredientSearch").value = "";
  1377. if(sortType === "category"){
  1378. this.populateByProperty("category");
  1379. return;
  1380. }
  1381. if(sortType === "unit"){
  1382. this.populateByProperty("unit");
  1383. return;
  1384. }
  1385. document.getElementById("ingredientClearButton").style.display = "inline";
  1386. let sortedIngredients = this.ingredients.slice().sort((a, b)=> (a[sortType] > b[sortType]) ? 1 : -1);
  1387. this.displayIngredientsOnly(sortedIngredients);
  1388. },
  1389. clearSorting: function(button){
  1390. document.getElementById("ingredientSearch").value = "";
  1391. document.getElementById("ingredientSelect").selectedIndex = 0;
  1392. document.getElementById("ingredientClearButton").style.display = "none";
  1393. this.populateByProperty("category");
  1394. }
  1395. }
  1396. },{}],11:[function(require,module,exports){
  1397. module.exports = {
  1398. display: function(Ingredient){
  1399. document.getElementById("newIngName").value = "";
  1400. document.getElementById("newIngCategory").value = "";
  1401. document.getElementById("newIngQuantity").value = 0;
  1402. document.getElementById("submitNewIng").onclick = ()=>{this.submit(Ingredient)};
  1403. },
  1404. submit: function(Ingredient){
  1405. let unitSelector = document.getElementById("unitSelector");
  1406. let options = document.querySelectorAll("#unitSelector option");
  1407. let unit = unitSelector.value;
  1408. let newIngredient = {
  1409. ingredient: {
  1410. name: document.getElementById("newIngName").value,
  1411. category: document.getElementById("newIngCategory").value,
  1412. unitType: options[unitSelector.selectedIndex].getAttribute("type"),
  1413. },
  1414. quantity: controller.convertToMain(unit, document.getElementById("newIngQuantity").value),
  1415. defaultUnit: unit
  1416. }
  1417. let loader = document.getElementById("loaderContainer");
  1418. loader.style.display = "flex";
  1419. fetch("/ingredients/create", {
  1420. method: "POST",
  1421. headers: {
  1422. "Content-Type": "application/json;charset=utf-8"
  1423. },
  1424. body: JSON.stringify(newIngredient)
  1425. })
  1426. .then((response) => response.json())
  1427. .then((response)=>{
  1428. if(typeof(response) === "string"){
  1429. banner.createError(response);
  1430. }else{
  1431. merchant.editIngredients([{
  1432. ingredient: new Ingredient(
  1433. response.ingredient._id,
  1434. response.ingredient.name,
  1435. response.ingredient.category,
  1436. response.ingredient.unitType,
  1437. response.defaultUnit,
  1438. merchant
  1439. ),
  1440. quantity: response.quantity
  1441. }]);
  1442. banner.createNotification("INGREDIENT CREATED");
  1443. }
  1444. })
  1445. .catch((err)=>{
  1446. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1447. })
  1448. .finally(()=>{
  1449. loader.style.display = "none";
  1450. });
  1451. }
  1452. }
  1453. },{}],12:[function(require,module,exports){
  1454. module.exports = {
  1455. isPopulated: false,
  1456. unused: [],
  1457. display: function(Order){
  1458. if(!this.isPopulated){
  1459. let categories = merchant.categorizeIngredients();
  1460. let categoriesList = document.getElementById("newOrderCategories");
  1461. let template = document.getElementById("addIngredientsCategory").content.children[0];
  1462. let ingredientTemplate = document.getElementById("addIngredientsIngredient").content.children[0];
  1463. for(let i = 0; i < categories.length; i++){
  1464. let category = template.cloneNode(true);
  1465. category.children[0].children[0].innerText = categories[i].name;
  1466. category.children[0].children[1].onclick = ()=>{this.toggleAddIngredient(category)};
  1467. category.children[0].children[1].children[1].style.display = "none";
  1468. category.children[1].style.display = "none";
  1469. categoriesList.appendChild(category);
  1470. for(let j = 0; j < categories[i].ingredients.length; j++){
  1471. let ingredientDiv = ingredientTemplate.cloneNode(true);
  1472. ingredientDiv.children[0].innerText = categories[i].ingredients[j].ingredient.name;
  1473. ingredientDiv.children[2].onclick = ()=>{this.addOne(ingredientDiv, category.children[1])};
  1474. ingredientDiv.ingredient = categories[i].ingredients[j].ingredient;
  1475. this.unused.push(categories[i].ingredients[j]);
  1476. category.children[1].appendChild(ingredientDiv);
  1477. }
  1478. }
  1479. document.getElementById("submitNewOrder").onclick = ()=>{this.submit(Order)};
  1480. this.isPopulated = true;
  1481. }
  1482. },
  1483. addOne: function(ingredientDiv, container){
  1484. for(let i = 0; i < this.unused.length; i++){
  1485. if(this.unused[i] === ingredientDiv){
  1486. this.unused.splice(i, 1);
  1487. break;
  1488. }
  1489. }
  1490. let quantityInput = document.createElement("input");
  1491. quantityInput.type = "number";
  1492. quantityInput.placeholder = `QUANTITY (${ingredientDiv.ingredient.unit})`;
  1493. quantityInput.min = "0";
  1494. quantityInput.step = "0.01";
  1495. ingredientDiv.insertBefore(quantityInput, ingredientDiv.children[1]);
  1496. let priceInput = document.createElement("input");
  1497. priceInput.type = "number";
  1498. priceInput.placeholder = "Price Per Unit";
  1499. priceInput.min = "0";
  1500. priceInput.step = "0.01";
  1501. ingredientDiv.insertBefore(priceInput, ingredientDiv.children[2]);
  1502. ingredientDiv.children[4].innerText = "-";
  1503. ingredientDiv.children[4].onclick = ()=>{this.removeOne(ingredientDiv, container)};
  1504. container.removeChild(ingredientDiv);
  1505. document.getElementById("newOrderAdded").appendChild(ingredientDiv);
  1506. },
  1507. removeOne: function(ingredientDiv, container){
  1508. this.unused.push(ingredientDiv.ingredient);
  1509. ingredientDiv.removeChild(ingredientDiv.children[1]);
  1510. ingredientDiv.removeChild(ingredientDiv.children[1]);
  1511. ingredientDiv.children[1].innerText = "+";
  1512. ingredientDiv.children[1].onclick = ()=>{this.addOne(ingredientDiv, container)};
  1513. ingredientDiv.parentElement.removeChild(ingredientDiv);
  1514. container.appendChild(ingredientDiv);
  1515. },
  1516. toggleAddIngredient: function(categoryElement){
  1517. let button = categoryElement.children[0].children[1];
  1518. let ingredientDisplay = categoryElement.children[1];
  1519. if(ingredientDisplay.style.display === "none"){
  1520. ingredientDisplay.style.display = "flex";
  1521. button.children[0].style.display = "none";
  1522. button.children[1].style.display = "block";
  1523. }else{
  1524. ingredientDisplay.style.display = "none";
  1525. button.children[0].style.display = "block";
  1526. button.children[1].style.display = "none";
  1527. }
  1528. },
  1529. submit: function(Order){
  1530. let categoriesList = document.getElementById("newOrderAdded");
  1531. let ingredients = [];
  1532. for(let i = 0; i < categoriesList.children.length; i++){
  1533. let quantity = categoriesList.children[i].children[1].value;
  1534. let price = categoriesList.children[i].children[2].value;
  1535. let fakeOrder = new Order(undefined, undefined, new Date(), [], undefined);
  1536. if(quantity !== "" && price !== ""){
  1537. ingredients.push({
  1538. ingredient: categoriesList.children[i].ingredient.id,
  1539. quantity: controller.convertToMain(categoriesList.children[i].ingredient.unit, parseFloat(quantity)),
  1540. price: categoriesList.children[i].ingredient.convert(parseInt(price * 100))
  1541. });
  1542. }
  1543. }
  1544. let time = document.getElementById("orderTime").value;
  1545. let date = document.getElementById("orderDate").value;
  1546. let dateTime = "";
  1547. if(time === "" && date === ""){
  1548. dateTime = undefined;
  1549. }else if(time === "" && date !== ""){
  1550. dateTime = date;
  1551. }else if(time !== "" && date === ""){
  1552. banner.createError("PLEASE ADD A DATE IF YOU WISH TO HAVE A TIME");
  1553. }else{
  1554. dateTime = `${date}T${time}:00`
  1555. }
  1556. let data = {
  1557. name: document.getElementById("orderName").value,
  1558. date: dateTime,
  1559. ingredients: ingredients
  1560. };
  1561. let loader = document.getElementById("loaderContainer");
  1562. loader.style.display = "flex";
  1563. fetch("/order/create", {
  1564. method: "POST",
  1565. headers: {
  1566. "Content-Type": "application/json;charset=utf-8"
  1567. },
  1568. body: JSON.stringify(data)
  1569. })
  1570. .then(response => response.json())
  1571. .then((response)=>{
  1572. if(typeof(response) === "string"){
  1573. banner.createError(response);
  1574. }else{
  1575. let order = new Order(
  1576. response._id,
  1577. response.name,
  1578. response.date,
  1579. response.ingredients,
  1580. merchant
  1581. )
  1582. merchant.editOrders([order]);
  1583. merchant.editIngredients(order.ingredients, false, true);
  1584. banner.createNotification("ORDER CREATED");
  1585. }
  1586. })
  1587. .catch((err)=>{
  1588. banner.createError("SOEMTHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1589. })
  1590. .finally(()=>{
  1591. loader.style.display = "none";
  1592. });
  1593. },
  1594. }
  1595. },{}],13:[function(require,module,exports){
  1596. module.exports = {
  1597. display: function(Recipe){
  1598. let ingredientsSelect = document.querySelector("#recipeInputIngredients select");
  1599. let categories = merchant.categorizeIngredients();
  1600. while(ingredientsSelect.children.length > 0){
  1601. ingredientsSelect.removeChild(ingredientsSelect.firstChild);
  1602. }
  1603. for(let i = 0; i < categories.length; i++){
  1604. let optgroup = document.createElement("optgroup");
  1605. optgroup.label = categories[i].name;
  1606. ingredientsSelect.appendChild(optgroup);
  1607. for(let j = 0; j < categories[i].ingredients.length; j++){
  1608. let option = document.createElement("option");
  1609. option.value = categories[i].ingredients[j].ingredient.id;
  1610. option.innerText = `${categories[i].ingredients[j].ingredient.name} (${categories[i].ingredients[j].ingredient.unit})`;
  1611. optgroup.appendChild(option);
  1612. }
  1613. }
  1614. document.getElementById("ingredientCount").onclick = ()=>{this.changeRecipeCount()};
  1615. document.getElementById("submitNewRecipe").onclick = ()=>{this.submit(Recipe)};
  1616. },
  1617. //Updates the number of ingredient inputs displayed for new recipes
  1618. changeRecipeCount: function(){
  1619. let newCount = document.getElementById("ingredientCount").value;
  1620. let ingredientsDiv = document.getElementById("recipeInputIngredients");
  1621. let oldCount = ingredientsDiv.children.length;
  1622. if(newCount > oldCount){
  1623. let newDivs = newCount - oldCount;
  1624. for(let i = 0; i < newDivs; i++){
  1625. let newNode = ingredientsDiv.children[0].cloneNode(true);
  1626. newNode.children[2].children[0].value = "";
  1627. ingredientsDiv.appendChild(newNode);
  1628. }
  1629. for(let i = 0; i < newCount; i++){
  1630. ingredientsDiv.children[i].children[0].innerText = `INGREDIENT ${i + 1}`;
  1631. }
  1632. }else if(newCount < oldCount){
  1633. let newDivs = oldCount - newCount;
  1634. for(let i = 0; i < newDivs; i++){
  1635. ingredientsDiv.removeChild(ingredientsDiv.children[ingredientsDiv.children.length-1]);
  1636. }
  1637. }
  1638. },
  1639. submit: function(Recipe){
  1640. let newRecipe = {
  1641. name: document.getElementById("newRecipeName").value,
  1642. price: document.getElementById("newRecipePrice").value,
  1643. ingredients: []
  1644. }
  1645. let inputs = document.querySelectorAll("#recipeInputIngredients > div");
  1646. for(let i = 0; i < inputs.length; i++){
  1647. for(let j = 0; j < merchant.ingredients.length; j++){
  1648. if(merchant.ingredients[j].ingredient.id === inputs[i].children[1].children[0].value){
  1649. newRecipe.ingredients.push({
  1650. ingredient: inputs[i].children[1].children[0].value,
  1651. quantity: controller.convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
  1652. });
  1653. break;
  1654. }
  1655. }
  1656. }
  1657. let loader = document.getElementById("loaderContainer");
  1658. loader.style.display = "flex";
  1659. fetch("/recipe/create", {
  1660. method: "POST",
  1661. headers: {
  1662. "Content-Type": "application/json;charset=utf-8"
  1663. },
  1664. body: JSON.stringify(newRecipe)
  1665. })
  1666. .then((response) => response.json())
  1667. .then((response)=>{
  1668. if(typeof(response) === "string"){
  1669. banner.createError(response);
  1670. }else{
  1671. let recipe = new Recipe(
  1672. response._id,
  1673. response.name,
  1674. response.price,
  1675. response.ingredients,
  1676. merchant,
  1677. );
  1678. merchant.editRecipes([recipe]);
  1679. banner.createNotification("RECIPE CREATED");
  1680. }
  1681. })
  1682. .catch((err)=>{
  1683. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1684. })
  1685. .finally(()=>{
  1686. loader.style.display = "none";
  1687. });
  1688. },
  1689. }
  1690. },{}],14:[function(require,module,exports){
  1691. module.exports = {
  1692. display: function(Transaction){
  1693. let recipeList = document.getElementById("newTransactionRecipes");
  1694. let template = document.getElementById("createTransaction").content.children[0];
  1695. while(recipeList.children.length > 0){
  1696. recipeList.removeChild(recipeList.firstChild);
  1697. }
  1698. for(let i = 0; i < merchant.recipes.length; i++){
  1699. let recipeDiv = template.cloneNode(true);
  1700. recipeDiv.recipe = merchant.recipes[i];
  1701. recipeList.appendChild(recipeDiv);
  1702. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  1703. }
  1704. document.getElementById("submitNewTransaction").onclick = ()=>{this.submit(Transaction)};
  1705. },
  1706. submit: function(Transaction){
  1707. let recipeDivs = document.getElementById("newTransactionRecipes");
  1708. let date = document.getElementById("newTransactionDate").valueAsDate;
  1709. if(date > new Date()){
  1710. banner.createError("CANNOT HAVE A DATE IN THE FUTURE");
  1711. return;
  1712. }
  1713. let newTransaction = {
  1714. date: date,
  1715. recipes: []
  1716. };
  1717. for(let i = 0; i < recipeDivs.children.length; i++){
  1718. let quantity = recipeDivs.children[i].children[1].value;
  1719. if(quantity !== "" && quantity > 0){
  1720. newTransaction.recipes.push({
  1721. recipe: recipeDivs.children[i].recipe.id,
  1722. quantity: quantity
  1723. });
  1724. }else if(quantity < 0){
  1725. banner.createError("CANNOT HAVE NEGATIVE VALUES");
  1726. return;
  1727. }
  1728. }
  1729. if(newTransaction.recipes.length > 0){
  1730. let loader = document.getElementById("loaderContainer");
  1731. loader.style.display = "flex";
  1732. fetch("/transaction/create", {
  1733. method: "post",
  1734. headers: {
  1735. "Content-Type": "application/json;charset=utf-8"
  1736. },
  1737. body: JSON.stringify(newTransaction)
  1738. })
  1739. .then(response => response.json())
  1740. .then((response)=>{
  1741. if(typeof(response) === "string"){
  1742. banner.createError(response);
  1743. }else{
  1744. let transaction = new Transaction(
  1745. response._id,
  1746. response.date,
  1747. response.recipes,
  1748. merchant
  1749. );
  1750. merchant.editTransactions(transaction);
  1751. banner.createNotification("NEW TRANSACTION CREATED");
  1752. }
  1753. })
  1754. .catch((err)=>{
  1755. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1756. })
  1757. .finally(()=>{
  1758. loader.style.display = "none";
  1759. });
  1760. }
  1761. }
  1762. }
  1763. },{}],15:[function(require,module,exports){
  1764. module.exports = {
  1765. display: function(order){
  1766. document.getElementById("removeOrderBtn").onclick = ()=>{this.remove(order)};
  1767. document.getElementById("orderDetailName").innerText = order.name;
  1768. document.getElementById("orderDetailDate").innerText = order.date.toLocaleDateString("en-US");
  1769. document.getElementById("orderDetailTime").innerText = order.date.toLocaleTimeString("en-US");
  1770. let ingredientList = document.getElementById("orderIngredients");
  1771. while(ingredientList.children.length > 0){
  1772. ingredientList.removeChild(ingredientList.firstChild);
  1773. }
  1774. let template = document.getElementById("orderIngredient").content.children[0];
  1775. let grandTotal = 0;
  1776. for(let i = 0; i < order.ingredients.length; i++){
  1777. let ingredientDiv = template.cloneNode(true);
  1778. let price = (order.ingredients[i].quantity * order.ingredients[i].price) / 100;
  1779. grandTotal += price;
  1780. let ingredient = order.ingredients[i].ingredient;
  1781. let priceText = ingredient.convert(order.ingredients[i].quantity).toFixed(2) + " " +
  1782. ingredient.unit.toUpperCase() + " x $" +
  1783. (order.convertPrice(ingredient.unitType, ingredient.unit, order.ingredients[i].price) / 100).toFixed(2);
  1784. ingredientDiv.children[0].innerText = order.ingredients[i].ingredient.name;
  1785. ingredientDiv.children[1].innerText = priceText;
  1786. ingredientDiv.children[2].innerText = `$${price.toFixed(2)}`;
  1787. ingredientList.appendChild(ingredientDiv);
  1788. }
  1789. document.querySelector("#orderTotalPrice p").innerText = `$${grandTotal.toFixed(2)}`;
  1790. },
  1791. remove: function(order){
  1792. let loader = document.getElementById("loaderContainer");
  1793. loader.style.display = "flex";
  1794. fetch(`/order/${order.id}`, {
  1795. method: "DELETE",
  1796. headers: {
  1797. "Content-Type": "application/json;charset=utf-8"
  1798. }
  1799. })
  1800. .then((response) => response.json())
  1801. .then((response)=>{
  1802. if(typeof(response) === "string"){
  1803. banner.createError(response);
  1804. }else{
  1805. merchant.editOrders([order], true);
  1806. banner.createNotification("ORDER REMOVED");
  1807. }
  1808. })
  1809. .catch((err)=>{
  1810. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1811. })
  1812. .finally(()=>{
  1813. loader.style.display = "none";
  1814. });
  1815. }
  1816. }
  1817. },{}],16:[function(require,module,exports){
  1818. const Order = require("./Order");
  1819. module.exports = {
  1820. isFetched: false,
  1821. display: async function(Order){
  1822. if(!this.isFetched){
  1823. let loader = document.getElementById("loaderContainer");
  1824. loader.style.display = "flex";
  1825. fetch("/order", {
  1826. method: "GET",
  1827. headers: {
  1828. "Content-Type": "application/json;charset=utf-8"
  1829. },
  1830. })
  1831. .then((response) => response.json())
  1832. .then((response)=>{
  1833. if(typeof(response) === "string"){
  1834. banner.createError(response);
  1835. }else{
  1836. let newOrders = [];
  1837. for(let i = 0; i < response.length; i++){
  1838. newOrders.push(new Order(
  1839. response[i]._id,
  1840. response[i].name,
  1841. response[i].date,
  1842. response[i].ingredients,
  1843. merchant
  1844. ));
  1845. }
  1846. merchant.editOrders(newOrders);
  1847. document.getElementById("orderSubmitForm").onsubmit = ()=>{this.submitFilter(Order)};
  1848. this.isFetched = true;
  1849. }
  1850. })
  1851. .catch((err)=>{
  1852. banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE");
  1853. })
  1854. .finally(()=>{
  1855. loader.style.display = "none";
  1856. });
  1857. }
  1858. },
  1859. populate: function(){
  1860. let listDiv = document.getElementById("orderList");
  1861. let template = document.getElementById("order").content.children[0];
  1862. let dateDropdown = document.getElementById("dateDropdownOrder");
  1863. let ingredientDropdown = document.getElementById("ingredientDropdown");
  1864. dateDropdown.style.display = "none";
  1865. ingredientDropdown.style.display = "none";
  1866. document.getElementById("dateFilterBtnOrder").onclick = ()=>{this.toggleDropdown(dateDropdown)};
  1867. document.getElementById("ingredientFilterBtn").onclick = ()=>{this.toggleDropdown(ingredientDropdown)};
  1868. for(let i = 0; i < merchant.ingredients.length; i++){
  1869. let checkbox = document.createElement("input");
  1870. checkbox.type = "checkbox";
  1871. checkbox.ingredient = merchant.ingredients[i].ingredient;
  1872. ingredientDropdown.appendChild(checkbox);
  1873. let label = document.createElement("label");
  1874. label.innerText = merchant.ingredients[i].ingredient.name;
  1875. label.for = checkbox;
  1876. ingredientDropdown.appendChild(label);
  1877. let brk = document.createElement("br");
  1878. ingredientDropdown.appendChild(brk);
  1879. }
  1880. while(listDiv.children.length > 0){
  1881. listDiv.removeChild(listDiv.firstChild);
  1882. }
  1883. for(let i = 0; i < merchant.orders.length; i++){
  1884. let row = template.cloneNode(true);
  1885. let totalCost = 0;
  1886. for(let j = 0; j < merchant.orders[i].ingredients.length; j++){
  1887. totalCost += merchant.orders[i].ingredients[j].quantity * merchant.orders[i].ingredients[j].price;
  1888. }
  1889. row.children[0].innerText = merchant.orders[i].name;
  1890. row.children[1].innerText = `${merchant.orders[i].ingredients.length} items`;
  1891. row.children[2].innerText = new Date(merchant.orders[i].date).toLocaleDateString("en-US");
  1892. row.children[3].innerText = `$${(totalCost / 100).toFixed(2)}`;
  1893. row.order = merchant.orders[i];
  1894. row.onclick = ()=>{controller.openSidebar("orderDetails", merchant.orders[i])};
  1895. listDiv.appendChild(row);
  1896. }
  1897. },
  1898. submitFilter: function(){
  1899. event.preventDefault();
  1900. let data = {
  1901. startDate: document.getElementById("orderFilDate1").valueAsDate,
  1902. endDate: document.getElementById("orderFilDate2").valueAsDate,
  1903. ingredients: []
  1904. }
  1905. if(data.startDate >= data.endDate){
  1906. banner.createError("START DATE CANNOT BE AFTER END DATE");
  1907. return;
  1908. }
  1909. let ingredientChoices = document.getElementById("ingredientDropdown");
  1910. for(let i = 0; i < ingredientChoices.children.length; i += 3){
  1911. if(ingredientChoices.children[i].checked){
  1912. data.ingredients.push(ingredientChoices.children[i].ingredient.id);
  1913. }
  1914. }
  1915. if(data.ingredients.length === 0){
  1916. for(let i = 0; i < merchant.ingredients.length; i++){
  1917. data.ingredients.push(merchant.ingredients[i].ingredient.id);
  1918. }
  1919. }
  1920. let loader = document.getElementById("loaderContainer");
  1921. loader.style.display = "flex";
  1922. fetch("/order", {
  1923. method: "POST",
  1924. headers: {
  1925. "Content-Type": "application/json;charset=utf-8"
  1926. },
  1927. body: JSON.stringify(data)
  1928. })
  1929. .then((response) => response.json())
  1930. .then((response)=>{
  1931. if(typeof(response) === "string"){
  1932. banner.createError(response);
  1933. }else{
  1934. let orderList = document.getElementById("orderList");
  1935. let template = document.getElementById("order").content.children[0];
  1936. while(orderList.children.length > 0){
  1937. orderList.removeChild(orderList.firstChild);
  1938. }
  1939. for(let i = 0; i < response.length; i++){
  1940. let orderDiv = template.cloneNode(true);
  1941. let order = new Order(
  1942. response[i]._id,
  1943. response[i].name,
  1944. response[i].date,
  1945. response[i].ingredients,
  1946. merchant
  1947. );
  1948. let cost = 0;
  1949. for(let j = 0; j < order.ingredients.length; j++){
  1950. cost += (order.ingredients[j].price / 100) * order.ingredients[j].quantity;
  1951. }
  1952. orderDiv.children[0].innerText = order.name;
  1953. orderDiv.children[1].innerText = `${order.ingredients.length} items`;
  1954. orderDiv.children[2].innerText = order.date.toLocaleDateString();
  1955. orderDiv.children[3].innerText = `$${cost.toFixed(2)}`;
  1956. orderDiv.onclick = ()=>{controller.openSidebar("orderDetails", order)};
  1957. orderList.appendChild(orderDiv);
  1958. }
  1959. }
  1960. })
  1961. .catch((err)=>{
  1962. banner.createError("UNABLE TO DISPLAY THE ORDERS");
  1963. })
  1964. .finally(()=>{
  1965. loader.style.display = "none";
  1966. });
  1967. },
  1968. toggleDropdown: function(dropdown){
  1969. event.preventDefault();
  1970. let polyline = dropdown.parentElement.children[0].children[1].children[0].children[0];
  1971. if(dropdown.style.display === "none"){
  1972. dropdown.style.display = "block";
  1973. polyline.setAttribute("points", "18 15 12 9 6 15");
  1974. }else{
  1975. dropdown.style.display = "none";
  1976. polyline.setAttribute("points", "6 9 12 15 18 9");
  1977. }
  1978. }
  1979. }
  1980. },{"./Order":3}],17:[function(require,module,exports){
  1981. module.exports = {
  1982. isPopulated: false,
  1983. recipeDivList: [],
  1984. display: function(){
  1985. if(!this.isPopulated){
  1986. this.populateRecipes();
  1987. if(merchant.pos === "clover"){
  1988. document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate()};
  1989. }
  1990. document.getElementById("recipeSearch").oninput = ()=>{this.search()};
  1991. document.getElementById("recipeClearButton").onclick = ()=>{this.clearSorting()};
  1992. this.isPopulated = true;
  1993. }
  1994. },
  1995. populateRecipes: function(){
  1996. let recipeList = document.getElementById("recipeList");
  1997. let template = document.getElementById("recipe").content.children[0];
  1998. this.recipeDivList = [];
  1999. while(recipeList.children.length > 0){
  2000. recipeList.removeChild(recipeList.firstChild);
  2001. }
  2002. for(let i = 0; i < merchant.recipes.length; i++){
  2003. let recipeDiv = template.cloneNode(true);
  2004. recipeDiv.onclick = ()=>{controller.openSidebar("recipeDetails", merchant.recipes[i])};
  2005. recipeDiv._name = merchant.recipes[i].name;
  2006. recipeList.appendChild(recipeDiv);
  2007. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  2008. recipeDiv.children[1].innerText = `$${(merchant.recipes[i].price / 100).toFixed(2)}`;
  2009. this.recipeDivList.push(recipeDiv);
  2010. }
  2011. },
  2012. search: function(){
  2013. let input = document.getElementById("recipeSearch").value.toLowerCase();
  2014. let recipeList = document.getElementById("recipeList");
  2015. let clearButton = document.getElementById("recipeClearButton");
  2016. let matchingRecipes = [];
  2017. for(let i = 0; i < this.recipeDivList.length; i++){
  2018. if(this.recipeDivList[i]._name.toLowerCase().includes(input)){
  2019. matchingRecipes.push(this.recipeDivList[i]);
  2020. }
  2021. }
  2022. while(recipeList.children.length > 0){
  2023. recipeList.removeChild(recipeList.firstChild);
  2024. }
  2025. for(let i = 0; i < matchingRecipes.length; i++){
  2026. recipeList.appendChild(matchingRecipes[i]);
  2027. }
  2028. if(input === ""){
  2029. clearButton.style.display = "none";
  2030. }else{
  2031. clearButton.style.display = "inline";
  2032. }
  2033. },
  2034. clearSorting: function(){
  2035. document.getElementById("recipeSearch").value = "";
  2036. this.search();
  2037. },
  2038. posUpdate: function(){
  2039. let loader = document.getElementById("loaderContainer");
  2040. loader.style.display = "flex";
  2041. fetch("/recipe/update/clover", {
  2042. method: "GET",
  2043. headers: {
  2044. "Content-Type": "application/json;charset=utf-8"
  2045. },
  2046. })
  2047. .then(response => response.json())
  2048. .then((response)=>{
  2049. let newRecipes = [];
  2050. for(let i = 0; i < response.new.length; i++){
  2051. newRecipes.push(new Recipe(
  2052. response.new[i]._id,
  2053. response.new[i].name,
  2054. response.new[i].price,
  2055. merchant,
  2056. []
  2057. ));
  2058. }
  2059. if(newRecipes.length > 0){
  2060. merchant.editRecipes(newRecipes);
  2061. }
  2062. let removeRecipes = [];
  2063. for(let i = 0; i < response.removed.length; i++){
  2064. for(let j = 0; j < merchant.recipes.length; j++){
  2065. if(response.removed[i]._id === merchant.recipes[j].id){
  2066. removeRecipes.push(merchant.recipes[j], true);
  2067. break;
  2068. }
  2069. }
  2070. }
  2071. if(removeRecipes.length > 0){
  2072. merchant.editRecipes(removeRecipes, true);
  2073. }
  2074. })
  2075. .catch((err)=>{
  2076. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2077. })
  2078. .finally(()=>{
  2079. loader.style.display = "none";
  2080. });
  2081. }
  2082. }
  2083. },{}],18:[function(require,module,exports){
  2084. module.exports = {
  2085. recipe: {},
  2086. display: function(recipe){
  2087. this.recipe = recipe;
  2088. document.getElementById("recipeName").style.display = "block";
  2089. document.getElementById("recipeNameIn").style.display = "none";
  2090. document.querySelector("#recipeDetails h1").innerText = recipe.name;
  2091. let ingredientList = document.getElementById("recipeIngredientList");
  2092. while(ingredientList.children.length > 0){
  2093. ingredientList.removeChild(ingredientList.firstChild);
  2094. }
  2095. let template = document.getElementById("recipeIngredient").content.children[0];
  2096. for(let i = 0; i < recipe.ingredients.length; i++){
  2097. ingredientDiv = template.cloneNode(true);
  2098. ingredientDiv.children[0].innerText = recipe.ingredients[i].ingredient.name;
  2099. ingredientDiv.children[2].innerText = `${recipe.ingredients[i].ingredient.convert(recipe.ingredients[i].quantity).toFixed(2)} ${recipe.ingredients[i].ingredient.unit}`;
  2100. ingredientDiv.ingredient = recipe.ingredients[i].ingredient;
  2101. ingredientDiv.name = recipe.ingredients[i].ingredient.name;
  2102. ingredientList.appendChild(ingredientDiv);
  2103. }
  2104. document.getElementById("addRecIng").style.display = "none";
  2105. let price = document.getElementById("recipePrice");
  2106. price.children[1].style.display = "block";
  2107. price.children[2].style.display = "none";
  2108. price.children[1].innerText = `$${(recipe.price / 100).toFixed(2)}`;
  2109. document.getElementById("recipeUpdate").style.display = "none";
  2110. document.getElementById("editRecipeBtn").onclick = ()=>{this.edit()};
  2111. document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove()};
  2112. document.getElementById("addRecIng").onclick = ()=>{this.displayAddIngredient()};
  2113. document.getElementById("recipeUpdate").onclick = ()=>{this.update()};
  2114. },
  2115. edit: function(){
  2116. let ingredientDivs = document.getElementById("recipeIngredientList");
  2117. if(merchant.pos === "none"){
  2118. let name = document.getElementById("recipeName");
  2119. let nameIn = document.getElementById("recipeNameIn");
  2120. name.style.display = "none";
  2121. nameIn.style.display = "block";
  2122. nameIn.value = this.recipe.name;
  2123. let price = document.getElementById("recipePrice");
  2124. price.children[1].style.display = "none";
  2125. price.children[2].style.display = "block";
  2126. price.children[2].value = parseFloat((this.recipe.price / 100).toFixed(2));
  2127. }
  2128. for(let i = 0; i < ingredientDivs.children.length; i++){
  2129. let div = ingredientDivs.children[i];
  2130. div.children[2].innerText = this.recipe.ingredients[i].ingredient.unit;
  2131. div.children[1].style.display = "block";
  2132. div.children[1].value = this.recipe.ingredients[i].ingredient.convert(this.recipe.ingredients[i].quantity).toFixed(2);
  2133. div.children[3].style.display = "block";
  2134. div.children[3].onclick = ()=>{div.parentElement.removeChild(div)};
  2135. }
  2136. document.getElementById("addRecIng").style.display = "flex";
  2137. document.getElementById("recipeUpdate").style.display = "flex";
  2138. },
  2139. update: function(){
  2140. this.recipe.name = document.getElementById("recipeNameIn").value || this.recipe.name;
  2141. this.recipe.price = Math.round((document.getElementById("recipePrice").children[2].value * 100)) || this.recipe.price;
  2142. this.recipe.ingredients = [];
  2143. let divs = document.getElementById("recipeIngredientList").children;
  2144. for(let i = 0; i < divs.length; i++){
  2145. if(divs[i].name === "new"){
  2146. let select = divs[i].children[0];
  2147. this.recipe.ingredients.push({
  2148. ingredient: select.options[select.selectedIndex].ingredient,
  2149. quantity: controller.convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
  2150. });
  2151. }else{
  2152. this.recipe.ingredients.push({
  2153. ingredient: divs[i].ingredient,
  2154. quantity: controller.convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
  2155. });
  2156. }
  2157. }
  2158. let data = {
  2159. id: this.recipe.id,
  2160. name: this.recipe.name,
  2161. price: this.recipe.price,
  2162. ingredients: []
  2163. }
  2164. for(let i = 0; i < this.recipe.ingredients.length; i++){
  2165. data.ingredients.push({
  2166. ingredient: this.recipe.ingredients[i].ingredient.id,
  2167. quantity: this.recipe.ingredients[i].quantity
  2168. });
  2169. }
  2170. let loader = document.getElementById("loaderContainer");
  2171. loader.style.display = "flex";
  2172. fetch("/recipe/update", {
  2173. method: "PUT",
  2174. headers: {
  2175. "Content-Type": "application/json;charset=utf-8"
  2176. },
  2177. body: JSON.stringify(data)
  2178. })
  2179. .then((response) => response.json())
  2180. .then((response)=>{
  2181. if(typeof(response) === "string"){
  2182. banner.createError(response);
  2183. }else{
  2184. merchant.editRecipes([this.recipe]);
  2185. banner.createNotification("RECIPE UPDATE");
  2186. }
  2187. })
  2188. .catch((err)=>{
  2189. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2190. })
  2191. .finally(()=>{
  2192. loader.style.display = "none";
  2193. });
  2194. },
  2195. remove: function(){
  2196. fetch(`/merchant/recipes/remove/${this.recipe.id}`, {
  2197. method: "DELETE"
  2198. })
  2199. .then((response) => response.json())
  2200. .then((response)=>{
  2201. if(typeof(response) === "string"){
  2202. banner.createError(response);
  2203. }else{
  2204. merchant.editRecipes([this.recipe], true);
  2205. banner.createNotification("RECIPE REMOVED");
  2206. }
  2207. })
  2208. .catch((err)=>{
  2209. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2210. });
  2211. },
  2212. displayAddIngredient: function(){
  2213. let template = document.getElementById("addRecIngredient").content.children[0].cloneNode(true);
  2214. template.name = "new";
  2215. document.getElementById("recipeIngredientList").appendChild(template);
  2216. let categories = merchant.categorizeIngredients();
  2217. for(let i = 0; i < categories.length; i++){
  2218. let optGroup = document.createElement("optgroup");
  2219. optGroup.label = categories[i].name;
  2220. template.children[0].appendChild(optGroup);
  2221. for(let j = 0; j < categories[i].ingredients.length; j++){
  2222. let option = document.createElement("option");
  2223. option.innerText = `${categories[i].ingredients[j].ingredient.name} (${categories[i].ingredients[j].ingredient.unit})`;
  2224. option.ingredient = categories[i].ingredients[j].ingredient;
  2225. optGroup.appendChild(option);
  2226. }
  2227. }
  2228. }
  2229. }
  2230. },{}],19:[function(require,module,exports){
  2231. module.exports = {
  2232. transaction: {},
  2233. display: function(transaction){
  2234. this.transaction = transaction;
  2235. let recipeList = document.getElementById("transactionRecipes");
  2236. let template = document.getElementById("transactionRecipe").content.children[0];
  2237. let totalRecipes = 0;
  2238. let totalPrice = 0;
  2239. while(recipeList.children.length > 0){
  2240. recipeList.removeChild(recipeList.firstChild);
  2241. }
  2242. for(let i = 0; i < transaction.recipes.length; i++){
  2243. let recipe = template.cloneNode(true);
  2244. let price = transaction.recipes[i].quantity * transaction.recipes[i].recipe.price;
  2245. recipe.children[0].innerText = transaction.recipes[i].recipe.name;
  2246. recipe.children[1].innerText = `${transaction.recipes[i].quantity} x $${parseFloat(transaction.recipes[i].recipe.price / 100).toFixed(2)}`;
  2247. recipe.children[2].innerText = `$${(price / 100).toFixed(2)}`;
  2248. recipeList.appendChild(recipe);
  2249. totalRecipes += transaction.recipes[i].quantity;
  2250. totalPrice += price;
  2251. }
  2252. let months = ["January", "Fecbruary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2253. let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  2254. let dateString = `${days[transaction.date.getDay()]}, ${months[transaction.date.getMonth()]} ${transaction.date.getDate()}, ${transaction.date.getFullYear()}`;
  2255. document.getElementById("transactionDate").innerText = dateString;
  2256. document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
  2257. document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
  2258. document.getElementById("totalPrice").innerText = `$${(totalPrice / 100).toFixed(2)}`;
  2259. document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
  2260. },
  2261. remove: function(){
  2262. let loader = document.getElementById("loaderContainer");
  2263. loader.style.display = "flex";
  2264. fetch(`/transaction/${this.transaction.id}`, {
  2265. method: "delete",
  2266. headers: {
  2267. "Content-Type": "application/json;charset=utf-8"
  2268. },
  2269. })
  2270. .then(response => response.json())
  2271. .then((response)=>{
  2272. if(typeof(response) === "string"){
  2273. banner.createError(response);
  2274. }else{
  2275. merchant.editTransactions(this.transaction, true);
  2276. banner.createNotification("TRANSACTION REMOVED");
  2277. }
  2278. })
  2279. .catch((err)=>{
  2280. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2281. })
  2282. .finally(()=>{
  2283. loader.style.display = "none";
  2284. });
  2285. },
  2286. }
  2287. },{}],20:[function(require,module,exports){
  2288. module.exports = {
  2289. isPopulated: false,
  2290. display: function(Transaction){
  2291. if(!this.isPopulated){
  2292. let transactionsList = document.getElementById("transactionsList");
  2293. let dateDropdown = document.getElementById("dateDropdown");
  2294. let recipeDropdown = document.getElementById("recipeDropDown");
  2295. let template = document.getElementById("transaction").content.children[0];
  2296. let now = new Date();
  2297. let monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
  2298. document.getElementById("transFilDate1").valueAsDate = monthAgo;
  2299. document.getElementById("transFilDate2").valueAsDate = now;
  2300. dateDropdown.style.display = "none";
  2301. recipeDropdown.style.display = "none";
  2302. document.getElementById("dateFilterBtn").onclick = ()=>{this.toggleDropdown(dateDropdown)};
  2303. document.getElementById("recipeFilterBtn").onclick = ()=>{this.toggleDropdown(recipeDropdown)};
  2304. while(recipeDropdown.children.length > 0){
  2305. recipeDropdown.removeChild(recipeDropdown.firstChild);
  2306. }
  2307. for(let i = 0; i < merchant.recipes.length; i++){
  2308. let checkbox = document.createElement("input");
  2309. checkbox.type = "checkbox";
  2310. checkbox.recipe = merchant.recipes[i];
  2311. recipeDropdown.appendChild(checkbox);
  2312. let label = document.createElement("label");
  2313. label.innerText = merchant.recipes[i].name;
  2314. label.for = checkbox;
  2315. recipeDropdown.appendChild(label);
  2316. let brk = document.createElement("br");
  2317. recipeDropdown.appendChild(brk);
  2318. }
  2319. while(transactionsList.children.length > 0){
  2320. transactionsList.removeChild(transactionsList.firstChild);
  2321. }
  2322. let i = 0
  2323. while(i < merchant.transactions.length && i < 100){
  2324. let transactionDiv = template.cloneNode(true);
  2325. let transaction = merchant.transactions[i];
  2326. transactionDiv.onclick = ()=>{controller.openSidebar("transactionDetails", transaction)};
  2327. transactionsList.appendChild(transactionDiv);
  2328. let totalRecipes = 0;
  2329. let totalPrice = 0;
  2330. for(let j = 0; j < merchant.transactions[i].recipes.length; j++){
  2331. totalRecipes += merchant.transactions[i].recipes[j].quantity;
  2332. totalPrice += merchant.transactions[i].recipes[j].recipe.price * merchant.transactions[i].recipes[j].quantity;
  2333. }
  2334. transactionDiv.children[0].innerText = `${merchant.transactions[i].date.toLocaleDateString()} ${merchant.transactions[i].date.toLocaleTimeString()}`;
  2335. transactionDiv.children[1].innerText = `${totalRecipes} recipes sold`;
  2336. transactionDiv.children[2].innerText = `$${(totalPrice / 100).toFixed(2)}`;
  2337. i++;
  2338. }
  2339. document.getElementById("transFormSubmit").onsubmit = ()=>{this.submitFilter(Transaction)};
  2340. this.isPopulated = true;
  2341. }
  2342. },
  2343. submitFilter: function(Transaction){
  2344. event.preventDefault();
  2345. let data = {
  2346. startDate: document.getElementById("transFilDate1").valueAsDate,
  2347. endDate: document.getElementById("transFilDate2").valueAsDate,
  2348. recipes: []
  2349. }
  2350. if(data.startDate >= data.endDate){
  2351. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2352. return;
  2353. }
  2354. let recipeChoices = document.getElementById("recipeDropDown");
  2355. for(let i = 0; i < recipeChoices.children.length; i += 3){
  2356. if(recipeChoices.children[i].checked){
  2357. data.recipes.push(recipeChoices.children[i].recipe.id);
  2358. }
  2359. }
  2360. if(data.recipes.length === 0){
  2361. for(let i = 0; i < merchant.recipes.length; i++){
  2362. data.recipes.push(merchant.recipes[i].id);
  2363. }
  2364. }
  2365. let loader = document.getElementById("loaderContainer");
  2366. loader.style.display = "flex";
  2367. fetch("/transaction", {
  2368. method: "POST",
  2369. headers: {
  2370. "Content-Type": "application/json;charset=utf-8"
  2371. },
  2372. body: JSON.stringify(data)
  2373. })
  2374. .then((response) => response.json())
  2375. .then((response)=>{
  2376. if(typeof(response) === "string"){
  2377. banner.createError(response);
  2378. }else{
  2379. let transactionList = document.getElementById("transactionsList");
  2380. let template = document.getElementById("transaction").content.children[0];
  2381. while(transactionList.children.length > 0){
  2382. transactionList.removeChild(transactionList.firstChild);
  2383. }
  2384. for(let i = 0; i < response.length; i++){
  2385. let transactionDiv = template.cloneNode(true);
  2386. let recipeCount = 0;
  2387. let cost = 0;
  2388. let transaction = new Transaction(
  2389. response[i]._id,
  2390. response[i].date,
  2391. response[i].recipes,
  2392. merchant
  2393. );
  2394. for(let j = 0; j < transaction.recipes.length; j++){
  2395. recipeCount += transaction.recipes[j].quantity;
  2396. cost += transaction.recipes[j].quantity * transaction.recipes[j].recipe.price;
  2397. }
  2398. transactionDiv.children[0].innerText = `${transaction.date.toLocaleDateString()} ${transaction.date.toLocaleTimeString()}`;
  2399. transactionDiv.children[1].innerText = `${recipeCount} recipes sold`;
  2400. transactionDiv.children[2].innerText = `$${(cost / 100).toFixed(2)}`;
  2401. transactionDiv.onclick = ()=>{controller.openSidebar("transactionDetails", transaction)};
  2402. transactionList.appendChild(transactionDiv);
  2403. }
  2404. }
  2405. })
  2406. .catch((err)=>{
  2407. banner.createError("UNABLE TO DISPLAY THE TRANSACTIONS");
  2408. })
  2409. .finally(()=>{
  2410. loader.style.display = "none";
  2411. });
  2412. },
  2413. toggleDropdown: function(dropdown){
  2414. event.preventDefault();
  2415. let polyline = dropdown.parentElement.children[0].children[1].children[0].children[0];
  2416. if(dropdown.style.display === "none"){
  2417. dropdown.style.display = "block";
  2418. polyline.setAttribute("points", "18 15 12 9 6 15");
  2419. }else{
  2420. dropdown.style.display = "none";
  2421. polyline.setAttribute("points", "6 9 12 15 18 9");
  2422. }
  2423. }
  2424. }
  2425. },{}],21:[function(require,module,exports){
  2426. //Creates a line graph within a canvas
  2427. //Will expand or shrink to the size of the canvas
  2428. //Inputs:
  2429. // canvas = the canvas that you would like to draw on
  2430. // yName = a string for the name of the Y axis
  2431. // xName = a string for the name of the X axis
  2432. class LineGraph{
  2433. constructor(canvas){
  2434. this.canvas = canvas;
  2435. this.context = canvas.getContext("2d");
  2436. this.left = canvas.clientWidth - (canvas.clientWidth * 0.95);
  2437. this.right = canvas.clientWidth * 1;
  2438. this.top = canvas.clientHeight - (canvas.clientHeight * 1);
  2439. this.bottom = canvas.clientHeight * 0.85;
  2440. this.data = [];
  2441. this.max = 0;
  2442. this.xRange = [];
  2443. this.colors = [];
  2444. this.colorIndex = 0;
  2445. for(let i = 0; i < 100; i++){
  2446. let redRand = Math.floor(Math.random() * 200);
  2447. let greenRand = Math.floor(Math.random() * 200);
  2448. let blueRand = Math.floor(Math.random() * 200);
  2449. this.colors.push(`rgb(${redRand}, ${greenRand}, ${blueRand})`);
  2450. }
  2451. }
  2452. //Add a dataset to the graph to draw
  2453. //Inputs:
  2454. // data = array containing list of numbers as the data points for the graph
  2455. // data[0] will be on the left. data[data.length-1] will be on the right.
  2456. // xRange = array containing two elements, start and end for x axis data (currently only dates)
  2457. // name = string name for the line. Used for display and finding lines. Each must be unique
  2458. addData(data, xRange, name){
  2459. data = {
  2460. set: data,
  2461. colorIndex: this.colorIndex,
  2462. name: name
  2463. }
  2464. this.colorIndex++;
  2465. this.data.push(data);
  2466. let isChange = false;
  2467. for(let i = 0; i < data.set.length; i++){
  2468. if(data.set[i] > this.max){
  2469. this.max = data.set[i];
  2470. this.verticalMultiplier = (this.bottom - this.top) / this.max;
  2471. this.horizontalMultiplier = (this.right - this.left) / (data.set.length - 1);
  2472. isChange = true;
  2473. }
  2474. }
  2475. if(this.xRange.length === 0){
  2476. this.xRange = xRange;
  2477. isChange = true;
  2478. }else{
  2479. if(xRange[0] < this.xRange[0]){
  2480. this.xRange[0] = xRange[0];
  2481. isChange = true;
  2482. }
  2483. if(xRange[1] > this.xRange[1]){
  2484. this.xRange[1] = xRange[1];
  2485. isChange = true;
  2486. }
  2487. }
  2488. if(isChange){
  2489. this.drawGraph();
  2490. }else{
  2491. this.drawLine(data);
  2492. }
  2493. }
  2494. //Removes a single data set from the graph and its line
  2495. //Inputs:
  2496. // id = the unique identifier of the data set that was passed in with addData function
  2497. removeData(name){
  2498. for(let i = 0; i < this.data.length; i++){
  2499. if(this.data[i].name === name){
  2500. this.data.splice(i, 1);
  2501. break;
  2502. }
  2503. }
  2504. this.drawGraph();
  2505. }
  2506. //Completely clears all data
  2507. //Does not delete the current graph displaying
  2508. clearData(){
  2509. this.max = 0;
  2510. this.data = [];
  2511. this.xRange = [];
  2512. }
  2513. addTitle(title){
  2514. this.top = this.canvas.clientHeight - (this.canvas.clientHeight * 0.9);
  2515. this.title = title;
  2516. }
  2517. /**********
  2518. *********PRIVATE*********
  2519. **********/
  2520. drawGraph(){
  2521. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  2522. this.drawYAxis();
  2523. this.drawXAxis();
  2524. for(let i = 0; i < this.data.length; i++){
  2525. this.drawLine(this.data[i]);
  2526. }
  2527. if(this.title){
  2528. this.context.font = "25px Saira";
  2529. let xLocation = ((this.right - this.left) / 2) - (this.context.measureText(this.title).width / 2);
  2530. this.context.fillText(this.title, xLocation, this.top - 10);
  2531. }
  2532. }
  2533. drawLine(data){
  2534. for(let i = 0; i < data.set.length - 1; i++){
  2535. this.context.beginPath();
  2536. this.context.moveTo(this.left + (this.horizontalMultiplier * i), this.bottom - (this.verticalMultiplier * data.set[i]));
  2537. this.context.lineTo(this.left + (this.horizontalMultiplier * (i + 1)), this.bottom - (this.verticalMultiplier * data.set[i + 1]));
  2538. this.context.strokeStyle = this.colors[data.colorIndex];
  2539. this.context.lineWidth = 2;
  2540. this.context.stroke();
  2541. }
  2542. this.context.strokeStyle = "black";
  2543. if(this.data.length > 1){
  2544. this.drawLegend(data.colorIndex, data.name);
  2545. }
  2546. }
  2547. drawXAxis(){
  2548. this.context.beginPath();
  2549. this.context.moveTo(this.left, this.bottom);
  2550. this.context.lineTo(this.right, this.bottom);
  2551. this.context.lineWidth = 4;
  2552. this.context.stroke();
  2553. this.context.setLineDash([5, 10]);
  2554. this.context.font = "10px Arial";
  2555. this.context.lineWidth = 1;
  2556. if(Object.prototype.toString.call(this.xRange[0]) === '[object Date]'){
  2557. let diff = Math.abs(Math.floor((Date.UTC(this.xRange[0].getFullYear(), this.xRange[0].getMonth(), this.xRange[0].getDate()) - Date.UTC(this.xRange[1].getFullYear(), this.xRange[1].getMonth(), this.xRange[1].getDate())) / (1000 * 60 * 60 * 24))) + 1;
  2558. let showDate = new Date(this.xRange[0]);
  2559. for(let i = 0; i < diff; i += Math.floor(diff / 10)){
  2560. this.context.fillText(showDate.toLocaleDateString("en-US", {month: "short", day: "numeric", year: "2-digit"}), this.left + (this.horizontalMultiplier * i) - 20, this.bottom + 15);
  2561. if(i !== 0){
  2562. this.context.beginPath()
  2563. this.context.moveTo(this.left + (this.horizontalMultiplier * i), this.bottom);
  2564. this.context.lineTo(this.left + (this.horizontalMultiplier * i), this.top);
  2565. this.context.strokeStyle = "#a5a5a5";
  2566. this.context.stroke();
  2567. }
  2568. showDate.setDate(showDate.getDate() + Math.abs(diff / 10));
  2569. }
  2570. }
  2571. this.context.strokeStyle = "black";
  2572. this.context.setLineDash([]);
  2573. }
  2574. drawYAxis(){
  2575. this.context.beginPath();
  2576. this.context.moveTo(this.left, this.top);
  2577. this.context.lineTo(this.left, this.bottom);
  2578. this.context.lineWidth = 2;
  2579. this.context.stroke();
  2580. this.context.setLineDash([5, 10]);
  2581. this.context.font = "10px Arial";
  2582. this.context.lineWidth = 1;
  2583. let axisNum = 0;
  2584. let verticalIncrement = (this.bottom - this.top) / 10;
  2585. let verticalOffset = 0;
  2586. do{
  2587. this.context.fillText(Math.round(axisNum).toString(), this.left - 20, this.bottom - verticalOffset + 3);
  2588. this.context.beginPath();
  2589. this.context.moveTo(this.left, this.bottom - verticalOffset);
  2590. this.context.lineTo(this.right, this.bottom - verticalOffset);
  2591. this.context.strokeStyle = "#a5a5a5";
  2592. this.context.stroke();
  2593. verticalOffset += verticalIncrement;
  2594. axisNum += this.max / 10;
  2595. }while(verticalOffset <= (this.bottom - this.top));
  2596. this.context.strokeStyle = "black";
  2597. this.context.setLineDash([]);
  2598. }
  2599. drawLegend(colorIndex, name){
  2600. let verticalOffset;
  2601. for(let i = 0; i < this.data.length; i++){
  2602. if(this.data[i].name === name){
  2603. verticalOffset = i * 25;
  2604. break;
  2605. }
  2606. }
  2607. this.context.beginPath();
  2608. this.context.fillStyle = this.colors[colorIndex];
  2609. this.context.fillRect(this.right + 50, this.top + 50 + verticalOffset, 10, 10);
  2610. this.context.stroke();
  2611. this.context.font = "15px Arial";
  2612. this.context.fillText(name, this.right + 65, this.top + 60 + verticalOffset);
  2613. this.context.fillStyle = "black";
  2614. }
  2615. }
  2616. class HorizontalBarGraph{
  2617. constructor(canvas){
  2618. this.canvas = canvas;
  2619. this.context = canvas.getContext("2d");
  2620. this.left = 0;
  2621. this.right = canvas.clientWidth;
  2622. this.top = canvas.clientHeight - (canvas.clientHeight * 0.99);
  2623. this.bottom = canvas.clientHeight;
  2624. this.data = [];
  2625. this.max = 0;
  2626. }
  2627. //Adds an array of data points to the chart
  2628. //All data is removed and redrawn when called
  2629. //Must pass in all data points
  2630. //Inputs:
  2631. // dataArray: array of objects
  2632. // num: number for the actual data
  2633. // label: text to display on bar
  2634. addData(dataArray){
  2635. this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
  2636. for(let i = 0; i < dataArray.length; i++){
  2637. if(dataArray[i].num > this.max){
  2638. this.max = dataArray[i].num;
  2639. }
  2640. this.data.push(dataArray[i]);
  2641. }
  2642. this.drawGraph();
  2643. }
  2644. drawGraph(){
  2645. let barHeight = ((this.bottom - this.top) / this.data.length) - 2;
  2646. for(let i = 0; i < this.data.length; i++){
  2647. let topLocation = this.top + (i * barHeight) + 5;
  2648. let width = (this.right - this.left) * (this.data[i].num / this.max);
  2649. if(this.data[i].num >= this.max){
  2650. this.context.fillStyle = "rgb(255, 99, 107)";
  2651. }else{
  2652. this.context.fillStyle = "rgb(179, 191, 209)";
  2653. }
  2654. this.context.beginPath();
  2655. this.context.fillRect(this.left, topLocation, width, barHeight - 5);
  2656. this.context.stroke();
  2657. let textLocation = 15;
  2658. this.context.font = "12px Saira";
  2659. this.context.fillStyle = "black";
  2660. this.context.fillText(this.data[i].label, textLocation, (this.top) + (i * barHeight) + (barHeight / 1.5));
  2661. }
  2662. }
  2663. }
  2664. module.exports = {
  2665. LineGraph: LineGraph,
  2666. HorizontalBarGraph: HorizontalBarGraph
  2667. }
  2668. },{}]},{},[7]);