From b14b98eb97b437479055f814553904c190908fab Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 17 Aug 2018 04:52:27 +0200 Subject: [PATCH] Fix balance calculus for sell transaction --- .../moodl/DataManagers/DatabaseManager.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java index 053ba92..c1574e3 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -555,15 +555,54 @@ public class DatabaseManager extends SQLiteOpenHelper{ while(resultatList.moveToNext()) { - if(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)).equals(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_FEE_CURRENCY)))) + String symbol = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)); + String feeSym = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_FEE_CURRENCY)); + String type = resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_TYPE)); + + if(type != null) { - currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + switch (type) + { + case "b": + if(symbol.equals(feeSym)) + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + } + else + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); + } + break; + case "s": + if(symbol.equals(feeSym)) + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) + resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + } + else + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , -resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); + } + break; + case "t": + break; + } } else { - currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) - , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); + if(symbol.equals(feeSym)) + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)) - resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_FEES)))); + } + else + { + currencyList.add(new Currency(resultatList.getString(resultatList.getColumnIndex(KEY_TRANSACTION_SYMBOL)) + , resultatList.getDouble(resultatList.getColumnIndex(KEY_TRANSACTION_AMOUNT)))); + } } }