Skip to content

Commit

Permalink
Compute correct budget with category and Every 2 Months periods.
Browse files Browse the repository at this point in the history
close issue #1566
  • Loading branch information
wolfsolver committed Feb 10, 2024
1 parent d42df5c commit 50e1ef3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ public void setBudgetYearId(long budgetYearId) {

private double getActualAmount(boolean hasSubcategory, Cursor cursor) {
double actual;
// wolfsolver since category can be neested we need to consider always category as master
// probabily until we don't handle third and other level actual value does not count correctlry
if (!hasSubcategory) {
int categoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.CATEGID));
actual = getAmountForCategory(categoryId);
} else {
int subCategoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.SUBCATEGID));
actual = getAmountForSubCategory(subCategoryId);
actual = getAmountForCategory(subCategoryId);
// actual = getAmountForSubCategory(subCategoryId);
}
return actual;
}
Expand Down Expand Up @@ -270,6 +273,7 @@ private double loadTotalFor(String where) {
}

try {
// wolfsolver todo adapt query for nested category
String query = prepareQuery(where);
Cursor cursor = databaseLazy.get().query(query);
if (cursor == null) return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static BudgetPeriodEnum getEnum(String periodString) {
periodEnumLookup.put("Bi-Weekly" , BudgetPeriodEnum.BI_WEEKLY);
periodEnumLookup.put("Monthly" , BudgetPeriodEnum.MONTHLY);
periodEnumLookup.put("Bi-Monthly" , BudgetPeriodEnum.BI_MONTHLY);
periodEnumLookup.put("Every 2 Months" , BudgetPeriodEnum.BI_MONTHLY); // wolfsolver adapt periods
periodEnumLookup.put("Quarterly" , BudgetPeriodEnum.QUARTERLY);
periodEnumLookup.put("Half-Yearly", BudgetPeriodEnum.HALF_YEARLY);
periodEnumLookup.put("Yearly" , BudgetPeriodEnum.YEARLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public BudgetEntry load(int id) {
* @return
*/
public static String getKeyForCategories(int categoryId, int subCategoryId) {
return categoryId + "_" + subCategoryId;
// Wolfsolver - adapt budget for category & sub category.
if (categoryId < 0 ) {
return "_"+subCategoryId;
}
if ( subCategoryId < 0 ) {
return "_" + categoryId;
}
return "_" + subCategoryId;
}

public HashMap<String, BudgetEntry> loadForYear(long budgetYearId) {
Expand Down Expand Up @@ -99,11 +106,16 @@ public HashMap<String, BudgetEntry> loadForYear(long budgetYearId) {
if (category == null) {
continue;
}
if (category.getParentId() > 0) {
budgetEntryHashMap.put(getKeyForCategories(categoryId, category.getParentId()), budgetEntry);
} else {
budgetEntryHashMap.put(getKeyForCategories(categoryId, categoryId), budgetEntry);
}
// wolfsolver - GetKeyForCatgories has 2 parametrs:
// (int categoryId, int subCategoryId)
// it's wrong to user getParentId for subcategory, need to switch parameterd
// also delegate to GetKeyForCategory logic for handle -1
// if (category.getParentId() > 0) {
// budgetEntryHashMap.put(getKeyForCategories(categoryId, category.getParentId()), budgetEntry);
// } else {
// budgetEntryHashMap.put(getKeyForCategories(categoryId, categoryId), budgetEntry);
// }
budgetEntryHashMap.put(getKeyForCategories(category.getParentId(), categoryId), budgetEntry);
}
cursor.close();

Expand Down

0 comments on commit 50e1ef3

Please sign in to comment.