mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-27 17:48:17 -05:00
Goals: add flag to percent goals to use previous month income instead of this months (#1403)
This is a more elegant way of implementing a month ahead version of the percent goals. To use it add the `previous` flag to the percent goal, ex `#template 10% of previous Paycheck`.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// https://peggyjs.org
|
||||
|
||||
expr
|
||||
= priority: priority? _? percent: percent _ of _ category: name
|
||||
{ return { type: 'percentage', percent: +percent, category, priority: +priority }}
|
||||
= priority: priority? _? percentOf:percentOf category: name
|
||||
{ return { type: 'percentage', percent: +percentOf.percent, previous: percentOf.prev, category, priority: +priority }}
|
||||
/ priority: priority? _? amount: amount _ repeatEvery _ weeks: weekCount _ starting _ starting: date limit: limit?
|
||||
{ return { type: 'week', amount, weeks, starting, limit, priority: +priority }}
|
||||
/ priority: priority? _? amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)?
|
||||
@@ -33,6 +33,8 @@ repeat 'repeat interval'
|
||||
limit = _? upTo _ amount: amount _ 'hold'i { return {amount: amount, hold: true } }
|
||||
/ _? upTo _ amount: amount { return {amount: amount, hold: false } }
|
||||
|
||||
percentOf = percent:percent _ of _ 'previous'i _ { return { percent: percent, prev: true} }
|
||||
/ percent:percent _ of _ { return { percent: percent, prev: false} }
|
||||
|
||||
weekCount
|
||||
= week { return null }
|
||||
|
||||
@@ -554,8 +554,19 @@ async function applyCategoryTemplate(
|
||||
case 'percentage': {
|
||||
let percent = template.percent;
|
||||
let monthlyIncome = 0;
|
||||
|
||||
if (template.category.toLowerCase() === 'all income') {
|
||||
monthlyIncome = await getSheetValue(sheetName, `total-income`);
|
||||
if (template.previous) {
|
||||
let sheetName_lastmonth = monthUtils.sheetForMonth(
|
||||
monthUtils.addMonths(month, -1),
|
||||
);
|
||||
monthlyIncome = await getSheetValue(
|
||||
sheetName_lastmonth,
|
||||
'total-income',
|
||||
);
|
||||
} else {
|
||||
monthlyIncome = await getSheetValue(sheetName, `total-income`);
|
||||
}
|
||||
} else if (template.category.toLowerCase() === 'available funds') {
|
||||
monthlyIncome = available_start;
|
||||
} else {
|
||||
@@ -568,11 +579,22 @@ async function applyCategoryTemplate(
|
||||
errors.push(`Could not find category “${template.category}”`);
|
||||
return { errors };
|
||||
}
|
||||
monthlyIncome = await getSheetValue(
|
||||
sheetName,
|
||||
`sum-amount-${income_category.id}`,
|
||||
);
|
||||
if (template.previous) {
|
||||
let sheetName_lastmonth = monthUtils.sheetForMonth(
|
||||
monthUtils.addMonths(month, -1),
|
||||
);
|
||||
monthlyIncome = await getSheetValue(
|
||||
sheetName_lastmonth,
|
||||
`sum-amount-${income_category.id}`,
|
||||
);
|
||||
} else {
|
||||
monthlyIncome = await getSheetValue(
|
||||
sheetName,
|
||||
`sum-amount-${income_category.id}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let increment = Math.max(
|
||||
0,
|
||||
Math.round(monthlyIncome * (percent / 100)),
|
||||
|
||||
6
upcoming-release-notes/1403.md
Normal file
6
upcoming-release-notes/1403.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [youngcw]
|
||||
---
|
||||
|
||||
Goals: add "prev" flag to percent goal to use previous month income.
|
||||
Reference in New Issue
Block a user