bundle.js 139 KB

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