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

Commit fa6db4f

Browse files
committed
All teller functionalities implemented using couchbase
1 parent 31fffb8 commit fa6db4f

File tree

9 files changed

+67
-74
lines changed

9 files changed

+67
-74
lines changed

app/src/main/java/org/apache/fineract/couchbase/DocumentType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ package org.apache.fineract.couchbase
66

77
enum class DocumentType(val value: String) {
88
GROUP("Group"),
9-
CUSTOMER("customer")
9+
CUSTOMER("customer"),
10+
TELLER("Teller")
1011
}

app/src/main/java/org/apache/fineract/data/models/teller/Teller.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@ package org.apache.fineract.data.models.teller
33
import android.os.Parcelable
44
import com.google.gson.annotations.SerializedName
55
import kotlinx.android.parcel.Parcelize
6+
import org.apache.fineract.couchbase.DocumentType
67
import java.math.BigDecimal
78

89
@Parcelize
910
data class Teller(
1011

11-
@SerializedName("code") var code: String? = null,
12-
@SerializedName("password") var password: String? = null,
13-
@SerializedName("cashdrawLimit") var cashdrawLimit: BigDecimal? = null,
14-
@SerializedName("tellerAccountIdentifier") var tellerAccountIdentifier: String? = null,
15-
@SerializedName("vaultAccountIdentifier") var vaultAccountIdentifier: String? = null,
16-
@SerializedName("chequesReceivableAccount") var chequesReceivableAccount: String? = null,
17-
@SerializedName("cashOverShortAccount") var cashOverShortAccount: String? = null,
18-
@SerializedName("denominationRequired") var denominationRequired: Boolean = false,
19-
@SerializedName("assignedEmployee") var assignedEmployee: String? = null,
20-
@SerializedName("state") var state: State? = null,
21-
@SerializedName("createdBy") var createdBy: String? = null,
22-
@SerializedName("createdOn") var createdOn: String? = null,
23-
@SerializedName("lastModifiedBy") var lastModifiedBy: String? = null,
24-
@SerializedName("lastModifiedOn") var lastModifiedOn: String? = null,
25-
@SerializedName("lastOpenedBy") var lastOpenedBy: String? = null,
26-
@SerializedName("lastOpenedOn") var lastOpenedOn: String? = null
27-
12+
var code: String? = null,
13+
var password: String? = null,
14+
var cashdrawLimit: BigDecimal? = null,
15+
var tellerAccountIdentifier: String? = null,
16+
var vaultAccountIdentifier: String? = null,
17+
var chequesReceivableAccount: String? = null,
18+
var cashOverShortAccount: String? = null,
19+
var denominationRequired: Boolean = false,
20+
var assignedEmployee: String? = null,
21+
var state: State? = State.OPEN,
22+
var createdBy: String? = null,
23+
var createdOn: String? = null,
24+
var lastModifiedBy: String? = null,
25+
var lastModifiedOn: String? = null,
26+
var lastOpenedBy: String? = null,
27+
var lastOpenedOn: String? = null,
28+
var documentType: String = DocumentType.TELLER.value
2829
) : Parcelable {
2930

3031
enum class State {

app/src/main/java/org/apache/fineract/data/models/teller/tellerCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.apache.fineract.data.models.teller
33
import com.google.gson.annotations.SerializedName
44

55
data class TellerCommand (
6-
@SerializedName("action") var action: String? = null,
6+
@SerializedName("action") var action: TellerAction? = null,
77
@SerializedName("adjustment") var adjustment: String? = "NONE",
88
@SerializedName("assignedEmployeeIdentifier") var assignedEmployeeIdentifier: String? = null
99
) {

app/src/main/java/org/apache/fineract/ui/online/teller/TellerFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import android.content.Context
55
import android.content.Intent
66
import android.os.Bundle
77
import android.text.TextUtils
8-
import android.util.Log
8+
import android.util.Log.e
99
import android.view.*
10-
import android.widget.Toast
1110
import androidx.appcompat.widget.SearchView
11+
import androidx.lifecycle.Observer
1212
import androidx.lifecycle.ViewModelProviders
1313
import androidx.recyclerview.widget.LinearLayoutManager
1414
import androidx.recyclerview.widget.RecyclerView
@@ -84,7 +84,7 @@ class TellerFragment : FineractBaseFragment(), OnItemClickListener, SwipeRefresh
8484

8585
override fun onStart() {
8686
super.onStart()
87-
viewModel.getTellers()?.observe(this, androidx.lifecycle.Observer {
87+
viewModel.getTellers()?.observe(this, Observer {
8888
it?.let {
8989
tellerList = it
9090
tellerAdapter.setTellerList(it)
@@ -120,7 +120,7 @@ class TellerFragment : FineractBaseFragment(), OnItemClickListener, SwipeRefresh
120120

121121
override fun onRefresh() {
122122
showProgressbar()
123-
viewModel.getTellers()?.observe(this, androidx.lifecycle.Observer {
123+
viewModel.getTellers()?.observe(this, Observer {
124124
it?.let {
125125
tellerList = it
126126
tellerAdapter.setTellerList(it)

app/src/main/java/org/apache/fineract/ui/online/teller/createteller/TellerDetailsStepFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.view.View
1111
import android.view.ViewGroup
1212
import android.widget.EditText
1313
import com.wajahatkarim3.easyvalidation.core.view_ktx.validator
14+
import kotlinx.android.synthetic.main.fragment_step_group_details.view.*
1415
import kotlinx.android.synthetic.main.fragment_step_teller_details.*
1516
import kotlinx.android.synthetic.main.fragment_step_teller_details.view.*
1617
import org.apache.fineract.R
@@ -57,6 +58,7 @@ class TellerDetailsStepFragment : FineractBaseFragment(), Step {
5758
private fun populateData() {
5859
val teller = (activity as CreateTellerActivity).getTeller()
5960
rootView.etTellerCode.setText(teller.code)
61+
rootView.etTellerAccountIdentifier.isEnabled = false
6062
rootView.etTellerPassword.setText(teller.password)
6163
rootView.etTellerCashdrawlimit.setText(teller.cashdrawLimit.toString())
6264
rootView.etTellerAccountIdentifier.setText(teller.tellerAccountIdentifier)

app/src/main/java/org/apache/fineract/ui/online/teller/tellerdetails/TellerDetailsFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class TellerDetailsFragment : FineractBaseFragment() {
8080
putExtra(Constants.TELLER_ACTION, TellerAction.EDIT)
8181
}
8282
startActivity(intent)
83+
activity!!.finish()
8384
}
8485
}
8586
return super.onOptionsItemSelected(item)

app/src/main/java/org/apache/fineract/ui/online/teller/tellerlist/TellerViewModel.kt

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package org.apache.fineract.ui.online.teller.tellerlist
22

33
import android.annotation.SuppressLint
4+
import android.util.Log.e
45
import androidx.lifecycle.LiveData
56
import androidx.lifecycle.MutableLiveData
67
import androidx.lifecycle.ViewModel
8+
import com.couchbase.lite.Expression
79
import io.reactivex.Observable
810
import io.reactivex.android.schedulers.AndroidSchedulers
9-
import io.reactivex.observers.DisposableCompletableObserver
1011
import io.reactivex.schedulers.Schedulers
1112
import kotlinx.coroutines.*
13+
import org.apache.fineract.couchbase.DocumentType
1214
import org.apache.fineract.couchbase.SynchronizationManager
1315
import org.apache.fineract.data.Status
14-
import org.apache.fineract.data.datamanager.DataManagerTeller
1516
import org.apache.fineract.data.datamanager.api.DataManagerAnonymous
1617
import org.apache.fineract.data.local.PreferencesHelper
18+
import org.apache.fineract.data.models.Group
1719
import org.apache.fineract.data.models.customer.Country
1820
import org.apache.fineract.data.models.teller.Teller
1921
import org.apache.fineract.data.models.teller.TellerCommand
2022
import org.apache.fineract.utils.DateUtils
23+
import org.apache.fineract.utils.serializeToMap
24+
import org.apache.fineract.utils.toDataClass
2125
import java.lang.Exception
2226

2327
/*
@@ -29,8 +33,7 @@ import java.lang.Exception
2933
*/
3034
class TellerViewModel(private val synchronizationManager: SynchronizationManager,
3135
private val dataManagerAnonymous: DataManagerAnonymous,
32-
private val preferencesHelper: PreferencesHelper,
33-
private val dataManagerTeller: DataManagerTeller
36+
private val preferencesHelper: PreferencesHelper
3437
) : ViewModel() {
3538

3639
var tellersList = MutableLiveData<ArrayList<Teller>>()
@@ -44,13 +47,18 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
4447

4548
@SuppressLint("CheckResult")
4649
fun getTellers(): MutableLiveData<ArrayList<Teller>>? {
47-
48-
dataManagerTeller.getTellers().subscribeOn(Schedulers.io())
49-
.observeOn(AndroidSchedulers.mainThread())
50-
.subscribe{
51-
tellersList.value = it as ArrayList<Teller>?
52-
}
53-
50+
val expression = Expression.property("documentType")
51+
.equalTo(Expression.string(DocumentType.TELLER.value))
52+
.and(Expression.property("state").notEqualTo(Expression.string("null")))
53+
val hashMapList = synchronizationManager.getDocuments(expression)
54+
if (hashMapList?.isEmpty() == null) {
55+
return null
56+
}
57+
val list = arrayListOf<Teller>()
58+
for (map in hashMapList) {
59+
list.add(map.toDataClass())
60+
}
61+
tellersList.value = list
5462
return tellersList
5563
}
5664

@@ -81,17 +89,8 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
8189
teller.lastModifiedOn = DateUtils.getCurrentDate()
8290
teller.lastOpenedBy = preferencesHelper.userName
8391
teller.lastOpenedOn = DateUtils.getCurrentDate()
84-
dataManagerTeller.createTeller(teller).subscribeOn(Schedulers.io())
85-
.observeOn(AndroidSchedulers.mainThread())
86-
.subscribeWith(object : DisposableCompletableObserver() {
87-
override fun onComplete() {
88-
_status.value = Status.DONE
89-
}
90-
91-
override fun onError(e: Throwable) {
92-
_status.value = Status.ERROR
93-
}
94-
})
92+
synchronizationManager.saveDocument(teller.tellerAccountIdentifier!!, teller.serializeToMap())
93+
_status.value = Status.DONE
9594
} catch (exception: Exception) {
9695
_status.value = Status.ERROR
9796
}
@@ -110,17 +109,8 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
110109
teller.lastModifiedOn = DateUtils.getCurrentDate()
111110
teller.lastOpenedBy = preferencesHelper.userName
112111
teller.lastOpenedOn = DateUtils.getCurrentDate()
113-
dataManagerTeller.updateTeller(teller).subscribeOn(Schedulers.io())
114-
.observeOn(AndroidSchedulers.mainThread())
115-
.subscribeWith(object : DisposableCompletableObserver() {
116-
override fun onComplete() {
117-
_status.value = Status.DONE
118-
}
119-
120-
override fun onError(e: Throwable) {
121-
_status.value = Status.ERROR
122-
}
123-
})
112+
synchronizationManager.updateDocument(teller.tellerAccountIdentifier!!, teller.serializeToMap())
113+
_status.value = Status.DONE
124114
} catch (exception: Exception) {
125115
_status.value = Status.ERROR
126116
}
@@ -133,17 +123,14 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
133123
withContext(Dispatchers.Main) {
134124
try {
135125
_status.value = Status.LOADING
136-
dataManagerTeller.changeTellerStatus(teller, command).subscribeOn(Schedulers.io())
137-
.observeOn(AndroidSchedulers.mainThread())
138-
.subscribeWith(object : DisposableCompletableObserver() {
139-
override fun onComplete() {
140-
_status.value = Status.DONE
141-
}
142-
143-
override fun onError(e: Throwable) {
144-
_status.value = Status.ERROR
145-
}
146-
})
126+
when (command.action) {
127+
TellerCommand.TellerAction.ACTIVATE -> teller.state = Teller.State.ACTIVE
128+
TellerCommand.TellerAction.CLOSE -> teller.state = Teller.State.CLOSED
129+
TellerCommand.TellerAction.REOPEN -> teller.state = Teller.State.OPEN
130+
else -> teller.state = Teller.State.PAUSED
131+
}
132+
synchronizationManager.updateDocument(teller.tellerAccountIdentifier!!, teller.serializeToMap())
133+
_status.value = Status.DONE
147134
} catch (e: Exception) {
148135
_status.value = Status.ERROR
149136
}
@@ -179,6 +166,7 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
179166
override fun onCleared() {
180167
super.onCleared()
181168
viewModelJob.cancel()
169+
synchronizationManager.closeDatabase()
182170
}
183171

184172
}

app/src/main/java/org/apache/fineract/ui/online/teller/tellerlist/TellerViewModelFactory.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import javax.inject.Inject
1717
class TellerViewModelFactory @Inject constructor(@ApplicationContext var context: Context,
1818
private val synchronizationManager: SynchronizationManager,
1919
private val dataManagerAnonymous: DataManagerAnonymous,
20-
private val preferencesHelper: PreferencesHelper,
21-
private val dataManagerTeller: DataManagerTeller
20+
private val preferencesHelper: PreferencesHelper
2221
) : ViewModelProvider.NewInstanceFactory() {
2322

2423
@Suppress("UNCHECKED_CAST")
2524
override fun <T: ViewModel?> create(modelClass: Class<T>): T {
26-
return TellerViewModel(synchronizationManager, dataManagerAnonymous, preferencesHelper, dataManagerTeller) as T
25+
return TellerViewModel(synchronizationManager, dataManagerAnonymous, preferencesHelper) as T
2726
}
2827
}

app/src/main/java/org/apache/fineract/ui/online/teller/tellertasks/TellerTasksBottomSheetFragment.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,28 @@ class TellerTasksBottomSheetFragment(val teller: Teller) : FineractBaseBottomShe
103103
fun onTaskImageViewClicked() {
104104
when (teller.state) {
105105
Teller.State.ACTIVE -> {
106-
command.action = TellerCommand.TellerAction.CLOSE.toString()
106+
command.action = TellerCommand.TellerAction.CLOSE
107107
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
108108
rootView.tvTellerHeader.text = getString(R.string.close)
109109
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.close))
110110
rootView.btnTellerSubmitTask.text = getString(R.string.close)
111111
}
112112
Teller.State.PAUSED -> {
113-
command.action = TellerCommand.TellerAction.ACTIVATE.toString()
113+
command.action = TellerCommand.TellerAction.ACTIVATE
114114
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
115115
rootView.tvTellerHeader.text = getString(R.string.activate)
116116
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.activate))
117117
rootView.btnTellerSubmitTask.text = getString(R.string.activate)
118118
}
119119
Teller.State.CLOSED -> {
120-
command.action = TellerCommand.TellerAction.REOPEN.toString()
120+
command.action = TellerCommand.TellerAction.REOPEN
121121
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
122122
rootView.tvTellerHeader.text = getString(R.string.reopen)
123123
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.reopen))
124124
rootView.btnTellerSubmitTask.text = getString(R.string.reopen)
125125
}
126126
Teller.State.OPEN -> {
127-
command.action = TellerCommand.TellerAction.CLOSE.toString()
127+
command.action = TellerCommand.TellerAction.CLOSE
128128
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
129129
rootView.tvTellerHeader.text = getString(R.string.close)
130130
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.close))
@@ -138,6 +138,7 @@ class TellerTasksBottomSheetFragment(val teller: Teller) : FineractBaseBottomShe
138138
@OnClick(R.id.btnTellerSubmitTask)
139139
fun submitTask() {
140140
viewModel.changeTellerStatus(teller, command)
141+
activity!!.finish()
141142
}
142143

143144
@OnClick(R.id.btnTellerCancel)

0 commit comments

Comments
 (0)