mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 19:16:51 +00:00
Add code for budgets
This commit is contained in:
12
frontend/src/api/v2/budgets/sum.js
vendored
12
frontend/src/api/v2/budgets/sum.js
vendored
@@ -29,10 +29,10 @@ export default class Sum {
|
||||
return api.get(url, {params: {start: startStr, end: endStr}});
|
||||
}
|
||||
|
||||
// /*paid(start, end) {
|
||||
// let url = 'api/v2/bills/sum/paid';
|
||||
// let startStr = format(start, 'y-MM-dd');
|
||||
// let endStr = format(end, 'y-MM-dd');
|
||||
// return api.get(url, {params: {start: startStr, end: endStr}});
|
||||
// }*/
|
||||
spent(start, end) {
|
||||
let url = 'api/v2/budgets/sum/spent';
|
||||
let startStr = format(start, 'y-MM-dd');
|
||||
let endStr = format(end, 'y-MM-dd');
|
||||
return api.get(url, {params: {start: startStr, end: endStr}});
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@
|
||||
<q-card bordered>
|
||||
<q-item>
|
||||
<q-item-section>
|
||||
<q-item-label><strong>Spend</strong></q-item-label>
|
||||
<q-item-label><strong>To spend and left</strong></q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-separator/>
|
||||
@@ -48,6 +48,10 @@
|
||||
<span :title="formatAmount(this.currency, this.budgetedAmount)">Budgeted</span>:
|
||||
<span v-for="(budget, index) in budgeted"><span v-if="budget.native">(</span>{{ formatAmount(budget.code, budget.sum) }}<span v-if="budget.native">)</span><span
|
||||
v-if="index+1 !== budgeted.length">, </span></span>
|
||||
<br>
|
||||
<span :title="formatAmount(this.currency, this.spentAmount)">Spent</span>:
|
||||
<span v-for="(budget, index) in spent"><span v-if="budget.native">(</span>{{ formatAmount(budget.code, budget.sum) }}<span v-if="budget.native">)</span><span
|
||||
v-if="index+1 !== budgeted.length">, </span></span>
|
||||
</q-card-section>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
@@ -118,7 +122,7 @@ export default {
|
||||
const sum = new Sum;
|
||||
this.currency = this.store.getCurrencyCode;
|
||||
sum.budgeted(start, end).then((response) => this.parseBudgetedResponse(response.data));
|
||||
//sum.paid(start, end).then((response) => this.parsePaidResponse(response.data));
|
||||
sum.spent(start, end).then((response) => this.parseSpentResponse(response.data));
|
||||
}
|
||||
},
|
||||
// TODO this method is recycled a lot.
|
||||
@@ -143,6 +147,24 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
parseSpentResponse: function (data) {
|
||||
for (let i in data) {
|
||||
if (data.hasOwnProperty(i)) {
|
||||
const current = data[i];
|
||||
const hasNative = current.native_id !== current.id && parseFloat(current.native_sum) !== 0.0;
|
||||
this.spent.push(
|
||||
{
|
||||
sum: current.sum,
|
||||
code: current.code,
|
||||
native: hasNative
|
||||
}
|
||||
);
|
||||
if (hasNative || current.native_id === current.id) {
|
||||
this.spentAmount = this.spentAmount + (parseFloat(current.native_sum) * -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user