feat: boxPickingPrepared refs #7855

This commit is contained in:
Sergio De la torre 2024-09-24 10:24:42 +02:00
parent e77aae4826
commit fceab8c182
2 changed files with 108 additions and 58 deletions

View File

@ -5,15 +5,18 @@ import android.view.inputmethod.EditorInfo
import es.verdnatura.R
import es.verdnatura.databinding.FragmentGeneralBlackBinding
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.ExpeditionPrintOut
import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.view.component.CustomDialogInput
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix
import es.verdnatura.presentation.view.feature.delivery.model.Expeditions
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
class BoxPickingFragment(var title: String) :
BaseFragment<FragmentGeneralBlackBinding, BoxPickingViewModel>(BoxPickingViewModel::class) {
BaseFragment<FragmentGeneralBlackBinding, DeliveryViewModel>(DeliveryViewModel::class) {
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
private var isBoxScanned: Boolean = false
private lateinit var customDialogInput: CustomDialogInput
private var codeStateId: Number = 0
override fun getLayoutId(): Int = R.layout.fragment_general_black
companion object {
@ -25,6 +28,7 @@ class BoxPickingFragment(var title: String) :
binding.mainToolbar.toolbarTitle.text = title
setEvents()
customDialogInput = CustomDialogInput(requireContext())
viewModel.getExpeditionStateId("CHECKED")
super.init()
}
@ -40,11 +44,20 @@ class BoxPickingFragment(var title: String) :
if (!binding.scanInput.text.isNullOrEmpty()) {
try {
showScanBarcode(binding.scanInput.text.toString().toLong())
}catch (ex:Exception){
ma.messageWithSound(message =getString(R.string.itemNotValid), isError = true, isPlayed = true, isToasted = false)
}
viewModel.findExpedition(
expedition = binding.scanInput.text.toString().toLong(),
expeditionStateId = codeStateId
)
} catch (ex: Exception) {
ma.messageWithSound(
message = getString(R.string.itemNotValid),
isError = true,
isPlayed = true,
isToasted = false
)
}
}
binding.scanInput.setText("")
@ -61,10 +74,19 @@ class BoxPickingFragment(var title: String) :
customDialogInput.setTitle(getString(R.string.scanItem))
.setOkButton(getString(R.string.accept)) {
if (customDialogInput.getValue().isNotEmpty()) {
viewModel.isBoxPickingInPrintOut(
expeditionFk = expeditionFk,
customDialogInput.getValue()
viewModel.expeditionStateAddSalix(
expeditions = Expeditions(
arrayListOf(
ExpeditionSalix(
expeditionFk = expeditionFk,
stateCode = "CHECKED",
isScanned = 1
)
)
)
)
}
customDialogInput.dismiss()
}
@ -76,15 +98,12 @@ class BoxPickingFragment(var title: String) :
}.setValue("").show()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) {
if (customDialogInput.getValue().isNotEmpty()) {
viewModel.isBoxPickingInPrintOut(
expeditionFk = expeditionFk,
customDialogInput.getValue()
viewModel.findExpedition(
expedition = expeditionFk, expeditionStateId = expeditionFk
)
}
customDialogInput.dismiss()
@ -101,50 +120,55 @@ class BoxPickingFragment(var title: String) :
override fun observeViewModel() {
with(viewModel) {
/*isBoxPickingInPrintOut.observe(viewLifecycleOwner) {
responseExpeditionStateId.observe(viewLifecycleOwner) {
codeStateId = it
}
responseFindExpeditionId.observe(viewLifecycleOwner) {
if (it != 0) {
showScanBarcode(it.toLong())
} else {
ma.messageWithSound(
getString(
R.string.errorBoxPicking
), isError = true, isPlayed = true, isToasted = true
)
}
responseStateAdd.observe(viewLifecycleOwner) {
if (it) {
customDialogInput.dismiss()
binding.scanInput.requestFocus()
}
}
//Tarea 7751
isBoxPickingInPrintOut.observe(viewLifecycleOwner) {
if (it.isChecked) {
ma.messageWithSound(
message = getString(R.string.errorBoxPicking),
isError = true,
isPlayed = true,
isToasted = false
)
} else {
}
binding.scanInput.requestFocus()
}
responseCode.observe(viewLifecycleOwner) {
ma.messageWithSound(
message = getString(R.string.errorInput),
isError = !it,
isError = true,
isPlayed = true,
isToasted = null
)
binding.scanInput.requestFocus()
}*/
//Tarea 7751
isBoxPickingInPrintOut.observe(viewLifecycleOwner) {
if (it.isChecked){
ma.messageWithSound(
message = getString(R.string.errorBoxPicking),
isError = true,
isPlayed = true,
isToasted = false
)
}else{
viewModel.updateExpeditionPrint(it.expeditionFk, expeditionPrintOut = ExpeditionPrintOut(it.expeditionFk,it.itemFk, true))
}
binding.scanInput.requestFocus()
}
responseCode.observe(viewLifecycleOwner) {
ma.messageWithSound(
message = getString(R.string.errorInput),
isError = true,
isPlayed = true,
isToasted = null
)
binding.scanInput.requestFocus()
binding.scanInput.requestFocus()
}
}
}
}
}

View File

@ -12,8 +12,11 @@ import retrofit2.Response
class BoxPickingViewModel(val context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
/*private val _isBoxPickingInPrintOut by lazy { MutableLiveData<Boolean>() }
val isBoxPickingInPrintOut: LiveData<Boolean> = _isBoxPickingInPrintOut*/
private val _responseFindExpeditionId by lazy { MutableLiveData<Number>() }
val responseFindExpeditionId: LiveData<Number> = _responseFindExpeditionId
//Tarea 7751
private val _isBoxPickingInPrintOut by lazy { MutableLiveData<ExpeditionPrintOut>() }
@ -28,16 +31,16 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) {
salix.isBoxPickingInPrintOut(
filter = """{"where":{"expeditionFk":$expeditionFk,"itemFk":$itemFk}}"""
/* ).enqueue(object : SalixCallback<Any>(context) {
/* ).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_isBoxPickingInPrintOut.value = true
}
override fun onError(t: Throwable) {
_isBoxPickingInPrintOut.value = false
}
override fun onSuccess(response: Response<Any>) {
_isBoxPickingInPrintOut.value = true
}
override fun onError(t: Throwable) {
_isBoxPickingInPrintOut.value = false
}
})*/
})*/
//Tarea 7751
//isChecked
).enqueue(object : SalixCallback<ExpeditionPrintOut>(context) {
@ -45,8 +48,9 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) {
override fun onSuccess(response: Response<ExpeditionPrintOut>) {
_isBoxPickingInPrintOut.value = response.body()
}
override fun onError(t: Throwable) {
_isBoxPickingInPrintOut.value = ExpeditionPrintOut(0,0,false)
_isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false)
}
})
@ -70,8 +74,30 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) {
}
})
}
fun findExpedition(expedition: Number, expeditionStateId: Number) {
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 updateExpeditionPrint(expeditionFk: Long, expeditionPrintOut: ExpeditionPrintOut) {
salix.update(expeditionFk, expeditionPrintOut)
salix.update(expeditionFk, expeditionPrintOut)
.enqueue(object : SalixCallback<ExpeditionPrintOut>(context) {
})