bundle.js 132 KB

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