bundle.js 115 KB

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