feat: refs#6845 userInterface

This commit is contained in:
Sergio De la torre 2024-11-20 08:03:45 +01:00
parent f2eb4d4c11
commit 622bb221ab
3 changed files with 1561 additions and 0 deletions

View File

@ -130,6 +130,11 @@ class CustomDialogList(context: Context) : Dialog(context, R.style.DialogTheme)
return this
}
fun showDialog(): CustomDialogList {
binding.customDialogValue.visibility = View.VISIBLE
return this
}
fun hideDescription(): CustomDialogList {
binding.customDialogDescription.visibility = View.GONE
return this

View File

@ -0,0 +1,358 @@
package es.verdnatura.presentation.view.feature.collection.fragment
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.google.gson.JsonObject
import es.verdnatura.MobileApplication
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.toast
import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.PickupResponse
import es.verdnatura.presentation.common.SaleTrackingReplaceSalix
import es.verdnatura.presentation.common.TicketState
import es.verdnatura.presentation.view.feature.collection.SalixSaleQuantity
import es.verdnatura.presentation.view.feature.collection.mapper.map
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeListVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO
import es.verdnatura.presentation.view.feature.workermistake.model.SaleMistakeSalix
import retrofit2.Response
class CollectionCheckerViewModel(val context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
//var isPaused: Boolean = false
private val _isPaused = MutableLiveData<Boolean>()
val isPaused: LiveData<Boolean> get() = _isPaused
private val _collectionTicketList by lazy { MutableLiveData<CollectionVO>() }
val collectionTicketList: LiveData<CollectionVO> = _collectionTicketList
val loadTicketList: LiveData<Event<CollectionVO>> = _collectionTicketList.map { Event(it) }
private val _responseSaleReplace by lazy { MutableLiveData<Boolean>() }
val responseSaleReplace: LiveData<Boolean> = _responseSaleReplace
val loadSaleReplace: LiveData<Event<Boolean>> = _responseSaleReplace.map { Event(it) }
private val _responseCollectionAddItem by lazy { MutableLiveData<Boolean>() }
val responseCollectionAddItem: LiveData<Boolean> = _responseCollectionAddItem
val loadResponseAddItem: LiveData<Event<Boolean>> = _responseCollectionAddItem.map { Event(it) }
private val _responsePrint by lazy { MutableLiveData<Boolean>() }
val responsePrint: LiveData<Boolean> = _responsePrint
val loadPrint: LiveData<Event<Boolean>> = _responsePrint.map { Event(it) }
private val _responseTicketState by lazy { MutableLiveData<TicketState>() }
val responseTicketState: LiveData<TicketState> = _responseTicketState
val loadTicketState: LiveData<Event<TicketState>> = _responseTicketState.map { Event(it) }
private val _responseTicketIsPickup by lazy { MutableLiveData<Boolean>() }
val responseTicketIsPickup: LiveData<Boolean> = _responseTicketIsPickup
val loadTicketIsPickup: LiveData<Event<Boolean>> = _responseTicketIsPickup.map { Event(it) }
private val _responseTicketClosure by lazy { MutableLiveData<String>() }
val responseTicketClosure: LiveData<String> = _responseTicketClosure
val loadTicketClousure: LiveData<Event<String>> = _responseTicketClosure.map { Event(it) }
private val _responseCollectionUnchecked by lazy { MutableLiveData<String>() }
val responseCollectionUnchecked: LiveData<String> = _responseCollectionUnchecked
val loadCollectionUnchecked: LiveData<Event<String>> =
_responseCollectionUnchecked.map { Event(it) }
private val _responseNew by lazy { MutableLiveData<Boolean>() }
val responseNew: LiveData<Boolean> = _responseNew
val loadAddNew: LiveData<Event<Boolean>> = _responseNew.map { Event(it) }
private val _responseIncQuantity by lazy { MutableLiveData<Boolean>() }
val responseIncQuantity: LiveData<Boolean> = _responseIncQuantity
val loadIncQuantity: LiveData<Event<Boolean>> = _responseIncQuantity.map { Event(it) }
private val _responseParking by lazy { MutableLiveData<Boolean>() }
val responseParking: LiveData<Boolean> = _responseParking
val loadParking: LiveData<Event<Boolean>> = _responseParking.map { Event(it) }
private val _mistakeList by lazy { MutableLiveData<MistakeTypeListVO>() }
val mistakeList: LiveData<MistakeTypeListVO> = _mistakeList
val loadMistakes: LiveData<Event<MistakeTypeListVO>> = _mistakeList.map { Event(it) }
fun getSales(
collectionFk: Number, print: String, source: String
) {
salix.getSalesFromTicketOrCollection(
collectionOrTicketFk = collectionFk, print = print != "0", source = source
).enqueue(object : SalixCallback<CollectionVO>(context) {
override fun onError(t: Throwable) {
_collectionTicketList.value = CollectionVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<CollectionVO>) {
try {
_collectionTicketList.value = response.body()?.let { it.map(context) }
} catch (ex: Exception) {
ex.toast(context)
}
}
})
}
fun collectionGetId(
ticketFk: Int, print: String, type: String
) {
salix.getCollectionId(
filter = """{"where":{"ticketFk":$ticketFk},"fields":"collectionFk"}"""
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
override fun onError(t: Throwable) {
_collectionTicketList.value = CollectionVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<List<JsonObject>>) {
if (response.body()!!.isNotEmpty()) {
getSales(
response.body()!![0].entrySet().first().value.toString().toInt(),
print,
type
)
} else {
_collectionTicketList.value = CollectionVO(
0, isError = false
)
}
}
})
}
fun saleTrackingUpdate(
saleFk: Int,
originalQuantity: Int,
code: String,
isChecked: String,
buyFk: Long,
isScanned: Boolean?
) {
salix.saleTrackingUpdate(
SaleTrackingReplaceSalix(
saleFk, originalQuantity, code, isChecked != "0", buyFk, isScanned!!
)
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseSaleReplace.value = true
}
override fun onError(t: Throwable) {
_responseSaleReplace.value = false
super.onError(t)
}
})
}
fun collectionStickerPrint(
collectionFk: Int, labelCount: Int?
) {
salix.collectionStickerPrint(
arrayListOf(
collectionFk, labelCount
)
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responsePrint.value = true
}
})
}
fun collectionAddItem(
itemFk: Int, quantity: Int, ticketFk: Int
) {
salix.addSale(
id = ticketFk, barcode = itemFk.toString(), quantity = quantity
).enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_responseNew.value = false
}
override fun onSuccess(response: Response<Any>) {
_responseNew.value = true
}
})
}
fun setParking(
ticketFk: Int, parking: String
) {
salix.setParking(arrayListOf(ticketFk, parking).formatWithQuotes())
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseParking.value = true
super.onSuccess(response)
}
})
}
fun ticketStateTodaySetState(
ticketFk: Int, state: String
) {
salix.ticketStateTodaySetState(arrayListOf(ticketFk, state).formatWithQuotes())
.enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) {
_responseTicketState.value = TicketState()
super.onSuccess(response)
}
})
}
fun collectionIncreaseQuantitySalix(
saleFk: Int, quantity: String
) {
salix.collectionIncreaseQuantitySalix(
SalixSaleQuantity(saleId = saleFk, quantity = quantity.toInt())
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
super.onSuccess(response)
_responseIncQuantity.value = true
}
})
}
fun saleMistakeAdd(
saleFk: Int, typeFk: Int
) {
salix.saleMistakeAdd(
SaleMistakeSalix(
userFk = (context as MobileApplication).userId!!, saleFk = saleFk, typeFk = typeFk
)
).enqueue(object : SalixCallback<Any>(context) {
})
}
fun mistakeType() {
salix.getMistakeTypes().enqueue(object : SalixCallback<List<MistakeTypeVO>>(context) {
override fun onSuccess(response: Response<List<MistakeTypeVO>>) {
if (response.body() != null) {
_mistakeList.value = response.body()?.let { MistakeTypeListVO(it) }
} else {
val listError: ArrayList<MistakeTypeVO> = ArrayList()
listError.add(MistakeTypeVO(0, ""))
_mistakeList.value = MistakeTypeListVO(listError)
}
}
})
}
fun ticketIsOutClosureZone(
ticketFk: Int
) {
salix.ticketIsOutClosureZone(
arrayListOf(ticketFk)
).enqueue(object : SalixCallback<Any?>(context) {
override fun onSuccess(response: Response<Any?>) {
_responseTicketClosure.value = response.body()?.toString() ?: "false"
}
})
}
fun ticketState(
ticketFk: Int
) {
salix.ticketState(
"""{"where": {"ticketFk": "$ticketFk"},"include":[{"relation":"user","scope":{"fields":["username"]}}]}"""
).enqueue(object : SalixCallback<List<TicketState>>(context) {
override fun onSuccess(response: Response<List<TicketState>>) {
_responseTicketState.value = if (response.body()!!.isEmpty()) {
TicketState()
} else {
response.body()!![0]
}
}
})
}
fun ticketIsPickup(
ticketFk: Number
) {
salix.ticketIsPickup(
"""{
"where": {
"id": $ticketFk
},
"fields": ["id", "routeFk"],
"include": [
{
"relation": "route",
"scope": {
"fields": ["id", "agencyModeFk"],
"include": {
"relation": "agencyMode",
"scope": {
"fields": ["id", "deliveryMethodFk","code"],
"where": {"code": "REC_ALG"},
"include": {
"relation": "deliveryMethod",
"scope": {
"fields": ["id", "code"]
}
}
}
}
}
}
]
}""".trim()
).enqueue(object : SalixCallback<List<PickupResponse>>(context) {
override fun onSuccess(response: Response<List<PickupResponse>>) {
_responseTicketIsPickup.value =
response.body()
?.firstOrNull()?.route?.agencyMode?.deliveryMethod?.code == "PICKUP"
}
})
}
fun hasUncheckedTicket(
collectionFk: Int
) {
salix.hasUncheckedTicket(collectionFk).enqueue(object : SalixCallback<String>(context) {
override fun onSuccess(response: Response<String>) {
_responseCollectionUnchecked.value = response.body()!!.toString()
}
})
}
fun setPausedState(paused: Boolean) {
_isPaused.value = paused
}
}