bundle.js 134 KB

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