bundle.js 130 KB

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