[Feature] Initial concept for adding percentage based goals (#858)

This is an initial concept for adding percent based goal targets.

This version works by using a string in the form of: 
#template 10% of Income <- Income is an income category name. Only
income category names will work here currently.
or
#template 10% of all income<- 'all income' is a keyword in this context
and will base the calculation on the total income for the month.

Some of the nicer touches like Jed's polite notification that the syntax
isn't correct is not implemented here yet.
This commit is contained in:
shall0pass
2023-04-22 10:44:07 -05:00
committed by GitHub
parent 0bcf6ea6f9
commit 3ceb2d92ad
2 changed files with 25 additions and 12 deletions

View File

@@ -337,19 +337,26 @@ async function applyCategoryTemplate(category, template_lines, month, force) {
break;
}
case 'percentage': {
/*
let income_category = (await actual.getCategories()).filter(c => c.is_income == true && c.name == template.category);
let func = (getBudgetMonthTestFunc || getBudgetMonth);
let budget = await func(month);
for (var g = 0; g < budget.categoryGroups.length; g++) {
if (income_category.group_id == budget.categoryGroups[g].id) {
for (var c = 0; c < budget.categoryGroups[g].categories.length; c++)
if (income_category.id == budget.categoryGroups[g].categories[c].id) {
let month_category = budget.categoryGroups[g].categories[c];
}
}
let percent = template.percent;
let monthlyIncome = 0;
if (template.category.toLowerCase() === 'all income') {
monthlyIncome = await getSheetValue(sheetName, `total-income`);
} else {
let income_category = (await db.getCategories()).find(
c =>
c.is_income &&
c.name.toLowerCase() === template.category.toLowerCase(),
);
if (!income_category) {
errors.push(`Could not find category “${template.category}`);
return { errors };
}
*/
monthlyIncome = await getSheetValue(
sheetName,
`sum-amount-${income_category.id}`,
);
}
to_budget = Math.max(0, Math.round(monthlyIncome * (percent / 100)));
break;
}
case 'error':

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [shall0pass]
---
Goals: Added support for percentage driven targets