From 3203e35698c0ce4b9df9f6b60c62c99cb3df9b3b Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Wed, 31 Jul 2024 12:15:51 +0200 Subject: [PATCH] feat multipleUbicator refs #7805 --- .../java/es/verdnatura/domain/SalixService.kt | 2 +- .../presentation/common/SalixBackItems.kt | 2 +- .../inventario/fragment/InventaryViewModel.kt | 5 +- .../ubicador/fragment/UbicadorFragmentNew.kt | 203 ++++++++++++++++-- .../ubicador/fragment/UbicadorViewModel.kt | 88 ++++++-- app/src/main/res/values-es/strings.xml | 2 + 6 files changed, 262 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index c0353a48..99bad8a3 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -1041,7 +1041,7 @@ interface SalixService { fun itemShelvingUpdate( @Path("id") id: Number, @Body params: Any - ): Call + ): Call @POST("ItemShelvings/update") fun itemShelvingsUpdate( diff --git a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt index a61fc951..9f62e87f 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt @@ -40,7 +40,7 @@ data class ItemShelvingSaleSalix( data class ItemShelvingSalix( var visible: Int, - var packing: Int, + var packing: Int?, var grouping: Int? ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt index 39ac6a48..afbae503 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt @@ -20,6 +20,7 @@ import es.verdnatura.presentation.view.feature.inventario.model.InventaryListVO import es.verdnatura.presentation.view.feature.inventario.model.InventoryParkingList import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventoryParking +import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistakeList import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix @@ -105,8 +106,8 @@ class InventaryViewModel(val context: Context) : BaseViewModel(context) { ) { salix.itemShelvingUpdate(itemShelvingFk, params) - .enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { + .enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { _responseReset.value = response.message() super.onSuccess(response) } 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 49c80348..fd19b4c2 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 @@ -12,6 +12,7 @@ import android.view.View.VISIBLE import android.view.inputmethod.EditorInfo import android.widget.ImageView import android.widget.Toast +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R import es.verdnatura.databinding.FragmentUbicadorBinding @@ -22,6 +23,7 @@ import es.verdnatura.domain.toInt import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.Action +import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnMoreClickListenerNew import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener @@ -30,15 +32,18 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.itemScanValue import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.component.CustomDialogList import es.verdnatura.presentation.view.component.CustomDialogTwoButtons import es.verdnatura.presentation.view.component.CustomDialogUbicadorNew +import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador - +import kotlinx.coroutines.launch @Suppress("UNUSED_ANONYMOUS_PARAMETER") -class UbicadorFragmentNew: BaseFragment( +class UbicadorFragmentNew : BaseFragment( UbicadorViewModel::class ) { private var shelvingFk: String = "" @@ -61,6 +66,10 @@ class UbicadorFragmentNew: BaseFragment = ArrayList() private lateinit var textWatcher: TextWatcher private var buyScanned: String = "" + private lateinit var customDialogList: CustomDialogList + private var listShelvings: ArrayList = ArrayList() + private var listShelvingsAdapter: BarcodeAdapter? = null + private var locateMultipleShelvings: Boolean = false companion object { private const val ARG_SHELVINGFK = "shelvingFk" @@ -73,6 +82,7 @@ class UbicadorFragmentNew: BaseFragment + val formattedList = it.list.map { item -> val itemFk = item.itemFk val shelvingFk = item.shelvingFk "$itemFk (${shelvingFk.uppercase()})" @@ -818,17 +834,25 @@ class UbicadorFragmentNew: BaseFragment + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (customDialogList.getValue().isNotEmpty()) { + + try { + customDialogList.setValue( + itemScanValue( + customDialogList.getValue(), + arrayOf("saleGroup"), + field = "id" + ).toString() + ) + if (customDialogList.getValue().isShelving()) { + if (listShelvings.firstOrNull { it.code == customDialogList.getValue() } == null) { + listShelvings.add(BarcodeVO(code = customDialogList.getValue())) + /*viewModel.sectorCollectionSaleGroupAdd( + customDialogList.getValue().toInt(), collectionFk + )*/ + } else { + throw Exception(getString(R.string.errorRepeatedShelving)) + } + } else { + throw Exception() + } + + } catch (ex: Exception) { + ma.messageWithSound( + getString(R.string.errorInput), + isError = true, + isPlayed = true, + isToasted = true + ) + listShelvings.removeAt(0) + } + + listShelvingsAdapter!!.notifyItemChanged(0) + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + listShelvingsAdapter = BarcodeAdapter( + listShelvings, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + + } + }, showDelete = false + ) + customDialogList.getRecyclerView().adapter = listShelvingsAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + private fun setWatcher() { customDialogUbicador.addTextWatcher(customDialogUbicador.getPackingItem()) { s -> @@ -928,16 +1041,27 @@ class UbicadorFragmentNew: BaseFragment + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + + actionRename(item, customDialogInput.getValue()) + return@setOnEditorActionListener true + } + false + } + customDialogInput.getEditText().requestFocus() + }*/ customDialogTwoButtons.setKoButton(getString(R.string.cancel)) { customDialogTwoButtons.dismiss() @@ -946,6 +1070,39 @@ class UbicadorFragmentNew: BaseFragment(context) { override fun onResponse(call: Call, response: Response) { + + + if (!createdRename.isNullOrBlank() && response.body()!=null) { + + val jsonArray = JsonParser().parse(response.body().toString()).asJsonArray + val jsonObject = jsonArray.get(0).asJsonObject + itemShelvingUpdateCreated(itemShelvingFk = (jsonObject.get("LAST_INSERT_ID()") as JsonPrimitive).asInt, created = createdRename) + } else { + _responseMake.value = + ResponseItemVO(isError = false, response = response.message()!!) + } _responseMake.value = ResponseItemVO(isError = false, response = response.message()!!) super.onResponse(call, response) @@ -185,14 +204,14 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { } fun itemShelvingMakeEdit( - quantity: Int, packing: Int, itemShelvingFk: Int, grouping: Int? + quantity: Int, packing: Int?, itemShelvingFk: Int, grouping: Int? ) { salix.itemShelvingUpdate( params = ItemShelvingSalix(visible = quantity, packing = packing, grouping = grouping), id = itemShelvingFk, - ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { _responseMake.value = ResponseItemVO(isError = false, response = response.message()!!) } @@ -200,6 +219,34 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } + fun rename( + item: ItemUbicador, barCode: Long, warehouse: Int + + ) { + salix.itemShelvingUpdate( + params = ItemShelvingSalix( + visible = 0, + packing = item.packing, + grouping = item.grouping + ), + id = item.id, + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + + itemShelvingAdd( + shelving = response.body()!!.shelvingFk!!, + item = barCode, + quantity = item.visible, + packing = null, + warehouse = warehouse, + grouping = null, + createdRename = response.body()!!.created + ) + } + + }) + } + fun setParking( shelving: String, parking: String ) { @@ -271,6 +318,21 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { } }) } + fun itemShelvingUpdateCreated( + itemShelvingFk: Int, created:String + + ) { + salix.itemShelvingsUpdate( + where = JsonObject().apply { addProperty("id", itemShelvingFk) }, + params = hashMapOf("created" to created) + ).enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + _response.value = ResponseItemVO(isError = false, response = response.message()!!) + super.onSuccess(response) + } + }) + } fun shelvingLogAdd( code: String @@ -325,9 +387,9 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { salix.itemShelvingUpdate( id = itemShelvingFk, params = hashMapOf("isChecked" to 1) - ).enqueue(object : SalixCallback(context) { + ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { + override fun onSuccess(response: Response) { _response.value = ResponseItemVO(isError = false, response = response.message()) } }) @@ -373,8 +435,8 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } - fun itemShelvingDelete(itemFk: Int) { - salix.itemShelvingsDelete(itemFk).enqueue(object : SalixCallback(context) { + fun itemShelvingDelete(itemShelvingFk: Int) { + salix.itemShelvingsDelete(itemShelvingFk).enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { _response.value = ResponseItemVO( @@ -404,14 +466,14 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { fun getIdFromCode(code: String) { getItemFromBarcodeUseCase.execute(code) - .enqueue(object : SalixCallback(context) { + .enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { + override fun onSuccess(response: Response) { - _responseCode.value = response.body() + _responseCode.value = response.body() - } - }) + } + }) } } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9f1bb568..a6b53f40 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -848,5 +848,7 @@ Ubicar Escanea carros para ubicar el artículo Carros a ubicar + Carro ya introducido + errorGetData