bundle.js 116 KB

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