bundle.js 137 KB

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