diff --git a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt index a443f024..85ab9158 100644 --- a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt +++ b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt @@ -8,6 +8,7 @@ object ConstAndValues { const val ON_PREPARATION = "ON_PREPARATION" const val PRESACADOR = "PRESACADOR" //PREITEMPICKER const val PREITEMPICKER = "PREITEMPICKER" + const val PREITEMPICKERTEST = "PREITEMPICKERTEST" const val SERIALNUMBER = "SERIALNUMBER" const val ON_CHECKING = "ON_CHECKING" const val PRECHECKER = "PRECHECKER" 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 7769f1d4..a56f3481 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 @@ -2,14 +2,10 @@ package es.verdnatura.presentation.view.feature.collection.fragment import android.app.AlertDialog import android.content.Context -import android.content.Intent import android.graphics.drawable.Drawable import android.media.MediaPlayer -import android.net.Uri -import android.os.Build import android.os.Bundle import android.text.InputType -import android.util.Log.d import android.view.KeyEvent import android.view.View import android.view.WindowManager @@ -17,8 +13,6 @@ import android.view.inputmethod.EditorInfo import android.widget.EditText import android.widget.ImageView import android.widget.Toast -import androidx.annotation.RequiresApi -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.gson.Gson @@ -64,7 +58,7 @@ import org.json.JSONObject class CollectionFragmentPickerNew( var collection: CollectionTicket, var type: String = SACADOR, - var hasPickingOrder: Boolean = false + private var hasPickingOrder: Boolean = false ) : BaseFragment( CollectionViewModel::class ) { @@ -107,11 +101,8 @@ class CollectionFragmentPickerNew( companion object { fun newInstance( - collection: CollectionTicket, - type: String, - hasPickingOrder: Boolean = false - ) = - CollectionFragmentPickerNew(collection, type, hasPickingOrder) + collection: CollectionTicket, type: String, hasPickingOrder: Boolean = false + ) = CollectionFragmentPickerNew(collection, type, hasPickingOrder) } override fun onAttach(context: Context) { @@ -143,7 +134,6 @@ class CollectionFragmentPickerNew( customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) customDialogThreeButtonsQuantity = CustomDialogThreeButtons(requireContext()) ma.hideBottomNavigation(View.GONE) - binding.splashProgress.visibility = View.VISIBLE setEvents() setToolBar() @@ -185,15 +175,13 @@ class CollectionFragmentPickerNew( val iconUpdate = ImageView(context) iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) - iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) - iconViewCollection.tooltipText = getTooltip(R.drawable.ic_collection) - iconPhone.tooltipText = getTooltip(R.drawable.phone_call) - iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) - iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) + iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) + iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) + iconViewCollection.tooltipText = getTooltip(R.drawable.ic_collection) + iconPhone.tooltipText = getTooltip(R.drawable.phone_call) + iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) + iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) - } listIcons.add(iconPrint) listIcons.add(iconAdd) listIcons.add(iconUpdate) @@ -229,16 +217,14 @@ class CollectionFragmentPickerNew( } private fun markPrevia(saleGroupScanned: String): Boolean { - println("Sacador saleGroup $saleGroupScanned ") + try { for (indice in sales.indices) { - println("Sacador saleGroup ${sales[indice].saleGroupFk}") if (sales[indice].saleGroupFk != null && sales[indice].saleGroupFk == saleGroupScanned.toInt()) { - println("Sacador saleGroup ${sales[indice].itemShelvingSaleFk}") viewModel.itemShelvingSaleSetSaleGroup(saleGroupScanned.toInt()) positionMarkPrevia = indice - return true mpok!!.start() + return true } } @@ -248,27 +234,6 @@ class CollectionFragmentPickerNew( return false } - /* private fun getCollection() { - binding.splashProgress.visibility = View.VISIBLE - if (!buttonPushedGetCollection) { - viewModel.collection_get( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), - print = "0", - type - ) - buttonPushedGetCollection = true - } else { - viewModel.collectionTicketGetSalix( - lastScanned, - print = false - - ) - buttonPushedGetCollection = false - } - lastScanned = collection.collectionFk - }*/ - private fun scanRequest() { binding.scanInput.requestFocus() hideKeyboards() @@ -293,7 +258,7 @@ class CollectionFragmentPickerNew( binding.scanInput.requestFocus() binding.scanInput.setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {//ID=0 ACTION_NEXT ID=5 ACTION_UNESPECEFIED) - if (!binding.scanInput.text.toString().isNullOrEmpty()) { + if (binding.scanInput.text.toString().isNotEmpty()) { binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) isScanned = event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER @@ -331,15 +296,7 @@ class CollectionFragmentPickerNew( binding.collectionSwipe.setOnRefreshListener { isMarking = false binding.collectionSwipe.isRefreshing = false - binding.splashProgress.visibility = View.VISIBLE - updateScreen() - /* viewModel.collectionTicketGet( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), - print = "0", - type - )*/ buttonPushedGetCollection = false binding.collectionSwipe.isRefreshing = false @@ -350,36 +307,17 @@ class CollectionFragmentPickerNew( try { requireActivity().hideKeyboard() } catch (e: Exception) { + e.toast(requireContext()) } } - @RequiresApi(Build.VERSION_CODES.O) override fun observeViewModel() { with(viewModel) { - binding.splashProgress.visibility = View.GONE - /* collectionTicketList.observe(viewLifecycleOwner, Observer { - if (!it.isError) { - if (it.tickets.isNotEmpty()) { - //collection = it - createCollectionList() - workerFkFromTicket = it.tickets.get(0).sales.get(0).workerFk - } else { - binding.mainToolbar.toolbarSubtitle.text = "0/0" - } - } else { - customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) - .setOkButton(getString(R.string.accept)) { - customDialog.dismiss() - if (activity != null) ma.onMyBackPressed() - }.show() - } - - })*/ loadCollectionTicketSalix.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { - binding.splashProgress.visibility = View.GONE + // if (!it.isError) { if (it.tickets.isNotEmpty()) { @@ -406,49 +344,22 @@ class CollectionFragmentPickerNew( } } - /* collectionTicketSalix.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE - if (!it.isError) { - - if (it.tickets.isNotEmpty()) { - collection = it - createCollectionList() - workerFkFromTicket = if (it.tickets[0].sales.isNotEmpty()) { - it.tickets[0].sales[0].workerFk.toString() - } else { - "" - } - - } else { - binding.mainToolbar.toolbarSubtitle.text = "0/0" - } - } else { - customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) - .setOkButton(getString(R.string.accept)) { - customDialog.dismiss() - if (activity != null) ma.onMyBackPressed() - }.show() - } - - })*/ - responseExistsItemShelvingSale.observe(viewLifecycleOwner, Observer { + responseExistsItemShelvingSale.observe(viewLifecycleOwner) { if (!goBack) { if (it.exists) { markLine(it.position, it.quantity, true) } else { - "Actualizando las líneas porque la reserva está modificada".toast( + getString(R.string.updateSalesReserve).toast( requireContext() ) viewModel.collectionTicketGetSalix(collection.collectionFk, false) } } - }) - responseParking.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + } + responseParking.observe(viewLifecycleOwner) { if (!goBack) { - binding.splashProgress.visibility = View.GONE ma.messageWithSound( if (it.isError) it.errorMessage else getString(R.string.Aparcado), it.isError, @@ -456,24 +367,23 @@ class CollectionFragmentPickerNew( ) } - }) + } - responseCollectionAddItem.observe(viewLifecycleOwner, Observer { + responseCollectionAddItem.observe(viewLifecycleOwner) { if (!goBack) { updateScreen() goBack = false } - }) + } - responsePrint.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + responsePrint.observe(viewLifecycleOwner) { if (!goBack) { if (it.isError) { ma.messageWithSound( - it.errorMessage, it.isError, true + it.errorMessage, isError = true, isPlayed = true ) } else { (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( @@ -484,16 +394,15 @@ class CollectionFragmentPickerNew( } } - }) + } - responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner) { if (it.isError) { ma.messageWithSound( - if (it.isError) it.errorMessage else getString(R.string.confirmReserv), - it.isError, - it.isError + it.errorMessage, + isError = true, + isPlayed = true ) } if (!it.isError) { @@ -505,36 +414,32 @@ class CollectionFragmentPickerNew( ) } - }) + } - responseItemShelvingSale.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + responseItemShelvingSale.observe(viewLifecycleOwner) { myGroupList[positionConfirm].isPicked = 1 myGroupList[positionConfirm].reservedQuantity = quantityConfirm viewModel.collectionTicketGetSalix( collection.collectionFk, print = false ) lm!!.scrollToPositionWithOffset(positionConfirm, 0) - //saleAdapter!!.notifyDataSetChanged() ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError + getString(R.string.operationSuccess), it.isError, !it.isError, isToasted = false ) - }) - responseItemShelvingSaleUnPicked.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + } + responseItemShelvingSaleUnPicked.observe(viewLifecycleOwner) { myGroupList[positionUnmarked].isPicked = 1 myGroupList[positionUnmarked].reservedQuantity = quantityConfirm viewModel.collectionTicketGetSalix( collection.collectionFk, print = false ) lm!!.scrollToPositionWithOffset(positionUnmarked, 0) - //saleAdapter!!.notifyDataSetChanged() ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError + getString(R.string.operationSuccess), it.isError, !it.isError, isToasted = false ) - }) - responseItemShelvingSaleGroup.observe(viewLifecycleOwner, Observer { + } + responseItemShelvingSaleGroup.observe(viewLifecycleOwner) { viewModel.collectionTicketGetSalix( collection.collectionFk, print = false @@ -542,12 +447,11 @@ class CollectionFragmentPickerNew( lm!!.scrollToPositionWithOffset(positionMarkPrevia, 0) ma.messageWithSound( - "Previa recogida", it.isError, !it.isError + getString(R.string.previousCollected), it.isError, !it.isError ) - }) + } - responseCode.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + responseCode.observe(viewLifecycleOwner) { if (!goBack2) { if (it.isError) { customDialog.setTitle(getString(R.string.error)) @@ -563,7 +467,6 @@ class CollectionFragmentPickerNew( mpok?.start() onQuantityOfShelvingSelected(itemShelvingFkStored) } else { - var value = customDialogList.getValueTwo() customDialogList.setValueTwo("") if (it.response.isBlank() || it.response.isEmpty()) { showErrorMessage(text = getString(R.string.codeNotExist)) @@ -580,30 +483,16 @@ class CollectionFragmentPickerNew( goBack2 = false - }) - - } - } - - private fun callPicker(extensionNumber: String) { - - try { - val intent = Intent(Intent.ACTION_DIAL).apply { - data = Uri.parse("tel:$extensionNumber") } - startActivity(intent) - } catch (e: Exception) { - // d("VERDNATURA::" + e.message) - } + } } private fun createCollectionList() { state = 0 binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() - binding.splashProgress.visibility = View.GONE collection.map(requireContext()) - var salesList: ArrayList = ArrayList() + val salesList: ArrayList = ArrayList() tickets = ArrayList() var observations = "" @@ -611,7 +500,7 @@ class CollectionFragmentPickerNew( val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_TO") collection.tickets.forEach { ticket -> - if (!observations.isNullOrEmpty()) observations = + if (observations.isNotEmpty()) observations = observations + " " + ticket.observations ticket.sales.forEach { sale -> @@ -627,11 +516,6 @@ class CollectionFragmentPickerNew( } sales = salesList.sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) - - for (s in sales) { - println("Sacador sale: ${s.saleFk} saleGRoup: ${s.saleGroupFk} item : ${s.itemFk}") - } - //quitar comentarios FALTA AGRUPAR LAS PREVIAS myGroupList = groupSaleGroup(salesList).sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) saleAdapter = SaleAdapterNew( @@ -646,10 +530,8 @@ class CollectionFragmentPickerNew( if (sale.isPicked == 1) { showErrorMessage( title = getString(R.string.info), - text = "Tienes que desmarcar la línea para poder modificar la cantidad" + text = getString(R.string.unmarkForModify) ) - } else { - // showQuantityDialog(index) } } @@ -658,34 +540,16 @@ class CollectionFragmentPickerNew( } }, object : OnSaleClickSaleListener { - override fun onSaleClick(mysale: Sale) { + override fun onSaleClick(mySale: Sale) { myGroupList.forEachIndexed { index, sale -> - //sales.forEachIndexed { index, sale -> - // println("Sacador la sale es ${sale.saleFk}") - // println("Sacador la sale picked es ${sale.isPicked}") - // println("Sacador la sale group es ${sale.saleGroupFk}") - // println("Sacador la sale reserved es ${sale.reservedQuantity}") - if (sale.itemShelvingSaleFk == 0) { - println("Sacador Que hacemos en este caso ?? ") - } else { - if (sale.itemShelvingSaleFk == mysale.itemShelvingSaleFk) { - println("Sacador **** itemShelvingSale es ${sale.itemShelvingSaleFk}") - println("Sacador **** isPicked es ${sale.isPicked}") - println("Sacador **** saleGroup es ${sale.saleGroupFk}") - //println("Sacador la sale es ${sale.saleFk}") - //println("Sacador la sale picked es ${sale.isPicked}") - //println("Sacador la sale group es ${sale.saleGroupFk}") - //println("Sacador la sale reserved es ${sale.reservedQuantity}") - //println("Sacador la sale dentro es ${sale.saleFk}") - if (sale.isPicked != 1 && sale.saleGroupFk == null) { - println("Sacador **** showScanner") - showScanner(index, sale) - } else { - println("Sacador **** desmarcar") - unMarkLine(index, myGroupList[index]) - } + if (sale.itemShelvingSaleFk == mySale.itemShelvingSaleFk) { + if (sale.isPicked != 1 && sale.saleGroupFk == null) { + showScanner(index, sale) + } else { + unMarkLine(index, myGroupList[index]) } + } } @@ -699,20 +563,18 @@ class CollectionFragmentPickerNew( object : OnPackingClickSaleListener { override fun onPackingClick(sale: Sale) { goBack = true - println("ubicador") if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener( PasillerosItemVO( title = getString(R.string.titleUbicator), - ), entryPoint = sale.code!! + ), entryPoint = sale.code ) } }, object : OnTicketClickSaleListener { override fun onTicketClickListener(sale: Sale) { - var entryPoint = Gson().toJson( + val entryPoint = Gson().toJson( mutableMapOf( - "entryPoint" to sale.ticketFk, - "web" to "${ + "entryPoint" to sale.ticketFk, "web" to "${ mobileApplication.dataStoreApp.readDataStoreKey( BASEURLSALIX ) @@ -735,7 +597,7 @@ class CollectionFragmentPickerNew( binding.fragmentSacadorCollections.layoutManager = lm setTotalLines() - setStoredPosition(true) + setListPosition() setScrollListener(lm!!) printObservations(observations) } @@ -767,13 +629,18 @@ class CollectionFragmentPickerNew( if (isOk) { //Se ha escanado un ticket y se ha marcado la previa + ma.messageWithSound( + getString(R.string.previousCollected), + isPlayed = false, + isError = false, + isToasted = true + ) } else { //Se busca la matricula en las lineas for (indice in myGroupList.indices) { if (myGroupList[indice].isPicked != 1 && myGroupList[indice].code != null && myGroupList[indice].code!!.uppercase() == txtscan.uppercase()) { mpok!!.start() isOk = true - positionMarkPrevia = indice printShelvingResult(indice) break } @@ -794,8 +661,6 @@ class CollectionFragmentPickerNew( } private fun findSale(txtscan: String, position: Int, sale: Sale) { - println("Sacador La position es $position") - println("Sacador El escaneado es $txtscan y el code ${sale.code}") storedPosition = position @@ -822,63 +687,19 @@ class CollectionFragmentPickerNew( myGroupList[position].itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty ) - //nuevo tema agrupacion sales - //checkStateParent() - // var mySale = sales[position].saleFk Ordenar setPosition - - var mySale = sales[position].itemShelvingSaleFk + val mySale = sales[position].itemShelvingSaleFk for (indice in myGroupList.indices) { if (!myGroupList[indice].isParent && myGroupList[indice].itemShelvingSaleFk == mySale) { - d("VERDNATURA::", "la pos del index de la sale es" + indice) storedBackPosition = indice } } - //setTotalLines() } - //Tarea #4371 - - private fun checkStateParent() { - for (s in myGroupList) { - if (s.isParent) { - var totalLines = s.sonSales.size - var isPreviousPrepared = s.sonSales.filter { it.semaphore == "1" }.size - var isPrepared = s.sonSales.filter { it.semaphore == "2" }.size - var isControlled = s.sonSales.filter { it.semaphore == "1" }.size - var isPreControlled = s.sonSales.filter { it.semaphore == "4" }.size/* if (totalLines == isPreviousPrepared) { - s.isPreviousPrepared = "1" - } else { - s.isPreviousPrepared = "0" - } - if (totalLines == isPrepared) { - s.isPrepared = "1" - } else { - s.isPrepared = "0" - } - if (totalLines == isControlled) { - s.isControlled = "1" - } else { - s.isControlled = "0" - } - if (totalLines == isPreControlled) { - s.isPreControlled = "1" - } else { - s.isPreControlled = "0" - } -*/ - - } - } - - } - - private fun setListPosition(position: Int, isFromBack: Boolean) { - d("VERDNATURA::", "Vamos a la pos" + storedBackPosition) + private fun setListPosition() { if (storedPosition == 0 && storedBackPosition == 0) { // se inicia lista, se busca porqué item vamos. for (indice in myGroupList.indices) { if (myGroupList[indice].isPicked == 0) { - //storedPosition = indice lm!!.scrollToPositionWithOffset(indice - 1, 0) break } @@ -897,19 +718,10 @@ class CollectionFragmentPickerNew( ) ).setOkButton(getString(R.string.unmark)) { if (!sale.isParent && sale.reservedQuantity == 0 && sale.originalQuantity != sale.saleQuantity) { - "No es posible desmarcar. Hablar con responsable almacén".toast(requireContext()) + getString(R.string.unmarkError).toast(requireContext()) } else { - /* saleAdapter!!.notifyDataSetChanged() - var mySale = sale.saleFk - for (indice in myGroupList.indices) { - if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { - d("VERDNATURA::", "la pos del index de la sale es" + indice) - storedBackPosition = indice - } - }*/ storedBackPosition = position - setListPosition(position, false) - + setListPosition() viewModel.itemShelvingSaleUnpicked(myGroupList[position].itemShelvingSaleFk) sale.isPicked = 0 positionUnmarked = position @@ -934,11 +746,11 @@ class CollectionFragmentPickerNew( customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) customDialogList.getEditTextTwo().requestFocus() - var shelving = myGroupList[pos].code - var item = myGroupList[pos].itemFk - var longName = myGroupList[pos].longName - var totalReserved = myGroupList[pos].reservedQuantity - var itemShelvingFk = myGroupList[pos].itemShelvingSaleFk + val shelving = myGroupList[pos].code + val item = myGroupList[pos].itemFk + val longName = myGroupList[pos].longName + val totalReserved = myGroupList[pos].reservedQuantity + val itemShelvingFk = myGroupList[pos].itemShelvingSaleFk try { customDialogList.setTitle("$shelving($item) $totalReserved de $longName").setOkButton( @@ -972,7 +784,7 @@ class CollectionFragmentPickerNew( false } } catch (e: Exception) { - ma.messageWithSound(e.message.toString(), true, true) + ma.messageWithSound(e.message.toString(), isError = true, isPlayed = true) } } @@ -988,7 +800,7 @@ class CollectionFragmentPickerNew( customDialogList.getValueTwo(), "buy", "more" ).toString() ) - var quantityToReserve = customDialogList.getValue().toInt() + val quantityToReserve = customDialogList.getValue().toInt() if (quantityToReserve < totalReserved) { @@ -997,8 +809,10 @@ class CollectionFragmentPickerNew( showQuestionUbicationEmpty(position, quantityToReserve) } else { ma.messageWithSound( - message = "Indique el item correctamente", isError = - true, isPlayed = true, isToasted = false + message = getString(R.string.errorItem), + isError = true, + isPlayed = true, + isToasted = false ) } } @@ -1010,11 +824,10 @@ class CollectionFragmentPickerNew( if (quantityToReserve == totalReserved) { originalItemScan = customDialogList.getValueTwo().toLong() - println("Sacador a checkItemScan") if (checkItemScan(customDialogList.getValueTwo())) { onQuantityOfShelvingSelected( - itemShelvingFk, quantityToReserve + quantityToReserve ) mpok?.start() @@ -1024,7 +837,6 @@ class CollectionFragmentPickerNew( } else { itemShelvingFkStored = itemShelvingFk - binding.splashProgress.visibility = View.VISIBLE viewModel.getIdFromCodeSalix( code = customDialogList.getValueTwo(), ) @@ -1037,17 +849,9 @@ class CollectionFragmentPickerNew( } } - private fun setStoredPosition(isFromBack: Boolean) { - setListPosition(storedBackPosition, isFromBack) - /*if (goBack) setListPosition(storedBackPosition, isFromBack) else { - setListPosition(storedPosition, isFromBack)*/ - } - private fun checkItemScan(valueToCheck: String): Boolean { - println("Sacador valor a checkear ${valueToCheck}") if (storedPosition >= 0 && sales.size > storedPosition) { val saleToCheck = myGroupList[storedPosition] - println("Sacador valor de la sale a checkear ${saleToCheck}") if (saleToCheck.itemFk.toString() == valueToCheck) return true else { saleToCheck.Barcodes.forEach { barcode -> @@ -1055,47 +859,40 @@ class CollectionFragmentPickerNew( } } } - - return false return false } //Tarea #4371 - private fun onQuantityOfShelvingSelected(itemShelvingFk: Int, quantity: Int = 0) { - println("Sacador $itemShelvingFk-$quantity")/* if (myGroupList[storedPosition].reservedQuantity == 0) { - showQuestionUbicationEmpty(storedPosition) - } else {*/ + private fun onQuantityOfShelvingSelected(quantity: Int = 0) { markLine(storedPosition, quantity, null) - // } } private fun showQuestionUbicationEmpty(position: Int, quantity: Int = 0) { - customDialogThreeButtonsQuantity.setTitle("Cambio de cantidad a $quantity del artículo ${sales[position].itemFk}") - .setDescription("¿Quedan unidades del artículo ${sales[position].itemFk} en el carro escaneado?") - .setValue("").setCustomDialogValue(View.GONE) - customDialogThreeButtonsQuantity.setOkButtonAdd("SI") { + customDialogThreeButtonsQuantity.setTitle( + getString( + R.string.changeQuantity, quantity, sales[position].itemFk + ) + ).setDescription(getString(R.string.questionItemShelving, sales[position].itemFk)) + .setValue("").setValue("").setCustomDialogValue(View.GONE) + customDialogThreeButtonsQuantity.setOkButtonAdd(getString(R.string.yes)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() - //markLine(position, quantity, false) - "No puedes seleccionar menos cantidad habiendo en el carro".toast(requireContext()) + getString(R.string.errorQuantityShelving).toast(requireContext()) customDialogThreeButtonsQuantity.dismiss() showQuestionUbicationEmpty(position, quantity) - }.setOkButtonTwo("NO") { + }.setOkButtonTwo(getString(R.string.no)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() if (quantity == 0) { viewModel.itemShelvingSaleExists( - myGroupList[position].itemShelvingSaleFk, - position, - quantity + myGroupList[position].itemShelvingSaleFk, position, quantity ) } else { markLine(position, quantity, true) } - //markLine(position, quantity, true) - }.setKoButton("CANCELAR") { + }.setKoButton(getString(R.string.cancel)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() }.show() @@ -1145,7 +942,7 @@ class CollectionFragmentPickerNew( customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - if (!customDialogList.getValue().isNullOrEmpty()) { + if (customDialogList.getValue().isNotEmpty()) { try { customDialogList.setValue( itemScanValue( @@ -1154,7 +951,7 @@ class CollectionFragmentPickerNew( ) } catch (e: Exception) { - ma.messageWithSound(e.message.toString(), true, true) + ma.messageWithSound(e.message.toString(), isError = true, isPlayed = true) } customDialogList.getEditTextTwo().requestFocus() } @@ -1194,11 +991,11 @@ class CollectionFragmentPickerNew( private fun customDialogAddItem() { - if (!customDialogList.getValueTwo().isNullOrEmpty()) { + if (customDialogList.getValueTwo().isNotEmpty()) { if (ticketSelected == 0) { getString(R.string.Seleccionaunticketdelaista).toast(requireContext()) - } else if (customDialogList.getValue().isNullOrEmpty() || customDialogList.getValueTwo() - .isNullOrEmpty() + } else if (customDialogList.getValue().isEmpty() || customDialogList.getValueTwo() + .isEmpty() ) { getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { @@ -1219,7 +1016,7 @@ class CollectionFragmentPickerNew( } private fun toastDisponibility(item: ItemVO) { - if (item.available.isNullOrEmpty()) { + if (item.available.isEmpty()) { item.available = "0" } customDialog.setTitle(getString(R.string.itemPoints) + item.id) @@ -1236,27 +1033,24 @@ class CollectionFragmentPickerNew( var totalMark = 0 sales.forEach { if (it.isPicked == 1) { - totalMark += 1/* } else if (it.reservedQuantity == 0) { - totalMark += 1*/ + totalMark += 1 } } - if (binding.mainToolbar.toolbarTitle != null) binding.mainToolbar.toolbarTitle.text = + binding.mainToolbar.toolbarTitle.text = if (collection.collectionFk != 0) collection.collectionFk.toString() else "" var total = sales.size - var totalParents = sales.filter { it.isParent }.size - total = total - totalParents + val totalParents = sales.filter { it.isParent }.size + total -= totalParents - if (binding.mainToolbar.toolbarSubtitle != null && totalMark != null) binding.mainToolbar.toolbarSubtitle.text = - "" + totalMark + "/" + total + binding.mainToolbar.toolbarSubtitle.text = + getString(R.string.totalsPicker, totalMark, total) if (totalMark == sales.size) { getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) saleAdapter!!.notifyDataSetChanged() - - changeTicketState() } @@ -1290,7 +1084,7 @@ class CollectionFragmentPickerNew( } private fun findSaleAction(index: Int, sale: Sale) { - if (!customDialogInput.getValue().isNullOrEmpty()) { + if (customDialogInput.getValue().isNotEmpty()) { findSale(customDialogInput.getValue(), index, sale) } closeCustomDialog(binding.scanInput, customDialogInput) @@ -1311,10 +1105,9 @@ class CollectionFragmentPickerNew( } private fun showDialogLabelCount() { - //tarea#4672 var isTicket = false for (t in collection.tickets) { - if (t.ticketFk.toInt() == (collection.collectionFk)) { + if (t.ticketFk == (collection.collectionFk)) { isTicket = true } } @@ -1342,19 +1135,9 @@ class CollectionFragmentPickerNew( } - fun isNumber(num: String): Boolean { - var numberInt = 0 - try { - numberInt = num.toInt() - return true - } catch (e: Exception) { - return false - } - } - private fun groupSaleGroup(salesList: ArrayList): MutableList { - var myMap = salesList.groupBy { it.saleGroupFk } - var myList: MutableList = mutableListOf() + val myMap = salesList.groupBy { it.saleGroupFk } + val myList: MutableList = mutableListOf() for ((key, value) in myMap.entries) { if (key == null) { // si no tiene saleGroup se añaden las líneas @@ -1362,14 +1145,13 @@ class CollectionFragmentPickerNew( myList.add(s) } } else { // si tiene saleGroup se crea el padre con el tamaño e indicando que es padre, como ejemplo se toma el primer elemento - /*crea padre*/ if (value.size > 1) { - var mySale = //= value[0] + val mySale = //= value[0] Sale( level = value[0].level, isPicked = value[0].isPicked, - parkingCode = "Líneas : ${value.size}", + parkingCode = getString(R.string.linesSaelGroup, value.size), pickingOrder = value[0].pickingOrder, workerFk = value[0].workerFk, originalQuantity = value[0].originalQuantity, @@ -1392,10 +1174,7 @@ class CollectionFragmentPickerNew( mySale.isParent = true value as MutableList mySale.sonSales = - value.sortedWith(compareBy { it.isPicked }) as MutableList/*mySale.line1 = "Previa :${mySale.saleGroupFk}" - mySale.line2 = "Líneas: ${value.size}" - mySale.line3 = value[0].code*/ - // mySale.placements = listOf(PlacementVO(shelving = value[0].code!!)) + value.sortedWith(compareBy { it.isPicked }) as MutableList myList.add(mySale) } else { 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 new file mode 100644 index 00000000..9be64633 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt @@ -0,0 +1,1265 @@ +package es.verdnatura.presentation.view.feature.collection.fragment + +import android.app.AlertDialog +import android.content.Context +import android.graphics.drawable.Drawable +import android.media.MediaPlayer +import android.os.Bundle +import android.text.InputType +import android.view.KeyEvent +import android.view.View +import android.view.WindowManager +import android.view.inputmethod.EditorInfo +import android.widget.EditText +import android.widget.ImageView +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.google.gson.Gson +import es.verdnatura.R +import es.verdnatura.databinding.FragmentCollectionNewBinding +import es.verdnatura.domain.ConstAndValues.BASEURLSALIX +import es.verdnatura.domain.ConstAndValues.PRINTERNAME +import es.verdnatura.domain.ConstAndValues.SACADOR +import es.verdnatura.domain.notNull +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.ItemScanned +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.OnMistakeClickListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnPackingClickSaleListener +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.OnQuantityClickSaleListener +import es.verdnatura.presentation.common.OnSaleClickSaleListener +import es.verdnatura.presentation.common.OnTicketClickSaleListener +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +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 +import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.component.CustomDialogThreeButtons +import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO +import es.verdnatura.presentation.view.feature.collection.ItemVO +import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapterNew +import es.verdnatura.presentation.view.feature.collection.mapper.map +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket +import es.verdnatura.presentation.view.feature.sacador.model.Sale +import es.verdnatura.presentation.view.feature.sacador.model.SaleVO +import org.json.JSONObject + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class CollectionFragmentPickerPreviousNew( + var collection: CollectionTicket, + var type: String = SACADOR, + private var hasPickingOrder: Boolean = false +) : BaseFragment( + CollectionViewModel::class +) { + private var sales: List = listOf() + private var salesParent: List = listOf() + private var saleAdapter: SaleAdapterNew? = null + private var lm: LinearLayoutManager? = null + private var storedPosition: Int = 0 + private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null + private lateinit var customDialogList: CustomDialogList + private var placementSupplyAdapter: BarcodeAdapter? = null + private var listPlacementSupply: ArrayList = ArrayList() + private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialogThreeButtons: CustomDialogThreeButtons + private lateinit var customDialogThreeButtonsQuantity: CustomDialogThreeButtons + private var ticketSelected: Int = 0 + private lateinit var customDialog: CustomDialog + private var goBack: Boolean = false + private var goBack2: Boolean = false + private var goMistakeBack: Boolean = false + var mperror: MediaPlayer? = null + var mpok: MediaPlayer? = null + private var itemShelvingFkStored: Int = 0 + private var storedBackPosition: Int = 0 + private var tickets: ArrayList = ArrayList() + private var mistakeSale: SaleVO? = null + private var isMarking = false + private lateinit var ticketScanTxt: String + private var lastScanned: Int = 0 + private var buttonPushedGetCollection = false + private var positionUnmarked = -1 + private var state = 0 + private var originalItemScan: Long = 0 + private var workerFkFromTicket: String? = null + private var isScanned: Boolean? = null + private var positionConfirm = 0 + private var quantityConfirm = 0 + private var positionMarkPrevia = 0 + private lateinit var myGroupList: List + private var quantityReserveToCheckItemScan = 0 + + companion object { + fun newInstance( + collection: CollectionTicket, type: String, hasPickingOrder: Boolean = false + ) = CollectionFragmentPickerPreviousNew(collection, type, hasPickingOrder) + } + + override fun onAttach(context: Context) { + if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context + super.onAttach(context) + } + + override fun getLayoutId(): Int = R.layout.fragment_collection_new + + override fun onCreate(savedInstanceState: Bundle?) { + + mperror = MediaPlayer.create((activity as MainActivity), R.raw.error) + mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok) + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + super.onCreate(savedInstanceState) + } + + override fun onResume() { + super.onResume() + scanRequest() + } + + override fun init() { + customDialogList = CustomDialogList(requireContext()) + customDialogInput = CustomDialogInput(requireContext()) + customDialog = CustomDialog(requireContext()) + customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) + customDialogThreeButtonsQuantity = CustomDialogThreeButtons(requireContext()) + ma.hideBottomNavigation(View.GONE) + + setEvents() + setToolBar() + + super.init() + } + + override fun onPause() { + super.onPause() + goBack = true + goBack2 = true + goMistakeBack = true + } + + private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = View.VISIBLE + binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE + binding.mainToolbar.backButton.visibility = View.VISIBLE + collection.collectionFk.let { + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + } + + val listIcons: ArrayList = ArrayList() + val iconPrint = ImageView(context) + iconPrint.setImageResource(R.drawable.ic_print_black_24dp) + val iconAdd = ImageView(context) + iconAdd.setImageResource(R.drawable.ic_playlist_add_black_24dp) + val iconViewCollection = ImageView(context) + iconViewCollection.setImageResource(R.drawable.ic_collection) + val iconWorker = ImageView(context) + iconWorker.setImageResource(R.drawable.ic_worker) + val iconPhone = ImageView(context) + iconPhone.setImageResource(R.drawable.phone_call) + val iconParking = ImageView(context) + iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) + val iconUpdate = ImageView(context) + iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp) + + iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) + iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) + iconViewCollection.tooltipText = getTooltip(R.drawable.ic_collection) + iconPhone.tooltipText = getTooltip(R.drawable.phone_call) + iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) + iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) + + // listIcons.add(iconPrint) + listIcons.add(iconAdd) + listIcons.add(iconParking) + listIcons.add(iconUpdate) + // listIcons.remove(iconWorker) + + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + + when (item) { + //iconViewCollection.drawable -> getCollection() + iconPrint.drawable -> print() + iconAdd.drawable -> addItem() + iconWorker.drawable -> showUser() + iconUpdate.drawable -> updateScreen() + iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( + PasillerosItemVO( + title = getString(R.string.Parking) + ), "" + ) + } + + } + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun updateScreen() { + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + } + + private fun markPrevia(saleGroupScanned: String): Boolean { + println("Sacador saleGroup $saleGroupScanned ") + try { + for (indice in sales.indices) { + println("Sacador saleGroup ${sales[indice].saleGroupFk}") + if (sales[indice].saleGroupFk != null && sales[indice].saleGroupFk == saleGroupScanned.toInt()) { + println("Sacador saleGroup ${sales[indice].itemShelvingSaleFk}") + viewModel.itemShelvingSaleSetSaleGroup(saleGroupScanned.toInt()) + positionMarkPrevia = indice + mpok!!.start() + return true + + + } + } + } catch (ex: Exception) { + return false + } + return false + } + + private fun scanRequest() { + binding.scanInput.requestFocus() + hideKeyboards() + } + + private fun showUser() { + + ma.onPasillerosItemClickListener( + PasillerosItemVO(title = getString(R.string.titleUserControlVehicle)), + workerFkFromTicket.toString() + ) + + } + + private fun setEvents() { + + binding.mainToolbar.backButton.setOnClickListener { + ma.onMyBackPressed() + } + //ESCANER ========= + + binding.scanInput.requestFocus() + binding.scanInput.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {//ID=0 ACTION_NEXT ID=5 ACTION_UNESPECEFIED) + if (binding.scanInput.text.toString().isNotEmpty()) { + binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) + isScanned = + event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + if (itemScanIsQr(binding.scanInput.text.toString())) { + val myQr = ItemScanned(JSONObject(binding.scanInput.text.toString())) + when (myQr.table) { + "saleGroup" -> {/* if (type == CONTROLADOR) { + markPrevia(myQr.id.toString()) + } else {*/ + binding.scanInput.setText(myQr.id.toString()) + //findSale(binding.scanInput.text.toString()) + // } + } + + "buy" -> binding.scanInput.setText(myQr.more) + } + + } else { + ma.hideKeyboard(binding.scanInput) + findSale(binding.scanInput.text.toString()) + } + buttonPushedGetCollection = false + } + binding.scanInput.setText("") + hideKeyboards() + return@setOnEditorActionListener true + } + true + } + + hideKeyboards() + + //LISTA ========= + binding.collectionSwipe.setOnRefreshListener { + isMarking = false + binding.collectionSwipe.isRefreshing = false + + updateScreen()/* viewModel.collectionTicketGet( + collection.collectionFk, + mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), + print = "0", + type + )*/ + buttonPushedGetCollection = false + binding.collectionSwipe.isRefreshing = false + + } + } + + private fun hideKeyboards() { + try { + requireActivity().hideKeyboard() + } catch (e: Exception) { + println(e.message) + } + } + + override fun observeViewModel() { + + with(viewModel) { + + /* collectionTicketList.observe(viewLifecycleOwner, Observer { + if (!it.isError) { + if (it.tickets.isNotEmpty()) { + //collection = it + createCollectionList() + workerFkFromTicket = it.tickets.get(0).sales.get(0).workerFk + + } else { + binding.mainToolbar.toolbarSubtitle.text = "0/0" + } + } else { + customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) + .setOkButton(getString(R.string.accept)) { + customDialog.dismiss() + if (activity != null) ma.onMyBackPressed() + }.show() + } + + })*/ + loadCollectionTicketSalix.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + if (!it.isError) { + + if (it.tickets.isNotEmpty()) { + collection = it + createCollectionList() + workerFkFromTicket = if (it.tickets[0].sales.isNotEmpty()) { + it.tickets[0].sales[0].workerFk.toString() + } else { + "" + } + + } else { + binding.mainToolbar.toolbarSubtitle.text = "0/0" + } + } else { + customDialog.setTitle(getString(R.string.error)) + .setDescription(it.errorMessage) + .setOkButton(getString(R.string.accept)) { + customDialog.dismiss() + if (activity != null) ma.onMyBackPressed() + }.show() + } + + } + } + + /* collectionTicketSalix.observe(viewLifecycleOwner, Observer { + + if (!it.isError) { + + if (it.tickets.isNotEmpty()) { + collection = it + createCollectionList() + workerFkFromTicket = if (it.tickets[0].sales.isNotEmpty()) { + it.tickets[0].sales[0].workerFk.toString() + } else { + "" + } + + } else { + binding.mainToolbar.toolbarSubtitle.text = "0/0" + } + } else { + customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) + .setOkButton(getString(R.string.accept)) { + customDialog.dismiss() + if (activity != null) ma.onMyBackPressed() + }.show() + } + + })*/ + responseExistsItemShelvingSale.observe(viewLifecycleOwner) { + if (!goBack) { + if (it.exists) { + markLine(it.position, it.quantity, true) + } else { + getString(R.string.updateSalesReserve).toast( + requireContext() + ) + viewModel.collectionTicketGetSalix(collection.collectionFk, false) + } + } + + } + responseParking.observe(viewLifecycleOwner) { + if (!goBack) { + ma.messageWithSound( + if (it.isError) it.errorMessage else getString(R.string.Aparcado), + it.isError, + true + ) + } + + } + + responseCollectionAddItem.observe(viewLifecycleOwner) { + if (!goBack) { + updateScreen() + goBack = false + } + + } + + responsePrint.observe(viewLifecycleOwner) { + + if (!goBack) { + + if (it.isError) { + ma.messageWithSound( + it.errorMessage, isError = true, true + ) + } else { + (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( + PRINTERNAME + )).toast( + requireContext() + ) + } + } + + } + + responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner) { + + + if (it.isError) { + ma.messageWithSound( + it.errorMessage, isError = true, true + ) + } + if (!it.isError) { + myGroupList[positionConfirm].isPicked = 1 + saleAdapter!!.notifyDataSetChanged() + lm!!.scrollToPositionWithOffset(storedBackPosition+1, 0) + /* viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + )*/ + } + + } + + + responseItemShelvingSale.observe(viewLifecycleOwner) { + + myGroupList[positionConfirm].isPicked = 1 + myGroupList[positionConfirm].reservedQuantity = quantityConfirm + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + lm!!.scrollToPositionWithOffset(positionConfirm, 0) + //saleAdapter!!.notifyDataSetChanged() + ma.messageWithSound( + "Confirmada acción", it.isError, !it.isError + ) + } + responseItemShelvingSaleUnPicked.observe(viewLifecycleOwner) { + + myGroupList[positionUnmarked].isPicked = 1 + myGroupList[positionUnmarked].reservedQuantity = quantityConfirm + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + lm!!.scrollToPositionWithOffset(positionUnmarked, 0) + //saleAdapter!!.notifyDataSetChanged() + ma.messageWithSound( + "Confirmada acción", it.isError, !it.isError + ) + } + responseItemShelvingSaleGroup.observe(viewLifecycleOwner) { + + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + lm!!.scrollToPositionWithOffset(positionMarkPrevia, 0) + + ma.messageWithSound( + "Previa recogida", it.isError, !it.isError + ) + } + + responseCode.observe(viewLifecycleOwner) { + + if (!goBack2) { + if (it.isError) { + customDialog.setTitle(getString(R.string.error)) + .setDescription(it.errorMessage) + .setKoButton(getString(R.string.close)) { + customDialog.dismiss() + scanRequest() + }.show() + } else { + if (checkItemScan(it.response)) { + scanRequest() + customDialogList.dismiss() + mpok?.start() + markLine(storedPosition, quantityReserveToCheckItemScan, null) + } else { + customDialogList.setValueTwo("") + if (it.response.isBlank() || it.response.isEmpty()) { + showErrorMessage(text = getString(R.string.codeNotExist)) + + } else { + showErrorMessage(text = getString(R.string.lineNotExist)) + } + + + if (mperror != null) mperror?.start() + } + } + } + + goBack2 = false + + } + + } + } + + + private fun createCollectionList() { + state = 0 + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + + collection.map(requireContext()) + val salesList: ArrayList = ArrayList() + + tickets = ArrayList() + var observations = "" + val myPickingFrom = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_FROM") + val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_TO") + collection.tickets.forEach { ticket -> + + if (!observations.isNullOrEmpty()) observations = + observations + " " + ticket.observations + ticket.sales.forEach { sale -> + + if (hasPickingOrder) { + if (sale.pickingOrder != null && sale.pickingOrder in myPickingFrom..myPickingTo) { + salesList.add(sale) + } + } else { + salesList.add(sale) + } + + } + } + + sales = salesList.sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) + + //quitar comentarios FALTA AGRUPAR LAS PREVIAS + myGroupList = + groupSaleGroup(salesList).sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) + // sales //sales porque no se ggrupan las previas hay que cambiar los estados. + + saleAdapter = SaleAdapterNew( + myGroupList, + pasillerosItemClickListener!!, + object : OnQuantityClickSaleListener { + + override fun onQuantityClick(sale: Sale) { + sales.forEachIndexed { index, saleVO -> + + if (saleVO.saleFk == sale.saleFk) { + if (sale.isPicked == 1) { + showErrorMessage( + title = getString(R.string.info), + text = getString(R.string.unmarkForModify) + ) + } + + } + } + + } + }, + object : OnSaleClickSaleListener { + override fun onSaleClick(mysale: Sale) { + + var position = myGroupList.indexOfFirst { it.itemShelvingSaleFk == mysale.itemShelvingSaleFk } + if (position>-1){ + if (mysale.isPicked ==1){ + unMarkLine(position, myGroupList[position]) + }else{ + showScanner(position, mysale) + } + } + + /* myGroupList.forEachIndexed { index, sale -> + //sales.forEachIndexed { index, sale -> + // println("Sacador la sale es ${sale.saleFk}") + // println("Sacador la sale picked es ${sale.isPicked}") + // println("Sacador la sale group es ${sale.saleGroupFk}") + // println("Sacador la sale reserved es ${sale.reservedQuantity}") + if (sale.itemShelvingSaleFk == 0) { + println("Sacador Que hacemos en este caso ?? ") + } else { + + + if (sale.itemShelvingSaleFk == mysale.itemShelvingSaleFk) { + println("Sacador **** itemShelvingSale es ${sale.itemShelvingSaleFk}") + println("Sacador **** isPicked es ${sale.isPicked}") + println("Sacador **** saleGroup es ${sale.saleGroupFk}") + //println("Sacador la sale es ${sale.saleFk}") + //println("Sacador la sale picked es ${sale.isPicked}") + //println("Sacador la sale group es ${sale.saleGroupFk}") + //println("Sacador la sale reserved es ${sale.reservedQuantity}") + //println("Sacador la sale dentro es ${sale.saleFk}") + if (sale.isPicked != 1 && sale.saleGroupFk == null) { + println("Sacador **** showScanner") + showScanner(index, sale) + } else { + println("Sacador **** desmarcar") + unMarkLine(index, myGroupList[index]) + } + + } + } + + }*/ + } + + }, + object : OnMistakeClickListener { + override fun onMistakeClickListener(sale: SaleVO) { + } + }, + object : OnPackingClickSaleListener { + override fun onPackingClick(sale: Sale) { + goBack = true + + if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener( + PasillerosItemVO( + title = getString(R.string.titleUbicator), + ), entryPoint = sale.code + ) + } + }, + object : OnTicketClickSaleListener { + override fun onTicketClickListener(sale: Sale) { + val entryPoint = Gson().toJson( + mutableMapOf( + "entryPoint" to sale.ticketFk, "web" to "${ + mobileApplication.dataStoreApp.readDataStoreKey( + BASEURLSALIX + ) + }/#!/ticket/${sale.ticketFk}/sale" + ) + ) + ma.onPasillerosItemClickListener( + PasillerosItemVO( + title = getString(R.string.titleWebViewer), + ), entryPoint = entryPoint + ) + } + }, + type = type + ) + + + lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + binding.fragmentSacadorCollections.adapter = saleAdapter + binding.fragmentSacadorCollections.layoutManager = lm + + setTotalLines() + setStoredPosition() + setScrollListener(lm!!) + printObservations(observations) + } + + private fun setScrollListener(lm: LinearLayoutManager) { + binding.fragmentSacadorCollections.clearOnScrollListeners() + 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 printObservations(observations: String) { + if (observations.trim().isNotEmpty()) { + customDialog.setTitle(getString(R.string.observations)).setDescription(observations) + .setOkButton(getString(R.string.accept)) { + customDialog.hide() + customDialog.dismiss() + }.show() + } + } + + private fun findSale(txtscan: String) { + + var isFoundSale = false // markPrevia(txtscan) + + //Se busca la matricula en las lineas + for (indice in myGroupList.indices) { + if (myGroupList[indice].isPicked != 1 && myGroupList[indice].code != null && myGroupList[indice].code!!.uppercase() == txtscan.uppercase()) { + mpok!!.start() + isFoundSale = true + positionMarkPrevia = indice + printShelvingResult(indice) + break + } + } + + if (!isFoundSale) mperror!!.start() + + } + + private fun findSale(txtscan: String, position: Int, sale: Sale) { + + storedPosition = position + + if (sale.code!!.uppercase() == txtscan.uppercase()) { + mpok!!.start() + printShelvingResult(position) + //sale.isPicked = 1 + //saleAdapter!!.notifyItemChanged(position) + } else { + mperror!!.start() + } + + } + + private fun markLine(position: Int, quantity: Int, isItemShelvingSaleEmpty: Boolean?) { + + state = 0 + isScanned = null + positionConfirm = position + quantityConfirm = quantity + isMarking = true + + viewModel.itemShelvingSaleSetQuantity( + myGroupList[position].itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty + ) + storedBackPosition = position/* var mySale = myGroupList[position].itemShelvingSaleFk + for (indice in myGroupList.indices) { + if (!myGroupList[indice].isParent && myGroupList[indice].itemShelvingSaleFk == mySale) { + storedBackPosition = indice + } + }*/ + + } + + private fun setListPosition() { + + if (storedPosition == 0 && storedBackPosition == 0) { // se inicia lista, se busca porqué item vamos. + for (indice in myGroupList.indices) { + if (myGroupList[indice].isPicked == 0) { + //storedPosition = indice + lm!!.scrollToPositionWithOffset(indice - 1, 0) + break + } + } + + } else { + lm!!.scrollToPositionWithOffset(storedBackPosition, 0) + } + } + + private fun unMarkLine(position: Int, sale: Sale) { + state = 0 + customDialog.setTitle(getString(R.string.unmarkLine)).setDescription( + getString(R.string.goUnmark) + sale.itemFk + getString( + R.string.sure + ) + ).setOkButton(getString(R.string.unmark)) { + if (!sale.isParent && sale.reservedQuantity == 0 && sale.originalQuantity != sale.saleQuantity) { + getString(R.string.unmarkError).toast(requireContext()) + } else {/* saleAdapter!!.notifyDataSetChanged() + var mySale = sale.saleFk + for (indice in myGroupList.indices) { + if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { + d("VERDNATURA::", "la pos del index de la sale es" + indice) + storedBackPosition = indice + } + }*/ + storedBackPosition = position + setListPosition() + + viewModel.itemShelvingSaleUnpicked(myGroupList[position].itemShelvingSaleFk) + sale.isPicked = 0 + positionUnmarked = position + setTotalLines() + scanRequest() + } + + + customDialog.dismiss() + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() + + } + + //SHELVINGS + + private fun printShelvingResult(pos: Int) { + storedPosition = pos + customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_TEXT + customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) + customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) + customDialogList.getEditTextTwo().requestFocus() + val shelving = myGroupList[pos].code + val item = myGroupList[pos].itemFk + val longName = myGroupList[pos].longName + val totalReserved = myGroupList[pos].reservedQuantity + val itemShelvingFk = myGroupList[pos].itemShelvingSaleFk + + try { + customDialogList.setTitle("$shelving($item) $totalReserved de $longName").setOkButton( + getString( + R.string.take + ) + ) { + customDialogTakeAction(pos, itemShelvingFk, totalReserved, false) + + }.setKoButton(getString(R.string.close)) { + requireActivity().hideKeyboard(customDialogList.getEditTextTwo()) + customDialogList.dismiss() + scanRequest() + + }.setHintValue(getString(R.string.quantitySelect)).setValue(totalReserved.toString()) + .setHintValueTwo(getString(R.string.scanItem)).setValueTwo("").show() + + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + + customDialogTakeAction( + pos, + itemShelvingFk, + totalReserved, + event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + ) + + return@setOnEditorActionListener true + + } + false + } + } catch (e: Exception) { + ma.messageWithSound(e.message.toString(), isError =true, true) + } + } + + private fun customDialogTakeAction( + position: Int, itemShelvingFk: Int, totalReserved: Int, isItemScanned: Boolean? + ) { + goBack = false + isScanned = isItemScanned + if (customDialogList.getValueTwo().isNotEmpty()) { + + customDialogList.setValueTwo( + itemScanValue( + customDialogList.getValueTwo(), "buy", "more" + ).toString() + ) + val quantityToReserve = customDialogList.getValue().toInt() + + if (quantityToReserve < totalReserved) { + + if (customDialogList.getValueTwo() in sales[position].Barcodes || customDialogList.getValueTwo() == sales[position].itemFk.toString()) { + customDialogList.dismiss() + showQuestionUbicationEmpty(position, quantityToReserve) + } else { + ma.messageWithSound( + message = getString(R.string.errorItem), + isError = true, + isPlayed = true, + isToasted = false + ) + } + } + + if (quantityToReserve > totalReserved) { + ma.hideKeyboard(customDialogList.getEditTextTwo()) + getString(R.string.quantityHigh).toast(requireContext()) + } + if (quantityToReserve == totalReserved) { + originalItemScan = customDialogList.getValueTwo().toLong() + if (checkItemScan(customDialogList.getValueTwo())) { + + markLine(storedPosition, quantityToReserve, null) + + mpok?.start() + ma.hideKeyboard(customDialogList.getEditTextTwo()) + customDialogList.dismiss() + scanRequest() + + } else { + + itemShelvingFkStored = itemShelvingFk + + quantityReserveToCheckItemScan = quantityToReserve + viewModel.getIdFromCodeSalix( + code = customDialogList.getValueTwo(), + ) + customDialogList.dismiss() + } + } + + } else { + getString(R.string.scanItemValidate).toast(requireContext()) + } + } + + private fun setStoredPosition() { + setListPosition()/*if (goBack) setListPosition(storedBackPosition, isFromBack) else { + setListPosition(storedPosition, isFromBack)*/ + } + + private fun checkItemScan(valueToCheck: String): Boolean { + + val saleToCheck = myGroupList[storedPosition] + if (saleToCheck.itemFk.toString() == valueToCheck) return true + else { + saleToCheck.Barcodes.forEach { barcode -> + if (barcode == valueToCheck) return true + } + } + + return false + } + + private fun showQuestionUbicationEmpty(position: Int, quantity: Int = 0) { + + customDialogThreeButtonsQuantity.setTitle( + getString( + R.string.changeQuantity, quantity, sales[position].itemFk + ) + ).setDescription(getString(R.string.questionItemShelving, sales[position].itemFk)) + .setValue("").setCustomDialogValue(View.GONE) + customDialogThreeButtonsQuantity.setOkButtonAdd(text = getString(R.string.yes)) { + scanRequest() + customDialogThreeButtonsQuantity.dismiss() + getString(R.string.errorQuantityShelving).toast(requireContext()) + customDialogThreeButtonsQuantity.dismiss() + showQuestionUbicationEmpty(position, quantity) + }.setOkButtonTwo("NO") { + scanRequest() + customDialogThreeButtonsQuantity.dismiss() + if (quantity == 0) { + viewModel.itemShelvingSaleExists( + myGroupList[position].itemShelvingSaleFk, position, quantity + ) + } else { + markLine(position, quantity, true) + } + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialogThreeButtonsQuantity.dismiss() + }.show() + customDialogThreeButtons.setFocusDialogValue() + } + + //OPTIONS + private fun print() { + + if (ma.havePrinter() && ma.haveSector()) { + showDialogLabelCount() + + } else { + ma.messageWithSound( + getString(R.string.printerFault), + isError = true, + true, + getString(R.string.printError), + false + ) + + } + + } + + private fun addItem() { + listPlacementSupply = ArrayList() + collection.tickets.forEach { + listPlacementSupply.add(BarcodeVO(code = it.ticketFk.toString())) + } + if (listPlacementSupply.size == 1) { + ticketSelected = listPlacementSupply[0].code!!.toInt() + } + customDialogList.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_NUMBER + customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) + customDialogList.setTitle(getString(R.string.Agregarartículoparaticket) + " " + ticketSelected) + .setOkButton(getString(R.string.Agregar)) { + customDialogAddItem() + }.setKoButton(getString(R.string.close)) { + scanRequest() + customDialogList.dismiss() + }.setHintValue(getString(R.string.Artículo)).setValue("") + .setHintValueTwo(getString(R.string.Cantidad)).setValueTwo("").show() + customDialogList.getEditText().requestFocus() + requireActivity().hideKeyboard() + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!customDialogList.getValue().isNullOrEmpty()) { + try { + customDialogList.setValue( + itemScanValue( + customDialogList.getValue(), "buy", "more" + ).toString() + ) + + } catch (e: Exception) { + ma.messageWithSound(e.message.toString(), isError = true, true) + } + customDialogList.getEditTextTwo().requestFocus() + } + + return@setOnEditorActionListener true + + } + false + + } + + + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + customDialogAddItem() + return@setOnEditorActionListener true + + } + false + } + + placementSupplyAdapter = + BarcodeAdapter(listPlacementSupply, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + customDialogInput.setTitle(getString(R.string.ArtículoparaTicket) + " " + item.code!!) + ticketSelected = item.code!!.toInt() + customDialogList.setTitle(getString(R.string.Agregarartículoparaticket) + " " + ticketSelected) + } + }, showDelete = false) + + customDialogList.getRecyclerView().adapter = placementSupplyAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + + private fun customDialogAddItem() { + + if (!customDialogList.getValueTwo().isNullOrEmpty()) { + if (ticketSelected == 0) { + getString(R.string.Seleccionaunticketdelaista).toast(requireContext()) + } else if (customDialogList.getValue().isNullOrEmpty() || customDialogList.getValueTwo() + .isNullOrEmpty() + ) { + getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) + } else { + viewModel.collectionAddWithReservation( + customDialogList.getValue().toInt(), + customDialogList.getValueTwo().toInt(), + ticketSelected + ) + + customDialogList.dismiss() + hideKeyboards() + scanRequest() + } + } else { + getString(R.string.scanItem).toast(requireContext()) + } + + } + + private fun toastDisponibility(item: ItemVO) { + if (item.available.isNullOrEmpty()) { + item.available = "0" + } + customDialog.setTitle(getString(R.string.itemPoints) + item.id) + .setDescription(getString(R.string.available) + ":" + item.available) + .setOkButton(getString(R.string.accept)) { + scanRequest() + customDialog.dismiss() + }.show() + + } + + private fun setTotalLines() { + + val totalMark = sales.count { it.isPicked == 1 } + + binding.mainToolbar.toolbarTitle.text = + if (collection.collectionFk != 0) collection.collectionFk.toString() else "" + + + binding.mainToolbar.toolbarSubtitle.text = + getString(R.string.totalsPicker, totalMark, sales.size) + + if (totalMark == sales.size) { + getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) + changeTicketState() + } + } + + private fun changeTicketState() { + + viewModel.saleTrackingAddPrevOK(collection.collectionFk) + } + + private fun showScanner(index: Int, sale: Sale) { + customDialogInput.getEditText().inputType = InputType.TYPE_CLASS_TEXT + customDialogInput.setTitle("" + sale.itemFk) + .setDescription(getString(R.string.scanWagonForItem)) + .setOkButton(getString(R.string.accept)) { + findSaleAction(index, sale) + }.setKoButton(getString(R.string.cancel)) { + closeCustomDialog(binding.scanInput, customDialogInput) + }.setValue("").show() + + + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + findSaleAction(index, sale) + return@setOnEditorActionListener false + } + false + } + customDialogInput.getEditText().requestFocus() + } + + private fun findSaleAction(index: Int, sale: Sale) { + if (customDialogInput.getValue().isNotEmpty()) { + findSale(customDialogInput.getValue(), index, sale) + } + closeCustomDialog(binding.scanInput, customDialogInput) + } + + private fun closeCustomDialog(scanInput: EditText, customDialogInput: CustomDialogInput) { + requireContext().hideKeyboard(customDialogInput.getEditText()) + scanInput.requestFocus() + customDialogInput.dismiss() + scanInput.requestFocus() + + } + + private fun showErrorMessage(title: String = getString(R.string.errorMarkLine), text: String) { + customDialog.setTitle(title).setDescription(text).setKoButton(getString(R.string.close)) { + customDialog.dismiss() + }.show() + } + + private fun showDialogLabelCount() { + var isTicket = false + for (t in collection.tickets) { + if (t.ticketFk == (collection.collectionFk)) { + isTicket = true + } + } + if (isTicket) { + val builder = AlertDialog.Builder(context) + builder.setTitle(getString(R.string.selectLabeltoPrint)) + val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") + builder.setItems(labelCount) { dialog, which -> + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, labelCount = (which + 1) + ) + (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( + PRINTERNAME + )).toast(requireContext()) + + } + val dialog = builder.create() + dialog.show() + } else { + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, null + ) + + } + + } + + private fun groupSaleGroup(salesList: ArrayList): MutableList {/* var myMap = salesList.groupBy { it.saleGroupFk } + var myList: MutableList = mutableListOf() + + for ((key, value) in myMap.entries) { + if (key == null) { // si no tiene saleGroup se añaden las líneas + for (s in value) { + myList.add(s) + } + } else { // si tiene saleGroup se crea el padre con el tamaño e indicando que es padre, como ejemplo se toma el primer elemento + + *//*crea padre*//* + if (value.size > 1) { + var mySale = //= value[0] + Sale( + level = value[0].level, + isPicked = value[0].isPicked, + parkingCode = "Líneas : ${value.size}", + pickingOrder = value[0].pickingOrder, + workerFk = value[0].workerFk, + originalQuantity = value[0].originalQuantity, + saleQuantity = 0, + saleFk = value[0].saleFk, + saleGroupFk = value[0].saleGroupFk, + semaphore = value[0].semaphore, + ticketFk = value[0].ticketFk, + itemFk = value[0].saleGroupFk!!, + isAdded = value[0].isAdded, + hasMistake = value[0].hasMistake, + origin = value[0].origin, + size = value[0].size, + itemShelvingSaleFk = value[0].itemShelvingSaleFk, + longName = value[0].parkingCode ?: "" + ) + + //prime elemento//hay que hacer una copia si no queda la referencia + mySale.totalSales = value.size //total líneas + mySale.isParent = true + value as MutableList + mySale.sonSales = + value.sortedWith(compareBy { it.isPicked }) as MutableList*//*mySale.line1 = "Previa :${mySale.saleGroupFk}" + mySale.line2 = "Líneas: ${value.size}" + mySale.line3 = value[0].code*//* + // mySale.placements = listOf(PlacementVO(shelving = value[0].code!!)) + + myList.add(mySale) + } else { + for (s in value) { + myList.add(s) + } + } + + } + + }*/ + + return salesList + } + +} + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index 48d4436b..51b333e1 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -55,6 +55,7 @@ import es.verdnatura.presentation.view.feature.claim.fragment.ClaimFragment import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragment import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPicker import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPickerNew +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPickerPreviousNew import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPreChecker import es.verdnatura.presentation.view.feature.collection.fragment.CollectionShowTicketFragment import es.verdnatura.presentation.view.feature.controlador.fragment.ControladorFragment @@ -98,6 +99,7 @@ import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragm import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.precontrol.PreControladorFragment import es.verdnatura.presentation.view.feature.presacador.fragment.EndSacadorFragment +import es.verdnatura.presentation.view.feature.presacador.fragment.SectorCollectionReserveFragment import es.verdnatura.presentation.view.feature.qr.QrFragment import es.verdnatura.presentation.view.feature.reubication.fragment.ReubicationCollectionFragment import es.verdnatura.presentation.view.feature.reubication.fragment.ReubicationFragment @@ -168,7 +170,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? { - backDispatcher.addCallback(object : OnBackPressedCallback(true) { + backDispatcher.addCallback(object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { onMyBackPressed() } @@ -690,6 +692,10 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL addFragmentOnTop(PackingMistakeFragment.newInstance(item.title)) } + getString(R.string.titlePrePickerTest) -> { + addFragmentOnTop(SacadorFragmentNew.newInstance("PREITEMPICKERTEST")) + } + getString(R.string.titlePrePicker) -> { addFragmentOnTop(SacadorFragment.newInstance("PREITEMPICKER")) } @@ -854,6 +860,16 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.pickerHelper) -> { addFragmentOnTop(PickerHelperFragment.newInstance(item.title)) } + + "PREITEMPICKERTEST" -> { + addFragmentOnTop( + CollectionFragmentPickerPreviousNew.newInstance( + CollectionTicket(collectionFk = entryPoint.toInt()), + "PREITEMPICKERTEST", + false + ) + ) + } } } @@ -879,9 +895,13 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL val index = supportFragmentManager.backStackEntryCount - 1 var backEntry = "" + if (index >= 0) { backEntry = supportFragmentManager.getBackStackEntryAt(index).name.toString() + /* println("onback LOadUnload $backEntry") + if (backEntry.contains("itemShelvingLog")){ + }*/ if (backEntry.contains(getString(R.string.titleLoadTruck)) || backEntry.contains( getString(R.string.titleUnLoadTruck) ) @@ -924,14 +944,15 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL if (backEntry.contains("fragment.ExpeditionPalletDetailFragment.Companion")) { addFragmentOnTop(ExpeditionTruckListFragment.newInstance()) } - if (backEntry.contains(getString(R.string.titleLog)) || backEntry.contains( + /* if (backEntry.contains(getString(R.string.titleLog)) || backEntry.contains( getString( R.string.titleInfo ) ) ) { + println("backk finish ?? ") finish() - } + }*/ } else { customDialog.setTitle(getString(R.string.closeSession)) @@ -987,8 +1008,29 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL type: String, hasPicking: Boolean ) { + when (type) { + "PREITEMPICKERTEST" -> { + println("test presacador") + //addFragmentOnTop(EndSacadorFragment.newInstance(collection, type)) + addFragmentOnTop( + SectorCollectionReserveFragment.newInstance( + "PREITEMPICKERTEST", + collection.collectionFk + ) + ) - addFragmentOnTop(CollectionFragmentPickerNew.newInstance(collection, type, hasPicking)) + } + + else -> { + addFragmentOnTop( + CollectionFragmentPickerNew.newInstance( + collection, + type, + hasPicking + ) + ) + } + } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt index bb8b8540..948f20df 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt @@ -79,6 +79,12 @@ class PreSacadorViewModel(val context: Context) : BaseViewModel(context) { val loadResponseSaleGropAdd: LiveData> = _responseSaleGroupAdd.map { Event(it) } + private val _responseReserveSectorCollection by lazy { MutableLiveData() } + val responseReserveSectorCollection: LiveData + get() = _responseReserveSectorCollection + val loadResponseReserveSectorCollection: LiveData> = + _responseReserveSectorCollection.map { Event(it) } + private val _responseSaleAddPrevOK by lazy { MutableLiveData() } val responseSaleAddPrevOK: LiveData get() = _responseSaleAddPrevOK @@ -343,6 +349,32 @@ class PreSacadorViewModel(val context: Context) : BaseViewModel(context) { } }) } + fun getReserveBySectorCollection( + vSectorCollectionFk: Int + ) { + salix.getReserveBySectorCollection( + params = arrayListOf( + vSectorCollectionFk + ).formatWithQuotes() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseReserveSectorCollection.value = ResponseItemVO( + isError = false, errorMessage = "" + getMessageFromAllResponse( + nameofFunction(this), response.message() + ) + ) + } + + override fun onError(t: Throwable) { + _responseReserveSectorCollection.value = ResponseItemVO( + isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), t.message!! + ) + ) + + } + }) + } fun saleTrackingAddPrevOK( sectorCollectionFk: Int @@ -399,7 +431,8 @@ class PreSacadorViewModel(val context: Context) : BaseViewModel(context) { saleFk: Int ) { //Tarea 6276 pasar a Salix - salix.itemShelvingUpdateFromSale(saleFk) + //09/04/2024 + salix.itemShelvingUpdateFromSale(hashMapOf("saleFk" to saleFk)) // silex.itemShelving_updateFromSale(saleFk) .enqueue(object : SalixCallback(context) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt index 0af80003..a19cd639 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt @@ -16,7 +16,8 @@ class CollectionAdapterNew( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { return AjustesItemHolder( - ItemCollectionRowNewBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ItemCollectionRowNewBinding.inflate(LayoutInflater.from(parent.context), parent, false), + type ) } @@ -30,11 +31,13 @@ class CollectionAdapterNew( } class AjustesItemHolder( - val binding: ItemCollectionRowNewBinding + val binding: ItemCollectionRowNewBinding, + val type: String ) : RecyclerView.ViewHolder(binding.root) { fun bind(item: CollectionTicket) { + binding.apply { - if (item.ticketTotalCount == null) { + if (item.ticketTotalCount == null || type == "PREITEMPICKERTEST") { binding.totalTicketsId.visibility = View.GONE } this.item = item diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt index 2b80999d..8ba12514 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt @@ -55,12 +55,11 @@ class SacadorFragmentNew( setToolBar() setEvents() callBack(type) - println("SacadorNEW") super.init() } private fun callBack(type: String) { - binding.splashProgress.visibility = View.VISIBLE + when (type) { "PREPARED" -> { viewModel.collectionGetSalixLocal() @@ -70,8 +69,12 @@ class SacadorFragmentNew( viewModel.sectorCollectionGet() } + "PREITEMPICKERTEST" -> { + viewModel.sectorCollectionGet() + } + else -> { - binding.splashProgress.visibility = View.GONE + } } } @@ -119,7 +122,7 @@ class SacadorFragmentNew( when (item) { iconAdd.drawable -> { - binding.splashProgress.visibility = View.VISIBLE + if (type == "PREPARED") { viewModel.collection_assignNew( ) @@ -206,24 +209,53 @@ class SacadorFragmentNew( override fun observeViewModel() { with(viewModel) { - binding.splashProgress.visibility = View.GONE + collectionListLocal.observe(viewLifecycleOwner, Observer { - if (!goBack2) binding.splashProgress.visibility = View.GONE + //if (!goBack2) createCollectionList(it.list) - binding.splashProgress.visibility = View.GONE + + goBack2 = false + }) + + collectionList.observe(viewLifecycleOwner, Observer { it -> + //if (!goBack2) + var myCollectionsList = mutableListOf() + it.list.forEach { + myCollectionsList.add(CollectionTicket(it.collectionFk)) + } + createCollectionList(myCollectionsList) goBack2 = false }) response.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + if (it.isError) { ma.messageWithSound(it.errorMessage, true, false) } else { if (!it.response.isNullOrBlank()) { addCollectionToList(it.response.toInt()) - viewModel.collectionGetSalixLocal() + + }else{ + when (type) { + "PREPARED" -> { + viewModel.collectionGetSalixLocal() + } + + "PREITEMPICKER" -> { + viewModel.sectorCollectionGet() + } + + "PREITEMPICKERTEST" -> { + println("SacadorFragmentNew sectorCollectionGET") + viewModel.sectorCollectionGet() + } + + else -> { + + } + } } } goBack = false @@ -242,6 +274,7 @@ class SacadorFragmentNew( adapter = CollectionAdapterNew(collectionsList, onCollectionSelectedListener!!, type) binding.fragmentSacadorCollections.layoutManager = lm binding.fragmentSacadorCollections.adapter = adapter + adapter!!.notifyDataSetChanged() }