From 6b507bf7aec3d7e05a6613da07deb48e802e5ff0 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Fri, 14 Apr 2023 07:07:33 +0200 Subject: [PATCH] refs precontrol --- .../fragment/CollectionFragmentPreChecker.kt | 2903 +++++++++++++++++ .../feature/main/activity/MainActivity.kt | 5 + 2 files changed, 2908 insertions(+) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt 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 new file mode 100644 index 00000000..68a1e804 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreChecker.kt @@ -0,0 +1,2903 @@ +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.os.Parcelable +import android.text.InputType +import android.text.InputType.TYPE_CLASS_NUMBER +import android.text.InputType.TYPE_CLASS_TEXT +import android.util.Log.d +import android.view.KeyEvent +import android.view.KeyEvent.ACTION_DOWN +import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE +import android.view.WindowManager +import android.view.inputmethod.EditorInfo +import android.view.inputmethod.InputMethodManager +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 +import es.verdnatura.R +import es.verdnatura.databinding.FragmentCollectionBinding +import es.verdnatura.domain.ConstAndValues.CONTROLADOR +import es.verdnatura.domain.ConstAndValues.OK +import es.verdnatura.domain.ConstAndValues.PRECHECKER +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.* +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.SaleAdapter +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.* +import org.json.JSONObject + + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class CollectionFragmentPreChecker( + 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 + 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 var storedShelvingPosition: Int = 0 + private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialogThreeButtons: 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 positionIncreaseQuantity = 0 + private var positionReject = 0 + private var quantityIncrease: Int = 0 + private var quantityReject = "" + private var typeCollectionMissing = "" + private var positionCollectionMissing = 0 + private var quantityCollectionMissing: Int = 0 + private var isMarking = false + private var positionCollectionSplit = 0 + private var quantityCollectionSplit: Int = 0 + private lateinit var ticketToParking: String + private lateinit var ticketScanTxt: String + + private var itemShelvingSaleSupplyAddCall = -1 + private var saleTrackingCall = -1 + private var lastScanned: Int = 0 + private var buttonPushedGetCollection = false + private var positionUnmarked = -1 + private var state = 0 + private var mIsListening = false + private var placementPicked: PlacementVO? = null + private var lastPlacementPicked: PlacementVO? = null + private var originalItemScan: Int = 0 + private var workerFkFromTicket: String? = null + private var itemShelvingTracking_mark: Int = 0 + private var recylerViewState: Parcelable? = null + private var isScanned: Boolean? = null + + private lateinit var myGroupList: List + + companion object { + fun newInstance(collection: CollectionVO, type: String) = + CollectionFragmentPreChecker(collection, type) + } + + override fun onAttach(context: Context) { + if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context + super.onAttach(context) + } + + override fun getLayoutId(): Int = R.layout.fragment_collection + + override fun onCreate(savedInstanceState: Bundle?) { + d("VERDNATURA::", "Precontrol test. No operativo todavia") + mperror = MediaPlayer.create((activity as MainActivity), R.raw.error) + mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok) + if (type.equals(CONTROLADOR)) { + //sergio: comprueba si viene de la pantalla de controlador + //Tarea #4280 + viewModel.ticket_isOutClosureZone( + collection.collectionFk + + ) + workerFkFromTicket = collection.tickets.get(0).sales.get(0).workerFk + } + + if (collection.tickets.isEmpty()) { + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + super.onCreate(savedInstanceState) + } + + override fun onResume() { + super.onResume() + scanRequest() + } + + override fun init() { + customDialogList = CustomDialogList(requireContext()) + customDialogInput = CustomDialogInput(requireContext()) + customDialog = CustomDialog(requireContext()) + customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) + ma.hideBottomNavigation(GONE) + binding.splashProgress.visibility = VISIBLE + setEvents() + setToolBar() + if (collection.tickets.isNotEmpty()) { + createCollectionList() + } + super.init() + } + + override fun onPause() { + super.onPause() + goBack = true + goBack2 = true + goMistakeBack = true + + } + + private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE + binding.mainToolbar.toolbarIcons.visibility = VISIBLE + binding.mainToolbar.backButton.visibility = 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) + + 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) + + } + listIcons.add(iconPrint) + if (type == CONTROLADOR) { + listIcons.add(iconViewCollection) + binding.previaButton.visibility = VISIBLE + binding.previaButton.setOnClickListener { + showPrevia() + } + listIcons.add(iconWorker) + } + + listIcons.add(iconAdd) + + if (type == SACADOR) { + listIcons.add(iconUpdate) + listIcons.remove(iconWorker) + } + + if (type == PRECHECKER) { + listIcons.add(iconParking) + listIcons.remove(iconPrint) + } + + 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() { + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + + private fun markPrevia(saleGroupScanned: String): Boolean { + + for (indice in sales.indices) { + if (!sales[indice].saleGroupFk.isNullOrEmpty() && sales[indice].saleGroupFk == saleGroupScanned) { + + when (type) { + CONTROLADOR -> markLine(indice, type) + SACADOR -> { + viewModel.saleTracking_add( + saleGroupScanned.toInt() + ) + return true + } + + } + if (mpok != null) { + mpok!!.start() + } + + } + } + return false + } + + private fun showPrevia() { + customDialogList.getEditText().setRawInputType(TYPE_CLASS_NUMBER) + customDialogList.setTitle(getString(R.string.scanPreviousTicket)) + .setOkButton(getString(R.string.end)) { + ma.hideKeyboard(customDialogList.getEditText()) + customDialogList.dismiss() + + }.setValue("").show() + + customDialogList.getEditText().requestFocus() + ma.hideKeyboard(customDialogList.getEditText()) + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + 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 == ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + markPrevia(saleGroupScanned) + customDialogList.dismiss() + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + hideKeyboard() + } + + private fun getCollection() { + + binding.splashProgress.visibility = VISIBLE + if (!buttonPushedGetCollection) { + viewModel.collection_get( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + buttonPushedGetCollection = true + } else { + viewModel.collectionTicketGet( + lastScanned, + getDataInt(SECTORFK), + print = "0", + type + + ) + buttonPushedGetCollection = false + } + lastScanned = collection.collectionFk + } + + 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 { + requireActivity().onBackPressed() + } + //ESCANER ========= + hideKeyboards() + 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()) { + + //sergio:para ver si ha marcado dos veces el mismo ticket + binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) + + //de momento solo está el qr de artículo + isScanned = + event != null && event.action == ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + + if (itemScanIsQr(binding.scanInput.text.toString())) { + + var 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) + "parking" -> { + tickets.forEach { + viewModel.parking( + ticketFk = it, + parking = binding.scanInput.text.toString() + ) + } + } + + } + + } else { + 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 + // if (type != PRECHECKER) { + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + buttonPushedGetCollection = false + binding.collectionSwipe.isRefreshing = false + //} + } + } + + private fun hideKeyboards() { + try { + requireActivity().hideKeyboard() + } catch (e: Exception) { + } + } + + + private fun showKeyboards() { + try { + requireActivity().showKeyboard() + } catch (e: Exception) { + } + } + + private fun showKeyboardsIN() { + try { + requireActivity().showKeyboardIn() + } catch (e: Exception) { + } + } + + @RequiresApi(Build.VERSION_CODES.O) + override fun observeViewModel() { + with(viewModel) { + binding.splashProgress.visibility = 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) requireActivity().onBackPressed() + }.show() + } + + }) + + responseUsedShelves.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + + if (!goBack) { + ma.messageWithSound( + if (it.isError) it.errorMessage else getString(R.string.savedShelves), + it.isError, true + ) + } + + }) + responseParking.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + + if (!goBack) { + binding.splashProgress.visibility = GONE + ma.messageWithSound( + if (it.isError) it.errorMessage else getString(R.string.Aparcado), + it.isError, true + ) + } + + }) + + responsePrint.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + + if (!goBack) { + + if (it.isError) { + ma.messageWithSound( + it.errorMessage, + it.isError, true + ) + } else { + (getString(R.string.Imprimiendo) + getData(PRINTERNAME)).toast( + requireContext() + ) + } + } + + }) + + responseSplit.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = GONE + + if (!goBack) { + + if (it.isError) { + ma.messageWithSound( + it.errorMessage, + it.isError, true + ) + } else { + ma.messageWithSound( + getString(R.string.splitOk), + it.isError, true + ) + //responseSaleMoveSuccesful() + } + } + + } + + + + responseItem_updatePackingShelve.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + ma.messageWithSound( + if (it.isError) it.errorMessage else getString(R.string.packingSave), + it.isError, !it.isError + ) + if (!it.isError) { + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + }) + + responseSaleGroup.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + + ma.messageWithSound(it.errorMessage, true, true) + } else { + ma.messageWithSound(getString(R.string.previousCollected), false, true) + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + }) + placementSuppleyList.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + if (!goBack) printShelvingResult(it) + goBack = false + }) + + item.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + if (!goBack) toastDisponibility(it) + goBack = false + }) + + responseNew.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + // if (!goBack) { + if (it.isError) { + customDialog.setTitle(getString(R.string.disponibility)) + .setDescription(getString(R.string.errorCollectionNew) + it.errorMessage) + .setKoButton(getString(R.string.close)) { + scanRequest() + customDialog.dismiss() + }.show() + } else { + + binding.splashProgress.visibility = + VISIBLE + + + if (!goBack) { + sendSalixMessage( + item = dataMessageSalix.item, + ticketFk = dataMessageSalix.ticket, + quantity = dataMessageSalix.quantity, + salePerson = dataMessageSalix.personSale + ) + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + // //Log.i("VERDNATURA:","La collection es ${collection.collectionFk}") + } + } + // } + + goBack = false + + }) + + responseCode.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (!goBack2) { + if (it.isError) { + customDialog.setTitle(getString(R.string.error)) + .setDescription(it.errorMessage) + .setKoButton(getString(R.string.close)) { + scanRequest() + customDialog.dismiss() + }.show() + } else { + if (checkItemScan(it.response)) { + scanRequest() + customDialogList.dismiss() + mpok?.start() + onQuantityOfShelvingSelected(itemShelvingFkStored) + } else { + var value = customDialogList.getValueTwo() + customDialogList.setValueTwo("") + if (it.response.isBlank() || it.response.isEmpty()) { + showErrorMessage(getString(R.string.codeNotExist)) + + } else { + showErrorMessage(getString(R.string.lineNotExist)) + } + + + if (mperror != null) mperror?.start() + } + } + } + + goBack2 = false + + }) + + /* responseMissingTrash.observe(viewLifecycleOwner, Observer { + + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + + } else { + + missingTrashSuccesful() + + } + } + + })*/ + //Tarea 4280 + responseTicketClosure.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + if (!goBack) { + if (it.response.toBoolean()) { + var customDialogWarning = CustomDialog(requireContext()) + customDialogWarning.setTitle(getString(R.string.urgentWarning)) + customDialogWarning.setDescription(getString(R.string.ticketWarning)) + .setOkButton(getString(R.string.aware)) { + customDialogWarning.dismiss() + }.show() + } + } + + }) + + responseIncQuantity.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + + } else { + if (!goBack) { + incresaseSuccesful() + } else { + goBack = false + } + } + + }) + + responseSaleMistakeAdd.observe(viewLifecycleOwner, Observer { + + + if (!goBack) { + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + + } else { + ma.messageWithSound( + getString(R.string.errorRegistered), + isError = false, + false + ) + goBack = true + } + + } + }) + /* responseSaleMove.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + ma.messageWithSound(it.errorMessage, isError = true, true) + + } else { + if (!goBack) + responseSaleMoveSuccesful() + goBack = false + } + + })*/ + responseGetExtensionFromUserId.observe(viewLifecycleOwner, Observer { + + binding.splashProgress.visibility = GONE + + if (it.isError) { + if (!goMistakeBack) + ma.messageWithSound( + getString(R.string.noSIP) + it.errorMessage + getString(R.string.user) + workerFkFromTicket, + isError = true, + true + ) + + } else { + if (!goMistakeBack) + callPicker(it.response) + + } + goMistakeBack = true + }) + + + mistakeList.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + /*sergio:se quita y se pone esta comprobacion porque si no aparece de nuevo otra vez al volver atrás */ + + if (!goMistakeBack) + showMistakeList(it.list) + goMistakeBack = true + }) + //sergio: para si hay algun ticket por revisar antes de parkinear + + responseCollectionUnchecked.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, it.isError, false) + + } else { + //sergio: devuelve false si no hay para revisar y <> false. + if (it.response != "false") { + + customDialog.setTitle(getString(R.string.warning)) + .setDescription(getString(R.string.pendingReviewParking) + (it.response)) + .setOkButton(getString(R.string.accept)) { + customDialog.dismiss() + + } + .setKoButton(getString(R.string.review)) { + binding.splashProgress.visibility = View.VISIBLE + viewModel.collectionTicketGet( + it.response.toInt(), + getDataInt(SECTORFK), + print = "0", + type + ) + customDialog.dismiss() + } + customDialog.show() + } else { + viewModel.parking( + ticketFk = tickets[0], + parking = ticketScanTxt + ) + } + // if (!goBack)navigateToCollectionList(it) + //goBack = false + } + }) + + loadResponseDel.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + binding.splashProgress.visibility = View.INVISIBLE + if (it.isError) { + binding.splashProgress.visibility = GONE + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, false) + + } + } else { + + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + goBack = false + } + } + } + + + /* responseDel.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + binding.splashProgress.visibility = GONE + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, false) + + } + } else { + + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + goBack = false + } + + })*/ + + loadResponseItemShelvingUpdate.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + if (it.isError) { + ma.messageWithSound(it.errorMessage, it.isError, false) + + } else { + viewModel.saleTrackingDel( + saleFk = sales[positionUnmarked].saleFk + ) + } + } + } + + /* responseItemShelvingUpdate.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, false) + + } + + + } else { + //Test volver atrás + if (!goBack){ + viewModel.saleTrackingDel( + saleFk = sales[positionUnmarked].saleFk + )} + goBack = false + } + })*/ + + responseSaleReplace.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + + if (it.isError) { + + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, true) + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + } else { + + if (type != PRECHECKER) { + saleAdapter!!.notifyDataSetChanged() + } + goBack = false + } + }) + + + + loadResponseSaleTrackingMark.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + binding.splashProgress.visibility = GONE + if (it.isError) { + //TEST3 + /* if (getDataInt(USERFK) == 18890 || getDataInt(USERFK) == 19591) { + "La línea NO se ha marcado correctamente".toast(context) + }*/ + + if (!goBack) { + ma.messageWithSound(it.errorMessage, it.isError, true) + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + } else { + // pintar línea + + saleAdapter!!.notifyDataSetChanged() + + ReviewQuantityForRefreshingAndSorting( + sales[storedPosition].quantity!!.toInt(), + sales[storedPosition].pickedQuantity!!.toInt() + ) + goBack = false + } + + } + } + ////Tarea #4371 + /* responseSaleTracking_mark.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = GONE + if (it.isError) { + //TEST3 + *//* if (getDataInt(USERFK) == 18890 || getDataInt(USERFK) == 19591) { + "La línea NO se ha marcado correctamente".toast(context) + }*//* + + if (!goBack) { + ma.messageWithSound(it.errorMessage, it.isError, true) + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + } else { + // pintar línea + //TEST3 + if (getDataInt(USERFK) == 18890 || getDataInt(USERFK) == 19591) { + "La línea se ha marcado correctamente".toast(context) + } + saleAdapter!!.notifyDataSetChanged() + + ReviewQuantityForRefreshingAndSorting( + sales[storedPosition].quantity!!.toInt(), + sales[storedPosition].pickedQuantity!!.toInt() + ) + goBack = false + } + })*/ + + + responseItemShelvingSaleSupplyAdd.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, true) + + } + + + } else { + goBack = false + } + }) + + + responseSalixMessage.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + if (!goBack) { + ma.messageWithSound( + getString(R.string.rocketKO) + it.errorMessage, + it.isError, + false + ) + } else { + goBack = false + } + + + } + }) + + + } + } + + private fun responseSaleMoveSuccesful() { + sales[positionCollectionSplit].quantity = quantityCollectionSplit + + if (quantityCollectionSplit == 0) + markLine(positionCollectionSplit, type) + saleAdapter!!.notifyDataSetChanged() + + val ticket = + "[" + sales[positionCollectionSplit].ticketFk + "](https://salix.verdnatura.es/#!/ticket/" + sales[positionCollectionSplit].ticketFk + "/summary)" + val message = + getString(R.string.splitSent) + sales[positionCollectionSplit].itemFk + getString(R.string.fromTicket) + ticket + + sendSalixMessageNew(message, sales[positionCollectionSplit].salePersonFk) + + } + + 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 getSalePerson(ticketFk: Int): String { + var salePerson = "" + for (it in sales) { + if (it.ticketFk.equals(ticketFk)) { + salePerson = it.salePersonFk + break + } + } + return salePerson + } + + private fun sendSalixMessage( + item: String, + ticketFk: Int, + quantity: String, + salePerson: String + ) { + val ticket = + "[" + ticketFk + "](https://salix.verdnatura.es/#!/ticket/" + ticketFk + "/summary)" + val message = + getString(R.string.itemAdded) + item + getString(R.string.with) + quantity + getString(R.string.unityTicket) + ticket + + viewModel.sendChekingPresence( + workerId = salePerson, + message = message + ) + } + + //CREATE LIST + private fun createCollectionList() { + + state = 0 + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + + binding.splashProgress.visibility = View.GONE + var salesList: ArrayList = ArrayList() + tickets = ArrayList() + var observations = "" + collection.tickets.forEach { ticket -> + // if (!ticket.sales.isNullOrEmpty()){ + ticket.sales.forEach { saleVO -> + if (type == SACADOR && saleVO.quantity != 0) { + salesList.add(saleVO) + if (tickets.firstOrNull { it == saleVO.ticketFk }.isNullOrEmpty()) + tickets.add(saleVO.ticketFk) + } else if (type == CONTROLADOR) { + salesList.add(saleVO) + if (tickets.firstOrNull { it == saleVO.ticketFk }.isNullOrEmpty()) + tickets.add(saleVO.ticketFk) + } else if (type == PRECHECKER) { + if (saleVO.saleGroupFk != "") { + salesList.add(saleVO) + if (tickets.firstOrNull { it == saleVO.ticketFk }.isNullOrEmpty()) + tickets.add(saleVO.ticketFk) + } + } + } + + observations = observations + " " + ticket.observations + }//} + + + sales = salesList.sortedWith(compareBy({ it.saleOrder })) + myGroupList = groupSaleGroup(salesList).sortedWith(compareBy({ it.saleOrder })) + + if (type == CONTROLADOR || type == PRECHECKER) { + sales = salesList.sortedWith(compareBy({ it.picked })) + myGroupList = groupSaleGroup(salesList).sortedWith(compareBy({ it.picked })) + + } + + saleAdapter = + SaleAdapter( + myGroupList, + pasillerosItemClickListener!!, + object : OnQuantityClickListener { + + override fun onQuantityClick(sale: SaleVO) { + + sales.forEachIndexed { index, saleVO -> + if (saleVO.saleFk == sale.saleFk) { + if (type != "PRECHECKER") { + showQuantityDialog(index) + } + + } + } + + } + }, + object : OnSaleClickListener { + override fun onSaleClick(sale: SaleVO) { + + sales.forEachIndexed { index, saleVO -> + if (saleVO.saleFk == sale.saleFk) { + + if (type == CONTROLADOR || type == PRECHECKER) {// sergio:cuidado , esta es de lo último para marcar colores + isScanned = false + markLine(index, type) + /// Log.i("VERDNATURA:","marcamos linea") + } else if (type == SACADOR) { + + if (sale.isPrepared == "0" || sale.isPrepared.isNullOrEmpty()) { + showScanner(index, sale) + } else { + unMarkLine(index, OK) + } + + } + } + + } + } + + }, + object : OnMistakeClickListener { + override fun onMistakeClickListener(sale: SaleVO) { + //Tarea #4969 + binding.splashProgress.visibility = VISIBLE + viewModel.mistakeType() + mistakeSale = sale + goMistakeBack = false + + } + }, + object : onPackingClickListener { + override fun onPackingClick(sale: SaleVO) { + item_updatePackingShelve(sale.itemFk) + } + }, + object : OnTicketClickListener { + override fun onTicketClickListener(sale: SaleVO) { + if (type == CONTROLADOR) { + //var ticketFk = sale.ticketFk + + var entryPoint = Gson().toJson( + mutableMapOf( + "entryPoint" to sale.ticketFk, + "web" to "https://salix.verdnatura.es/#!/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() + //Tarea #4628 + if (type == CONTROLADOR) { + setListPosition(storedBackPosition, true) + setScrollListener(lm!!) + } + //CAU ISMAELCT + else { + + if (type == SACADOR) { + setStoredPosition(true) + } else { + if (storedPosition != 0) + setListPosition(storedPosition, true) + else if (storedBackPosition != 0) + setListPosition(storedBackPosition, true) + + } + } + + 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() + } + } + + //SEARCH AND MARK + + + private fun findSale(txtscan: String) { + var index = 0 + var isBreak = false + var isOk = false + goBack = false + goBack2 = false + + if (type == SACADOR) { + isOk = markPrevia(txtscan) + for (saleVO in sales) { + if (isOk) break + + if (saleVO.isPrepared != "1" && saleVO.isPreviousPrepared != "1") { + //1- Por itemFk + /* if (txtscan == saleVO.itemFk){ + mpok!!.start() + isOk = true + markLine(index,type) + break + }*/ + //2- Por carro + if (saleVO.placements != null) { + var shelvingIndex = 0 + for (placementVO in saleVO.placements) { + // para comprobar si es igual a una matricula + if (placementVO.shelving != null && placementVO.visible != null && txtscan.uppercase() == placementVO.shelving.uppercase() && placementVO.visible != "(0)") { + if (mpok != null) mpok!!.start() + isOk = true + //////Log.i("VERDNATURA:","encontrado producto") + showShelving(index, shelvingIndex) + isBreak = true + break + } + shelvingIndex += 1 + } + if (isBreak) break + } + + //3- Por barcode + /*saleVO.Barcodes.forEach { barcode -> + if (txtscan == barcode){ + mpok!!.start() + isOk = true + markLine(index,type) + isBreak = true + } + } + if (isBreak) break*/ + } + index += 1 + } + if (!isOk) { + if (txtscan.contains("-")) { + if (tickets.size > 0) { + + + viewModel.parking( + ticketFk = tickets[0], + parking = txtscan + ) + + } + } else { + if (mperror != null) mperror!!.start() + } + + } + } else if (type == CONTROLADOR || type == PRECHECKER) { + + for (saleVO in sales) { + //0-Salegroup + + if (saleVO.isControlled == "0") { + //1- Por itemFk + if (txtscan == saleVO.itemFk.toString()) { + if (mpok != null) mpok!!.start() + isOk = true + markLine(index, type) + break + } + //2- Por barcode + saleVO.Barcodes.forEach { barcode -> + + if (txtscan == barcode) { + if (mpok != null) mpok!!.start() + isOk = true + markLine(index, type) + isBreak = true + } + } + + if (isBreak) break + } + index += 1 + } + //Lo escaneado no encontrado miramos si es parking o ticket + if (!isOk) { + if (txtscan.contains("-")) { + + + if (tickets.size > 0) { + + ticketToParking = tickets[0] + ticketScanTxt = txtscan + //#tarea4107 + viewModel.collection_getUncheckedTicket( + collectionFk = tickets[0].toInt() + ) + } + + } else { + binding.splashProgress.visibility = + VISIBLE + storedPosition = 0 + storedBackPosition = 0 + // if (type != PRECHECKER) { + isMarking = false + try { + viewModel.collectionTicketGet( + txtscan.toInt(), + getDataInt(SECTORFK), + print = "0", + type + ) + + } catch (ex: Exception) { + binding.splashProgress.visibility = GONE + ma.messageWithSound( + getString(R.string.error), + isError = false, + isPlayed = false + ) + } + + if (type.equals(CONTROLADOR)) { + //Tarea #4280 cambiar a ticket_isOutClosureZone + viewModel.ticket_isOutClosureZone( + txtscan.toInt() + + ) + } + + } + } + } + + } + + private fun findSale(txtscan: String, position: Int) { + var isOk = false + if (type == SACADOR) { + var saleVO = sales[position] + + if (saleVO.isPrepared != "1" && saleVO.isPreviousPrepared != "1") { + //1- Por itemFk + /*if (txtscan == saleVO.itemFk){ + if (mpok != null) mpok!!.start() + isOk = true + markLine(position,type) + + }*/ + if (!isOk) { + //2- Por carro + var shelvingIndex = 0 + for (placementVO in saleVO.placements) { + if (txtscan.uppercase() == placementVO.shelving.uppercase()) { + if (mpok != null) mpok!!.start() + isOk = true + showShelving(position, shelvingIndex) + break + } + shelvingIndex += 1 + } + } + /* + if (!isOk){ + //3- Por barcode + saleVO.Barcodes.forEach { barcode -> + if (txtscan == barcode){ + if (mpok != null) mpok!!.start() + isOk = true + markLine(position,type) + } + } + }*/ + } + if (!isOk) { + if (txtscan.contains("-")) { + tickets.forEach { + viewModel.parking( + ticketFk = it, + parking = txtscan + ) + } + + } else { + if (mperror != null) mperror!!.start() + } + + } + } + + } + + //Tarea #4371 + private fun markLine(position: Int, newType: String) { + state = 0 + //////Log.i("VERDNATURA:","Marcamos linea y enviamos saleTracking") + if (type == SACADOR) { + sales[position].isPrepared = if (sales[position].isPrepared == "1") "0" else "1" + if (sales[position].isPrepared == "1") { + sales[position].pickedQuantity = sales[position].quantity!! + } + checkStateParent() + } else if (type == CONTROLADOR) { + sales[position].isControlled = if (sales[position].isControlled == "1") "0" else "1" + //En primera instancia coge el primer elemento hijo para realizar la copia y según se va interactuando con las sales ya se actualiza el + // estado del padre + checkStateParent() + + } + + if (type == PRECHECKER) { + sales[position].isPreControlled = + if (sales[position].isPreControlled == "1") "0" else "1" + checkStateParent() + + } + + //Tarea #4371 se quita y se deja en el response de viewmodel saleTracking_mark + //saleAdapter!!.notifyDataSetChanged() + //setListPosition(position, false) + + if (type == SACADOR) { + saleTracking_mark(position, newType) + //saleTrackingReplace(position,newType) + } else { + saleAdapter!!.notifyDataSetChanged() + saleTrackingReplace(position, newType) + setListPosition(position, false) + } + isMarking = true + setTotalLines() + } + + private fun checkStateParent() { + for (s in myGroupList) { + if (s.isParent) { + var totalLines = s.sonSales.size + var isPreviousPrepared = s.sonSales.filter { it.isPreviousPrepared == "1" }.size + var isPrepared = s.sonSales.filter { it.isPrepared == "1" }.size + var isControlled = s.sonSales.filter { it.isControlled == "1" }.size + var isPreControlled = s.sonSales.filter { it.isPreControlled == "1" }.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) { + storedPosition = position + //tarea #4628, se asigna storedBackPosition + storedBackPosition = position + + if (type == SACADOR || getData(SECTORDESCRIP).uppercase() == getString( + R.string.sectorALGEMESINEW + ) + || type == PRECHECKER + ) { + var myPosition = position + + if (type == CONTROLADOR && getData(SECTORDESCRIP).uppercase() == getString( + R.string.sectorALGEMESINEW + ) + ) { + if (position > 0) { + var totalPrevias = 0 + + for (s in myGroupList) { + if (s.isParent) { + totalPrevias += s.sonSales.size + myPosition = position - totalPrevias + 1 + + } + + } + } else { + myPosition = position + } + } + if (binding.fragmentSacadorCollections != null) { + binding.fragmentSacadorCollections.addViewObserver { + lm!!.scrollToPositionWithOffset(myPosition, 0) + } + + } + + } else if (isFromBack) { + + if (binding.fragmentSacadorCollections != null) { + binding.fragmentSacadorCollections.addViewObserver { + lm!!.scrollToPositionWithOffset(position, 0) + } + } + } + + + } + + private fun saleTrackingReplace(position: Int, type: String) { + + //Tarea #4371 se quita para ver si funciona correctamente + //binding.splashProgress.visibility=VISIBLE + viewModel.saleTrackingReplace( + saleFk = sales[position].saleFk, + vIsChecked = if (type == SACADOR) sales[position].isPrepared else if (type == CONTROLADOR) sales[position].isControlled else if (type == "PRECHECKER") sales[position].isPreControlled else "1", + vOriginalQuantity = sales[position].pickedQuantity!!, + vStateFk = if (type == CONTROLADOR) "CHECKED" else if (type == "PRECHECKER") "PREVIOUS_CONTROL" else type,//type.toString(), + vBuyFk = originalItemScan!!, + vIsScanned = isScanned + + ) + + } + + + //Tarea #4371 se quita para ver si funciona correctamente + private fun saleTracking_mark(position: Int, type: String) { + + binding.splashProgress.visibility = VISIBLE + viewModel.run { + saleTracking_mark( + saleFk = sales[position].saleFk, + vIsChecked = if (type == SACADOR) sales[position].isPrepared else if (type == CONTROLADOR) sales[position].isControlled else if (type == "PRECHECKER") sales[position].isPreControlled else "1", + vOriginalQuantity = sales[position].pickedQuantity!!, + vStateFk = if (type == CONTROLADOR) "CHECKED" else if (type == "PRECHECKER") "PREVIOUS_CONTROL" else type,//type.toString(), + vBuyFk = originalItemScan!!, + vItemShelvingFk = itemShelvingTracking_mark, + vQuantity = customDialogList.getValue().toInt(), + vIsScanned = isScanned + + ) + } + isScanned = null + + } + + private fun unMarkLine(position: Int, newType: String) { + state = 0 + if (sales[position].isPrepared == "1") { + 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].isPrepared = "0" + sales[position].pickedQuantity = 0 + saleAdapter!!.notifyDataSetChanged() + setListPosition(position, false) + if (type != PRECHECKER) { + + + binding.splashProgress.visibility = VISIBLE + + viewModel.itemShelving_updateFromSale( + sales[position].saleFk + ) + positionUnmarked = position + + /* viewModel.saleTrackingDel( + getData(USER), + getData(PASSWORD), + saleFk = sales[position].saleFk, + "saleTracking_del" + )*/ + + + } + setTotalLines() + scanRequest() + customDialog.dismiss() + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() + } + + } + + //SHELVINGS + private fun showShelving(position: Int, shelvingPosition: Int) { + storedShelvingPosition = shelvingPosition + storedPosition = position + binding.splashProgress.visibility = VISIBLE + var quantityGet = 0 + try { + quantityGet = + (sales[position].quantity!! - sales[position].pickedQuantity!!.toInt()) + } catch (e: Exception) { + } + //Log.i("VERDNATURA:","Aparece para enviar") + viewModel.itemPlacementSupplyAiming( + itemFk = sales[position].itemFk, + quantity = quantityGet, + shelvingFk = sales[position].placements[shelvingPosition].shelving + + ) + } + + @RequiresApi(Build.VERSION_CODES.O) + private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) { + //////Log.i("VERDNATURA:","Print CustomDialog") + var shelving = "" + var item = "" + var longName = "" + var total = "0" + var itemShelvingFk = 0 + if (!placementSupplyListVO.list.isEmpty()) { + var placement: PlacementSupplyVO? = null + placementSupplyListVO.list.forEach { placementVO -> + if (placementVO.stock != "0" && placement == null) + placement = placementVO + } + if (placement != null) { + shelving = placement!!.shelving + item = placement!!.itemFk + longName = placement!!.longName + total = placement!!.total + itemShelvingFk = placement!!.itemShelvingFk + } + + } + listPlacementSupply = ArrayList() + placementSupplyListVO.list.forEach { + if (it.stock != "0") + listPlacementSupply.add(BarcodeVO(code = it.proposal)) + //////Log.i("VERDNATURA:","Array de placementsupply") + } + try { + // Log.i("VERDNATURA:","Pulso COGER-1") + customDialogList.setTitle("$shelving($item) $total de $longName").setOkButton( + getString( + R.string.take + ) + ) { + + if (customDialogList.getValueTwo().isNotEmpty()) { + isScanned = false + /*Tarea #5109*/ + customDialogList.setValueTwo( + itemScanValue( + customDialogList.getValueTwo(), + "buy", + "more" + ).toString() + ) + + + + if (isNumber(customDialogList.getValue()) && isNumber(total) && customDialogList.getValue() + .toInt() > total.toInt() + ) { + getString(R.string.quantityHigh).toast(requireContext()) + } else if (isNumber(customDialogList.getValue())) { + originalItemScan = customDialogList.getValueTwo().toInt() + // Log.i("VERDATURA","Le pasamos el siguiente item $originalItemScan que es el escaneado") + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + //Log.i("VERDNATURA:","Cantidad seleccionada") + mpok?.start() + /* Se quita para comprobar al final de saleTracking_mark + ReviewQuantityForRefreshingAndSorting( + customDialogList.getValue().toInt(), + sales[storedPosition].quantity!!.toInt(), + sales[storedPosition].pickedQuantity.toInt() + )*/ + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = + VISIBLE + + viewModel.getIdFromCodeSalix( + code = customDialogList.getValueTwo(), + ) + /* } else { + viewModel.getIdFromCode( + usuario = getData(USER), + password = getData(PASSWORD), + code = customDialogList.getValueTwo(), "barcodeToItem" + ) + }*/ + + customDialogList.dismiss() + } + scanRequest() + hideKeyboards() + } else { + getString(R.string.quantityError).toast(requireContext()) + } + + } 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() + } catch (e: Exception) { + ma.messageWithSound(e.message.toString(), true, true) + } + try { + customDialogList.getEditTextTwo().post(Runnable { + customDialogList.getEditTextTwo().requestFocusFromTouch() + if (activity != null) { + val lManager: InputMethodManager = + requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + lManager.hideSoftInputFromWindow( + customDialogList.getEditTextTwo().windowToken, + InputMethodManager.SHOW_FORCED + ) + } + + }) + } catch (e: Exception) { + } + try { + customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) + + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + + /*Tarea 4729*/ + isScanned = + event != null && event.action == ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + + customDialogList.setValueTwo( + itemScanValue( + customDialogList.getValueTwo(), + "buy", + "more" + ).toString() + ) + + + // Log.i("VERDNATURA:","Comprobando COGER-1") + if (customDialogList.getValueTwo().isNotEmpty()) { + try { + if (isNumber(customDialogList.getValue()) && customDialogList.getValue() + .toInt() > total.toInt() + ) { + getString(R.string.quantityHigh).toast(requireContext()) + } else if (isNumber(customDialogList.getValue())) { + originalItemScan = customDialogList.getValueTwo().toInt() + + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + /* ReviewQuantityForRefreshingAndSorting( + customDialogList.getValue().toInt(), + sales[storedPosition].quantity!!.toInt(), + sales[storedPosition].pickedQuantity.toInt() + )*/ + // SalesSorter(sales) + + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = View.VISIBLE + + + viewModel.getIdFromCodeSalix( + code = customDialogList.getValueTwo() + ) +/* + } else { + viewModel.getIdFromCode( + getData(USER), + getData(PASSWORD), + code = customDialogList.getValueTwo(), "barcodeToItem" + ) + }*/ + customDialogList.dismiss() + scanRequest() + } + } else { + getString(R.string.quantityError).toast(requireContext()) + } + + } catch (e: Exception) { + + } + + } else { + getString(R.string.scanItemValidate).toast(requireContext()) + } + scanRequest() + hideKeyboards() + return@setOnEditorActionListener true + + } + false + } + } catch (e: Exception) { + ma.messageWithSound(e.message.toString(), true, true) + } + + 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 ReviewQuantityForRefreshingAndSorting( + quantityTotal: Int, + quantityPicked: Int + ) { + + if (quantityPicked < quantityTotal) { + + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + } else { + setStoredPosition(false) + + } + + } + + private fun setStoredPosition(isFromBack: Boolean) { + /* if (type == SACADOR) { + + for (indice in myGroupList.indices) { + if (myGroupList[indice].isPrepared == "0") { + storedPosition = if (indice != 0) { + indice - 1 + } else { + indice + } + break + } + }*/ + + setListPosition(storedPosition, isFromBack) + } + + + private fun checkItemScan(valueToCheck: String): Boolean { + d("VERDNATURA::", "Entramos a ver el checkItem") + if (storedPosition >= 0 && sales.size > storedPosition) { + val saleToCheck = sales[storedPosition] + + if (saleToCheck.itemFk.toString() == valueToCheck) + return true + else { + saleToCheck.Barcodes.forEach { barcode -> + if (barcode == valueToCheck) + return true + } + } + } + d("VERDNATURA::", "SAlimos de ver el checkItem") + return false + } + + //Tarea #4371 + private fun onQuantityOfShelvingSelected(itemShelvingFk: Int, quantity: Int = 0) { + //1 - MODIFICAR CANTIDAD DEL CARRO + try { + val shelvingVisible = + sales[storedPosition].placements[storedShelvingPosition].visible.substring( + 1, + sales[storedPosition].placements[storedShelvingPosition].visible.indexOf(")") + ) + + if (quantity == 0) { + sales[storedPosition].placements[storedShelvingPosition].visible = + "(" + (shelvingVisible.toInt() - customDialogList.getValue() + .toInt()).toString() + ")" + } else { + sales[storedPosition].placements[storedShelvingPosition].visible = + "(" + (shelvingVisible.toInt() - quantity.toInt()).toString() + ")" + } + //Tarea #4371 se quita para ver si funciona correctamente + /*viewModel.itemShelvingSaleSupplyAdd( + getData(USER), + getData(PASSWORD), + itemShelvingFk = itemShelvingFk, + saleFk = sales[storedPosition].saleFk, + quantity = if (quantity != "0") quantity else customDialogList.getValue() + + )*/ + + + } catch (e: Exception) { + } + + //2- MODIFICAR EL PICKED DEL SALE + try { + if (quantity == 0) { + sales[storedPosition].pickedQuantity = + (sales[storedPosition].pickedQuantity!! + customDialogList.getValue() + .toInt()) + } else { + sales[storedPosition].pickedQuantity = + (sales[storedPosition].pickedQuantity!! + quantity + .toInt()) + } + } catch (e: Exception) { + } + + //3- MARCAR LINEA + + //Tarea #4371 + itemShelvingTracking_mark = itemShelvingFk + + if (sales[storedPosition].pickedQuantity != sales[storedPosition].quantity) { + sales[storedPosition].isPrepared = "1" + markLine(storedPosition, OK) + } else { + markLine(storedPosition, type) + } + + } + + //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)) + } + 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)) { + + if (ticketSelected == 0) { + getString(R.string.Seleccionaunticketdelaista).toast(requireContext()) + } else if (customDialogList.getValue() + .isNullOrEmpty() || customDialogList.getValueTwo().isNullOrEmpty() + ) { + getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) + } else { + binding.splashProgress.visibility = + VISIBLE + + //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 = getDataInt(WAREHOUSEFK) + ) + + + scanRequest() + customDialogList.dismiss() + } + + }.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() + hideKeyboards() + + 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(), true, true) + } + customDialogList.getEditTextTwo().requestFocus() + } + //hideKeyboards() + 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) { + 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 { + binding.splashProgress.visibility = + VISIBLE + + 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 = getDataInt(WAREHOUSEFK) + ) + scanRequest() + customDialogList.dismiss() + } + } + hideKeyboards() + return@setOnEditorActionListener true + scanRequest() + customDialogList.dismiss() + } + 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 showDisponibility() { + + customDialogInput.setTitle(getString(R.string.Verdisponible)) + .setDescription(getString(R.string.Escaneaetiqueta)) + .setOkButton(getString(R.string.Buscar)) { + try { + if (binding.splashProgress != null) { + binding.splashProgress.visibility = View.VISIBLE + } + + } catch (e: Exception) { + } + + hideKeyboards() + viewModel.itemGetAvailable( + usuario = user, + password = password, + itemFk = customDialogInput.getValue(), + warehouseFk = warehouseFk, + "item_GetVisibleAvailable" + ) + scanRequest() + customDialogInput.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + if (binding.splashProgress != null) { + binding.splashProgress.visibility = View.GONE + } + hideKeyboards() + scanRequest() + customDialogInput.dismiss() + }.setValue("").show() + customDialogInput.getEditText().requestFocus() + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + if (binding.splashProgress != null) binding.splashProgress.visibility = View.VISIBLE + viewModel.itemGetAvailable( + usuario = user, + password = password, + itemFk = customDialogInput.getValue(), + warehouseFk = warehouseFk + ,"item_GetVisibleAvailable") + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + return@setOnEditorActionListener true + } + false + } + }*/ + + 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() { + + var totalMark = 0 + sales.forEach { + if (type == SACADOR) { + if (it.isPrepared == "1" || it.isControlled == "1" || it.isPreviousPrepared == "1") { + totalMark += 1 + } else if (it.quantity == 0) { + totalMark += 1 + } + } else if (type == CONTROLADOR) { + if ((it.isControlled == "1" || it.isControlled == "2") && !it.isParent) + totalMark += 1 + + }//Refactor #4030 + else if (type == PRECHECKER) { + if (it.isPreControlled == "1") { + totalMark += 1 + } + + } + } + + if (binding.mainToolbar.toolbarTitle != null) 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 + + if (binding.mainToolbar.toolbarSubtitle != null && totalMark != null) binding.mainToolbar.toolbarSubtitle.text = + "" + totalMark + "/" + total + + if (totalMark == sales.size) { + getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) + saleAdapter!!.notifyDataSetChanged() + + if (!goBack) + ticketCollection_setUsedShelves() + goBack = false + + changeTicketState() + + + } + } + + + private fun ticketCollection_setUsedShelves() { + + + if (type.equals("CHECKER") && (isMarking && (getData(SECTORDESCRIP).uppercase() != getString( + R.string.sectorALGEMESI + ) && getData(SECTORDESCRIP).uppercase() != getString( + R.string.sectorALGEMESINEW + ) + )) + ) { + + + customDialogInput.setTitle(getString(R.string.shlevesNumber)) + .setDescription(getString(R.string.shlevesNumberTicket)) + .setOkButton(getString(R.string.accept)) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + + binding.splashProgress.visibility = VISIBLE + viewModel.ticketCollection_setUsedShelves( + ticketFk = collection.collectionFk, + usedShelves = customDialogInput.getValue().toInt() + ) + hideKeyboards() + // showKeyboards() + + } + customDialogInput.setValue("") + customDialogInput.dismiss() + showKeyboards() + //hideKeyboards() + //showKeyboards() + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + // hideKeyboards() + showKeyboards() + }.setValue("").show() + + customDialogInput.setInputText() + // customDialogInput.currentFocus + customDialogInput.setFocusText() + showKeyboards() + + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + + binding.splashProgress.visibility = VISIBLE + viewModel.ticketCollection_setUsedShelves( + ticketFk = collection.collectionFk, + usedShelves = customDialogInput.getValue().toInt() + ) + hideKeyboards() + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + return@setOnEditorActionListener true + } + false + } + + + } + + + } + + private fun item_updatePackingShelve(itemFk: Int) { + + + isMarking = false + customDialogInput.setTitle(getString(R.string.packetNumberShelves)) + .setDescription(getString(R.string.packetIndicate)) + .setOkButton(getString(R.string.accept)) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + + binding.splashProgress.visibility = VISIBLE + viewModel.item_updatePackingShelve( + vSelf = itemFk, + vPacking = customDialogInput.getValue().toInt() + ) + hideKeyboards() + //showKeyboards() + + } + customDialogInput.setValue("") + customDialogInput.dismiss() + // hideKeyboards() + showKeyboards() + }.setKoButton(getString(R.string.cancel)) { + + customDialogInput.dismiss() + //hideKeyboards() + showKeyboards() + }.setValue("").show() + + customDialogInput.setInputText() + customDialogInput.currentFocus + customDialogInput.setFocusText() + showKeyboards() + + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + + binding.splashProgress.visibility = VISIBLE + viewModel.item_updatePackingShelve( + vSelf = itemFk, + vPacking = customDialogInput.getValue().toInt() + ) + + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + return@setOnEditorActionListener true + } + false + } + + } + + private fun showBottomNavigation(visibilitiy: Int) { + //requireActivity().main_bottom_navigation.visibility = visibilitiy + } + +//FALTAS / BASURA / SPLIT + + + private fun showQuantityDialog(position: Int) { + customDialogThreeButtons.setDescription(getString(R.string.txtnuevacantidad)) + .setValue("") + + //Tarea4495 + // if (type != SACADOR) { + /* customDialogThreeButtons.setOkButton(getString(R.string.titleFaults)) { + checkAndCall( + position, + customDialogThreeButtons.getValue(), + getString(R.string.titleFaults) + ) + + }.setOkButtonTwo(getString(R.string.BasuraRechazar)) { + + checkAndCall( + position, + customDialogThreeButtons.getValue(), + getString(R.string.BasuraRechazar) + ) + } + // } + + customDialogThreeButtons.setOkButtonThree(getString(R.string.Reject)) { + checkAndCall( + position, + customDialogThreeButtons.getValue(), + getString(R.string.Reject) + ) + + }.setOkButtonFour(getString(R.string.Split)) { + checkAndCall( + position, + customDialogThreeButtons.getValue(), + getString(R.string.Split) + )*/ + + + .setOkButtonAdd(getString(R.string.Agregar)) { + /* checkAndCall( + position, + customDialogThreeButtons.getValue(), + getString(R.string.Agregar) + )*/ + increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) + scanRequest() + customDialogThreeButtons.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialogThreeButtons.dismiss() + }.show() + customDialogThreeButtons.setFocusDialogValue() + } + +/* private fun checkAndCall(position: Int, value: String, action: String) { + if (value.trim().isNullOrEmpty()) { + getString(R.string.Indicanuevacantidad).toast(requireContext()) + } else { + + when (action) { + getString(R.string.Agregar) -> increaseQuantity(position, value.toInt()) + getString(R.string.BasuraRechazar) -> TrashMissingReject( + position, + value.toInt(), + "TRUE" + ) + getString(R.string.titleFaults) -> TrashMissingReject( + position, + value.toInt(), + "FALSE" + ) + getString(R.string.Reject) -> TrashMissingReject( + position, + value.toInt(), + "reject" + ) + getString(R.string.Split) -> split(position, value.toInt()) + + } + + scanRequest() + customDialogThreeButtons.dismiss() + } + }*/ + +/* private fun split(position: Int, quantity: Int) { + + //sergio: SPLIT SALIX + + quantityCollectionSplit = quantity + positionCollectionSplit = position + + var totalQuantity: Int = 0 + try { + totalQuantity = sales[position].quantity!!.toInt() - quantity.toInt() + } catch (e: Exception) { + } + + + viewModel.transferSalesSalix( + ticketFk = sales[position].ticketFk, + saleFk = sales[position].saleFk, + quantity = totalQuantity.toString() + ) + + }*/ + +/* private fun TrashMissingReject( + position: Int, + quantity: Int, + typeCollectionTrashMissingReject: String + ) { + typeCollectionMissing = typeCollectionTrashMissingReject + positionCollectionMissing = position + quantityCollectionMissing = quantity + + var totalQuantity: Int = 0 + try { + totalQuantity = sales[position].quantity!!.toInt() - quantity.toInt() + } catch (e: Exception) { + } + + viewModel.collectionMissingTrash( + saleFk = sales[position].saleFk, + quantity = totalQuantity.toString(), + warehouseFk = getData(WAREHOUSEFK), + type = typeCollectionTrashMissingReject, + originalQuantity = quantity + ) + + }*/ + + + private fun missingTrashSuccesful() { + + var message = "" + + sales[positionCollectionMissing].quantity = quantityCollectionMissing + saleAdapter!!.notifyDataSetChanged() + if (quantityCollectionMissing == 0) + markLine(positionCollectionMissing, type) + + var totalQuantity: Int = 0 + try { + totalQuantity = + sales[positionCollectionMissing].originalQuantity!!.toInt() - quantityCollectionMissing.toInt() + } catch (e: Exception) { + } + + saleAdapter!!.notifyDataSetChanged() + + val ticket = + "[" + sales[positionCollectionMissing].ticketFk + "](https://salix.verdnatura.es/#!/ticket/" + sales[positionCollectionMissing].ticketFk + "/summary)" + + + when (typeCollectionMissing) { + + "TRUE" -> { + message = + "Se ha enviado a Basura " + totalQuantity + getString(R.string.fromItem) + sales[positionCollectionMissing].itemFk + " ticket " + ticket + + } + "FALSE" -> { + message = + "Se ha enviado a Faltas la cantidad de " + totalQuantity + getString(R.string.fromItem) + sales[positionCollectionMissing].itemFk + " ticket " + ticket + + } + "reject" -> { + message = + "Se ha modificado la cantidad de " + sales[positionCollectionMissing].originalQuantity + " del artículo " + sales[positionCollectionMissing].itemFk + " a nueva cantidad: " + sales[positionCollectionMissing].quantity + " del ticket " + ticket + + } + } + + //sergio:ahora desde encajado + // sendSalixMessageNew(message, sales[positionCollectionMissing].salePersonFk) + + binding.splashProgress.visibility = VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + } + + private fun incresaseSuccesful() { + try { + //val quantityPicked = (quantity.toInt() - sales[position].quantitytoInt()).toString() + // sergio: se añade linea para que se actualice la originalQuantity + //sales[positionIncreaseQuantity].originalQuantity = quantityIncrease + + sales[positionIncreaseQuantity].quantity = quantityIncrease + + } catch (e: Exception) { + } + saleAdapter?.notifyDataSetChanged() + //enviar mensaje a salix + + val ticket = + "[" + sales[positionIncreaseQuantity].ticketFk + "](https://salix.verdnatura.es/#!/ticket/" + sales[positionIncreaseQuantity].ticketFk + "/summary)" + val message = + "Se ha modificado la cantidad original " + sales[positionIncreaseQuantity].originalQuantity + " del artículo " + sales[positionIncreaseQuantity].itemFk + " a nueva cantidad: " + sales[positionIncreaseQuantity].quantity + " del ticket " + ticket + + + //sergio: ahora desde encajadores + // sendSalixMessageNew(message, sales[positionIncreaseQuantity].salePersonFk) + + sales[positionIncreaseQuantity].originalQuantity = quantityIncrease + + } + + private fun sendSalixMessageNew(message: String, workerId: String) { + + viewModel.sendChekingPresence( + workerId = workerId, + message = message + + ) + } + + private fun increaseQuantity(position: Int, quantity: Int) { + positionIncreaseQuantity = position + quantityIncrease = quantity + + viewModel.collectionIncreaseQuantitySalix( + saleFk = sales[position].saleFk, + quantity = quantity.toString() + ) + + + } + + //ESTADOS + private fun changeTicketState() { + if (type == CONTROLADOR) { + tickets.forEach { + viewModel.ticket_setState( + ticketFk = it.toInt(), + state = "CHECKED" + ) + } + } else if (type == SACADOR) { + tickets.forEach { + viewModel.ticket_setState( + ticketFk = it.toInt(), + state = "PREPARED" + ) + } +////Refactor #4030 + + } else if (type == PRECHECKER) { + tickets.forEach { + viewModel.ticket_setState( + ticketFk = it.toInt(), + state = "PREVIOUS_CONTROLLED" + ) + } + } + } + + + //OTROS + private fun showScanner(index: Int, sale: SaleVO) { + customDialogInput.getEditText().inputType = TYPE_CLASS_TEXT + customDialogInput.setTitle("" + sale.itemFk) + .setDescription(getString(R.string.scanWagonForItem)) + .setOkButton(getString(R.string.accept)) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(), index) + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + }.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) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(), index) + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + return@setOnEditorActionListener true + } + false + } + + } + + private fun showErrorMessage(text: String) { + customDialog.setTitle(getString(R.string.errorMarkLine)).setDescription(text) + .setKoButton(getString(R.string.close)) { + customDialog.dismiss() + }.show() + } + + private fun showDialogLabelCount() { + //tarea#4672 + var isTicket = false + for (t in collection.tickets) { + if (t.ticketFk.toInt() == (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) + getData(PRINTERNAME)).toast(requireContext()) + + } + val dialog = builder.create() + dialog.show() + } else { + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, + null + ) + + } + + + } + + private fun showMistakeList(list: List) { + + customDialogInput.dismiss() + binding.splashProgress.visibility = GONE + listPlacementSupply = ArrayList() + list.forEach { + listPlacementSupply.add(BarcodeVO(code = it.description)) + } + + customDialogList.setTitle(getString(R.string.errorCause)) + customDialogList.hideTextInput() + .setKoButton(getString(R.string.cancel)) { + scanRequest() + hideKeyboards() + listPlacementSupply.clear() + customDialogList.dismiss() + + }.show() + + + placementSupplyAdapter = + BarcodeAdapter(listPlacementSupply, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + list.forEach { + if (it.description == item.code) { + + viewModel.saleMistakeAdd( + vSaleFk = mistakeSale?.saleFk!!, + vTypeFk = it.id + ) + + + getString(R.string.errorRegistered).toast(requireContext()) + customDialogList.dismiss() + } + } + + } + }, showDelete = false) + + customDialogList.getRecyclerView().adapter = placementSupplyAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + } + + 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() + + for ((key, value) in myMap.entries) { + if (key.isNullOrEmpty()) { // 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 = SaleVO( + saleOrder = value[0].saleOrder, + workerFk = value[0].workerFk, + originalQuantity = null, + quantity = null, + rgb = null, + saleFk = value[0].saleFk, + saleGroupFk = value[0].saleGroupFk, + isPreControlled = value[0].isPreControlled, + isPrepared = value[0].isPrepared, + isPreviousPrepared = value[0].isPreviousPrepared, + isControlled = value[0].isControlled, + line3 = value[0].code, + picked = value[0].picked, + ticketFk = value[0].ticketFk, + level = value[0].level + + )//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.picked }) 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 myList + } + +} + + 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 87b83d84..f6784632 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 @@ -26,6 +26,7 @@ import es.verdnatura.presentation.view.feature.buffer.fragment.BufferLoadFragmen import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment 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.CollectionFragmentPreChecker import es.verdnatura.presentation.view.feature.collection.fragment.CollectionShowTicketFragment import es.verdnatura.presentation.view.feature.controlador.fragment.ControladorFragment import es.verdnatura.presentation.view.feature.controlador.fragment.WebFragment @@ -733,6 +734,10 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL "SHOWTICKET" -> { addFragmentOnTop(CollectionShowTicketFragment.newInstance(collection, type)) } + //Tarea 4711 + "PRECHECKER"->{ + addFragmentOnTop(CollectionFragmentPreChecker.newInstance(collection, type)) + } else -> { addFragmentOnTop(CollectionFragment.newInstance(collection, type))