feat: refs#8676 advanceTicketInChecker

This commit is contained in:
Sergio De la torre 2025-03-21 07:28:16 +01:00
parent 6af6f92192
commit 36f8a43f34
1 changed files with 67 additions and 18 deletions

View File

@ -20,6 +20,7 @@ import es.verdnatura.databinding.FragmentCollectionBinding
import es.verdnatura.domain.ConstAndValues
import es.verdnatura.domain.ConstAndValues.CONTROLADOR
import es.verdnatura.domain.ConstAndValues.PRINTERNAME
import es.verdnatura.domain.ConstAndValues.SECTORFK
import es.verdnatura.domain.notNull
import es.verdnatura.domain.showToastCenterWithBackground
import es.verdnatura.domain.toast
@ -54,7 +55,6 @@ import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO
import es.verdnatura.presentation.view.feature.sacador.model.SaleVO
import org.json.JSONObject
// FALTA TESTEAR REVISORES DESPUÉS DE CAMPAÑA Y VER HOLDPOSITION
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class CollectionFragmentChecker(
var collection: CollectionVO = CollectionVO(0), var type: String = CONTROLADOR
@ -124,6 +124,7 @@ class CollectionFragmentChecker(
if (collection.tickets.isNotEmpty()) {
createCollectionList()
}
super.init()
}
@ -138,7 +139,7 @@ class CollectionFragmentChecker(
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
binding.mainToolbar.toolbarIcons.visibility = VISIBLE
binding.mainToolbar.backButton.visibility = VISIBLE
binding.previaButton.visibility = INVISIBLE
binding.mainToolbar.toolbarTitle.text =
if (collection.collectionFk == 0) getString(R.string.review) else collection.collectionFk.toString()
@ -167,10 +168,11 @@ class CollectionFragmentChecker(
listIcons.add(iconWorker)
listIcons.add(iconAdd)
binding.previaButton.setOnClickListener {
showPrevia()
showDialog(isAdvanceTicket = false)
}
binding.ticketAdvanceButton.setOnClickListener {
showDialog(isAdvanceTicket = true)
}
binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) {
@ -210,11 +212,20 @@ class CollectionFragmentChecker(
}
}
private fun showPrevia() {
private fun showDialog(isAdvanceTicket: Boolean) {
customDialogList.getEditText().setRawInputType(TYPE_CLASS_NUMBER)
customDialogList.setTitle(getString(R.string.scanPreviousTicket))
customDialogList.setTitle(
if (isAdvanceTicket) getString(R.string.ticketAdvance) else getString(
R.string.scanPreviousTicket
)
)
.setOkButton(getString(R.string.end)) {
takeActionPrevia(customDialogList)
if (customDialogList.getValue().isNotEmpty()) {
takeAction(customDialogList, isAdvanceTicket)
} else {
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.dismiss()
}
}.setValue("").show()
@ -226,7 +237,8 @@ class CollectionFragmentChecker(
if (customDialogList.getValue().isNotEmpty()) {
isScanned =
event != null && event.action == ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER
takeActionPrevia(customDialogList)
takeAction(customDialogList, isAdvanceTicket)
ma.hideKeyboard(customDialogList.getEditText())
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
@ -237,14 +249,18 @@ class CollectionFragmentChecker(
hideKeyboard()
}
private fun takeActionPrevia(customDialogList: CustomDialogList) {
private fun takeAction(customDialogList: CustomDialogList, isAdvanceTicket: Boolean) {
ma.hideKeyboard(customDialogList.getEditText())
try {
val saleGroupScanned = itemScanValue(
customDialogList.getValue(), arrayOf("saleGroup"), "id"
val itemScanned = itemScanValue(
customDialogList.getValue(), if (isAdvanceTicket) {
arrayOf("ticket")
} else arrayOf("saleGroup"), "id"
).toString()
markPrevia(saleGroupScanned)
if (isAdvanceTicket) {
viewModel.ticketAdvance(itemScanned.toInt(), mobileApplication.userId!!)
} else markPrevia(itemScanned)
customDialogList.dismiss()
} catch (ex: Exception) {
ma.messageWithSound(
@ -360,6 +376,7 @@ class CollectionFragmentChecker(
if (it.tickets.isNotEmpty()) {
collection = it
binding.previaButton.visibility = VISIBLE
binding.ticketAdvanceButton.visibility = VISIBLE
binding.fragmentSacadorCollections.visibility = VISIBLE
createCollectionList()
} else {
@ -368,6 +385,7 @@ class CollectionFragmentChecker(
getString(R.string.summaryCount, 0, 0)
binding.fragmentSacadorCollections.visibility = INVISIBLE
binding.previaButton.visibility = INVISIBLE
binding.ticketAdvanceButton.visibility = INVISIBLE
}
} else {
customDialog.setTitle(getString(R.string.error))
@ -555,17 +573,48 @@ class CollectionFragmentChecker(
observations.takeIf { it.isNotBlank() }?.plus(" ${ticket.observations}") ?: ""
}
if (!buttonPushedGetCollection) {
sales = salesList.sortedWith(compareBy { it.picked })
myGroupList = groupSaleGroup(salesList).sortedWith(compareBy { it.picked })
val isOnReservationMode = mobileApplication.dataStoreApp.readDataStoreKey<Boolean>(
ConstAndValues.RESERVATIONMODE
) || (mobileApplication.dataStoreApp.readDataStoreKey<Boolean?>(
ConstAndValues.SECTORISONRESERVATIONMODE
) == true)
sales = if (isOnReservationMode) {
salesList.filter {
it.sectorFk == mobileApplication.dataStoreApp.readDataStoreKey<Int>(SECTORFK)
}.sortedWith(compareBy({ it.saleOrder }))
} else {
sales = salesList.sortedWith(
salesList.filter {
it.sectorFk == mobileApplication.dataStoreApp.readDataStoreKey<Int>(SECTORFK)
}.sortedWith(compareBy({ it.picked }))
}
if (!buttonPushedGetCollection) {
println("Reorden lineas sin boton pulsado")
sales =
if (!isOnReservationMode) salesList.sortedWith(compareBy { it.picked }) else salesList.sortedWith(
compareBy { it.pickedOrder })
myGroupList =
if (!isOnReservationMode) groupSaleGroup(salesList).sortedWith(compareBy { it.picked }) else groupSaleGroup(
salesList
).sortedWith(compareBy { it.pickedOrder })
for (m in myGroupList) {
println("Linea ${m.itemFk}-${m.pickedOrder} ")
}
} else {
sales = if (!isOnReservationMode) salesList.sortedWith(
compareBy({ it.isControlled }, { it.picked })
) else salesList.sortedWith(
compareBy({ it.isControlled }, { it.pickedOrder })
)
//para la nueva revisión : hay que poner el saleOrder si no no podrán revisar correctamente
myGroupList = groupSaleGroup(salesList).sortedWith(
println("Reorden lineas con boton pulsado")
myGroupList = if (!isOnReservationMode) groupSaleGroup(salesList).sortedWith(
compareBy({ it.isControlled }, { it.picked })
) else groupSaleGroup(salesList).sortedWith(
compareBy({ it.isControlled }, { it.pickedOrder })
)
}