bundle.js 134 KB

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