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

Fixes #FINCN-326 Create, update, list tellers and Teller Details implemented #189

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,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 @@ -33,6 +34,9 @@ class DataManagerTeller @Inject constructor(val baseManagerApi: BaseApiManager,
baseManagerApi.tellerService.createTeller(preferencesHelper.tenantIdentifier, teller)

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

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

}
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: String? = 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
Expand Up @@ -3,6 +3,7 @@ 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.*

Expand All @@ -19,7 +20,14 @@ interface TellersService {
fun createTeller(@Path("officeIdentifier") officeIdentifier: String,
@Body teller: Teller): Completable

@PUT(EndPoints.API_TELLER_PATH + "/offices/{officeIdentifier}/teller")
@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 @@ -63,6 +63,7 @@
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 @@ -171,5 +172,7 @@ public interface ActivityComponent {
void inject(TellerDetailsStepFragment tellerDetailsStepFragment);

void inject(TellerReviewStepFragment tellerReviewStepFragment);

void inject(TellerTasksBottomSheetFragment tellerTasksBottomSheetFragment);
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.Intent
import android.os.Bundle
import android.view.*
import butterknife.ButterKnife
import butterknife.OnClick
import kotlinx.android.synthetic.main.fragment_teller_details.*
import org.apache.fineract.R
import org.apache.fineract.data.models.teller.Teller
import org.apache.fineract.ui.base.FineractBaseFragment
import org.apache.fineract.ui.base.FineractBaseActivity
import org.apache.fineract.ui.online.teller.TellerAction
import org.apache.fineract.ui.online.teller.createteller.CreateTellerActivity
import org.apache.fineract.ui.online.teller.tellertasks.TellerTasksBottomSheetFragment
import org.apache.fineract.ui.views.CircularImageView
import org.apache.fineract.utils.Constants
import org.apache.fineract.utils.Utils
Expand Down Expand Up @@ -83,6 +85,12 @@ class TellerDetailsFragment : FineractBaseFragment() {
return super.onOptionsItemSelected(item)
}

@OnClick(R.id.tellerDetailsTasks)
fun onTasksCardViewClicked() {
val bottomSheet = TellerTasksBottomSheetFragment(teller)
bottomSheet.show(childFragmentManager, getString(R.string.tasks))
}

private fun setTellerStatusIcon(status: Teller.State?, imageView: CircularImageView) {
when (status) {
Teller.State.OPEN -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import org.apache.fineract.data.Status
import org.apache.fineract.data.datamanager.DataManagerTeller
import org.apache.fineract.data.datamanager.api.DataManagerAnonymous
import org.apache.fineract.data.local.PreferencesHelper
import org.apache.fineract.data.models.customer.Command
import org.apache.fineract.data.models.customer.Country
import org.apache.fineract.data.models.teller.Teller
import org.apache.fineract.data.models.teller.TellerCommand
import org.apache.fineract.utils.DateUtils
import java.lang.Exception

Expand Down Expand Up @@ -128,6 +128,29 @@ class TellerViewModel(private val synchronizationManager: SynchronizationManager
}
}

fun changeTellerStatus(teller: Teller, command: TellerCommand) {
uiScope.launch {
withContext(Dispatchers.Main) {
try {
_status.value = Status.LOADING
dataManagerTeller.changeTellerStatus(teller, command).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableCompletableObserver() {
override fun onComplete() {
_status.value = Status.DONE
}

override fun onError(e: Throwable) {
_status.value = Status.ERROR
}
})
} catch (e: Exception) {
_status.value = Status.ERROR
}
}
}
}

fun getCountryNames(countries: List<Country>): List<String> {
return Observable.fromIterable(countries).map { country: Country -> country.name }.toList().blockingGet()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package org.apache.fineract.ui.online.teller.tellertasks

import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import butterknife.ButterKnife
import butterknife.OnClick
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.fragment_teller_tasks_bottom_sheet.view.*
import org.apache.fineract.R
import org.apache.fineract.data.Status
import org.apache.fineract.data.models.teller.Teller
import org.apache.fineract.data.models.teller.TellerCommand
import org.apache.fineract.ui.base.FineractBaseActivity
import org.apache.fineract.ui.base.FineractBaseBottomSheetDialogFragment
import org.apache.fineract.ui.base.Toaster
import org.apache.fineract.ui.online.teller.tellerlist.TellerViewModel
import org.apache.fineract.ui.online.teller.tellerlist.TellerViewModelFactory
import javax.inject.Inject

/*
* Created by Varun Jain on 21.06.2021
*/

class TellerTasksBottomSheetFragment(val teller: Teller) : FineractBaseBottomSheetDialogFragment() {

lateinit var rootView: View
private var command = TellerCommand()
lateinit var behavior: BottomSheetBehavior<*>
private lateinit var viewModel: TellerViewModel

@Inject
lateinit var viewModelFactory: TellerViewModelFactory

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
rootView = View.inflate(context, R.layout.fragment_teller_tasks_bottom_sheet, null)
dialog.setContentView(rootView)
behavior = BottomSheetBehavior.from(rootView.parent as View)
(activity as FineractBaseActivity).activityComponent.inject(this)
ButterKnife.bind(this, rootView)
viewModel = ViewModelProviders.of(this, viewModelFactory).get(TellerViewModel::class.java)

setDataOnViews()
subscribeUI()
return dialog
}

private fun subscribeUI() {
viewModel.status.observe(this, Observer { status ->
when (status) {
Status.LOADING -> {
showMifosProgressDialog(getString(R.string.please_wait_updating_teller_status))
}
Status.ERROR -> {
hideMifosProgressDialog()
Toaster.show(rootView, R.string.error_while_updating_teller_status, Toast.LENGTH_SHORT)
}
Status.DONE -> {
Toaster.show(rootView, getString(R.string.teller_identifier_updated_successfully, teller.tellerAccountIdentifier), Toast.LENGTH_SHORT)
hideMifosProgressDialog()
dismiss()
}
}
})
}

private fun setDataOnViews() {
when (teller.state) {
Teller.State.ACTIVE -> {
rootView.ivTellerTask.setImageDrawable(
ContextCompat.getDrawable(activity!!, R.drawable.ic_close_black_24dp))
rootView.ivTellerTask.setColorFilter(ContextCompat.getColor(activity!!, R.color.red_dark))
rootView.tvTellerTask.text = getString(R.string.close)
}
Teller.State.OPEN -> {
rootView.ivTellerTask.setImageDrawable(
ContextCompat.getDrawable(activity!!, R.drawable.ic_close_black_24dp))
rootView.ivTellerTask.setColorFilter(ContextCompat.getColor(activity!!, R.color.red_dark))
rootView.tvTellerTask.text = getString(R.string.close)
}
Teller.State.CLOSED -> {
rootView.ivTellerTask.setImageDrawable(
ContextCompat.getDrawable(activity!!, R.drawable.ic_check_circle_black_24dp))
rootView.ivTellerTask.setColorFilter(ContextCompat.getColor(activity!!, R.color.status))
rootView.tvTellerTask.text = getString(R.string.reopen)
}
Teller.State.PAUSED -> {
rootView.ivTellerTask.setImageDrawable(
ContextCompat.getDrawable(activity!!, R.drawable.ic_check_circle_black_24dp))
rootView.ivTellerTask.setColorFilter(ContextCompat.getColor(activity!!, R.color.status))
rootView.tvTellerTask.text = getString(R.string.activate)
}
}
}

@OnClick(R.id.ivTellerTask)
fun onTaskImageViewClicked() {
when (teller.state) {
Teller.State.ACTIVE -> {
command.action = TellerCommand.TellerAction.CLOSE.toString()
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
rootView.tvTellerHeader.text = getString(R.string.close)
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.close))
rootView.btnTellerSubmitTask.text = getString(R.string.close)
}
Teller.State.PAUSED -> {
command.action = TellerCommand.TellerAction.ACTIVATE.toString()
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
rootView.tvTellerHeader.text = getString(R.string.activate)
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.activate))
rootView.btnTellerSubmitTask.text = getString(R.string.activate)
}
Teller.State.CLOSED -> {
command.action = TellerCommand.TellerAction.REOPEN.toString()
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
rootView.tvTellerHeader.text = getString(R.string.reopen)
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.reopen))
rootView.btnTellerSubmitTask.text = getString(R.string.reopen)
}
Teller.State.OPEN -> {
command.action = TellerCommand.TellerAction.CLOSE.toString()
command.assignedEmployeeIdentifier = teller.assignedEmployee.toString()
rootView.tvTellerHeader.text = getString(R.string.close)
rootView.tvTellerSubHeader.text = getString(R.string.please_verify_following_teller_task, getString(R.string.close))
rootView.btnTellerSubmitTask.text = getString(R.string.close)
}
}
rootView.llTellerTaskList.visibility = View.GONE
rootView.llTellerTaskForm.visibility = View.VISIBLE
}

@OnClick(R.id.btnTellerSubmitTask)
fun submitTask() {
viewModel.changeTellerStatus(teller, command)
}

@OnClick(R.id.btnTellerCancel)
fun onCancel() {
dismiss()
}

override fun onStart() {
super.onStart()
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}

override fun onDestroy() {
super.onDestroy()
hideMifosProgressBar()
}
}
Loading