bundle.js 111 KB

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