From 4ce7dc9a01c62b01d6faebf83ba9adea8efa93c8 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Fri, 22 Mar 2024 13:01:58 +0100 Subject: [PATCH] refs #6810 feat:crashlytics --- .../presacador/fragment/EndSacadorFragment.kt | 1307 ++++++++--------- 1 file changed, 631 insertions(+), 676 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/EndSacadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/EndSacadorFragment.kt index 2d418593..5a605018 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/EndSacadorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/EndSacadorFragment.kt @@ -24,7 +24,15 @@ 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.* +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.OnQuantityClickListener +import es.verdnatura.presentation.common.OnSaleClickListener +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +import es.verdnatura.presentation.common.addViewObserver +import es.verdnatura.presentation.common.hideKeyboard +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 @@ -67,7 +75,6 @@ class EndSacadorFragment( private lateinit var customDialogInputParking: CustomDialogInput private lateinit var customDialogInput: CustomDialogInput private lateinit var customDialogThreeButtons: CustomDialogThreeButtons - private var ticketFk = "" private var originalScanned = "" private var positionUnmarked = -1 @@ -145,8 +152,13 @@ class EndSacadorFragment( // miramos si el primer digito es un numero de esta manera sabemos que no es una matrícula que sería el findsale if (binding.scanInput.text.first().isDigit()) { //es ticket - ticketFk = binding.scanInput.text.toString() - searchTicket(binding.scanInput.toInt()) + ticket = binding.scanInput.toInt() + try { + searchTicket(ticket) + } catch (ex: Exception) { + getString(R.string.errorInputTicketParking).toast(requireContext()) + } + } else { //es sale findSale(binding.scanInput.text.toString()) @@ -281,307 +293,320 @@ class EndSacadorFragment( } - /* responseSaleGroupAdd.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE + responseSaleAddPrevOK.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE - if (!goBack) { - if (it.isError) { - ma.messageWithSound( - getString(R.string.errorTicketAdd) + it.errorMessage, - isError = true, - true, - isToasted = true - ) + if (!goBack) { + if (it.isError) { + ma.messageWithSound( + getString(R.string.errorChangeState) + it.errorMessage, + isError = true, + true + ) - } else { - viewModel.sectorCollection_getSale( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) - ) - } - } - })*/ - - responseSaleAddPrevOK.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE - - if (!goBack) { - if (it.isError) { - ma.messageWithSound( - getString(R.string.errorChangeState) + it.errorMessage, - isError = true, - true - ) - - } else { - ma.messageWithSound(getString(R.string.previousOK), isError = false, false) - - } - } - goBack = false - }) - response.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE - - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - - } else { - ma.messageWithSound(getString(R.string.previousOK), isError = false, false) - - } - } - goBack = false - }) - responseSaleupdateIsChecked.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE - - - if (!goBack) { - if (it.isError) { - ma.messageWithSound( - getString(R.string.errorChangeState) + it.errorMessage, - isError = true, - true - ) - - } else { - if (positionUnmarked != -1) { - - searchSaleCollection() - saleAdapter!!.notifyDataSetChanged() - positionUnmarked = -1 - } - - } - } - goBack = false - - }) - responseItemShelvingSaleSupplyAdd.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE - - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - searchSaleCollection() - } - } - goBack = false - - }) - - responseCode.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = GONE - if (!goBack2) { - if (it.isError) { - customDialog.setTitle(getString(R.string.error)) - .setDescription(it.errorMessage) - .setKoButton(getString(R.string.close)) { - scanRequest() - customDialog.dismiss() - }.show() - } else { - if (checkItemScan(it.response)) { - scanRequest() - customDialogList.dismiss() - mpok?.start() - onQuantityOfShelvingSelected(itemShelvingFkStored) } else { - customDialogList.setValueTwo("") - showErrorMessage(getString(R.string.lineNotExist)) - if (mperror != null) { - mperror?.start() - } + ma.messageWithSound(getString(R.string.previousOK), isError = false, false) + } } - } + goBack = false + }) + response.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE - goBack2 = false + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) - }) - } -} + } else { + ma.messageWithSound(getString(R.string.previousOK), isError = false, false) -private fun responseSaleMoveSuccesful() { - - try { - sales[positionCollectionSplit].saldo = quantityCollectionSplit.toInt() - } catch (e: Exception) { - sales[positionCollectionSplit].saldo = 0 - } - //sales[position].startQuantity = quantity - - if (quantityCollectionSplit == 0) - markLine(positionCollectionSplit) - saleAdapter!!.notifyDataSetChanged() - -} - -private fun incresaseSuccesful() { - - try { - sales[positionIncreaseQuantity].saldo = quantityIncrease.toInt() - } catch (e: Exception) { - sales[positionIncreaseQuantity].saldo = 0 - } - - saleAdapter?.notifyDataSetChanged() - - searchSaleCollection() - -} - -//CREATE LIST - -private fun searchSaleCollection() { - binding.splashProgress.visibility = VISIBLE - viewModel.sectorCollection_getSale( - collection.collectionFk, - sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) - ) -} - -private fun searchTicket(ticketFk: Int) { - - ticket = ticketFk - - if (ticketFk != 0) - binding.splashProgress.visibility = VISIBLE - viewModel.sectorCollectionSaleGroupAdd( - ticketFk, - collection.collectionFk - ) -} - -private fun createSaleList(salesList: List) { - binding.splashProgress.visibility = GONE - if (salesList.isNullOrEmpty()) { - - ma.messageWithSound( - getString(R.string.scanTicketsForAdd), - false, - false, - getString(R.string.titlePrePicker), isToasted = true - ) - - } else { - if (ticket == 0) { - binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() - } - sales = ArrayList() - - salesList.forEach { - sales.add(it) - } - - //sergio: se tiene que ordenar por el pickingOrder del primer carro (Pako) - - for (s in sales) { - - //sergio: para que no de error si no hay carros. Ya está asignado a 0 el pickingorder si no hay item en el carro - if (!s.carros.isNullOrEmpty()) { - /* s.carros = s.carros.sortedWith(compareBy{it.pickingOrder}).sortedWith( - compareByDescending{it.priority})*/ - s.pickingOrder = s.carros.get(0).pickingOrder - } - } - - //sergio: Se ordena las sales por ellas mismas con With - sales.sortWith(compareBy { it.pickingOrder }) - lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) - - saleAdapter = PreSacadorAdapter( - sales, - pasillerosItemClickListener!!, - object : OnQuantityClickListener { - override fun onQuantityClick(sale: SaleVO) { - sales.forEachIndexed { index, saleVO -> - if (saleVO.idMovimiento == sale.saleFk) { - showQuantityDialog(index) - } } } + goBack = false + }) + responseSaleupdateIsChecked.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE - }, - object : - OnSaleClickListener { - override fun onSaleClick(sale: SaleVO) { - //sales.forEachIndexed { index, saleVO -> - sales.forEachIndexed { index, saleVO -> - if (saleVO.idMovimiento == sale.saleFk) { - if (saleVO.quantity != saleVO.picked) { - showScanner(index, saleVO) - } else { - unMarkLine(index) + + if (!goBack) { + if (it.isError) { + ma.messageWithSound( + getString(R.string.errorChangeState) + it.errorMessage, + isError = true, + true + ) + + } else { + if (positionUnmarked != -1) { + + searchSaleCollection() + saleAdapter!!.notifyDataSetChanged() + positionUnmarked = -1 + } + + } + } + goBack = false + + }) + responseItemShelvingSaleSupplyAdd.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + searchSaleCollection() + } + } + goBack = false + + }) + + responseCode.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + if (!goBack2) { + if (it.isError) { + customDialog.setTitle(getString(R.string.error)) + .setDescription(it.errorMessage) + .setKoButton(getString(R.string.close)) { + scanRequest() + customDialog.dismiss() + }.show() + } else { + if (checkItemScan(it.response)) { + scanRequest() + customDialogList.dismiss() + mpok?.start() + onQuantityOfShelvingSelected(itemShelvingFkStored) + } else { + customDialogList.setValueTwo("") + showErrorMessage(getString(R.string.lineNotExist)) + if (mperror != null) { + mperror?.start() } } } } + + goBack2 = false + }) - binding.fragmentSacadorCollections.adapter = saleAdapter - binding.fragmentSacadorCollections.layoutManager = lm - - setTotalLines() - if (storedPosition != 0) - setListPosition(storedPosition) - else if (storedBackPosition != 0) - setListPosition(storedBackPosition) - - setScrollListener(lm!!) - } -} - -private fun setScrollListener(lm: LinearLayoutManager) { - binding.fragmentSacadorCollections.addOnScrollListener(object : - RecyclerView.OnScrollListener() { - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - storedBackPosition = lm.findFirstVisibleItemPosition() - super.onScrolled(recyclerView, dx, dy) } - }) -} - -private fun setTotalLines() { - var totalMark = 0 - sales.forEach { - if (it.saldo == it.picked) - totalMark += 1 - } - if (ticket == 0) { - binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() } - binding.mainToolbar.toolbarSubtitle.text = "" + totalMark + "/" + sales.size - if (totalMark == sales.size) { - getString(R.string.ticketCompleted).toast(this.context, Toast.LENGTH_SHORT) + private fun responseSaleMoveSuccesful() { + try { + sales[positionCollectionSplit].saldo = quantityCollectionSplit.toInt() + } catch (e: Exception) { + sales[positionCollectionSplit].saldo = 0 + } + //sales[position].startQuantity = quantity + + if (quantityCollectionSplit == 0) + markLine(positionCollectionSplit) + saleAdapter!!.notifyDataSetChanged() + + } + + private fun incresaseSuccesful() { + + try { + sales[positionIncreaseQuantity].saldo = quantityIncrease.toInt() + } catch (e: Exception) { + sales[positionIncreaseQuantity].saldo = 0 + } + + saleAdapter?.notifyDataSetChanged() + + searchSaleCollection() + + } + +//CREATE LIST + + private fun searchSaleCollection() { binding.splashProgress.visibility = VISIBLE - viewModel.saleTrackingAddPrevOK( - sectorCollectionFk = collection.collectionFk + viewModel.sectorCollection_getSale( + collection.collectionFk, + sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) ) + } + + private fun searchTicket(ticketFk: Int) { + + ticket = ticketFk + + if (ticketFk != 0) + binding.splashProgress.visibility = VISIBLE + viewModel.sectorCollectionSaleGroupAdd( + ticketFk, + collection.collectionFk + ) + } + + private fun createSaleList(salesList: List) { + binding.splashProgress.visibility = GONE + if (salesList.isNullOrEmpty()) { + + ma.messageWithSound( + getString(R.string.scanTicketsForAdd), + false, + false, + getString(R.string.titlePrePicker), isToasted = true + ) + + } else { + if (ticket == 0) { + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + } + sales = ArrayList() + + salesList.forEach { + sales.add(it) + } + + //sergio: se tiene que ordenar por el pickingOrder del primer carro (Pako) + + for (s in sales) { + + //sergio: para que no de error si no hay carros. Ya está asignado a 0 el pickingorder si no hay item en el carro + if (!s.carros.isNullOrEmpty()) { + /* s.carros = s.carros.sortedWith(compareBy{it.pickingOrder}).sortedWith( + compareByDescending{it.priority})*/ + s.pickingOrder = s.carros.get(0).pickingOrder + } + } + + //sergio: Se ordena las sales por ellas mismas con With + sales.sortWith(compareBy { it.pickingOrder }) + lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + saleAdapter = PreSacadorAdapter( + sales, + pasillerosItemClickListener!!, + object : OnQuantityClickListener { + override fun onQuantityClick(sale: SaleVO) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.idMovimiento == sale.saleFk) { + showQuantityDialog(index) + } + } + } + + }, + object : + OnSaleClickListener { + override fun onSaleClick(sale: SaleVO) { + //sales.forEachIndexed { index, saleVO -> + sales.forEachIndexed { index, saleVO -> + if (saleVO.idMovimiento == sale.saleFk) { + if (saleVO.quantity != saleVO.picked) { + showScanner(index, saleVO) + } else { + unMarkLine(index) + } + } + } + } + }) + binding.fragmentSacadorCollections.adapter = saleAdapter + binding.fragmentSacadorCollections.layoutManager = lm + + setTotalLines() + if (storedPosition != 0) + setListPosition(storedPosition) + else if (storedBackPosition != 0) + setListPosition(storedBackPosition) + + setScrollListener(lm!!) + } + } + + private fun setScrollListener(lm: LinearLayoutManager) { + binding.fragmentSacadorCollections.addOnScrollListener(object : + RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + storedBackPosition = lm.findFirstVisibleItemPosition() + super.onScrolled(recyclerView, dx, dy) + } + }) + } + + private fun setTotalLines() { + var totalMark = 0 + sales.forEach { + if (it.saldo == it.picked) + totalMark += 1 + } + if (ticket == 0) { + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + } + + binding.mainToolbar.toolbarSubtitle.text = "" + totalMark + "/" + sales.size + if (totalMark == sales.size) { + getString(R.string.ticketCompleted).toast(this.context, Toast.LENGTH_SHORT) + + binding.splashProgress.visibility = VISIBLE + viewModel.saleTrackingAddPrevOK( + sectorCollectionFk = collection.collectionFk + ) + + } } -} + private fun setListPosition(position: Int) { + storedPosition = position + binding.fragmentSacadorCollections.addViewObserver { + lm!!.scrollToPositionWithOffset(position, 0) -private fun setListPosition(position: Int) { - storedPosition = position - binding.fragmentSacadorCollections.addViewObserver { - lm!!.scrollToPositionWithOffset(position, 0) + } } -} + //SEARCH AND MARK + private fun findSale(txtscan: String) { + var index = 0 + var isBreak = false + var isOk = false -//SEARCH AND MARK -private fun findSale(txtscan: String) { - var index = 0 - var isBreak = false - var isOk = false + for (saleVO in sales) { + if (saleVO.quantity != saleVO.picked) { + //1- Por carro + var shelvingIndex = 0 + for (placementVO in saleVO.carros) { + if (txtscan.uppercase() == placementVO.shelving.uppercase()) { + if (mpok != null) mpok!!.start() + isOk = true + showShelving(index, shelvingIndex) + isBreak = true + break + } + shelvingIndex += 1 + } + if (isBreak) break + } + index += 1 + } + + if (!isOk) { + if (mperror != null) { + mperror!!.start() + } + (getString(R.string.itemScanetNotFound) + txtscan).toast(requireContext()) + } + + } + + private fun findSale(txtscan: String, position: Int) { + var index = 0 + var isBreak = false + var isOk = false + + val saleVO = sales[position] - for (saleVO in sales) { if (saleVO.quantity != saleVO.picked) { //1- Por carro var shelvingIndex = 0 @@ -589,482 +614,412 @@ private fun findSale(txtscan: String) { if (txtscan.uppercase() == placementVO.shelving.uppercase()) { if (mpok != null) mpok!!.start() isOk = true - showShelving(index, shelvingIndex) + showShelving(position, shelvingIndex) isBreak = true break } shelvingIndex += 1 } - if (isBreak) break } index += 1 - } - if (!isOk) { - if (mperror != null) { - mperror!!.start() - } - (getString(R.string.itemScanetNotFound) + txtscan).toast(requireContext()) - } -} - -private fun findSale(txtscan: String, position: Int) { - var index = 0 - var isBreak = false - var isOk = false - - val saleVO = sales[position] - - if (saleVO.quantity != saleVO.picked) { - //1- Por carro - var shelvingIndex = 0 - for (placementVO in saleVO.carros) { - if (txtscan.uppercase() == placementVO.shelving.uppercase()) { - if (mpok != null) mpok!!.start() - isOk = true - showShelving(position, shelvingIndex) - isBreak = true - break + if (!isOk) { + if (mperror != null) { + mperror!!.start() } - shelvingIndex += 1 + ("getString(R.string.itemScanetNotFound)" + txtscan).toast(requireContext()) } - } - index += 1 - - if (!isOk) { - if (mperror != null) { - mperror!!.start() - } - ("getString(R.string.itemScanetNotFound)" + txtscan).toast(requireContext()) } -} + private fun markLine(position: Int) { -private fun markLine(position: Int) { + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + saleTrackingReplace(position) + setTotalLines() + } - 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) { - if (sales[position].picked == sales[position].quantity || sales[position].picked == 0) { + viewModel.saleTrackingUpdateIsChecked( + vSaleFk = sales[position].idMovimiento, + vIsChecked = sales[position].picked == sales[position].quantity, + vIsScanned = isScanned - viewModel.saleTrackingUpdateIsChecked( - vSaleFk = sales[position].idMovimiento, - vIsChecked = sales[position].picked == sales[position].quantity, - vIsScanned = isScanned + ) + } + isScanned = null + } + + private fun unMarkLine(position: Int) { + + if (sales[position].quantity == sales[position].picked) { + customDialog.setTitle(getString(R.string.unmarkLine)) + .setDescription(getString(R.string.goUnmark) + sales[position].itemFk + getString(R.string.sure)) + .setOkButton(getString(R.string.unmark)) { + sales[position].picked = 0 + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + + viewModel.itemShelving_updateFromSale( + saleFk = sales[position].idMovimiento + ) + positionUnmarked = position + scanRequest() + customDialog.dismiss() + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() + } + + } + + //SHELVINGS + private fun showShelving(position: Int, shelvingPosition: Int) { + storedShelvingPosition = shelvingPosition + storedPosition = position + binding.splashProgress.visibility = VISIBLE + var quantityGet = 0 + try { + quantityGet = (sales[position].saldo!! - sales[position].picked!!) + } catch (e: Exception) { + } + viewModel.itemPlacementSupplyAiming( + itemFk = sales[position].itemFk, + quantity = quantityGet, + shelvingFk = sales[position].carros[shelvingPosition].shelving ) } - isScanned = null -} + @RequiresApi(Build.VERSION_CODES.O) + private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) { + var shelving = "" + var item = "" + var longName = "" + var total = "0" + var itemShelvingFk = 0 + if (!placementSupplyListVO.list.isEmpty()) { + val placement = placementSupplyListVO.list[0] + shelving = placement.shelving + item = placement.itemFk + longName = placement.longName + total = placement.total + itemShelvingFk = placement.itemShelvingFk + } + listPlacementSupply = ArrayList() + placementSupplyListVO.list.forEach { + listPlacementSupply.add(BarcodeVO(code = it.proposal)) + } -private fun unMarkLine(position: Int) { + customDialogList.setTitle("$shelving($item) $total del $longName") + .setOkButton(getString(R.string.take)) { + isScanned = false - if (sales[position].quantity == sales[position].picked) { - customDialog.setTitle(getString(R.string.unmarkLine)) - .setDescription(getString(R.string.goUnmark) + sales[position].itemFk + getString(R.string.sure)) - .setOkButton(getString(R.string.unmark)) { - sales[position].picked = 0 - saleAdapter!!.notifyDataSetChanged() - setListPosition(position) + if (customDialogList.getValueTwo().isNotEmpty()) { + /*Tarea 5109*/ + try { + customDialogList.setValueTwo( + itemScanValue( + customDialogList.getValueTwo(), + "buy", + "more" + ).toString() + ) - viewModel.itemShelving_updateFromSale( - saleFk = sales[position].idMovimiento - ) - positionUnmarked = position + + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = View.VISIBLE + viewModel.getIdFromCode( + code = customDialogList.getValueTwo() + ) + customDialogList.dismiss() + } + } catch (Ex: Exception) { + ma.messageWithSound(Ex.message.toString(), true, true) + } + scanRequest() + hideKeyboards() + + } else { + getString(R.string.scanItemValidate).toast(requireContext()) + } + + }.setKoButton(getString(R.string.close)) { scanRequest() - customDialog.dismiss() - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialog.dismiss() - }.show() - } + hideKeyboards() + customDialogList.dismiss() + }.setHintValue(getString(R.string.quantitySelect)).setValue(total) + .setHintValueTwo(getString(R.string.scanItem)) + .setValueTwo("").show() -} -//SHELVINGS -private fun showShelving(position: Int, shelvingPosition: Int) { - storedShelvingPosition = shelvingPosition - storedPosition = position - binding.splashProgress.visibility = VISIBLE - var quantityGet = 0 - try { - quantityGet = (sales[position].saldo!! - sales[position].picked!!) - } catch (e: Exception) { - } - viewModel.itemPlacementSupplyAiming( - itemFk = sales[position].itemFk, - quantity = quantityGet, - shelvingFk = sales[position].carros[shelvingPosition].shelving - ) -} + customDialogList.getEditTextTwo().post(Runnable { + customDialogList.getEditTextTwo().requestFocusFromTouch() + val lManager: InputMethodManager = + requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + lManager.hideSoftInputFromWindow( + customDialogList.getEditTextTwo().windowToken, + InputMethodManager.SHOW_IMPLICIT + ) + }) -@RequiresApi(Build.VERSION_CODES.O) -private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) { - var shelving = "" - var item = "" - var longName = "" - var total = "0" - var itemShelvingFk = 0 - if (!placementSupplyListVO.list.isEmpty()) { - val placement = placementSupplyListVO.list[0] - shelving = placement.shelving - item = placement.itemFk - longName = placement.longName - total = placement.total - itemShelvingFk = placement.itemShelvingFk - } - listPlacementSupply = ArrayList() - placementSupplyListVO.list.forEach { - listPlacementSupply.add(BarcodeVO(code = it.proposal)) - } - - customDialogList.setTitle("$shelving($item) $total del $longName") - .setOkButton(getString(R.string.take)) { - isScanned = false - - if (customDialogList.getValueTwo().isNotEmpty()) { - /*Tarea 5109*/ + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { try { + isScanned = + event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + customDialogList.setValueTwo( itemScanValue( customDialogList.getValueTwo(), "buy", - "more" + "id" ).toString() ) + originalItemScan = customDialogList.getValueTwo() - if (checkItemScan(customDialogList.getValueTwo())) { - onQuantityOfShelvingSelected(itemShelvingFk) - mpok?.start() - customDialogList.dismiss() + if (customDialogList.getValueTwo().isNotEmpty()) { + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = View.VISIBLE + viewModel.getIdFromCode( + code = customDialogList.getValueTwo() + ) + customDialogList.dismiss() + } } else { - itemShelvingFkStored = itemShelvingFk - binding.splashProgress.visibility = View.VISIBLE - viewModel.getIdFromCode( - code = customDialogList.getValueTwo() - ) - customDialogList.dismiss() + getString(R.string.scanItemValidate).toast(requireContext()) } } catch (Ex: Exception) { ma.messageWithSound(Ex.message.toString(), true, true) + } scanRequest() hideKeyboards() - - } else { - getString(R.string.scanItemValidate).toast(requireContext()) - } - - }.setKoButton(getString(R.string.close)) { - scanRequest() - hideKeyboards() - customDialogList.dismiss() - }.setHintValue(getString(R.string.quantitySelect)).setValue(total) - .setHintValueTwo(getString(R.string.scanItem)) - .setValueTwo("").show() - - - customDialogList.getEditTextTwo().post(Runnable { - customDialogList.getEditTextTwo().requestFocusFromTouch() - val lManager: InputMethodManager = - requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - lManager.hideSoftInputFromWindow( - customDialogList.getEditTextTwo().windowToken, - InputMethodManager.SHOW_IMPLICIT - ) - }) - - customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - try { - isScanned = - event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER - - customDialogList.setValueTwo( - itemScanValue( - customDialogList.getValueTwo(), - "buy", - "id" - ).toString() - ) - originalItemScan = customDialogList.getValueTwo() - - - if (customDialogList.getValueTwo().isNotEmpty()) { - if (checkItemScan(customDialogList.getValueTwo())) { - onQuantityOfShelvingSelected(itemShelvingFk) - mpok?.start() - customDialogList.dismiss() - } else { - itemShelvingFkStored = itemShelvingFk - binding.splashProgress.visibility = View.VISIBLE - viewModel.getIdFromCode( - code = customDialogList.getValueTwo() - ) - customDialogList.dismiss() - } - } else { - getString(R.string.scanItemValidate).toast(requireContext()) - } - } catch (Ex: Exception) { - ma.messageWithSound(Ex.message.toString(), true, true) + return@setOnEditorActionListener true } - scanRequest() - hideKeyboards() - return@setOnEditorActionListener true - + false } - false - } - placementSupplyAdapter = - BarcodeAdapter(listPlacementSupply, object : OnBarcodeRowClickListener { - override fun onBarcodeRowClickListener(item: BarcodeVO) { - placementSupplyListVO.list.forEach { - if (it.proposal == item.code) { - customDialogList.setValue(it.total) - total = it.total - itemShelvingFk = it.itemShelvingFk + placementSupplyAdapter = + BarcodeAdapter(listPlacementSupply, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + placementSupplyListVO.list.forEach { + if (it.proposal == item.code) { + customDialogList.setValue(it.total) + total = it.total + itemShelvingFk = it.itemShelvingFk + } } + } + }, showDelete = false) + customDialogList.getRecyclerView().adapter = placementSupplyAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + + private fun onQuantityOfShelvingSelected(itemShelvingFk: Int) { + //1 - MODIFICAR CANTIDAD DEL CARRO + try { + val shelvingVisible = sales[storedPosition].carros[storedShelvingPosition].stockTotal + + sales[storedPosition].carros[storedShelvingPosition].stockTotal = + (shelvingVisible.toInt() - customDialogList.getValue().toInt()).toString() + + //sergio: se añade línea que actualiza la pantalla. Es posible que falle + // el itemShelvingSaleSupplyAdd que se actualiza pantalla si falla se actualizará todo + + sales[storedPosition].carros[storedShelvingPosition].visible = + "(" + (shelvingVisible.toInt() - customDialogList.getValue() + .toInt()).toString() + ")" + + + viewModel.itemShelvingSaleAdd( + itemShelvingFk = itemShelvingFk, + saleFk = sales[storedPosition].idMovimiento, + quantity = customDialogList.getValue().toInt() + ) + + } catch (e: Exception) { + } + + //2- MODIFICAR EL PICKED DEL SALE + try { + sales[storedPosition].picked = + sales[storedPosition].picked!! + customDialogList.getValue().toInt() + } catch (e: Exception) { + } + + //3- MARCAR LINEA + markLine(storedPosition) + + } + + private fun checkItemScan(valueToCheck: String): Boolean { + val saleToCheck = sales[storedPosition] + return saleToCheck.itemFk.toDouble() == valueToCheck.toDouble() + } + + private fun showScanner(index: Int, sale: PreSacadorItemVO) { + + customDialogInput.setTitle("" + sale.itemFk) + .setDescription(getString(R.string.scanWagonForItem)) + .setOkButton(getString(R.string.accept)) { + customDialogInputAction(index) + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.setValue("").show() + customDialogInput.getEditText().requestFocus() + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + customDialogInputAction(index) + return@setOnEditorActionListener true } - }, showDelete = false) + false + } - customDialogList.getRecyclerView().adapter = placementSupplyAdapter - - customDialogList.getRecyclerView().layoutManager = - LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) - -} - -private fun onQuantityOfShelvingSelected(itemShelvingFk: Int) { - //1 - MODIFICAR CANTIDAD DEL CARRO - try { - val shelvingVisible = sales[storedPosition].carros[storedShelvingPosition].stockTotal - - sales[storedPosition].carros[storedShelvingPosition].stockTotal = - (shelvingVisible.toInt() - customDialogList.getValue().toInt()).toString() - - //sergio: se añade línea que actualiza la pantalla. Es posible que falle - // el itemShelvingSaleSupplyAdd que se actualiza pantalla si falla se actualizará todo - - sales[storedPosition].carros[storedShelvingPosition].visible = - "(" + (shelvingVisible.toInt() - customDialogList.getValue() - .toInt()).toString() + ")" - - - viewModel.itemShelvingSaleAdd( - itemShelvingFk = itemShelvingFk, - saleFk = sales[storedPosition].idMovimiento, - quantity = customDialogList.getValue().toInt() - ) - - } catch (e: Exception) { } - //2- MODIFICAR EL PICKED DEL SALE - try { - sales[storedPosition].picked = - sales[storedPosition].picked!! + customDialogList.getValue().toInt() - } catch (e: Exception) { - } - - //3- MARCAR LINEA - markLine(storedPosition) - -} - -private fun checkItemScan(valueToCheck: String): Boolean { - val saleToCheck = sales[storedPosition] - return saleToCheck.itemFk.toDouble() == valueToCheck.toDouble() -} - -private fun showScanner(index: Int, sale: PreSacadorItemVO) { - - customDialogInput.setTitle("" + sale.itemFk) - .setDescription(getString(R.string.scanWagonForItem)) - .setOkButton(getString(R.string.accept)) { - customDialogInputAction(index) - }.setKoButton(getString(R.string.cancel)) { + private fun customDialogInputAction(index: Int) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(), index) + customDialogInput.setValue("") + scanRequest() customDialogInput.dismiss() - }.setValue("").show() - customDialogInput.getEditText().requestFocus() - customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { - customDialogInputAction(index) - return@setOnEditorActionListener true + hideKeyboards() } - false } -} + //OTROS + private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() -private fun customDialogInputAction(index: Int) { - if (!customDialogInput.getValue().isNullOrEmpty()) { - findSale(customDialogInput.getValue(), index) - customDialogInput.setValue("") - scanRequest() - customDialogInput.dismiss() + val listIcons: ArrayList = ArrayList() + + val iconParking = ImageView(context) + iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) + + val iconEraser = ImageView(context) + iconEraser.setImageResource(R.drawable.previous_delete) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) + iconEraser.tooltipText = getTooltip(R.drawable.previous_delete) + + } + + //listIcons.add(iconEraser) + listIcons.add(iconParking) + + + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + + goBack = false + /*if (item == iconEraser) { + + } else*/ + when (item) { + iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( + PasillerosItemVO( + title = getString(R.string.parking) + ), "" + ) + + } + + } + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun scanRequest() { + binding.scanInput.requestFocus() hideKeyboards() } -} - -//OTROS -private fun setToolBar() { - binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE - binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() - - val listIcons: ArrayList = ArrayList() - - val iconParking = ImageView(context) - iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) - - val iconEraser = ImageView(context) - iconEraser.setImageResource(R.drawable.previous_delete) - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) - iconEraser.tooltipText = getTooltip(R.drawable.previous_delete) + private fun hideKeyboards() { + requireActivity().hideKeyboard() } - //listIcons.add(iconEraser) - listIcons.add(iconParking) + companion object { + fun newInstance(collection: CollectionVO?, entrypoint: String) = EndSacadorFragment( + collection!!, entrypoint + ) + } + override fun getLayoutId(): Int = R.layout.fragment_pre_sacador - binding.mainToolbar.toolbarIcons.adapter = - ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { - override fun onOptionsItemSelected(item: Drawable) { + override fun onPause() { + goBack = true + goBack2 = true + super.onPause() + } - goBack = false - /*if (item == iconEraser) { + override fun onResume() { + goBack = false + super.onResume() + } - } else*/ - when (item) { - iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( - PasillerosItemVO( - title = getString(R.string.parking) - ), "" - ) - - } - - } - }) - binding.mainToolbar.toolbarIcons.layoutManager = - LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) -} - -private fun scanRequest() { - binding.scanInput.requestFocus() - hideKeyboards() -} - -private fun hideKeyboards() { - requireActivity().hideKeyboard() -} - -companion object { - fun newInstance(collection: CollectionVO?, entrypoint: String) = EndSacadorFragment( - collection!!, entrypoint - ) -} - -override fun getLayoutId(): Int = R.layout.fragment_pre_sacador - -override fun onPause() { - goBack = true //SERGIO: se quita porque si no no entra la primera vez - goBack2 = true - super.onPause() -} - -override fun onResume() { - goBack = false - super.onResume() -} - -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) { - try { - customDialogThreeButtons.setDescription(getString(R.string.txtnuevacantidad)) - .setValue("") - /* .setOkButton(getString(R.string.titleFaults)) { - checkAndCall( - position, - customDialogThreeButtons.getValue().toInt(), - getString(R.string.titleFaults) - ) - - }.setOkButtonTwo(getString(R.string.BasuraRechazar)) { - - checkAndCall( - position, - customDialogThreeButtons.getValue().toInt(), - getString(R.string.BasuraRechazar) - ) - - }.setOkButtonThree(getString(R.string.Reject)) { - checkAndCall( - position, - customDialogThreeButtons.getValue().toInt(), - getString(R.string.Reject) - ) - - }.setOkButtonFour(getString(R.string.Split)) { - checkAndCall( - position, - customDialogThreeButtons.getValue().toInt(), - getString(R.string.Split) - ) - -*/ - .setOkButtonAdd(getString(R.string.Agregar)) { - increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) - scanRequest() - customDialogThreeButtons.dismiss() - - /* checkAndCall( - position, - customDialogThreeButtons.getValue().toInt(), - getString(R.string.Agregar) - )*/ - - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialogThreeButtons.dismiss() + private fun showErrorMessage(text: String) { + customDialog.setTitle(getString(R.string.errorMarkLine)).setDescription(text) + .setKoButton(getString(R.string.close)) { + customDialog.dismiss() }.show() - customDialogThreeButtons.setFocusDialogValue() - } catch (ex: Exception) { - getString(R.string.errorQuantity).toast(context) } -} -private fun increaseQuantity(position: Int, quantity: Int) { - positionIncreaseQuantity = position - quantityIncrease = quantity + private fun showQuantityDialog(position: Int) { + try { + customDialogThreeButtons.setDescription(getString(R.string.txtnuevacantidad)) + .setValue("") + .setOkButtonAdd(getString(R.string.Agregar)) { + increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) + scanRequest() + customDialogThreeButtons.dismiss() - viewModel.collectionIncreaseQuantity( - saleFk = sales[position].idMovimiento, - quantity = quantity - ) - -} + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialogThreeButtons.dismiss() + }.show() + customDialogThreeButtons.setFocusDialogValue() + } catch (ex: Exception) { + getString(R.string.errorQuantity).toast(context) + } + } + + private fun increaseQuantity(position: Int, quantity: Int) { + positionIncreaseQuantity = position + quantityIncrease = quantity + + viewModel.collectionIncreaseQuantity( + saleFk = sales[position].idMovimiento, + quantity = quantity + ) + + } }