bundle.js 119 KB

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