bundle.js 134 KB

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