Skip to content

Commit

Permalink
Merge pull request #724 from mayank-kgp/centersync
Browse files Browse the repository at this point in the history
feat: sync for centers
  • Loading branch information
therajanmaurya authored Aug 7, 2017
2 parents 82a23f3 + d5f19c5 commit 9b5c639
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public void onError(Throwable e) {

@Override
public void onNext(GroupWithAssociations groupWithAssociations) {
mClients = groupWithAssociations.getClientMembers();
mClients = Utils.getActiveClients(groupWithAssociations.getClientMembers());
mClientSyncIndex = 0;
resetIndexes();
if (mClients.size() != 0) {
Expand Down Expand Up @@ -644,7 +644,7 @@ public void onError(Throwable e) {
public void onNext(ClientAccounts clientAccounts) {
mLoanAccountList = Utils.getActiveLoanAccounts(clientAccounts
.getLoanAccounts());
mSavingsAccountList = Utils.getActiveSavingsAccounts(clientAccounts
mSavingsAccountList = Utils.getSyncableSavingsAccounts(clientAccounts
.getSavingsAccounts());

checkAccountsSyncStatusAndSyncClientAccounts();
Expand Down
42 changes: 42 additions & 0 deletions mifosng-android/src/main/java/com/mifos/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mifos.objects.PaymentTypeOption;
import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.savings.SavingsAccount;
import com.mifos.objects.client.Client;

import java.text.DateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -120,6 +121,47 @@ public void call(SavingsAccount savingsAccount) {
return accounts;
}

public static List<Client> getActiveClients(List<Client> clients) {
final List<Client> accounts = new ArrayList<>();
Observable.from(clients)
.filter(new Func1<Client, Boolean>() {
@Override
public Boolean call(Client client) {
return (client.isActive());
}
})
.subscribe(new Action1<Client>() {
@Override
public void call(Client client) {
accounts.add(client)
;
}
});
return accounts;
}

public static List<SavingsAccount> getSyncableSavingsAccounts(List<SavingsAccount>
savingsAccounts) {
final List<SavingsAccount> accounts = new ArrayList<>();
Observable.from(savingsAccounts)
.filter(new Func1<SavingsAccount, Boolean>() {
@Override
public Boolean call(SavingsAccount savingsAccount) {
return (savingsAccount.getDepositType().getValue().equals("Savings") &&
savingsAccount.getStatus().getActive() &&
!savingsAccount.isRecurring());
}
})
.subscribe(new Action1<SavingsAccount>() {
@Override
public void call(SavingsAccount savingsAccount) {
accounts.add(savingsAccount)
;
}
});
return accounts;
}

/**
* This Method Converting the List<Integer> of Activation Date to String.
*
Expand Down

0 comments on commit 9b5c639

Please sign in to comment.