bundle.js 139 KB

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