bundle.js 137 KB

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