feat multipleUbicator refs #7805

This commit is contained in:
Sergio De la torre 2024-07-31 12:15:51 +02:00
parent ec6b61b414
commit 3203e35698
6 changed files with 262 additions and 40 deletions

View File

@ -1041,7 +1041,7 @@ interface SalixService {
fun itemShelvingUpdate(
@Path("id") id: Number,
@Body params: Any
): Call<Any>
): Call<ItemUbicador?>
@POST("ItemShelvings/update")
fun itemShelvingsUpdate(

View File

@ -40,7 +40,7 @@ data class ItemShelvingSaleSalix(
data class ItemShelvingSalix(
var visible: Int,
var packing: Int,
var packing: Int?,
var grouping: Int?
)

View File

@ -20,6 +20,7 @@ import es.verdnatura.presentation.view.feature.inventario.model.InventaryListVO
import es.verdnatura.presentation.view.feature.inventario.model.InventoryParkingList
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventoryParking
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistakeList
import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix
@ -105,8 +106,8 @@ class InventaryViewModel(val context: Context) : BaseViewModel(context) {
) {
salix.itemShelvingUpdate(itemShelvingFk, params)
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
.enqueue(object : SalixCallback<ItemUbicador?>(context) {
override fun onSuccess(response: Response<ItemUbicador?>) {
_responseReset.value = response.message()
super.onSuccess(response)
}

View File

@ -12,6 +12,7 @@ import android.view.View.VISIBLE
import android.view.inputmethod.EditorInfo
import android.widget.ImageView
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentUbicadorBinding
@ -22,6 +23,7 @@ import es.verdnatura.domain.toInt
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.Action
import es.verdnatura.presentation.common.OnBarcodeRowClickListener
import es.verdnatura.presentation.common.OnMoreClickListenerNew
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
@ -30,15 +32,18 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.common.itemScanValue
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogInput
import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.component.CustomDialogTwoButtons
import es.verdnatura.presentation.view.component.CustomDialogUbicadorNew
import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter
import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import kotlinx.coroutines.launch
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>(
class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>(
UbicadorViewModel::class
) {
private var shelvingFk: String = ""
@ -61,6 +66,10 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
var listIcons: ArrayList<ImageView> = ArrayList()
private lateinit var textWatcher: TextWatcher
private var buyScanned: String = ""
private lateinit var customDialogList: CustomDialogList
private var listShelvings: ArrayList<BarcodeVO> = ArrayList()
private var listShelvingsAdapter: BarcodeAdapter? = null
private var locateMultipleShelvings: Boolean = false
companion object {
private const val ARG_SHELVINGFK = "shelvingFk"
@ -73,6 +82,7 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
@ -116,6 +126,8 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
} else {
isShelvinLogfromMainScreen = true
setIconsActions(false)
//Tarea 7805
// setIcons(true)
}
super.init()
}
@ -146,7 +158,7 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
}
}
private fun setIcons() {
private fun setIcons(isOnlyIconAdd: Boolean = false) {
listIcons.clear()
val iconAdd = ImageView(context)
@ -189,7 +201,11 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
iconReset.tooltipText = getTooltip(R.drawable.ic_remove_checks)
listIcons.add(iconAdd)
listIcons.add(iconReload)
if (!isOnlyIconAdd) {
listIcons.add(iconReload)
}
//Tarea7805
// locateMultipleShelvings = isOnlyIconAdd
binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
@ -562,7 +578,7 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
event.getContentIfNotHandled().notNull {
if (it.list.isNotEmpty()) {
var formattedList = it.list.map { item ->
val formattedList = it.list.map { item ->
val itemFk = item.itemFk
val shelvingFk = item.shelvingFk
"$itemFk (${shelvingFk.uppercase()})"
@ -818,17 +834,25 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
) {
if (itemUbicador?.id == null) {
//item nuevo sin shelving
try {
if (locateMultipleShelvings)
insertShelvingsForUbicator(
customDialogUbicador.getItemValue().toLong(),
customDialogUbicador.getVisibleValue().toInt(),
customDialogUbicador.getPackingValue().toIntOrNull()
) else {
viewModel.itemShelvingAdd(
shelving = shelvingFk,
item = customDialogUbicador.getItemValue().toLong(),
quantity = customDialogUbicador.getVisibleValue().toInt(),
packing = customDialogUbicador.getPackingValue().toIntOrNull(),
warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK),
grouping = null
)
}
viewModel.itemShelvingAdd(
shelving = shelvingFk,
item = customDialogUbicador.getItemValue().toLong(),
quantity = customDialogUbicador.getVisibleValue()
.toIntOrNull()!!,
packing = customDialogUbicador.getPackingValue().toIntOrNull(),
warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK),
grouping = null
)
} catch (ex: Exception) {
ma.messageWithSound(
getString(R.string.reviewData),
@ -848,6 +872,95 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
}
private fun insertShelvingsForUbicator(barCode: Number, visible: Int, packing: Int?) {
customDialogList = CustomDialogList(requireContext())
customDialogList.setTitle(
getString(R.string.shelvingsLocate)
)
customDialogList.setDescription(
getString(R.string.scanShelvingsLocate)
).setOkButton(getString(R.string.locate)) {
listShelvings.forEach {
viewModel.itemShelvingAdd(
shelving = it.code!!,
item = barCode,
quantity = visible,
packing = packing,
warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK),
grouping = null
)
}
customDialogList.dismiss()
}.setKoButton(getString(R.string.cancel)) {
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.dismiss()
}.setValue("").show()
customDialogList.getEditText().requestFocus()
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (customDialogList.getValue().isNotEmpty()) {
try {
customDialogList.setValue(
itemScanValue(
customDialogList.getValue(),
arrayOf("saleGroup"),
field = "id"
).toString()
)
if (customDialogList.getValue().isShelving()) {
if (listShelvings.firstOrNull { it.code == customDialogList.getValue() } == null) {
listShelvings.add(BarcodeVO(code = customDialogList.getValue()))
/*viewModel.sectorCollectionSaleGroupAdd(
customDialogList.getValue().toInt(), collectionFk
)*/
} else {
throw Exception(getString(R.string.errorRepeatedShelving))
}
} else {
throw Exception()
}
} catch (ex: Exception) {
ma.messageWithSound(
getString(R.string.errorInput),
isError = true,
isPlayed = true,
isToasted = true
)
listShelvings.removeAt(0)
}
listShelvingsAdapter!!.notifyItemChanged(0)
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
return@setOnEditorActionListener true
}
false
}
listShelvingsAdapter = BarcodeAdapter(
listShelvings, object : OnBarcodeRowClickListener {
override fun onBarcodeRowClickListener(item: BarcodeVO) {
}
}, showDelete = false
)
customDialogList.getRecyclerView().adapter = listShelvingsAdapter
customDialogList.getRecyclerView().layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
private fun setWatcher() {
customDialogUbicador.addTextWatcher(customDialogUbicador.getPackingItem()) { s ->
@ -928,16 +1041,27 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
}
customDialogConfirm.show()
}//Tarea 7763
/* .setOkButtonThree("Renombrar") {
customDialogInput.setTitle("Nuevo artículo")
.setDescription("Introduzca nueva etiqueta").setValue("")
.setOkButton("Renombrar") {
//rename()
/*.setOkButtonThree(getString(R.string.rename)) {
customDialogInput.setTitle(getString(R.string.itemNew))
.setDescription(getString(R.string.scanItem)).setValue("")
.setOkButton(getString(R.string.rename)) {
}.setKoButton(getString(R.string.cancel)) {
customDialogTwoButtons.dismiss()
}.show()
}*/
actionRename(item, customDialogInput.getValue())
}.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
customDialogTwoButtons.dismiss()
}.show()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
actionRename(item, customDialogInput.getValue())
return@setOnEditorActionListener true
}
false
}
customDialogInput.getEditText().requestFocus()
}*/
customDialogTwoButtons.setKoButton(getString(R.string.cancel)) {
customDialogTwoButtons.dismiss()
@ -946,6 +1070,39 @@ class UbicadorFragmentNew: BaseFragment<FragmentUbicadorBinding, UbicadorViewMod
customDialogTwoButtons.show()
}
private fun actionRename(item: ItemUbicador, itemScan: String) {
if (itemScan.isNotEmpty()) {
renameItem(
item, itemScanValue(
itemScan, arrayOf("buy"), "id"
).toString().toLong()
)
customDialogInput.dismiss()
customDialogTwoButtons.dismiss()
} else {
getString(R.string.scanItem).toast(requireContext())
}
}
private fun renameItem(item: ItemUbicador, barCode: Long) {
viewLifecycleOwner.lifecycleScope.launch {
try {
viewModel.rename(
item = item,
barCode = barCode,
warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK)
)
} catch (ex: Exception) {
ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true)
}
}
}
private fun customDialogTransferAction(item: ItemUbicador) {
if (customDialogInput.getValue().isNotEmpty()) {
/*tearea 6964*/

View File

@ -5,6 +5,8 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.google.gson.JsonPrimitive
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
@ -162,7 +164,13 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}
fun itemShelvingAdd(
shelving: String, item: Number, quantity: Int, packing: Int?, warehouse: Int, grouping: Int?
shelving: String,
item: Number,
quantity: Int,
packing: Int?,
warehouse: Int,
grouping: Int?,
createdRename: String? = null
) {
salix.itemShelvingAdd(
arrayListOf(
@ -176,6 +184,17 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
).formatWithQuotes()
).enqueue(object : SalixCallback<Any>(context) {
override fun onResponse(call: Call<Any>, response: Response<Any>) {
if (!createdRename.isNullOrBlank() && response.body()!=null) {
val jsonArray = JsonParser().parse(response.body().toString()).asJsonArray
val jsonObject = jsonArray.get(0).asJsonObject
itemShelvingUpdateCreated(itemShelvingFk = (jsonObject.get("LAST_INSERT_ID()") as JsonPrimitive).asInt, created = createdRename)
} else {
_responseMake.value =
ResponseItemVO(isError = false, response = response.message()!!)
}
_responseMake.value =
ResponseItemVO(isError = false, response = response.message()!!)
super.onResponse(call, response)
@ -185,14 +204,14 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}
fun itemShelvingMakeEdit(
quantity: Int, packing: Int, itemShelvingFk: Int, grouping: Int?
quantity: Int, packing: Int?, itemShelvingFk: Int, grouping: Int?
) {
salix.itemShelvingUpdate(
params = ItemShelvingSalix(visible = quantity, packing = packing, grouping = grouping),
id = itemShelvingFk,
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
).enqueue(object : SalixCallback<ItemUbicador?>(context) {
override fun onSuccess(response: Response<ItemUbicador?>) {
_responseMake.value =
ResponseItemVO(isError = false, response = response.message()!!)
}
@ -200,6 +219,34 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun rename(
item: ItemUbicador, barCode: Long, warehouse: Int
) {
salix.itemShelvingUpdate(
params = ItemShelvingSalix(
visible = 0,
packing = item.packing,
grouping = item.grouping
),
id = item.id,
).enqueue(object : SalixCallback<ItemUbicador?>(context) {
override fun onSuccess(response: Response<ItemUbicador?>) {
itemShelvingAdd(
shelving = response.body()!!.shelvingFk!!,
item = barCode,
quantity = item.visible,
packing = null,
warehouse = warehouse,
grouping = null,
createdRename = response.body()!!.created
)
}
})
}
fun setParking(
shelving: String, parking: String
) {
@ -271,6 +318,21 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}
})
}
fun itemShelvingUpdateCreated(
itemShelvingFk: Int, created:String
) {
salix.itemShelvingsUpdate(
where = JsonObject().apply { addProperty("id", itemShelvingFk) },
params = hashMapOf("created" to created)
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message()!!)
super.onSuccess(response)
}
})
}
fun shelvingLogAdd(
code: String
@ -325,9 +387,9 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
salix.itemShelvingUpdate(
id = itemShelvingFk,
params = hashMapOf("isChecked" to 1)
).enqueue(object : SalixCallback<Any>(context) {
).enqueue(object : SalixCallback<ItemUbicador?>(context) {
override fun onSuccess(response: Response<Any>) {
override fun onSuccess(response: Response<ItemUbicador?>) {
_response.value = ResponseItemVO(isError = false, response = response.message())
}
})
@ -373,8 +435,8 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun itemShelvingDelete(itemFk: Int) {
salix.itemShelvingsDelete(itemFk).enqueue(object : SalixCallback<Any>(context) {
fun itemShelvingDelete(itemShelvingFk: Int) {
salix.itemShelvingsDelete(itemShelvingFk).enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
@ -404,14 +466,14 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
fun getIdFromCode(code: String) {
getItemFromBarcodeUseCase.execute(code)
.enqueue(object : SalixCallback<Int?>(context) {
.enqueue(object : SalixCallback<Int?>(context) {
override fun onSuccess(response: Response<Int?>) {
override fun onSuccess(response: Response<Int?>) {
_responseCode.value = response.body()
_responseCode.value = response.body()
}
})
}
})
}
}

View File

@ -848,5 +848,7 @@
<string name="locate">Ubicar</string>
<string name="scanShelvingsLocate">Escanea carros para ubicar el artículo</string>
<string name="shelvingsLocate">Carros a ubicar</string>
<string name="errorRepeatedShelving">Carro ya introducido</string>
<string name="errorGetData">errorGetData</string>
</resources>