bundle.js 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149
  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. if(ingredient.ingredient.specialUnit === "bottle"){
  1140. input.value = (ingredient.quantity / ingredient.ingredient.unitSize).toFixed(2);
  1141. ingredientCheck.children[2].innerText = "BOTTLES";
  1142. }else{
  1143. input.value = ingredient.ingredient.convert(ingredient.quantity).toFixed(2);
  1144. ingredientCheck.children[2].innerText = ingredient.ingredient.unit.toUpperCase();
  1145. }
  1146. ingredientCheck.children[1].children[2].onclick = ()=>{
  1147. input.value++;
  1148. input.changed = true;
  1149. }
  1150. input.onchange = ()=>{input.changed = true};
  1151. ul.appendChild(ingredientCheck);
  1152. }
  1153. document.getElementById("inventoryCheck").onclick = ()=>{this.submitInventoryCheck()};
  1154. },
  1155. drawPopularCard: function(){
  1156. let thisMonth = new Date();
  1157. thisMonth.setDate(1);
  1158. let ingredientList = merchant.ingredientsSold(controller.transactionIndices(merchant.transactions, thisMonth));
  1159. if(ingredientList !== false){
  1160. ingredientList.sort((a, b)=>{
  1161. if(a.quantity < b.quantity){
  1162. return 1;
  1163. }
  1164. if(a.quantity > b.quantity){
  1165. return -1;
  1166. }
  1167. return 0;
  1168. });
  1169. let quantities = [];
  1170. let labels = [];
  1171. let colors = [];
  1172. let count = (ingredientList.length < 5) ? ingredientList.length - 1 : 4;
  1173. for(let i = count; i >= 0; i--){
  1174. const ingredientName = ingredientList[i].ingredient.name;
  1175. const ingredientQuantity = ingredientList[i].ingredient.convert(ingredientList[i].quantity);
  1176. const unitName = ingredientList[i].ingredient.unit;
  1177. quantities.push(ingredientList[i].quantity);
  1178. labels.push(`${ingredientName}: ${ingredientQuantity.toFixed(2)} ${unitName.toUpperCase()}`);
  1179. if(i === 0){
  1180. colors.push("rgb(255, 99, 107");
  1181. }else{
  1182. colors.push("rgb(179, 191, 209");
  1183. }
  1184. }
  1185. let trace = {
  1186. x: quantities,
  1187. type: "bar",
  1188. orientation: "h",
  1189. text: labels,
  1190. textposition: "auto",
  1191. hoverinfo: "none",
  1192. marker: {
  1193. color: colors
  1194. }
  1195. }
  1196. let layout = {
  1197. title: "MOST POPULAR INGREDIENTS",
  1198. xaxis: {
  1199. zeroline: false,
  1200. title: "QUANTITY"
  1201. },
  1202. yaxis: {
  1203. showticklabels: false
  1204. }
  1205. }
  1206. Plotly.newPlot("popularIngredientsCard", [trace], layout);
  1207. }else{
  1208. document.getElementById("popularCanvas").style.display = "none";
  1209. let notice = document.createElement("p");
  1210. notice.innerText = "N/A";
  1211. notice.classList = "notice";
  1212. document.getElementById("popularIngredientsCard").appendChild(notice);
  1213. }
  1214. },
  1215. submitInventoryCheck: function(){
  1216. let lis = document.querySelectorAll("#inventoryCheckCard li");
  1217. let changes = [];
  1218. let fetchData = [];
  1219. for(let i = 0; i < lis.length; i++){
  1220. if(lis[i].children[1].children[1].value >= 0){
  1221. let merchIngredient = lis[i].ingredient;
  1222. if(lis[i].children[1].children[1].changed === true){
  1223. let value = 0;
  1224. if(merchIngredient.ingredient.specialUnit === "bottle"){
  1225. value = parseFloat(lis[i].children[1].children[1].value) * merchIngredient.ingredient.unitSize;
  1226. }else{
  1227. value = controller.convertToMain(merchIngredient.ingredient.unit, parseFloat(lis[i].children[1].children[1].value));
  1228. }
  1229. changes.push({
  1230. ingredient: merchIngredient.ingredient,
  1231. quantity: value
  1232. });
  1233. fetchData.push({
  1234. id: merchIngredient.ingredient.id,
  1235. quantity: value
  1236. });
  1237. lis[i].children[1].children[1].changed = false;
  1238. }
  1239. }else{
  1240. banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");
  1241. return;
  1242. }
  1243. }
  1244. if(fetchData.length > 0){
  1245. let loader = document.getElementById("loaderContainer");
  1246. loader.style.display = "flex";
  1247. fetch("/merchant/ingredients/update", {
  1248. method: "PUT",
  1249. headers: {
  1250. "Content-Type": "application/json;charset=utf-8"
  1251. },
  1252. body: JSON.stringify(fetchData)
  1253. })
  1254. .then((response) => response.json())
  1255. .then((response)=>{
  1256. if(typeof(response) === "string"){
  1257. banner.createError(response);
  1258. }else{
  1259. merchant.editIngredients(changes);
  1260. banner.createNotification("INGREDIENTS UPDATED");
  1261. }
  1262. })
  1263. .catch((err)=>{})
  1264. .finally(()=>{
  1265. loader.style.display = "none";
  1266. });
  1267. }
  1268. }
  1269. }
  1270. module.exports = home;
  1271. },{}],9:[function(require,module,exports){
  1272. let ingredientDetails = {
  1273. ingredient: {},
  1274. dailyUse: 0,
  1275. display: function(ingredient){
  1276. this.ingredient = ingredient;
  1277. document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
  1278. let categoryInput = document.getElementById("detailsCategoryInput");
  1279. categoryInput.value = "";
  1280. categoryInput.placeholder = ingredient.ingredient.category;
  1281. document.getElementById("ingredientDetailsName").innerText = ingredient.ingredient.name;
  1282. let nameInput = document.getElementById("ingredientDetailsNameIn");
  1283. nameInput.value = "";
  1284. nameInput.placeholder = ingredient.ingredient.name;
  1285. //Display the stock quantity (and the edit input) based on the unit type
  1286. let stockInput = document.getElementById("ingredientInput");
  1287. let stockDisplay = document.getElementById("ingredientStock");
  1288. stockInput.value = "";
  1289. if(ingredient.ingredient.specialUnit = "bottle"){
  1290. let quantity = ingredient.ingredient.convert(ingredient.quantity);
  1291. stockDisplay.innerText = `${quantity.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1292. stockDisplay.innerText = `${(ingredient.quantity / ingredient.ingredient.unitSize).toFixed(2)} BOTTLES`;
  1293. stockInput.placeholder = quantity.toFixed(2);
  1294. }else{
  1295. stockDisplay.innerText = `${ingredient.ingredient.convert(ingredient.quantity).toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1296. stockInput.placeholder = ingredient.ingredient.convert(ingredient.quantity).toFixed(2);
  1297. }
  1298. let quantities = [];
  1299. let now = new Date();
  1300. for(let i = 1; i < 31; i++){
  1301. let endDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i)
  1302. let startDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i - 1);
  1303. let indices = controller.transactionIndices(merchant.transactions, startDay, endDay);
  1304. if(indices === false){
  1305. quantities.push(0);
  1306. }else{
  1307. quantities.push(merchant.singleIngredientSold(indices, ingredient));
  1308. }
  1309. }
  1310. let sum = 0;
  1311. for(let i = 0; i < quantities.length; i++){
  1312. sum += quantities[i];
  1313. }
  1314. let dailyUse = sum / quantities.length;
  1315. document.getElementById("dailyUse").innerText = `${ingredient.ingredient.convert(dailyUse).toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1316. let ul = document.getElementById("ingredientRecipeList");
  1317. let recipes = merchant.getRecipesForIngredient(ingredient.ingredient);
  1318. while(ul.children.length > 0){
  1319. ul.removeChild(ul.firstChild);
  1320. }
  1321. for(let i = 0; i < recipes.length; i++){
  1322. let li = document.createElement("li");
  1323. li.innerText = recipes[i].name;
  1324. li.onclick = ()=>{
  1325. controller.openStrand("recipeBook");
  1326. controller.openSidebar("recipeDetails", recipes[i]);
  1327. }
  1328. ul.appendChild(li);
  1329. }
  1330. let ingredientButtons = document.getElementById("ingredientButtons");
  1331. let units = [];
  1332. if(this.ingredient.ingredient.unitType !== "other"){
  1333. units = merchant.units[this.ingredient.ingredient.unitType];
  1334. }
  1335. while(ingredientButtons.children.length > 0){
  1336. ingredientButtons.removeChild(ingredientButtons.firstChild);
  1337. }
  1338. for(let i = 0; i < units.length; i++){
  1339. let button = document.createElement("button");
  1340. button.classList.add("unitButton");
  1341. button.innerText = units[i].toUpperCase();
  1342. button.onclick = ()=>{this.changeUnit(button, units[i])};
  1343. ingredientButtons.appendChild(button);
  1344. if(units[i] === this.ingredient.ingredient.unit){
  1345. button.classList.add("unitActive");
  1346. }
  1347. }
  1348. let add = document.querySelectorAll(".editAdd");
  1349. let remove = document.querySelectorAll(".editRemove");
  1350. for(let i = 0; i < add.length; i++){
  1351. add[i].style.display = "none";
  1352. }
  1353. for(let i = 0; i < remove.length; i++){
  1354. remove[i].style.display = "block";
  1355. }
  1356. document.getElementById("editSubmitButton").onclick = ()=>{this.editSubmit()};
  1357. document.getElementById("editCancelButton").onclick = ()=>{this.display(this.ingredient)};
  1358. document.getElementById("editIngBtn").onclick = ()=>{this.edit()};
  1359. document.getElementById("removeIngBtn").onclick = ()=>{this.remove()};
  1360. },
  1361. remove: function(){
  1362. for(let i = 0; i < merchant.recipes.length; i++){
  1363. for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
  1364. if(this.ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
  1365. banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");
  1366. return;
  1367. }
  1368. }
  1369. }
  1370. let loader = document.getElementById("loaderContainer");
  1371. loader.style.display = "flex";
  1372. fetch(`/ingredients/remove/${this.ingredient.ingredient.id}`, {
  1373. method: "DELETE",
  1374. })
  1375. .then((response) => response.json())
  1376. .then((response)=>{
  1377. if(typeof(response) === "string"){
  1378. banner.createError(response);
  1379. }else{
  1380. banner.createNotification("INGREDIENT REMOVED");
  1381. merchant.editIngredients([this.ingredient], true);
  1382. }
  1383. })
  1384. .catch((err)=>{})
  1385. .finally(()=>{
  1386. loader.style.display = "none";
  1387. });
  1388. },
  1389. edit: function(){
  1390. let add = document.querySelectorAll(".editAdd");
  1391. let remove = document.querySelectorAll(".editRemove");
  1392. for(let i = 0; i < add.length; i++){
  1393. add[i].style.display = "flex";
  1394. }
  1395. for(let i = 0; i < remove.length; i++){
  1396. remove[i].style.display = "none";
  1397. }
  1398. },
  1399. editSubmit: function(){
  1400. //Update the ingredient unit depending on the type of unit
  1401. let ingredientButtons = document.querySelectorAll(".unitButton");
  1402. for(let i = 0; i < ingredientButtons.length; i++){
  1403. if(ingredientButtons[i].classList.contains("unitActive")){
  1404. const unit = ingredientButtons[i].innerText.toLowerCase();
  1405. this.ingredient.ingredient.unit = unit;
  1406. break;
  1407. }
  1408. }
  1409. //Update the ingredient quantity depending on the type of unit
  1410. const quantityElem = document.getElementById("ingredientInput");
  1411. if(quantityElem.value !== ""){
  1412. if(this.ingredient.ingredient.specialUnit === "bottle"){
  1413. let quantInMain = controller.convertToMain(
  1414. this.ingredient.ingredient.unit,
  1415. quantityElem.value * this.ingredient.ingredient.unitSize
  1416. );
  1417. this.ingredient.quantity = quantInMain / this.ingredient.ingredient.unitSize;
  1418. }else{
  1419. this.ingredient.quantity = controller.convertToMain(
  1420. this.ingredient.ingredient.unit,
  1421. Number(quantityElem.value)
  1422. );
  1423. }
  1424. }
  1425. const category = document.getElementById("detailsCategoryInput");
  1426. this.ingredient.ingredient.category = (category.value === "") ? this.ingredient.ingredient.category : category.value;
  1427. const name = document.getElementById("ingredientDetailsNameIn");
  1428. this.ingredient.ingredient.name = (name.value === "") ? this.ingredient.ingredient.name : name.value;
  1429. let data = {
  1430. id: this.ingredient.ingredient.id,
  1431. name: this.ingredient.ingredient.name,
  1432. quantity: this.ingredient.quantity,
  1433. category: this.ingredient.ingredient.category,
  1434. defaultUnit: this.ingredient.ingredient.unit
  1435. };
  1436. let loader = document.getElementById("loaderContainer");
  1437. loader.style.display = "flex";
  1438. fetch("/ingredients/update", {
  1439. method: "PUT",
  1440. headers: {
  1441. "Content-Type": "application/json;charset=utf-8"
  1442. },
  1443. body: JSON.stringify(data)
  1444. })
  1445. .then((response) => response.json())
  1446. .then((response)=>{
  1447. if(typeof(response) === "string"){
  1448. banner.createError(response);
  1449. }else{
  1450. merchant.editIngredients([this.ingredient]);
  1451. this.display(this.ingredient);
  1452. banner.createNotification("INGREDIENT UPDATED");
  1453. }
  1454. })
  1455. .catch((err)=>{
  1456. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1457. })
  1458. .finally(()=>{
  1459. loader.style.display = "none";
  1460. });
  1461. },
  1462. changeUnit: function(newActive, unit){
  1463. let ingredientButtons = document.querySelectorAll(".unitButton");
  1464. for(let i = 0; i < ingredientButtons.length; i++){
  1465. ingredientButtons[i].classList.remove("unitActive");
  1466. }
  1467. newActive.classList.add("unitActive");
  1468. },
  1469. changeUnitDefault: function(){
  1470. let loader = document.getElementById("loaderContainer");
  1471. loader.style.display = "flex";
  1472. let id = this.ingredient.ingredient.id;
  1473. let unit = this.ingredient.ingredient.unit;
  1474. fetch(`/merchant/ingredients/update/${id}/${unit}`, {
  1475. method: "put",
  1476. headers: {
  1477. "Content-Type": "application/json;charset=utf-8"
  1478. },
  1479. })
  1480. .then((response)=>{
  1481. if(typeof(response) === "string"){
  1482. banner.createError(response);
  1483. }else{
  1484. banner.createNotification("INGREDIENT DEFAULT UNIT UPDATED");
  1485. }
  1486. })
  1487. .catch((err)=>{
  1488. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1489. })
  1490. .finally(()=>{
  1491. loader.style.display = "none";
  1492. });
  1493. }
  1494. }
  1495. module.exports = ingredientDetails;
  1496. },{}],10:[function(require,module,exports){
  1497. let ingredients = {
  1498. isPopulated: false,
  1499. ingredients: [],
  1500. display: function(){
  1501. if(!this.isPopulated){
  1502. this.populateByProperty("category");
  1503. document.getElementById("ingredientSearch").oninput = ()=>{this.search()};
  1504. document.getElementById("ingredientClearButton").onclick = ()=>{this.clearSorting()};
  1505. document.getElementById("ingredientSelect").onchange = ()=>{this.sort()};
  1506. this.isPopulated = true;
  1507. }
  1508. },
  1509. populateByProperty: function(property){
  1510. let categories;
  1511. if(property === "category"){
  1512. categories = merchant.categorizeIngredients();
  1513. }else if(property === "unit"){
  1514. categories = merchant.unitizeIngredients();
  1515. }
  1516. let ingredientStrand = document.getElementById("categoryList");
  1517. let categoryTemplate = document.getElementById("categoryDiv").content.children[0];
  1518. let ingredientTemplate = document.getElementById("ingredient").content.children[0];
  1519. this.ingredients = [];
  1520. while(ingredientStrand.children.length > 0){
  1521. ingredientStrand.removeChild(ingredientStrand.firstChild);
  1522. }
  1523. for(let i = 0; i < categories.length; i++){
  1524. let categoryDiv = categoryTemplate.cloneNode(true);
  1525. categoryDiv.children[0].children[0].innerText = categories[i].name;
  1526. categoryDiv.children[0].children[1].onclick = ()=>{
  1527. this.toggleCategory(categoryDiv.children[1], categoryDiv.children[0].children[1]);
  1528. };
  1529. categoryDiv.children[1].style.display = "none";
  1530. ingredientStrand.appendChild(categoryDiv);
  1531. for(let j = 0; j < categories[i].ingredients.length; j++){
  1532. let ingredient = categories[i].ingredients[j];
  1533. let ingredientDiv = ingredientTemplate.cloneNode(true);
  1534. ingredientDiv.children[0].innerText = ingredient.ingredient.name;
  1535. ingredientDiv.onclick = ()=>{controller.openSidebar("ingredientDetails", ingredient)};
  1536. ingredientDiv._name = ingredient.ingredient.name.toLowerCase();
  1537. ingredientDiv._unit = ingredient.ingredient.unit.toLowerCase();
  1538. if(ingredient.ingredient.specialUnit === "bottle"){
  1539. ingredientDiv.children[2].innerText = `${(ingredient.quantity / ingredient.ingredient.unitSize).toFixed(2)} BOTTLES`
  1540. }else{
  1541. ingredientDiv.children[2].innerText = `${ingredient.ingredient.convert(ingredient.quantity).toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1542. }
  1543. categoryDiv.children[1].appendChild(ingredientDiv);
  1544. this.ingredients.push(ingredientDiv);
  1545. }
  1546. }
  1547. },
  1548. displayIngredientsOnly: function(ingredients){
  1549. let ingredientDiv = document.getElementById("categoryList");
  1550. while(ingredientDiv.children.length > 0){
  1551. ingredientDiv.removeChild(ingredientDiv.firstChild);
  1552. }
  1553. for(let i = 0; i < ingredients.length; i++){
  1554. ingredientDiv.appendChild(ingredients[i]);
  1555. }
  1556. },
  1557. toggleCategory: function(div, button){
  1558. if(div.style.display === "none"){
  1559. 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>';
  1560. div.style.display = "flex";
  1561. }else if(div.style.display === "flex"){
  1562. 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>';
  1563. div.style.display = "none";
  1564. }
  1565. },
  1566. search: function(){
  1567. let input = document.getElementById("ingredientSearch").value.toLowerCase();
  1568. document.getElementById("ingredientSelect").selectedIndex = 0;
  1569. if(input === ""){
  1570. this.populateByProperty("category");
  1571. document.getElementById("ingredientClearButton").style.display = "none";
  1572. return;
  1573. }
  1574. let matchingIngredients = [];
  1575. for(let i = 0; i < this.ingredients.length; i++){
  1576. if(this.ingredients[i]._name.includes(input)){
  1577. matchingIngredients.push(this.ingredients[i]);
  1578. }
  1579. }
  1580. document.getElementById("ingredientClearButton").style.display = "inline";
  1581. this.displayIngredientsOnly(matchingIngredients);
  1582. },
  1583. sort: function(){
  1584. let sortType = document.getElementById("ingredientSelect").value;
  1585. if(sortType === ""){
  1586. return;
  1587. }
  1588. document.getElementById("ingredientSearch").value = "";
  1589. if(sortType === "category"){
  1590. this.populateByProperty("category");
  1591. return;
  1592. }
  1593. if(sortType === "unit"){
  1594. this.populateByProperty("unit");
  1595. return;
  1596. }
  1597. document.getElementById("ingredientClearButton").style.display = "inline";
  1598. let sortedIngredients = this.ingredients.slice().sort((a, b)=> (a[sortType] > b[sortType]) ? 1 : -1);
  1599. this.displayIngredientsOnly(sortedIngredients);
  1600. },
  1601. clearSorting: function(button){
  1602. document.getElementById("ingredientSearch").value = "";
  1603. document.getElementById("ingredientSelect").selectedIndex = 0;
  1604. document.getElementById("ingredientClearButton").style.display = "none";
  1605. this.populateByProperty("category");
  1606. }
  1607. }
  1608. module.exports = ingredients;
  1609. },{}],11:[function(require,module,exports){
  1610. let newIngredient = {
  1611. display: function(Ingredient){
  1612. const selector = document.getElementById("unitSelector");
  1613. document.getElementById("newIngName").value = "";
  1614. document.getElementById("newIngCategory").value = "";
  1615. document.getElementById("newIngQuantity").value = 0;
  1616. document.getElementById("bottleSizeLabel").style.display = "none";
  1617. selector.value = "g";
  1618. selector.onchange = ()=>{this.unitChange()};
  1619. document.getElementById("submitNewIng").onclick = ()=>{this.submit(Ingredient)};
  1620. },
  1621. unitChange: function(){
  1622. const select = document.getElementById("unitSelector");
  1623. const bottleLabel = document.getElementById("bottleSizeLabel");
  1624. if(select.value === "bottle"){
  1625. bottleLabel.style.display = "block";
  1626. }else{
  1627. bottleLabel.style.display = "none";
  1628. }
  1629. },
  1630. submit: function(Ingredient){
  1631. let unitSelector = document.getElementById("unitSelector");
  1632. let options = document.querySelectorAll("#unitSelector option");
  1633. const quantityValue = document.getElementById("newIngQuantity").value;
  1634. let unit = unitSelector.value;
  1635. let newIngredient = {
  1636. ingredient: {
  1637. name: document.getElementById("newIngName").value,
  1638. category: document.getElementById("newIngCategory").value,
  1639. unitType: options[unitSelector.selectedIndex].getAttribute("type"),
  1640. },
  1641. quantity: controller.convertToMain(unit, quantityValue),
  1642. defaultUnit: unit
  1643. }
  1644. //Change the ingredient if it is a special unit type (ie "bottle")
  1645. if(unit === "bottle"){
  1646. const bottleUnit = document.getElementById("bottleUnits").value;
  1647. const bottleSize = controller.convertToMain(bottleUnit, document.getElementById("bottleSize").value);
  1648. newIngredient.ingredient.unitType = "volume";
  1649. newIngredient.ingredient.unitSize = bottleSize;
  1650. newIngredient.defaultUnit = bottleUnit;
  1651. newIngredient.ingredient.specialUnit = unit;
  1652. newIngredient.quantity = quantityValue * bottleSize;
  1653. }
  1654. let loader = document.getElementById("loaderContainer");
  1655. loader.style.display = "flex";
  1656. fetch("/ingredients/create", {
  1657. method: "POST",
  1658. headers: {
  1659. "Content-Type": "application/json;charset=utf-8"
  1660. },
  1661. body: JSON.stringify(newIngredient)
  1662. })
  1663. .then((response) => response.json())
  1664. .then((response)=>{
  1665. if(typeof(response) === "string"){
  1666. banner.createError(response);
  1667. }else{
  1668. merchant.editIngredients([{
  1669. ingredient: new Ingredient(
  1670. response.ingredient._id,
  1671. response.ingredient.name,
  1672. response.ingredient.category,
  1673. response.ingredient.unitType,
  1674. response.defaultUnit,
  1675. merchant,
  1676. response.ingredient.specialUnit,
  1677. response.ingredient.unitSize
  1678. ),
  1679. quantity: response.quantity
  1680. }]);
  1681. banner.createNotification("INGREDIENT CREATED");
  1682. }
  1683. })
  1684. .catch((err)=>{
  1685. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1686. })
  1687. .finally(()=>{
  1688. loader.style.display = "none";
  1689. });
  1690. }
  1691. }
  1692. module.exports = newIngredient;
  1693. },{}],12:[function(require,module,exports){
  1694. let newOrder = {
  1695. display: function(Order){
  1696. document.getElementById("sidebarDiv").classList.add("sidebarWide");
  1697. document.getElementById("newOrderIngredientList").style.display = "flex";
  1698. let selectedList = document.getElementById("selectedIngredientList");
  1699. while(selectedList.children.length > 0){
  1700. selectedList.removeChild(selectedList.firstChild);
  1701. }
  1702. let ingredientList = document.getElementById("newOrderIngredients");
  1703. while(ingredientList.children.length > 0){
  1704. ingredientList.removeChild(ingredientList.firstChild);
  1705. }
  1706. for(let i = 0; i < merchant.ingredients.length; i++){
  1707. let ingredient = document.createElement("button");
  1708. ingredient.classList = "newOrderIngredient";
  1709. ingredient.innerText = merchant.ingredients[i].ingredient.name;
  1710. ingredient.onclick = ()=>{this.addIngredient(merchant.ingredients[i].ingredient, ingredient)};
  1711. ingredientList.appendChild(ingredient);
  1712. }
  1713. document.getElementById("submitNewOrder").onclick = ()=>{this.submit(Order)};
  1714. },
  1715. addIngredient: function(ingredient, element){
  1716. element.style.display = "none";
  1717. let div = document.getElementById("selectedIngredient").content.children[0].cloneNode(true);
  1718. div.ingredient = ingredient;
  1719. div.children[0].children[1].onclick = ()=>{this.removeIngredient(div, element)};
  1720. //Display units depending on the whether it is a special unit
  1721. if(ingredient.specialUnit === "bottle"){
  1722. div.children[0].children[0].innerText = `${ingredient.name} (BOTTLES)`;
  1723. }else{
  1724. div.children[0].children[0].innerText = `${ingredient.name} (${ingredient.unit.toUpperCase()})`;
  1725. }
  1726. document.getElementById("selectedIngredientList").appendChild(div);
  1727. },
  1728. removeIngredient: function(selectedElement, element){
  1729. selectedElement.parentElement.removeChild(selectedElement);
  1730. element.style.display = "block";
  1731. },
  1732. submit: function(Order){
  1733. let date = document.getElementById("newOrderDate").value;
  1734. let taxes = document.getElementById("orderTaxes").value * 100;
  1735. let fees = document.getElementById("orderFees").value * 100;
  1736. let ingredients = document.getElementById("selectedIngredientList").children;
  1737. if(date === ""){
  1738. banner.createError("DATE IS REQUIRED FOR ORDERS");
  1739. return;
  1740. }
  1741. let data = {
  1742. name: document.getElementById("newOrderName").value,
  1743. date: date,
  1744. taxes: taxes,
  1745. fees: fees,
  1746. ingredients: []
  1747. }
  1748. for(let i = 0; i < ingredients.length; i++){
  1749. let quantity = ingredients[i].children[1].children[0].value;
  1750. let price = ingredients[i].children[1].children[1].value;
  1751. if(quantity === "" || price === ""){
  1752. banner.createError("MUST PROVIDE QUANTITY AND PRICE PER UNIT FOR ALL INGREDIENTS");
  1753. return;
  1754. }
  1755. if(quantity < 0 || price < 0){
  1756. banner.createError("QUANTITY AND PRICE MUST BE NON-NEGATIVE NUMBERS");
  1757. }
  1758. if(ingredients[i].ingredient.specialUnit === "bottle"){
  1759. const ppu = controller.convertPrice("volume", ingredients[i].ingredient.unit, (price * 100) / (ingredients[i].ingredient.convert(ingredients[i].ingredient.unitSize)));
  1760. data.ingredients.push({
  1761. ingredient: ingredients[i].ingredient.id,
  1762. quantity: quantity * ingredients[i].ingredient.unitSize,
  1763. pricePerUnit: ppu,
  1764. });
  1765. }else{
  1766. data.ingredients.push({
  1767. ingredient: ingredients[i].ingredient.id,
  1768. quantity: controller.convertToMain(ingredients[i].ingredient.unit, quantity),
  1769. pricePerUnit: controller.convertPrice(ingredients[i].ingredient.unitType, ingredients[i].ingredient.unit, price * 100)
  1770. });
  1771. }
  1772. }
  1773. let loader = document.getElementById("loaderContainer");
  1774. loader.style.display = "flex";
  1775. fetch("/order/create", {
  1776. method: "post",
  1777. headers: {
  1778. "Content-Type": "application/json;charset=utf-8"
  1779. },
  1780. body: JSON.stringify(data)
  1781. })
  1782. .then((response)=>response.json())
  1783. .then((response)=>{
  1784. if(typeof(response) === "string"){
  1785. banner.createError(response);
  1786. }else{
  1787. let order = new Order(
  1788. response._id,
  1789. response.name,
  1790. response.date,
  1791. response.taxes,
  1792. response.fees,
  1793. response.ingredients,
  1794. merchant
  1795. );
  1796. merchant.editOrders([order]);
  1797. merchant.editIngredients(order.ingredients, false, true);
  1798. banner.createNotification("NEW ORDER CREATED");
  1799. }
  1800. })
  1801. .catch((err)=>{
  1802. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1803. })
  1804. .finally(()=>{
  1805. loader.style.display = "none";
  1806. });
  1807. }
  1808. }
  1809. module.exports = newOrder;
  1810. },{}],13:[function(require,module,exports){
  1811. let newRecipe = {
  1812. display: function(Recipe){
  1813. let ingredientsSelect = document.querySelector("#recipeInputIngredients select");
  1814. let categories = merchant.categorizeIngredients();
  1815. while(ingredientsSelect.children.length > 0){
  1816. ingredientsSelect.removeChild(ingredientsSelect.firstChild);
  1817. }
  1818. for(let i = 0; i < categories.length; i++){
  1819. let optgroup = document.createElement("optgroup");
  1820. optgroup.label = categories[i].name;
  1821. ingredientsSelect.appendChild(optgroup);
  1822. for(let j = 0; j < categories[i].ingredients.length; j++){
  1823. let option = document.createElement("option");
  1824. option.value = categories[i].ingredients[j].ingredient.id;
  1825. option.innerText = `${categories[i].ingredients[j].ingredient.name} (${categories[i].ingredients[j].ingredient.unit})`;
  1826. optgroup.appendChild(option);
  1827. }
  1828. }
  1829. document.getElementById("ingredientCount").onchange = ()=>{this.changeRecipeCount()};
  1830. document.getElementById("submitNewRecipe").onclick = ()=>{this.submit(Recipe)};
  1831. },
  1832. //Updates the number of ingredient inputs displayed for new recipes
  1833. changeRecipeCount: function(){
  1834. let newCount = document.getElementById("ingredientCount").value;
  1835. let ingredientsDiv = document.getElementById("recipeInputIngredients");
  1836. let oldCount = ingredientsDiv.children.length;
  1837. if(newCount > oldCount){
  1838. let newDivs = newCount - oldCount;
  1839. for(let i = 0; i < newDivs; i++){
  1840. let newNode = ingredientsDiv.children[0].cloneNode(true);
  1841. newNode.children[2].children[0].value = "";
  1842. ingredientsDiv.appendChild(newNode);
  1843. }
  1844. for(let i = 0; i < newCount; i++){
  1845. ingredientsDiv.children[i].children[0].innerText = `INGREDIENT ${i + 1}`;
  1846. }
  1847. }else if(newCount < oldCount){
  1848. let newDivs = oldCount - newCount;
  1849. for(let i = 0; i < newDivs; i++){
  1850. ingredientsDiv.removeChild(ingredientsDiv.children[ingredientsDiv.children.length-1]);
  1851. }
  1852. }
  1853. },
  1854. submit: function(Recipe){
  1855. let newRecipe = {
  1856. name: document.getElementById("newRecipeName").value,
  1857. price: document.getElementById("newRecipePrice").value,
  1858. ingredients: []
  1859. }
  1860. let inputs = document.querySelectorAll("#recipeInputIngredients > div");
  1861. for(let i = 0; i < inputs.length; i++){
  1862. for(let j = 0; j < merchant.ingredients.length; j++){
  1863. if(merchant.ingredients[j].ingredient.id === inputs[i].children[1].children[0].value){
  1864. newRecipe.ingredients.push({
  1865. ingredient: inputs[i].children[1].children[0].value,
  1866. quantity: controller.convertToMain(merchant.ingredients[j].ingredient.unit, inputs[i].children[2].children[0].value)
  1867. });
  1868. break;
  1869. }
  1870. }
  1871. }
  1872. let loader = document.getElementById("loaderContainer");
  1873. loader.style.display = "flex";
  1874. fetch("/recipe/create", {
  1875. method: "POST",
  1876. headers: {
  1877. "Content-Type": "application/json;charset=utf-8"
  1878. },
  1879. body: JSON.stringify(newRecipe)
  1880. })
  1881. .then((response) => response.json())
  1882. .then((response)=>{
  1883. if(typeof(response) === "string"){
  1884. banner.createError(response);
  1885. }else{
  1886. let recipe = new Recipe(
  1887. response._id,
  1888. response.name,
  1889. response.price,
  1890. response.ingredients,
  1891. merchant,
  1892. );
  1893. merchant.editRecipes([recipe]);
  1894. banner.createNotification("RECIPE CREATED");
  1895. }
  1896. })
  1897. .catch((err)=>{
  1898. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1899. })
  1900. .finally(()=>{
  1901. loader.style.display = "none";
  1902. });
  1903. },
  1904. }
  1905. module.exports = newRecipe;
  1906. },{}],14:[function(require,module,exports){
  1907. let newTransaction = {
  1908. display: function(Transaction){
  1909. let recipeList = document.getElementById("newTransactionRecipes");
  1910. let template = document.getElementById("createTransaction").content.children[0];
  1911. while(recipeList.children.length > 0){
  1912. recipeList.removeChild(recipeList.firstChild);
  1913. }
  1914. for(let i = 0; i < merchant.recipes.length; i++){
  1915. let recipeDiv = template.cloneNode(true);
  1916. recipeDiv.recipe = merchant.recipes[i];
  1917. recipeList.appendChild(recipeDiv);
  1918. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  1919. }
  1920. document.getElementById("submitNewTransaction").onclick = ()=>{this.submit(Transaction)};
  1921. },
  1922. submit: function(Transaction){
  1923. let recipeDivs = document.getElementById("newTransactionRecipes");
  1924. let date = document.getElementById("newTransactionDate").valueAsDate;
  1925. if(date > new Date()){
  1926. banner.createError("CANNOT HAVE A DATE IN THE FUTURE");
  1927. return;
  1928. }
  1929. let data = {
  1930. date: date,
  1931. recipes: [],
  1932. ingredientUpdates: {}
  1933. };
  1934. for(let i = 0; i < recipeDivs.children.length; i++){
  1935. let quantity = recipeDivs.children[i].children[1].value;
  1936. const recipe = recipeDivs.children[i].recipe;
  1937. if(quantity !== "" && quantity > 0){
  1938. data.recipes.push({
  1939. recipe: recipe.id,
  1940. quantity: quantity
  1941. });
  1942. for(let j = 0; j < recipe.ingredients.length; j++){
  1943. const ingredient = recipe.ingredients[j];
  1944. if(data.ingredientUpdates[ingredient.ingredient.id]){
  1945. data.ingredientUpdates[ingredient.ingredient.id] += ingredient.quantity * quantity;
  1946. }else{
  1947. data.ingredientUpdates[ingredient.ingredient.id] = ingredient.quantity * quantity;
  1948. }
  1949. }
  1950. }else if(quantity < 0){
  1951. banner.createError("CANNOT HAVE NEGATIVE VALUES");
  1952. return;
  1953. }
  1954. }
  1955. if(data.recipes.length > 0){
  1956. let loader = document.getElementById("loaderContainer");
  1957. loader.style.display = "flex";
  1958. fetch("/transaction/create", {
  1959. method: "post",
  1960. headers: {
  1961. "Content-Type": "application/json;charset=utf-8"
  1962. },
  1963. body: JSON.stringify(data)
  1964. })
  1965. .then(response => response.json())
  1966. .then((response)=>{
  1967. if(typeof(response) === "string"){
  1968. banner.createError(response);
  1969. }else{
  1970. let transaction = new Transaction(
  1971. response._id,
  1972. response.date,
  1973. response.recipes,
  1974. merchant
  1975. );
  1976. merchant.editTransactions(transaction, data.ingredientUpdates);
  1977. banner.createNotification("NEW TRANSACTION CREATED, INGREDIENTS UPDATED ACCORDINGLY");
  1978. }
  1979. })
  1980. .catch((err)=>{
  1981. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1982. })
  1983. .finally(()=>{
  1984. loader.style.display = "none";
  1985. });
  1986. }
  1987. }
  1988. }
  1989. module.exports = newTransaction;
  1990. },{}],15:[function(require,module,exports){
  1991. let orderDetails = {
  1992. display: function(order){
  1993. document.getElementById("removeOrderBtn").onclick = ()=>{this.remove(order)};
  1994. document.getElementById("orderDetailName").innerText = order.name;
  1995. document.getElementById("orderDetailDate").innerText = order.date.toLocaleDateString("en-US");
  1996. document.getElementById("orderDetailTax").innerText = `$${(order.taxes / 100).toFixed(2)}`;
  1997. document.getElementById("orderDetailFee").innerText = `$${(order.fees / 100).toFixed(2)}`;
  1998. let ingredientList = document.getElementById("orderIngredients");
  1999. while(ingredientList.children.length > 0){
  2000. ingredientList.removeChild(ingredientList.firstChild);
  2001. }
  2002. let template = document.getElementById("orderIngredient").content.children[0];
  2003. let grandTotal = 0;
  2004. for(let i = 0; i < order.ingredients.length; i++){
  2005. let ingredientDiv = template.cloneNode(true);
  2006. let price = order.ingredients[i].pricePerUnit * order.ingredients[i].quantity;
  2007. grandTotal += price;
  2008. const ingredient = order.ingredients[i].ingredient;
  2009. ingredientDiv.children[0].innerText = order.ingredients[i].ingredient.name;
  2010. ingredientDiv.children[2].innerText = `$${(price / 100).toFixed(2)}`;
  2011. const ingredientDisplay = ingredientDiv.children[1];
  2012. if(ingredient.specialUnit === "bottle"){
  2013. const quantSold = order.ingredients[i].quantity / ingredient.unitSize;
  2014. const ppu = (order.ingredients[i].pricePerUnit * order.ingredients[i].quantity) / quantSold;
  2015. ingredientDisplay.innerText = `${quantSold.toFixed(0)} bottles x $${(ppu / 100).toFixed(2)}`;
  2016. }else{
  2017. const convertedQuantity = ingredient.convert(order.ingredients[i].quantity);
  2018. const convertedPrice = controller.reconvertPrice(order.ingredients[i].ingredient.unitType, order.ingredients[i].ingredient.unit, order.ingredients[i].pricePerUnit);
  2019. ingredientDisplay.innerText = `${convertedQuantity.toFixed(2)} ${ingredient.unit.toUpperCase()} x $${(convertedPrice / 100).toFixed(2)}`;
  2020. }
  2021. ingredientList.appendChild(ingredientDiv);
  2022. }
  2023. document.getElementById("orderDetailTotal").innerText = `$${(grandTotal / 100).toFixed(2)}`;
  2024. document.querySelector("#orderTotalPrice p").innerText = `$${((grandTotal + order.taxes + order.fees) / 100).toFixed(2)}`;
  2025. },
  2026. remove: function(order){
  2027. let loader = document.getElementById("loaderContainer");
  2028. loader.style.display = "flex";
  2029. fetch(`/order/${order.id}`, {
  2030. method: "DELETE",
  2031. headers: {
  2032. "Content-Type": "application/json;charset=utf-8"
  2033. }
  2034. })
  2035. .then((response) => response.json())
  2036. .then((response)=>{
  2037. if(typeof(response) === "string"){
  2038. banner.createError(response);
  2039. }else{
  2040. for(let i = 0; i < order.ingredients.length; i++){
  2041. order.ingredients[i].quantity = -order.ingredients[i].quantity;
  2042. }
  2043. merchant.editOrders([order], true);
  2044. merchant.editIngredients(order.ingredients, false, true);
  2045. banner.createNotification("ORDER REMOVED");
  2046. }
  2047. })
  2048. .catch((err)=>{
  2049. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2050. })
  2051. .finally(()=>{
  2052. loader.style.display = "none";
  2053. });
  2054. }
  2055. }
  2056. module.exports = orderDetails;
  2057. },{}],16:[function(require,module,exports){
  2058. let orders = {
  2059. isFetched: false,
  2060. display: async function(Order){
  2061. if(!this.isFetched){
  2062. let loader = document.getElementById("loaderContainer");
  2063. loader.style.display = "flex";
  2064. fetch("/order", {
  2065. method: "GET",
  2066. headers: {
  2067. "Content-Type": "application/json;charset=utf-8"
  2068. },
  2069. })
  2070. .then((response) => response.json())
  2071. .then((response)=>{
  2072. if(typeof(response) === "string"){
  2073. banner.createError(response);
  2074. }else{
  2075. let newOrders = [];
  2076. for(let i = 0; i < response.length; i++){
  2077. newOrders.push(new Order(
  2078. response[i]._id,
  2079. response[i].name,
  2080. response[i].date,
  2081. response[i].taxes,
  2082. response[i].fees,
  2083. response[i].ingredients,
  2084. merchant
  2085. ));
  2086. }
  2087. merchant.editOrders(newOrders);
  2088. document.getElementById("orderSubmitForm").onsubmit = ()=>{this.submitFilter(Order)};
  2089. this.isFetched = true;
  2090. }
  2091. })
  2092. .catch((err)=>{
  2093. banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE");
  2094. })
  2095. .finally(()=>{
  2096. loader.style.display = "none";
  2097. });
  2098. }
  2099. },
  2100. populate: function(){
  2101. let listDiv = document.getElementById("orderList");
  2102. let template = document.getElementById("order").content.children[0];
  2103. let dateDropdown = document.getElementById("dateDropdownOrder");
  2104. let ingredientDropdown = document.getElementById("ingredientDropdown");
  2105. dateDropdown.style.display = "none";
  2106. ingredientDropdown.style.display = "none";
  2107. document.getElementById("dateFilterBtnOrder").onclick = ()=>{this.toggleDropdown(dateDropdown)};
  2108. document.getElementById("ingredientFilterBtn").onclick = ()=>{this.toggleDropdown(ingredientDropdown)};
  2109. for(let i = 0; i < merchant.ingredients.length; i++){
  2110. let checkbox = document.createElement("input");
  2111. checkbox.type = "checkbox";
  2112. checkbox.ingredient = merchant.ingredients[i].ingredient;
  2113. ingredientDropdown.appendChild(checkbox);
  2114. let label = document.createElement("label");
  2115. label.innerText = merchant.ingredients[i].ingredient.name;
  2116. label.for = checkbox;
  2117. ingredientDropdown.appendChild(label);
  2118. let brk = document.createElement("br");
  2119. ingredientDropdown.appendChild(brk);
  2120. }
  2121. while(listDiv.children.length > 0){
  2122. listDiv.removeChild(listDiv.firstChild);
  2123. }
  2124. for(let i = 0; i < merchant.orders.length; i++){
  2125. let row = template.cloneNode(true);
  2126. let totalCost = 0;
  2127. for(let j = 0; j < merchant.orders[i].ingredients.length; j++){
  2128. const ingredient = merchant.orders[i].ingredients[j];
  2129. totalCost += ingredient.pricePerUnit * ingredient.quantity;
  2130. }
  2131. row.children[0].innerText = merchant.orders[i].name;
  2132. row.children[1].innerText = `${merchant.orders[i].ingredients.length} ingredients`;
  2133. row.children[2].innerText = new Date(merchant.orders[i].date).toLocaleDateString("en-US");
  2134. row.children[3].innerText = `$${((totalCost / 100) + (merchant.orders[i].taxes / 100) + (merchant.orders[i].fees / 100)).toFixed(2)}`;
  2135. row.order = merchant.orders[i];
  2136. row.onclick = ()=>{controller.openSidebar("orderDetails", merchant.orders[i])};
  2137. listDiv.appendChild(row);
  2138. }
  2139. },
  2140. submitFilter: function(){
  2141. event.preventDefault();
  2142. let data = {
  2143. startDate: document.getElementById("orderFilDate1").valueAsDate,
  2144. endDate: document.getElementById("orderFilDate2").valueAsDate,
  2145. ingredients: []
  2146. }
  2147. if(data.startDate >= data.endDate){
  2148. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2149. return;
  2150. }
  2151. let ingredientChoices = document.getElementById("ingredientDropdown");
  2152. for(let i = 0; i < ingredientChoices.children.length; i += 3){
  2153. if(ingredientChoices.children[i].checked){
  2154. data.ingredients.push(ingredientChoices.children[i].ingredient.id);
  2155. }
  2156. }
  2157. if(data.ingredients.length === 0){
  2158. for(let i = 0; i < merchant.ingredients.length; i++){
  2159. data.ingredients.push(merchant.ingredients[i].ingredient.id);
  2160. }
  2161. }
  2162. let loader = document.getElementById("loaderContainer");
  2163. loader.style.display = "flex";
  2164. fetch("/order", {
  2165. method: "POST",
  2166. headers: {
  2167. "Content-Type": "application/json;charset=utf-8"
  2168. },
  2169. body: JSON.stringify(data)
  2170. })
  2171. .then((response) => response.json())
  2172. .then((response)=>{
  2173. if(typeof(response) === "string"){
  2174. banner.createError(response);
  2175. }else{
  2176. let orderList = document.getElementById("orderList");
  2177. let template = document.getElementById("order").content.children[0];
  2178. while(orderList.children.length > 0){
  2179. orderList.removeChild(orderList.firstChild);
  2180. }
  2181. for(let i = 0; i < response.length; i++){
  2182. let orderDiv = template.cloneNode(true);
  2183. let order = new Order(
  2184. response[i]._id,
  2185. response[i].name,
  2186. response[i].date,
  2187. response[i].taxes,
  2188. response[i].fees,
  2189. response[i].ingredients,
  2190. merchant
  2191. );
  2192. let cost = 0;
  2193. for(let j = 0; j < order.ingredients.length; j++){
  2194. cost += (order.ingredients[j].price / 100) * order.ingredients[j].quantity;
  2195. }
  2196. orderDiv.children[0].innerText = order.name;
  2197. orderDiv.children[1].innerText = `${order.ingredients.length} items`;
  2198. orderDiv.children[2].innerText = order.date.toLocaleDateString();
  2199. orderDiv.children[3].innerText = `$${cost.toFixed(2)}`;
  2200. orderDiv.onclick = ()=>{controller.openSidebar("orderDetails", order)};
  2201. orderList.appendChild(orderDiv);
  2202. }
  2203. }
  2204. })
  2205. .catch((err)=>{
  2206. banner.createError("UNABLE TO DISPLAY THE ORDERS");
  2207. })
  2208. .finally(()=>{
  2209. loader.style.display = "none";
  2210. });
  2211. },
  2212. toggleDropdown: function(dropdown){
  2213. event.preventDefault();
  2214. let polyline = dropdown.parentElement.children[0].children[1].children[0].children[0];
  2215. if(dropdown.style.display === "none"){
  2216. dropdown.style.display = "block";
  2217. polyline.setAttribute("points", "18 15 12 9 6 15");
  2218. }else{
  2219. dropdown.style.display = "none";
  2220. polyline.setAttribute("points", "6 9 12 15 18 9");
  2221. }
  2222. }
  2223. }
  2224. module.exports = orders;
  2225. },{}],17:[function(require,module,exports){
  2226. let recipeBook = {
  2227. isPopulated: false,
  2228. recipeDivList: [],
  2229. display: function(Recipe){
  2230. if(!this.isPopulated){
  2231. this.populateRecipes();
  2232. if(merchant.pos !== "none"){
  2233. document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate(Recipe)};
  2234. }
  2235. document.getElementById("recipeSearch").oninput = ()=>{this.search()};
  2236. document.getElementById("recipeClearButton").onclick = ()=>{this.clearSorting()};
  2237. this.isPopulated = true;
  2238. }
  2239. },
  2240. populateRecipes: function(){
  2241. let recipeList = document.getElementById("recipeList");
  2242. let template = document.getElementById("recipe").content.children[0];
  2243. this.recipeDivList = [];
  2244. while(recipeList.children.length > 0){
  2245. recipeList.removeChild(recipeList.firstChild);
  2246. }
  2247. for(let i = 0; i < merchant.recipes.length; i++){
  2248. let recipeDiv = template.cloneNode(true);
  2249. recipeDiv.onclick = ()=>{controller.openSidebar("recipeDetails", merchant.recipes[i])};
  2250. recipeDiv._name = merchant.recipes[i].name;
  2251. recipeList.appendChild(recipeDiv);
  2252. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  2253. recipeDiv.children[1].innerText = `$${(merchant.recipes[i].price / 100).toFixed(2)}`;
  2254. this.recipeDivList.push(recipeDiv);
  2255. }
  2256. },
  2257. search: function(){
  2258. let input = document.getElementById("recipeSearch").value.toLowerCase();
  2259. let recipeList = document.getElementById("recipeList");
  2260. let clearButton = document.getElementById("recipeClearButton");
  2261. let matchingRecipes = [];
  2262. for(let i = 0; i < this.recipeDivList.length; i++){
  2263. if(this.recipeDivList[i]._name.toLowerCase().includes(input)){
  2264. matchingRecipes.push(this.recipeDivList[i]);
  2265. }
  2266. }
  2267. while(recipeList.children.length > 0){
  2268. recipeList.removeChild(recipeList.firstChild);
  2269. }
  2270. for(let i = 0; i < matchingRecipes.length; i++){
  2271. recipeList.appendChild(matchingRecipes[i]);
  2272. }
  2273. if(input === ""){
  2274. clearButton.style.display = "none";
  2275. }else{
  2276. clearButton.style.display = "inline";
  2277. }
  2278. },
  2279. clearSorting: function(){
  2280. document.getElementById("recipeSearch").value = "";
  2281. this.search();
  2282. },
  2283. posUpdate: function(Recipe){
  2284. let loader = document.getElementById("loaderContainer");
  2285. loader.style.display = "flex";
  2286. let url = `/recipe/update/${merchant.pos}`;
  2287. fetch(url, {
  2288. method: "GET",
  2289. headers: {
  2290. "Content-Type": "application/json;charset=utf-8"
  2291. },
  2292. })
  2293. .then(response => response.json())
  2294. .then((response)=>{
  2295. let newRecipes = [];
  2296. for(let i = 0; i < response.new.length; i++){
  2297. newRecipes.push(new Recipe(
  2298. response.new[i]._id,
  2299. response.new[i].name,
  2300. response.new[i].price,
  2301. merchant,
  2302. []
  2303. ));
  2304. }
  2305. if(newRecipes.length > 0){
  2306. merchant.editRecipes(newRecipes);
  2307. }
  2308. let removeRecipes = [];
  2309. for(let i = 0; i < response.removed.length; i++){
  2310. for(let j = 0; j < merchant.recipes.length; j++){
  2311. if(response.removed[i]._id === merchant.recipes[j].id){
  2312. removeRecipes.push(merchant.recipes[j], true);
  2313. break;
  2314. }
  2315. }
  2316. }
  2317. if(removeRecipes.length > 0){
  2318. merchant.editRecipes(removeRecipes, true);
  2319. }
  2320. })
  2321. .catch((err)=>{
  2322. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2323. })
  2324. .finally(()=>{
  2325. loader.style.display = "none";
  2326. });
  2327. }
  2328. }
  2329. module.exports = recipeBook;
  2330. },{}],18:[function(require,module,exports){
  2331. let recipeDetails = {
  2332. recipe: {},
  2333. display: function(recipe){
  2334. this.recipe = recipe;
  2335. document.getElementById("recipeName").style.display = "block";
  2336. document.getElementById("recipeNameIn").style.display = "none";
  2337. document.querySelector("#recipeDetails h1").innerText = recipe.name;
  2338. let ingredientList = document.getElementById("recipeIngredientList");
  2339. while(ingredientList.children.length > 0){
  2340. ingredientList.removeChild(ingredientList.firstChild);
  2341. }
  2342. let template = document.getElementById("recipeIngredient").content.children[0];
  2343. for(let i = 0; i < recipe.ingredients.length; i++){
  2344. ingredientDiv = template.cloneNode(true);
  2345. ingredientDiv.children[0].innerText = recipe.ingredients[i].ingredient.name;
  2346. ingredientDiv.children[2].innerText = `${recipe.ingredients[i].ingredient.convert(recipe.ingredients[i].quantity).toFixed(2)} ${recipe.ingredients[i].ingredient.unit}`;
  2347. ingredientDiv.ingredient = recipe.ingredients[i].ingredient;
  2348. ingredientDiv.name = recipe.ingredients[i].ingredient.name;
  2349. ingredientList.appendChild(ingredientDiv);
  2350. }
  2351. document.getElementById("addRecIng").style.display = "none";
  2352. let price = document.getElementById("recipePrice");
  2353. price.children[1].style.display = "block";
  2354. price.children[2].style.display = "none";
  2355. price.children[1].innerText = `$${(recipe.price / 100).toFixed(2)}`;
  2356. document.getElementById("recipeUpdate").style.display = "none";
  2357. document.getElementById("editRecipeBtn").onclick = ()=>{this.edit()};
  2358. if(merchant.pos === "none"){
  2359. document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove()};
  2360. }
  2361. document.getElementById("addRecIng").onclick = ()=>{this.displayAddIngredient()};
  2362. document.getElementById("recipeUpdate").onclick = ()=>{this.update()};
  2363. },
  2364. edit: function(){
  2365. let ingredientDivs = document.getElementById("recipeIngredientList");
  2366. if(merchant.pos === "none"){
  2367. let name = document.getElementById("recipeName");
  2368. let nameIn = document.getElementById("recipeNameIn");
  2369. name.style.display = "none";
  2370. nameIn.style.display = "block";
  2371. nameIn.value = this.recipe.name;
  2372. let price = document.getElementById("recipePrice");
  2373. price.children[1].style.display = "none";
  2374. price.children[2].style.display = "block";
  2375. price.children[2].value = parseFloat((this.recipe.price / 100).toFixed(2));
  2376. }
  2377. for(let i = 0; i < ingredientDivs.children.length; i++){
  2378. let div = ingredientDivs.children[i];
  2379. div.children[2].innerText = this.recipe.ingredients[i].ingredient.unit;
  2380. div.children[1].style.display = "block";
  2381. div.children[1].value = this.recipe.ingredients[i].ingredient.convert(this.recipe.ingredients[i].quantity).toFixed(2);
  2382. div.children[3].style.display = "block";
  2383. div.children[3].onclick = ()=>{div.parentElement.removeChild(div)};
  2384. }
  2385. document.getElementById("addRecIng").style.display = "flex";
  2386. document.getElementById("recipeUpdate").style.display = "flex";
  2387. },
  2388. update: function(){
  2389. this.recipe.name = document.getElementById("recipeNameIn").value || this.recipe.name;
  2390. this.recipe.price = Math.round((document.getElementById("recipePrice").children[2].value * 100)) || this.recipe.price;
  2391. this.recipe.ingredients = [];
  2392. let divs = document.getElementById("recipeIngredientList").children;
  2393. for(let i = 0; i < divs.length; i++){
  2394. if(divs[i].name === "new"){
  2395. let select = divs[i].children[0];
  2396. this.recipe.ingredients.push({
  2397. ingredient: select.options[select.selectedIndex].ingredient,
  2398. quantity: controller.convertToMain(select.options[select.selectedIndex].ingredient.unit, divs[i].children[1].value)
  2399. });
  2400. }else{
  2401. this.recipe.ingredients.push({
  2402. ingredient: divs[i].ingredient,
  2403. quantity: controller.convertToMain(divs[i].ingredient.unit, divs[i].children[1].value)
  2404. });
  2405. }
  2406. }
  2407. let data = {
  2408. id: this.recipe.id,
  2409. name: this.recipe.name,
  2410. price: this.recipe.price,
  2411. ingredients: []
  2412. }
  2413. for(let i = 0; i < this.recipe.ingredients.length; i++){
  2414. data.ingredients.push({
  2415. ingredient: this.recipe.ingredients[i].ingredient.id,
  2416. quantity: this.recipe.ingredients[i].quantity
  2417. });
  2418. }
  2419. let loader = document.getElementById("loaderContainer");
  2420. loader.style.display = "flex";
  2421. fetch("/recipe/update", {
  2422. method: "PUT",
  2423. headers: {
  2424. "Content-Type": "application/json;charset=utf-8"
  2425. },
  2426. body: JSON.stringify(data)
  2427. })
  2428. .then((response) => response.json())
  2429. .then((response)=>{
  2430. if(typeof(response) === "string"){
  2431. banner.createError(response);
  2432. }else{
  2433. window.merchant.editRecipes([this.recipe]);
  2434. banner.createNotification("RECIPE UPDATE");
  2435. }
  2436. })
  2437. .catch((err)=>{
  2438. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2439. })
  2440. .finally(()=>{
  2441. loader.style.display = "none";
  2442. });
  2443. },
  2444. remove: function(){
  2445. fetch(`/merchant/recipes/remove/${this.recipe.id}`, {
  2446. method: "DELETE"
  2447. })
  2448. .then((response) => response.json())
  2449. .then((response)=>{
  2450. if(typeof(response) === "string"){
  2451. banner.createError(response);
  2452. }else{
  2453. merchant.editRecipes([this.recipe], true);
  2454. banner.createNotification("RECIPE REMOVED");
  2455. }
  2456. })
  2457. .catch((err)=>{
  2458. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2459. });
  2460. },
  2461. displayAddIngredient: function(){
  2462. let template = document.getElementById("addRecIngredient").content.children[0].cloneNode(true);
  2463. template.name = "new";
  2464. document.getElementById("recipeIngredientList").appendChild(template);
  2465. let categories = window.merchant.categorizeIngredients();
  2466. for(let i = 0; i < categories.length; i++){
  2467. let optGroup = document.createElement("optgroup");
  2468. optGroup.label = categories[i].name;
  2469. template.children[0].appendChild(optGroup);
  2470. for(let j = 0; j < categories[i].ingredients.length; j++){
  2471. let option = document.createElement("option");
  2472. option.innerText = `${categories[i].ingredients[j].ingredient.name} (${categories[i].ingredients[j].ingredient.unit})`;
  2473. option.ingredient = categories[i].ingredients[j].ingredient;
  2474. optGroup.appendChild(option);
  2475. }
  2476. }
  2477. }
  2478. }
  2479. module.exports = recipeDetails;
  2480. },{}],19:[function(require,module,exports){
  2481. let transactionDetails = {
  2482. transaction: {},
  2483. display: function(transaction){
  2484. this.transaction = transaction;
  2485. let recipeList = document.getElementById("transactionRecipes");
  2486. let template = document.getElementById("transactionRecipe").content.children[0];
  2487. let totalRecipes = 0;
  2488. let totalPrice = 0;
  2489. while(recipeList.children.length > 0){
  2490. recipeList.removeChild(recipeList.firstChild);
  2491. }
  2492. for(let i = 0; i < transaction.recipes.length; i++){
  2493. let recipe = template.cloneNode(true);
  2494. let price = transaction.recipes[i].quantity * transaction.recipes[i].recipe.price;
  2495. recipe.children[0].innerText = transaction.recipes[i].recipe.name;
  2496. recipe.children[1].innerText = `${transaction.recipes[i].quantity} x $${parseFloat(transaction.recipes[i].recipe.price / 100).toFixed(2)}`;
  2497. recipe.children[2].innerText = `$${(price / 100).toFixed(2)}`;
  2498. recipeList.appendChild(recipe);
  2499. totalRecipes += transaction.recipes[i].quantity;
  2500. totalPrice += price;
  2501. }
  2502. let months = ["January", "Fecbruary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2503. let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  2504. let dateString = `${days[transaction.date.getDay()]}, ${months[transaction.date.getMonth()]} ${transaction.date.getDate()}, ${transaction.date.getFullYear()}`;
  2505. document.getElementById("transactionDate").innerText = dateString;
  2506. document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
  2507. document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
  2508. document.getElementById("totalPrice").innerText = `$${(totalPrice / 100).toFixed(2)}`;
  2509. if(merchant.pos === "none"){
  2510. document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
  2511. }
  2512. },
  2513. remove: function(){
  2514. let loader = document.getElementById("loaderContainer");
  2515. loader.style.display = "flex";
  2516. fetch(`/transaction/${this.transaction.id}`, {
  2517. method: "delete",
  2518. headers: {
  2519. "Content-Type": "application/json;charset=utf-8"
  2520. },
  2521. })
  2522. .then(response => response.json())
  2523. .then((response)=>{
  2524. if(typeof(response) === "string"){
  2525. banner.createError(response);
  2526. }else{
  2527. let ingredients = {};
  2528. for(let i = 0; i < this.transaction.recipes.length; i++){
  2529. let recipe = this.transaction.recipes[i];
  2530. for(let j = 0; j < recipe.recipe.ingredients.length; j++){
  2531. ingredient = recipe.recipe.ingredients[j];
  2532. ingredients[ingredient.ingredient.id] = ingredient.quantity * recipe.quantity;
  2533. }
  2534. }
  2535. merchant.editTransactions(this.transaction, ingredients, true);
  2536. banner.createNotification("TRANSACTION REMOVED");
  2537. }
  2538. })
  2539. .catch((err)=>{
  2540. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2541. })
  2542. .finally(()=>{
  2543. loader.style.display = "none";
  2544. });
  2545. },
  2546. }
  2547. module.exports = transactionDetails;
  2548. },{}],20:[function(require,module,exports){
  2549. let transactions = {
  2550. isPopulated: false,
  2551. display: function(Transaction){
  2552. if(!this.isPopulated){
  2553. let transactionsList = document.getElementById("transactionsList");
  2554. let dateDropdown = document.getElementById("dateDropdown");
  2555. let recipeDropdown = document.getElementById("recipeDropDown");
  2556. let template = document.getElementById("transaction").content.children[0];
  2557. let now = new Date();
  2558. let monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
  2559. document.getElementById("transFilDate1").valueAsDate = monthAgo;
  2560. document.getElementById("transFilDate2").valueAsDate = now;
  2561. dateDropdown.style.display = "none";
  2562. recipeDropdown.style.display = "none";
  2563. document.getElementById("dateFilterBtn").onclick = ()=>{this.toggleDropdown(dateDropdown)};
  2564. document.getElementById("recipeFilterBtn").onclick = ()=>{this.toggleDropdown(recipeDropdown)};
  2565. while(recipeDropdown.children.length > 0){
  2566. recipeDropdown.removeChild(recipeDropdown.firstChild);
  2567. }
  2568. for(let i = 0; i < merchant.recipes.length; i++){
  2569. let checkbox = document.createElement("input");
  2570. checkbox.type = "checkbox";
  2571. checkbox.recipe = merchant.recipes[i];
  2572. recipeDropdown.appendChild(checkbox);
  2573. let label = document.createElement("label");
  2574. label.innerText = merchant.recipes[i].name;
  2575. label.for = checkbox;
  2576. recipeDropdown.appendChild(label);
  2577. let brk = document.createElement("br");
  2578. recipeDropdown.appendChild(brk);
  2579. }
  2580. while(transactionsList.children.length > 0){
  2581. transactionsList.removeChild(transactionsList.firstChild);
  2582. }
  2583. let i = 0
  2584. while(i < merchant.transactions.length && i < 100){
  2585. let transactionDiv = template.cloneNode(true);
  2586. let transaction = merchant.transactions[i];
  2587. transactionDiv.onclick = ()=>{controller.openSidebar("transactionDetails", transaction)};
  2588. transactionsList.appendChild(transactionDiv);
  2589. let totalRecipes = 0;
  2590. let totalPrice = 0;
  2591. for(let j = 0; j < merchant.transactions[i].recipes.length; j++){
  2592. totalRecipes += merchant.transactions[i].recipes[j].quantity;
  2593. totalPrice += merchant.transactions[i].recipes[j].recipe.price * merchant.transactions[i].recipes[j].quantity;
  2594. }
  2595. transactionDiv.children[0].innerText = `${merchant.transactions[i].date.toLocaleDateString()} ${merchant.transactions[i].date.toLocaleTimeString()}`;
  2596. transactionDiv.children[1].innerText = `${totalRecipes} recipes sold`;
  2597. transactionDiv.children[2].innerText = `$${(totalPrice / 100).toFixed(2)}`;
  2598. i++;
  2599. }
  2600. document.getElementById("transFormSubmit").onsubmit = ()=>{this.submitFilter(Transaction)};
  2601. this.isPopulated = true;
  2602. }
  2603. },
  2604. submitFilter: function(Transaction){
  2605. event.preventDefault();
  2606. let data = {
  2607. startDate: document.getElementById("transFilDate1").valueAsDate,
  2608. endDate: document.getElementById("transFilDate2").valueAsDate,
  2609. recipes: []
  2610. }
  2611. if(data.startDate >= data.endDate){
  2612. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2613. return;
  2614. }
  2615. let recipeChoices = document.getElementById("recipeDropDown");
  2616. for(let i = 0; i < recipeChoices.children.length; i += 3){
  2617. if(recipeChoices.children[i].checked){
  2618. data.recipes.push(recipeChoices.children[i].recipe.id);
  2619. }
  2620. }
  2621. if(data.recipes.length === 0){
  2622. for(let i = 0; i < merchant.recipes.length; i++){
  2623. data.recipes.push(merchant.recipes[i].id);
  2624. }
  2625. }
  2626. let loader = document.getElementById("loaderContainer");
  2627. loader.style.display = "flex";
  2628. fetch("/transaction", {
  2629. method: "POST",
  2630. headers: {
  2631. "Content-Type": "application/json;charset=utf-8"
  2632. },
  2633. body: JSON.stringify(data)
  2634. })
  2635. .then((response) => response.json())
  2636. .then((response)=>{
  2637. if(typeof(response) === "string"){
  2638. banner.createError(response);
  2639. }else{
  2640. let transactionList = document.getElementById("transactionsList");
  2641. let template = document.getElementById("transaction").content.children[0];
  2642. while(transactionList.children.length > 0){
  2643. transactionList.removeChild(transactionList.firstChild);
  2644. }
  2645. for(let i = 0; i < response.length; i++){
  2646. let transactionDiv = template.cloneNode(true);
  2647. let recipeCount = 0;
  2648. let cost = 0;
  2649. let transaction = new Transaction(
  2650. response[i]._id,
  2651. response[i].date,
  2652. response[i].recipes,
  2653. merchant
  2654. );
  2655. for(let j = 0; j < transaction.recipes.length; j++){
  2656. recipeCount += transaction.recipes[j].quantity;
  2657. cost += transaction.recipes[j].quantity * transaction.recipes[j].recipe.price;
  2658. }
  2659. transactionDiv.children[0].innerText = `${transaction.date.toLocaleDateString()} ${transaction.date.toLocaleTimeString()}`;
  2660. transactionDiv.children[1].innerText = `${recipeCount} recipes sold`;
  2661. transactionDiv.children[2].innerText = `$${(cost / 100).toFixed(2)}`;
  2662. transactionDiv.onclick = ()=>{controller.openSidebar("transactionDetails", transaction)};
  2663. transactionList.appendChild(transactionDiv);
  2664. }
  2665. }
  2666. })
  2667. .catch((err)=>{
  2668. banner.createError("UNABLE TO DISPLAY THE TRANSACTIONS");
  2669. })
  2670. .finally(()=>{
  2671. loader.style.display = "none";
  2672. });
  2673. },
  2674. toggleDropdown: function(dropdown){
  2675. event.preventDefault();
  2676. let polyline = dropdown.parentElement.children[0].children[1].children[0].children[0];
  2677. if(dropdown.style.display === "none"){
  2678. dropdown.style.display = "block";
  2679. polyline.setAttribute("points", "18 15 12 9 6 15");
  2680. }else{
  2681. dropdown.style.display = "none";
  2682. polyline.setAttribute("points", "6 9 12 15 18 9");
  2683. }
  2684. }
  2685. }
  2686. module.exports = transactions;
  2687. },{}]},{},[7]);