feat: refs#6413 refactorUbicador

This commit is contained in:
Sergio De la torre 2025-01-27 07:37:43 +01:00
parent a0ae1e37f1
commit 0fe4c3c7d3
2 changed files with 81 additions and 55 deletions

View File

@ -151,8 +151,8 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
private fun setDialogs() {
customDialogInput = CustomDialogInput(requireContext())
customDialog = CustomDialog(requireContext())
customDialogOlder = CustomDialog(requireContext())
customDialogTwoButtons = CustomDialogTwoButtons(requireContext())
// customDialogOlder = CustomDialog(requireContext())
// customDialogTwoButtons = CustomDialogTwoButtons(requireContext())
}
private fun setToolBar() {
@ -255,8 +255,9 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
customDialogReset.setTitle(getString(R.string.checkItemShelvingDescrip))
.setDescription(getString(R.string.checkItemShelving))
.setOkButton(getString(R.string.ok)) {
if (listItems.isNotEmpty())
viewModel.itemShelvingDeleteChecked(listItems[0].shelvingFk)
if (listItems.isNotEmpty()) viewModel.itemShelvingDeleteChecked(
listItems[0].shelvingFk
)
customDialogReset.dismiss()
}.setKoButton(getString(R.string.cancel)) {
customDialogReset.dismiss()
@ -593,6 +594,16 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
)
}
}
responseItemShelvingSaleReserve.observe(viewLifecycleOwner) {
ma.messageWithSound(
getString(R.string.messageItemReserve),
isError = true,
isPlayed = true,
titleWithError = "",
true
)
}
responseLogAdd.observe(viewLifecycleOwner) {
isShelvinLogfromMainScreen = false
@ -638,7 +649,7 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
event.getContentIfNotHandled().notNull {
if (it.list.isNotEmpty()) {
customDialogOlder = CustomDialog(requireContext())
val oldList = it.list.filter { item ->
item.itemCreated!!.contains("old", ignoreCase = true)
}.map { item ->
@ -675,14 +686,12 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
var finalOutput = ""
if (oldList.isNotEmpty()) {
finalOutput =
getString(R.string.ubicationItemNewer, resultStringOld)
finalOutput = getString(R.string.ubicationItemNewer, resultStringOld)
}
if (newList.isNotEmpty()) {
finalOutput += getString(R.string.ubicationItemOlder, resultStringNew)
}
customDialogOlder.setTitle(getString(R.string.info))
.setDescription(
customDialogOlder.setTitle(getString(R.string.info)).setDescription(
finalOutput
).setOkButton(
getString(R.string.ok)
@ -693,18 +702,14 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
)
Action.TRANSFERIR -> {
println("transfer item ${it.itemShelvingFk}")
println("transfer carro ${it.originalShelvingFk}")
viewModel.itemShelvingTransfer(
it.itemShelvingFk!!,
it.originalShelvingFk
it.itemShelvingFk!!, it.originalShelvingFk
)
}
null -> d("", "no action")
}
customDialogOlder.dismiss()
}.setKoButton(getString(R.string.cancel)) {
@ -712,12 +717,13 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
}.setCancelable(true)
customDialogOlder.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
Handler(Looper.getMainLooper()).postDelayed({
customDialogOlder.show()
if (finalOutput != "") customDialogOlder.show()
}, 1000)
}
}
}
loadResponseHasOlder.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
@ -1098,12 +1104,12 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
customDialogUbicador.setVisibleValue("")
customDialogUbicador.setVisibleValue(
(((customDialogUbicador.getEtiquetaValue().toIntOrNull()
?: 0) * (customDialogUbicador.getPackingValue().toIntOrNull()
?: 0))).toString()
?: 0) * (customDialogUbicador.getPackingValue().toIntOrNull() ?: 0))).toString()
)
}
private fun showMoreOptions(item: ItemShelving) {
customDialogTwoButtons = CustomDialogTwoButtons(requireContext())
customDialogTwoButtons.setTitle(item.item.id.toString())
.setDescription(getString(R.string.selectAction))
.setOkButton(getString(R.string.transfer)) {
@ -1159,8 +1165,7 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
.setOkButtonThree(getString(R.string.print)) {
val printerDialogManager = PrinterDialogManager(requireContext())
printerDialogManager.showPrintDialog(
item.item.id,
item.description ?: ""
item.item.id, item.description ?: ""
) { id, labelType, packing, copies ->
if (item.buyFk == null) {
@ -1169,8 +1174,7 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(
WAREHOUSEFK
),
dated = LocalDate.now()
.format(
dated = LocalDate.now().format(
DateTimeFormatter.ofPattern("yyyy-dd-MM")
),
reportName = "LabelBuy",
@ -1276,14 +1280,7 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
private fun customDialogTransferAction(item: ItemShelving) {
if (customDialogInput.getValue().isNotEmpty()) {
/*tearea 6964*/
// }
/* viewModel.hasItemOlder(
shelvingFk = shelvingFk,
parking = customDialogInput.getValue(),
itemFk = item.id,
action = Action.TRANSFERIR
)*/
viewModel.getParkingToTransfer(
shelvingFkTo = customDialogInput.getValue(),
itemShelvingFk = item.id,
@ -1291,8 +1288,7 @@ class UbicadorFragment : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel
shelvingFkFrom = shelvingFk
)
println("transfer item ${item.id}")
println("transfer carro ${customDialogInput.getValue()}")
/* viewModel.itemShelvingTransfer(
println("transfer carro ${customDialogInput.getValue()}")/* viewModel.itemShelvingTransfer(
item.id, customDialogInput.getValue()
)*/
listItems.remove(item)

View File

@ -18,6 +18,7 @@ import es.verdnatura.presentation.common.ItemShelvingSalix
import es.verdnatura.presentation.common.ResponseHasOlder
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.ReubicationList
import es.verdnatura.presentation.view.feature.sacador.model.ItemShelvingSale
import es.verdnatura.presentation.view.feature.ubicador.model.ItemBuy
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList
@ -28,6 +29,9 @@ import es.verdnatura.presentation.view.feature.workermistake.model.MakeMultiSali
import org.json.JSONObject
import retrofit2.Call
import retrofit2.Response
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
@ -37,6 +41,10 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
val responseUbicator: LiveData<Boolean>
get() = _responseUbicator
private val _responseItemShelvingSaleReserve by lazy { MutableLiveData<Boolean>() }
val responseItemShelvingSaleReserve: LiveData<Boolean>
get() = _responseItemShelvingSaleReserve
private val _responseHasOlder by lazy { MutableLiveData<ResponseHasOlder>() }
val responseHasOlder: LiveData<ResponseHasOlder>
get() = _responseHasOlder
@ -360,8 +368,10 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
override fun onSuccess(response: Response<ShelvingItem>) {
val itemShelving = response.body()
if (itemShelving?.parking == null) {
println("No hay parking sin problema")
itemShelvingTransfer(itemShelvingFk, shelvingFkTo)
} else {
println("Tiene parking ${itemShelving}")
getItemsByReviewOrder(
shelving = shelvingFkTo,
itemFk = itemFk,
@ -572,13 +582,33 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}
fun itemShelvingDelete(itemShelvingFk: Int) {
salix.itemShelvingsDelete(itemShelvingFk).enqueue(object : SalixCallback<Any>(context) {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, 0)
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val today = dateFormat.format(calendar.time)
salix.itemShelvingSaleTotalBySale(
filter = """
{"where":{"itemShelvingFk":$itemShelvingFk,"created":{"gte":"$today"}},"limit":10}
""".trimIndent()
).enqueue(object : SalixCallback<List<ItemShelvingSale>>(context) {
override fun onSuccess(response: Response<List<ItemShelvingSale>>) {
if (response.body()!!.isEmpty())
salix.itemShelvingsDelete(itemShelvingFk)
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseUbicator.value = true
}
}) else {
_responseItemShelvingSaleReserve.value = false
}
}
})
}
fun itemShelvingSelfConsumption(shelvingFk: String, itemFk: Number, quantity: Int) {