feat qr previa refs $6477

This commit is contained in:
Sergio De la torre 2024-06-19 08:49:08 +02:00
parent 0e97150278
commit 4640cffc30
2 changed files with 739 additions and 731 deletions

View File

@ -42,7 +42,7 @@ fun EditText.toInt(): Int {
}
fun String.isParking(): Boolean {
val regex = Regex("[\\S-\\S]{5,}")
val regex = Regex("[\\S-\\S]{5}")
return regex.matches(this)
}
fun String.isShelving(): Boolean {

View File

@ -18,7 +18,9 @@ import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.FragmentPreSacadorBinding
import es.verdnatura.domain.ConstAndValues.SECTORFK
import es.verdnatura.domain.isParking
import es.verdnatura.domain.notNull
import es.verdnatura.domain.toInt
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnBarcodeRowClickListener
@ -133,9 +135,8 @@ class EndSacadorFragment(
if (!binding.scanInput.text.toString().isNullOrEmpty()) {
if (itemScanIsQr(binding.scanInput.text.toString())) {
try {
ticket = itemScanValue(
binding.scanInput.text.toString(),
arrayOf("saleGroup"),
@ -143,20 +144,26 @@ class EndSacadorFragment(
) as Int
addSaleGroupToCollection(ticket)
} catch (ex: Exception) {
ex.toast(requireContext())
}
} else {
if (binding.scanInput.text.contains("-")) {
if ((binding.scanInput.text.toString()).isParking()) {
pasillerosItemClickListener?.onPasillerosItemClickListener(
PasillerosItemVO(
title = getString(R.string.Parking)
), ""
)
} else {
if (binding.scanInput.text.first().isDigit()) {
addSaleGroupToCollection(binding.scanInput.toInt())
} else {
findSale(binding.scanInput.text.toString())
}
}
}
}
binding.scanInput.setText("")
@ -164,12 +171,12 @@ class EndSacadorFragment(
return@setOnEditorActionListener true
}
true
}
}
hideKeyboards()
hideKeyboards()
//LISTA =========
binding.collectionSwipe.setOnRefreshListener {
binding.collectionSwipe.setOnRefreshListener {
if (::sales.isInitialized) {
sales.clear()
@ -177,11 +184,11 @@ binding.collectionSwipe.setOnRefreshListener {
}
searchSaleCollection()
binding.collectionSwipe.isRefreshing = false
}
}
}
}
@RequiresApi(Build.VERSION_CODES.O)
override fun observeViewModel() {
@RequiresApi(Build.VERSION_CODES.O)
override fun observeViewModel() {
with(viewModel) {
salesList.observe(viewLifecycleOwner, Observer {
createSaleList(it)
@ -376,9 +383,9 @@ override fun observeViewModel() {
})
}
}
}
private fun responseSaleMoveSuccesful() {
private fun responseSaleMoveSuccesful() {
try {
sales[positionCollectionSplit].saldo = quantityCollectionSplit.toInt()
@ -391,9 +398,9 @@ private fun responseSaleMoveSuccesful() {
markLine(positionCollectionSplit)
saleAdapter!!.notifyDataSetChanged()
}
}
private fun incresaseSuccesful() {
private fun incresaseSuccesful() {
try {
sales[positionIncreaseQuantity].saldo = quantityIncrease.toInt()
@ -405,19 +412,19 @@ private fun incresaseSuccesful() {
searchSaleCollection()
}
}
//CREATE LIST
private fun searchSaleCollection() {
private fun searchSaleCollection() {
viewModel.sectorCollectionGetSale(
collection.collectionFk,
sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK)
)
}
}
private fun searchTicket(ticketFk: Int) {
private fun searchTicket(ticketFk: Int) {
ticket = ticketFk
@ -426,9 +433,9 @@ private fun searchTicket(ticketFk: Int) {
ticketFk,
collection.collectionFk
)
}
}
private fun addSaleGroupToCollection(ticketFk: Int) {
private fun addSaleGroupToCollection(ticketFk: Int) {
ticket = ticketFk
@ -437,9 +444,9 @@ private fun addSaleGroupToCollection(ticketFk: Int) {
ticketFk,
collection.collectionFk
)
}
}
private fun createSaleList(salesList: List<PreSacadorItemVO>) {
private fun createSaleList(salesList: List<PreSacadorItemVO>) {
if (salesList.isNullOrEmpty()) {
@ -515,9 +522,9 @@ private fun createSaleList(salesList: List<PreSacadorItemVO>) {
setScrollListener(lm!!)
}
}
}
private fun setScrollListener(lm: LinearLayoutManager) {
private fun setScrollListener(lm: LinearLayoutManager) {
binding.fragmentSacadorCollections.addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
@ -525,9 +532,9 @@ private fun setScrollListener(lm: LinearLayoutManager) {
super.onScrolled(recyclerView, dx, dy)
}
})
}
}
private fun setTotalLines() {
private fun setTotalLines() {
var totalMark = 0
sales.forEach {
if (it.saldo == it.picked)
@ -546,19 +553,20 @@ private fun setTotalLines() {
}
}
}
private fun setListPosition(position: Int) {
private fun setListPosition(position: Int) {
storedPosition = position
binding.fragmentSacadorCollections.addViewObserver {
lm!!.scrollToPositionWithOffset(position, 0)
}
}
}
//SEARCH AND MARK
private fun findSale(txtscan: String) {
//SEARCH AND MARK
private fun findSale(txtscan: String) {
println("text scanned" + txtscan)
var index = 0
var isBreak = false
var isOk = false
@ -589,9 +597,9 @@ private fun findSale(txtscan: String) {
(getString(R.string.itemScanetNotFound) + txtscan).toast(requireContext())
}
}
}
private fun findSale(txtscan: String, position: Int) {
private fun findSale(txtscan: String, position: Int) {
var index = 0
var isBreak = false
var isOk = false
@ -622,17 +630,17 @@ private fun findSale(txtscan: String, position: Int) {
("getString(R.string.itemScanetNotFound)" + txtscan).toast(requireContext())
}
}
}
private fun markLine(position: Int) {
private fun markLine(position: Int) {
saleAdapter!!.notifyDataSetChanged()
setListPosition(position)
saleTrackingReplace(position)
setTotalLines()
}
}
private fun saleTrackingReplace(position: Int) {
private fun saleTrackingReplace(position: Int) {
if (sales[position].picked == sales[position].quantity || sales[position].picked == 0) {
@ -645,9 +653,9 @@ private fun saleTrackingReplace(position: Int) {
}
isScanned = null
}
}
private fun unMarkLine(position: Int) {
private fun unMarkLine(position: Int) {
if (sales[position].quantity == sales[position].picked) {
customDialog.setTitle(getString(R.string.unmarkLine))
@ -669,10 +677,10 @@ private fun unMarkLine(position: Int) {
}.show()
}
}
}
//SHELVINGS
private fun showShelving(position: Int, shelvingPosition: Int) {
//SHELVINGS
private fun showShelving(position: Int, shelvingPosition: Int) {
storedShelvingPosition = shelvingPosition
storedPosition = position
var quantityGet = 0
@ -685,10 +693,10 @@ private fun showShelving(position: Int, shelvingPosition: Int) {
quantity = quantityGet,
shelvingFk = sales[position].carros[shelvingPosition].shelving
)
}
}
@RequiresApi(Build.VERSION_CODES.O)
private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) {
@RequiresApi(Build.VERSION_CODES.O)
private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) {
var shelving = ""
var item = ""
var longName = ""
@ -825,9 +833,9 @@ private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) {
customDialogList.getRecyclerView().layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
}
private fun onQuantityOfShelvingSelected(itemShelvingFk: Int) {
private fun onQuantityOfShelvingSelected(itemShelvingFk: Int) {
//1 - MODIFICAR CANTIDAD DEL CARRO
try {
val shelvingVisible = sales[storedPosition].carros[storedShelvingPosition].stockTotal
@ -862,14 +870,14 @@ private fun onQuantityOfShelvingSelected(itemShelvingFk: Int) {
//3- MARCAR LINEA
markLine(storedPosition)
}
}
private fun checkItemScan(valueToCheck: String): Boolean {
private fun checkItemScan(valueToCheck: String): Boolean {
val saleToCheck = sales[storedPosition]
return saleToCheck.itemFk.toDouble() == valueToCheck.toDouble()
}
}
private fun showScanner(index: Int, sale: PreSacadorItemVO) {
private fun showScanner(index: Int, sale: PreSacadorItemVO) {
customDialogInput.setTitle("" + sale.itemFk)
.setDescription(getString(R.string.scanWagonForItem))
@ -887,9 +895,9 @@ private fun showScanner(index: Int, sale: PreSacadorItemVO) {
false
}
}
}
private fun customDialogInputAction(index: Int) {
private fun customDialogInputAction(index: Int) {
if (!customDialogInput.getValue().isNullOrEmpty()) {
findSale(customDialogInput.getValue(), index)
customDialogInput.setValue("")
@ -897,10 +905,10 @@ private fun customDialogInputAction(index: Int) {
customDialogInput.dismiss()
hideKeyboards()
}
}
}
//OTROS
private fun setToolBar() {
//OTROS
private fun setToolBar() {
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
@ -943,44 +951,44 @@ private fun setToolBar() {
})
binding.mainToolbar.toolbarIcons.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
}
private fun scanRequest() {
private fun scanRequest() {
binding.scanInput.requestFocus()
hideKeyboards()
}
}
private fun hideKeyboards() {
private fun hideKeyboards() {
requireActivity().hideKeyboard()
}
}
companion object {
companion object {
fun newInstance(collection: CollectionVO?, entrypoint: String) = EndSacadorFragment(
collection!!, entrypoint
)
}
}
override fun getLayoutId(): Int = R.layout.fragment_pre_sacador
override fun getLayoutId(): Int = R.layout.fragment_pre_sacador
override fun onPause() {
override fun onPause() {
goBack = true
goBack2 = true
super.onPause()
}
}
override fun onResume() {
override fun onResume() {
goBack = false
super.onResume()
}
}
private fun showErrorMessage(text: String) {
private fun showErrorMessage(text: String) {
customDialog.setTitle(getString(R.string.errorMarkLine)).setDescription(text)
.setKoButton(getString(R.string.close)) {
customDialog.dismiss()
}.show()
}
}
private fun showQuantityDialog(position: Int) {
private fun showQuantityDialog(position: Int) {
try {
customDialogThreeButtons.setDescription(getString(R.string.itemSaleQuantity))
.setValue("")
@ -997,9 +1005,9 @@ private fun showQuantityDialog(position: Int) {
} catch (ex: Exception) {
getString(R.string.errorQuantity).toast(context)
}
}
}
private fun increaseQuantity(position: Int, quantity: Int) {
private fun increaseQuantity(position: Int, quantity: Int) {
positionIncreaseQuantity = position
quantityIncrease = quantity
@ -1008,6 +1016,6 @@ private fun increaseQuantity(position: Int, quantity: Int) {
quantity = quantity
)
}
}
}