diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/IndividualCollectionSheetAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/IndividualCollectionSheetAdapter.java index d040cf1fc3d..00d0f9d5f79 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/IndividualCollectionSheetAdapter.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/IndividualCollectionSheetAdapter.java @@ -37,7 +37,7 @@ public class IndividualCollectionSheetAdapter extends RecyclerView.Adapter { private List paymentTypeList; - private List loans; + private List loanAndClientNames; private List paymentTypeOptionsList; private Context c; @@ -61,8 +61,8 @@ public void setPaymentTypeList(List paymentTypeList) { this.paymentTypeList.add(c.getString(R.string.payment_type)); } - public void setLoans(List loans) { - this.loans = loans; + public void setLoans(List loanAndClientNameList) { + this.loanAndClientNames = loanAndClientNameList; } @@ -81,33 +81,39 @@ public void onBindViewHolder(final IndividualCollectionSheetAdapter.ViewHolder h int position) { if (holder != null) { - LoanAndClientName item = loans.get(position); - final LoanCollectionSheet loanItem = item.getLoan(); - holder.tvClientName.setText(item.getClientName()); + LoanAndClientName loanAndClientNameItem = loanAndClientNames.get(position); + final LoanCollectionSheet loanCollectionSheetItem = loanAndClientNameItem.getLoan(); + holder.tvClientName.setText(loanAndClientNameItem.getClientName()); - holder.tvProductCode.setText(concatProductWithAccount(loanItem.getProductShortName() - , loanItem.getAccountId())); + holder.tvProductCode.setText(concatProductWithAccount(loanCollectionSheetItem + .getProductShortName(), loanCollectionSheetItem.getAccountId())); - if (loanItem.getChargesDue() != null) { + if (loanCollectionSheetItem.getChargesDue() != null) { holder.etCharges.setText( - String.format(Locale.getDefault(), "%f", loanItem.getChargesDue())); + String.format(Locale.getDefault(), "%f", + loanCollectionSheetItem.getChargesDue())); } - if (loanItem.getTotalDue() != null) { + if (loanCollectionSheetItem.getTotalDue() != null) { holder.etTotalDues.setText( - String.format(Locale.getDefault(), "%f", loanItem.getTotalDue())); + String.format(Locale.getDefault(), "%f", + loanCollectionSheetItem.getTotalDue())); } //Add default value of transaction irrespective of they are 'saved' or 'cancelled' // manually by the user. - BulkRepaymentTransactions singleTransaction = new BulkRepaymentTransactions(); - singleTransaction.setLoanId(loanItem.getLoanId()); - singleTransaction.setTransactionAmount(loanItem.getChargesDue() != null ? - loanItem.getChargesDue() + loanItem.getTotalDue() : - loanItem.getTotalDue()); - - sheetItemClickListener.onShowSheetMandatoryItem(singleTransaction, position); + BulkRepaymentTransactions defaultBulkRepaymentTransaction = new + BulkRepaymentTransactions(); + defaultBulkRepaymentTransaction.setLoanId(loanCollectionSheetItem.getLoanId()); + defaultBulkRepaymentTransaction.setTransactionAmount( + loanCollectionSheetItem.getChargesDue() != null ? + loanCollectionSheetItem.getChargesDue() + + loanCollectionSheetItem.getTotalDue() : + loanCollectionSheetItem.getTotalDue()); + + sheetItemClickListener.onShowSheetMandatoryItem(defaultBulkRepaymentTransaction, + position); } } @@ -117,7 +123,7 @@ private String concatProductWithAccount(String productCode, String accountNo) { @Override public int getItemCount() { - return loans.size(); + return loanAndClientNames.size(); } @Override @@ -128,7 +134,7 @@ public long getItemId(int i) { public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, Spinner.OnItemSelectedListener { int position; - BulkRepaymentTransactions transaction = new BulkRepaymentTransactions(); + BulkRepaymentTransactions bulkRepaymentTransaction = new BulkRepaymentTransactions(); public ViewHolder(View v) { super(v); @@ -140,9 +146,9 @@ public ViewHolder(View v) { public void onItemSelected(AdapterView adapterView, View view, int i, long l) { if (i != paymentTypeList.size() - 1) { - transaction.setPaymentTypeId(paymentTypeOptionsList.get(i).getId()); + bulkRepaymentTransaction.setPaymentTypeId(paymentTypeOptionsList.get(i).getId()); } else { - transaction.setPaymentTypeId(null); + bulkRepaymentTransaction.setPaymentTypeId(null); } } @@ -179,33 +185,35 @@ public void onClick(View view) { */ private void saveAdditional() { - transaction.setLoanId(loans.get(position).getLoan().getLoanId()); - transaction.setTransactionAmount((!etCharges.getText().toString().isEmpty() ? + bulkRepaymentTransaction.setLoanId(loanAndClientNames.get(position) + .getLoan().getLoanId()); + bulkRepaymentTransaction.setTransactionAmount((!etCharges + .getText().toString().isEmpty() ? Double.parseDouble(etCharges.getText().toString()) : 0) + (!etTotalDues.getText().toString().isEmpty() ? Double.parseDouble(etTotalDues.getText().toString()) : 0)); if (!etAccountNumber.getText().toString().isEmpty()) { - transaction.setAccountNumber(etAccountNumber.getText().toString()); + bulkRepaymentTransaction.setAccountNumber(etAccountNumber.getText().toString()); } if (!etChequeNumber.getText().toString().isEmpty()) { - transaction.setCheckNumber(etChequeNumber.getText().toString()); + bulkRepaymentTransaction.setCheckNumber(etChequeNumber.getText().toString()); } if (!etRoutingCode.getText().toString().isEmpty()) { - transaction.setRoutingCode(etRoutingCode.getText().toString()); + bulkRepaymentTransaction.setRoutingCode(etRoutingCode.getText().toString()); } if (!etReceiptNumber.getText().toString().isEmpty()) { - transaction.setReceiptNumber(etReceiptNumber.getText().toString()); + bulkRepaymentTransaction.setReceiptNumber(etReceiptNumber.getText().toString()); } if (!etBankNumber.getText().toString().isEmpty()) { - transaction.setBankNumber(etBankNumber.getText().toString()); + bulkRepaymentTransaction.setBankNumber(etBankNumber.getText().toString()); } - sheetItemClickListener.onSaveAdditionalItem(transaction, position); + sheetItemClickListener.onSaveAdditionalItem(bulkRepaymentTransaction, position); tableAdditional.setVisibility(View.GONE); } @@ -214,20 +222,22 @@ private void saveAdditional() { * the EditTexts and sets the remaining fields to null. */ private void cancelAdditional() { - transaction.setLoanId(loans.get(position).getLoan().getLoanId()); - transaction.setTransactionAmount((!etCharges.getText().toString().isEmpty() ? + bulkRepaymentTransaction.setLoanId(loanAndClientNames.get(position) + .getLoan().getLoanId()); + bulkRepaymentTransaction.setTransactionAmount((!etCharges.getText() + .toString().isEmpty() ? Double.parseDouble(etCharges.getText().toString()) : 0) + (!etTotalDues.getText().toString().isEmpty() ? Double.parseDouble(etTotalDues.getText().toString()) : 0)); tableAdditional.setVisibility(View.GONE); - transaction.setPaymentTypeId(null); - transaction.setAccountNumber(null); - transaction.setCheckNumber(null); - transaction.setRoutingCode(null); - transaction.setReceiptNumber(null); - transaction.setBankNumber(null); - sheetItemClickListener.onSaveAdditionalItem(transaction, position); + bulkRepaymentTransaction.setPaymentTypeId(null); + bulkRepaymentTransaction.setAccountNumber(null); + bulkRepaymentTransaction.setCheckNumber(null); + bulkRepaymentTransaction.setRoutingCode(null); + bulkRepaymentTransaction.setReceiptNumber(null); + bulkRepaymentTransaction.setBankNumber(null); + sheetItemClickListener.onSaveAdditionalItem(bulkRepaymentTransaction, position); } private void showAdditional() { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.java index 5aeb0154db8..ea6d008c76b 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.java @@ -190,15 +190,17 @@ private void setUpUi() { } @Override - public void onShowSheetMandatoryItem(BulkRepaymentTransactions transaction, int position) { + public void onShowSheetMandatoryItem(BulkRepaymentTransactions bulkRepaymentTransactions, + int position) { //Add the data as received - payload.getBulkRepaymentTransactions().set(position, transaction); + payload.getBulkRepaymentTransactions().set(position, bulkRepaymentTransactions); } @Override - public void onSaveAdditionalItem(BulkRepaymentTransactions transaction, int position) { + public void onSaveAdditionalItem(BulkRepaymentTransactions bulkRepaymentTransactions, + int position) { //Add or amend the data as changed by the user - payload.getBulkRepaymentTransactions().set(position, transaction); + payload.getBulkRepaymentTransactions().set(position, bulkRepaymentTransactions); } @@ -216,12 +218,15 @@ private void showCollectionSheetViews(IndividualCollectionSheet sheet) { //methods. payload = new IndividualCollectionSheetPayload(); - for (LoanAndClientName l : presenter.filterLoanAndClientNames(sheet.getClients())) { - LoanCollectionSheet loan = l.getLoan(); + for (LoanAndClientName loanAndClientName : + presenter.filterLoanAndClientNames(sheet.getClients())) { + LoanCollectionSheet loanCollectionSheet = loanAndClientName.getLoan(); payload.getBulkRepaymentTransactions().add(new BulkRepaymentTransactions( - loan.getLoanId(), - loan.getChargesDue() == null ? loan.getTotalDue() : - loan.getTotalDue() + loan.getChargesDue())); + loanCollectionSheet.getLoanId(), + loanCollectionSheet.getChargesDue() == null ? + loanCollectionSheet.getTotalDue() : + loanCollectionSheet.getTotalDue() + + loanCollectionSheet.getChargesDue())); } LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); @@ -250,8 +255,8 @@ private void submitSheet() { @Override - public void setOfficeSpinner(List list) { - officeList = list; + public void setOfficeSpinner(List offices) { + officeList = offices; officeNameList.clear(); officeNameList.addAll(presenter.filterOffices(officeList)); officeNameList.add(getString(R.string.spinner_office)); @@ -277,10 +282,10 @@ public void setTvRepaymentDate() { @Override - public void setStaffSpinner(List list) { + public void setStaffSpinner(List staffs) { spStaff.setOnItemSelectedListener(this); - staffList = list; + staffList = staffs; staffNameList.clear(); staffNameList.addAll(presenter.filterStaff(staffList)); staffNameList.add(getString(R.string.spinner_staff)); @@ -318,8 +323,8 @@ public void onNothingSelected(AdapterView adapterView) { } @Override - public void showSheet(IndividualCollectionSheet collectionSheet) { - sheet = collectionSheet; + public void showSheet(IndividualCollectionSheet individualCollectionSheet) { + sheet = individualCollectionSheet; if (recyclerSheets.getVisibility() == View.GONE) { recyclerSheets.setVisibility(View.VISIBLE); } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetPresenter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetPresenter.java index 6ef5dec91d9..3a1ffc06b69 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetPresenter.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetPresenter.java @@ -62,10 +62,12 @@ public void detachView() { } } - void submitIndividualCollectionSheet(IndividualCollectionSheetPayload payload) { + void submitIndividualCollectionSheet(IndividualCollectionSheetPayload + individualCollectionSheetPayload) { checkViewAttached(); getMvpView().showProgressbar(true); - mSubscription.add(mDataManagerCollection.saveIndividualCollectionSheet(payload) + mSubscription.add(mDataManagerCollection + .saveIndividualCollectionSheet(individualCollectionSheetPayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber() { @@ -90,18 +92,20 @@ public void onError(Throwable e) { } @Override - public void onNext(GenericResponse response) { + public void onNext(GenericResponse genericResponse) { getMvpView().showProgressbar(false); getMvpView().showSuccess(); } })); } - void fetchIndividualCollectionSheet(RequestCollectionSheetPayload payload) { + void fetchIndividualCollectionSheet(RequestCollectionSheetPayload + requestCollectionSheetPayload) { checkViewAttached(); getMvpView().showProgressbar(true); - mSubscription.add(mDataManagerCollection.getIndividualCollectionSheet(payload) + mSubscription.add(mDataManagerCollection + .getIndividualCollectionSheet(requestCollectionSheetPayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber() { @@ -129,10 +133,10 @@ public void onError(Throwable e) { } @Override - public void onNext(IndividualCollectionSheet collectionSheet) { + public void onNext(IndividualCollectionSheet individualCollectionSheet) { getMvpView().showProgressbar(false); - if (collectionSheet.getClients().size() > 0) { - getMvpView().showSheet(collectionSheet); + if (individualCollectionSheet.getClients().size() > 0) { + getMvpView().showSheet(individualCollectionSheet); } else { getMvpView().showNoSheetFound(); } @@ -222,9 +226,9 @@ public void call(Office office) { return officesList; } - List filterStaff(List staff) { + List filterStaff(List staffs) { final List staffList = new ArrayList<>(); - Observable.from(staff) + Observable.from(staffs) .subscribe(new Action1() { @Override public void call(Staff staff) { @@ -246,16 +250,20 @@ public void call(PaymentTypeOptions paymentTypeOption) { return paymentList; } - List filterLoanAndClientNames(List clients) { + List filterLoanAndClientNames(List + clientCollectionSheets) { final List loansAndClientNames = new ArrayList<>(); - Observable.from(clients) + Observable.from(clientCollectionSheets) .subscribe(new Action1() { @Override - public void call(ClientCollectionSheet client) { - for (LoanCollectionSheet loan : - client.getLoans()) { - loansAndClientNames.add(new - LoanAndClientName(loan, client.getClientName())); + public void call(ClientCollectionSheet clientCollectionSheet) { + if (clientCollectionSheet.getLoans() != null) { + for (LoanCollectionSheet loanCollectionSheet : + clientCollectionSheet.getLoans()) { + loansAndClientNames.add(new + LoanAndClientName(loanCollectionSheet, + clientCollectionSheet.getClientName())); + } } } }); diff --git a/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/ClientCollectionSheet.java b/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/ClientCollectionSheet.java index 458ecc98e87..db566e424a7 100644 --- a/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/ClientCollectionSheet.java +++ b/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/ClientCollectionSheet.java @@ -2,6 +2,9 @@ import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; import java.util.ArrayList; @@ -14,27 +17,9 @@ public class ClientCollectionSheet implements Parcelable { private int clientId; private String clientName; - private ArrayList loans; - - private AttendanceTypeOption attendanceType; - - private ArrayList savings = new ArrayList<>(); - - public ArrayList getSavings() { - return savings; - } - - public void setSavings(ArrayList savings) { - this.savings = savings; - } - - public AttendanceTypeOption getAttendanceType() { - return attendanceType; - } - - public void setAttendanceType(AttendanceTypeOption attendanceType) { - this.attendanceType = attendanceType; - } + @Nullable + @SerializedName("loans") + private ArrayList loanCollectionSheetList; public int getClientId() { return clientId; @@ -53,11 +38,11 @@ public void setClientName(String clientName) { } public ArrayList getLoans() { - return loans; + return loanCollectionSheetList; } public void setLoans(ArrayList loans) { - this.loans = loans; + this.loanCollectionSheetList = loans; } @@ -70,9 +55,7 @@ public int describeContents() { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.clientId); dest.writeString(this.clientName); - dest.writeTypedList(this.loans); - dest.writeParcelable(this.attendanceType, flags); - dest.writeTypedList(this.savings); + dest.writeList(this.loanCollectionSheetList); } public ClientCollectionSheet() { @@ -81,21 +64,20 @@ public ClientCollectionSheet() { protected ClientCollectionSheet(Parcel in) { this.clientId = in.readInt(); this.clientName = in.readString(); - this.loans = in.createTypedArrayList(LoanCollectionSheet.CREATOR); - this.attendanceType = in.readParcelable(AttendanceTypeOption.class.getClassLoader()); - this.savings = in.createTypedArrayList(SavingsCollectionSheet.CREATOR); + this.loanCollectionSheetList = new ArrayList(); + in.readList(this.loanCollectionSheetList, LoanCollectionSheet.class.getClassLoader()); } - public static final Creator CREATOR = new - Creator() { - @Override - public ClientCollectionSheet createFromParcel(Parcel source) { - return new ClientCollectionSheet(source); - } - - @Override - public ClientCollectionSheet[] newArray(int size) { - return new ClientCollectionSheet[size]; - } - }; + public static final Parcelable.Creator CREATOR = new + Parcelable.Creator() { + @Override + public ClientCollectionSheet createFromParcel(Parcel source) { + return new ClientCollectionSheet(source); + } + + @Override + public ClientCollectionSheet[] newArray(int size) { + return new ClientCollectionSheet[size]; + } + }; } diff --git a/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/IndividualCollectionSheet.java b/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/IndividualCollectionSheet.java index e1e6db52ba8..e1c64319b26 100644 --- a/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/IndividualCollectionSheet.java +++ b/mifosng-android/src/main/java/com/mifos/objects/collectionsheet/IndividualCollectionSheet.java @@ -3,6 +3,7 @@ import android.os.Parcel; import android.os.Parcelable; +import com.google.gson.annotations.SerializedName; import com.mifos.objects.accounts.loan.PaymentTypeOptions; import java.util.ArrayList; @@ -15,7 +16,8 @@ public class IndividualCollectionSheet implements Parcelable { private int[] dueDate; - private ArrayList clients; + @SerializedName("clients") + private ArrayList clientCollectionSheetList; private ArrayList paymentTypeOptions; @@ -28,11 +30,11 @@ public void setDueDate(int[] dueDate) { } public ArrayList getClients() { - return clients; + return clientCollectionSheetList; } public void setClients(ArrayList clients) { - this.clients = clients; + this.clientCollectionSheetList = clients; } public ArrayList getPaymentTypeOptions() { @@ -52,7 +54,7 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeIntArray(this.dueDate); - dest.writeList(this.clients); + dest.writeList(this.clientCollectionSheetList); dest.writeList(this.paymentTypeOptions); } @@ -61,8 +63,8 @@ public IndividualCollectionSheet() { protected IndividualCollectionSheet(Parcel in) { this.dueDate = in.createIntArray(); - this.clients = new ArrayList(); - in.readList(this.clients, ClientCollectionSheet.class.getClassLoader()); + this.clientCollectionSheetList = new ArrayList(); + in.readList(this.clientCollectionSheetList, ClientCollectionSheet.class.getClassLoader()); this.paymentTypeOptions = new ArrayList(); in.readList(this.paymentTypeOptions, PaymentTypeOptions.class.getClassLoader()); }