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 8e8b85c8..52fbd99d 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,7 +12,6 @@ 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 @@ -40,7 +39,6 @@ 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( @@ -760,7 +758,8 @@ 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() - }*/ + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + customDialogTwoButtons.dismiss() + }.show() + customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> + 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() } @@ -1098,19 +1098,13 @@ class UbicadorFragmentNew : BaseFragment() } - private val _response by lazy { MutableLiveData() } - val response: LiveData - get() = _response - private val _responseUbicator by lazy { MutableLiveData() } val responseUbicator: LiveData get() = _responseUbicator @@ -151,7 +145,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { packing: Int?, warehouse: Int, grouping: Int?, - createdRename: String? = null ) { salix.itemShelvingAdd( arrayListOf( @@ -166,18 +159,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { ).enqueue(object : SalixCallback(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 { - _responseUbicator.value = - true - } _responseUbicator.value = true super.onResponse(call, response) @@ -207,32 +188,16 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } - fun rename( - item: ItemUbicador, barCode: Long, warehouse: Int + fun getInfoFromBuy( + itemShelvingFk: Number, buyFk: Number ) { - salix.itemShelvingUpdate( - params = ItemShelvingSalix( - visible = 0, - packing = item.packing, - grouping = item.grouping, - available = item.available - ), - 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 - ) + salix.getInfoFromBuyId( + id = buyFk, + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + itemShelvingUpdateFromBuy(itemShelvingFk, response.body().let { it as ItemBuy }) } - }) } @@ -278,16 +243,18 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { } fun itemShelvingMerge( - vShelf: Int, vShelvingFk: String + vShelf: Int, shelvingFk: String ) { salix.itemShelvingsUpdate( where = JsonObject().apply { addProperty("id", vShelf) }, - params = hashMapOf("shelvingFk" to vShelvingFk) + params = hashMapOf("shelvingFk" to shelvingFk) ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _response.value = ResponseItemVO(isError = false, response = response.message()!!) super.onSuccess(response) + itemShelvingAlternative( + shelvingFk = shelvingFk, + ) } }) } @@ -308,20 +275,26 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } - fun itemShelvingUpdateCreated( - itemShelvingFk: Int, created: String + fun itemShelvingUpdateFromBuy( + itemShelvingFk: Number, itemBuy: ItemBuy ) { salix.itemShelvingsUpdate( where = JsonObject().apply { addProperty("id", itemShelvingFk) }, - params = hashMapOf("created" to created) - ).enqueue(object : SalixCallback(context) { + JsonObject().apply { + addProperty("itemFk", itemBuy.itemFk) + addProperty("buyFk", itemBuy.id) + addProperty("grouping", itemBuy.grouping) + addProperty("packing", itemBuy.packing) + addProperty("packagingFk", itemBuy.packagingFk) + }) + .enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _response.value = ResponseItemVO(isError = false, response = response.message()!!) - super.onSuccess(response) - } - }) + override fun onSuccess(response: Response) { + _responseUbicator.value = true + super.onSuccess(response) + } + }) } fun shelvingLogAdd( @@ -364,7 +337,7 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _response.value = ResponseItemVO(isError = false, response = response.message()) + _responseUbicator.value = true super.onSuccess(response) } }) @@ -397,7 +370,7 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _response.value = ResponseItemVO(isError = false, response = response.message()) + _responseUbicator.value = true super.onSuccess(response) } }) @@ -457,15 +430,10 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { salix.upsertItem(MakeMultiSalix(shelvingFk, items, warehouseFk)) .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - super.onError(t) - _response.value = - ResponseItemVO(isError = true, response = t.message.toString()) - } override fun onSuccess(response: Response) { super.onSuccess(response) - _response.value = ResponseItemVO(isError = false, response = response.message()) + _responseUbicator.value = true } }) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt index ffeec0e0..d041679a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt @@ -29,7 +29,7 @@ class ItemUbicador( var grouping: Int? = null, var available: Int? = null, var code: String? = "", - var created:String? = null, + var created: String? = null, var shelvingFk: String? = null, var id: Int = 0, var priority: Int = 0, @@ -39,7 +39,7 @@ class ItemUbicador( var isNew: Boolean = false, var isChecked: Int? = null, var url: String = "", - var units:Int = 0 + var units: Int = 0 ) class ItemEscanerVO( @@ -49,18 +49,26 @@ class ItemEscanerVO( class ItemUbicadorListVO( var list: List = listOf() ) + class ItemUbicadorListNew( var list: List = listOf() ) class ItemShelvingNewerList( var list: List = listOf(), - var originalParking:String, - var originalShelvingFk:String + var originalParking: String, + var originalShelvingFk: String ) data class ItemShelvingNewer( var itemFk: Int, - var shelvingFk : String, + var shelvingFk: String, +) +data class ItemBuy( + val id: Number, + val itemFk: Number, + val grouping: Int?, + val packing: Int, + val packagingFk: String? ) \ No newline at end of file