feat: boxPickingPrepared refs #7855

This commit is contained in:
Sergio De la torre 2024-09-24 10:27:10 +02:00
parent 50beca0cf3
commit eb729acc59
1 changed files with 90 additions and 0 deletions

View File

@ -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<ExpeditionPrintOut>() }
val isBoxPickingInPrintOut: LiveData<ExpeditionPrintOut> = _isBoxPickingInPrintOut
private val _responseCode by lazy { MutableLiveData<Boolean>() }
val responseCode: LiveData<Boolean> = _responseCode
private val _expeditionInfoList by lazy { MutableLiveData<ExpeditionInfoList>() }
val expeditionInfoList: LiveData<ExpeditionInfoList> = _expeditionInfoList
@ -64,6 +73,12 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
val responseStateAdd: LiveData<Boolean>
get() = _responseStateAdd
private val _responseExpeditionStateId by lazy { MutableLiveData<Number>() }
val responseExpeditionStateId: LiveData<Number> = _responseExpeditionStateId
private val _responseFindExpeditionId by lazy { MutableLiveData<Number>() }
val responseFindExpeditionId: LiveData<Number> = _responseFindExpeditionId
private val _responseUpdateRoute by lazy { MutableLiveData<Boolean>() }
val responseUpdateRoute: LiveData<Boolean>
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<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_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<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_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<Int?>(context) {
override fun onSuccess(response: Response<Int?>) {
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<ExpeditionPrintOut>(context) {
override fun onSuccess(response: Response<ExpeditionPrintOut>) {
_isBoxPickingInPrintOut.value = response.body()
}
override fun onError(t: Throwable) {
_isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false)
}
})
}
}
fun createJSONObject(listTickets: MutableList<Ticket>, note: String): String {