Skip to content

Commit

Permalink
Androapp5035 edit stock (#27)
Browse files Browse the repository at this point in the history
* ANDROAPP-4900 Integrate RTSM module into capture app

* Fixing exported in debug manifests

Fixing exported in debug manifests

* update dependencies and check styles

* kotlin check style

* Androapp 4915 Link RSTM module with current test program

* Removing RecentActivity section xml code from HomeActivity

* Removing RecentActivity Code code from HomeActivity

* Removing RecentActivity Code from  HomeViewModel.kt

* Removing data persistent package and it's files

* Removed this package files

* Removing imports

* Removinf imports from HomeViewModel

* Removed imports

* Removing un necessary usages.

* Delete RecentActivityAdapter

* Removing all code inside dtabaseModule

* Deliting no used functions

* Remove un necessary code

* Delete DatabaseModule.kt

* Update paperwork.json

* Removing room libraries

* Removing TypeConverter Annotation

* Update paperwork.json

* Removing room compile Options annotation

* Update paperwork.json

* Update paperwork.json

* kotlin check style

* Update dhis2-android-sdk

* Adding variables inside homeActivity xml file

* Adding new topbar to all activity_home.xml files

* Update strings.xml

* Adding variables

* Impoting variables

* Update HomeActivity.java

* Update paperwork.json

* Create ic_filter.xml

* Call Settings Activity

* Update paperwork.json

* Setting title and subtitle

* Set title on select DestributionType

* Update paperwork.json

* Adding from and to Strings.

I have added this only in the main strings.xm file. So you i did't dothe transactions.

* Adding Topbar logic usecase according to selected TransactionType

* Update paperwork.json

* Update HomeActivity.java

* Update paperwork.json

* Changing subtitle font size

* change status bar color dynamically

* Update paperwork.json

* Update dhis2-android-sdk

* Update paperwork.json

* Adding title and subTitle Variables.

* Adding title and subtile variables and removing commented code.

* Removing theme variable

* Removing theme variable

* Removing theme variable

* Removing setTitle and Subtitle Method

* Create method to set title on Toolbar

* Binding data from HomeViewmodel to activity_home.xml file

* inding data from HomeViewModel to activity_home.xml files

* Update paperwork.json

* Add data dynamically to android studio

* Adding method to set subtitle

* Removing methods from HomeActivity

* Update paperwork.json

* Removing not used variables

* Update HomeViewModel.kt

* Update paperwork.json

* Update HomeViewModel.kt

* Implement back buttton.

* Status bar color changing support from API 21+

* Update paperwork.json

* Update dhis2-android-sdk

* Correting title on toolbar click sequence

* Update HomeViewModel.kt

* Update paperwork.json

* Test: Toolbar on title change

* Update dhis2-android-sdk

* Test: Toolbar on subtitle change

* Androapp 4924 (#7)

* update SDK

* Create android.yml (#8)

* setup ci (#9)

* Fix item list layout

* Fix imports on ProgramFragment.kt

* Androapp 4930 (#12)

ANDROAPP-4930 Replace Sync button behaviour

* Androapp 4923 (#11) Settings section new layout

* Sync develop (#15)

* Androapp 4955 (#13)

App bar design review

* fix GranularSyncPresenterImpl.kt test

* Androapp 4953 (#14)

* Androapp 5000 (#16)

Create DataentryFragment

* Androapp 5025 (#17)

Move Search box and scan code buttons to Dataentry section

* Androapp 4925 (#18)

* Implement table structure for data entry

* Initialize ManageStockViewModel.kt to get data entry into table

* stock table label

* update

* loading ManageStockViewModel.kt for data entry

* building table for data entry

* updade

* Removing initialization by SavedStateHandle, removing init method to initialize data

* Resolving merge

* Resolving code style

* update

* update

* adding test dependency

* resolving tests

* update

* resolving code style

* resolving manage stock view model unit test

* initializing transaction

* update

* resolving code style

* removing stock management

* Insert table into main content

* moving table, methods and removing unnecessary vars

* fixing code style

* removing form dependency

* removing hardcoded appconfig

* removing commend and make proceed button go to review

* resolving code style

* Changing text color

* calling mdc theme as parent of the tree component

* moving mapTableModel to ManageStockViewModel.kt

* implementing mapTableModel to ManageStockViewModel.kt

* Removing mdctheme

* Resolving code style

* Androapp 5036 (#19)

Implement search

* ANDROAPP-4900 Integrate RTSM module into capture app

* Fixing exported in debug manifests

Fixing exported in debug manifests

* update dependencies and check styles

* kotlin check style

* Androapp 4915 Link RSTM module with current test program

* Removing RecentActivity section xml code from HomeActivity

* Removing RecentActivity Code code from HomeActivity

* Removing RecentActivity Code from  HomeViewModel.kt

* Removing data persistent package and it's files

* Removed this package files

* Removing imports

* Removinf imports from HomeViewModel

* Removed imports

* Removing un necessary usages.

* Delete RecentActivityAdapter

* Removing all code inside dtabaseModule

* Deliting no used functions

* Remove un necessary code

* Delete DatabaseModule.kt

* Update paperwork.json

* Removing room libraries

* Removing TypeConverter Annotation

* Update paperwork.json

* Removing room compile Options annotation

* Update paperwork.json

* Update paperwork.json

* kotlin check style

* Adding variables inside homeActivity xml file

* Adding new topbar to all activity_home.xml files

* Update strings.xml

* Adding variables

* Impoting variables

* Update HomeActivity.java

* Update paperwork.json

* Create ic_filter.xml

* Call Settings Activity

* Update paperwork.json

* Setting title and subtitle

* Set title on select DestributionType

* Update paperwork.json

* Adding from and to Strings.

I have added this only in the main strings.xm file. So you i did't dothe transactions.

* Adding Topbar logic usecase according to selected TransactionType

* Update paperwork.json

* Update HomeActivity.java

* Update paperwork.json

* Changing subtitle font size

* Update paperwork.json

* change status bar color dynamically

* Update paperwork.json

* Adding title and subTitle Variables.

* Adding title and subtile variables and removing commented code.

* Removing theme variable

* Removing theme variable

* Removing theme variable

* Removing setTitle and Subtitle Method

* Create method to set title on Toolbar

* Binding data from HomeViewmodel to activity_home.xml file

* inding data from HomeViewModel to activity_home.xml files

* Update paperwork.json

* Add data dynamically to android studio

* Adding method to set subtitle

* Removing methods from HomeActivity

* Update paperwork.json

* Removing not used variables

* Update HomeViewModel.kt

* Update paperwork.json

* Update HomeViewModel.kt

* Implement back buttton.

* Update paperwork.json

* Status bar color changing support from API 21+

* Correting title on toolbar click sequence

* Update HomeViewModel.kt

* Update paperwork.json

* Test: Toolbar on title change

* Test: Toolbar on subtitle change

* Androapp 4924 (#7)

* Create android.yml (#8)

* setup ci (#9)

* Fix item list layout

* Fix imports on ProgramFragment.kt

* Androapp 4930 (#12)

ANDROAPP-4930 Replace Sync button behaviour

* Androapp 4923 (#11) Settings section new layout

* Sync develop (#15)

* Androapp 4955 (#13)

App bar design review

* fix GranularSyncPresenterImpl.kt test

* Androapp 4953 (#14)

* Androapp 5000 (#16)

Create DataentryFragment

* Androapp 5025 (#17)

Move Search box and scan code buttons to Dataentry section

* Androapp 4925 (#18)

* Implement table structure for data entry

* Initialize ManageStockViewModel.kt to get data entry into table

* stock table label

* update

* loading ManageStockViewModel.kt for data entry

* building table for data entry

* updade

* Removing initialization by SavedStateHandle, removing init method to initialize data

* Resolving merge

* Resolving code style

* update

* update

* adding test dependency

* resolving tests

* update

* resolving code style

* resolving manage stock view model unit test

* initializing transaction

* update

* resolving code style

* removing stock management

* Insert table into main content

* moving table, methods and removing unnecessary vars

* fixing code style

* removing form dependency

* removing hardcoded appconfig

* removing commend and make proceed button go to review

* resolving code style

* Changing text color

* calling mdc theme as parent of the tree component

* moving mapTableModel to ManageStockViewModel.kt

* implementing mapTableModel to ManageStockViewModel.kt

* Removing mdctheme

* Resolving code style

* Androapp 5036 (#19)

Implement search

* update table usage

* Androapp 5037 (#21)

Implement scan button

* adding testing credentials to lmis

* fix code style

* implementing data entry

* Adding Verifications to solve table colors (#22)

Correct table color

* implementing data entry: test

* creating state for table data entry

* implementing screen state and stock item load

* feat: [ANDROAPP-4919] Remove SDK submodule and use LMIS SNAPSHOT

* Implementing data entry with item cache stored: blocked

* fixing merge conflicts

* stock items

* when user finish edition apply program rules

* Set title and subtitle on input field

* Implementing conceal backdrop when cell is clicked and table error management

* code style format

* unused var

* code style format (removing comma)

* code style format

* refactoring table error handler

* refactoring table on edit cell

* refactoring table on edit cell to conceal backdrop

* code style check

* [ANDROAPP-5035] avoid crash on backdrop

Co-authored-by: Miguel Vasco Macamo <[email protected]>
Co-authored-by: Carlos Macaneta <[email protected]>
Co-authored-by: Carlos Macaneta <[email protected]>
Co-authored-by: andresmr <[email protected]>
  • Loading branch information
5 people committed Feb 8, 2023
1 parent a4feade commit 415d680
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 105 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/paperwork.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildTime":"2022-11-29 16:42","gitSha":"9b13dc04d"}
{"buildTime":"2022-11-30 14:55","gitSha":"502a8af8a"}
9 changes: 2 additions & 7 deletions stock-managment/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@
<application android:supportsRtl="true">
<activity
android:name=".ui.home.HomeActivity"
android:exported="false" />
<activity
android:name=".ui.managestock.ManageStockActivity"
android:exported="false"
android:parentActivityName=".ui.home.HomeActivity"
android:windowSoftInputMode="stateHidden|adjustResize" />
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".ui.reviewstock.ReviewStockActivity"
android:exported="false"
android:parentActivityName=".ui.managestock.ManageStockActivity"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".ui.scanner.ScannerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {
supportFragmentManager,
this@HomeActivity,
barcodeLauncher,
{ scope, scaffold -> navigateToReviewStock(scope, scaffold) }
::navigateToReviewStock
) { scope, scaffold ->
synchronizeData(
scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ fun Backdrop(
manageStockViewModel,
hasFacilitySelected,
hasDestinationSelected,
homeContext,
barcodeLauncher
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import com.journeyapps.barcodescanner.ScanOptions
import kotlinx.coroutines.launch
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.data.TransactionType
import org.dhis2.android.rtsm.ui.home.HomeActivity
import org.dhis2.android.rtsm.ui.home.HomeViewModel
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel
import org.dhis2.android.rtsm.ui.managestock.components.ManageStockTable
Expand All @@ -63,7 +62,6 @@ fun MainContent(
manageStockViewModel: ManageStockViewModel,
hasFacilitySelected: Boolean,
hasDestinationSelected: Boolean?,
homeContext: HomeActivity,
barcodeLauncher: ActivityResultLauncher<ScanOptions>
) {
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -206,21 +204,27 @@ fun MainContent(
) {
if (hasFacilitySelected && hasDestinationSelected == true) {
updateTableState(manageStockViewModel, viewModel)
ManageStockTable(manageStockViewModel)
ManageStockTable(manageStockViewModel) {
scope.launch { backdropState.conceal() }
}
}
} else if (viewModel.toolbarTitle.collectAsState().value.name
== TransactionType.CORRECTION.name
) {
if (hasFacilitySelected) {
updateTableState(manageStockViewModel, viewModel)
ManageStockTable(manageStockViewModel)
ManageStockTable(manageStockViewModel) {
scope.launch { backdropState.conceal() }
}
}
} else if (viewModel.toolbarTitle.collectAsState().value.name
== TransactionType.DISCARD.name
) {
if (hasFacilitySelected) {
updateTableState(manageStockViewModel, viewModel)
ManageStockTable(manageStockViewModel)
ManageStockTable(manageStockViewModel) {
scope.launch { backdropState.conceal() }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.dhis2.android.rtsm.ui.managestock

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.Transformations
import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope
Expand All @@ -14,6 +13,8 @@ import java.util.Collections
import java.util.Date
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.commons.Constants.QUANTITY_ENTRY_DEBOUNCE
Expand All @@ -33,21 +34,24 @@ import org.dhis2.android.rtsm.services.rules.RuleValidationHelper
import org.dhis2.android.rtsm.services.scheduler.BaseSchedulerProvider
import org.dhis2.android.rtsm.ui.base.ItemWatcher
import org.dhis2.android.rtsm.ui.base.SpeechRecognitionAwareViewModel
import org.dhis2.android.rtsm.utils.Utils.Companion.isValidStockOnHand
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.composetable.TableScreenState
import org.dhis2.composetable.model.KeyboardInputType
import org.dhis2.composetable.model.RowHeader
import org.dhis2.composetable.model.TableCell
import org.dhis2.composetable.model.TableHeader
import org.dhis2.composetable.model.TableHeaderCell
import org.dhis2.composetable.model.TableHeaderRow
import org.dhis2.composetable.model.TableModel
import org.dhis2.composetable.model.TableRowModel
import org.dhis2.composetable.model.TextInputModel
import org.hisp.dhis.rules.models.RuleActionAssign
import org.hisp.dhis.rules.models.RuleEffect
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

@HiltViewModel
class ManageStockViewModel @Inject constructor(
savedState: SavedStateHandle,
private val disposable: CompositeDisposable,
private val schedulerProvider: BaseSchedulerProvider,
preferenceProvider: PreferenceProvider,
Expand Down Expand Up @@ -76,23 +80,29 @@ class ManageStockViewModel @Inject constructor(
val operationState: LiveData<OperationState<LiveData<PagedList<StockItem>>>>
get() = _networkState

private val _allTableState = MutableStateFlow<List<TableModel>>(mutableListOf())
private val allTableState: StateFlow<List<TableModel>> = _allTableState

private val _screenState: MutableLiveData<TableScreenState> = MutableLiveData(
TableScreenState(emptyList(), false)
)
val screenState: LiveData<TableScreenState> = _screenState

private val _stockItems: MutableLiveData<PagedList<StockItem>> =
MutableLiveData<PagedList<StockItem>>()

fun setup(transaction: Transaction) {
_transaction.value = transaction

configureRelays()
loadStockItems()

refreshData()
}

fun refreshData() {
viewModelScope.launch {
getStockItems().asFlow().collect {
_stockItems.value = it
tableRowData(
it,
resources.getString(R.string.stock),
Expand Down Expand Up @@ -193,19 +203,25 @@ class ManageStockViewModel @Inject constructor(
row = index
),
values = mapOf(
0 to TableCell(
id = item.id,
row = index,
column = 0,
editable = false,
value = item.stockOnHand
Pair(
0,
TableCell(
id = item.id,
row = index,
column = 0,
editable = false,
value = item.stockOnHand
)
),
1 to TableCell(
id = item.id,
row = index,
column = 1,
value = null,
editable = true
Pair(
1,
TableCell(
id = item.id,
row = index,
column = 1,
value = null,
editable = true
)
)
),
maxLines = 3
Expand All @@ -214,12 +230,14 @@ class ManageStockViewModel @Inject constructor(
tableRowModels.add(tableRowModel)
}

_allTableState.value = mapTableModel(
tableRowModels,
stockLabel,
qtdLabel
)

_screenState.value = TableScreenState(
tables = mapTableModel(
tableRowModels,
stockLabel,
qtdLabel
),
tables = allTableState.value,
selectNext = false
)
}
Expand All @@ -245,6 +263,128 @@ class ManageStockViewModel @Inject constructor(
)
)

fun onCellValueChanged(tableCell: TableCell) {
val updatedData = screenState.value?.tables?.map { tableModel ->
if (tableModel.hasCellWithId(tableCell.id)) {
tableModel.copy(
overwrittenValues = mapOf(
Pair(tableCell.column!!, tableCell)
)
)
} else {
tableModel
}
} ?: emptyList()

_screenState.postValue(
TableScreenState(
tables = updatedData,
selectNext = false
)
)
}

fun onCellClick(cell: TableCell): TextInputModel {
val stockItem = _stockItems.value?.find { it.id == cell.id }
val itemName = stockItem?.name ?: ""
return TextInputModel(
id = cell.id ?: "",
mainLabel = itemName,
secondaryLabels = mutableListOf(resources.getString(R.string.quantity)),
currentValue = cell.value,
keyboardInputType = KeyboardInputType.NumericInput(
allowDecimal = false,
allowSigned = false
)
)
}

fun onSaveValueChange(
cell: TableCell,
selectNext: Boolean
) {
// When user taps on done or next. We should apply program rules here
val stockItem = _stockItems.value?.find { it.id == cell.id }
stockItem?.let {
cell.value?.let { value ->
setQuantity(
it, 0, value,
object : ItemWatcher.OnQuantityValidated {
override fun validationCompleted(ruleEffects: List<RuleEffect>) {
// Update fields
ruleEffects.forEach { ruleEffect ->
if (ruleEffect.ruleAction() is RuleActionAssign &&
(
(ruleEffect.ruleAction() as RuleActionAssign).field()
== config.value?.stockOnHand
)
) {
val data = ruleEffect.data()
val isValid: Boolean = isValidStockOnHand(data)
val stockOnHand = if (isValid) data else it.stockOnHand
addItem(it, cell.value, stockOnHand, !isValid)

_allTableState.value = _allTableState.value.map { tableModel ->
tableModel.copy(
tableRows = updateTableRows(tableModel.tableRows, cell)
)
}
}
}

_screenState.postValue(
TableScreenState(
tables = allTableState.value,
selectNext = selectNext
)
)
}
}
)
}
}
}

private fun updateTableRows(
tableRowModels: List<TableRowModel>,
cell: TableCell
): List<TableRowModel> {
return tableRowModels.map { tableRowModel ->
if (tableRowModel.values.values.find { tableCell ->
tableCell.id == cell.id
} != null
) {
tableRowModel.copy(
values = updateTableCells(tableRowModel.values, cell)
)
} else {
tableRowModel
}
}
}

private fun updateTableCells(
tableCells: Map<Int, TableCell>,
cell: TableCell
): Map<Int, TableCell> {
val stockEntry = getPopulatedEntries().find { it.item.id == cell.id }
return tableCells.mapValues { (index, tableCell) ->
when (index) {
0 -> tableCell.copy(
value = stockEntry?.stockOnHand
)
else -> tableCell.copy(
value = stockEntry?.qty,
error = if (stockEntry?.hasError == true) {
resources.getString(R.string.stock_on_hand_exceeded_message)
} else {
null
}
)
}
}
}

fun onSearchQueryChanged(query: String) {
searchRelay.accept(query)
}
Expand All @@ -257,7 +397,7 @@ class ManageStockViewModel @Inject constructor(
item: @NotNull StockItem,
position: @NotNull Int,
qty: @NotNull String,
callback: @Nullable ItemWatcher.OnQuantityValidated?
callback: ItemWatcher.OnQuantityValidated?
) {
entryRelay.accept(RowAction(StockEntry(item, qty), position, callback))
}
Expand Down
Loading

0 comments on commit 415d680

Please sign in to comment.