bundle.js 130 KB

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