Skip to content

Commit

Permalink
Merge pull request #93 from gotosleep/master
Browse files Browse the repository at this point in the history
Add basic support for recurring accounts
  • Loading branch information
droidchef committed Nov 21, 2014
2 parents 8895311 + b87c0b2 commit c977c05
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.mifos.mifosxdroid.R;
import com.mifos.objects.accounts.loan.LoanWithAssociations;
import com.mifos.objects.accounts.savings.DepositType;
import com.mifos.objects.accounts.savings.SavingsAccountWithAssociations;
import com.mifos.utils.Constants;
import com.mifos.utils.FragmentConstants;
Expand Down Expand Up @@ -102,9 +103,9 @@ public void loadLoanAccountSummary(int loanAccountNumber) {
*/

@Override
public void loadSavingsAccountSummary(int savingsAccountNumber) {
public void loadSavingsAccountSummary(int savingsAccountNumber, DepositType accountType) {
SavingsAccountSummaryFragment savingsAccountSummaryFragment
= SavingsAccountSummaryFragment.newInstance(savingsAccountNumber);
= SavingsAccountSummaryFragment.newInstance(savingsAccountNumber, accountType);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS);
fragmentTransaction.replace(R.id.global_container, savingsAccountSummaryFragment).commit();
Expand Down Expand Up @@ -171,10 +172,10 @@ public void loadLoanTransactions(int loanId) {
*
*/
@Override
public void doTransaction(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType) {
public void doTransaction(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType, DepositType accountType) {

SavingsAccountTransactionFragment savingsAccountTransactionFragment =
SavingsAccountTransactionFragment.newInstance(savingsAccountWithAssociations, transactionType);
SavingsAccountTransactionFragment.newInstance(savingsAccountWithAssociations, transactionType, accountType);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SAVINGS_ACCOUNT_SUMMARY);
fragmentTransaction.replace(R.id.global_container, savingsAccountTransactionFragment).commit();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.joanzapata.android.iconify.Iconify;
import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.adapters.SavingsAccountTransactionsListAdapter;
import com.mifos.objects.accounts.savings.DepositType;
import com.mifos.objects.accounts.savings.SavingsAccountWithAssociations;
import com.mifos.objects.accounts.savings.Status;
import com.mifos.objects.accounts.savings.Transaction;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class SavingsAccountSummaryFragment extends Fragment {
public static final int MENU_ITEM_DATA_TABLES = 1001;
public static final int MENU_ITEM_DOCUMENTS = 1004;
public static int savingsAccountNumber;
public static DepositType savingsAccountType;

public static List<DataTable> savingsAccountDataTables = new ArrayList<DataTable>();
@InjectView(R.id.tv_clientName)
TextView tv_clientName;
Expand Down Expand Up @@ -108,10 +111,11 @@ public SavingsAccountSummaryFragment() {
// Required empty public constructor
}

public static SavingsAccountSummaryFragment newInstance(int savingsAccountNumber) {
public static SavingsAccountSummaryFragment newInstance(int savingsAccountNumber, DepositType type) {
SavingsAccountSummaryFragment fragment = new SavingsAccountSummaryFragment();
Bundle args = new Bundle();
args.putInt(Constants.SAVINGS_ACCOUNT_NUMBER, savingsAccountNumber);
args.putParcelable(Constants.SAVINGS_ACCOUNT_TYPE, type);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -121,6 +125,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
savingsAccountNumber = getArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER);
savingsAccountType = getArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE);
}

setHasOptionsMenu(true);
Expand All @@ -146,11 +151,21 @@ public void inflateSavingsAccountSummary() {

safeUIBlockingUtility.safelyBlockUI();

actionBar.setTitle(getResources().getString(R.string.savingsAccountSummary));
switch (savingsAccountType.getServerType()) {
case RECURRING:
actionBar.setTitle(getResources().getString(R.string.recurringAccountSummary));
break;
default:
actionBar.setTitle(getResources().getString(R.string.savingsAccountSummary));
break;
}

/**
* This Method will hit end point ?associations=transactions
*/
API.savingsAccountService.getSavingsAccountWithAssociations(savingsAccountNumber,


API.savingsAccountService.getSavingsAccountWithAssociations(savingsAccountType.getEndpoint(), savingsAccountNumber,
"transactions", new Callback<SavingsAccountWithAssociations>() {
@Override
public void success(SavingsAccountWithAssociations savingsAccountWithAssociations, Response response) {
Expand Down Expand Up @@ -348,12 +363,12 @@ public boolean onOptionsItemSelected(MenuItem item) {

@OnClick(R.id.bt_deposit)
public void onDepositButtonClicked() {
mListener.doTransaction(savingsAccountWithAssociations, Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT);
mListener.doTransaction(savingsAccountWithAssociations, Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, savingsAccountType);
}

@OnClick(R.id.bt_withdrawal)
public void onWithdrawalButtonClicked() {
mListener.doTransaction(savingsAccountWithAssociations, Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL);
mListener.doTransaction(savingsAccountWithAssociations, Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL, savingsAccountType);
}

/**
Expand Down Expand Up @@ -485,6 +500,6 @@ public void toggleTransactionCapabilityOfAccount(Status status) {

public interface OnFragmentInteractionListener {

public void doTransaction(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType);
public void doTransaction(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType, DepositType accountType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.uihelpers.MFDatePicker;
import com.mifos.objects.PaymentTypeOption;
import com.mifos.objects.accounts.savings.DepositType;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionResponse;
import com.mifos.objects.accounts.savings.SavingsAccountWithAssociations;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class SavingsAccountTransactionFragment extends Fragment implements MFDat
ActionBar actionBar;
SharedPreferences sharedPreferences;
String savingsAccountNumber;
private DepositType savingsAccountType;

String transactionType; //Defines if the Transaction is a Deposit to an Account or a Withdrawal from an Account
String clientName;
// Values to be fetched from Savings Account Template
Expand All @@ -102,12 +105,13 @@ public SavingsAccountTransactionFragment() {
* @param transactionType Type of Transaction (Deposit or Withdrawal)
* @return A new instance of fragment SavingsAccountTransactionDialogFragment.
*/
public static SavingsAccountTransactionFragment newInstance(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType) {
public static SavingsAccountTransactionFragment newInstance(SavingsAccountWithAssociations savingsAccountWithAssociations, String transactionType, DepositType accountType) {
SavingsAccountTransactionFragment fragment = new SavingsAccountTransactionFragment();
Bundle args = new Bundle();
args.putString(Constants.SAVINGS_ACCOUNT_NUMBER, savingsAccountWithAssociations.getAccountNo());
args.putString(Constants.SAVINGS_ACCOUNT_TRANSACTION_TYPE, transactionType);
args.putString(Constants.CLIENT_NAME, savingsAccountWithAssociations.getClientName());
args.putParcelable(Constants.SAVINGS_ACCOUNT_TYPE, accountType);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -120,6 +124,7 @@ public void onCreate(Bundle savedInstanceState) {
savingsAccountNumber = getArguments().getString(Constants.SAVINGS_ACCOUNT_NUMBER);
transactionType = getArguments().getString(Constants.SAVINGS_ACCOUNT_TRANSACTION_TYPE);
clientName = getArguments().getString(Constants.CLIENT_NAME);
savingsAccountType = getArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE);

}
}
Expand Down Expand Up @@ -184,7 +189,7 @@ public void inflateUI() {

public void inflatePaymentOptions() {

API.savingsAccountService.getSavingsAccountTransactionTemplate(Integer.parseInt(savingsAccountNumber), new Callback<SavingsAccountTransactionTemplate>() {
API.savingsAccountService.getSavingsAccountTransactionTemplate(savingsAccountType.getEndpoint(), Integer.parseInt(savingsAccountNumber), transactionType, new Callback<SavingsAccountTransactionTemplate>() {
@Override
public void success(SavingsAccountTransactionTemplate savingsAccountTransactionTemplate, Response response) {

Expand Down Expand Up @@ -305,7 +310,7 @@ public void processTransaction() {

safeUIBlockingUtility.safelyBlockUI();

API.savingsAccountService.processTransaction(Integer.parseInt(savingsAccountNumber), transactionType,
API.savingsAccountService.processTransaction(savingsAccountType.getEndpoint(), Integer.parseInt(savingsAccountNumber), transactionType,
savingsAccountTransactionRequest, new Callback<SavingsAccountTransactionResponse>() {
@Override
public void success(SavingsAccountTransactionResponse savingsAccountTransactionResponse, Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ public ClientAccounts withSavingsAccounts(List<SavingsAccount> savingsAccounts)
return this;
}

public List<SavingsAccount>getRecurringSavingsAccounts() {
return getSavingsAccounts(true);
}

public List<SavingsAccount>getNonRecurringSavingsAccounts() {
return getSavingsAccounts(false);
}

private List<SavingsAccount>getSavingsAccounts(boolean wantRecurring) {
List<SavingsAccount> result = new ArrayList<SavingsAccount>();
if (this.savingsAccounts != null) {
for (SavingsAccount account : savingsAccounts) {
if (account.isRecurring() == wantRecurring) {
result.add(account);
}
}
}
return result;
}

@Override
public String toString() {
return "ClientAccounts{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.mifos.objects.accounts.savings;

import android.os.Parcel;
import android.os.Parcelable;

import com.mifos.services.data.APIEndPoint;

/*
* This project is licensed under the open source MPL V2.
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
public class DepositType implements Parcelable {

public static enum ServerTypes {
// TODO: Are these all the types?
SAVINGS(100, "depositAccountType.savingsDeposit", APIEndPoint.SAVINGSACCOUNTS),
FIXED(200, "depositAccountType.fixedDeposit", APIEndPoint.SAVINGSACCOUNTS),
RECURRING(300, "depositAccountType.recurringDeposit", APIEndPoint.RECURRING_ACCOUNTS);

private Integer id;
private String code;
private String endpoint;

ServerTypes(Integer id, String code, String endpoint) {
this.id = id;
this.code = code;
this.endpoint = endpoint;
}

public Integer getId() {
return id;
}

public String getCode() {
return code;
}

public String getEndpoint() {
return endpoint;
}

public static ServerTypes fromId(int id) {
for (ServerTypes type : ServerTypes.values()) {
if (type.getId().equals(id)) {
return type;
}
}
return SAVINGS;
}
}

private Integer id;
private String code;
private String value;

public Integer getId() {
return id;
}

public String getCode() {
return code;
}

public String getValue() {
return value;
}

public boolean isRecurring() {
return ServerTypes.RECURRING.getId().equals(this.getId());
}

public String getEndpoint() {
return ServerTypes.fromId(getId()).getEndpoint();
}

public ServerTypes getServerType() {
return ServerTypes.fromId(getId());
}

@Override
public String toString() {
return "DepositType{" +
"id=" + id +
", code='" + code + '\'' +
", value='" + value + '\'' +
'}';
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(this.id);
dest.writeString(this.code);
dest.writeString(this.value);
}

public DepositType() {
}

private DepositType(Parcel in) {
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
this.code = in.readString();
this.value = in.readString();
}

public static final Parcelable.Creator<DepositType> CREATOR = new Parcelable.Creator<DepositType>() {
public DepositType createFromParcel(Parcel source) {
return new DepositType(source);
}

public DepositType[] newArray(int size) {
return new DepositType[size];
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SavingsAccount {
private Currency currency;
private Double accountBalance;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private DepositType depositType;

public Integer getId() {
return id;
Expand Down Expand Up @@ -112,6 +113,18 @@ public SavingsAccount withAccountBalance(Double accountBalance) {
return this;
}

public DepositType getDepositType() {
return depositType;
}

public void setDepositType(DepositType depositType) {
this.depositType = depositType;
}

public boolean isRecurring() {
return this.getDepositType() == null ? false : this.getDepositType().isRecurring();
}

@Override
public String toString() {
return "SavingsAccount{" +
Expand All @@ -123,6 +136,7 @@ public String toString() {
", status=" + status +
", currency=" + currency +
", additionalProperties=" + additionalProperties +
", depositType=" + depositType +
'}';
}

Expand Down
19 changes: 13 additions & 6 deletions mifosng-android/src/main/java/com/mifos/services/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.mifos.objects.accounts.loan.LoanRepaymentRequest;
import com.mifos.objects.accounts.loan.LoanRepaymentResponse;
import com.mifos.objects.accounts.loan.LoanWithAssociations;
import com.mifos.objects.accounts.savings.DepositType;
import com.mifos.objects.accounts.savings.SavingsAccount;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest;
import com.mifos.objects.accounts.savings.SavingsAccountTransactionResponse;
import com.mifos.objects.accounts.savings.SavingsAccountWithAssociations;
Expand Down Expand Up @@ -359,8 +361,9 @@ public interface SavingsAccountService {
* Use this method to retrieve the Savings Account With Associations
*/
@Headers({ACCEPT_JSON, CONTENT_TYPE_JSON})
@GET(APIEndPoint.SAVINGSACCOUNTS + "/{savingsAccountId}")
public void getSavingsAccountWithAssociations(@Path("savingsAccountId") int savingsAccountId,
@GET("/{savingsAccountType}/{savingsAccountId}")
public void getSavingsAccountWithAssociations(@Path("savingsAccountType") String savingsAccountType,
@Path("savingsAccountId") int savingsAccountId,
@Query("associations") String association,
Callback<SavingsAccountWithAssociations> savingsAccountWithAssociationsCallback);

Expand All @@ -372,12 +375,16 @@ public void getSavingsAccountWithAssociations(@Path("savingsAccountId") int savi
* Use this method to retrieve the Savings Account Transaction Template
*/
@Headers({ACCEPT_JSON, CONTENT_TYPE_JSON})
@GET(APIEndPoint.SAVINGSACCOUNTS + "/{savingsAccountId}/transactions/template")
public void getSavingsAccountTransactionTemplate(@Path("savingsAccountId") int savingsAccountId, Callback<SavingsAccountTransactionTemplate> savingsAccountTransactionTemplateCallback);
@GET("/{savingsAccountType}/{savingsAccountId}/transactions/template")
public void getSavingsAccountTransactionTemplate(@Path("savingsAccountType") String savingsAccountType,
@Path("savingsAccountId") int savingsAccountId,
@Query("command") String transactionType,
Callback<SavingsAccountTransactionTemplate> savingsAccountTransactionTemplateCallback);

@Headers({ACCEPT_JSON, CONTENT_TYPE_JSON})
@POST(APIEndPoint.SAVINGSACCOUNTS + "/{savingsAccountId}/transactions")
public void processTransaction(@Path("savingsAccountId") int savingsAccountId,
@POST("/{savingsAccountType}/{savingsAccountId}/transactions")
public void processTransaction(@Path("savingsAccountType") String savingsAccountType,
@Path("savingsAccountId") int savingsAccountId,
@Query("command") String transactionType,
@Body SavingsAccountTransactionRequest savingsAccountTransactionRequest,
Callback<SavingsAccountTransactionResponse> savingsAccountTransactionResponseCallback);
Expand Down
Loading

0 comments on commit c977c05

Please sign in to comment.