bundle.js 141 KB

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