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

Reports too much empty space #228

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -885,19 +885,15 @@ private Money computeBalance(String accountUID, long startTimestamp, long endTim
*/
public Money getAccountsBalance(@NonNull List<String> accountUIDList, long startTimestamp, long endTimestamp) {
String currencyCode = GnuCashApplication.getDefaultCurrencyCode();
Money balance = Money.createZeroInstance(currencyCode);

if (accountUIDList.isEmpty())
return balance;
return Money.createZeroInstance(currencyCode);

boolean hasDebitNormalBalance = getAccountType(accountUIDList.get(0)).hasDebitNormalBalance();

SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
Money splitSum = (startTimestamp == -1 && endTimestamp == -1)
? splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance)
: splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);

return balance.plus(splitSum);
return splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ public Money computeSplitBalance(List<String> accountUIDList, String currencyCod

private Money calculateSplitBalance(List<String> accountUIDList, String currencyCode, boolean hasDebitNormalBalance,
long startTimestamp, long endTimestamp) {
if (accountUIDList.size() == 0) {
return new Money("0", currencyCode);
if (accountUIDList.isEmpty()) {
return Money.createZeroInstance(currencyCode);
}

Cursor cursor;
String[] selectionArgs = null;
String selection = DatabaseSchema.AccountEntry.TABLE_NAME + "_" + DatabaseSchema.CommonColumns.COLUMN_UID + " in ( '" + TextUtils.join("' , '", accountUIDList) + "' ) AND " +
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_TEMPLATE + " = 0";
Expand All @@ -210,12 +209,12 @@ private Money calculateSplitBalance(List<String> accountUIDList, String currency
selectionArgs = new String[]{String.valueOf(startTimestamp)};
}

cursor = mDb.query("trans_split_acct",
new String[]{"TOTAL ( CASE WHEN " + SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_TYPE + " = 'DEBIT' THEN " +
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_NUM + " ELSE - " +
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_NUM + " END )",
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_DENOM,
DatabaseSchema.AccountEntry.TABLE_NAME + "_" + DatabaseSchema.AccountEntry.COLUMN_CURRENCY},
String[] columns = new String[]{"TOTAL ( CASE WHEN " + SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_TYPE + " = 'DEBIT' THEN " +
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_NUM + " ELSE - " +
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_NUM + " END )",
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_DENOM,
DatabaseSchema.AccountEntry.TABLE_NAME + "_" + DatabaseSchema.AccountEntry.COLUMN_CURRENCY};
Cursor cursor = mDb.query("trans_split_acct", columns,
selection, selectionArgs, DatabaseSchema.AccountEntry.TABLE_NAME + "_" + DatabaseSchema.AccountEntry.COLUMN_CURRENCY, null, null);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.ui.common.BaseDrawerActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.joda.time.LocalDateTime;
import org.joda.time.Months;
Expand Down Expand Up @@ -211,28 +212,19 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mAccountType = reportsActivity.getAccountType();
}

@Override
public void onStart() {
super.onStart();
refresh();
}

@Override
public void onResume() {
super.onResume();
mReportsActivity.onFragmentResumed(this);
toggleBaseReportingOptionsVisibility();
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity activity = getActivity();
if (activity instanceof ReportsActivity) {
mReportsActivity = (ReportsActivity) activity;
} else {
throw new RuntimeException("Report fragments can only be used with the ReportsActivity");
}
mReportsActivity.onFragmentResumed(this);
toggleBaseReportingOptionsVisibility(mReportsActivity);
refresh();
}

@Override
Expand All @@ -242,9 +234,9 @@ public void onDetach() {
mReportGenerator.cancel(true);
}

private void toggleBaseReportingOptionsVisibility() {
View timeRangeLayout = mReportsActivity.findViewById(R.id.time_range_layout);
View dateRangeDivider = mReportsActivity.findViewById(R.id.date_range_divider);
private void toggleBaseReportingOptionsVisibility(ReportsActivity activity) {
View timeRangeLayout = activity.findViewById(R.id.time_range_layout);
View dateRangeDivider = activity.findViewById(R.id.date_range_divider);
if (timeRangeLayout != null && dateRangeDivider != null) {
int visibility = requiresTimeRangeOptions() ? View.VISIBLE : View.GONE;
timeRangeLayout.setVisibility(visibility);
Expand Down Expand Up @@ -297,26 +289,34 @@ public void refresh() {
mReportGenerator.cancel(true);

mReportGenerator = new AsyncTask<Void, Void, Void>() {
private final ReportsActivity activity = mReportsActivity;

@Override
protected void onPreExecute() {
BaseDrawerActivity activity = mReportsActivity;
assert activity != null;
activity.showProgressBar(true);
}

@Override
protected Void doInBackground(Void... params) {
generateReport(activity);
BaseDrawerActivity activity = mReportsActivity;
if (activity != null) {
// FIXME return data to be displayed.
generateReport(activity);
}
return null;
}

@Override
protected void onPostExecute(Void aVoid) {
displayReport();
activity.showProgressBar(false);
protected void onPostExecute(Void result) {
BaseDrawerActivity activity = mReportsActivity;
if (activity != null) {
// FIXME display the result data that was generated.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pnemonic78 is there another bug here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually more of a TODO

displayReport();
activity.showProgressBar(false);
}
}
};
mReportGenerator.execute();
}.execute();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.gnucash.android.ui.report;

import static com.github.mikephil.charting.components.Legend.LegendPosition;
import static org.gnucash.android.ui.util.TextViewExtKt.displayBalance;

import android.content.Context;
Expand All @@ -36,7 +35,6 @@
import androidx.core.view.ViewCompat;

import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
Expand All @@ -60,8 +58,6 @@
*/
public class ReportsOverviewFragment extends BaseReportFragment {

public static final int LEGEND_TEXT_SIZE = 14;

private Money mAssetsBalance;
private Money mLiabilitiesBalance;

Expand Down Expand Up @@ -111,11 +107,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mBinding.pieChart.setCenterTextColor(textColorPrimary);
mBinding.pieChart.setHoleColor(Color.TRANSPARENT);
Legend legend = mBinding.pieChart.getLegend();
legend.setEnabled(true);
legend.setWordWrapEnabled(true);
legend.setForm(LegendForm.CIRCLE);
legend.setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
legend.setTextSize(LEGEND_TEXT_SIZE);
legend.setTextColor(textColorPrimary);

ColorStateList csl = new ColorStateList(new int[][]{StateSet.WILD_CARD}, new int[]{ContextCompat.getColor(context, R.color.account_green)});
Expand All @@ -130,12 +122,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {

@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_group_reports_by).setVisible(false);
}

@Override
protected void generateReport(@NonNull Context context) {
PieData pieData = PieChartFragment.groupSmallerSlices(getData(), context);
PieData pieData = PieChartFragment.groupSmallerSlices(context, getData());
if (pieData.getYValCount() != 0) {
mBinding.pieChart.setData(pieData);
float sum = mBinding.pieChart.getData().getYValueSum();
Expand Down Expand Up @@ -171,18 +164,18 @@ private PieData getData() {
PieDataSet dataSet = new PieDataSet(null, "");
List<String> labels = new ArrayList<>();
List<Integer> colors = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
long start = now.minusMonths(2).dayOfMonth().withMinimumValue().toDateTime().getMillis();
long end = now.toDateTime().getMillis();

for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
if (account.getAccountType() == AccountType.EXPENSE
&& !account.isPlaceholderAccount()
&& account.getCommodity().equals(mCommodity)) {

LocalDateTime now = LocalDateTime.now();
long start = now.minusMonths(2).dayOfMonth().withMinimumValue().toDateTime().getMillis();
long end = now.plusDays(1).toDateTime().getMillis();
double balance = mAccountsDbAdapter.getAccountsBalance(
Collections.singletonList(account.getUID()), start, end).toDouble();
float balance = mAccountsDbAdapter.getAccountBalance(account.getUID(), start, end).toFloat();
if (balance > 0) {
dataSet.addEntry(new Entry((float) balance, dataSet.getEntryCount()));
dataSet.addEntry(new Entry(balance, dataSet.getEntryCount()));
colors.add(account.getColor() != Account.DEFAULT_COLOR
? account.getColor()
: COLORS[(dataSet.getEntryCount() - 1) % COLORS.length]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.BarData;
Expand All @@ -51,7 +52,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -98,19 +98,16 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {

mBinding.barChart.setOnChartValueSelectedListener(this);
mBinding.barChart.setDescription("");
// mChart.setDrawValuesForWholeStack(false);
mBinding.barChart.getXAxis().setDrawGridLines(false);
mBinding.barChart.getXAxis().setTextColor(textColorPrimary);
mBinding.barChart.getAxisRight().setEnabled(false);
mBinding.barChart.getAxisLeft().setStartAtZero(false);
mBinding.barChart.getAxisLeft().enableGridDashedLine(4.0f, 4.0f, 0);
mBinding.barChart.getAxisLeft().setValueFormatter(new LargeValueFormatter(mCommodity.getSymbol()));
mBinding.barChart.getAxisLeft().setTextColor(textColorPrimary);
Legend chartLegend = mBinding.barChart.getLegend();
chartLegend.setForm(Legend.LegendForm.CIRCLE);
chartLegend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
chartLegend.setWordWrapEnabled(true);
chartLegend.setTextColor(textColorPrimary);
Legend legend = mBinding.barChart.getLegend();
legend.setTextColor(textColorPrimary);
legend.setWordWrapEnabled(true);
}


Expand Down Expand Up @@ -161,10 +158,9 @@ protected BarData getData(@NonNull Context context) {
&& !account.isPlaceholderAccount()
&& account.getCommodity().equals(mCommodity)) {

double balance = mAccountsDbAdapter.getAccountsBalance(
Collections.singletonList(account.getUID()), start, end).toDouble();
float balance = mAccountsDbAdapter.getAccountBalance(account.getUID(), start, end).toFloat();
if (balance != 0) {
stack.add((float) balance);
stack.add(balance);

String accountName = account.getName();
while (labels.contains(accountName)) {
Expand Down Expand Up @@ -332,6 +328,7 @@ private void setCustomLegend() {

@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_percentage_mode).setVisible(mChartDataPresent);
// hide pie/line chart specific menu items
menu.findItem(R.id.menu_order_by_size).setVisible(false);
Expand All @@ -342,13 +339,15 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.isCheckable())
if (item.isCheckable()) {
item.setChecked(!item.isChecked());
}
final Context context = mBinding.barChart.getContext();
switch (item.getItemId()) {
case R.id.menu_toggle_legend:
Legend legend = mBinding.barChart.getLegend();
if (!legend.isLegendCustom()) {
Toast.makeText(getActivity(), R.string.toast_legend_too_long, Toast.LENGTH_LONG).show();
Toast.makeText(context, R.string.toast_legend_too_long, Toast.LENGTH_LONG).show();
item.setChecked(false);
} else {
item.setChecked(!mBinding.barChart.getLegend().isEnabled());
Expand All @@ -359,9 +358,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {

case R.id.menu_percentage_mode:
mTotalPercentageMode = !mTotalPercentageMode;
int msgId = mTotalPercentageMode ? R.string.toast_chart_percentage_mode_total
@StringRes int msgId = mTotalPercentageMode ? R.string.toast_chart_percentage_mode_total
: R.string.toast_chart_percentage_mode_current_bar;
Toast.makeText(getActivity(), msgId, Toast.LENGTH_LONG).show();
Toast.makeText(context, msgId, Toast.LENGTH_LONG).show();
return true;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
mBinding.lineChart.getAxisLeft().enableGridDashedLine(4.0f, 4.0f, 0);
mBinding.lineChart.getAxisLeft().setValueFormatter(new LargeValueFormatter(mCommodity.getSymbol()));
mBinding.lineChart.getAxisLeft().setTextColor(textColorPrimary);

Legend legend = mBinding.lineChart.getLegend();
legend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
legend.setTextSize(16);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setTextColor(textColorPrimary);
}

Expand Down Expand Up @@ -361,6 +357,7 @@ public void onGroupingUpdated(GroupInterval groupInterval) {

@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_toggle_average_lines).setVisible(mChartDataPresent);
// hide pie/bar chart specific menu items
menu.findItem(R.id.menu_order_by_size).setVisible(false);
Expand Down
Loading
Loading