From d81c537e4f849a60b4818e62835e82ec9b70715e Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 18 Jun 2024 12:28:26 +0200 Subject: [PATCH] feat hasItemOlder #refs 6964 --- .../fragment/PackingHollandFragment.kt | 2 +- .../ubicador/fragment/UbicadorFragmentNew.kt | 81 ++++++++++++++----- .../ubicador/fragment/UbicadorViewModel.kt | 58 +++++++------ 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt index 721de9b1..d766d29e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt @@ -43,7 +43,7 @@ class PackingHollandFragment(var entrypoint: String) : try { shelvingScaned = itemScanValue( - binding.scanInput.text.toString(), "buy", "more" + binding.scanInput.text.toString(), arrayOf("buy"), "more" ).toString().toInt() showQuantityPacking() } catch (ex: Exception) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt index fdaef009..da32389d 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt @@ -58,6 +58,7 @@ class UbicadorFragmentNew( private var isBack = false var listIcons: ArrayList = ArrayList() private lateinit var textWatcher: TextWatcher + private var buyScanned :String = "" companion object { fun newInstance(entryPoint: String, autoSelf: Boolean = false) = @@ -149,12 +150,12 @@ class UbicadorFragmentNew( } if (!isChecked) { - listIcons.removeAt(listIcons.size-1) + listIcons.removeAt(listIcons.size - 1) binding.mainToolbar.toolbarIcons.adapter!!.notifyItemRemoved(listIcons.size) } else { listIcons.add(iconReset) - binding.mainToolbar.toolbarIcons.adapter!!.notifyItemInserted(listIcons.size-1) + binding.mainToolbar.toolbarIcons.adapter!!.notifyItemInserted(listIcons.size - 1) } @@ -247,10 +248,11 @@ class UbicadorFragmentNew( ) } else { try { + buyScanned = itemScanValue( + binding.editMatricula.text.toString(), arrayOf("buy"), "more" + ).toString() viewModel.getIdFromCode( - code = itemScanValue( - binding.editMatricula.text.toString(), "buy", "more" - ).toString() + code = buyScanned ) } catch (ex: Exception) { ma.messageWithSound( @@ -401,14 +403,13 @@ class UbicadorFragmentNew( private fun customDialogActionParking() { parking = customDialogInput.getValue() - //tarea 6964 - /* viewModel.hasItemOlder( - shelvingFk, customDialogInput.getValue(), - action = Action.PARKINEAR - )*/ - viewModel.setParking( - shelvingFk, customDialogInput.getValue() - ) + //tarea 6964 + /* viewModel.hasItemOlder( + shelvingFk, customDialogInput.getValue(), + )*/ + viewModel.setParking( + shelvingFk, customDialogInput.getValue() + ) customDialogInput.dismiss() } @@ -427,7 +428,7 @@ class UbicadorFragmentNew( val listInt: ArrayList = ArrayList() if (listItems.none { it.item == itemScanned }) { - listInt.add(itemScanned) + listInt.add(buyScanned.toLong()) } else { listItems.sortedBy { it.isChecked }.forEachIndexed { index, item -> if (item.item == itemScanned) { @@ -530,6 +531,44 @@ class UbicadorFragmentNew( } } + + loadShelvingListItemNewer.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + if (it.list.isNotEmpty()) { + var formattedList = it.list.map { item -> + val itemFk = item.itemFk + val shelvingFk = item.shelvingFk + "$itemFk (${shelvingFk.uppercase()})" + } + val resultString = formattedList.joinToString(separator = "\n") + val finalOutput = "\n$resultString" + customDialogOlder.setTitle(getString(R.string.info)) + .setDescription( + getString( + R.string.itemOlderInfo, + Action.PARKINEAR + ) + + getString(R.string.listItems) + finalOutput + ) + .setOkButton( + getString(R.string.ok) + ) { + viewModel.setParking( + it.originalShelvingFk, + it.originalParking + ) + + customDialogOlder.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + customDialogOlder.dismiss() + }.show() + + } + } + } + loadResponseHasOlder.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { @@ -702,7 +741,7 @@ class UbicadorFragmentNew( customDialogUbicador.setItemValue( itemScanValue( customDialogUbicador.getItemValue(), - "buy", + arrayOf("buy"), "more" ).toString() ) @@ -874,12 +913,12 @@ class UbicadorFragmentNew( private fun customDialogTransferAction(item: ItemUbicador) { if (customDialogInput.getValue().isNotEmpty()) { /*tearea 6964*/ - /*viewModel.hasItemOlder( - shelvingFkIn = shelvingFk, - shelvingFkOut = customDialogInput.getValue(), - itemFk = item.id, - action = Action.TRANSFERIR - )*/ + /*viewModel.hasItemOlder( + shelvingFkIn = shelvingFk, + shelvingFkOut = customDialogInput.getValue(), + itemFk = item.id, + action = Action.TRANSFERIR + )*/ viewModel.itemShelvingTransfer( item.id, customDialogInput.getValue() ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt index d81d9746..89f97021 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt @@ -10,13 +10,14 @@ import es.verdnatura.domain.formatWithQuotes import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction -import es.verdnatura.presentation.common.Action import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.ItemShelvingSalix import es.verdnatura.presentation.common.ResponseHasOlder import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.ReubicationList +import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer +import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListNew import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListVO @@ -52,6 +53,10 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { val loadShelvingListNew: LiveData> = _shelvingListNew.map { Event(it) } + private val _shelvingListItemNewer by lazy { MutableLiveData() } + val loadShelvingListItemNewer: LiveData> = + _shelvingListItemNewer.map { Event(it) } + private val _reubicationList by lazy { MutableLiveData() } val loadReubicationList: LiveData> = _reubicationList.map { Event(it) } @@ -207,37 +212,38 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { } fun hasItemOlder( - shelvingFkIn: String, - parking: String? = null, - shelvingFkOut: String? = null, - itemFk: Int? = null, - action: Action - ) { - salix.hasItemOlder(shelvingFkIn, parking, shelvingFkOut, itemFk) - .enqueue(object : SalixCallback(context) { + shelvingFk: String, + parking: String, - override fun onSuccess(response: Response) { - if (response.body() == false) { - when (action) { - Action.PARKINEAR -> { - setParking(shelvingFkIn, parking!!) - } + ) { + salix.getListItemNewer(shelvingFk, parking) + .enqueue(object : SalixCallback>(context) { - Action.TRANSFERIR -> itemShelvingTransfer(itemFk!!, shelvingFkOut!!) - } + override fun onSuccess(response: Response>) { + if (response.body()!!.isEmpty()) { + setParking(shelvingFk, parking) } else { - _responseHasOlder.value = ResponseHasOlder( - shelvingFkIn = shelvingFkIn, - parking = parking, - shelvingFkOut = shelvingFkOut, - itemFk = itemFk, - action = action, - hasOlder = true - ) - + _shelvingListItemNewer.value = + response.body()?.let { + ItemShelvingNewerList( + it, + originalParking = parking, + originalShelvingFk = shelvingFk + ) + } } + + /* when (action) { + Action.PARKINEAR -> { + setParking(shelvingFk, parking!!) + } + + // Action.TRANSFERIR -> itemShelvingTransfer(itemFk!!, shelvingFkOut!!) + else -> {} + }*/ } + }) }