bundle.js 134 KB

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