Skip to content

Commit

Permalink
Merge pull request #1940 from moneymanagerex/google
Browse files Browse the repository at this point in the history
Refactor: unify regular transaction and scheduled transaction
  • Loading branch information
wolfsolver authored Dec 1, 2024
2 parents f8f44b2 + b5235af commit 9290feb
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private Bundle prepareQuery() {
.toIsoDateString());

// Status
where.addStatement(QueryAllData.Status, "IN", mFilter.transactionStatus.getSqlParameters());
where.addStatement(QueryAllData.STATUS, "IN", mFilter.transactionStatus.getSqlParameters());

// create a bundle to returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.money.manager.ex.common.AllDataListFragment;
import com.money.manager.ex.core.TransactionStatuses;
import com.money.manager.ex.core.TransactionTypes;
import com.money.manager.ex.datalayer.QueryAllDataRepository;
import com.money.manager.ex.database.QueryAllDataRepository;
import com.money.manager.ex.utils.MmxDate;
import com.money.manager.ex.viewmodels.AccountTransactionDisplay;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ public void setShowBalanceAmount(boolean mShowBalanceAmount) {
public void setFieldFromTypeCursor() {
ID = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.ID : QueryBillDeposits.BDID;
DATE = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.Date : QueryBillDeposits.NEXTOCCURRENCEDATE;
ACCOUNTID = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.ACCOUNTID : QueryBillDeposits.TOACCOUNTID;
STATUS = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.Status : QueryBillDeposits.STATUS;
AMOUNT = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.Amount : QueryBillDeposits.AMOUNT;
PAYEE = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.Payee : QueryBillDeposits.PAYEENAME;
ACCOUNTID = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.ACCOUNTID : QueryBillDeposits.ACCOUNTID;
STATUS = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.STATUS : QueryBillDeposits.STATUS;
AMOUNT = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.AMOUNT : QueryBillDeposits.AMOUNT;
PAYEE = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.PAYEENAME : QueryBillDeposits.PAYEENAME;
TRANSACTIONTYPE = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.TransactionType : QueryBillDeposits.TRANSCODE;
CURRENCYID = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.CURRENCYID : QueryBillDeposits.CURRENCYID;
TOACCOUNTID = mTypeCursor == TypeCursor.ALLDATA ? QueryAllData.TOACCOUNTID : QueryBillDeposits.TOACCOUNTID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private boolean runTask() {
String[] record = new String[7];
// compose a records
record[0] = data.getString(data.getColumnIndex(QueryAllData.Date));
if (!TextUtils.isEmpty(data.getString(data.getColumnIndex(QueryAllData.Payee)))) {
record[1] = data.getString(data.getColumnIndex(QueryAllData.Payee));
if (!TextUtils.isEmpty(data.getString(data.getColumnIndex(QueryAllData.PAYEENAME)))) {
record[1] = data.getString(data.getColumnIndex(QueryAllData.PAYEENAME));
} else {
record[1] = data.getString(data.getColumnIndex(QueryAllData.AccountName));
}
record[2] = Double.toString(data.getDouble(data.getColumnIndex(QueryAllData.Amount)));
record[2] = Double.toString(data.getDouble(data.getColumnIndex(QueryAllData.AMOUNT)));
record[3] = data.getString(data.getColumnIndex(QueryAllData.Category));
record[4] = data.getString(data.getColumnIndex(QueryAllData.Subcategory));
record[5] = Integer.toString(data.getInt(data.getColumnIndex(QueryAllData.TransactionNumber)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public class QueryAllData
public static final String Day = "Day";
public static final String Category = "Category";
public static final String Subcategory = "Subcategory";
public static final String Amount = "Amount";
public static final String AMOUNT = "Amount";
public static final String BaseConvRate = "BaseConvRate";
public static final String CURRENCYID = "CurrencyID";
public static final String AccountName = "AccountName";
public static final String ACCOUNTID = "AccountID";
public static final String SPLITTED = "SPLITTED";
public static final String CATEGID = "CategID";
public static final String Payee = "Payee";
public static final String PayeeID = "PayeeID";
public static final String PAYEENAME = "PayeeName";
public static final String PAYEEID = "PayeeID";
public static final String ToAccountName = "ToAccountName";
public static final String TOACCOUNTID = "ToAccountId";
public static final String ToAmount = "ToAmount";
public static final String ToCurrencyId = "ToCurrencyId";
public static final String TransactionNumber = "TransactionNumber";
public static final String Status = "Status";
public static final String STATUS = "Status";
public static final String Notes = "Notes";
public static final String currency = "currency";

Expand All @@ -63,8 +63,8 @@ public QueryAllData(Context context) {
@Override
public String[] getAllColumns() {
return new String[]{"ID AS _id", ID, TransactionType, Date, Year, Month, Day,
Category, Subcategory, Amount, BaseConvRate, CURRENCYID, AccountName, ACCOUNTID,
SPLITTED, CATEGID, Payee, PayeeID, TransactionNumber, Status, Notes,
Category, Subcategory, AMOUNT, BaseConvRate, CURRENCYID, AccountName, ACCOUNTID,
SPLITTED, CATEGID, PAYEENAME, PAYEEID, TransactionNumber, STATUS, Notes,
ToAccountName, TOACCOUNTID, ToAmount, ToCurrencyId,
currency};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2018 The Android Money Manager Ex Project Team
* Copyright (C) 2012-2024 The Android Money Manager Ex Project Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -15,14 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.money.manager.ex.datalayer;
package com.money.manager.ex.database;

import android.content.Context;
import android.database.Cursor;

import com.money.manager.ex.R;
import com.money.manager.ex.database.DatasetType;
import com.money.manager.ex.database.QueryAllData;
import com.money.manager.ex.datalayer.RepositoryBase;
import com.money.manager.ex.utils.MmxFileUtils;
import com.money.manager.ex.viewmodels.AccountTransactionDisplay;

Expand All @@ -41,12 +40,12 @@ public QueryAllDataRepository(Context context) {
public String[] getAllColumns() {
return new String[]{"ID AS _id", QueryAllData.ID, QueryAllData.TransactionType,
QueryAllData.Date, QueryAllData.Year, QueryAllData.Month, QueryAllData.Day,
QueryAllData.Category, QueryAllData.Subcategory, QueryAllData.Amount,
QueryAllData.Category, QueryAllData.Subcategory, QueryAllData.AMOUNT,
QueryAllData.BaseConvRate, QueryAllData.CURRENCYID, QueryAllData.AccountName,
QueryAllData.ACCOUNTID,
QueryAllData.SPLITTED,
QueryAllData.Payee, QueryAllData.PayeeID, QueryAllData.TransactionNumber,
QueryAllData.Status, QueryAllData.Notes, QueryAllData.ToAccountName,
QueryAllData.PAYEENAME, QueryAllData.PAYEEID, QueryAllData.TransactionNumber,
QueryAllData.STATUS, QueryAllData.Notes, QueryAllData.ToAccountName,
QueryAllData.TOACCOUNTID, QueryAllData.ToAmount, QueryAllData.ToCurrencyId,
QueryAllData.currency};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void bindView(View view, Context context, Cursor cursor) {
TextView txtColumn1 = view.findViewById(R.id.textViewColumn1);
TextView txtColumn2 = view.findViewById(R.id.textViewColumn2);
double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
if (cursor.getColumnIndex(QueryAllData.Payee) >= 0 && !TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(QueryAllData.Payee)))) {
txtColumn1.setText(cursor.getString(cursor.getColumnIndex(QueryAllData.Payee)));
if (cursor.getColumnIndex(QueryAllData.PAYEENAME) >= 0 && !TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(QueryAllData.PAYEENAME)))) {
txtColumn1.setText(cursor.getString(cursor.getColumnIndex(QueryAllData.PAYEENAME)));
} else {
txtColumn1.setText(context.getString(R.string.empty_payee));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private String assembleWhereClause() {
if (searchParameters.status != null &&
!searchParameters.status.equals(SearchParameters.STRING_NULL_VALUE) &&
!searchParameters.status.isEmpty()) {
where.addStatement(QueryAllData.Status, "=", searchParameters.status);
where.addStatement(QueryAllData.STATUS, "=", searchParameters.status);
}

addAmountStatements(where, searchParameters);
Expand All @@ -469,7 +469,7 @@ private String assembleWhereClause() {
}
// payee
if (searchParameters.payeeId != null) {
where.addStatement(QueryAllData.PayeeID, " = ", searchParameters.payeeId);
where.addStatement(QueryAllData.PAYEEID, " = ", searchParameters.payeeId);
}
// category

Expand Down Expand Up @@ -541,11 +541,11 @@ private void addAmountStatements(WhereStatementGenerator where, SearchParameters

// from amount
if (searchParameters.amountFrom != null) {
where.addStatement(QueryAllData.Amount, " >= ", searchParameters.amountFrom);
where.addStatement(QueryAllData.AMOUNT, " >= ", searchParameters.amountFrom);
}
// to amount
if (searchParameters.amountTo != null) {
where.addStatement(QueryAllData.Amount, " <= ", searchParameters.amountTo);
where.addStatement(QueryAllData.AMOUNT, " <= ", searchParameters.amountTo);
}

}
Expand All @@ -561,11 +561,11 @@ private void addAmountStatementForBothAmounts(WhereStatementGenerator where, Sea

// from amount
if (searchParameters.amountFrom != null) {
where.addStatement(QueryAllData.Amount, " >= ", lowerAmount);
where.addStatement(QueryAllData.AMOUNT, " >= ", lowerAmount);
}
// to amount
if (searchParameters.amountTo != null) {
where.addStatement(QueryAllData.Amount, " <= ", higherAmount);
where.addStatement(QueryAllData.AMOUNT, " <= ", higherAmount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ public Money calculateBalanceOn(long accountId, String isoDate) {
switch (TransactionTypes.valueOf(transType)) {
case Withdrawal:
DatabaseUtils.cursorDoubleToContentValues(cursor, ITransactionEntity.TRANSAMOUNT,
tx.contentValues, QueryAllData.Amount);
tx.contentValues, QueryAllData.AMOUNT);
amount = tx.getAmount();
total = total.subtract(amount);
break;
case Deposit:
DatabaseUtils.cursorDoubleToContentValues(cursor, ITransactionEntity.TRANSAMOUNT,
tx.contentValues, QueryAllData.Amount);
tx.contentValues, QueryAllData.AMOUNT);
amount = tx.getAmount();
total = total.add(amount);
break;
Expand All @@ -162,12 +162,12 @@ public Money calculateBalanceOn(long accountId, String isoDate) {

if (tx.getAccountId().equals(accountId)) {
DatabaseUtils.cursorDoubleToContentValues(cursor, ITransactionEntity.TRANSAMOUNT,
tx.contentValues, QueryAllData.Amount);
tx.contentValues, QueryAllData.AMOUNT);
amount = tx.getAmount();
total = total.subtract(amount);
} else {
DatabaseUtils.cursorDoubleToContentValues(cursor, ITransactionEntity.TOTRANSAMOUNT,
tx.contentValues, QueryAllData.Amount);
tx.contentValues, QueryAllData.AMOUNT);
amount = tx.getAmount();
total = total.add(amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void loadFromCursor(Cursor c) {
super.loadFromCursor(c);

// Reload all money values.
DatabaseUtils.cursorDoubleToCursorValues(c, QueryAllData.Amount, this.contentValues);
DatabaseUtils.cursorDoubleToCursorValues(c, QueryAllData.AMOUNT, this.contentValues);
DatabaseUtils.cursorDoubleToCursorValues(c, QueryAllData.ToAmount, this.contentValues);
}

Expand All @@ -60,7 +60,7 @@ public String getAccountName() {
}

public Money getAmount() {
return getMoney(QueryAllData.Amount);
return getMoney(QueryAllData.AMOUNT);
}

public String getCategory() {
Expand Down Expand Up @@ -89,11 +89,11 @@ public boolean getIsSplit() {
}

public String getPayee() {
return getString(QueryAllData.Payee);
return getString(QueryAllData.PAYEENAME);
}

public String getStatusCode() {
return getString(QueryAllData.Status);
return getString(QueryAllData.STATUS);
}

public TransactionStatuses getStatus() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw/query_alldata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT
ifnull(ToAcc.CurrencyId, FromAcc.CurrencyID) AS ToCurrencyId,
( CASE ifnull( TX.CATEGID, -1 ) WHEN -1 THEN 1 ELSE 0 END ) AS SPLITTED,
TX.CATEGID AS CategID,
ifnull( PAYEE.PayeeName, '') AS Payee,
ifnull( PAYEE.PayeeName, '') AS PayeeName,
ifnull( PAYEE.PayeeID, -1 ) AS PayeeID,
TX.TRANSACTIONNUMBER AS TransactionNumber,

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw/query_mobiledata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SELECT TX.TransID AS ID,
( CASE ifnull( TX.CATEGID, -1 ) WHEN -1 THEN 1 ELSE 0 END ) AS SPLITTED,
coalesce( SPARENTCAT.CATEGID, PARENTCAT.CATEGID, st.CategId, TX.CategId ) AS CATEGID,
-1 AS SubcategID,
ifnull( PAYEE.PayeeName, '') AS Payee,
ifnull( PAYEE.PayeeName, '') AS PayeeName,
ifnull( PAYEE.PayeeID, -1 ) AS PayeeID,
TX.TRANSACTIONNUMBER AS TransactionNumber,
round( strftime( '%d', TX.transdate ) ) AS day,
Expand Down

0 comments on commit 9290feb

Please sign in to comment.