fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-teller] 21/30: refactored to add more clarity
Date Mon, 22 Jan 2018 15:32:19 GMT
This is an automated email from the ASF dual-hosted git repository.

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-teller.git

commit 733149bfe9ba9fe17976d82116ead8ecac4738fe
Author: mgeiss <mgeiss@mifos.org>
AuthorDate: Wed Jun 28 09:06:21 2017 +0200

    refactored to add more clarity
---
 .../processor/TellerTransactionProcessor.java      | 73 +++++++++++++---------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
b/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
index f429425..c03adff 100644
--- a/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
+++ b/service/src/main/java/io/mifos/teller/service/internal/processor/TellerTransactionProcessor.java
@@ -89,39 +89,28 @@ public class TellerTransactionProcessor {
       case ServiceConstants.TX_ACCOUNT_TRANSFER:
       case ServiceConstants.TX_CASH_DEPOSIT:
       case ServiceConstants.TX_CASH_WITHDRAWAL:
-        return this.depositAccountCosts(tellerTransaction);
+        return this.getDepositTransactionCosts(tellerTransaction);
       default:
         throw new IllegalArgumentException("Unsupported TX type " + tellerTransaction.getTransactionType());
     }
   }
 
-  private TellerTransactionCosts depositAccountCosts(final TellerTransaction tellerTransaction)
{
-    final List<Charge> charges = this.depositAccountManagementService.getCharges(tellerTransaction);
-
-    final TellerTransactionCosts tellerTransactionCosts = new TellerTransactionCosts();
-    tellerTransactionCosts.setCharges(charges);
-    tellerTransactionCosts.setTellerTransactionIdentifier(tellerTransaction.getIdentifier());
-    tellerTransactionCosts.setTotalAmount(tellerTransaction.getAmount() + charges.stream().mapToDouble(Charge::getAmount).sum());
-
-    return tellerTransactionCosts;
-  }
-
   private void processTransfer(final TellerTransaction tellerTransaction) {
     final JournalEntry journalEntry = this.prepareJournalEntry(tellerTransaction);
 
-    final TellerTransactionCosts tellerTransactionCosts = this.depositAccountCosts(tellerTransaction);
+    final TellerTransactionCosts tellerTransactionCosts = this.getDepositTransactionCosts(tellerTransaction);
 
     final HashSet<Debtor> debtors = new HashSet<>();
     journalEntry.setDebtors(debtors);
 
-    final Debtor debtor = new Debtor();
-    debtor.setAccountNumber(tellerTransaction.getCustomerAccountIdentifier());
+    final Debtor customerDebtor = new Debtor();
+    customerDebtor.setAccountNumber(tellerTransaction.getCustomerAccountIdentifier());
+    customerDebtor.setAmount(tellerTransaction.getAmount().toString());
+    debtors.add(customerDebtor);
+
     if (!tellerTransactionCosts.getCharges().isEmpty()) {
-      debtor.setAmount(tellerTransactionCosts.getTotalAmount().toString());
-    } else {
-      debtor.setAmount(tellerTransaction.getAmount().toString());
+      debtors.add(this.createChargesDebtor(tellerTransaction.getCustomerAccountIdentifier(),
tellerTransactionCosts));
     }
-    debtors.add(debtor);
 
     final HashSet<Creditor> creditors = new HashSet<>();
     journalEntry.setCreditors(creditors);
@@ -145,7 +134,7 @@ public class TellerTransactionProcessor {
 
     final TellerEntity tellerEntity = optionalTeller.get();
     final JournalEntry journalEntry = this.prepareJournalEntry(tellerTransaction);
-    final TellerTransactionCosts tellerTransactionCosts = this.depositAccountCosts(tellerTransaction);
+    final TellerTransactionCosts tellerTransactionCosts = this.getDepositTransactionCosts(tellerTransaction);
 
     final HashSet<Debtor> debtors = new HashSet<>();
     journalEntry.setDebtors(debtors);
@@ -156,11 +145,7 @@ public class TellerTransactionProcessor {
     debtors.add(tellerDebtor);
 
     if (!tellerTransactionCosts.getCharges().isEmpty()) {
-      final Double chargesTotal = tellerTransactionCosts.getTotalAmount() - tellerTransaction.getAmount();
-      final Debtor customerDebtor = new Debtor();
-      customerDebtor.setAccountNumber(tellerTransaction.getCustomerAccountIdentifier());
-      customerDebtor.setAmount(chargesTotal.toString());
-      debtors.add(customerDebtor);
+      debtors.add(this.createChargesDebtor(tellerTransaction.getCustomerAccountIdentifier(),
tellerTransactionCosts));
     }
 
     final HashSet<Creditor> creditors = new HashSet<>();
@@ -185,19 +170,19 @@ public class TellerTransactionProcessor {
 
     final TellerEntity tellerEntity = optionalTeller.get();
     final JournalEntry journalEntry = this.prepareJournalEntry(tellerTransaction);
-    final TellerTransactionCosts tellerTransactionCosts = this.depositAccountCosts(tellerTransaction);
+    final TellerTransactionCosts tellerTransactionCosts = this.getDepositTransactionCosts(tellerTransaction);
 
     final HashSet<Debtor> debtors = new HashSet<>();
     journalEntry.setDebtors(debtors);
 
     final Debtor customerDebtor = new Debtor();
     customerDebtor.setAccountNumber(tellerTransaction.getCustomerAccountIdentifier());
+    customerDebtor.setAmount(tellerTransaction.getAmount().toString());
+    debtors.add(customerDebtor);
+
     if (!tellerTransactionCosts.getCharges().isEmpty()) {
-      customerDebtor.setAmount(tellerTransactionCosts.getTotalAmount().toString());
-    } else {
-      customerDebtor.setAmount(tellerTransaction.getAmount().toString());
+      debtors.add(this.createChargesDebtor(tellerTransaction.getCustomerAccountIdentifier(),
tellerTransactionCosts));
     }
-    debtors.add(customerDebtor);
 
     final HashSet<Creditor> creditors = new HashSet<>();
     journalEntry.setCreditors(creditors);
@@ -252,6 +237,34 @@ public class TellerTransactionProcessor {
     return journalEntry;
   }
 
+  private TellerTransactionCosts getDepositTransactionCosts(final TellerTransaction tellerTransaction)
{
+    final List<Charge> charges = this.depositAccountManagementService.getCharges(tellerTransaction);
+
+    final TellerTransactionCosts tellerTransactionCosts = new TellerTransactionCosts();
+    tellerTransactionCosts.setCharges(charges);
+    tellerTransactionCosts.setTellerTransactionIdentifier(tellerTransaction.getIdentifier());
+    tellerTransactionCosts.setTotalAmount(
+        tellerTransaction.getAmount() + charges.stream().mapToDouble(Charge::getAmount).sum()
+    );
+
+    return tellerTransactionCosts;
+  }
+
+  private Debtor createChargesDebtor(final String accountIdentifier, final TellerTransactionCosts
tellerTransactionCosts) {
+    final Debtor chargesDebtor = new Debtor();
+    chargesDebtor.setAccountNumber(accountIdentifier);
+    chargesDebtor.setAmount(
+        Double.valueOf(
+            tellerTransactionCosts.getCharges()
+                .stream()
+                .mapToDouble(Charge::getAmount)
+                .sum()
+        ).toString()
+    );
+
+    return chargesDebtor;
+  }
+
   private Set<Creditor> createChargeCreditors(final TellerTransactionCosts tellerTransactionCosts)
{
     return tellerTransactionCosts.getCharges()
         .stream()

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message