bundle.js 137 KB

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