bundle.js 132 KB

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