feat: refs#8213 reservas

This commit is contained in:
Sergio De la torre 2025-03-24 16:29:06 +01:00
parent d3679ae52c
commit b26cf1b76f
11 changed files with 503 additions and 246 deletions

View File

@ -18,7 +18,6 @@ import es.verdnatura.databinding.SaleRowFragmentReserveBinding
import es.verdnatura.domain.ConstAndValues.PREITEMPICKERTEST
import es.verdnatura.domain.ConstAndValues.PREPARED
import es.verdnatura.domain.ConstAndValues.SACADOR
import es.verdnatura.domain.toast
import es.verdnatura.presentation.common.OnAddItemClickListener
import es.verdnatura.presentation.common.OnMistakeClickListener
import es.verdnatura.presentation.common.OnPackingClickSaleListener
@ -63,13 +62,15 @@ class SaleAdapterReserve(
override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
this.position = position
holder.bind(items[position])
val item = items[position]
val calculatedValues = precalculateDisplayValues(item)
holder.bind(item, calculatedValues)
}
inner class AjustesItemHolder(
val binding: SaleRowFragmentReserveBinding
) : RecyclerView.ViewHolder(binding.root) {
fun bind(sale: Sale) {
fun bind(sale: Sale, calculatedValues: Pair<String, String>) {
binding.apply {
println("type $type ")
println("type isExpanded $isExpanded")
@ -222,49 +223,23 @@ class SaleAdapterReserve(
previous.text = "PREV:${sale.saleGroupFk}"
}
val result: Int
val textToConcat: String
binding.txtQuantityReserved.text = calculatedValues.first
if (sale.totalItemShelving > 1) {
binding.txtQuantityReserved.text = calculatedValues.first
binding.txtQuantity.text = calculatedValues.second
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
binding.txtReserveToComplete.visibility = VISIBLE
binding.txtQuantity.text =
"${sale.reservedQuantity}"
} else {
binding.txtQuantity.text =
if (sale.itemShelvingFk == 0 && sale.itemShelvingSaleFk == 0) {
"${sale.saleQuantity}"
} else "${sale.reservedQuantity}"
binding.txtReserveToComplete.visibility = GONE
try {
result = sale.reservedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
textToConcat = if (result != 0) {
"${sale.reservedQuantity / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${sale.reservedQuantity / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
binding.txtQuantityReserved.text = textToConcat
val textToConcat2: String
val result2: Int =
sale.accumulatedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
textToConcat2 = if (result2 != 0) {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
if (sale.totalItemShelving > 1) {
binding.txtQuantityReserved.text = textToConcat
binding.txtQuantity.text = textToConcat2
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
binding.txtReserveToComplete.visibility = VISIBLE
binding.txtQuantity.text =
"${sale.reservedQuantity}"
} else {
binding.txtQuantity.text = "${sale.reservedQuantity}"
binding.txtReserveToComplete.visibility = GONE
}
} catch (ex: Exception) {
ex.message!!.toast(context)
}
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
@ -362,4 +337,30 @@ class SaleAdapterReserve(
}
}
private fun precalculateDisplayValues(sale: Sale): Pair<String, String> {
try {
val result = sale.reservedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
val textToConcat = if (result != 0) {
"${sale.reservedQuantity / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${sale.reservedQuantity / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
val result2 = sale.accumulatedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
val textToConcat2 = if (result2 != 0) {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
return if (sale.itemShelvingSaleFk == 0 && sale.itemShelvingFk == 0) Pair(
"-",
"0"
) else {
Pair(textToConcat, textToConcat2)
}
} catch (ex: Exception) {
return Pair("Error", "Error")
}
}
}

View File

@ -18,7 +18,6 @@ import es.verdnatura.databinding.SaleRowFragmentReserveSacadorBinding
import es.verdnatura.domain.ConstAndValues.PREITEMPICKERTEST
import es.verdnatura.domain.ConstAndValues.PREPARED
import es.verdnatura.domain.ConstAndValues.SACADOR
import es.verdnatura.domain.toast
import es.verdnatura.presentation.common.OnAddItemClickListener
import es.verdnatura.presentation.common.OnMistakeClickListener
import es.verdnatura.presentation.common.OnPackingClickSaleListener
@ -61,15 +60,19 @@ class SaleAdapterReserveSacador(
override fun getItemCount() = items.size
override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {/* this.position = position
holder.bind(items[position])*/
this.position = position
holder.bind(items[position])
val item = items[position]
val calculatedValues = precalculateDisplayValues(item)
holder.bind(item, calculatedValues)
}
inner class AjustesItemHolder(
val binding: SaleRowFragmentReserveSacadorBinding
) : RecyclerView.ViewHolder(binding.root) {
fun bind(sale: Sale) {
fun bind(sale: Sale, calculatedValues: Pair<String, String>) {
binding.apply {
val childLayoutManagerV =
@ -219,50 +222,23 @@ class SaleAdapterReserveSacador(
previous.text = "PREV:${sale.saleGroupFk}"
}
binding.txtQuantityReserved.text = calculatedValues.first
if (sale.totalItemShelving > 1) {
binding.txtQuantityReserved.text = calculatedValues.first
binding.txtQuantity.text = calculatedValues.second
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
binding.txtReserveToComplete.visibility = VISIBLE
binding.txtQuantity.text = "${sale.reservedQuantity}"
} else {
binding.txtQuantity.text =
if (sale.itemShelvingFk == 0 && sale.itemShelvingSaleFk == 0) {
"${sale.saleQuantity}"
} else "${sale.reservedQuantity}"
binding.txtReserveToComplete.visibility = GONE
val result: Int
val textToConcat: String
try {
result = sale.reservedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
textToConcat = if (result != 0) {
"${sale.reservedQuantity / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${sale.reservedQuantity / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
binding.txtQuantityReserved.text = textToConcat
val textToConcat2: String
val result2: Int =
sale.accumulatedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
textToConcat2 = if (result2 != 0) {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
if (sale.totalItemShelving > 1) {
binding.txtQuantityReserved.text = textToConcat
binding.txtQuantity.text = textToConcat2
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
binding.txtReserveToComplete.visibility = VISIBLE
binding.txtQuantity.text =
"${sale.reservedQuantity}"
} else {
binding.txtQuantity.text = "${sale.reservedQuantity}"
binding.txtReserveToComplete.visibility = GONE
}
} catch (ex: Exception) {
ex.message!!.toast(context)
}
binding.txtReserveToComplete.text =
"${sale.currentItemShelving}/${sale.totalItemShelving}"
@ -290,8 +266,11 @@ class SaleAdapterReserveSacador(
} else {
if (sale.stateCode != null && sale.stateCode == "PREVIOUS_CONTROLLED") {
getColor(
context!!, R.color.verdnatura_dark_mint_light
)
context!!,
R.color.verdnatura_dark_mint_light_precontrolled
)/* getColor(
context!!, R.color.verdnatura_dark_sky_blue
)*/
} else {
getColor(
context!!, R.color.verdnatura_black
@ -339,7 +318,6 @@ class SaleAdapterReserveSacador(
}
this.sale = sale
}
@ -360,4 +338,30 @@ class SaleAdapterReserveSacador(
}
}
private fun precalculateDisplayValues(sale: Sale): Pair<String, String> {
try {
val result = sale.reservedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
val textToConcat = if (result != 0) {
"${sale.reservedQuantity / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${sale.reservedQuantity / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
val result2 = sale.accumulatedQuantity % (sale.packing ?: (sale.saleQuantity + 1))
val textToConcat2 = if (result2 != 0) {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}"
} else {
"${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}"
}
println("reserva sale $sale")
return if (sale.itemShelvingSaleFk == 0 && sale.itemShelvingFk == 0) Pair(
"-",
"0"
) else {
Pair(textToConcat, textToConcat2)
}
} catch (ex: Exception) {
return Pair("Error", "Error")
}
}
}

View File

@ -365,8 +365,7 @@ class CollectionFragmentPickerPreviousNewInterface(
}
}
loadResponseReserveAddPrevOK.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
}
event.getContentIfNotHandled().notNull {}
}
loadSetStateResponse.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
@ -402,119 +401,139 @@ class CollectionFragmentPickerPreviousNewInterface(
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
collection.map(requireContext())
val salesList: ArrayList<Sale> = ArrayList()
tickets = ArrayList()
var observations = ""
val myPickingFrom = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_FROM")
val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_TO")
collection.tickets.forEach { ticket ->
val sectorFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(SECTORFK)
if (collection.sectorFk != null && collection.sectorFk != sectorFk) {
if (observations.isNotEmpty()) observations = observations + " " + ticket.observations
ticket.sales.forEach { sale ->
ma.messageWithSound(
getString(R.string.cambia_el_sector_vas_a_preparar_una_previa_que_no_es_de_tu_sector),
isError = true,
isPlayed = true,
isToasted = false
)
} else {
if (hasPickingOrder) {
if (sale.pickingOrder != null && sale.pickingOrder in myPickingFrom..myPickingTo) {
salesList.add(sale)
}
} else {
salesList.add(sale)
}
val salesList: ArrayList<Sale> = ArrayList()
}
}
// sales = salesList.sortedWith(compareBy<Sale> { it.pickingOrderPrevia }.thenBy { it.itemFk })
//quitar comentarios FALTA AGRUPAR LAS PREVIAS
tickets = ArrayList()
var observations = ""
val myPickingFrom = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_FROM")
val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_TO")
collection.tickets.forEach { ticket ->
when (type) {
PREITEMPICKERTEST -> {
myGroupList =
salesList.sortedWith(compareBy<Sale> { it.pickingOrder }.thenBy { it.itemFk })
}
if (observations.isNotEmpty()) observations =
observations + " " + ticket.observations
ticket.sales.forEach { sale ->
SACADOR -> {
myGroupList =
groupSaleGroup(salesList).sortedWith(compareBy<Sale> { it.pickingOrder }.thenBy { it.itemFk })
}
}
saleAdapter = SaleAdapterReserve(myGroupList, pasillerosItemClickListener!!,
object : OnSaleClickSaleListener {
override fun onSaleClick(sale: Sale) {
println("sale ${sale.saleFk} ${sale.itemFk} ${sale.isPicked}")
val position =
myGroupList.indexOfFirst { it.itemShelvingSaleFk == sale.itemShelvingSaleFk }
if (position > -1 && !myGroupList[position].isParent) {
if (sale.isPicked == 1) {
unMarkLine(position, myGroupList[position])
} else {
showScanner(position, sale)
if (hasPickingOrder) {
if (sale.pickingOrder != null && sale.pickingOrder in myPickingFrom..myPickingTo) {
salesList.add(sale)
}
} else {
//TODO desmarcamos una linea de previa ?
salesList.add(sale)
}
}
}
// sales = salesList.sortedWith(compareBy<Sale> { it.pickingOrderPrevia }.thenBy { it.itemFk })
//quitar comentarios FALTA AGRUPAR LAS PREVIAS
}, object : OnMistakeClickListener {
override fun onMistakeClickListener(sale: SaleVO) {
when (type) {
PREITEMPICKERTEST -> {
myGroupList =
salesList.sortedWith(compareBy<Sale> { it.pickingOrder }.thenBy { it.itemFk })
}
}, object : OnPackingClickSaleListener {
override fun onPackingClick(sale: Sale) {
if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener(
PasillerosItemVO(
title = R.string.titleUbicator,
), entryPoint = sale.code
)
SACADOR -> {
myGroupList =
groupSaleGroup(salesList).sortedWith(compareBy<Sale> { it.pickingOrder }.thenBy { it.itemFk })
}
}, object : OnTicketClickSaleListener {
override fun onTicketClickListener(sale: Sale) {
val entryPoint = Gson().toJson(
mutableMapOf(
"entryPoint" to sale.ticketFk, "web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
BASEURLSALIX
)
}/#!/ticket/${sale.ticketFk}/sale"
}
saleAdapter = SaleAdapterReserve(myGroupList, pasillerosItemClickListener!!,
object : OnSaleClickSaleListener {
override fun onSaleClick(sale: Sale) {
println("sale ${sale.saleFk} ${sale.itemFk} ${sale.isPicked}")
val position =
myGroupList.indexOfFirst { it.itemShelvingSaleFk == sale.itemShelvingSaleFk }
if (position > -1 && !myGroupList[position].isParent) {
if (sale.isPicked == 1) {
unMarkLine(position, myGroupList[position])
} else {
if (sale.itemShelvingSaleFk == 0 && sale.itemShelvingFk == 0 && sale.code.isNullOrEmpty())
showManagement(sale)
else {
showScanner(position, sale)
}
}
} else {
//TODO desmarcamos una linea de previa ?
}
}
}, object : OnMistakeClickListener {
override fun onMistakeClickListener(sale: SaleVO) {
}
}, object : OnPackingClickSaleListener {
override fun onPackingClick(sale: Sale) {
if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener(
PasillerosItemVO(
title = R.string.titleUbicator,
), entryPoint = sale.code
)
)
ma.onPasillerosItemClickListener(
PasillerosItemVO(
title = R.string.titleWebViewer,
), entryPoint = entryPoint
)
}
}, onReserveSaleClick = object : OnSaleReserveClickListener {
override fun onSaleReserveListener(sale: Sale) {
showDeleteItemShelving(sale)
}
}
}, object : OnTicketClickSaleListener {
override fun onTicketClickListener(sale: Sale) {
val entryPoint = Gson().toJson(
mutableMapOf(
"entryPoint" to sale.ticketFk, "web" to "${
mobileApplication.dataStoreApp.readDataStoreKey<String>(
BASEURLSALIX
)
}/#!/ticket/${sale.ticketFk}/sale"
)
)
ma.onPasillerosItemClickListener(
PasillerosItemVO(
title = R.string.titleWebViewer,
), entryPoint = entryPoint
)
}
}, onReserveSaleClick = object : OnSaleReserveClickListener {
override fun onSaleReserveListener(sale: Sale) {
showDeleteItemShelving(sale)
}
}, onAddItemClickListener = object : OnAddItemClickListener {
}, onAddItemClickListener = object : OnAddItemClickListener {
override fun onAddItemClickListener(sale: Sale) {
customDialogAddItemFromSale(sale)
}
override fun onAddItemClickListener(sale: Sale) {
customDialogAddItemFromSale(sale)
}
}, type = type
)
}, type = type
)
lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.fragmentSacadorCollections.adapter = saleAdapter
binding.fragmentSacadorCollections.layoutManager = lm
lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.fragmentSacadorCollections.adapter = saleAdapter
binding.fragmentSacadorCollections.layoutManager = lm
setTotalLines()
setListPosition()
setScrollListener(lm!!)
printObservations(observations)
if (!isVerifiedCollection && type == PREPARED) {
binding.fragmentSacadorCollections.visibility = View.INVISIBLE
verifyCollection()
setTotalLines()
setListPosition()
setScrollListener(lm!!)
printObservations(observations)
if (!isVerifiedCollection && type == PREPARED) {
binding.fragmentSacadorCollections.visibility = View.INVISIBLE
verifyCollection()
}
}
}
@ -740,10 +759,7 @@ class CollectionFragmentPickerPreviousNewInterface(
AbsoluteSizeSpan(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16f, resources.displayMetrics)
.toInt(), true
),
0,
item.toString().length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
), 0, item.toString().length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
try {
@ -760,10 +776,9 @@ class CollectionFragmentPickerPreviousNewInterface(
customDialogList.dismiss()
scanRequest()
}.setHintValue(getString(R.string.quantitySelect))
.setTextSize(20f)
.setValue(totalReserved.toString())
.setHintValueTwo(getString(R.string.scanItem)).setValueTwo("").show()
}.setHintValue(getString(R.string.quantitySelect)).setTextSize(20f)
.setValue(totalReserved.toString()).setHintValueTwo(getString(R.string.scanItem))
.setValueTwo("").show()
customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
@ -1103,10 +1118,9 @@ class CollectionFragmentPickerPreviousNewInterface(
}
}
try {
if (distinctSaleGroups.isNotEmpty())
distinctSaleGroups.forEach { saleGroup ->
setStateSaleGroup(saleGroup, stateCodeId!!)
}
if (distinctSaleGroups.isNotEmpty()) distinctSaleGroups.forEach { saleGroup ->
setStateSaleGroup(saleGroup, stateCodeId!!)
}
} catch (ex: Exception) {
}
@ -1327,4 +1341,40 @@ class CollectionFragmentPickerPreviousNewInterface(
}
}
private fun showManagement(sale: Sale) {
customDialogThreeButtons = CustomDialogThreeButtons(requireContext())
customDialogThreeButtons.setCustomDialogValue(View.GONE)
customDialogThreeButtons.setTitle("Gestionar línea artículo ${sale.itemFk}")
.setDescription("Selecciona RESERVAR para añadir reserva y que muestre ubicación")
.setOkButton("Reservar") {
viewModel.itemShelvingSaleAddByCollection(collection.collectionFk)
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}/*.setOkButtonTwo("Poner a cero la cantidad") {
viewModel.collectionIncreaseQuantitySalix(sale.saleFk, "0")
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}*/
.setKoButton(getString(R.string.cancel)) {
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}.setValue("").show()
/* customDialogThreeButtons.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) {
findSaleAction(index, sale)
return@setOnEditorActionListener false
}
false
}*/
customDialogThreeButtons.getEditText().requestFocus()
}
private fun closeCustomDialogManagement(
scanInput: EditText,
customDialogInput: CustomDialogThreeButtons
) {
requireContext().hideKeyboard(customDialogInput.getEditText())
scanInput.requestFocus()
customDialogInput.dismiss()
scanInput.requestFocus()
}
}

View File

@ -1,6 +1,7 @@
package es.verdnatura.presentation.view.feature.collection.fragment
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.media.MediaPlayer
import android.os.Bundle
@ -21,6 +22,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.ImageView
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.gson.Gson
@ -32,6 +34,7 @@ import es.verdnatura.domain.ConstAndValues.PREPARED
import es.verdnatura.domain.ConstAndValues.PRINTERNAME
import es.verdnatura.domain.ConstAndValues.SACADOR
import es.verdnatura.domain.ConstAndValues.SECTORFK
import es.verdnatura.domain.isShelving
import es.verdnatura.domain.notNull
import es.verdnatura.domain.showToastCenterWithBackground
import es.verdnatura.domain.toast
@ -61,6 +64,8 @@ import es.verdnatura.presentation.view.feature.collection.ItemVO
import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapterReserveSacador
import es.verdnatura.presentation.view.feature.collection.mapper.map
import es.verdnatura.presentation.view.feature.main.activity.MainActivity
import es.verdnatura.presentation.view.feature.pasillero.model.CleanAction
import es.verdnatura.presentation.view.feature.pasillero.model.CodeWorkerAction
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.Sale
@ -115,6 +120,7 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
private var isVerifiedCollection = false
private var stateCodeId: Number? = null
private var stateCodePreparedId: Number? = null
private lateinit var iconClean: ImageView
companion object {
fun newInstance(
@ -178,22 +184,38 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp)
val iconPrint = ImageView(context)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
val iconReserve = ImageView(context)
iconReserve.setImageResource(R.drawable.ic_booking)
iconClean = ImageView(context)
iconClean.setImageResource(R.drawable.ic_clean_shelving)
iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp)
iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp)
iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp)
iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp)
iconReserve.tooltipText = getTooltip(R.drawable.ic_booking)
iconClean.tooltipText = getTooltip(R.drawable.ic_clean_shelving)
listIcons.add(iconAdd)
listIcons.add(iconUpdate)
if (type == PREPARED) listIcons.add(iconPrint) else listIcons.add(iconParking)
// listIcons.add(iconReserve)
listIcons.add(iconClean)
binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) {
when (item) {
iconClean.drawable -> clean()
iconReserve.drawable -> {
println("collection to reserve${collection.collectionFk} ")
viewModel.itemShelvingSaleAddByCollection(collection.collectionFk)
}
iconPrint.drawable -> print()
iconAdd.drawable -> addItem()
iconUpdate.drawable -> updateScreen()
@ -210,6 +232,68 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun clean() {
val shelving = mobileApplication.dataStoreApp.readDataStoreKey<String>(
"SHELVINGACTION"
)
if (
shelving.isNotBlank()
) {
addWorkerActivity(
CodeWorkerAction.SHELVING_CLEAN_STOP,
shelving = shelving
)
} else {
customDialogInput.setTitle(getString(R.string.titleCleanShelving))
.setDescription(getString(R.string.descripOrganize))
.setOkButton(getString(R.string.organize)) {
ma.hideKeyboard(customDialogInput.getEditText())
actionOrganizeClean(customDialogInput.getValue())
}.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
}.setValue("").show()
customDialogInput.getEditText().requestFocus()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
actionOrganizeClean(customDialogInput.getValue())
return@setOnEditorActionListener true
}
false
}
}
}
private fun addWorkerActivity(codeWorkerAction: CodeWorkerAction, shelving: String) {
viewModel.addWorkerActivity(
CleanAction(
codeWorkerAction = codeWorkerAction,
shelving = shelving.uppercase(),
description = shelving.uppercase()
)
)
}
private fun actionOrganizeClean(input: String) {
if (input.isShelving()) {
addWorkerActivity(
CodeWorkerAction.SHELVING_CLEAN_START,
shelving = input
)
} else {
ma.messageWithSound(
message = getString(R.string.errorInput),
isError = true,
isPlayed = true,
isToasted = true
)
}
customDialogInput.dismiss()
}
private fun updateScreen() {
viewModel.collectionTicketGetSalix(
collection.collectionFk, print = false
@ -277,15 +361,42 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
}
}
private fun updateIconColor() {
val newColor =
ContextCompat.getColor(
requireContext(),
if (mobileApplication.dataStoreApp.readDataStoreKey<String>("SHELVINGACTION")
.isNotBlank()
) R.color.verdnatura_orange_salix else R.color.verdnatura_white
)
iconClean.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
binding.mainToolbar.toolbarIcons.adapter?.notifyDataSetChanged()
}
override fun observeViewModel() {
with(viewModel) {
loadResponseActivity.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
println("shelvinAction ${it}")
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
"SHELVINGACTION",
if (it.codeWorkerAction == CodeWorkerAction.SHELVING_CLEAN_START) it.shelving else ""
)
}
updateIconColor()
}
}
loadCollectionTicketSalix.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
if (!it.isError) {
if (it.tickets.isNotEmpty()) {
if (it.tickets.size > 0) {
collection = it
createCollectionList()
@ -314,6 +425,12 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
}
}
loadItemShelvingSaleAddByCollection.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
updateScreen()
}
}
loadFindItemShelvingResponse.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
@ -336,6 +453,13 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
}
loadIncQuantity.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
updateScreen()
}
}
loadPicked.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
if (it) {
@ -407,18 +531,27 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
private fun createCollectionList() {
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
collection.map(requireContext())
val allSalesAreNullOrEmpty = collection.tickets.all { it.sales.isNullOrEmpty() }
if (allSalesAreNullOrEmpty) {
ma.messageWithSound(
message = "No se han podido reservas líneas a la colección del/os ticket/s: ${collection.tickets?.map { it.ticketFk }} \n Revisa tu sector si estás en previas",
isError = true,
isPlayed = false,
isToasted = false
)
}
val salesList: ArrayList<Sale> = ArrayList()
tickets = ArrayList()
var observations = ""
val myPickingFrom = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_FROM")
val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey<Int>("PICKING_TO")
collection.tickets.forEach { ticket ->
collection.tickets?.forEach { ticket ->
if (observations.isNotEmpty()) observations = observations + " " + ticket.observations
ticket.sales.forEach { sale ->
ticket.sales?.forEach { sale ->
if (hasPickingOrder) {
if (sale.pickingOrder != null && sale.pickingOrder in myPickingFrom..myPickingTo) {
@ -458,7 +591,11 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
if (sale.isPicked == 1) {
unMarkLine(position, myGroupList[position])
} else {
showScanner(position, sale)
if (sale.itemShelvingSaleFk == 0 && sale.itemShelvingFk == 0 && sale.code.isNullOrEmpty())
showManagement(sale)
else {
showScanner(position, sale)
}
}
} else {
//TODO desmarcamos una linea de previa ? ya se desmarca el salegroup
@ -552,6 +689,7 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
storedPosition = lm.findFirstVisibleItemPosition()
super.onScrolled(recyclerView, dx, dy)
}
})
}
@ -673,12 +811,12 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
quantityConfirm = quantity
runBlocking {
val sectorFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(SECTORFK)
// val sectorFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(SECTORFK)
viewModel.itemShelvingSaleSetQuantity(
myGroupList[position].itemShelvingSaleFk,
quantity,
isItemShelvingSaleEmpty = isItemShelvingSaleEmpty,
sectorFk = if (sectorFk == -1) null else sectorFk,
sectorFk = null,
shelvingFk = myGroupList[position].code!!
)
}
@ -1149,6 +1287,45 @@ class CollectionFragmentPickerPreviousNewInterfaceSacador(
customDialogInput.getEditText().requestFocus()
}
//Falta ver si ponemos a cero la linea como la representamos , qué nos indica que
// está cogida ?? No tiene itemShelvinSale
// PONEMOS ISPICKED A 1
private fun showManagement(sale: Sale) {
customDialogThreeButtons = CustomDialogThreeButtons(requireContext())
customDialogThreeButtons.setCustomDialogValue(View.GONE)
customDialogThreeButtons.setTitle("Gestionar línea artículo ${sale.itemFk}")
.setDescription("Selecciona RESERVAR para añadir reserva y que muestre ubicación")
.setOkButton("Reservar") {
viewModel.itemShelvingSaleAddByCollection(collection.collectionFk)
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}/*setOkButtonTwo("Poner a cero la cantidad") {
viewModel.collectionIncreaseQuantitySalix(sale.saleFk, "0")
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}.*/
.setKoButton(getString(R.string.cancel)) {
closeCustomDialogManagement(binding.scanInput, customDialogThreeButtons)
}.setValue("").show()
/* customDialogThreeButtons.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) {
findSaleAction(index, sale)
return@setOnEditorActionListener false
}
false
}*/
customDialogThreeButtons.getEditText().requestFocus()
}
private fun closeCustomDialogManagement(
scanInput: EditText,
customDialogInput: CustomDialogThreeButtons
) {
requireContext().hideKeyboard(customDialogInput.getEditText())
scanInput.requestFocus()
customDialogInput.dismiss()
scanInput.requestFocus()
}
private fun findSaleAction(index: Int, sale: Sale) {
if (customDialogInput.getValue().isNotEmpty()) {
findSale(customDialogInput.getValue(), index, sale)

View File

@ -242,6 +242,11 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) {
val loadResponseActivity: LiveData<Event<CleanAction>> =
_responseActivity.map { Event(it) }
private val _itemShelvingSaleAddByCollection by lazy { MutableLiveData<Boolean>() }
val itemShelvingSaleAddByCollection: LiveData<Boolean> = _itemShelvingSaleAddByCollection
val loadItemShelvingSaleAddByCollection: LiveData<Event<Boolean>> =
_itemShelvingSaleAddByCollection.map { Event(it) }
fun getSales(
collectionFk: Number, print: String, source: String
@ -1150,4 +1155,15 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) {
}
})
}
fun itemShelvingSaleAddByCollection(collection: Number) {
salix.itemShelvingSaleAddByCollection(params = collection)
.enqueue(
object :
SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_itemShelvingSaleAddByCollection.value = true
}
})
}
}

View File

@ -20,7 +20,6 @@ fun CollectionVO.map(context: Context): CollectionVO {
it.ticketFk = ticket.ticketFk
it.level = ticket.level
it.rgb = ticket.rgb
it.salePersonFk = ticket.salesPersonFk
it.agencyName = ticket.agencyName
it.isNew = it.isAdded == "1"
it.code = it.cel3
@ -65,22 +64,24 @@ fun CollectionVO.map(context: Context): CollectionVO {
fun CollectionTicket.map(context: Context): CollectionTicket {
try {
this.tickets.forEach { ticket ->
ticket.sales.forEach {
it.level = ticket.level ?: ""
it.rgb = ticket.rgb ?: ""
val allSalesAreNullOrEmpty = tickets.all { it.sales.isNullOrEmpty() }
if (!allSalesAreNullOrEmpty) {
this.tickets?.forEach { ticket ->
ticket.sales?.forEach {
it.level = ticket.level ?: ""
it.rgb = ticket.rgb ?: ""
}
}
}
}
} catch (e: Exception) {
this.isError = true
if (this.tickets.isNullOrEmpty()) {
if (this.tickets.isEmpty()) {
this.errorMessage = context.getString(R.string.collectionNoTicketsError)
} else {
this.errorMessage =
context.getString(R.string.collectionErrorBuilding) + context.getString(R.string.reviewSector)
}
}
return this
}

View File

@ -52,7 +52,6 @@ class ControlVehiculoUsuarioFragment(
if (userFk == vUserFK) {
val androidId: String = mobileApplication.dataStoreApp.readDataStoreKey(ANDROID_ID)
// viewModel.machineGetWorkerPlate(mobileApplication.userId!!)
viewModel.deviceProductionGetnameDevice(
androidId
)
@ -64,7 +63,6 @@ class ControlVehiculoUsuarioFragment(
binding.userInformation.visibility = INVISIBLE
binding.nameVehiclecontrol.visibility = INVISIBLE
binding.userImage.setOnClickListener { binding.mainToolbar.backButton.performClick() }
// viewModel.machineGetWorkerPlate(mobileApplication.userId!!)
binding.nameVehiclecontrol.visibility = VISIBLE
viewModel.getNameWorker(userFk)
}

View File

@ -160,40 +160,40 @@ class SacadorViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun itemShelvingSale_addByCollection(collection: Int) {
salix.itemShelvingSaleAddByCollection(collection).enqueue(
object :
SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_response.value =
ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!
)
)
}
/* fun itemShelvingSale_addByCollection(collection: Int) {
salix.itemShelvingSaleAddByCollection(collection).enqueue(
object :
SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_response.value =
ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!
)
)
}
override fun onSuccess(response: Response<Any>) {
if (response.body() != null) {
override fun onSuccess(response: Response<Any>) {
if (response.body() != null) {
_response.value =
ResponseItemVO(isError = false, response = collection.toString())
} else {
_response.value =
ResponseItemVO(isError = false, response = collection.toString())
} else {
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
}
}
})
}
}
}
})
}*/
fun collectionGet() {
salix.getCollectionSalix().enqueue(object :

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/color">
<path
android:fillColor="@android:color/white"
android:pathData="M200,840L200,200Q200,167 223.5,143.5Q247,120 280,120L520,120Q520,143 520,160Q520,177 520,200L280,200Q280,200 280,200Q280,200 280,200L280,718L480,632L680,718L680,440Q703,440 720,440Q737,440 760,440L760,840L480,720L200,840ZM280,200L280,200Q280,200 280,200Q280,200 280,200L520,200Q520,200 520,200Q520,200 520,200Q520,200 520,200Q520,200 520,200L520,200L480,200L280,200ZM680,360L680,280L600,280L600,200L680,200L680,120L760,120L760,200L840,200L840,280L760,280L760,360L680,360Z"/>
</vector>

View File

@ -207,7 +207,7 @@
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@{sale.color}"
android:text='@{sale.productor != null ? (!sale.productor.isEmpty() ? sale.color + " - " + sale.productor : sale.color) : sale.color}'
android:textColor="#FFFFFF"
android:textSize="16sp"
tool:text="Mixto Natural" />

View File

@ -206,7 +206,7 @@
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@{sale.color}"
android:text='@{sale.productor != null ? (!sale.productor.isEmpty() ? sale.color + " - " + sale.productor : sale.color) : sale.color}'
android:textColor="#FFFFFF"
android:textSize="16sp"
tool:text="Mixto Natural" />