bundle.js 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. class Ingredient{
  3. constructor(id, name, category, unitType, unit, parent, specialUnit = undefined, unitSize = undefined){
  4. if(!this.isSanitaryString(name)){
  5. banner.createError("NAME CONTAINS ILLEGAL CHARCTERS");
  6. return false;
  7. }
  8. if(!this.isSanitaryString(category)){
  9. banner.createError("CATEGORY CONTAINS ILLEGAL CHARACTERS");
  10. return false;
  11. }
  12. this._id = id;
  13. this._name = name;
  14. this._category = category;
  15. this._unitType = unitType;
  16. this._unit = unit;
  17. this._parent = parent;
  18. if(specialUnit){
  19. this._specialUnit = specialUnit;
  20. this._unitSize = unitSize;
  21. }
  22. }
  23. get id(){
  24. return this._id;
  25. }
  26. get name(){
  27. return this._name;
  28. }
  29. set name(name){
  30. if(!this.isSanitaryString(name)){
  31. return false;
  32. }
  33. this._name = name;
  34. }
  35. get category(){
  36. return this._category;
  37. }
  38. set category(category){
  39. if(!this.isSanitaryString(category)){
  40. return false;
  41. }
  42. this._category = category;
  43. }
  44. get unitType(){
  45. return this._unitType;
  46. }
  47. get unit(){
  48. return this._unit;
  49. }
  50. set unit(unit){
  51. this._unit = unit;
  52. }
  53. get parent(){
  54. return this._parent;
  55. }
  56. get specialUnit(){
  57. return this._specialUnit;
  58. }
  59. get unitSize(){
  60. switch(this._unit){
  61. case "g":return this._unitSize;
  62. case "kg": return this._unitSize / 1000;
  63. case "oz": return this._unitSize / 28.3495;
  64. case "lb": return this._unitSize / 453.5924;
  65. case "ml": return this._unitSize * 1000;
  66. case "l": return this._unitSize;
  67. case "tsp": return this._unitSize * 202.8842;
  68. case "tbsp": return this._unitSize * 67.6278;
  69. case "ozfl": return this._unitSize * 33.8141;
  70. case "cup": return this._unitSize * 4.1667;
  71. case "pt": return this._unitSize * 2.1134;
  72. case "qt": return this._unitSize * 1.0567;
  73. case "gal": return this._unitSize / 3.7854;
  74. case "mm": return this._unitSize * 1000;
  75. case "cm": return this._unitSize * 100;
  76. case "m": return this._unitSize;
  77. case "in": return this._unitSize * 39.3701;
  78. case "ft": return this._unitSize * 3.2808;
  79. default: return this._unitSize;
  80. }
  81. }
  82. set unitSize(unitSize){
  83. if(unitSize < 0){
  84. return false;
  85. }
  86. this._unitSize = unitSize;
  87. }
  88. getNameAndUnit(){
  89. if(this._specialUnit === "bottle"){
  90. return `${this._name} (BOTTLES)`;
  91. }
  92. return `${this._name} (${this._unit.toUpperCase()})`;
  93. }
  94. isSanitaryString(str){
  95. let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
  96. for(let i = 0; i < disallowed.length; i++){
  97. if(str.includes(disallowed[i])){
  98. return false;
  99. }
  100. }
  101. return true;
  102. }
  103. }
  104. module.exports = Ingredient;
  105. },{}],2:[function(require,module,exports){
  106. 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. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  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. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  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. banner.createError("PRICE CANNOT BE A NEGATIVE NUMBER");
  960. return false;
  961. }
  962. if(!this.isSanitaryString(name)){
  963. banner.createError("NAME CONTAINS ILLEGAL CHARACTERS");
  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. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  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. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  1036. return false;
  1037. }
  1038. if(quantity % 1 !== 0){
  1039. banner.createError("RECIPES WITHIN A TRANSACTION MUST BE WHOLE NUMBERS");
  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. banner.createError("DATE CANNOT BE SET TO THE FUTURE");
  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 recipeDetails = require("./sidebars/recipeDetails.js");
  1122. const transactionDetails = require("./sidebars/transactionDetails.js");
  1123. const transactionFilter = require("./sidebars/transactionFilter.js");
  1124. const Merchant = require("./classes/Merchant.js");
  1125. const Ingredient = require("./classes/Ingredient.js");
  1126. const Recipe = require("./classes/Recipe.js");
  1127. const Order = require("./classes/Order.js");
  1128. const Transaction = require("./classes/Transaction.js");
  1129. merchant = new Merchant(data.merchant, data.transactions, {
  1130. home: home,
  1131. ingredients: ingredients,
  1132. transactions: transactions,
  1133. recipeBook: recipeBook,
  1134. analytics: analytics,
  1135. orders: orders,
  1136. Ingredient: Ingredient,
  1137. Recipe: Recipe,
  1138. Transaction: Transaction
  1139. });
  1140. controller = {
  1141. openStrand: function(strand, data = undefined){
  1142. this.closeSidebar();
  1143. let strands = document.querySelectorAll(".strand");
  1144. for(let i = 0; i < strands.length; i++){
  1145. strands[i].style.display = "none";
  1146. }
  1147. let buttons = document.querySelectorAll(".menuButton");
  1148. for(let i = 0; i < buttons.length - 1; i++){
  1149. buttons[i].classList = "menuButton";
  1150. buttons[i].disabled = false;
  1151. }
  1152. let activeButton = {};
  1153. switch(strand){
  1154. case "home":
  1155. activeButton = document.getElementById("homeBtn");
  1156. document.getElementById("homeStrand").style.display = "flex";
  1157. home.display();
  1158. break;
  1159. case "ingredients":
  1160. activeButton = document.getElementById("ingredientsBtn");
  1161. document.getElementById("ingredientsStrand").style.display = "flex";
  1162. ingredients.display();
  1163. break;
  1164. case "recipeBook":
  1165. activeButton = document.getElementById("recipeBookBtn");
  1166. document.getElementById("recipeBookStrand").style.display = "flex";
  1167. recipeBook.display(Recipe);
  1168. break;
  1169. case "analytics":
  1170. activeButton = document.getElementById("analyticsBtn");
  1171. document.getElementById("analyticsStrand").style.display = "flex";
  1172. analytics.display(Transaction);
  1173. break;
  1174. case "orders":
  1175. activeButton = document.getElementById("ordersBtn");
  1176. document.getElementById("ordersStrand").style.display = "flex";
  1177. orders.orders = data;
  1178. orders.display(Order);
  1179. break;
  1180. case "transactions":
  1181. activeButton = document.getElementById("transactionsBtn");
  1182. document.getElementById("transactionsStrand").style.display = "flex";
  1183. transactions.transactions = data;
  1184. transactions.display(Transaction);
  1185. break;
  1186. }
  1187. activeButton.classList = "menuButton active";
  1188. activeButton.disabled = true;
  1189. if(window.screen.availWidth <= 1000){
  1190. this.closeMenu();
  1191. }
  1192. },
  1193. /*
  1194. Open a specific sidebar
  1195. Input:
  1196. sidebar: the outermost element of the sidebar (must contain class sidebar)
  1197. */
  1198. openSidebar: function(sidebar, data = {}){
  1199. this.closeSidebar();
  1200. document.getElementById("sidebarDiv").classList = "sidebar";
  1201. document.getElementById(sidebar).style.display = "flex";
  1202. switch(sidebar){
  1203. case "ingredientDetails":
  1204. ingredientDetails.display(data, ingredients);
  1205. break;
  1206. case "newIngredient":
  1207. newIngredient.display(Ingredient);
  1208. break;
  1209. case "editIngredient":
  1210. editIngredient.display(data);
  1211. break;
  1212. case "recipeDetails":
  1213. recipeDetails.display(data);
  1214. break;
  1215. case "editRecipe":
  1216. editRecipe.display(data);
  1217. break;
  1218. case "addRecipe":
  1219. newRecipe.display(Recipe);
  1220. break;
  1221. case "orderDetails":
  1222. orderDetails.display(data);
  1223. break;
  1224. case "orderFilter":
  1225. orderFilter.display(Order);
  1226. break;
  1227. case "newOrder":
  1228. newOrder.display(Order);
  1229. break;
  1230. case "transactionDetails":
  1231. transactionDetails.display(data);
  1232. break;
  1233. case "transactionFilter":
  1234. transactionFilter.display();
  1235. break;
  1236. case "newTransaction":
  1237. newTransaction.display(Transaction);
  1238. break;
  1239. }
  1240. if(window.screen.availWidth <= 1000){
  1241. document.querySelector(".contentBlock").style.display = "none";
  1242. document.getElementById("mobileMenuSelector").style.display = "none";
  1243. document.getElementById("sidebarCloser").style.display = "block";
  1244. }
  1245. },
  1246. closeSidebar: function(){
  1247. let sidebar = document.getElementById("sidebarDiv");
  1248. for(let i = 0; i < sidebar.children.length; i++){
  1249. if(sidebar.children[i].style.display !== "none"){
  1250. sidebar.children[i].style.display = "none";
  1251. let choosables = [];
  1252. switch(sidebar.children[i].id){
  1253. case "ingredientDetails":
  1254. choosables = document.querySelectorAll(".ingredient");
  1255. break;
  1256. case "transactionDetails":
  1257. choosables = document.getElementById("transactionsList").children;
  1258. break;
  1259. case "recipeDetails":
  1260. choosables = document.getElementById("recipeList").children;
  1261. break;
  1262. case "orderDetails":
  1263. choosables = document.getElementById("orderList").children;
  1264. break;
  1265. }
  1266. for(let i = 0; i < choosables.length; i++){
  1267. choosables[i].classList.remove("active");
  1268. }
  1269. }
  1270. }
  1271. sidebar.classList = "sidebarHide";
  1272. if(window.screen.availWidth <= 1000){
  1273. document.querySelector(".contentBlock").style.display = "flex";
  1274. document.getElementById("mobileMenuSelector").style.display = "block";
  1275. document.getElementById("sidebarCloser").style.display = "none";
  1276. }
  1277. },
  1278. openModal: function(str){
  1279. let modal = document.getElementById("modal");
  1280. modal.style.display = "flex";
  1281. document.getElementById("modalClose").addEventListener("click", this.closeModal);
  1282. let content = {};
  1283. switch(str){
  1284. case "ingredientSpreadsheet":
  1285. content = document.getElementById("modalSpreadsheetUpload");
  1286. content.style.display = "flex";
  1287. document.getElementById("modalSpreadsheetTitle").innerText = "ingredients";
  1288. document.getElementById("spreadsheetDownload").href = "/ingredients/download/spreadsheet";
  1289. content.onsubmit = newIngredient.submitSpreadsheet;
  1290. break;
  1291. case "recipeSpreadsheet":
  1292. content = document.getElementById("modalSpreadsheetUpload");
  1293. content.style.display = "flex";
  1294. document.getElementById("modalSpreadsheetTitle").innerText = "recipes";
  1295. document.getElementById("spreadsheetDownload").href = "/recipes/download/spreadsheet";
  1296. content.onsubmit = newRecipe.submitSpreadsheet;
  1297. break;
  1298. case "orderSpreadsheet":
  1299. content = document.getElementById("modalSpreadsheetUpload");
  1300. content.style.display = "flex";
  1301. document.getElementById("modalSpreadsheetTitle").innerText = "orders";
  1302. document.getElementById("spreadsheetDownload").href = "/orders/download/spreadsheet";
  1303. content.onsubmit = newOrder.submitSpreadsheet;
  1304. break;
  1305. case "transactionSpreadsheet":
  1306. content = document.getElementById("modalSpreadsheetUpload");
  1307. content.style.display = "flex";
  1308. document.getElementById("modalSpreadsheetTitle").innerText = "transactions";
  1309. document.getElementById("spreadsheetDownload").href = "/transactions/download/spreadsheet";
  1310. content.onsubmit = newTransaction.submitSpreadsheet;
  1311. }
  1312. },
  1313. closeModal: function(){
  1314. let modal = document.getElementById("modal");
  1315. let modalContent = document.getElementById("modalContent");
  1316. for(let i = 0; i < modalContent.children.length; i++){
  1317. modalContent.children[i].style.display = "none";
  1318. }
  1319. modal.style.display = "none";
  1320. },
  1321. changeMenu: function(){
  1322. let menu = document.querySelector(".menu");
  1323. let buttons = document.querySelectorAll(".menuButton");
  1324. if(!menu.classList.contains("menuMinimized")){
  1325. menu.classList = "menu menuMinimized";
  1326. for(let i = 0; i < buttons.length; i++){
  1327. buttons[i].children[1].style.display = "none";
  1328. }
  1329. document.getElementById("max").style.display = "none";
  1330. document.getElementById("min").style.display = "flex";
  1331. }else if(menu.classList.contains("menuMinimized")){
  1332. menu.classList = "menu";
  1333. for(let i = 0; i < buttons.length; i++){
  1334. buttons[i].children[1].style.display = "block";
  1335. }
  1336. setTimeout(()=>{
  1337. document.getElementById("max").style.display = "flex";
  1338. document.getElementById("min").style.display = "none";
  1339. }, 150);
  1340. }
  1341. },
  1342. openMenu: function(){
  1343. document.getElementById("menu").style.display = "flex";
  1344. document.querySelector(".contentBlock").style.display = "none";
  1345. document.getElementById("mobileMenuSelector").onclick = ()=>{this.closeMenu()};
  1346. },
  1347. closeMenu: function(){
  1348. document.getElementById("menu").style.display = "none";
  1349. document.querySelector(".contentBlock").style.display = "flex";
  1350. document.getElementById("mobileMenuSelector").onclick = ()=>{this.openMenu()};
  1351. },
  1352. /*
  1353. Converts the price of unit back to the price per default unit
  1354. unitType = type of the unit (i.e. mass, volume)
  1355. unit = exact unit to convert to
  1356. price = price of the ingredient per unit in cents
  1357. */
  1358. reconvertPrice(unitType, unit, price){
  1359. if(unitType === "mass"){
  1360. switch(unit){
  1361. case "g": break;
  1362. case "kg": price *= 1000; break;
  1363. case "oz": price *= 28.3495; break;
  1364. case "lb": price *= 453.5924; break;
  1365. }
  1366. }else if(unitType === "volume"){
  1367. switch(unit){
  1368. case "ml": price /= 1000; break;
  1369. case "l": break;
  1370. case "tsp": price /= 202.8842; break;
  1371. case "tbsp": price /= 67.6278; break;
  1372. case "ozfl": price /= 33.8141; break;
  1373. case "cup": price /= 4.1667; break;
  1374. case "pt": price /= 2.1134; break;
  1375. case "qt": price /= 1.0567; break;
  1376. case "gal": price *= 3.7854; break;
  1377. }
  1378. }else if(unitType === "length"){
  1379. switch(unit){
  1380. case "mm": price /= 1000; break;
  1381. case "cm": price /= 100; break;
  1382. case "m": break;
  1383. case "in": price /= 39.3701; break;
  1384. case "ft": price /= 3.2808; break;
  1385. }
  1386. }
  1387. return price;
  1388. }
  1389. }
  1390. if(window.screen.availWidth > 1000 && window.screen.availWidth <= 1400){
  1391. this.changeMenu();
  1392. document.getElementById("menuShifter2").style.display = "none";
  1393. }
  1394. //Add click listeners for menu buttons
  1395. document.getElementById("homeBtn").onclick = ()=>{controller.openStrand("home")};
  1396. document.getElementById("ingredientsBtn").onclick = ()=>{controller.openStrand("ingredients")};
  1397. document.getElementById("recipeBookBtn").onclick = ()=>{controller.openStrand("recipeBook")};
  1398. document.getElementById("analyticsBtn").onclick = ()=>{controller.openStrand("analytics")};
  1399. document.getElementById("ordersBtn").onclick = async ()=>{
  1400. if(merchant.orders.length === 0){
  1401. merchant.setOrders(await orders.getOrders(Order));
  1402. }
  1403. controller.openStrand("orders", merchant.orders);
  1404. }
  1405. document.getElementById("transactionsBtn").onclick = ()=>{controller.openStrand("transactions", merchant.getTransactions())};
  1406. controller.openStrand("home");
  1407. },{"./classes/Ingredient.js":1,"./classes/Merchant.js":2,"./classes/Order.js":3,"./classes/Recipe.js":4,"./classes/Transaction.js":5,"./sidebars/editIngredient.js":7,"./sidebars/editRecipe.js":8,"./sidebars/ingredientDetails.js":9,"./sidebars/newIngredient.js":10,"./sidebars/newOrder.js":11,"./sidebars/newRecipe.js":12,"./sidebars/newTransaction.js":13,"./sidebars/orderDetails.js":14,"./sidebars/orderFilter.js":15,"./sidebars/recipeDetails.js":16,"./sidebars/transactionDetails.js":17,"./sidebars/transactionFilter.js":18,"./strands/analytics.js":19,"./strands/home.js":20,"./strands/ingredients.js":21,"./strands/orders.js":22,"./strands/recipeBook.js":23,"./strands/transactions.js":24}],7:[function(require,module,exports){
  1408. let editIngredient = {
  1409. display: function(ingredient){
  1410. let buttonList = document.getElementById("unitButtons");
  1411. let quantLabel = document.getElementById("editIngQuantityLabel");
  1412. let specialLabel = document.getElementById("editSpecialLabel");
  1413. //Clear any existing data
  1414. while(buttonList.children.length > 0){
  1415. buttonList.removeChild(buttonList.firstChild);
  1416. }
  1417. //Populate basic fields
  1418. document.getElementById("editIngTitle").innerText = ingredient.ingredient.name;
  1419. document.getElementById("editIngName").value = ingredient.ingredient.name;
  1420. document.getElementById("editIngCategory").value = ingredient.ingredient.category;
  1421. quantLabel.innerText = `CURRENT STOCK (${ingredient.ingredient.unit.toUpperCase()})`;
  1422. document.getElementById("editIngSubmit").onclick = ()=>{this.submit(ingredient)};
  1423. //Populate the unit buttons
  1424. const units = merchant.units[ingredient.ingredient.unitType];
  1425. for(let i = 0; i < units.length; i++){
  1426. let button = document.createElement("button");
  1427. button.classList.add("unitButton");
  1428. button.innerText = units[i].toUpperCase();
  1429. button.onclick = ()=>{this.changeUnit(button)};
  1430. buttonList.appendChild(button);
  1431. if(units[i] === ingredient.ingredient.unit){
  1432. button.classList.add("unitActive");
  1433. }
  1434. }
  1435. //Make any changes for special ingredients
  1436. if(ingredient.ingredient.specialUnit === "bottle"){
  1437. quantLabel.innerText = "CURRENT STOCK (BOTTLES):";
  1438. specialLabel.style.display = "flex";
  1439. specialLabel.innerText = `BOTTLE SIZE (${ingredient.ingredient.unit.toUpperCase()}):`;
  1440. let sizeInput = document.createElement("input");
  1441. sizeInput.id = "editIngSpecialSize";
  1442. sizeInput.type = "number";
  1443. sizeInput.min = "0";
  1444. sizeInput.step = "0.01";
  1445. sizeInput.value = ingredient.ingredient.unitSize.toFixed(2);
  1446. specialLabel.appendChild(sizeInput);
  1447. }else{
  1448. specialLabel.style.display = "none";
  1449. }
  1450. let quantInput = document.createElement("input");
  1451. quantInput.id = "editIngQuantity";
  1452. quantInput.type = "number";
  1453. quantInput.min = "0";
  1454. quantInput.step = "0.01";
  1455. quantInput.value = ingredient.quantity.toFixed(2);
  1456. quantLabel.appendChild(quantInput);
  1457. },
  1458. changeUnit(button){
  1459. let buttons = document.getElementById("unitButtons");
  1460. for(let i = 0; i < buttons.children.length; i++){
  1461. buttons.children[i].classList.remove("unitActive");
  1462. }
  1463. button.classList.add("unitActive");
  1464. },
  1465. submit(ingredient){
  1466. const quantity = parseFloat(document.getElementById("editIngQuantityLabel").children[0].value);
  1467. let data = {
  1468. id: ingredient.ingredient.id,
  1469. name: document.getElementById("editIngName").value,
  1470. category: document.getElementById("editIngCategory").value
  1471. }
  1472. //Add data based on unit type
  1473. if(ingredient.ingredient.specialUnit === "bottle"){
  1474. let unitSize = ingredient.convertToBase(parseFloat(document.getElementById("editSpecialLabel").children[0].value));
  1475. data.quantity = quantity * unitSize;
  1476. data.unitSize = unitSize;
  1477. }else{
  1478. data.quantity = quantity;
  1479. }
  1480. //Get the measurement unit
  1481. let units = document.getElementById("unitButtons");
  1482. for(let i = 0; i < units.children.length; i++){
  1483. if(units.children[i].classList.contains("unitActive")){
  1484. data.unit = units.children[i].innerText.toLowerCase();
  1485. break;
  1486. }
  1487. }
  1488. let loader = document.getElementById("loaderContainer");
  1489. loader.style.display = "flex";
  1490. fetch("/ingredients/update", {
  1491. method: "put",
  1492. headers: {
  1493. "Content-Type": "application/json;charset=utf-8"
  1494. },
  1495. body: JSON.stringify(data)
  1496. })
  1497. .then(response => response.json())
  1498. .then((response)=>{
  1499. if(typeof(response) === "string"){
  1500. banner.createError(response);
  1501. }else{
  1502. merchant.removeIngredient(merchant.getIngredient(response.ingredient._id));
  1503. merchant.addIngredient(response.ingredient, response.quantity, response.unit);
  1504. controller.openStrand("ingredients");
  1505. banner.createNotification("INGREDIENT UPDATED");
  1506. }
  1507. })
  1508. .catch((err)=>{
  1509. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1510. })
  1511. .finally(()=>{
  1512. loader.style.display = "none";
  1513. });
  1514. }
  1515. }
  1516. module.exports = editIngredient;
  1517. },{}],8:[function(require,module,exports){
  1518. let editRecipe = {
  1519. display: function(recipe){
  1520. let nameInput = document.getElementById("editRecipeName");
  1521. if(merchant.pos === "none"){
  1522. nameInput.value = recipe.name;
  1523. }else{
  1524. document.getElementById("editRecipeNoName").innertext = recipe.name;
  1525. nameInput.parentNode.style.display = "none";
  1526. }
  1527. //Populate ingredients
  1528. let ingredientList = document.getElementById("editRecipeIngList");
  1529. while(ingredientList.children.length > 0){
  1530. ingredientList.removeChild(ingredientList.firstChild);
  1531. }
  1532. let template = document.getElementById("editRecipeIng").content.children[0];
  1533. for(let i = 0; i < recipe.ingredients.length; i++){
  1534. let ingredientDiv = template.cloneNode(true);
  1535. ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
  1536. ingredientDiv.children[1].innerText = recipe.ingredients[i].ingredient.getNameAndUnit();
  1537. ingredientDiv.children[2].style.display = "none";
  1538. ingredientDiv.children[3].value = recipe.ingredients[i].quantity;
  1539. ingredientDiv.ingredient = recipe.ingredients[i];
  1540. ingredientList.appendChild(ingredientDiv);
  1541. }
  1542. document.getElementById("addRecIng").onclick = ()=>{this.newIngredient()};
  1543. document.getElementById("editRecipePrice").value = recipe.price;
  1544. document.getElementById("editRecipeSubmit").onclick = ()=>{this.submit(recipe)};
  1545. document.getElementById("editRecipeCancel").onclick = ()=>{controller.openSidebar("recipeDetails", recipe)};
  1546. },
  1547. newIngredient: function(){
  1548. let ingredientList = document.getElementById("editRecipeIngList");
  1549. let ingredientDiv = document.getElementById("editRecipeIng").content.children[0].cloneNode(true);
  1550. ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
  1551. ingredientDiv.children[1].style.display = "none";
  1552. ingredientDiv.children[3].value = "0.00";
  1553. //Populate selector
  1554. let categories = merchant.categorizeIngredients();
  1555. for(let i = 0; i < categories.length; i++){
  1556. let group = document.createElement("optgroup");
  1557. group.label = categories[i].name;
  1558. for(let j = 0; j < categories[i].ingredients.length; j++){
  1559. let option = document.createElement("option");
  1560. option.innerText = categories[i].ingredients[j].ingredient.getNameAndUnit();
  1561. option.ingredient = categories[i].ingredients[j];
  1562. group.appendChild(option);
  1563. }
  1564. ingredientDiv.children[2].appendChild(group);
  1565. }
  1566. ingredientList.appendChild(ingredientDiv);
  1567. },
  1568. submit: function(recipe){
  1569. let data = {
  1570. id: recipe.id,
  1571. name: recipe.name,
  1572. price: document.getElementById("editRecipePrice").value * 100,
  1573. ingredients: []
  1574. }
  1575. if(merchant.pos === "none"){
  1576. data.name = document.getElementById("editRecipeName").value;
  1577. }
  1578. let ingredients = document.getElementById("editRecipeIngList").children;
  1579. for(let i = 0; i < ingredients.length; i++){
  1580. const quantity = parseFloat(ingredients[i].children[3].value);
  1581. if(ingredients[i].children[1].style.display === "none"){
  1582. let selector = ingredients[i].children[2];
  1583. let ingredient = selector.options[selector.selectedIndex].ingredient;
  1584. data.ingredients.push({
  1585. ingredient: ingredient.ingredient.id,
  1586. quantity: ingredient.convertToBase(quantity)
  1587. });
  1588. }else{
  1589. data.ingredients.push({
  1590. ingredient: ingredients[i].ingredient.ingredient.id,
  1591. quantity: ingredients[i].ingredient.convertToBase(quantity)
  1592. });
  1593. }
  1594. }
  1595. let loader = document.getElementById("loaderContainer");
  1596. loader.style.display = "flex";
  1597. fetch("/recipe/update", {
  1598. method: "put",
  1599. headers: {
  1600. "Content-Type": "application/json;charset=utf-8"
  1601. },
  1602. body: JSON.stringify(data)
  1603. })
  1604. .then(response => response.json())
  1605. .then((response)=>{
  1606. if(typeof(response) === "string"){
  1607. banner.createError(response);
  1608. }else{
  1609. merchant.updateRecipe(response);
  1610. controller.openStrand("recipeBook");
  1611. banner.createNotification("RECIPE UPDATED");
  1612. }
  1613. })
  1614. .catch((err)=>{
  1615. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1616. })
  1617. .finally(()=>{
  1618. loader.style.display = "none";
  1619. });
  1620. }
  1621. }
  1622. module.exports = editRecipe;
  1623. },{}],9:[function(require,module,exports){
  1624. let ingredientDetails = {
  1625. dailyUse: 0,
  1626. display: function(ingredient){
  1627. document.getElementById("editIngBtn").onclick = ()=>{controller.openSidebar("editIngredient", ingredient)};
  1628. document.getElementById("removeIngBtn").onclick = ()=>{this.remove(ingredient)};
  1629. document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
  1630. document.getElementById("ingredientDetailsName").innerText = ingredient.ingredient.name;
  1631. document.getElementById("ingredientStock").innerText = ingredient.getQuantityDisplay();
  1632. //Calculate and display average daily use
  1633. let quantities = [];
  1634. let now = new Date();
  1635. for(let i = 1; i < 31; i++){
  1636. let endDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i)
  1637. let startDay = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i - 1);
  1638. quantities.push(merchant.getSingleIngredientSold(ingredient, startDay, endDay));
  1639. }
  1640. let sum = 0;
  1641. for(let i = 0; i < quantities.length; i++){
  1642. sum += quantities[i];
  1643. }
  1644. let dailyUse = sum / quantities.length;
  1645. const dailyUseDiv = document.getElementById("dailyUse");
  1646. if(ingredient.ingredient.specialUnit === "bottle"){
  1647. dailyUseDiv.innerText = `${dailyUse.toFixed(2)} BOTTLES`;
  1648. }else{
  1649. dailyUseDiv.innerText = `${dailyUse.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  1650. }
  1651. //Show recipes that this ingredient is a part of
  1652. let recipeList = document.getElementById("ingredientRecipeList");
  1653. let template = document.getElementById("ingredientRecipe").content.children[0];
  1654. let recipes = merchant.getRecipesForIngredient(ingredient.ingredient);
  1655. while(recipeList.children.length > 0){
  1656. recipeList.removeChild(recipeList.firstChild);
  1657. }
  1658. for(let i = 0; i < recipes.length; i++){
  1659. let recipeDiv = template.cloneNode(true);
  1660. recipeDiv.children[0].innerText = recipes[i].name;
  1661. recipeDiv.onclick = ()=>{
  1662. controller.openStrand("recipeBook");
  1663. controller.openSidebar("recipeDetails", recipes[i]);
  1664. }
  1665. recipeDiv.classList.add("choosable");
  1666. recipeList.appendChild(recipeDiv);
  1667. }
  1668. },
  1669. remove: function(ingredient){
  1670. for(let i = 0; i < merchant.recipes.length; i++){
  1671. for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
  1672. if(ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
  1673. banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");
  1674. return;
  1675. }
  1676. }
  1677. }
  1678. let loader = document.getElementById("loaderContainer");
  1679. loader.style.display = "flex";
  1680. fetch(`/ingredients/remove/${ingredient.ingredient.id}`, {
  1681. method: "delete",
  1682. })
  1683. .then((response) => response.json())
  1684. .then((response)=>{
  1685. if(typeof(response) === "string"){
  1686. banner.createError(response);
  1687. }else{
  1688. merchant.removeIngredient(ingredient);
  1689. controller.openStrand("ingredients");
  1690. banner.createNotification("INGREDIENT REMOVED");
  1691. }
  1692. })
  1693. .catch((err)=>{})
  1694. .finally(()=>{
  1695. loader.style.display = "none";
  1696. });
  1697. }
  1698. }
  1699. module.exports = ingredientDetails;
  1700. },{}],10:[function(require,module,exports){
  1701. let newIngredient = {
  1702. display: function(Ingredient){
  1703. const selector = document.getElementById("unitSelector");
  1704. document.getElementById("newIngName").value = "";
  1705. document.getElementById("newIngCategory").value = "";
  1706. document.getElementById("newIngQuantity").value = 0;
  1707. document.getElementById("bottleSizeLabel").style.display = "none";
  1708. selector.value = "g";
  1709. selector.onchange = ()=>{this.unitChange()};
  1710. document.getElementById("submitNewIng").onclick = ()=>{this.submit(Ingredient)};
  1711. document.getElementById("ingredientFileUpload").addEventListener("click", ()=>{controller.openModal("ingredientSpreadsheet")});
  1712. },
  1713. unitChange: function(){
  1714. const select = document.getElementById("unitSelector");
  1715. const bottleLabel = document.getElementById("bottleSizeLabel");
  1716. if(select.value === "bottle"){
  1717. bottleLabel.style.display = "block";
  1718. }else{
  1719. bottleLabel.style.display = "none";
  1720. }
  1721. },
  1722. submit: function(){
  1723. let unitSelector = document.getElementById("unitSelector");
  1724. let options = document.querySelectorAll("#unitSelector option");
  1725. const quantityValue = parseFloat(document.getElementById("newIngQuantity").value);
  1726. let unit = unitSelector.value;
  1727. let newIngredient = {
  1728. ingredient: {
  1729. name: document.getElementById("newIngName").value,
  1730. category: document.getElementById("newIngCategory").value,
  1731. unitType: options[unitSelector.selectedIndex].getAttribute("type")
  1732. },
  1733. quantity: quantityValue,
  1734. defaultUnit: unit
  1735. }
  1736. //Change the ingredient if it is a special unit type (ie "bottle")
  1737. if(unit === "bottle"){
  1738. newIngredient.ingredient.unitType = "volume";
  1739. newIngredient.ingredient.unitSize = document.getElementById("bottleSize").value;
  1740. newIngredient.defaultUnit = document.getElementById("bottleUnits").value;
  1741. newIngredient.ingredient.specialUnit = unit;
  1742. newIngredient.quantity = quantityValue;
  1743. }
  1744. let loader = document.getElementById("loaderContainer");
  1745. loader.style.display = "flex";
  1746. fetch("/ingredients/create", {
  1747. method: "POST",
  1748. headers: {
  1749. "Content-Type": "application/json;charset=utf-8"
  1750. },
  1751. body: JSON.stringify(newIngredient)
  1752. })
  1753. .then((response) => response.json())
  1754. .then((response)=>{
  1755. if(typeof(response) === "string"){
  1756. banner.createError(response);
  1757. }else{
  1758. merchant.addIngredient(response.ingredient, response.quantity, response.defaultUnit);
  1759. controller.openStrand("ingredients");
  1760. banner.createNotification("INGREDIENT CREATED");
  1761. }
  1762. })
  1763. .catch((err)=>{
  1764. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  1765. })
  1766. .finally(()=>{
  1767. loader.style.display = "none";
  1768. });
  1769. },
  1770. submitSpreadsheet: function(){
  1771. event.preventDefault();
  1772. controller.closeModal();
  1773. const file = document.getElementById("spreadsheetInput").files[0];
  1774. let data = new FormData();
  1775. data.append("ingredients", file);
  1776. let loader = document.getElementById("loaderContainer");
  1777. loader.style.display = "flex";
  1778. fetch("/ingredients/create/spreadsheet", {
  1779. method: "post",
  1780. body: data
  1781. })
  1782. .then(response => response.json())
  1783. .then((response)=>{
  1784. if(typeof(response) === "string"){
  1785. banner.createError(response);
  1786. }else{
  1787. for(let i = 0; i < response.length; i++){
  1788. merchant.addIngredient(response[i].ingredient, response[i].quantity, response[i].defaultUnit);
  1789. controller.openStrand("ingredients");
  1790. }
  1791. }
  1792. })
  1793. .catch((err)=>{
  1794. banner.createError("SOMETHING WENT WRONG. TRY REFRESHING THE PAGE");
  1795. })
  1796. .finally(()=>{
  1797. loader.style.display = "none";
  1798. });
  1799. }
  1800. }
  1801. module.exports = newIngredient;
  1802. },{}],11:[function(require,module,exports){
  1803. let newOrder = {
  1804. display: function(Order){
  1805. document.getElementById("sidebarDiv").classList.add("sidebarWide");
  1806. document.getElementById("newOrderIngredientList").style.display = "flex";
  1807. document.getElementById("orderFileUpload").addEventListener("click", ()=>{controller.openModal("orderSpreadsheet")});
  1808. let selectedList = document.getElementById("selectedIngredientList");
  1809. while(selectedList.children.length > 0){
  1810. selectedList.removeChild(selectedList.firstChild);
  1811. }
  1812. let ingredientList = document.getElementById("newOrderIngredients");
  1813. while(ingredientList.children.length > 0){
  1814. ingredientList.removeChild(ingredientList.firstChild);
  1815. }
  1816. for(let i = 0; i < merchant.ingredients.length; i++){
  1817. let ingredient = document.createElement("button");
  1818. ingredient.classList = "choosable";
  1819. ingredient.innerText = merchant.ingredients[i].ingredient.name;
  1820. ingredient.onclick = ()=>{this.addIngredient(merchant.ingredients[i], ingredient)};
  1821. ingredientList.appendChild(ingredient);
  1822. }
  1823. document.getElementById("submitNewOrder").onclick = ()=>{this.submit(Order)};
  1824. },
  1825. addIngredient: function(ingredient, element){
  1826. element.style.display = "none";
  1827. let div = document.getElementById("selectedIngredient").content.children[0].cloneNode(true);
  1828. div.ingredient = ingredient;
  1829. div.children[0].children[1].onclick = ()=>{this.removeIngredient(div, element)};
  1830. //Display units depending on the whether it is a special unit
  1831. if(ingredient.ingredient.specialUnit === "bottle"){
  1832. div.children[0].children[0].innerText = `${ingredient.ingredient.name} (BOTTLES)`;
  1833. }else{
  1834. div.children[0].children[0].innerText = `${ingredient.ingredient.name} (${ingredient.ingredient.unit.toUpperCase()})`;
  1835. }
  1836. document.getElementById("selectedIngredientList").appendChild(div);
  1837. },
  1838. removeIngredient: function(selectedElement, element){
  1839. selectedElement.parentElement.removeChild(selectedElement);
  1840. element.style.display = "block";
  1841. },
  1842. submit: function(Order){
  1843. let date = document.getElementById("newOrderDate").value;
  1844. let taxes = document.getElementById("orderTaxes").value * 100;
  1845. let fees = document.getElementById("orderFees").value * 100;
  1846. let ingredients = document.getElementById("selectedIngredientList").children;
  1847. if(date === ""){
  1848. banner.createError("DATE IS REQUIRED FOR ORDERS");
  1849. return;
  1850. }
  1851. let data = {
  1852. name: document.getElementById("newOrderName").value,
  1853. date: date,
  1854. taxes: taxes,
  1855. fees: fees,
  1856. ingredients: []
  1857. }
  1858. for(let i = 0; i < ingredients.length; i++){
  1859. let quantity = ingredients[i].children[1].children[0].value;
  1860. let price = ingredients[i].children[1].children[1].value;
  1861. if(quantity === "" || price === ""){
  1862. banner.createError("MUST PROVIDE QUANTITY AND PRICE PER UNIT FOR ALL INGREDIENTS");
  1863. return;
  1864. }
  1865. if(quantity < 0 || price < 0){
  1866. banner.createError("QUANTITY AND PRICE MUST BE NON-NEGATIVE NUMBERS");
  1867. }
  1868. if(ingredients[i].ingredient.ingredient.specialUnit === "bottle"){
  1869. data.ingredients.push({
  1870. ingredient: ingredients[i].ingredient.ingredient.id,
  1871. quantity: quantity * ingredients[i].ingredient.ingredient.unitSize,
  1872. pricePerUnit: this.convertPrice(ingredients[i].ingredient.ingredient, price * 100)
  1873. });
  1874. }else{
  1875. data.ingredients.push({
  1876. ingredient: ingredients[i].ingredient.ingredient.id,
  1877. quantity: ingredients[i].ingredient.convertToBase(quantity),
  1878. pricePerUnit: this.convertPrice(ingredients[i].ingredient.ingredient, price * 100)
  1879. });
  1880. }
  1881. }
  1882. let loader = document.getElementById("loaderContainer");
  1883. loader.style.display = "flex";
  1884. fetch("/order/create", {
  1885. method: "post",
  1886. headers: {
  1887. "Content-Type": "application/json;charset=utf-8"
  1888. },
  1889. body: JSON.stringify(data)
  1890. })
  1891. .then((response)=>response.json())
  1892. .then((response)=>{
  1893. if(typeof(response) === "string"){
  1894. banner.createError(response);
  1895. }else{
  1896. merchant.addOrder(response, true);
  1897. controller.openStrand("orders", merchant.orders);
  1898. banner.createNotification("NEW ORDER CREATED");
  1899. }
  1900. })
  1901. .catch((err)=>{
  1902. banner.createError("SOMETHING WENT WRONG, PLEASE REFRESH THE PAGE");
  1903. })
  1904. .finally(()=>{
  1905. loader.style.display = "none";
  1906. });
  1907. },
  1908. //TODO: Remove this function, it should be on the order
  1909. convertPrice: function(ingredient, price){
  1910. if(ingredient.specialUnit === "bottle"){
  1911. return price / ingredient.unitSize;
  1912. }
  1913. switch(ingredient.unit){
  1914. case "g": return price;
  1915. case "kg": return price / 1000;
  1916. case "oz": return price / 28.3495;
  1917. case "lb": return price / 453.5924;
  1918. case "ml": return price * 1000;
  1919. case "l": return price;
  1920. case "tsp": return price * 202.8842;
  1921. case "tbsp": return price * 67.6278;
  1922. case "ozfl": return price * 33.8141;
  1923. case "cup": return price * 4.1667;
  1924. case "pt": return price * 2.1134;
  1925. case "qt": return price * 1.0567;
  1926. case "gal": return price / 3.7854;
  1927. case "mm": return price * 1000;
  1928. case "cm": return price * 100;
  1929. case "m": return price;
  1930. case "in": return price * 39.3701;
  1931. case "ft": return price * 3.2808;
  1932. }
  1933. },
  1934. submitSpreadsheet: function(){
  1935. event.preventDefault();
  1936. controller.closeModal();
  1937. const file = document.getElementById("spreadsheetInput").files[0];
  1938. let data = new FormData();
  1939. data.append("orders", file);
  1940. let loader = document.getElementById("loaderContainer");
  1941. loader.style.display = "flex";
  1942. fetch("/orders/create/spreadsheet", {
  1943. method: "post",
  1944. body: data
  1945. })
  1946. .then(response => response.json())
  1947. .then((response)=>{
  1948. if(typeof(response) === "string"){
  1949. banner.createError(response);
  1950. }else{
  1951. for(let i = 0; i < response.length; i++){
  1952. merchant.addOrder(response[i], true);
  1953. }
  1954. banner.createNotification("ORDER CREATED AND INGREDIENTS UPDATED SUCCESSFULLY");
  1955. controller.openStrand("orders");
  1956. }
  1957. })
  1958. .catch((err)=>{
  1959. banner.createError("UNABLE TO DISPLAY NEW ORDER. PLEASE REFRESH THE PAGE.");
  1960. })
  1961. .finally(()=>{
  1962. loader.style.display = "none";
  1963. });
  1964. }
  1965. }
  1966. module.exports = newOrder;
  1967. },{}],12:[function(require,module,exports){
  1968. let newRecipe = {
  1969. display: function(Recipe){
  1970. document.getElementById("newRecipeName").value = "";
  1971. document.getElementById("newRecipePrice").value = "";
  1972. document.getElementById("ingredientCount").value = 1;
  1973. let categories = merchant.categorizeIngredients();
  1974. let ingredientsSelect = document.getElementById("recipeInputIngredients");
  1975. while(ingredientsSelect.children.length > 0){
  1976. ingredientsSelect.removeChild(ingredientsSelect.firstChild);
  1977. }
  1978. this.changeIngredientCount(categories);
  1979. document.getElementById("ingredientCount").onchange = ()=>{this.changeIngredientCount(categories)};
  1980. document.getElementById("submitNewRecipe").onclick = ()=>{this.submit(Recipe)};
  1981. document.getElementById("recipeFileUpload").onclick = ()=>{controller.openModal("recipeSpreadsheet")};
  1982. },
  1983. //Updates the number of ingredient inputs displayed for new recipes
  1984. changeIngredientCount: function(categories){
  1985. let newCount = document.getElementById("ingredientCount").value;
  1986. let ingredientsDiv = document.getElementById("recipeInputIngredients");
  1987. let template = document.getElementById("recipeInputIngredient").content.children[0];
  1988. let oldCount = ingredientsDiv.children.length;
  1989. if(newCount > oldCount){
  1990. let newDivs = newCount - oldCount;
  1991. for(let i = 0; i < newDivs; i++){
  1992. let newNode = template.cloneNode(true);
  1993. newNode.children[0].innnerText = `INGREDIENT ${i + oldCount}`;
  1994. newNode.children[2].children[0].value = 0;
  1995. for(let j = 0; j < categories.length; j++){
  1996. let optgroup = document.createElement("optgroup");
  1997. optgroup.label = categories[j].name;
  1998. for(let k = 0; k < categories[j].ingredients.length; k++){
  1999. let option = document.createElement("option");
  2000. option.innerText = categories[j].ingredients[k].ingredient.getNameAndUnit();
  2001. option.ingredient = categories[j].ingredients[k];
  2002. optgroup.appendChild(option);
  2003. }
  2004. newNode.children[1].children[0].appendChild(optgroup);
  2005. }
  2006. ingredientsDiv.appendChild(newNode);
  2007. }
  2008. for(let i = 0; i < newCount; i++){
  2009. ingredientsDiv.children[i].children[0].innerText = `INGREDIENT ${i + 1}`;
  2010. }
  2011. }else if(newCount < oldCount){
  2012. let newDivs = oldCount - newCount;
  2013. for(let i = 0; i < newDivs; i++){
  2014. ingredientsDiv.removeChild(ingredientsDiv.children[ingredientsDiv.children.length-1]);
  2015. }
  2016. }
  2017. },
  2018. submit: function(Recipe){
  2019. let newRecipe = {
  2020. name: document.getElementById("newRecipeName").value,
  2021. price: document.getElementById("newRecipePrice").value,
  2022. ingredients: []
  2023. }
  2024. let inputs = document.getElementById("recipeInputIngredients").children;
  2025. for(let i = 0; i < inputs.length; i++){
  2026. let sel = inputs[i].children[1].children[0];
  2027. let ingredient = sel.options[sel.selectedIndex].ingredient;
  2028. newRecipe.ingredients.push({
  2029. ingredient: ingredient.ingredient.id,
  2030. quantity: ingredient.convertToBase(inputs[i].children[2].children[0].value)
  2031. });
  2032. }
  2033. let loader = document.getElementById("loaderContainer");
  2034. loader.style.display = "flex";
  2035. fetch("/recipe/create", {
  2036. method: "POST",
  2037. headers: {
  2038. "Content-Type": "application/json;charset=utf-8"
  2039. },
  2040. body: JSON.stringify(newRecipe)
  2041. })
  2042. .then((response) => response.json())
  2043. .then((response)=>{
  2044. if(typeof(response) === "string"){
  2045. banner.createError(response);
  2046. }else{
  2047. let ingredients = [];
  2048. for(let i = 0; i < response.ingredients.length; i++){
  2049. for(let j = 0; j < merchant.ingredients.length; j++){
  2050. if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
  2051. ingredients.push({
  2052. ingredient: merchant.ingredients[j].ingredient,
  2053. quantity: response.ingredients[i].quantity
  2054. });
  2055. break;
  2056. }
  2057. }
  2058. }
  2059. merchant.addRecipe(
  2060. response._id,
  2061. response.name,
  2062. response.price,
  2063. ingredients
  2064. );
  2065. banner.createNotification("RECIPE CREATED");
  2066. controller.openStrand("recipeBook");
  2067. }
  2068. })
  2069. .catch((err)=>{
  2070. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2071. })
  2072. .finally(()=>{
  2073. loader.style.display = "none";
  2074. });
  2075. },
  2076. submitSpreadsheet: function(){
  2077. event.preventDefault();
  2078. controller.closeModal();
  2079. const file = document.getElementById("spreadsheetInput").files[0];
  2080. let data = new FormData();
  2081. data.append("recipes", file);
  2082. let loader = document.getElementById("loaderContainer");
  2083. loader.style.display = "flex";
  2084. fetch("/recipes/create/spreadsheet", {
  2085. method: "post",
  2086. body: data
  2087. })
  2088. .then(response => response.json())
  2089. .then((response)=>{
  2090. if(typeof(response) === "String"){
  2091. banner.createError(response);
  2092. }else{
  2093. for(let i = 0; i < response.length; i++){
  2094. merchant.addRecipe(
  2095. response[i]._id,
  2096. response[i].name,
  2097. response[i].price,
  2098. response[i].ingredients
  2099. );
  2100. }
  2101. banner.createNotification("ALL INGREDIENTS SUCCESSFULLY CREATED");
  2102. controller.openStrand("recipeBook");
  2103. }
  2104. })
  2105. .catch((err)=>{
  2106. banner.createError("UNABLE TO DISPLAY NEW RECIPES. PLEASE REFRESH THE PAGE");
  2107. })
  2108. .finally(()=>{
  2109. loader.style.display = "none";
  2110. });
  2111. }
  2112. }
  2113. module.exports = newRecipe;
  2114. },{}],13:[function(require,module,exports){
  2115. let newTransaction = {
  2116. display: function(Transaction){
  2117. let recipeList = document.getElementById("newTransactionRecipes");
  2118. let template = document.getElementById("createTransaction").content.children[0];
  2119. document.getElementById("transactionFileUpload").addEventListener("click", ()=>{controller.openModal("transactionSpreadsheet")});
  2120. while(recipeList.children.length > 0){
  2121. recipeList.removeChild(recipeList.firstChild);
  2122. }
  2123. for(let i = 0; i < merchant.recipes.length; i++){
  2124. let recipeDiv = template.cloneNode(true);
  2125. recipeDiv.recipe = merchant.recipes[i];
  2126. recipeList.appendChild(recipeDiv);
  2127. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  2128. }
  2129. document.getElementById("submitNewTransaction").onclick = ()=>{this.submit(Transaction)};
  2130. },
  2131. submit: function(Transaction){
  2132. let recipeDivs = document.getElementById("newTransactionRecipes");
  2133. let date = document.getElementById("newTransactionDate").valueAsDate;
  2134. if(date > new Date()){
  2135. banner.createError("CANNOT HAVE A DATE IN THE FUTURE");
  2136. return;
  2137. }
  2138. let data = {
  2139. date: date,
  2140. recipes: [],
  2141. ingredientUpdates: {}
  2142. };
  2143. for(let i = 0; i < recipeDivs.children.length; i++){
  2144. let quantity = recipeDivs.children[i].children[1].value;
  2145. const recipe = recipeDivs.children[i].recipe;
  2146. if(quantity !== "" && quantity > 0){
  2147. data.recipes.push({
  2148. recipe: recipe.id,
  2149. quantity: quantity
  2150. });
  2151. for(let j = 0; j < recipe.ingredients.length; j++){
  2152. let ingredient = recipe.ingredients[j];
  2153. if(data.ingredientUpdates[ingredient.ingredient.id]){
  2154. data.ingredientUpdates[ingredient.ingredient.id] += ingredient.convertToBase(ingredient.quantity) * quantity;
  2155. }else{
  2156. data.ingredientUpdates[ingredient.ingredient.id] = ingredient.convertToBase(ingredient.quantity) * quantity;
  2157. }
  2158. }
  2159. }else if(quantity < 0){
  2160. banner.createError("CANNOT HAVE NEGATIVE VALUES");
  2161. return;
  2162. }
  2163. }
  2164. if(data.recipes.length > 0){
  2165. let loader = document.getElementById("loaderContainer");
  2166. loader.style.display = "flex";
  2167. fetch("/transaction/create", {
  2168. method: "post",
  2169. headers: {
  2170. "Content-Type": "application/json;charset=utf-8"
  2171. },
  2172. body: JSON.stringify(data)
  2173. })
  2174. .then(response => response.json())
  2175. .then((response)=>{
  2176. if(typeof(response) === "string"){
  2177. banner.createError(response);
  2178. }else{
  2179. merchant.addTransaction(response);
  2180. controller.openStrand("transactions", merchant.getTransactions());
  2181. banner.createNotification("TRANSACTION CREATED");
  2182. }
  2183. })
  2184. .catch((err)=>{
  2185. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2186. })
  2187. .finally(()=>{
  2188. loader.style.display = "none";
  2189. });
  2190. }
  2191. },
  2192. submitSpreadsheet: function(){
  2193. event.preventDefault();
  2194. controller.closeModal();
  2195. const file = document.getElementById("spreadsheetInput").files[0];
  2196. let data = new FormData();
  2197. data.append("transactions", file);
  2198. let loader = document.getElementById("loaderContainer");
  2199. loader.style.display = "flex";
  2200. fetch("/transactions/create/spreadsheet", {
  2201. method: "post",
  2202. body: data
  2203. })
  2204. .then(response => response.json())
  2205. .then((response)=>{
  2206. if(typeof(response) === "string"){
  2207. banner.createError(response);
  2208. }else{
  2209. for(let i = 0; i < response.recipes.length; i++){
  2210. response.recipes[i].recipe = response.recipes[i].recipe._id;
  2211. }
  2212. merchant.addTransaction(response);
  2213. controller.openStrand("transactions", merchant.transactions);
  2214. banner.createNotification("TRANSACTION SUCCESSFULLY CREATED. INGREDIENTS UPDATED");
  2215. }
  2216. })
  2217. .catch((err)=>{
  2218. banner.createError("UNABLE TO DISPLAY NEW TRANSACTIONS. PLEASE REFRESH THE PAGE");
  2219. })
  2220. .finally(()=>{
  2221. loader.style.display = "none";
  2222. });
  2223. }
  2224. }
  2225. module.exports = newTransaction;
  2226. },{}],14:[function(require,module,exports){
  2227. let orderDetails = {
  2228. display: function(order){
  2229. document.getElementById("removeOrderBtn").onclick = ()=>{this.remove(order)};
  2230. document.getElementById("orderDetailName").innerText = order.name;
  2231. document.getElementById("orderDetailDate").innerText = order.date.toLocaleDateString("en-US");
  2232. document.getElementById("orderDetailTax").innerText = `$${order.taxes.toFixed(2)}`;
  2233. document.getElementById("orderDetailFee").innerText = `$${order.fees.toFixed(2)}`;
  2234. let ingredientList = document.getElementById("orderIngredients");
  2235. while(ingredientList.children.length > 0){
  2236. ingredientList.removeChild(ingredientList.firstChild);
  2237. }
  2238. let template = document.getElementById("orderIngredient").content.children[0];
  2239. for(let i = 0; i < order.ingredients.length; i++){
  2240. let ingredientDiv = template.cloneNode(true);
  2241. const ingredient = order.ingredients[i].ingredient;
  2242. ingredientDiv.children[0].innerText = order.ingredients[i].ingredient.name;
  2243. ingredientDiv.children[2].innerText = `$${order.ingredients[i].cost().toFixed(2)}`;
  2244. ingredientDiv.onclick = ()=>{
  2245. controller.openStrand("ingredients");
  2246. controller.openSidebar("ingredientDetails", merchant.getIngredient(order.ingredients[i].ingredient.id));
  2247. }
  2248. let ingredientDisplay = ingredientDiv.children[1];
  2249. if(ingredient.specialUnit === "bottle"){
  2250. ingredientDisplay.innerText = `${order.ingredients[i].quantity.toFixed(2)} bottles x $${order.ingredients[i].pricePerUnit.toFixed(2)}`;
  2251. }else{
  2252. ingredientDisplay.innerText = `${order.ingredients[i].quantity.toFixed(2)} ${ingredient.unit.toUpperCase()} X $${order.ingredients[i].pricePerUnit.toFixed(2)}`;
  2253. }
  2254. ingredientList.appendChild(ingredientDiv);
  2255. }
  2256. document.getElementById("orderDetailTotal").innerText = `$${order.getIngredientCost().toFixed(2)}`;
  2257. document.querySelector("#orderTotalPrice p").innerText = `$${order.getTotalCost().toFixed(2)}`;
  2258. },
  2259. remove: function(order){
  2260. let loader = document.getElementById("loaderContainer");
  2261. loader.style.display = "flex";
  2262. fetch(`/order/${order.id}`, {
  2263. method: "DELETE",
  2264. headers: {
  2265. "Content-Type": "application/json;charset=utf-8"
  2266. }
  2267. })
  2268. .then((response) => response.json())
  2269. .then((response)=>{
  2270. if(typeof(response) === "string"){
  2271. banner.createError(response);
  2272. }else{
  2273. merchant.removeOrder(order);
  2274. controller.openStrand("orders", merchant.orders);
  2275. banner.createNotification("ORDER REMOVED");
  2276. }
  2277. })
  2278. .catch((err)=>{
  2279. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2280. })
  2281. .finally(()=>{
  2282. loader.style.display = "none";
  2283. });
  2284. }
  2285. }
  2286. module.exports = orderDetails;
  2287. },{}],15:[function(require,module,exports){
  2288. let orderFilter = {
  2289. display: function(Order){
  2290. let now = new Date();
  2291. let past = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
  2292. let ingredientList = document.getElementById("orderFilterIngredients");
  2293. document.getElementById("orderFilterDateFrom").valueAsDate = past;
  2294. document.getElementById("orderFilterDateTo").valueAsDate = now;
  2295. while(ingredientList.children.length > 0){
  2296. ingredientList.removeChild(ingredientList.firstChild);
  2297. }
  2298. for(let i = 0; i < merchant.ingredients.length; i++){
  2299. let element = document.createElement("div");
  2300. element.classList.add("choosable");
  2301. element.ingredient = merchant.ingredients[i].ingredient.id;
  2302. element.onclick = ()=>{this.toggleActive(element)};
  2303. ingredientList.appendChild(element);
  2304. let text = document.createElement("p");
  2305. text.innerText = merchant.ingredients[i].ingredient.name;
  2306. element.appendChild(text);
  2307. }
  2308. document.getElementById("orderFilterSubmit").onclick = ()=>{this.submit(Order)};
  2309. },
  2310. toggleActive: function(element){
  2311. if(element.classList.contains("active")){
  2312. element.classList.remove("active");
  2313. }else{
  2314. element.classList.add("active");
  2315. }
  2316. },
  2317. submit: function(Order){
  2318. let data = {
  2319. startDate: document.getElementById("orderFilterDateFrom").valueAsDate,
  2320. endDate: document.getElementById("orderFilterDateTo").valueAsDate,
  2321. ingredients: []
  2322. }
  2323. if(data.startDate >= data.endDate){
  2324. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2325. return;
  2326. }
  2327. let ingredients = document.getElementById("orderFilterIngredients").children;
  2328. for(let i = 0; i < ingredients.length; i++){
  2329. if(ingredients[i].classList.contains("active")){
  2330. data.ingredients.push(ingredients[i].ingredient);
  2331. }
  2332. }
  2333. if(data.ingredients.length === 0){
  2334. for(let i = 0; i < merchant.ingredients.length; i++){
  2335. data.ingredients.push(merchant.ingredients[i].ingredient.id);
  2336. }
  2337. }
  2338. let loader = document.getElementById("loaderContainer");
  2339. loader.style.display = "flex";
  2340. fetch("/order", {
  2341. method: "post",
  2342. headers: {
  2343. "Content-Type": "application/json;charset=utf-8"
  2344. },
  2345. body: JSON.stringify(data)
  2346. })
  2347. .then(response => response.json())
  2348. .then((response)=>{
  2349. let orders = [];
  2350. if(typeof(response) === "string"){
  2351. banner.createError(response);
  2352. }else if(response.length === 0){
  2353. banner.createError("NO ORDERS MATCH YOUR SEARCH");
  2354. }else{
  2355. for(let i = 0; i < response.length; i++){
  2356. orders.push(new Order(
  2357. response[i]._id,
  2358. response[i].name,
  2359. response[i].date,
  2360. response[i].taxes,
  2361. response[i].fees,
  2362. response[i].ingredients,
  2363. merchant
  2364. ));
  2365. }
  2366. }
  2367. controller.openStrand("orders", orders);
  2368. })
  2369. .catch((err)=>{
  2370. banner.createError("UNABLE TO DISPLAY THE ORDERS");
  2371. })
  2372. .finally(()=>{
  2373. loader.style.display = "none";
  2374. });
  2375. }
  2376. }
  2377. module.exports = orderFilter;
  2378. },{}],16:[function(require,module,exports){
  2379. let recipeDetails = {
  2380. display: function(recipe){
  2381. document.getElementById("editRecipeBtn").onclick = ()=>{controller.openSidebar("editRecipe", recipe)};
  2382. document.getElementById("recipeName").innerText = recipe.name;
  2383. if(merchant.pos === "none"){
  2384. document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove(recipe)};
  2385. }
  2386. //ingredient list
  2387. let ingredientsDiv = document.getElementById("recipeIngredientList");
  2388. while(ingredientsDiv.children.length > 0){
  2389. ingredientsDiv.removeChild(ingredientsDiv.firstChild);
  2390. }
  2391. let template = document.getElementById("recipeIngredient").content.children[0];
  2392. for(let i = 0; i < recipe.ingredients.length; i++){
  2393. let recipeDiv = template.cloneNode(true);
  2394. recipeDiv.children[0].innerText = recipe.ingredients[i].ingredient.name;
  2395. recipeDiv.children[1].innerText = `${recipe.ingredients[i].getQuantityDisplay()}`;
  2396. recipeDiv.onclick = ()=>{
  2397. controller.openStrand("ingredients");
  2398. controller.openSidebar("ingredientDetails", merchant.getIngredient(recipe.ingredients[i].ingredient.id));
  2399. }
  2400. ingredientsDiv.appendChild(recipeDiv);
  2401. }
  2402. document.getElementById("recipePrice").children[1].innerText = `$${recipe.price.toFixed(2)}`;
  2403. },
  2404. remove: function(recipe){
  2405. let loader = document.getElementById("loaderContainer");
  2406. loader.style.display = "flex";
  2407. fetch(`/recipe/remove/${recipe.id}`, {
  2408. method: "delete"
  2409. })
  2410. .then((response) => response.json())
  2411. .then((response)=>{
  2412. if(typeof(response) === "string"){
  2413. banner.createError(response);
  2414. }else{
  2415. merchant.removeRecipe(recipe);
  2416. banner.createNotification("RECIPE REMOVED");
  2417. controller.openStrand("recipeBook");
  2418. }
  2419. })
  2420. .catch((err)=>{
  2421. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2422. })
  2423. .finally(()=>{
  2424. loader.style.display = "none";
  2425. });
  2426. }
  2427. }
  2428. module.exports = recipeDetails;
  2429. },{}],17:[function(require,module,exports){
  2430. let transactionDetails = {
  2431. transaction: {},
  2432. display: function(transaction){
  2433. this.transaction = transaction;
  2434. let recipeList = document.getElementById("transactionRecipes");
  2435. let template = document.getElementById("transactionRecipe").content.children[0];
  2436. let totalRecipes = 0;
  2437. let totalPrice = 0;
  2438. while(recipeList.children.length > 0){
  2439. recipeList.removeChild(recipeList.firstChild);
  2440. }
  2441. for(let i = 0; i < transaction.recipes.length; i++){
  2442. let recipe = template.cloneNode(true);
  2443. let price = transaction.recipes[i].quantity * transaction.recipes[i].recipe.price;
  2444. recipe.children[0].innerText = transaction.recipes[i].recipe.name;
  2445. recipe.children[1].innerText = `${transaction.recipes[i].quantity} x $${transaction.recipes[i].recipe.price.toFixed(2)}`;
  2446. recipe.children[2].innerText = `$${price.toFixed(2)}`;
  2447. recipe.onclick = ()=>{
  2448. controller.openStrand("recipeBook");
  2449. controller.openSidebar("recipeDetails", transaction.recipes[i].recipe);
  2450. }
  2451. recipeList.appendChild(recipe);
  2452. totalRecipes += transaction.recipes[i].quantity;
  2453. totalPrice += price;
  2454. }
  2455. let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2456. let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  2457. let dateString = `${days[transaction.date.getDay()]}, ${months[transaction.date.getMonth()]} ${transaction.date.getDate()}, ${transaction.date.getFullYear()}`;
  2458. document.getElementById("transactionDate").innerText = dateString;
  2459. document.getElementById("transactionTime").innerText = transaction.date.toLocaleTimeString();
  2460. document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
  2461. document.getElementById("totalPrice").innerText = `$${totalPrice.toFixed(2)}`;
  2462. if(merchant.pos === "none"){
  2463. document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
  2464. }
  2465. },
  2466. remove: function(){
  2467. let loader = document.getElementById("loaderContainer");
  2468. loader.style.display = "flex";
  2469. fetch(`/transaction/${this.transaction.id}`, {
  2470. method: "delete",
  2471. headers: {
  2472. "Content-Type": "application/json;charset=utf-8"
  2473. },
  2474. })
  2475. .then((response)=>{
  2476. if(typeof(response) === "string"){
  2477. banner.createError(response);
  2478. }else{
  2479. merchant.removeTransaction(this.transaction);
  2480. controller.openStrand("transactions", merchant.getTransactions());
  2481. banner.createNotification("TRANSACTION REMOVED");
  2482. }
  2483. })
  2484. .catch((err)=>{
  2485. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2486. })
  2487. .finally(()=>{
  2488. loader.style.display = "none";
  2489. });
  2490. },
  2491. }
  2492. module.exports = transactionDetails;
  2493. },{}],18:[function(require,module,exports){
  2494. let transactionFilter = {
  2495. display: function(){
  2496. //Set default dates
  2497. let today = new Date();
  2498. let monthAgo = new Date(today);
  2499. monthAgo.setMonth(today.getMonth() - 1);
  2500. document.getElementById("transFilterDateStart").valueAsDate = monthAgo;
  2501. document.getElementById("transFilterDateEnd").valueAsDate = today;
  2502. //populate recipes
  2503. let recipeList = document.getElementById("transFilterRecipeList");
  2504. while(recipeList.children.length > 0){
  2505. recipeList.removeChild(recipeList.firstChild);
  2506. }
  2507. for(let i = 0; i < merchant.recipes.length; i++){
  2508. let recipe = document.createElement("div");
  2509. recipe.innerText = merchant.recipes[i].name;
  2510. recipe.recipe = merchant.recipes[i];
  2511. recipe.classList.add("choosable");
  2512. recipe.onclick = ()=>{this.toggleActive(recipe)};
  2513. recipeList.appendChild(recipe);
  2514. }
  2515. //Submit button
  2516. document.getElementById("transFilterSubmit").onclick = ()=>{this.submit()};
  2517. },
  2518. toggleActive: function(element){
  2519. if(element.classList.contains("active")){
  2520. element.classList.remove("active");
  2521. }else{
  2522. element.classList.add("active");
  2523. }
  2524. },
  2525. submit: function(){
  2526. let data = {
  2527. startDate: document.getElementById("transFilterDateStart").valueAsDate,
  2528. endDate: document.getElementById("transFilterDateEnd").valueAsDate,
  2529. recipes: []
  2530. }
  2531. if(data.startDate >= data.endDate){
  2532. banner.createError("START DATE CANNOT BE AFTER END DATE");
  2533. return;
  2534. }
  2535. let recipes = document.getElementById("transFilterRecipeList").children;
  2536. for(let i = 0; i < recipes.length; i++){
  2537. if(recipes[i].classList.contains("active")){
  2538. data.recipes.push(recipes[i].recipe.id);
  2539. }
  2540. }
  2541. if(data.recipes.length === 0){
  2542. for(let i = 0; i < merchant.recipes.length; i++){
  2543. data.recipes.push(merchant.recipes[i].id);
  2544. }
  2545. }
  2546. let loader = document.getElementById("loaderContainer");
  2547. loader.style.display = "flex";
  2548. fetch("/transaction", {
  2549. method: "post",
  2550. headers: {
  2551. "Content-Type": "application/json;charset=utf-8"
  2552. },
  2553. body: JSON.stringify(data)
  2554. })
  2555. .then(response => response.json())
  2556. .then((response)=>{
  2557. let transactions = [];
  2558. if(typeof(response) === "string"){
  2559. banner.createError(response);
  2560. }else if(response.length === 0){
  2561. banner.createError("NO TRANSACTIONS MATCH YOUR SEARCH");
  2562. }else{
  2563. for(let i = 0; i < response.length; i++){
  2564. transactions.push(new Transaction(
  2565. response[i]._id,
  2566. response[i].date,
  2567. response[i].recipes,
  2568. merchant
  2569. ));
  2570. }
  2571. }
  2572. controller.openStrand("transactions", transactions);
  2573. })
  2574. .catch((err)=>{
  2575. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  2576. })
  2577. .finally(()=>{
  2578. loader.style.display = "none";
  2579. });
  2580. }
  2581. }
  2582. module.exports = transactionFilter;
  2583. },{}],19:[function(require,module,exports){
  2584. let analytics = {
  2585. isPopulated: false,
  2586. ingredient: {},
  2587. recipe: {},
  2588. transactionsByDate: [],
  2589. display: function(Transaction){
  2590. if(!this.isPopulated){
  2591. document.getElementById("analRecipeContent").style.display = "none";
  2592. let to = new Date()
  2593. let from = new Date(to.getFullYear(), to.getMonth() - 1, to.getDate());
  2594. document.getElementById("analStartDate").valueAsDate = from;
  2595. document.getElementById("analEndDate").valueAsDate = to;
  2596. let analSlider = document.getElementById("analSlider");
  2597. analSlider.onclick = ()=>{this.switchDisplay()};
  2598. analSlider.checked = false;
  2599. document.getElementById("analDateBtn").onclick = ()=>{this.newDates(Transaction)};
  2600. this.populateButtons();
  2601. this.ingredient = merchant.ingredients[0].ingredient;
  2602. this.recipe = merchant.recipes[0];
  2603. this.newDates(Transaction);
  2604. this.isPopulated = true;
  2605. }
  2606. },
  2607. populateButtons: function(){
  2608. let ingredientButtons = document.getElementById("analIngredientList");
  2609. let recipeButtons = document.getElementById("analRecipeList");
  2610. for(let i = 0; i < merchant.ingredients.length; i++){
  2611. let button = document.createElement("button");
  2612. button.innerText = merchant.ingredients[i].ingredient.name;
  2613. button.classList.add("choosable");
  2614. button.onclick = ()=>{
  2615. this.ingredient = merchant.ingredients[i].ingredient;
  2616. this.displayIngredient()
  2617. };
  2618. ingredientButtons.appendChild(button);
  2619. }
  2620. for(let i = 0; i < merchant.recipes.length; i++){
  2621. let button = document.createElement("button");
  2622. button.innerText = merchant.recipes[i].name;
  2623. button.classList.add("choosable");
  2624. button.onclick = ()=>{
  2625. this.recipe = merchant.recipes[i];
  2626. this.displayRecipe()
  2627. };
  2628. recipeButtons.appendChild(button);
  2629. }
  2630. },
  2631. getData: function(from, to, Transaction){
  2632. let loader = document.getElementById("loaderContainer");
  2633. loader.style.display = "flex";
  2634. return fetch(`/transactions/${from.toISOString()}/${to.toISOString()}`)
  2635. .then(response => response.json())
  2636. .then((response)=>{
  2637. if(typeof(response) === "string"){
  2638. banner.createError(response);
  2639. }else{
  2640. this.transactionsByDate = [];
  2641. for(let i = 0; i < response.length; i++){
  2642. const date = new Date(response[i].date);
  2643. let newDate = {
  2644. date: date,
  2645. transactions: []
  2646. };
  2647. for(let j = 0; j < response[i].transactions.length; j++){
  2648. newDate.transactions.push(new Transaction(
  2649. response[i].transactions[j]._id,
  2650. date,
  2651. response[i].transactions[j].recipes,
  2652. merchant
  2653. ));
  2654. }
  2655. this.transactionsByDate.push(newDate);
  2656. }
  2657. }
  2658. })
  2659. .catch((err)=>{
  2660. banner.createError("UNABLE TO UPDATE THE PAGE");
  2661. })
  2662. .finally(()=>{
  2663. loader.style.display = "none";
  2664. });
  2665. },
  2666. displayIngredient: function(ingredient){
  2667. //break down data into dates and quantities
  2668. let dates = [];
  2669. let quantities = [];
  2670. for(let i = 0; i < this.transactionsByDate.length; i++){
  2671. dates.push(this.transactionsByDate[i].date);
  2672. let sum = 0;
  2673. for(let j = 0; j < this.transactionsByDate[i].transactions.length; j++){
  2674. let transactions = this.transactionsByDate[i].transactions[j];
  2675. sum += transactions.getIngredientQuantity(this.ingredient);
  2676. }
  2677. quantities.push(sum);
  2678. }
  2679. //create and display the graph
  2680. let trace = {
  2681. x: dates,
  2682. y: quantities,
  2683. mode: "lines+markers",
  2684. line: {
  2685. color: "rgb(255, 99, 107)"
  2686. }
  2687. }
  2688. const layout = {
  2689. title: this.ingredient.name.toUpperCase(),
  2690. xaxis: {title: "DATE"},
  2691. yaxis: {title: `QUANTITY (${this.ingredient.unit.toUpperCase()})`}
  2692. }
  2693. Plotly.newPlot("itemUseGraph", [trace], layout);
  2694. //Create min/max/avg
  2695. //Current ingredient is stored on the "analMinUse" element
  2696. let min = quantities[0];
  2697. let max = quantities[0];
  2698. let sum = 0;
  2699. for(let i = 0; i < quantities.length; i++){
  2700. if(quantities[i] < min){
  2701. min = quantities[i];
  2702. }
  2703. if(quantities[i] > max){
  2704. max = quantities[i];
  2705. }
  2706. sum += quantities[i];
  2707. }
  2708. document.getElementById("analMinUse").innerText = `${min.toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2709. document.getElementById("analAvgUse").innerText = `${(sum / quantities.length).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2710. document.getElementById("analMaxUse").innerText = `${max.toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2711. //Create weekday averages
  2712. let dayUse = [0, 0, 0, 0, 0, 0, 0];
  2713. let dayCount = [0, 0, 0, 0, 0, 0, 0];
  2714. for(let i = 0; i < quantities.length; i++){
  2715. dayUse[dates[i].getDay()] += quantities[i];
  2716. dayCount[dates[i].getDay()]++;
  2717. }
  2718. document.getElementById("analDayOne").innerText = `${(dayUse[0] / dayCount[0]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2719. document.getElementById("analDayTwo").innerText = `${(dayUse[1] / dayCount[1]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2720. document.getElementById("analDayThree").innerText = `${(dayUse[2] / dayCount[2]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2721. document.getElementById("analDayFour").innerText = `${(dayUse[3] / dayCount[3]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2722. document.getElementById("analDayFive").innerText = `${(dayUse[4] / dayCount[4]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2723. document.getElementById("analDaySix").innerText = `${(dayUse[5] / dayCount[5]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2724. document.getElementById("analDaySeven").innerText = `${(dayUse[6] / dayCount[6]).toFixed(2)} ${this.ingredient.unit.toUpperCase()}`;
  2725. },
  2726. displayRecipe: function(){
  2727. //break down data into dates and quantities
  2728. let dates = [];
  2729. let quantities = [];
  2730. for(let i = 0; i < this.transactionsByDate.length; i++){
  2731. dates.push(this.transactionsByDate[i].date);
  2732. let sum = 0;
  2733. for(let j = 0; j < this.transactionsByDate[i].transactions.length; j++){
  2734. const transaction = this.transactionsByDate[i].transactions[j];
  2735. for(let k = 0; k < transaction.recipes.length; k++){
  2736. if(transaction.recipes[k].recipe === this.recipe){
  2737. sum += transaction.recipes[k].quantity;
  2738. }
  2739. }
  2740. }
  2741. quantities.push(sum);
  2742. }
  2743. //create and display the graph
  2744. const trace = {
  2745. x: dates,
  2746. y: quantities,
  2747. mode: "lines+markers",
  2748. line: {
  2749. color: "rgb(255, 99, 107)"
  2750. }
  2751. }
  2752. const layout = {
  2753. title: this.recipe.name.toUpperCase(),
  2754. xaxis: {title: "DATE"},
  2755. yaxis: {title: "QUANTITY"}
  2756. }
  2757. Plotly.newPlot("recipeSalesGraph", [trace], layout);
  2758. //Display the boxes at the bottom
  2759. //Current recipe is stored on the "recipeAvgUse" element
  2760. let avg = 0;
  2761. for(let i = 0; i < quantities.length; i++){
  2762. avg += quantities[i];
  2763. }
  2764. avg = avg / quantities.length;
  2765. document.getElementById("recipeAvgUse").innerText = avg.toFixed(2);
  2766. document.getElementById("recipeAvgRevenue").innerText = `$${(avg * this.recipe.price).toFixed(2)}`
  2767. },
  2768. switchDisplay: function(){
  2769. const checkbox = document.getElementById("analSlider");
  2770. let ingredient = document.getElementById("analIngredientContent");
  2771. let recipe = document.getElementById("analRecipeContent");
  2772. if(checkbox.checked === true){
  2773. ingredient.style.display = "none";
  2774. recipe.style.display = "flex";
  2775. this.displayRecipe();
  2776. }else{
  2777. ingredient.style.display = "flex";
  2778. recipe.style.display = "none";
  2779. this.displayIngredient();
  2780. }
  2781. },
  2782. newDates: async function(Transaction){
  2783. const from = document.getElementById("analStartDate").valueAsDate;
  2784. const to = document.getElementById("analEndDate").valueAsDate;
  2785. await this.getData(from, to, Transaction);
  2786. if(document.getElementById("analSlider").checked === true){
  2787. this.displayRecipe();
  2788. }else{
  2789. this.displayIngredient();
  2790. }
  2791. }
  2792. }
  2793. module.exports = analytics;
  2794. },{}],20:[function(require,module,exports){
  2795. let home = {
  2796. isPopulated: false,
  2797. display: function(){
  2798. if(!this.isPopulated){
  2799. this.drawRevenueCard();
  2800. this.drawRevenueGraph();
  2801. this.drawInventoryCheckCard();
  2802. this.drawPopularCard();
  2803. this.isPopulated = true;
  2804. }
  2805. },
  2806. drawRevenueCard: function(){
  2807. let today = new Date();
  2808. let firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
  2809. let firstOfLastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
  2810. let lastMonthToDay = new Date(new Date().setMonth(today.getMonth() - 1));
  2811. const revenueThisMonth = merchant.getRevenue(firstOfMonth);
  2812. const revenueLastMonthToDay = merchant.getRevenue(firstOfLastMonth, lastMonthToDay);
  2813. document.getElementById("revenue").innerText = `$${revenueThisMonth.toFixed(2)}`;
  2814. let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
  2815. let img = "";
  2816. if(revenueChange >= 0){
  2817. img = "/shared/images/upArrow.png";
  2818. }else{
  2819. img = "/shared/images/downArrow.png";
  2820. }
  2821. document.querySelector("#revenueChange p").innerText = `${Math.abs(revenueChange).toFixed(2)}% vs last month`;
  2822. document.querySelector("#revenueChange img").src = img;
  2823. },
  2824. drawRevenueGraph: function(){
  2825. let monthAgo = new Date();
  2826. monthAgo.setMonth(monthAgo.getMonth() - 1);
  2827. let revenue = [];
  2828. let dates = [];
  2829. let dayRevenue = 0;
  2830. const transactions = merchant.getTransactions(monthAgo);
  2831. let currentDate = (transactions.length > 0) ? transactions[0].date : undefined;
  2832. for(let i = 0; i < transactions.length; i++){
  2833. if(transactions[i].date.getDate() !== currentDate.getDate()){
  2834. revenue.push(dayRevenue / 100);
  2835. dayRevenue = 0;
  2836. dates.push(currentDate);
  2837. currentDate = transactions[i].date;
  2838. }
  2839. for(let j = 0; j < transactions[i].recipes.length; j++){
  2840. const recipe = transactions[i].recipes[j];
  2841. dayRevenue += recipe.recipe.price * recipe.quantity;
  2842. }
  2843. }
  2844. const trace = {
  2845. x: dates,
  2846. y: revenue,
  2847. mode: "lines+markers",
  2848. line: {
  2849. color: "rgb(255, 99, 107)"
  2850. }
  2851. }
  2852. const layout = {
  2853. title: "REVENUE",
  2854. xaxis: {
  2855. title: "DATE"
  2856. },
  2857. yaxis: {
  2858. title: "$"
  2859. }
  2860. }
  2861. Plotly.newPlot("graphCard", [trace], layout);
  2862. },
  2863. drawInventoryCheckCard: function(){
  2864. let num;
  2865. if(merchant.ingredients.length < 5){
  2866. num = merchant.ingredients.length;
  2867. }else{
  2868. num = 5;
  2869. }
  2870. let rands = [];
  2871. for(let i = 0; i < num; i++){
  2872. let rand = Math.floor(Math.random() * merchant.ingredients.length);
  2873. if(rands.includes(rand)){
  2874. i--;
  2875. }else{
  2876. rands[i] = rand;
  2877. }
  2878. }
  2879. let ul = document.querySelector("#inventoryCheckCard ul");
  2880. let template = document.getElementById("ingredientCheck").content.children[0];
  2881. while(ul.children.length > 0){
  2882. ul.removeChild(ul.firstChild);
  2883. }
  2884. for(let i = 0; i < rands.length; i++){
  2885. let ingredientCheck = template.cloneNode(true);
  2886. let input = ingredientCheck.children[1].children[1];
  2887. const ingredient = merchant.ingredients[rands[i]];
  2888. ingredientCheck.ingredient = ingredient;
  2889. ingredientCheck.children[0].innerText = ingredient.ingredient.name;
  2890. ingredientCheck.children[1].children[0].onclick = ()=>{
  2891. input.value--;
  2892. input.changed = true;
  2893. };
  2894. if(ingredient.ingredient.specialUnit === "bottle"){
  2895. input.value = ingredient.quantity.toFixed(2);
  2896. ingredientCheck.children[2].innerText = "BOTTLES";
  2897. }else{
  2898. input.value = ingredient.quantity.toFixed(2);
  2899. ingredientCheck.children[2].innerText = ingredient.ingredient.unit.toUpperCase();
  2900. }
  2901. ingredientCheck.children[1].children[2].onclick = ()=>{
  2902. input.value++;
  2903. input.changed = true;
  2904. }
  2905. input.onchange = ()=>{input.changed = true};
  2906. ul.appendChild(ingredientCheck);
  2907. }
  2908. document.getElementById("inventoryCheck").onclick = ()=>{this.submitInventoryCheck()};
  2909. },
  2910. drawPopularCard: function(){
  2911. let thisMonth = new Date();
  2912. thisMonth.setDate(1);
  2913. const ingredientList = merchant.getIngredientsSold(thisMonth);
  2914. if(ingredientList !== false){
  2915. ingredientList.sort((a, b)=>{
  2916. if(a.quantity < b.quantity){
  2917. return 1;
  2918. }
  2919. if(a.quantity > b.quantity){
  2920. return -1;
  2921. }
  2922. return 0;
  2923. });
  2924. let quantities = [];
  2925. let labels = [];
  2926. let colors = [];
  2927. let count = (ingredientList.length < 5) ? ingredientList.length - 1 : 4;
  2928. for(let i = count; i >= 0; i--){
  2929. const ingredientName = ingredientList[i].ingredient.name;
  2930. const ingredientQuantity = ingredientList[i].quantity;
  2931. const unitName = ingredientList[i].ingredient.unit;
  2932. quantities.push(ingredientList[i].quantity);
  2933. labels.push(`${ingredientName}: ${ingredientQuantity.toFixed(2)} ${unitName.toUpperCase()}`);
  2934. if(i === 0){
  2935. colors.push("rgb(255, 99, 107");
  2936. }else{
  2937. colors.push("rgb(179, 191, 209");
  2938. }
  2939. }
  2940. let trace = {
  2941. x: quantities,
  2942. type: "bar",
  2943. orientation: "h",
  2944. text: labels,
  2945. textposition: "auto",
  2946. hoverinfo: "none",
  2947. marker: {
  2948. color: colors
  2949. }
  2950. }
  2951. let layout = {
  2952. title: "MOST POPULAR INGREDIENTS",
  2953. xaxis: {
  2954. zeroline: false,
  2955. title: "QUANTITY"
  2956. },
  2957. yaxis: {
  2958. showticklabels: false
  2959. }
  2960. }
  2961. Plotly.newPlot("popularIngredientsCard", [trace], layout);
  2962. }else{
  2963. document.getElementById("popularCanvas").style.display = "none";
  2964. let notice = document.createElement("p");
  2965. notice.innerText = "N/A";
  2966. notice.classList = "notice";
  2967. document.getElementById("popularIngredientsCard").appendChild(notice);
  2968. }
  2969. },
  2970. //Need to change the updating of ingredients
  2971. //should update the ingredient directly, then send that. Maybe...
  2972. submitInventoryCheck: function(){
  2973. let lis = document.querySelectorAll("#inventoryCheckCard li");
  2974. let data = [];
  2975. for(let i = 0; i < lis.length; i++){
  2976. if(lis[i].children[1].children[1].value >= 0){
  2977. if(lis[i].children[1].children[1].changed === true){
  2978. let merchIngredient = lis[i].ingredient;
  2979. data.push({
  2980. id: merchIngredient.ingredient.id,
  2981. quantity: lis[i].children[1].children[1].value
  2982. });
  2983. lis[i].children[1].children[1].changed = false;
  2984. }
  2985. }else{
  2986. banner.createError("CANNOT HAVE NEGATIVE INGREDIENTS");
  2987. return;
  2988. }
  2989. }
  2990. if(data.length > 0){
  2991. let loader = document.getElementById("loaderContainer");
  2992. loader.style.display = "flex";
  2993. fetch("/merchant/ingredients/update", {
  2994. method: "PUT",
  2995. headers: {
  2996. "Content-Type": "application/json;charset=utf-8"
  2997. },
  2998. body: JSON.stringify(data)
  2999. })
  3000. .then(response => response.json())
  3001. .then((response)=>{
  3002. if(typeof(response) === "string"){
  3003. banner.createError(response);
  3004. }else{
  3005. for(let i = 0; i < response.length; i++){
  3006. merchant.removeIngredient(merchant.getIngredient(response[i].ingredient._id));
  3007. merchant.addIngredient(response[i].ingredient, response[i].quantity, response[i].defaultUnit);
  3008. }
  3009. banner.createNotification("INGREDIENTS UPDATED");
  3010. }
  3011. })
  3012. .catch((err)=>{
  3013. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  3014. })
  3015. .finally(()=>{
  3016. loader.style.display = "none";
  3017. });
  3018. }
  3019. }
  3020. }
  3021. module.exports = home;
  3022. },{}],21:[function(require,module,exports){
  3023. let ingredients = {
  3024. isPopulated: false,
  3025. ingredients: [],
  3026. display: function(){
  3027. if(!this.isPopulated){
  3028. document.getElementById("ingredientSearch").oninput = ()=>{this.search()};
  3029. this.populateByProperty();
  3030. this.isPopulated = true;
  3031. }
  3032. },
  3033. populateByProperty: function(){
  3034. let categories;
  3035. categories = merchant.categorizeIngredients();
  3036. let ingredientStrand = document.getElementById("categoryList");
  3037. let categoryTemplate = document.getElementById("categoryDiv").content.children[0];
  3038. let ingredientTemplate = document.getElementById("ingredient").content.children[0];
  3039. this.ingredients = [];
  3040. while(ingredientStrand.children.length > 0){
  3041. ingredientStrand.removeChild(ingredientStrand.firstChild);
  3042. }
  3043. for(let i = 0; i < categories.length; i++){
  3044. let categoryDiv = categoryTemplate.cloneNode(true);
  3045. categoryDiv.children[0].children[0].innerText = categories[i].name.toUpperCase();
  3046. categoryDiv.children[0].onclick = ()=>{
  3047. this.toggleCategory(categoryDiv.children[1], categoryDiv.children[0].children[1]);
  3048. };
  3049. categoryDiv.children[1].style.display = "none";
  3050. ingredientStrand.appendChild(categoryDiv);
  3051. for(let j = 0; j < categories[i].ingredients.length; j++){
  3052. let ingredient = categories[i].ingredients[j];
  3053. let ingredientDiv = ingredientTemplate.cloneNode(true);
  3054. ingredientDiv.children[0].innerText = ingredient.ingredient.name;
  3055. ingredientDiv.onclick = ()=>{
  3056. controller.openSidebar("ingredientDetails", ingredient);
  3057. ingredientDiv.classList.add("active");
  3058. };
  3059. ingredientDiv._name = ingredient.ingredient.name.toLowerCase();
  3060. ingredientDiv._unit = ingredient.ingredient.unit.toLowerCase();
  3061. if(ingredient.ingredient.specialUnit === "bottle"){
  3062. ingredientDiv.children[2].innerText = `${ingredient.quantity.toFixed(2)} BOTTLES`
  3063. }else{
  3064. ingredientDiv.children[2].innerText = `${ingredient.quantity.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
  3065. }
  3066. categoryDiv.children[1].appendChild(ingredientDiv);
  3067. this.ingredients.push(ingredientDiv);
  3068. }
  3069. }
  3070. },
  3071. displayIngredientsOnly: function(ingredients){
  3072. let ingredientDiv = document.getElementById("categoryList");
  3073. while(ingredientDiv.children.length > 0){
  3074. ingredientDiv.removeChild(ingredientDiv.firstChild);
  3075. }
  3076. for(let i = 0; i < ingredients.length; i++){
  3077. ingredientDiv.appendChild(ingredients[i]);
  3078. }
  3079. },
  3080. toggleCategory: function(div, button){
  3081. if(div.style.display === "none"){
  3082. 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>';
  3083. div.style.display = "flex";
  3084. }else if(div.style.display === "flex"){
  3085. 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>';
  3086. div.style.display = "none";
  3087. }
  3088. },
  3089. search: function(){
  3090. let input = document.getElementById("ingredientSearch").value.toLowerCase();
  3091. if(input === ""){
  3092. this.populateByProperty();
  3093. return;
  3094. }
  3095. let matchingIngredients = [];
  3096. for(let i = 0; i < this.ingredients.length; i++){
  3097. if(this.ingredients[i]._name.includes(input)){
  3098. matchingIngredients.push(this.ingredients[i]);
  3099. }
  3100. }
  3101. this.displayIngredientsOnly(matchingIngredients);
  3102. }
  3103. }
  3104. module.exports = ingredients;
  3105. },{}],22:[function(require,module,exports){
  3106. let orders = {
  3107. display: function(){
  3108. document.getElementById("orderFilterBtn").onclick = ()=>{controller.openSidebar("orderFilter")};
  3109. document.getElementById("newOrderBtn").onclick = ()=>{controller.openSidebar("newOrder")};
  3110. let orderList = document.getElementById("orderList");
  3111. let template = document.getElementById("order").content.children[0];
  3112. while(orderList.children.length > 0){
  3113. orderList.removeChild(orderList.firstChild);
  3114. }
  3115. for(let i = 0; i < merchant.orders.length; i++){
  3116. let orderDiv = template.cloneNode(true);
  3117. orderDiv.order = merchant.orders[i];
  3118. orderDiv.children[0].innerText = merchant.orders[i].name;
  3119. orderDiv.children[1].innerText = `${merchant.orders[i].ingredients.length} ingredients`;
  3120. orderDiv.children[2].innerText = merchant.orders[i].date.toLocaleDateString("en-US");
  3121. orderDiv.children[3].innerText = `$${merchant.orders[i].getTotalCost().toFixed(2)}`;
  3122. orderDiv.onclick = ()=>{
  3123. controller.openSidebar("orderDetails", merchant.orders[i]);
  3124. orderDiv.classList.add("active");
  3125. }
  3126. orderList.appendChild(orderDiv);
  3127. }
  3128. },
  3129. getOrders: function(Order){
  3130. let loader = document.getElementById("loaderContainer");
  3131. loader.style.display = "flex";
  3132. return fetch("/order", {
  3133. method: "get",
  3134. headers: {
  3135. "Content-Type": "application/json;charset=utf-8"
  3136. }
  3137. })
  3138. .then(response => response.json())
  3139. .then((response)=>{
  3140. if(typeof(response) === "string"){
  3141. banner.createError(response);
  3142. }else{
  3143. let orders = [];
  3144. for(let i = 0; i < response.length; i++){
  3145. orders.push(new Order(
  3146. response[i]._id,
  3147. response[i].name,
  3148. response[i].date,
  3149. response[i].taxes,
  3150. response[i].fees,
  3151. response[i].ingredients,
  3152. merchant
  3153. ));
  3154. }
  3155. if(merchant.orders.length === 0){
  3156. merchant.setOrders(orders);
  3157. }
  3158. return orders;
  3159. }
  3160. })
  3161. .catch((err)=>{
  3162. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  3163. })
  3164. .finally(()=>{
  3165. loader.style.display = "none";
  3166. });
  3167. }
  3168. }
  3169. module.exports = orders;
  3170. },{}],23:[function(require,module,exports){
  3171. let recipeBook = {
  3172. isPopulated: false,
  3173. recipeDivList: [],
  3174. display: function(Recipe){
  3175. if(!this.isPopulated){
  3176. this.populateRecipes();
  3177. if(merchant.pos !== "none"){
  3178. document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate(Recipe)};
  3179. }
  3180. document.getElementById("recipeSearch").oninput = ()=>{this.search()};
  3181. this.populateRecipes();
  3182. this.isPopulated = true;
  3183. }
  3184. },
  3185. populateRecipes: function(){
  3186. let recipeList = document.getElementById("recipeList");
  3187. let template = document.getElementById("recipe").content.children[0];
  3188. this.recipeDivList = [];
  3189. while(recipeList.children.length > 0){
  3190. recipeList.removeChild(recipeList.firstChild);
  3191. }
  3192. for(let i = 0; i < merchant.recipes.length; i++){
  3193. let recipeDiv = template.cloneNode(true);
  3194. recipeDiv.onclick = ()=>{
  3195. controller.openSidebar("recipeDetails", merchant.recipes[i]);
  3196. recipeDiv.classList.add("active");
  3197. }
  3198. recipeDiv._name = merchant.recipes[i].name;
  3199. recipeList.appendChild(recipeDiv);
  3200. recipeDiv.children[0].innerText = merchant.recipes[i].name;
  3201. recipeDiv.children[1].innerText = `$${merchant.recipes[i].price.toFixed(2)}`;
  3202. this.recipeDivList.push(recipeDiv);
  3203. }
  3204. },
  3205. search: function(){
  3206. let input = document.getElementById("recipeSearch").value.toLowerCase();
  3207. let recipeList = document.getElementById("recipeList");
  3208. let matchingRecipes = [];
  3209. for(let i = 0; i < this.recipeDivList.length; i++){
  3210. if(this.recipeDivList[i]._name.toLowerCase().includes(input)){
  3211. matchingRecipes.push(this.recipeDivList[i]);
  3212. }
  3213. }
  3214. while(recipeList.children.length > 0){
  3215. recipeList.removeChild(recipeList.firstChild);
  3216. }
  3217. for(let i = 0; i < matchingRecipes.length; i++){
  3218. recipeList.appendChild(matchingRecipes[i]);
  3219. }
  3220. },
  3221. posUpdate: function(Recipe){
  3222. let loader = document.getElementById("loaderContainer");
  3223. loader.style.display = "flex";
  3224. let url = `/recipe/update/${merchant.pos}`;
  3225. fetch(url, {
  3226. method: "GET",
  3227. headers: {
  3228. "Content-Type": "application/json;charset=utf-8"
  3229. },
  3230. })
  3231. .then(response => response.json())
  3232. .then((response)=>{
  3233. if(typeof(response) === "string"){
  3234. banner.createError(response);
  3235. }else{
  3236. for(let i = 0; i < response.new.length; i++){
  3237. const recipe = new Recipe(
  3238. response.new[i]._id,
  3239. response.new[i].name,
  3240. response.new[i].price,
  3241. merchant,
  3242. []
  3243. );
  3244. merchant.addRecipe(recipe);
  3245. }
  3246. for(let i = 0; i < response.removed.length; i++){
  3247. for(let j = 0; j < merchant.recipes.length; j++){
  3248. if(merchant.recipes[j].id === response.removed[i]._id){
  3249. merchant.removeRecipe(merchant.recipes[j]);
  3250. break;
  3251. }
  3252. }
  3253. }
  3254. this.display();
  3255. }
  3256. })
  3257. .catch((err)=>{
  3258. banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
  3259. })
  3260. .finally(()=>{
  3261. loader.style.display = "none";
  3262. });
  3263. }
  3264. }
  3265. module.exports = recipeBook;
  3266. },{}],24:[function(require,module,exports){
  3267. let transactions = {
  3268. transactions: [],
  3269. display: function(Transaction){
  3270. document.getElementById("filterTransactionsButton").onclick = ()=>{controller.openSidebar("transactionFilter")};
  3271. document.getElementById("newTransactionButton").onclick = ()=>{controller.openSidebar("newTransaction")};
  3272. this.populateTransactions(this.transactions);
  3273. this.isPopulated = true;
  3274. },
  3275. populateTransactions: function(transactions){
  3276. let transactionsList = document.getElementById("transactionsList");
  3277. let template = document.getElementById("transaction").content.children[0];
  3278. while(transactionsList.children.length > 0){
  3279. transactionsList.removeChild(transactionsList.firstChild);
  3280. }
  3281. let i = 0;
  3282. while(i < transactions.length && i < 100){
  3283. let transactionDiv = template.cloneNode(true);
  3284. let transaction = transactions[i];
  3285. transactionDiv.onclick = ()=>{
  3286. controller.openSidebar("transactionDetails", transaction);
  3287. transactionDiv.classList.add("active");
  3288. }
  3289. transactionsList.appendChild(transactionDiv);
  3290. let totalRecipes = 0;
  3291. let totalPrice = 0;
  3292. for(let j = 0; j < transactions[i].recipes.length; j++){
  3293. totalRecipes += transactions[i].recipes[j].quantity;
  3294. totalPrice += transactions[i].recipes[j].recipe.price * transactions[i].recipes[j].quantity;
  3295. }
  3296. transactionDiv.children[0].innerText = `${transactions[i].date.toLocaleDateString()} ${transactions[i].date.toLocaleTimeString()}`;
  3297. transactionDiv.children[1].innerText = `${totalRecipes} recipes sold`;
  3298. transactionDiv.children[2].innerText = `$${totalPrice.toFixed(2)}`;
  3299. i++;
  3300. }
  3301. }
  3302. }
  3303. module.exports = transactions;
  3304. },{}]},{},[6]);