bundle.js 131 KB

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