From 718e418d3033df3412c5446c2abf429394a82c23 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Wed, 11 Oct 2023 09:25:24 +0200 Subject: [PATCH] refs #5652 --- .../java/es/verdnatura/domain/SalixService.kt | 31 +++++++++---- .../presentation/common/SalixBackItems.kt | 6 +++ .../component/CustomDialogDynamicButtons.kt | 2 +- .../articulo/fragment/ItemCardFragment.kt | 13 ++++-- .../articulo/fragment/ItemCardViewModel.kt | 46 +++++++++++++++++-- .../feature/articulo/model/ItemProposal.kt | 42 +++++++++-------- 6 files changed, 101 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index 48bf9d0f..a7326f06 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -1,9 +1,9 @@ package es.verdnatura.domain -import com.google.gson.JsonObject import es.verdnatura.presentation.common.itemBarCodeSalix import es.verdnatura.presentation.common.packingSiteSalix import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO +import es.verdnatura.presentation.view.feature.articulo.model.AddressLoses import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingType import es.verdnatura.presentation.view.feature.calidad.model.BuyerVO import es.verdnatura.presentation.view.feature.collection.SalixSaleQuantity @@ -65,9 +65,14 @@ interface SalixService { fun getCollectionSalix( ): Call> + @GET("Addresses/getAddress") + fun getAddressSalix( + ): Call> + @GET("Buyers") fun getBuyers( - ): Call> + ): Call> + @GET("collections/getCollection") fun getCollectionSalixLocal( ): Call> @@ -134,12 +139,12 @@ interface SalixService { @GET("Departments") fun department_getHasMistake( - @Query("filter") filter:String = """{"fields": {"id": true,"name": true},"where": {"hasToMistake": true}}""" + @Query("filter") filter: String = """{"fields": {"id": true,"name": true},"where": {"hasToMistake": true}}""" ): Call> @GET("Workers") fun worker_idF11Allowed( - @Query("filter") filter:String + @Query("filter") filter: String ): Call> @DELETE("ExpeditionPallets/{id}") @@ -174,6 +179,11 @@ interface SalixService { @Body params: Any ): Call + @POST("Items/setVisibleDiscard") + fun setVisibleDiscard( + @Body params: Any + ): Call + @POST("Shelvings/upsertWithWhere") fun updateShelvingPriority( @Query("where") where: String, @@ -199,12 +209,12 @@ interface SalixService { @GET("ItemPackingTypes") fun get_ItemPackingType( - @Query("filter") filter:String = """{"where": {"isActive": true}}""" + @Query("filter") filter: String = """{"where": {"isActive": true}}""" ): Call> @GET("ExpeditionTrucks") fun expeditionTruckGet( - @Query("filter") filter:String + @Query("filter") filter: String ): Call> @POST("PackingSiteAdvanceds") @@ -301,7 +311,7 @@ interface SalixService { @POST("ItemShelvings/update") fun itemShelvingsUpdate( - @Query("where") id : Any , + @Query("where") id: Any, @Body params: Any ): Call @@ -351,10 +361,13 @@ interface SalixService { ): Call> @POST("ExpeditionMistakes") - fun expeditionMistakesAdd(expeditionMistake:ExpeditionMistakeSalix + fun expeditionMistakesAdd( + expeditionMistake: ExpeditionMistakeSalix ): Call + @POST("WorkerMistakes") - fun workerMistakesAdd(workerMistake: WorkerMistakeSalix + fun workerMistakesAdd( + workerMistake: WorkerMistakeSalix ): Call @POST("SaleMistakes") 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 f8fc84b8..303b29c0 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt @@ -16,3 +16,9 @@ data class ItemShelvingSaleSalix( var quantity:Int, var isItemShelvingSaleEmpty:Boolean? ) + +data class ItemDiscardSalix( + var itemFk :Int, + var warehouseFk:Int, + var quantity:Int, + var addressFk:Int) \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogDynamicButtons.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogDynamicButtons.kt index 557228ba..148ea20e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogDynamicButtons.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogDynamicButtons.kt @@ -42,7 +42,7 @@ class CustomDialogDynamicButtons(context: Context, private val onClickDynamic: O fun createDynamicButtons(buttonInfoList: List) { for (buttonInfo in buttonInfoList) { - setDynamicButton(buttonInfo.nickname,buttonInfo.addressFk) + setDynamicButton(buttonInfo.nickname,buttonInfo.id) } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index 4d662093..cdbf0a01 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt @@ -47,6 +47,7 @@ class ItemCardFragment( private var listItemsRow: ArrayList = ArrayList() private var listBarcodes: ArrayList = ArrayList() private var itemsPackingType: ArrayList = ArrayList() + private var quantityToDiscard = 0 private var itemInfoG: ItemCardVO? = null @@ -58,6 +59,7 @@ class ItemCardFragment( private lateinit var customDialogInput: CustomDialogInput private lateinit var customDialogList: CustomDialogList private lateinit var customDialogTwo: CustomDialogTwoButtons + private lateinit var customDynamic: CustomDialogDynamicButtons override fun getLayoutId(): Int = R.layout.fragment_item_card @@ -73,6 +75,7 @@ class ItemCardFragment( customDialogInput = CustomDialogInput(requireContext()) customDialogList = CustomDialogList(requireContext()) customDialogTwo = CustomDialogTwoButtons(requireContext()) + customDynamic = CustomDialogDynamicButtons(requireContext(), this) if (!itemFk.isNullOrEmpty()) { @@ -607,9 +610,10 @@ class ItemCardFragment( //Tarea 5652 , quitar código cuando está asignada tarea var test = false if (test) { - println("Vamos a getAddress") binding.splashProgress.visibility = View.VISIBLE - viewModel.getAddressLoses() + viewModel.getAddress() + quantityToDiscard = value + } else { try { value.toInt() @@ -668,8 +672,6 @@ class ItemCardFragment( private fun showDialogTrashFault(listAddress: List) { - val customDynamic = - CustomDialogDynamicButtons(requireContext(), this)// Instancia de tu customDialogTwo customDynamic.setTitle("") customDynamic.setDescription(getString(R.string.deleteStock)) customDynamic.createDynamicButtons(listAddress) @@ -775,6 +777,9 @@ class ItemCardFragment( override fun onClickDynamic(addressFK: Int) { println("Acabas de pulsar" + addressFK) + customDynamic.dismiss() + binding.splashProgress.visibility = View.VISIBLE + viewModel.setVisibleDiscard(itemInfoG!!.id, warehouseFk!!, quantityToDiscard, addressFK) } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt index 64d4dab9..312b116a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt @@ -8,6 +8,7 @@ import es.verdnatura.domain.SilexCallback import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction +import es.verdnatura.presentation.common.ItemDiscardSalix import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.common.itemBarCodeSalix import es.verdnatura.presentation.view.feature.articulo.model.AddressLoses @@ -159,10 +160,11 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { fun setVisibleDiscard( itemFk: Int, warehouseFk: Int, - newValue: Int, - isTrash: Boolean - ) { - silex.itemTrash(itemFk, warehouseFk, newValue, isTrash) + quantity: Int, + addressFk: Int, + + ) { + salix.setVisibleDiscard(ItemDiscardSalix(itemFk, warehouseFk, quantity, addressFk)) .enqueue(object : SilexCallback(context) { override fun onError(t: Throwable) { _response.value = ResponseItemVO( @@ -291,7 +293,7 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { value: String, delete: Boolean ) {//Tarea 5134 cambiar Silex para obtener el id y así poder hacer un DELETE y un PATCH - // salix.barcodes_edit(idBarcode:Int, ) + // salix.barcodes_edit(idBarcode:Int, ) silex.barcodes_edit(value, itemFk, delete) .enqueue(object : SilexCallback(context) { override fun onError(t: Throwable) { @@ -371,10 +373,44 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { }) } + + fun getAddress() { + salix.getAddressSalix().enqueue(object : SilexCallback>(context) { + override fun onError(t: Throwable) { + + val listError: ArrayList = ArrayList() + listError.add(AddressLoses(isError = true, errorMessage = t.message!!)) + _addressLosesList.value = AddressLosesList(listError) + } + + override fun onSuccess(response: Response>) { + + if (response.body() != null) { + _addressLosesList.value = response.body()?.let { AddressLosesList(it) } + } else { + val listError: ArrayList = ArrayList() + listError.add( + AddressLoses( + isError = true, + errorMessage = getMessageFromAllResponse( + nameofFunction(this), + response.message() + ) + ) + ) + _addressLosesList.value = AddressLosesList(listError) + } + } + + }) + } + + fun getAddressLoses( ) { + val mermaRecords = listOf( AddressLoses(77, "MERMA: CONTENEDOR", "BASURA"), AddressLoses(317, "MERMA: FALTAS", "FALTAS"), diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemProposal.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemProposal.kt index 2878181c..c9bc85fb 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemProposal.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemProposal.kt @@ -2,24 +2,24 @@ package es.verdnatura.presentation.view.feature.articulo.model class ItemProposal( - var itemFk: String ="", - var longName: String="", - var subName: String="", + var itemFk: String = "", + var longName: String = "", + var subName: String = "", var tag5: String = "", - var value5: String="", - var match5: String="", - var tag6: String="", - var value6: String="", - var match6: String="", - var tag7: String="", - var value7: String="", - var match7: String="", - var tag8: String="", - var value8: String="", - var match8: String="", - var available: String="", - var counter: String="", - var minQuantity: String="", + var value5: String = "", + var match5: String = "", + var tag6: String = "", + var value6: String = "", + var match6: String = "", + var tag7: String = "", + var value7: String = "", + var match7: String = "", + var tag8: String = "", + var value8: String = "", + var match8: String = "", + var available: String = "", + var counter: String = "", + var minQuantity: String = "", var isError: Boolean = false, var errorMessage: String = "" @@ -35,8 +35,10 @@ class AddressLosesList( ) data class AddressLoses( - val addressFk: Int, - val nickname: String, - val name: String + val id: Int = 0, + val nickname: String = "", + val name: String = "", + var isError: Boolean = false, + var errorMessage: String = "" )