Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new Vue({
- el: "#app",
- data: {
- entries: [],
- amount :"",
- date :"",
- input2: "",
- setBudget: 400
- },
- methods: {
- submitEntry: function(){
- var formEntry = {
- amount: parseFloat(this.amount),
- date: new moment(this.date)
- }
- this.entries.push(formEntry);
- this.amount = "";
- this.date = "";
- },
- changeBudget: function(){
- this.setBudget = parseFloat(this.input2);
- this.input2 = '';
- }
- },
- computed: {
- weeklyExp: function(){
- var expense = 0;
- this.entries.forEach(function(entry){
- if(entry.date.diff(moment().startOf('week'), 'days')>0 && entry.date.diff(moment().startOf('week'), 'days')<=7){
- expense -= entry.amount;
- }
- })
- return expense;
- },
- monthlyExp: function(){
- var expense = 0;
- this.entries.forEach(function(entry){
- if(entry.date.diff(moment().startOf('month'), 'days')>=0 && entry.date.diff(moment().startOf('week'), 'days')<=30){
- expense -= entry.amount;
- }
- })
- return expense;
- },
- yearlyExp: function(){
- var expense = 0;
- this.entries.forEach(function(entry){
- if(entry.date.diff(moment().startOf('year'), 'days')>=0 && entry.date.diff(moment().startOf('week'), 'days')<=365){
- expense -= entry.amount;
- }
- })
- return expense;
- },
- budgetRemaining: function(){
- return this.setBudget - this.monthlyExp;
- }
- }
- })
Add Comment
Please, Sign In to add comment