Guest User

Untitled

a guest
May 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. new Vue({
  2. el: "#app",
  3. data: {
  4. entries: [],
  5. amount :"",
  6. date :"",
  7. input2: "",
  8. setBudget: 400
  9.  
  10. },
  11. methods: {
  12. submitEntry: function(){
  13. var formEntry = {
  14. amount: parseFloat(this.amount),
  15. date: new moment(this.date)
  16. }
  17.  
  18. this.entries.push(formEntry);
  19. this.amount = "";
  20. this.date = "";
  21. },
  22.  
  23. changeBudget: function(){
  24. this.setBudget = parseFloat(this.input2);
  25. this.input2 = '';
  26. }
  27. },
  28. computed: {
  29.  
  30. weeklyExp: function(){
  31. var expense = 0;
  32. this.entries.forEach(function(entry){
  33.  
  34. if(entry.date.diff(moment().startOf('week'), 'days')>0 && entry.date.diff(moment().startOf('week'), 'days')<=7){
  35. expense -= entry.amount;
  36. }
  37. })
  38. return expense;
  39.  
  40. },
  41.  
  42. monthlyExp: function(){
  43. var expense = 0;
  44. this.entries.forEach(function(entry){
  45.  
  46. if(entry.date.diff(moment().startOf('month'), 'days')>=0 && entry.date.diff(moment().startOf('week'), 'days')<=30){
  47. expense -= entry.amount;
  48. }
  49. })
  50. return expense;
  51.  
  52. },
  53.  
  54. yearlyExp: function(){
  55. var expense = 0;
  56. this.entries.forEach(function(entry){
  57.  
  58. if(entry.date.diff(moment().startOf('year'), 'days')>=0 && entry.date.diff(moment().startOf('week'), 'days')<=365){
  59. expense -= entry.amount;
  60. }
  61. })
  62. return expense;
  63. },
  64.  
  65. budgetRemaining: function(){
  66. return this.setBudget - this.monthlyExp;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75. })
Add Comment
Please, Sign In to add comment