From e940e9ec26a96d73d541722fe871ede9f7939cfb Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 18 Jun 2024 12:14:04 +0200 Subject: [PATCH] feat qr #refs 7520 --- .../buscaritem/fragment/BuscarItemFragment.kt | 2 +- .../collection/fragment/CollectionFragment.kt | 46 +- .../fragment/CollectionFragmentPicker.kt | 217 +-- .../fragment/CollectionFragmentPickerNew.kt | 17 +- .../CollectionFragmentPickerPreviousNew.kt | 4 +- .../fragment/CollectionFragmentPreChecker.kt | 43 +- .../fragment/CollectionViewModel.kt | 474 +++--- .../fragment/ControladorFragment.kt | 10 +- .../presacador/fragment/EndSacadorFragment.kt | 1508 +++++++++-------- .../fragment/InitPreSacadorFragment.kt | 14 +- .../fragment/AutomaticAddItemFragment.kt | 2 +- 11 files changed, 1101 insertions(+), 1236 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt index 16bc26d5..a9cdddd0 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt @@ -45,7 +45,7 @@ class BuscarItemFragment( if (binding.editItemFk.text.toString().isNotEmpty()) try { getLocations( itemScanValue( - binding.editItemFk.text.toString(), "buy", "more" + binding.editItemFk.text.toString(), arrayOf("buy"), "more" ) ) } catch (ex: Exception) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt index 8b90d349..37454031 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt @@ -36,11 +36,9 @@ import es.verdnatura.domain.ConstAndValues.PRINTERNAME import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.ConstAndValues.SECTORDESCRIP import es.verdnatura.domain.ConstAndValues.SECTORFK -import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK import es.verdnatura.domain.notNull import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.DataMessageSalix import es.verdnatura.presentation.common.ItemScanned import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnMistakeClickListener @@ -80,7 +78,6 @@ class CollectionFragment( var collection: CollectionVO = CollectionVO(0), var type: String = SACADOR ) : BaseFragment(CollectionViewModel::class) { - private lateinit var dataMessageSalix: DataMessageSalix private var sales: List = listOf() private var salesParent: List = listOf() private var saleAdapter: SaleAdapter? = null @@ -936,17 +933,6 @@ class CollectionFragment( } - private fun getSalePerson(ticketFk: Int): String { - var salePerson = "" - for (it in sales) { - if (it.ticketFk.equals(ticketFk)) { - salePerson = it.salePersonFk ?: "" - break - } - } - return salePerson - } - //CREATE LIST private fun createCollectionList() { @@ -1640,7 +1626,7 @@ class CollectionFragment( isScanned = false/*Tarea #5109*/ customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) @@ -1719,7 +1705,7 @@ class CollectionFragment( customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) @@ -1938,22 +1924,10 @@ class CollectionFragment( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - //sergio datos para mensaje salix - - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) - viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( - WAREHOUSEFK - ) + quantity = customDialogList.getValueTwo().toInt() ) @@ -1975,7 +1949,7 @@ class CollectionFragment( try { customDialogList.setValue( itemScanValue( - customDialogList.getValue(), "buy", "more" + customDialogList.getValue(), arrayOf("buy"), "more" ).toString() ) @@ -2004,20 +1978,10 @@ class CollectionFragment( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) - viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( - WAREHOUSEFK - ) + quantity = customDialogList.getValueTwo().toInt(), ) scanRequest() customDialogList.dismiss() diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt index e49614cb..1946ad3c 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPicker.kt @@ -32,11 +32,11 @@ import es.verdnatura.domain.ConstAndValues.PRINTERNAME import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.ConstAndValues.SECTORDESCRIP import es.verdnatura.domain.ConstAndValues.SECTORFK -import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK +import es.verdnatura.domain.isParking +import es.verdnatura.domain.isShelving import es.verdnatura.domain.notNull import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.DataMessageSalix import es.verdnatura.presentation.common.ItemScanned import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnMistakeClickListener @@ -75,7 +75,6 @@ class CollectionFragmentPicker( var collection: CollectionVO = CollectionVO(0), var type: String = SACADOR ) : BaseFragment(CollectionViewModel::class) { - private lateinit var dataMessageSalix: DataMessageSalix private var sales: List = listOf() private var salesParent: List = listOf() private var saleAdapter: SaleAdapter? = null @@ -323,11 +322,20 @@ class CollectionFragmentPicker( if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) { if (!customDialogList.getValue().isEmpty()) { ma.hideKeyboard(customDialogList.getEditText()) - var saleGroupScanned = customDialogList.getValue() - isScanned = - event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER - markPrevia(saleGroupScanned) - customDialogList.dismiss() + try { + val saleGroupScanned = itemScanValue( + customDialogList.getValue(), + arrayOf("saleGroup"), + "id" + ).toString() + isScanned = + event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + markPrevia(saleGroupScanned) + customDialogList.dismiss() + } catch (ex: Exception) { + ex.message!!.toast(requireContext()) + } + } customDialogList.setValue("") ma.hideKeyboard(customDialogList.getEditText()) @@ -905,17 +913,6 @@ class CollectionFragmentPicker( } - private fun getSalePerson(ticketFk: Int): String { - var salePerson = "" - for (it in sales) { - if (it.ticketFk.equals(ticketFk)) { - salePerson = it.salePersonFk ?: "" - break - } - } - return salePerson - } - //CREATE LIST private fun createCollectionList() { @@ -960,7 +957,8 @@ class CollectionFragmentPicker( } - saleAdapter = SaleAdapter(myGroupList, + saleAdapter = SaleAdapter( + myGroupList, pasillerosItemClickListener!!, object : OnQuantityClickListener { @@ -1088,8 +1086,8 @@ class CollectionFragmentPicker( customDialogList.dismiss() ma.onMyBackPressed() }.setValue("").setOkButton(getString(R.string.print)) { - print() - }.show() + print() + }.show() customDialogList.getEditText().requestFocus() ma.hideKeyboard(customDialogList.getEditText()) @@ -1100,7 +1098,7 @@ class CollectionFragmentPicker( try { customDialogList.setValue( itemScanValue( - customDialogList.getValue(), "ticket", "id" + customDialogList.getValue(), arrayOf("ticket"), "id" ).toString() ) @@ -1346,22 +1344,22 @@ class CollectionFragmentPicker( } if (!isOk) { - checkIsParking(txtscan) + + if (txtscan.isParking()) { + ticketParking(txtscan) + } else { + if (mperror != null) mperror!!.start() + } } } } - private fun checkIsParking(txtscan: String) { - if (txtscan.contains("-")) { - tickets.forEach { - viewModel.setParking( - ticketFk = it.toInt(), parking = txtscan - ) - } - - } else { - if (mperror != null) mperror!!.start() + private fun ticketParking(txtscan: String) { + tickets.forEach { + viewModel.setParking( + ticketFk = it.toInt(), parking = txtscan + ) } } @@ -1544,40 +1542,40 @@ class CollectionFragmentPicker( state = 0 if ((sales[position].isPrepared == "1") || (sales[position].quantity!! > 0)) { customDialog.setTitle(getString(R.string.unmarkLine)).setDescription( - getString(R.string.goUnmark) + sales[position].itemFk + getString( - R.string.sure + getString(R.string.goUnmark) + sales[position].itemFk + getString( + R.string.sure + ) + ).setOkButton(getString(R.string.unmark)) { + sales[position].isPrepared = "0" + sales[position].pickedQuantity = 0 + + saleAdapter!!.notifyDataSetChanged() + //nuevo + var mySale = sales[position].saleFk + for (indice in myGroupList.indices) { + + if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { + storedBackPosition = indice + + } + } + storedBackPosition = position + setListPosition(position, false) + if (type != PRECHECKER) { + + viewModel.itemShelvingUpdateFromSale( + sales[position].saleFk ) - ).setOkButton(getString(R.string.unmark)) { - sales[position].isPrepared = "0" - sales[position].pickedQuantity = 0 + positionUnmarked = position - saleAdapter!!.notifyDataSetChanged() - //nuevo - var mySale = sales[position].saleFk - for (indice in myGroupList.indices) { - - if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { - storedBackPosition = indice - - } - } - storedBackPosition = position - setListPosition(position, false) - if (type != PRECHECKER) { - - viewModel.itemShelvingUpdateFromSale( - sales[position].saleFk - ) - positionUnmarked = position - - } - setTotalLines() - scanRequest() - customDialog.dismiss() - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialog.dismiss() - }.show() + } + setTotalLines() + scanRequest() + customDialog.dismiss() + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() } } @@ -1641,7 +1639,7 @@ class CollectionFragmentPicker( isScanned = false/*Tarea #5109*/ customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) @@ -1726,7 +1724,7 @@ class CollectionFragmentPicker( customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) @@ -1949,20 +1947,10 @@ class CollectionFragmentPicker( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - //sergio datos para mensaje salix - - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) - viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + quantity = customDialogList.getValueTwo().toInt() ) @@ -1984,7 +1972,7 @@ class CollectionFragmentPicker( try { customDialogList.setValue( itemScanValue( - customDialogList.getValue(), "buy", "more" + customDialogList.getValue(), arrayOf("buy"), "more" ).toString() ) @@ -2013,20 +2001,10 @@ class CollectionFragmentPicker( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) - viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( - WAREHOUSEFK - ) + quantity = customDialogList.getValueTwo().toInt() ) scanRequest() customDialogList.dismiss() @@ -2293,17 +2271,31 @@ class CollectionFragmentPicker( .setOkButton(getString(R.string.accept)) { if (!customDialogInput.getValue().isNullOrEmpty()) { //Tarea 5675 - findSale(customDialogInput.getValue(), index) + + if (customDialogInput.getValue().isParking() || !customDialogInput.getValue() + .isShelving() + ) { + ma.messageWithSound( + message = getString(R.string.shelvingError), + isError = true, + isPlayed = true, + isToasted = true + ) + customDialogInput.setValue("") + } else { + findSale(customDialogInput.getValue(), index) + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + } } else { ma.messageWithSound( getString(R.string.shelvingError), true, true, "Error", true ) } - customDialogInput.setValue("") - scanRequest() - customDialogInput.dismiss() - hideKeyboards() + }.setKoButton(getString(R.string.cancel)) { customDialogInput.dismiss() }.setValue("").show() @@ -2312,12 +2304,25 @@ class CollectionFragmentPicker( if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { if (!customDialogInput.getValue().isNullOrEmpty()) { //Tarea 5675 - findSale(customDialogInput.getValue(), index) + if (customDialogInput.getValue().isParking() || !customDialogInput.getValue() + .isShelving() + ) { + ma.messageWithSound( + message = getString(R.string.shelvingError), + isError = true, + isPlayed = true, + isToasted = true + ) + customDialogInput.setValue("") + } else { + findSale(customDialogInput.getValue(), index) + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + } } - customDialogInput.setValue("") - scanRequest() - customDialogInput.dismiss() - hideKeyboards() + return@setOnEditorActionListener true } false @@ -2374,12 +2379,12 @@ class CollectionFragmentPicker( customDialogList.setTitle(getString(R.string.errorCause)) customDialogList.hideTextInput().setKoButton(getString(R.string.cancel)) { - scanRequest() - hideKeyboards() - listPlacementSupply.clear() - customDialogList.dismiss() + scanRequest() + hideKeyboards() + listPlacementSupply.clear() + customDialogList.dismiss() - }.show() + }.show() placementSupplyAdapter = diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt index 268def21..77d3ea09 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt @@ -22,6 +22,7 @@ import es.verdnatura.domain.ConstAndValues.BASEURLSALIX import es.verdnatura.domain.ConstAndValues.CONTROLADOR import es.verdnatura.domain.ConstAndValues.PRINTERNAME import es.verdnatura.domain.ConstAndValues.SACADOR +import es.verdnatura.domain.isParking import es.verdnatura.domain.notNull import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment @@ -757,7 +758,17 @@ class CollectionFragmentPickerNew( R.string.take ) ) { - customDialogTakeAction(pos, itemShelvingFk, totalReserved, false) + if (customDialogList.getValueTwo().isParking()) { + ma.messageWithSound( + message = getString(R.string.scanItem), + isError = true, + isPlayed = true, + isToasted = true + ) + customDialogList.setValueTwo("") + } else { + customDialogTakeAction(pos, itemShelvingFk, totalReserved, false) + } }.setKoButton(getString(R.string.close)) { requireActivity().hideKeyboard(customDialogList.getEditTextTwo()) @@ -796,7 +807,7 @@ class CollectionFragmentPickerNew( customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) val quantityToReserve = customDialogList.getValue().toInt() @@ -945,7 +956,7 @@ class CollectionFragmentPickerNew( try { customDialogList.setValue( itemScanValue( - customDialogList.getValue(), "buy", "more" + customDialogList.getValue(), arrayOf("buy"), "more" ).toString() ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt index 69193bc0..1e401e84 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt @@ -833,7 +833,7 @@ class CollectionFragmentPickerPreviousNew( customDialogList.setValueTwo( itemScanValue( - customDialogList.getValueTwo(), "buy", "more" + customDialogList.getValueTwo(), arrayOf("buy"), "more" ).toString() ) val quantityToReserve = customDialogList.getValue().toInt() @@ -981,7 +981,7 @@ class CollectionFragmentPickerPreviousNew( try { customDialogList.setValue( itemScanValue( - customDialogList.getValue(), "buy", "more" + customDialogList.getValue(), arrayOf("buy"), "more" ).toString() ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt index 6f1803c5..d4f19d5e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt @@ -35,11 +35,9 @@ import es.verdnatura.domain.ConstAndValues.PRINTERNAME import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.ConstAndValues.SECTORDESCRIP import es.verdnatura.domain.ConstAndValues.SECTORFK -import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK import es.verdnatura.domain.notNull import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.DataMessageSalix import es.verdnatura.presentation.common.ItemScanned import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnMistakeClickListener @@ -80,7 +78,6 @@ class CollectionFragmentPreChecker( var type: String = SACADOR ) : BaseFragment(CollectionViewModel::class) { - private lateinit var dataMessageSalix: DataMessageSalix private var sales: List = listOf() private var salesParent: List = listOf() private var saleAdapter: SaleAdapter? = null @@ -961,17 +958,6 @@ class CollectionFragmentPreChecker( } - private fun getSalePerson(ticketFk: Int): String { - var salePerson = "" - for (it in sales) { - if (it.ticketFk.equals(ticketFk)) { - salePerson = it.salePersonFk ?: "" - break - } - } - return salePerson - } - //CREATE LIST private fun createCollectionList() { @@ -1613,7 +1599,7 @@ class CollectionFragmentPreChecker( customDialogList.setValueTwo( itemScanValue( customDialogList.getValueTwo(), - "buy", + arrayOf("buy"), "more" ).toString() ) @@ -1689,7 +1675,7 @@ class CollectionFragmentPreChecker( customDialogList.setValueTwo( itemScanValue( customDialogList.getValueTwo(), - "buy", + arrayOf("buy"), "more" ).toString() ) @@ -1918,20 +1904,11 @@ class CollectionFragmentPreChecker( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - //sergio datos para mensaje salix - - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + quantity = customDialogList.getValueTwo().toInt() ) @@ -1954,7 +1931,7 @@ class CollectionFragmentPreChecker( customDialogList.setValue( itemScanValue( customDialogList.getValue(), - "buy", + arrayOf("buy"), "more" ).toString() ) @@ -1984,20 +1961,10 @@ class CollectionFragmentPreChecker( getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - dataMessageSalix = DataMessageSalix( - ticket = ticketSelected, - item = customDialogList.getValue(), - quantity = customDialogList.getValueTwo(), - personSale = getSalePerson(ticketSelected) - ) - viewModel.collectionAddItem( itemFk = customDialogList.getValue().toInt(), ticketFk = ticketSelected, - quantityFk = customDialogList.getValueTwo().toInt(), - warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( - WAREHOUSEFK - ) + quantity = customDialogList.getValueTwo().toInt(), ) scanRequest() customDialogList.dismiss() diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt index 9e801613..a4f0eb35 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt @@ -13,7 +13,6 @@ import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction -import es.verdnatura.presentation.common.CollectionItemSalix import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.ResponseItemExistsItemShelvingSale import es.verdnatura.presentation.common.ResponseItemVO @@ -194,7 +193,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val loadResponseDel: LiveData> = _responseDel.map { Event(it) } - val loadResponseAddItem: LiveData> = _responseCollectionAddItem.map { Event(it) } + val loadResponseAddItem: LiveData> = + _responseCollectionAddItem.map { Event(it) } val loadResponseSaleTrackingMark: LiveData> = _responseSaleTracking_mark.map { Event(it) } @@ -207,17 +207,12 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { get() = _responseSaleAddPrevOK fun getSales( - collectionFk: Int, - print: String, - source: String + collectionFk: Int, print: String, source: String ) { salix.getSalesFromTicketOrCollection( - collectionOrTicketFk = collectionFk, - print = print != "0", - source = source - ).enqueue(object : - SalixCallback(context) { + collectionOrTicketFk = collectionFk, print = print != "0", source = source + ).enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { _collectionTicketList.value = CollectionVO( 0, @@ -241,10 +236,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collectionTicketGet( - collectionFk: Int, - sectorFk: Int, - print: String, - type: String + collectionFk: Int, sectorFk: Int, print: String, type: String ) { getSales(collectionFk, print, type) @@ -258,10 +250,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ) { salix.getCollectionTickets( - collectionFk, - hashMapOf("print" to print) - ).enqueue(object : - SalixCallback(context) { + collectionFk, hashMapOf("print" to print) + ).enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { _collectionTicketSalix.value = CollectionTicket( 0, @@ -276,11 +266,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { _collectionTicketSalix.value = response.body()?.let { it.map(contextApp) } } else { _collectionTicketSalix.value = CollectionTicket( - 0, - isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() + 0, isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), response.message() ) ) } @@ -289,61 +276,51 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collectionGetId( - ticketFk: Int, - sectorFk: Int, - print: String, - type: String + ticketFk: Int, sectorFk: Int, print: String, type: String ) { salix.getCollectionId( filter = """{"where":{"ticketFk":$ticketFk},"fields":"collectionFk"}""" - ) - .enqueue(object : - SalixCallback>(context) { - override fun onError(t: Throwable) { + ).enqueue(object : SalixCallback>(context) { + override fun onError(t: Throwable) { + _collectionTicketList.value = CollectionVO( + 0, + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } + + override fun onSuccess(response: Response>) { + + if (response.body()!!.isNotEmpty()) { + collectionTicketGet( + response.body()!![0].entrySet().first().value.toString().toInt(), + sectorFk, + print, + type + ) + } else { _collectionTicketList.value = CollectionVO( - 0, - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + 0, isError = false ) } - - override fun onSuccess(response: Response>) { - - if (response.body()!!.isNotEmpty()) { - collectionTicketGet( - response.body()!![0].entrySet().first().value.toString().toInt(), - sectorFk, - print, - type - ) - } else { - _collectionTicketList.value = CollectionVO( - 0, - isError = false - ) - } - } - }) + } + }) } fun itemShelvingSaleExists( - itemShelvingSaleFk: Number, - position: Int, - quantity: Int + itemShelvingSaleFk: Number, position: Int, quantity: Int ) { salix.itemShelvingSaleExists( itemShelvingSaleFk - ) - .enqueue(object : - SalixCallback(context) { + ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _responseExistsItemShelvingSale.value = ResponseItemExistsItemShelvingSale( - response.body()!!.entrySet().first().value.asBoolean, position, quantity - ) - } - }) + override fun onSuccess(response: Response) { + _responseExistsItemShelvingSale.value = ResponseItemExistsItemShelvingSale( + response.body()!!.entrySet().first().value.asBoolean, position, quantity + ) + } + }) } fun saleTrackingReplace( @@ -359,27 +336,25 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { SaleTrackingReplaceSalix( saleFk, originalQuantity, code, isChecked != "0", buyFk, isScanned!! ) - ) - /* silex.saleTrackingReplace( + )/* silex.saleTrackingReplace( saleFk, originalQuantity, code, isChecked != "0", buyFk, isScanned!! - )*/ - .enqueue(object : SilexCallback(context) { - override fun onError(t: Throwable) { - _responseSaleReplace.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + )*/.enqueue(object : SilexCallback(context) { + override fun onError(t: Throwable) { + _responseSaleReplace.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { - _responseSaleReplace.value = ResponseItemVO(isError = false, response = "") - } - }) + override fun onSuccess(response: Response) { + _responseSaleReplace.value = ResponseItemVO(isError = false, response = "") + } + }) } fun saleTracking_mark( @@ -404,8 +379,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { quantity = quantity, isScanned = isScanned!! ) - ) - /* silex.saleTracking_mark( + )/* silex.saleTracking_mark( saleFk, originalQuantity, code, @@ -413,36 +387,31 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { buyFk, itemShelvingFk, quantity, - isScanned)*/ - .enqueue(object : SilexCallback(context) { - override fun onError(t: Throwable) { - _responseSaleTracking_mark.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + isScanned)*/.enqueue(object : SilexCallback(context) { + override fun onError(t: Throwable) { + _responseSaleTracking_mark.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { - if (!response.isSuccessful) { - _responseSaleTracking_mark.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() - ) + override fun onSuccess(response: Response) { + if (!response.isSuccessful) { + _responseSaleTracking_mark.value = ResponseItemVO( + isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), response.message() ) - } else { - _responseSaleTracking_mark.value = - ResponseItemVO(isError = false, response = "") - } + ) + } else { + _responseSaleTracking_mark.value = + ResponseItemVO(isError = false, response = "") } - }) + } + }) } fun itemShelvingSaleSetQuantity( - itemShelvingSaleFk: Int, - quantity: Int, - isItemShelvingSaleEmpty: Boolean? + itemShelvingSaleFk: Int, quantity: Int, isItemShelvingSaleEmpty: Boolean? ) { salix.itemShelvingSaleSetquantitySalix( params = arrayListOf(itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty) @@ -459,10 +428,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { if (!response.isSuccessful) { _responseConfirmReservedItemShelvingSale.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() + isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), response.message() ) ) } else { @@ -474,17 +441,13 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collectionAddWithReservation( - item: Int, - quantity: Int, - ticketSelected: Int, - saleGroupFk :Int ? + item: Int, quantity: Int, ticketSelected: Int, saleGroupFk: Int? ) { salix.collectionAddWithReservation( params = arrayListOf(item, quantity, ticketSelected, saleGroupFk) ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _responseCollectionAddItem.value = - ResponseItemVO(isError = false, response = "") + _responseCollectionAddItem.value = ResponseItemVO(isError = false, response = "") } /* override fun onError(t: Throwable) { @@ -498,8 +461,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun confirmItemShelvingReservedUpdate( - itemShelvingSaleFk: Int, - isPicked: Boolean + itemShelvingSaleFk: Int, isPicked: Boolean ) { salix.itemShelvingsReservedUpdate( id = itemShelvingSaleFk, params = hashMapOf("isPicked" to isPicked) @@ -514,10 +476,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { if (!response.isSuccessful) { _responseConfirmReservedUpdate.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() + isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), response.message() ) ) } else { @@ -529,18 +489,13 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun itemPlacementSupplyAiming( - shelvingFk: String, - quantity: Int, - itemFk: Int + shelvingFk: String, quantity: Int, itemFk: Int ) { salix.itemPlacementSupplyAiming( arrayListOf( - shelvingFk, - quantity, - itemFk + shelvingFk, quantity, itemFk ).formatWithQuotes() - ).enqueue(object : - SalixCallback>(context) { + ).enqueue(object : SalixCallback>(context) { override fun onSuccess(response: Response>) { if (response.body() != null) { _placementSuppleyList.value = response.body()?.let { PlacementSupplyListVO(it) } @@ -551,8 +506,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { itemShelvingFk = 0, isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() + nameofFunction(this), response.message() ) ) ) @@ -576,13 +530,11 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collectionStickerPrint( - collectionFk: Int, - labelCount: Int? + collectionFk: Int, labelCount: Int? ) { salix.collectionStickerPrint( arrayListOf( - collectionFk, - labelCount + collectionFk, labelCount ) ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { @@ -600,27 +552,24 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun ticketCollection_setUsedShelves( - ticketFk: Int, - usedShelves: Int + ticketFk: Int, usedShelves: Int ) { salix.ticketCollectionUpdate( - """where={"ticketFk":$ticketFk}""", - hashMapOf("usedShelves" to usedShelves) - ) - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { + """where={"ticketFk":$ticketFk}""", hashMapOf("usedShelves" to usedShelves) + ).enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { - _responseUsedShelves.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + _responseUsedShelves.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { - _responseUsedShelves.value = ResponseItemVO(isError = false) + override fun onSuccess(response: Response) { + _responseUsedShelves.value = ResponseItemVO(isError = false) - } - }) + } + }) } fun itemShelvingSaleUnpicked( @@ -687,41 +636,39 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collectionAddItem( - itemFk: Int, - quantityFk: Int, - ticketFk: Int, - warehouseFk: Int + itemFk: Int, quantity: Int, ticketFk: Int ) { - //Tarea 6276 OK - salix.addSaleByCode( - CollectionItemSalix( - itemFk.toString(), - quantityFk, - ticketFk, - warehouseFk - ) + + //Tarea 6889 + salix.addSale( + id = ticketFk, + barcode = itemFk.toString(), + quantity = quantity ) - /*silex.collectionAddItem( - itemFk, - quantityFk, - ticketFk, - warehouseFk - )*/ - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { + /* salix.addSaleByCode( + CollectionItemSalix( + itemFk.toString(), + quantityFk, + ticketFk, + warehouseFk + ) + )*/ - _responseNew.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + .enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { - override fun onSuccess(response: Response) { - _responseNew.value = - ResponseItemVO(isError = false, response = response.message()!!) + _responseNew.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - } - }) + override fun onSuccess(response: Response) { + _responseNew.value = + ResponseItemVO(isError = false, response = response.message()!!) + + } + }) } /* fun saleMove( @@ -805,8 +752,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { //Tarea 6276 salix.saleTrackingDel( SaleTrackingDelSalix( - saleFk = saleFk, - stateCodes = listOf("CHECKED", "OK", "PREPARED") + saleFk = saleFk, stateCodes = listOf("CHECKED", "OK", "PREPARED") ) ) //silex.saleTrackingDel(saleFk) @@ -848,8 +794,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun setParking( - ticketFk: Int, - parking: String + ticketFk: Int, parking: String ) { salix.setParking(arrayListOf(ticketFk, parking).formatWithQuotes()) .enqueue(object : SalixCallback(context) { @@ -868,14 +813,12 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun ticketStateTodaySetState( - ticketFk: Int, - state: String + ticketFk: Int, state: String ) { salix.ticketStateTodaySetState(arrayListOf(ticketFk, state).formatWithQuotes()) .enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _response.value = - ResponseItemVO(isError = false, response = "") + _response.value = ResponseItemVO(isError = false, response = "") } override fun onError(t: Throwable) { @@ -888,32 +831,28 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun getIdFromCodeSalix(code: String) { - salix.barcodes_toitem(code) - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _responseCode.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + salix.barcodes_toitem(code).enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + _responseCode.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { + override fun onSuccess(response: Response) { - _responseCode.value = - ResponseItemVO( - isError = false, - response = if (response.body() == null) "" else { - response!!.body().toString() - } - ) + _responseCode.value = ResponseItemVO( + isError = false, response = if (response.body() == null) "" else { + response!!.body().toString() + } + ) - } - }) + } + }) } fun collectionIncreaseQuantitySalix( - saleFk: Int, - quantity: String + saleFk: Int, quantity: String ) { salix.collectionIncreaseQuantitySalix( SalixSaleQuantity(saleId = saleFk, quantity = quantity.toInt()) @@ -935,53 +874,47 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun saleMistakeAdd( - saleFk: Int, - typeFk: Int + saleFk: Int, typeFk: Int ) { salix.saleMistakeAdd( SaleMistakeSalix( - userFk = (context as MobileApplication).userId!!, - saleFk = saleFk, - typeFk = typeFk + userFk = (context as MobileApplication).userId!!, saleFk = saleFk, typeFk = typeFk ) - ) - .enqueue(object : - SalixCallback(context) { - override fun onError(t: Throwable) { - _responseSaleMistakeAdd.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + ).enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + _responseSaleMistakeAdd.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { - super.onSuccess(response) - _responseSaleMistakeAdd.value = - ResponseItemVO(isError = false, response = response.message()) - } - }) + override fun onSuccess(response: Response) { + super.onSuccess(response) + _responseSaleMistakeAdd.value = + ResponseItemVO(isError = false, response = response.message()) + } + }) } fun mistakeType() { - salix.getMistakeTypes() - .enqueue(object : SalixCallback>(context) { - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _mistakeList.value = response.body()?.let { MistakeTypeListVO(it) } - } else { - val listError: ArrayList = ArrayList() - listError.add(MistakeTypeVO(0, "")) - _mistakeList.value = MistakeTypeListVO(listError) - } - } - - override fun onError(t: Throwable) { + salix.getMistakeTypes().enqueue(object : SalixCallback>(context) { + override fun onSuccess(response: Response>) { + if (response.body() != null) { + _mistakeList.value = response.body()?.let { MistakeTypeListVO(it) } + } else { val listError: ArrayList = ArrayList() listError.add(MistakeTypeVO(0, "")) _mistakeList.value = MistakeTypeListVO(listError) } - }) + } + + override fun onError(t: Throwable) { + val listError: ArrayList = ArrayList() + listError.add(MistakeTypeVO(0, "")) + _mistakeList.value = MistakeTypeListVO(listError) + } + }) } fun ticketIsOutClosureZone( @@ -989,8 +922,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ) { salix.ticketIsOutClosureZone( arrayListOf(ticketFk) - ).enqueue(object : - SalixCallback(context) { + ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { _responseTicketClosure.value = ResponseItemVO( isError = false, @@ -1014,8 +946,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { salix.ticketState( """{"where": {"ticketFk": "$ticketFk"},"include":[{"relation":"user","scope":{"fields":["username"]}}]}""" - ).enqueue(object : - SalixCallback>(context) { + ).enqueue(object : SalixCallback>(context) { override fun onSuccess(response: Response>) { _responseTicketState.value = if (response.body()!!.isEmpty()) { TicketState() @@ -1030,8 +961,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { fun callBackSalix(function: String, params: ArrayList) { salix.executeFunc( routine = function, params = params - ).enqueue(object : - SalixCallback(context) { + ).enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { _responseTicketClosure.value = ResponseItemVO( @@ -1042,9 +972,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { _responseTicketClosure.value = ResponseItemVO( - isError = false, - response = response.body()!!.toString(), - errorMessage = "" + isError = false, response = response.body()!!.toString(), errorMessage = "" ) } @@ -1057,8 +985,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ) { salix.hasUncheckedTicket(collectionFk) //silex.collection_getUncheckedTicket(collectionFk) - .enqueue(object : - SalixCallback(context) { + .enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { _responseCollectionUnchecked.value = ResponseItemVO( isError = true, @@ -1070,17 +997,14 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { if (response.body() != null) { _responseCollectionUnchecked.value = ResponseItemVO( - isError = false, - response = response.body()!!, - errorMessage = "" + isError = false, response = response.body()!!, errorMessage = "" ) } else { _responseCollectionUnchecked.value = ResponseItemVO( isError = true, response = response.body()!!.toString(), errorMessage = getMessageFromAllResponse( - nameofFunction(this), - response.message() + nameofFunction(this), response.message() ) ) } @@ -1089,31 +1013,27 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun collection_setState( - collectionFk: Int, - state: String + collectionFk: Int, state: String ) { salix.collectionSetState( params = arrayListOf( - collectionFk, - state + collectionFk, state ).formatWithQuotes() - ) - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { + ).enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { - _responseState.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - super.onError(t) - } + _responseState.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + super.onError(t) + } - override fun onSuccess(response: Response) { - _responseState.value = - ResponseItemVO(isError = false, response = "") - super.onSuccess(response) - } - }) + override fun onSuccess(response: Response) { + _responseState.value = ResponseItemVO(isError = false, response = "") + super.onSuccess(response) + } + }) } fun saleTrackingAddPrevOK( diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt index ce93dafc..92e6d1ac 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt @@ -62,7 +62,7 @@ class ControladorFragment : try { binding.scanInput.setText( itemScanValue( - binding.scanInput.text.toString(), "ticket", "id" + binding.scanInput.text.toString(), arrayOf("ticket","saleGroup"), "id" ).toString().toInt().toString(), ) } catch (ex: Exception) { @@ -77,7 +77,7 @@ class ControladorFragment : try { collectionViewModel!!.ticketState( itemScanValue( - binding.scanInput.text.toString(), "ticket", "id" + binding.scanInput.text.toString(), arrayOf("ticket","saleGroup"), "id" ).toString().toInt() ) } catch (ex: Exception) { @@ -107,12 +107,11 @@ class ControladorFragment : viewModel.getSales( collectionFk = itemScanValue( - binding.scanInput.text.toString(), "ticket", "id" + binding.scanInput.text.toString(), arrayOf("ticket","saleGroup"), "id" ).toString().toInt(), print = false, source = ConstAndValues.ON_CHECKING ) - println("Qrtest4") /* viewModel.getSales( collectionFk = binding.scanInput.text.toString() @@ -129,12 +128,11 @@ class ControladorFragment : } else { viewModel.getSales( collectionFk = itemScanValue( - binding.scanInput.text.toString(), "ticket", "id" + binding.scanInput.text.toString(), arrayOf("ticket","saleGRoup"), "id" ).toString().toInt(), print = false, source = ConstAndValues.ON_CHECKING ) - println("Qrtest3") /* viewModel.getSales( collectionFk = binding.scanInput.text.toString().toInt(), 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 78e8967b..d891fe83 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 @@ -19,7 +19,6 @@ import es.verdnatura.R import es.verdnatura.databinding.FragmentPreSacadorBinding import es.verdnatura.domain.ConstAndValues.SECTORFK 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 @@ -30,6 +29,7 @@ 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.itemScanIsQr import es.verdnatura.presentation.common.itemScanValue import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialogInput @@ -133,465 +133,437 @@ class EndSacadorFragment( if (!binding.scanInput.text.toString().isNullOrEmpty()) { - // originalScanned=binding.scanInput.text + if (itemScanIsQr(binding.scanInput.text.toString())) { + + ticket = itemScanValue( + binding.scanInput.text.toString(), + arrayOf("saleGroup"), + "id" + ) as Int + + addSaleGroupToCollection(ticket) + + + } else { if (binding.scanInput.text.contains("-")) { - - //es parking pasillerosItemClickListener?.onPasillerosItemClickListener( PasillerosItemVO( title = getString(R.string.Parking) ), "" ) - // parkingTicket(binding.scanInput.text.toString()) } else { - //if (binding.scanInput.text.length > 6){ - // 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 - ticket = binding.scanInput.toInt() - try { - searchTicket(ticket) - } catch (ex: Exception) { - getString(R.string.errorInputTicketParking).toast(requireContext()) - } - - } else { - //es sale - findSale(binding.scanInput.text.toString()) - } + findSale(binding.scanInput.text.toString()) } - } - binding.scanInput.setText("") - hideKeyboards() - return@setOnEditorActionListener true - } - true - } + + } + binding.scanInput.setText("") hideKeyboards() - - //LISTA ========= - binding.collectionSwipe.setOnRefreshListener { - - if (::sales.isInitialized) { - sales.clear() - saleAdapter!!.notifyDataSetChanged() - } - searchSaleCollection() - binding.collectionSwipe.isRefreshing = false - } + return@setOnEditorActionListener true } + true +} - @RequiresApi(Build.VERSION_CODES.O) - override fun observeViewModel() { - with(viewModel) { - salesList.observe(viewLifecycleOwner, Observer { - createSaleList(it) - }) +hideKeyboards() - responseItemShelvingUpdate.observe(viewLifecycleOwner, Observer { +//LISTA ========= +binding.collectionSwipe.setOnRefreshListener { - if (!goBack) { - if (it.isError) { + if (::sales.isInitialized) { + sales.clear() + saleAdapter!!.notifyDataSetChanged() + } + searchSaleCollection() + binding.collectionSwipe.isRefreshing = false +} +} - ma.messageWithSound(it.errorMessage, it.isError, false) +@RequiresApi(Build.VERSION_CODES.O) +override fun observeViewModel() { + with(viewModel) { + salesList.observe(viewLifecycleOwner, Observer { + createSaleList(it) + }) - } else { - saleTrackingReplace(positionUnmarked) - setTotalLines() - goBack = false - } + responseItemShelvingUpdate.observe(viewLifecycleOwner, Observer { - } - }) - - placementSuppleyList.observe(viewLifecycleOwner, Observer { - if (!goBack) printShelvingResult(it) - goBack = false - }) - - responseIncQuantity.observe(viewLifecycleOwner, Observer { - - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - } else { - incresaseSuccesful() - setTotalLines() - } - } - goBack = false - }) - - - responseParkingAdd.observe(viewLifecycleOwner, Observer { + if (!goBack) { if (it.isError) { - ma.messageWithSound(it.errorMessage, true, false) + + ma.messageWithSound(it.errorMessage, it.isError, false) } else { - if (mpok != null) mpok!!.start() - getString(R.string.saleParked).toast(requireContext()) - } - }) - - responseSaleTrackingUpdate.observe(viewLifecycleOwner, Observer { - - ma.messageWithSound(it.errorMessage, isError = it.isError, true) - - try { - sales.clear() - } catch (e: Exception) { - - } - - }) - - responseSplit.observe(viewLifecycleOwner, Observer { - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - - } else { - // responseSaleMoveSuccesful() - ma.messageWithSound(getString(R.string.splitOk), isError = false, true) - setTotalLines() - } + saleTrackingReplace(positionUnmarked) + setTotalLines() goBack = false } - }) - loadResponseSaleGropAdd.observe(viewLifecycleOwner) { event -> - event.getContentIfNotHandled().notNull { + } + }) - if (!goBack) { - if (it.isError) { - ma.messageWithSound( - getString(R.string.errorTicketAdd) + it.errorMessage, - isError = true, - true, - isToasted = true - ) + placementSuppleyList.observe(viewLifecycleOwner, Observer { + if (!goBack) printShelvingResult(it) + goBack = false + }) - } else { - viewModel.sectorCollectionGetSale( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) - ) + responseIncQuantity.observe(viewLifecycleOwner, Observer { + + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + } else { + incresaseSuccesful() + setTotalLines() + } + } + goBack = false + }) + + + responseParkingAdd.observe(viewLifecycleOwner, Observer { + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + + } else { + if (mpok != null) mpok!!.start() + getString(R.string.saleParked).toast(requireContext()) + } + }) + + responseSaleTrackingUpdate.observe(viewLifecycleOwner, Observer { + + ma.messageWithSound(it.errorMessage, isError = it.isError, true) + + try { + sales.clear() + } catch (e: Exception) { + + } + + }) + + responseSplit.observe(viewLifecycleOwner, Observer { + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + + } else { + // responseSaleMoveSuccesful() + ma.messageWithSound(getString(R.string.splitOk), isError = false, true) + setTotalLines() + } + goBack = false + } + }) + + loadResponseSaleGropAdd.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + if (!goBack) { + if (it.isError) { + ma.messageWithSound( + getString(R.string.errorTicketAdd) + it.errorMessage, + isError = true, + true, + isToasted = true + ) + + } else { + viewModel.sectorCollectionGetSale( + collection.collectionFk, + mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) + ) + } + } + } + } + + + responseSaleAddPrevOK.observe(viewLifecycleOwner, Observer { + + 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 { + + 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 { + + 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 { + + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + searchSaleCollection() + } + } + goBack = false + + }) + + responseCode.observe(viewLifecycleOwner, Observer { + + 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 - responseSaleAddPrevOK.observe(viewLifecycleOwner, Observer { + }) + } +} - if (!goBack) { - if (it.isError) { - ma.messageWithSound( - getString(R.string.errorChangeState) + it.errorMessage, - isError = true, - true - ) +private fun responseSaleMoveSuccesful() { - } else { - ma.messageWithSound(getString(R.string.previousOK), isError = false, false) + try { + sales[positionCollectionSplit].saldo = quantityCollectionSplit.toInt() + } catch (e: Exception) { + sales[positionCollectionSplit].saldo = 0 + } + //sales[position].startQuantity = quantity - } - } - goBack = false - }) - response.observe(viewLifecycleOwner, Observer { + if (quantityCollectionSplit == 0) + markLine(positionCollectionSplit) + saleAdapter!!.notifyDataSetChanged() - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) +} - } else { - ma.messageWithSound(getString(R.string.previousOK), isError = false, false) +private fun incresaseSuccesful() { - } - } - goBack = false - }) - responseSaleupdateIsChecked.observe(viewLifecycleOwner, Observer { - - - 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 { - - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - searchSaleCollection() - } - } - goBack = false - - }) - - responseCode.observe(viewLifecycleOwner, Observer { - - 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 - - }) - } + try { + sales[positionIncreaseQuantity].saldo = quantityIncrease.toInt() + } catch (e: Exception) { + sales[positionIncreaseQuantity].saldo = 0 } - private fun responseSaleMoveSuccesful() { + saleAdapter?.notifyDataSetChanged() - try { - sales[positionCollectionSplit].saldo = quantityCollectionSplit.toInt() - } catch (e: Exception) { - sales[positionCollectionSplit].saldo = 0 - } - //sales[position].startQuantity = quantity + searchSaleCollection() - 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() { - - viewModel.sectorCollectionGetSale( - collection.collectionFk, - sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) +private fun searchSaleCollection() { + + viewModel.sectorCollectionGetSale( + collection.collectionFk, + sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) + ) +} + +private fun searchTicket(ticketFk: Int) { + + ticket = ticketFk + + if (ticketFk != 0) + viewModel.sectorCollectionSaleGroupAdd( + ticketFk, + collection.collectionFk ) - } +} - private fun searchTicket(ticketFk: Int) { +private fun addSaleGroupToCollection(ticketFk: Int) { - ticket = ticketFk + ticket = ticketFk - if (ticketFk != 0) - viewModel.sectorCollectionSaleGroupAdd( - ticketFk, - collection.collectionFk - ) - } + if (ticketFk != 0) + viewModel.sectorCollectionSaleGroupAdd( + ticketFk, + collection.collectionFk + ) +} - private fun createSaleList(salesList: List) { +private fun createSaleList(salesList: List) { - if (salesList.isNullOrEmpty()) { + if (salesList.isNullOrEmpty()) { - ma.messageWithSound( - getString(R.string.scanTicketsForAdd), - false, - false, - getString(R.string.titlePrePicker), isToasted = true - ) + 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 - } + } else { if (ticket == 0) { binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() } + sales = ArrayList() - binding.mainToolbar.toolbarSubtitle.text = "" + totalMark + "/" + sales.size - if (totalMark == sales.size) { - getString(R.string.ticketCompleted).toast(this.context, Toast.LENGTH_SHORT) - viewModel.saleTrackingAddPrevOK( - sectorCollectionFk = collection.collectionFk - ) - + salesList.forEach { + sales.add(it) } - } + //sergio: se tiene que ordenar por el pickingOrder del primer carro (Pako) - private fun setListPosition(position: Int) { - storedPosition = position - binding.fragmentSacadorCollections.addViewObserver { - lm!!.scrollToPositionWithOffset(position, 0) + 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) - //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 + saleAdapter = PreSacadorAdapter( + sales, + pasillerosItemClickListener!!, + object : OnQuantityClickListener { + override fun onQuantityClick(sale: SaleVO) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.idMovimiento == sale.saleFk) { + showQuantityDialog(index) + } } - shelvingIndex += 1 } - if (isBreak) break - } - index += 1 - } - if (!isOk) { - if (mperror != null) { - mperror!!.start() - } - (getString(R.string.itemScanetNotFound) + txtscan).toast(requireContext()) + }, + 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) + viewModel.saleTrackingAddPrevOK( + sectorCollectionFk = collection.collectionFk + ) } - private fun findSale(txtscan: String, position: Int) { - var index = 0 - var isBreak = false - var isOk = false +} - val saleVO = sales[position] +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 + + for (saleVO in sales) { if (saleVO.quantity != saleVO.picked) { //1- Por carro var shelvingIndex = 0 @@ -599,409 +571,443 @@ class EndSacadorFragment( if (txtscan.uppercase() == placementVO.shelving.uppercase()) { if (mpok != null) mpok!!.start() isOk = true - showShelving(position, shelvingIndex) + 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()) + } - if (!isOk) { - if (mperror != null) { - mperror!!.start() +} + +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 } - ("getString(R.string.itemScanetNotFound)" + txtscan).toast(requireContext()) + shelvingIndex += 1 } + } + index += 1 + + if (!isOk) { + if (mperror != null) { + mperror!!.start() + } + ("getString(R.string.itemScanetNotFound)" + txtscan).toast(requireContext()) } - private fun markLine(position: Int) { +} - saleAdapter!!.notifyDataSetChanged() - setListPosition(position) - saleTrackingReplace(position) - setTotalLines() - } +private fun markLine(position: Int) { - private fun saleTrackingReplace(position: Int) { + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + saleTrackingReplace(position) + setTotalLines() +} - if (sales[position].picked == sales[position].quantity || sales[position].picked == 0) { +private fun saleTrackingReplace(position: Int) { - viewModel.saleTrackingUpdateIsChecked( - vSaleFk = sales[position].idMovimiento, - vIsChecked = sales[position].picked == sales[position].quantity, - vIsScanned = isScanned + 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 - 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 - 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 ) } - @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)) - } + isScanned = null +} - customDialogList.setTitle("$shelving($item) $total del $longName") - .setOkButton(getString(R.string.take)) { - isScanned = false +private fun unMarkLine(position: Int) { - if (customDialogList.getValueTwo().isNotEmpty()) { - /*Tarea 5109*/ - try { - customDialogList.setValueTwo( - itemScanValue( - customDialogList.getValueTwo(), - "buy", - "more" - ).toString() - ) + 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 (checkItemScan(customDialogList.getValueTwo())) { - onQuantityOfShelvingSelected(itemShelvingFk) - mpok?.start() - customDialogList.dismiss() - } else { - itemShelvingFkStored = itemShelvingFk - 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)) { + viewModel.itemShelving_updateFromSale( + saleFk = sales[position].idMovimiento + ) + positionUnmarked = position 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 - viewModel.getIdFromCode( - code = customDialogList.getValueTwo() - ) - customDialogList.dismiss() - } - } else { - getString(R.string.scanItemValidate).toast(requireContext()) - } - } catch (Ex: Exception) { - ma.messageWithSound(Ex.message.toString(), true, true) - - } - scanRequest() - hideKeyboards() - return@setOnEditorActionListener true - - } - 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 - } - } - - } - }, 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) + customDialog.dismiss() }.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 - } - false - } - - } - - private fun customDialogInputAction(index: Int) { - if (!customDialogInput.getValue().isNullOrEmpty()) { - findSale(customDialogInput.getValue(), index) - customDialogInput.setValue("") - scanRequest() - customDialogInput.dismiss() - 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) - - } - - //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() - } - - 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 - 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)) { + scanRequest() customDialog.dismiss() }.show() } - private fun showQuantityDialog(position: Int) { - try { - customDialogThreeButtons.setDescription(getString(R.string.itemSaleQuantity)) - .setValue("") - .setOkButtonAdd(getString(R.string.Agregar)) { - increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) - scanRequest() - customDialogThreeButtons.dismiss() +} - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialogThreeButtons.dismiss() - }.show() - customDialogThreeButtons.setFocusDialogValue() - } catch (ex: Exception) { - getString(R.string.errorQuantity).toast(context) - } +//SHELVINGS +private fun showShelving(position: Int, shelvingPosition: Int) { + storedShelvingPosition = shelvingPosition + storedPosition = position + 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 + ) +} + +@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 increaseQuantity(position: Int, quantity: Int) { - positionIncreaseQuantity = position - quantityIncrease = quantity + customDialogList.setTitle("$shelving($item) $total del $longName") + .setOkButton(getString(R.string.take)) { + isScanned = false - viewModel.collectionIncreaseQuantity( - saleFk = sales[position].idMovimiento, - quantity = quantity + if (customDialogList.getValueTwo().isNotEmpty()) { + /*Tarea 5109*/ + try { + customDialogList.setValueTwo( + itemScanValue( + customDialogList.getValueTwo(), + arrayOf("buy"), + "more" + ).toString() + ) + + + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + 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() + 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(), + arrayOf("buy"), + "id" + ).toString() + ) + originalItemScan = customDialogList.getValueTwo() + + + if (customDialogList.getValueTwo().isNotEmpty()) { + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + viewModel.getIdFromCode( + code = customDialogList.getValueTwo() + ) + customDialogList.dismiss() + } + } else { + getString(R.string.scanItemValidate).toast(requireContext()) + } + } catch (Ex: Exception) { + ma.messageWithSound(Ex.message.toString(), true, true) + + } + scanRequest() + hideKeyboards() + return@setOnEditorActionListener true + + } + 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 + } + } + + } + }, 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 + } + false } } + +private fun customDialogInputAction(index: Int) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(), index) + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + 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) + + } + + //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() +} + +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 + 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.itemSaleQuantity)) + .setValue("") + .setOkButtonAdd(getString(R.string.Agregar)) { + increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) + scanRequest() + customDialogThreeButtons.dismiss() + + }.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 + ) + +} + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/InitPreSacadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/InitPreSacadorFragment.kt index 510b60e2..fedf5a8b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/InitPreSacadorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/InitPreSacadorFragment.kt @@ -2,12 +2,10 @@ package es.verdnatura.presentation.view.feature.presacador.fragment import android.content.Context import android.graphics.drawable.Drawable -import android.os.Build import android.text.InputType import android.view.View import android.view.inputmethod.EditorInfo import android.widget.ImageView -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R import es.verdnatura.databinding.FragmentSacadorBinding @@ -78,13 +76,9 @@ class InitPreSacadorFragment( iconPrint.setImageResource(R.drawable.ic_print_black_24dp) iconAdd.setImageResource(R.drawable.ic_add_black_24dp) - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp) iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) - } listIcons.add(iconAdd) binding.mainToolbar.toolbarIcons.adapter = @@ -165,15 +159,15 @@ class InitPreSacadorFragment( with(viewModel) { - collectionList.observe(viewLifecycleOwner, Observer { + collectionList.observe(viewLifecycleOwner) { if (!goBack2) createCollectionList(it.list) goBack2 = false - }) + } - response.observe(viewLifecycleOwner, Observer { + response.observe(viewLifecycleOwner) { if (goBack) addCollectionToList(it.response.toInt()) goBack = false - }) + } } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt index 748b43a8..fde8733d 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt @@ -79,7 +79,7 @@ class AutomaticAddItemFragment( 0, itemScanValue( textScanned_filterDouble(binding.editMatricula.text.toString()), - "buy", + arrayOf("buy"), "more" ).toString().toLong()