bundle.js 139 KB

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