bundle.js 136 KB

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