76
76
</tbody >
77
77
<tfoot >
78
78
<tr >
79
- <td ></td >
79
+ <td >
80
+ Copy entire budget from:
81
+ <select
82
+ class =" select"
83
+ @change =" processDuplicateBudget($event.target.value)"
84
+ >
85
+ <option
86
+ v-for =" value, key in budgets"
87
+ :value =" key"
88
+ >
89
+ {{ value.month | moment }}
90
+ </option >
91
+ </select >
92
+ </td >
80
93
<td >${{ selectedBudget.budgeted }}</td >
81
94
<td >${{ selectedBudget.spent }}</td >
82
95
<td >${{ selectedBudget.budgeted - selectedBudget.spent }}</td >
92
105
</template >
93
106
94
107
<script >
95
- import { mapActions , mapGetters } from ' vuex' ;
108
+ import { mapActions , mapGetters , mapState } from ' vuex' ;
96
109
import Datepicker from ' vuejs-datepicker' ;
97
110
98
111
import CreateUpdateBudgetCategory from ' ./CreateUpdateBudgetCategory' ;
99
112
import BudgetCategory from ' ./BudgetCategory' ;
113
+ import { moment } from ' ../../../filters' ;
100
114
101
115
export default {
102
116
name: ' budget-create-edit-view' ,
@@ -111,10 +125,15 @@ export default {
111
125
return {
112
126
selectedBudget: {},
113
127
editing: false ,
114
- activeBudgetCategory: null
128
+ activeBudgetCategory: null ,
129
+ lastBudget: null
115
130
};
116
131
},
117
132
133
+ filters: {
134
+ moment
135
+ },
136
+
118
137
mounted () {
119
138
if (' budgetId' in this .$route .params ) {
120
139
this .loadBudgets ().then (() => {
@@ -125,6 +144,7 @@ export default {
125
144
}
126
145
});
127
146
}
147
+ this .lastBudget = this .getBudgetById (' d0862d23-e433-bb30-6088-09f0e2f9f221' );
128
148
},
129
149
130
150
methods: {
@@ -133,7 +153,8 @@ export default {
133
153
' updateBudget' ,
134
154
' loadBudgets' ,
135
155
' createBudgetCategory' ,
136
- ' updateBudgetCategory'
156
+ ' updateBudgetCategory' ,
157
+ ' duplicateBudget'
137
158
]),
138
159
139
160
resetAndGo () {
@@ -189,14 +210,29 @@ export default {
189
210
190
211
budgetCategoryComponent (budgetCategory ) {
191
212
return this .activeBudgetCategory && this .activeBudgetCategory === budgetCategory ? ' create-update-budget-category' : ' budget-category' ;
213
+ },
214
+
215
+ processDuplicateBudget (budgetId ) {
216
+ if (confirm (' Are you sure you want to duplicate this budget? Doing this will overwrite all existing data for this month (transaction data will NOT be erased).' )) {
217
+ this .duplicateBudget ({
218
+ budget: this .selectedBudget ,
219
+ baseBudget: this .getBudgetById (budgetId)
220
+ }).then ((budget ) => {
221
+ this .selectedBudget = budget;
222
+ });
223
+ }
192
224
}
193
225
},
194
226
195
227
computed: {
196
228
... mapGetters ([
197
229
' getBudgetById' ,
198
230
' getCategoryById'
199
- ])
231
+ ]),
232
+
233
+ ... mapState ({
234
+ ' budgets ' : state => state .budgets .budgets
235
+ })
200
236
}
201
237
};
202
238
</script >
0 commit comments