Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Budget financial year #1965

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions app/src/main/java/com/money/manager/ex/budget/BudgetAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@
import com.money.manager.ex.Constants;
import com.money.manager.ex.MmexApplication;
import com.money.manager.ex.R;
import com.money.manager.ex.core.InfoKeys;
import com.money.manager.ex.core.UIHelper;
import com.money.manager.ex.currency.CurrencyService;
import com.money.manager.ex.database.QueryMobileData;
import com.money.manager.ex.datalayer.BudgetEntryRepository;
import com.money.manager.ex.domainmodel.BudgetEntry;
import com.money.manager.ex.nestedcategory.QueryNestedCategory;
import com.money.manager.ex.servicelayer.InfoService;
import com.money.manager.ex.settings.AppSettings;
import com.money.manager.ex.utils.MmxDate;
import com.squareup.sqlbrite3.BriteDatabase;

import java.util.Date;
import java.util.HashMap;

import javax.inject.Inject;
Expand Down Expand Up @@ -82,10 +86,16 @@ public BudgetAdapter(Context context, Cursor cursor, String[] from, int[] to, in

MmexApplication.getApp().iocComponent.inject(this);

// get Budget financial
try {
useBudgetFinancialYear = (new AppSettings(getContext()).getBudgetSettings().getBudgetFinancialYear());
} catch (Exception e) {
}

}

@Inject Lazy<BriteDatabase> databaseLazy;

private boolean useBudgetFinancialYear = false;
private final int mLayout;
private String mBudgetName;
private long mBudgetYearId;
Expand Down Expand Up @@ -266,15 +276,23 @@ private double getAmountForSubCategory(long subCategoryId) {
private double loadTotalFor(String where) {
double total = 0;

long year = getYearFromBudgetName(mBudgetName);
where += " AND " + QueryMobileData.Year + "=" + year;
long month = getMonthFromBudgetName(mBudgetName);
if (month != Constants.NOT_SET) {
where += " AND " + QueryMobileData.Month + "=" + month;
//use financia year
if (!useBudgetFinancialYear) {
long year = getYearFromBudgetName(mBudgetName);
where += " AND " + QueryMobileData.Year + "=" + year;
long month = getMonthFromBudgetName(mBudgetName);
if (month != Constants.NOT_SET) {
where += " AND " + QueryMobileData.Month + "=" + month;
}
} else {
MmxDate dateFrom = getStartDateForFinancialYear(mBudgetName);
MmxDate dateTo = new MmxDate(dateFrom.toDate());
dateTo.addYear(1).minusDays(1);
where += " AND " + QueryMobileData.Date + " BETWEEN '" + dateFrom.toIsoDateString() + "' AND '" + dateTo.toIsoDateString() + "'";
}

try {
// wolfsolver todo adapt query for nested category
// wolfsolver adapt query for nested category
String query = prepareQuery(where);
Cursor cursor = databaseLazy.get().query(query);
if (cursor == null) return 0;
Expand Down Expand Up @@ -334,6 +352,20 @@ private long getYearFromBudgetName(String budgetName) {
return year;
}

private MmxDate getStartDateForFinancialYear(String budgetName) {
MmxDate newDate = MmxDate.newDate();
try {
InfoService infoService = new InfoService(getContext());
int financialYearStartDay = new Integer(infoService.getInfoValue(InfoKeys.FINANCIAL_YEAR_START_DAY, "1"));
int financialYearStartMonth = new Integer(infoService.getInfoValue(InfoKeys.FINANCIAL_YEAR_START_MONTH, "0")) - 1;
newDate.setYear((int)getYearFromBudgetName(budgetName));
newDate.setDate(financialYearStartDay);
newDate.setMonth(financialYearStartMonth);
} catch (Exception e) {
}
return newDate;
}

private boolean isMonthlyBudget(String budgetName) {
return budgetName.contains("-");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public void setShowSimpleView(boolean value) {
set(R.string.pref_budget_show_simple_view, value);
}

public Boolean getBudgetFinancialYear( ) {
return get(R.string.pref_budget_financial_year, false);
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values/prefids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<string name="pref_budget">pref_budgets</string>
<string name="pref_budget_show_simple_view">pref_budget_show_simple_view</string>
<string name="pref_budget_load_current">pref_budget_load_current</string>
<string name="pref_budget_financial_year">pref_budget_financial_year</string>

<!-- dropbox / deprecated -->
<string name="pref_dropbox_download">dropbox2download</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@

<string name="title_budget_show_simple_view">Show simple budget view</string>
<string name="summary_budget_show_simple_view">If checked budgets use the simplified view</string>

<string name="title_pref_budget_financial_year">Use financial year in budget</string>
<string name="summary_pref_budget_financial_year">If checked budgets use financial year instead of calendar year</string>


<string name="shares">Shares</string>
<string name="loan">Loan</string>
<string name="loan_account">Loan Accounts</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences_budget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@
android:summary="@string/summary_budget_show_simple_view"
android:title="@string/title_budget_show_simple_view" />

<SwitchPreferenceCompat
android:icon="@null"
android:defaultValue="false"
android:key="@string/pref_budget_financial_year"
android:summary="@string/summary_pref_budget_financial_year"
android:title="@string/title_pref_budget_financial_year" />

</PreferenceScreen>
Loading