bundle.js 128 KB

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