Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Add offline support for all the teller functionalities using Couchbase and sync-gateway #190

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@

<activity android:name=".ui.online.groups.groupdetails.GroupDetailsActivity" />

<activity android:name=".ui.online.teller.tellerdetails.TellerDetailsActivity" />

<activity
android:name=".ui.online.groups.creategroup.CreateGroupActivity"
android:windowSoftInputMode="adjustResize|stateHidden" />

<activity
android:name=".ui.online.teller.createteller.CreateTellerActivity"
android:windowSoftInputMode="adjustResize|stateHidden" />

<receiver
android:name=".jobs.JobsReceiver"
android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ package org.apache.fineract.couchbase

enum class DocumentType(val value: String) {
GROUP("Group"),
CUSTOMER("customer")
CUSTOMER("customer"),
TELLER("Teller")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.apache.fineract.data.datamanager

import io.reactivex.Completable
import io.reactivex.Observable
import io.reactivex.ObservableSource
import io.reactivex.functions.Function
Expand All @@ -10,6 +11,7 @@ import javax.inject.Inject
import org.apache.fineract.FakeRemoteDataSource
import org.apache.fineract.data.datamanager.api.DataManagerAuth
import org.apache.fineract.data.datamanager.api.FineractBaseDataManager
import org.apache.fineract.data.models.teller.TellerCommand
import javax.inject.Singleton

@Singleton
Expand All @@ -18,13 +20,23 @@ class DataManagerTeller @Inject constructor(val baseManagerApi: BaseApiManager,
val preferencesHelper: PreferencesHelper)
: FineractBaseDataManager(dataManagerAuth, preferencesHelper) {

fun getTellers(): Observable<List<Teller>> =
baseManagerApi.tellerService.getTellerList(preferencesHelper.tenantIdentifier)
.onErrorResumeNext(Function<Throwable, ObservableSource<List<Teller>>>
{ Observable.just(FakeRemoteDataSource.getTeller()) })
fun getTellers(): Observable<List<Teller>> = baseManagerApi.tellerService
.getTellerList(preferencesHelper.tenantIdentifier)
.onErrorResumeNext(Function<Throwable, ObservableSource<List<Teller>>>
{ Observable.just(FakeRemoteDataSource.getTeller()) })

fun findTeller(tellerCode: String): Observable<Teller> = baseManagerApi.tellerService
.searchTeller(preferencesHelper.tenantIdentifier, tellerCode)
.onErrorResumeNext(Function<Throwable, ObservableSource<Teller>>
{ Observable.just(FakeRemoteDataSource.getTeller()[0]) })

fun createTeller(teller: Teller): Completable = baseManagerApi.tellerService
.createTeller(preferencesHelper.tenantIdentifier, teller)

fun updateTeller(teller: Teller): Completable = baseManagerApi.tellerService
.updateTeller(preferencesHelper.tenantIdentifier, teller.tellerAccountIdentifier!!, teller)

fun changeTellerStatus(teller: Teller, tellerCommand: TellerCommand): Completable = baseManagerApi.tellerService
.changeTellerStatus(preferencesHelper.tenantIdentifier, teller.tellerAccountIdentifier!!, tellerCommand)

}
35 changes: 18 additions & 17 deletions app/src/main/java/org/apache/fineract/data/models/teller/Teller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ package org.apache.fineract.data.models.teller
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.android.parcel.Parcelize
import org.apache.fineract.couchbase.DocumentType
import java.math.BigDecimal

@Parcelize
data class Teller(

@SerializedName("code") val code: String? = null,
@SerializedName("password") val password: String? = null,
@SerializedName("cashdrawLimit") val cashdrawLimit: BigDecimal? = null,
@SerializedName("tellerAccountIdentifier") val tellerAccountIdentifier: String? = null,
@SerializedName("vaultAccountIdentifier") val vaultAccountIdentifier: String? = null,
@SerializedName("chequesReceivableAccount") val chequesReceivableAccount: String? = null,
@SerializedName("cashOverShortAccount") val cashOverShortAccount: String? = null,
@SerializedName("denominationRequired") val denominationRequired: Boolean = false,
@SerializedName("assignedEmployee") val assignedEmployee: String? = null,
@SerializedName("state") val state: State? = null,
@SerializedName("createdBy") val createdBy: String? = null,
@SerializedName("createdOn") val createdOn: String? = null,
@SerializedName("lastModifiedBy") val lastModifiedBy: String? = null,
@SerializedName("lastModifiedOn") val lastModifiedOn: String? = null,
@SerializedName("lastOpenedBy") val lastOpenedBy: String? = null,
@SerializedName("lastOpenedOn") val lastOpenedOn: String? = null

var code: String? = null,
var password: String? = null,
var cashdrawLimit: BigDecimal? = null,
var tellerAccountIdentifier: String? = null,
var vaultAccountIdentifier: String? = null,
var chequesReceivableAccount: String? = null,
var cashOverShortAccount: String? = null,
var denominationRequired: Boolean = false,
var assignedEmployee: String? = null,
var state: State? = State.OPEN,
var createdBy: String? = null,
var createdOn: String? = null,
var lastModifiedBy: String? = null,
var lastModifiedOn: String? = null,
var lastOpenedBy: String? = null,
var lastOpenedOn: String? = null,
var documentType: String = DocumentType.TELLER.value
) : Parcelable {

enum class State {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.apache.fineract.data.models.teller

import com.google.gson.annotations.SerializedName

data class TellerCommand (
@SerializedName("action") var action: TellerAction? = null,
@SerializedName("adjustment") var adjustment: String? = "NONE",
@SerializedName("assignedEmployeeIdentifier") var assignedEmployeeIdentifier: String? = null
) {
enum class TellerAction {

@SerializedName("CLOSE")
CLOSE,

@SerializedName("ACTIVATE")
ACTIVATE,

@SerializedName("REOPEN")
REOPEN,

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.apache.fineract.data.services

import io.reactivex.Completable
import io.reactivex.Observable
import org.apache.fineract.data.models.teller.Teller
import org.apache.fineract.data.models.teller.TellerCommand
import org.apache.fineract.data.remote.EndPoints
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.*

interface TellersService {

Expand All @@ -14,4 +15,18 @@ interface TellersService {
@GET(EndPoints.API_TELLER_PATH + "/offices/{officeIdentifier}/teller/{tellerCode}")
fun searchTeller(@Path("officeIdentifier") officeIdentifier: String,
@Path("tellerCode") tellerCode: String): Observable<Teller>

@POST(EndPoints.API_TELLER_PATH + "/offices/{officeIdentifier}/teller")
fun createTeller(@Path("officeIdentifier") officeIdentifier: String,
@Body teller: Teller): Completable

@PUT(EndPoints.API_TELLER_PATH + "/offices/{officeIdentifier}/teller/{tellerIdentifier}")
fun updateTeller(@Path("officeIdentifier") officeIdentifier: String,
@Path("tellerIdentifier") tellerIdentifier: String,
@Body teller: Teller): Completable

@POST(EndPoints.API_TELLER_PATH + "/offices/{officeIdentifier}/teller/{tellerIdentifier}/commands")
fun changeTellerStatus(@Path("officeIdentifier") officeIdentifier: String,
@Path("tellerIdentifier") tellerIdentifier: String,
@Body tellerCommand: TellerCommand): Completable
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
import org.apache.fineract.ui.online.review.AddLoanReviewFragment;
import org.apache.fineract.ui.online.roles.roleslist.RolesFragment;
import org.apache.fineract.ui.online.teller.TellerFragment;
import org.apache.fineract.ui.online.teller.createteller.CreateTellerActivity;
import org.apache.fineract.ui.online.teller.createteller.TellerDetailsStepFragment;
import org.apache.fineract.ui.online.teller.createteller.TellerReviewStepFragment;
import org.apache.fineract.ui.online.teller.tellerdetails.TellerDetailsFragment;
import org.apache.fineract.ui.online.teller.tellertasks.TellerTasksBottomSheetFragment;
import org.apache.fineract.ui.product.ProductFragment;

import dagger.Subcomponent;
Expand Down Expand Up @@ -159,5 +164,15 @@ public interface ActivityComponent {
void inject(GroupDetailsFragment groupDetailsFragment);

void inject(GroupTasksBottomSheetFragment groupTasksBottomSheetFragment);

void inject(TellerDetailsFragment tellerDetailsFragment);

void inject(CreateTellerActivity createTellerActivity);

void inject(TellerDetailsStepFragment tellerDetailsStepFragment);

void inject(TellerReviewStepFragment tellerReviewStepFragment);

void inject(TellerTasksBottomSheetFragment tellerTasksBottomSheetFragment);
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import kotlinx.android.synthetic.main.item_teller.view.*
import org.apache.fineract.R
import org.apache.fineract.data.models.teller.Teller
import org.apache.fineract.injection.ApplicationContext
import org.apache.fineract.ui.base.OnItemClickListener
import org.apache.fineract.utils.DateUtils
import org.apache.fineract.utils.StatusUtils
import javax.inject.Inject
Expand All @@ -20,6 +22,7 @@ class TellerAdapter @Inject constructor(@ApplicationContext val context: Context
: RecyclerView.Adapter<TellerAdapter.ViewHolder>() {

var tellers: List<Teller> = ArrayList()
lateinit var onItemClickListener: OnItemClickListener

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_teller,
Expand Down Expand Up @@ -56,12 +59,27 @@ class TellerAdapter @Inject constructor(@ApplicationContext val context: Context
notifyDataSetChanged()
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun setItemClickListener(onItemClickListener: OnItemClickListener) {
this.onItemClickListener = onItemClickListener
}

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {

val llTeller: LinearLayout = itemView.ll_teller
val tellerIdentifier: TextView = itemView.tv_teller_identifier
val tvModifiedBy: TextView = itemView.tv_modified_by
val tvModifiedOn: TextView = itemView.tv_modified_on
val withDrawLimit: TextView = itemView.tv_cashWithdraw_limit
val statusIndicator: AppCompatImageView = itemView.iv_status_indicator

init {
llTeller.setOnClickListener(this)
}

override fun onClick(v: View?) {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(v, adapterPosition)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.apache.fineract.ui.online.teller

enum class TellerAction {
EDIT,
CREATE
}

This file was deleted.

Loading