From eb729acc59b345bd6c20555367955524ef0a2318 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:27:10 +0200 Subject: [PATCH] feat: boxPickingPrepared refs #7855 --- .../delivery/viewmodels/DeliveryViewModel.kt | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt index 60b0463c..ad6a5bcd 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt @@ -6,8 +6,10 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.map import es.verdnatura.R import es.verdnatura.domain.SalixCallback +import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.common.ExpeditionPrintOut import es.verdnatura.presentation.common.ResponseSign import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketList import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix @@ -36,6 +38,13 @@ import java.io.File class DeliveryViewModel(val context: Context) : BaseViewModel(context) { + private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) + private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } + val isBoxPickingInPrintOut: LiveData = _isBoxPickingInPrintOut + + private val _responseCode by lazy { MutableLiveData() } + val responseCode: LiveData = _responseCode + private val _expeditionInfoList by lazy { MutableLiveData() } val expeditionInfoList: LiveData = _expeditionInfoList @@ -64,6 +73,12 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { val responseStateAdd: LiveData get() = _responseStateAdd + private val _responseExpeditionStateId by lazy { MutableLiveData() } + val responseExpeditionStateId: LiveData = _responseExpeditionStateId + + private val _responseFindExpeditionId by lazy { MutableLiveData() } + val responseFindExpeditionId: LiveData = _responseFindExpeditionId + private val _responseUpdateRoute by lazy { MutableLiveData() } val responseUpdateRoute: LiveData get() = _responseUpdateRoute @@ -228,6 +243,41 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { }) } + fun findExpedition(expedition: Number, expeditionStateId: Number) { + println("Expedition $expedition") + salix.findExpedition( + filter = """{"where": + { + "expeditionFk":$expedition, + "typeFk":$expeditionStateId + } + }""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseFindExpeditionId.value = 0 + + } + + override fun onError(t: Throwable) { + _responseFindExpeditionId.value = expedition + } + + }) + } + + fun getExpeditionStateId(stateCode: String) { + + salix.getExpeditionStateTypeId( + filter = """{"where":{"code":"$stateCode"}}""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseExpeditionStateId.value = + response.body()?.toString()?.let { JSONObject(it).getInt("id") } + } + + }) + } + fun getInfoFreelance( userId: Int ) { @@ -393,6 +443,46 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { }) } + + fun isBoxPickingInPrintOut(expeditionFk: Long, barcode: String) { + getItemFromBarcodeUseCase.execute(barcode) + .enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + + if (response.body() != null) { + isBoxPickingOk( + itemFk = response.body().toString().toLong(), + expeditionFk = expeditionFk + ) + } else { + _responseCode.value = false + } + + } + }) + } + + fun isBoxPickingOk( + expeditionFk: Long, itemFk: Long + + ) { + + salix.isBoxPickingInPrintOut( + filter = """{"where":{"expeditionFk":$expeditionFk,"itemFk":$itemFk}}""" + ).enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + _isBoxPickingInPrintOut.value = response.body() + } + + override fun onError(t: Throwable) { + _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false) + } + + }) + } + } fun createJSONObject(listTickets: MutableList, note: String): String {