From ecbea7fa6ca533f39b9d586a81b76293f6ec3ff9 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 10 Oct 2023 09:59:18 +0200 Subject: [PATCH] refs #5890 --- .../presentation/common/SalixBackItems.kt | 6 + .../presentation/common/UICallbacks.kt | 21 +- .../collection/adapter/SaleAdapterNew.kt | 346 +++ .../fragment/CollectionFragmentPickerNew.kt | 2401 +++++++++++++++++ .../sacador/adapter/CollectionAdapterNew.kt | 49 + .../sacador/fragment/SacadorFragmentNew.kt | 280 ++ .../res/layout/item_article_row_fragment.xml | 2 +- .../res/layout/item_collection_row_new.xml | 67 + app/src/main/res/layout/sale_row_fragment.xml | 686 +++++ app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-pt/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 13 files changed, 3865 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt create mode 100644 app/src/main/res/layout/item_collection_row_new.xml create mode 100644 app/src/main/res/layout/sale_row_fragment.xml diff --git a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt index 53987ec0..f8fc84b8 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt @@ -10,3 +10,9 @@ class packingSiteSalix( var workerFk: Int ) + +data class ItemShelvingSaleSalix( + var id:Int, + var quantity:Int, + var isItemShelvingSaleEmpty:Boolean? +) diff --git a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index 8d00071c..8093c824 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -19,7 +19,9 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionT import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.reubication.model.Reubication +import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import es.verdnatura.presentation.view.feature.sacador.model.Sale import es.verdnatura.presentation.view.feature.sacador.model.SaleVO import es.verdnatura.presentation.view.feature.smarttag.model.SmartTag import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO @@ -159,18 +161,32 @@ interface OnCollectionSelectedListener { fun onCollectionSelected(collection: CollectionVO, type: String) } +interface OnCollectionTicketSelectedListener { + fun onCollectionSelected(collection: CollectionTicket, type: String) +} + interface OnQuantityClickListener { fun onQuantityClick(sale: SaleVO) } +interface OnQuantityClickSaleListener { + fun onQuantityClick(sale: Sale) +} + interface onPackingClickListener { fun onPackingClick(sale: SaleVO) } +interface OnPackingClickSaleListener { + fun onPackingClick(sale: Sale) +} + interface OnSaleClickListener { fun onSaleClick(sale: SaleVO) } - +interface OnSaleClickSaleListener { + fun onSaleClick(sale: Sale) +} interface OnReubicationClickListener { fun onReubicationClick(reubication: Reubication) } @@ -182,6 +198,9 @@ interface OnMistakeClickListener { interface OnTicketClickListener { fun onTicketClickListener(sale: SaleVO) } +interface OnTicketClickSaleListener { + fun onTicketClickListener(sale: Sale) +} interface OnBuyerSelectedListener { fun onBuyerSelected(userFk: String) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt new file mode 100644 index 00000000..c9f3fbb4 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt @@ -0,0 +1,346 @@ +package es.verdnatura.presentation.view.feature.collection.adapter + +import android.content.Context +import android.content.res.ColorStateList +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.content.ContextCompat.getColor +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.SaleRowFragmentBinding +import es.verdnatura.domain.ConstAndValues.SACADOR +import es.verdnatura.presentation.common.OnMistakeClickListener +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.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.sacador.model.Sale + + +class SaleAdapterNew( + private val items: List, + private val onPasillerosItemClickListener: OnPasillerosItemClickListener, + private val onQuantityClick: OnQuantityClickSaleListener, + private val onSaleClickListener: OnSaleClickSaleListener, + private val onMistakeClickListener: OnMistakeClickListener, + private val onPackingClick: OnPackingClickSaleListener, + private var onTicketClick: OnTicketClickSaleListener? = null, + private var SaleAdapter: SaleAdapterNew? = null, + private var type: String? = null, + + ) : RecyclerView.Adapter() { + var context: Context? = null + var position: Int = 0 + + var isExpanded: Boolean = type == "PRECHECKER" + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { + this.context = parent.context + + + return AjustesItemHolder( + + SaleRowFragmentBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + ) + } + + override fun getItemCount() = items.size + + override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) { + this.position = position + holder.bind(items[position]) + } + + inner class AjustesItemHolder( + val binding: SaleRowFragmentBinding + ) : RecyclerView.ViewHolder(binding.root) { + fun bind(sale: Sale) { + binding.apply { + if (sale.reservedQuantity == null) + sale.reservedQuantity = 0 + + val childLayoutManager = + LinearLayoutManager(context!!, RecyclerView.HORIZONTAL, false) + + val childLayoutManagerV = + LinearLayoutManager(context!!, RecyclerView.VERTICAL, false) + + + itemArticlePlacements.apply { + layoutManager = childLayoutManager + + // se quita porque ya no es necesario + // adapter = PlacementAdapter(sale.placements, onPasillerosItemClickListener) + } + + //CLICK EVENTS + contentLayout.setOnClickListener { + if (!sale.isParent) { + onSaleClickListener.onSaleClick(sale) + } + } + + itemArticleItemFk.setOnClickListener { + onPasillerosItemClickListener.onPasillerosItemClickListener( + PasillerosItemVO( + title = binding.root.context.getString(R.string.titleItemConsult) + ), sale.itemFk.toString() + ) + } + + itemPackingItemFk.setOnClickListener { + onPackingClick.onPackingClick(sale) + } + + itemArticleQuantity.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + itemArticleQuantityPicked.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + txtde.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + itemArticleFirstAccumulate.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + itemFirstToPicker.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + linearLayoutItem.setOnClickListener { + + println("El ticket es ${sale.ticketFk}") + if (onTicketClick != null) { + onTicketClick!!.onTicketClickListener(sale) + } + + } + + /*itemRowLayout.setOnLongClickListener{ + onMistakeClickListener.onMistakeClickListener(sale) + false + }*/ + + imageErrorMessage.setOnClickListener { + // onMistakeClickListener.onMistakeClickListener(sale) + false + } + + + //ERROR + if (sale.originalQuantity != sale.saleQuantity && sale.originalQuantity != null) { + layoutError.visibility = View.VISIBLE + txtError.text = + binding.root.context.getString(R.string.originalQuantity) + sale.originalQuantity!! + + } + + if (sale.isAdded == 1) { + layoutError.visibility = View.VISIBLE + txtError.text = binding.root.context.getString(R.string.newItem) + + } + + paintTicketcolor(sale.rgb, itemTicketColor, sale.isPicked) + + if (sale.isAdded == 1 && sale.reservedQuantity != sale.saleQuantity) { + layoutError.visibility = View.GONE + } + + if (sale.isPicked == 1) { + contentLayout.setBackgroundColor( + getColor( + context!!, + R.color.verdnatura_pumpkin_orange + ) + ) + } else { + contentLayout.setBackgroundColor( + getColor( + context!!, + R.color.verdnatura_black + ) + ) + + } + + + if (isExpanded) { + itemArticlePlacements.visibility = View.VISIBLE + ivArrow.setImageResource(R.drawable.ic_arrow_down) + + } else { + itemArticlePlacements.visibility = View.GONE + ivArrow.setImageResource(R.drawable.ic_arrow_up) + } + + itemArticlePlacements.visibility = if (isExpanded) View.VISIBLE else { + View.GONE + } + + if (sale.isParent) { + itemArticleItemFk.visibility = View.INVISIBLE + itemPackingText.visibility = View.INVISIBLE + itemPackingItemFk.visibility = View.INVISIBLE + itemArticleCel1.visibility = View.INVISIBLE + itemArticleCel2.visibility = View.INVISIBLE + itemArticleCel3.visibility = View.INVISIBLE + itemArticleQuantity.visibility = View.INVISIBLE + txtdeNew.visibility = View.INVISIBLE + itemArticleQuantityPicked.visibility = View.INVISIBLE + itemArticleQuantityLine3.visibility = View.VISIBLE + imageErrorMessage.visibility = View.INVISIBLE + ivArrow.visibility = View.VISIBLE + + + } else { + /*itemArticleItemFk.visibility = View.VISIBLE + itemPackingText.visibility = View.VISIBLE + itemPackingItemFk.visibility = View.VISIBLE + itemArticleCel1.visibility = View.VISIBLE + itemArticleCel2.visibility = View.VISIBLE + itemArticleCel3.visibility = View.VISIBLE + itemArticleQuantity.visibility = View.VISIBLE + txtdeNew.visibility = View.VISIBLE + itemArticleQuantityPicked.visibility = View.VISIBLE + itemArticleQuantityLine3.visibility = View.VISIBLE*/ + if (type != SACADOR) { + val colorRes = + if (sale.hasMistake == true) R.color.verdnatura_red_salix else R.color.verdnatura_black + imageErrorMessage.imageTintList = + ColorStateList.valueOf(getColor(context!!, colorRes)) + imageErrorMessage.visibility = View.VISIBLE + } else { + imageErrorMessage.visibility = View.INVISIBLE + } + ivArrow.visibility = View.INVISIBLE + } + + if (!sale.sonSales.isNullOrEmpty()) { + itemArticlePlacements.apply { + layoutManager = childLayoutManagerV + adapter = SaleAdapterNew( + sale.sonSales, + onPasillerosItemClickListener, + onQuantityClick, + onSaleClickListener, + onMistakeClickListener, + onPackingClick + ) + } + + } else { + itemArticlePlacements.visibility = View.VISIBLE + } + + ivArrow.setOnClickListener { + + if (isExpanded!!) { + ivArrow.setImageResource(R.drawable.ic_arrow_up) + itemArticlePlacements.visibility = View.GONE + } else { + + ivArrow.setImageResource(R.drawable.ic_arrow_down) + itemArticlePlacements.visibility = View.VISIBLE + } + isExpanded = !isExpanded + + } + + // previA NUEVA + if (sale.saleGroupFk == null) { + previous.visibility = View.INVISIBLE + } else { + previous.visibility = View.VISIBLE + } + + var result: Int + var textToConcat: String + + result = sale.reservedQuantity % (sale.packing ?: sale.saleQuantity + 1) + if (result != 0) { + textToConcat = + "${sale.reservedQuantity / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}" + } else { + textToConcat = + "${sale.reservedQuantity / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}" + } + binding.itemArticleCel2.text = textToConcat + binding.itemFirstToPicker.text = textToConcat + + var result2: Int + var textToConcat2: String + + result2 = sale.accumulatedQuantity % (sale.packing ?: sale.saleQuantity + 1) + if (result2 != 0) { + textToConcat2 = + "${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}" + } else { + textToConcat2 = + "${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.packing ?: 1)} pack de ${sale.packing ?: "1"}" + } + + + if (sale.totalItemShelving > 1) { + binding.itemArticleCel1.text = textToConcat2 + binding.itemSecondToPicker.text = textToConcat2 + + binding.itemReservedNumber.text = + "${sale.currentItemShelving}/${sale.totalItemShelving}" + + binding.itemSecond.text = + "${sale.saleQuantity - sale.accumulatedQuantity} de ${sale.saleQuantity}" + binding.itemArticleSecondAccumulate.text = + "${sale.saleQuantity - sale.accumulatedQuantity} de ${sale.saleQuantity}" + } else { + binding.itemArticleCel1.text = "" + binding.itemReservedNumber.text = "" + binding.itemSecond.text = "" + binding.itemArticleSecondAccumulate.text = "" + binding.itemSecondToPicker.text = "" + } //segona linea començant per d'alt + + binding.itemArticleCel3.text = + "${sale.currentItemShelving}/${sale.totalItemShelving}" + + binding.itemArticleFirstAccumulate.text = + "${sale.reservedQuantity} de ${sale.saleQuantity}" + + + this.sale = sale + + } + } + } + + + private fun paintTicketcolor(color: String?, itemView: View, picked: Int) { + + if (color.isNullOrBlank()) { + itemView.setBackgroundColor( + if (picked == 0) { + (Color.TRANSPARENT) + } else { + (context!!.getColor(R.color.verdnatura_pumpkin_orange)) + }) + } else { + itemView.setBackgroundColor(Color.parseColor(color)) + } + + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..d86efbad --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt @@ -0,0 +1,2401 @@ +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.util.Log.d +import android.view.KeyEvent +import android.view.View +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.FragmentCollectionNewBinding +import es.verdnatura.domain.ConstAndValues.CONTROLADOR +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.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.* +import org.json.JSONObject + + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class CollectionFragmentPickerNew( + var collection: CollectionTicket, + 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: 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 var storedShelvingPosition: Int = 0 + 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 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: Long = 0 + private var workerFkFromTicket: String? = null + private var itemShelvingTracking_mark: Int = 0 + private var recylerViewState: Parcelable? = null + private var isScanned: Boolean? = null + private var positionConfirm = 0 + + private lateinit var myGroupList: List + + companion object { + fun newInstance(collection: CollectionTicket, type: String) = + CollectionFragmentPickerNew(collection, type) + } + + 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 + ) + + /* if (collection.tickets.isEmpty()) { + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + + } else { + viewModel.collectionTicketGetLocal( + 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()) + customDialogThreeButtonsQuantity = CustomDialogThreeButtons(requireContext()) + ma.hideBottomNavigation(View.GONE) + binding.splashProgress.visibility = View.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 = 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) + + 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) + listIcons.add(iconAdd) + 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() { + binding.splashProgress.visibility = View.VISIBLE + viewModel.collectionTicketGetSalix( + collection.collectionFk, + print = false + ) + /* viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + )*/ + } + + + private fun markPrevia(saleGroupScanned: String): Boolean { + try { + for (indice in sales.indices) { + if (sales[indice].saleGroupFk != null && sales[indice].saleGroupFk == saleGroupScanned.toInt()) { + + viewModel.saleTracking_add( + saleGroupScanned.toInt() + ) + return true + + mpok!!.start() + + } + } + } catch (ex: Exception) { + return false + } + return false + } + + private fun showPrevia() { + customDialogList.getEditText().setRawInputType(InputType.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 == KeyEvent.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 = View.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()) { + + binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) + + //de momento solo está el qr de artículo + isScanned = + event != null && event.action == KeyEvent.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) + + } + + } 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 = View.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 = 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) requireActivity().onBackPressed() + }.show() + } + + }) + + collectionTicketSalix.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (!it.isError) { + + if (it.tickets.isNotEmpty()) { + collection = it + createCollectionList() + workerFkFromTicket = it.tickets[0].sales[0].workerFk.toString() + + } 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 = View.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 = View.GONE + + if (!goBack) { + binding.splashProgress.visibility = View.GONE + ma.messageWithSound( + if (it.isError) it.errorMessage else getString(R.string.Aparcado), + it.isError, true + ) + } + + }) + + responsePrint.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.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 = View.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 = View.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 + ) + } + + }) + + responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + + if (it.isError) { + ma.messageWithSound( + if (it.isError) it.errorMessage else "Confirmada reserva", + it.isError, !it.isError + ) + } + if (!it.isError) { + sales[positionConfirm].isPicked = 1 + saleAdapter!!.notifyDataSetChanged() + + /* viewModel.collectionTicketGetSalix( + collection.collectionFk, + print = false + )*/ + } + + }) + + + + 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 = View.VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + }) + placementSuppleyList.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (!goBack) printShelvingResult(it) + goBack = false + }) + + item.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.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 = + View.VISIBLE + + + if (!goBack) { + /* sendSalixMessage( + item = dataMessageSalix.item, + ticketFk = dataMessageSalix.ticket, + quantity = dataMessageSalix.quantity, + salePerson = dataMessageSalix.personSale + )*/ + // TODO()→ LLAMAR Al procedimiento bySale o + 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 + + }) + + + //Tarea 4280 + responseTicketClosure.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.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 + } + + } + }) + + responseGetExtensionFromUserId.observe(viewLifecycleOwner, Observer { + + binding.splashProgress.visibility = View.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 = View.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 = View.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 + ) + } + } + } + + responseSaleReplace.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + + if (it.isError) { + + if (!goBack) { + + ma.messageWithSound(it.errorMessage, it.isError, true) + binding.splashProgress.visibility = View.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 = View.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 = View.VISIBLE + viewModel.collectionTicketGet( + collection.collectionFk, + getDataInt(SECTORFK), + print = "0", + type + ) + } + + } else { + // pintar línea + + saleAdapter!!.notifyDataSetChanged() + + ReviewQuantityForRefreshingAndSorting( + sales[storedPosition].saleQuantity!!.toInt(), + sales[storedPosition].reservedQuantity!!.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].saleQuantity = quantityCollectionSplit + + if (quantityCollectionSplit == 0) + markLine( + positionCollectionSplit, + sales[positionCollectionSplit].saleQuantity, + false + ) + 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 createCollectionList() { + state = 0 + binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() + binding.splashProgress.visibility = View.GONE + collection.map(requireContext()) + var salesList: ArrayList = ArrayList() + + tickets = ArrayList() + var observations = "" + collection.tickets.forEach { ticket -> + + if (!observations.isNullOrEmpty()) + observations = observations + " " + ticket.observations + ticket.sales.forEach { sale -> + salesList.add(sale) + + } + } + println("Sacador esta vacia las sales: ${salesList.isEmpty()}") + for (s in salesList) { + println("Sacador la saleeeee es ${s.saleFk} cantidad: ${s.saleQuantity} y ${s.pickingOrder}") + } + sales = salesList.sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) + for (s in sales) { + println("Sacador la sale es ${s.saleFk} cantidad: ${s.saleQuantity} y ${s.pickingOrder}") + } + //quitar comentarios FALTA AGRUPAR LAS PREVIAS + myGroupList = groupSaleGroup(salesList).sortedWith(compareBy({ it.pickingOrder })) + saleAdapter = + SaleAdapterNew( + myGroupList, + pasillerosItemClickListener!!, + object : OnQuantityClickSaleListener { + + override fun onQuantityClick(sale: Sale) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.saleFk == sale.saleFk) { + if (type != "PRECHECKER") { + showQuantityDialog(index) + } + + } + } + + } + }, + object : OnSaleClickSaleListener { + override fun onSaleClick(mysale: Sale) { + println("Sacador onSaleClickListener") + + + 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 == mysale.itemShelvingSaleFk) { + 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) { + showScanner(index, sale) + } else { + unMarkLine(index, sales[index]) + } + + + } + + } + } + + }, + object : OnMistakeClickListener { + override fun onMistakeClickListener(sale: SaleVO) { + binding.splashProgress.visibility = View.VISIBLE + viewModel.mistakeType() + mistakeSale = sale + goMistakeBack = false + + } + }, + object : OnPackingClickSaleListener { + override fun onPackingClick(sale: Sale) { + // item_updatePackingShelve(sale.itemFk) + if (!sale.code.isNullOrEmpty()) + ma.onPasillerosItemClickListener( + PasillerosItemVO( + title = getString(R.string.titleUbicator), + ), entryPoint = sale.code!! + ) + } + }, + object : OnTicketClickSaleListener { + override fun onTicketClickListener(sale: Sale) { + if (type == CONTROLADOR) { + //var ticketFk = sale.ticketFk + + var entryPoint = Gson().toJson( + mutableMapOf( + "entryPoint" to sale.ticketFk, + "web" to "${getData("base_urlSalix")}/#!/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(true) + 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() + } + } + + //SEARCH AND MARK + + private fun findSale(txtscan: String) { + + var isOk = markPrevia(txtscan) + + if (isOk) { + //Se ha escanado un ticket y se ha marcado la previa + } else { + //Se busca la matricula en las lineas + for (indice in sales.indices) { + if (sales[indice].isPicked != 1 && sales[indice].code != null && sales[indice].code!!.uppercase() == txtscan.uppercase()) { + mpok!!.start() + isOk = true + showShelving(indice) + break + } + } + if (!isOk) { + //Si no es previa ni está cogiendo nada se comprueba si es un parking + if (txtscan.contains("-")) { + viewModel.parking( + ticketFk = collection.collectionFk.toString(), + parking = txtscan + ) + } else { + mperror!!.start() + } + + } + } + /* + 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.semaphore != "2" && saleVO.semaphore != "1") { + //if (saleVO.isPrepared != "1" && saleVO.isPreviousPrepared != "1") { + //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) + //nuevo + var mySale = sales[index].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 + // setListPosition(storedBackPosition,false) + } + } + + isBreak = true + break + } + shelvingIndex += 1 + } + 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() + } + + } + } + */ + } + + 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}") + if (sale.code!!.uppercase() == txtscan.uppercase()) { + mpok!!.start() + //showShelving(position) + sale.isPicked = 1 + binding.splashProgress.visibility = View.VISIBLE + viewModel.confirmItemShelvingReserved( + sale.itemShelvingSaleFk, + sale.reservedQuantity!!, + false + ) + saleAdapter!!.notifyDataSetChanged() + } else { + mperror!!.start() + } + + + } + + private fun markLine(position: Int, quantity: Int, isItemShelvingSaleEmpty: Boolean) { + state = 0 + println("Sacador linea pos:$position sale: ${sales[position].saleFk},item:${sales[position].itemFk} itemShelvingSale ${sales[position].itemShelvingSaleFk}} cantidad $quantity") + binding.splashProgress.visibility = View.VISIBLE + positionConfirm = position + viewModel.confirmItemShelvingReserved( + sales[position].itemShelvingSaleFk, + sales[position].reservedQuantity, + isItemShelvingSaleEmpty + ) + + isScanned = null + + //nuevo tema agrupacion sales + checkStateParent() + var mySale = sales[position].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 + } + } + + isMarking = true + //setTotalLines() + } + + + //Tarea #4371 + private fun markLineOld(position: Int, newType: String) { + state = 0 + if (type == SACADOR) { + sales[position].semaphore = if (sales[position].semaphore == "2") "2" else null + if (sales[position].semaphore == "2") { + //A modificar + sales[position].reservedQuantity = sales[position].saleQuantity!! + } + checkStateParent() + } + + + if (type == SACADOR) { + saleTracking_mark(position, newType) + //nuevo + var mySale = sales[position].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 + // setListPosition(storedBackPosition,false) + } + } + // storedBackPosition=position + //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.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) + lm!!.scrollToPositionWithOffset(storedBackPosition, 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 = View.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, sale: Sale) { + state = 0 + + //sales[position].isPicked = 0 + //saleAdapter!!.notifyDataSetChanged() + customDialog.setTitle(getString(R.string.unmarkLine)) + .setDescription( + getString(R.string.goUnmark) + sale.itemFk + getString( + R.string.sure + ) + ) + .setOkButton(getString(R.string.unmark)) { + sale.isPicked = 0 + saleAdapter!!.notifyDataSetChanged() + //nuevo + + 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 + // setListPosition(storedBackPosition,false) + } + } + storedBackPosition = position + setListPosition(position, false) + + /*Cuando esté en SALIX + binding.splashProgress.visibility = View.VISIBLE + viewModel.confirmItemShelvingReservedUpdate( + sale.itemShelvingSaleFk, + false + )*/ + positionUnmarked = position + + + setTotalLines() + scanRequest() + customDialog.dismiss() + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() + + + } + + //SHELVINGS + private fun showShelving(position: Int) { + // storedShelvingPosition = shelvingPosition + storedPosition = position + binding.splashProgress.visibility = View.VISIBLE + try { + var quantityGet = + (sales[position].reservedQuantity!!) + + viewModel.itemPlacementSupplyAiming( + itemFk = sales[position].itemFk, + quantity = quantityGet, + shelvingFk = sales[position].code!! + + ) + } catch (e: Exception) { + } + } + + private fun showShelvingOld(position: Int, shelvingPosition: Int) { + storedShelvingPosition = shelvingPosition + storedPosition = position + binding.splashProgress.visibility = View.VISIBLE + var quantityGet = 0 + try { + quantityGet = + (sales[position].reservedQuantity!!) + } catch (e: Exception) { + } + + viewModel.itemPlacementSupplyAiming( + itemFk = sales[position].itemFk, + quantity = quantityGet, + shelvingFk = sales[position].placements[shelvingPosition].shelving + + ) + } + + @RequiresApi(Build.VERSION_CODES.O) + private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO) { + customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_TEXT + + 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.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) + 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().toLong() + // Log.i("VERDNATURA","Le pasamos el siguiente item $originalItemScan que es el escaneado") + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected( + itemShelvingFk, + customDialogList.getValue().toInt() + ) + //Log.i("VERDNATURA:","Cantidad seleccionada") + mpok?.start() + customDialogList.dismiss() + } else { + //Si no está se transforma a Id + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = + View.VISIBLE + viewModel.getIdFromCodeSalix( + code = customDialogList.getValueTwo(), + ) + 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 == KeyEvent.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().toLong() + + if (checkItemScan(customDialogList.getValueTwo())) { + onQuantityOfShelvingSelected( + itemShelvingFk, + customDialogList.getValue().toInt() + ) + mpok?.start() + customDialogList.dismiss() + } else { + itemShelvingFkStored = itemShelvingFk + binding.splashProgress.visibility = View.VISIBLE + + viewModel.getIdFromCodeSalix( + code = customDialogList.getValueTwo() + ) + 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) { + setListPosition(storedPosition, isFromBack) + } + + + private fun checkItemScan(valueToCheck: String): Boolean { + 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 + } + } + } + + return false + } + + //Tarea #4371 + private fun onQuantityOfShelvingSelected(itemShelvingFk: Int, quantity: Int = 0) { + + println("Sacador $itemShelvingFk-$quantity") + itemShelvingTracking_mark = itemShelvingFk + + if (sales[storedPosition].reservedQuantity == 0) { + showQuestionUbicationEmpty(storedPosition) + } else { + markLine(storedPosition, quantity, false) + } + + /* //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() + ")" + } + + } 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) + } + */ + } + + private fun showQuestionUbicationEmpty(position: Int) { + customDialogThreeButtonsQuantity + .setTitle("Cambio de cantidad a 0") + .setDescription("¿Hay unidades del artículo ${sales[position].itemFk} en el carro escaneado?") + .setValue("") + .setCustomDialogValue(View.GONE) + customDialogThreeButtonsQuantity.setOkButtonAdd("SI") { + scanRequest() + customDialogThreeButtonsQuantity.dismiss() + markLine(storedPosition, 0, false) + }.setOkButtonTwo("NO") { + scanRequest() + customDialogThreeButtonsQuantity.dismiss() + markLine(storedPosition, 0, true) + } + .setKoButton("CANCELAR") { + 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)) { + + 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 = + View.VISIBLE + + 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 = + View.VISIBLE + + 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 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 (it.isPicked == 1) { + totalMark += 1 + /* } else if (it.reservedQuantity == 0) { + 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 = View.VISIBLE + viewModel.ticketCollection_setUsedShelves( + ticketFk = collection.collectionFk, + usedShelves = customDialogInput.getValue().toInt() + ) + hideKeyboards() + // showKeyboards() + + } + customDialogInput.setValue("") + customDialogInput.dismiss() + showKeyboards() + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + showKeyboards() + }.setValue("").show() + + customDialogInput.setInputText(InputType.TYPE_CLASS_NUMBER) + // 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 = View.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 = View.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(InputType.TYPE_CLASS_NUMBER) + 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 = View.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.itemSaleQuantity)) + .setTitle("") + .setValue("") + .setOkButtonAdd(getString(R.string.modify)) { + //increaseQuantity(position, customDialogThreeButtons.getValue().toInt()) + + if (customDialogThreeButtons.getValue().toInt() == 0) { + showQuestionUbicationEmpty(position) + } else { + if (customDialogThreeButtons.getValue() + .toInt() != sales[position].reservedQuantity + ) { + markLine(position, customDialogThreeButtons.getValue().toInt(), false) + } else { + scanRequest() + customDialogThreeButtons.dismiss() + } + } + scanRequest() + customDialogThreeButtons.dismiss() + } + .setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialogThreeButtons.dismiss() + }.show() + customDialogThreeButtons.setFocusDialogValue() + + } + + private fun incresaseSuccesful() { + /* try { + + sales[positionIncreaseQuantity].reservedQuantity = quantityIncrease + + } catch (e: Exception) { + } + saleAdapter?.notifyDataSetChanged() + sales[positionIncreaseQuantity].originalQuantity = quantityIncrease*/ + + + } + + + private fun increaseQuantity(position: Int, quantity: Int) { + positionIncreaseQuantity = position + quantityIncrease = quantity + + viewModel.collectionIncreaseQuantitySalix( + saleFk = sales[position].saleFk, + quantity = quantity.toString() + ) + + + } + + //ESTADOS + private fun changeTicketState() { + + tickets.forEach { + viewModel.ticket_setState( + ticketFk = it.toInt(), + state = "PREPARED" + ) + } + + } + + + //OTROS + 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)) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(), index, sale) + } + 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, sale) + } + 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 = View.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( + saleFk = mistakeSale?.saleFk!!, + typeFk = 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 == 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( + 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].itemFk, + isAdded = value[0].isAdded, + hasMistake = value[0].hasMistake, + origin = value[0].origin, + size = value[0].size, + itemShelvingSaleFk = value[0].itemShelvingSaleFk, + longName = value[0].longName + + ) + + //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 myList + } + +} + + 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 new file mode 100644 index 00000000..8c41a5e0 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/adapter/CollectionAdapterNew.kt @@ -0,0 +1,49 @@ +package es.verdnatura.presentation.view.feature.sacador.adapter + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemCollectionRowBinding +import es.verdnatura.databinding.ItemCollectionRowNewBinding +import es.verdnatura.presentation.common.OnCollectionSelectedListener +import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener +import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO + +class CollectionAdapterNew( + private val items: List, + private val onCollectionTicketSelected: OnCollectionTicketSelectedListener, + private val type: String +) : RecyclerView.Adapter() { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { + return AjustesItemHolder( + ItemCollectionRowNewBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ) + } + + override fun getItemCount() = items.size + + override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onCollectionTicketSelected.onCollectionSelected(items[position], type) + } + } + + + class AjustesItemHolder( + val binding: ItemCollectionRowNewBinding + ) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: CollectionTicket) { + binding.apply { + if (item.ticketTotalCount == null) { + binding.totalTicketsId.visibility = View.GONE + } + this.item = item + } + } + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..ec53bd97 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt @@ -0,0 +1,280 @@ +package es.verdnatura.presentation.view.feature.sacador.fragment + +import android.content.Context +import android.graphics.drawable.Drawable +import android.os.Build +import android.text.InputType +import android.view.View +import android.view.inputmethod.EditorInfo +import android.widget.ImageView +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentSacadorBinding +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.TAG +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.feature.sacador.adapter.CollectionAdapterNew +import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket + + +class SacadorFragmentNew( + var type: String +) : + BaseFragment(SacadorViewModel::class) { + + private var onCollectionSelectedListener: OnCollectionTicketSelectedListener? = null + private var goBack: Boolean = false + private var goBack2: Boolean = false + private lateinit var customDialog: CustomDialog + private lateinit var customDialogInput: CustomDialogInput + private var collectionsList: ArrayList = ArrayList() + private var adapter: CollectionAdapterNew? = null + + + companion object { + fun newInstance(type: String) = SacadorFragmentNew(type) + } + + override fun onAttach(context: Context) { + super.onAttach(context) + if (context is OnCollectionTicketSelectedListener) onCollectionSelectedListener = context + } + + override fun getLayoutId(): Int = R.layout.fragment_sacador + + override fun init() { + customDialog = CustomDialog(requireContext()) + customDialogInput = CustomDialogInput(requireContext()) + binding.mainToolbar.toolbarTitle.text = getString(R.string.getcollection) + setToolBar() + setEvents() + callBack(type) + println("El sacador new y type $type") + super.init() + } + + private fun callBack(type: String) { + binding.splashProgress.visibility = View.VISIBLE + when (type) { + "PREPARED" -> { + viewModel.collectionGetSalixLocal() + } + + "PREITEMPICKER" -> { + viewModel.sectorCollection_get() + } + + else -> { + binding.splashProgress.visibility = View.GONE + } + } + } + + override fun onPause() { + goBack = true + goBack2 = true + super.onPause() + } + + private fun setToolBar() { + + ma.hideBottomNavigation(View.VISIBLE) + binding.mainToolbar.backButton.setOnClickListener { + requireActivity().onBackPressed() + } + + val listIcons: ArrayList = ArrayList() + val iconAdd = ImageView(context) + iconAdd.setImageResource(R.drawable.ic_add_black_24dp) + val iconVehicleIn = ImageView(context) + iconVehicleIn.setImageResource(R.drawable.car) + val iconPrint = ImageView(context) + iconPrint.setImageResource(R.drawable.ic_print_black_24dp) + + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp) + iconVehicleIn.tooltipText = getTooltip(R.drawable.car) + iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp) + iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) + } + + if (type == "PREPARED") { + listIcons.add(iconVehicleIn) + } else { + listIcons.add(iconPrint) + } + listIcons.add(iconAdd) + + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + + when (item) { + + iconAdd.drawable -> { + binding.splashProgress.visibility = View.VISIBLE + if (type == "PREPARED") { + viewModel.collection_assignNew( + ) + } else { + viewModel.sectorCollection_new(getDataInt(SECTORFK)) + } + + + } + + iconVehicleIn.drawable -> ma.onVehicleSelected(SacadorFragment.TAG) + + iconPrint.drawable -> { + showPrintPrevious() + } + } + } + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun showPrintPrevious() { + + customDialogInput.setInputText(InputType.TYPE_CLASS_NUMBER) + customDialogInput.setTitle(getString(R.string.printTicket)) + customDialogInput.setDescription(getString(R.string.printPreviousGroup)) + .setValue("") + .setOkButton(getString(R.string.print)) { + try { + if (customDialogInput.getValue().isNotEmpty() + ) { + print() + } + } catch (ex: Exception) { + getString(R.string.errorInput) + } + customDialogInput.setValue("") + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + customDialogInput.setFocusText() + + + customDialogInput.setFocusText() + ma.hideKeyboard(customDialogInput.getEditText()) + + customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) { + + if (customDialogInput.getValue().isNotEmpty() + ) { + print() + } + + return@setOnEditorActionListener true + } + false + } + + + } + + private fun print() { + if (ma.havePrinter()) { + viewModel.ticket_printLabelPrevious(customDialogInput.getValue().toInt()) + (getString(R.string.Imprimiendo) + getData(PRINTERNAME)).toast( + requireContext() + ) + } else { + getString(R.string.selectPrinter).toast(requireContext()) + } + } + + private fun setEvents() { + binding.sacadorSwipe.setOnRefreshListener { + callBack(type) + binding.sacadorSwipe.isRefreshing = false + } + } + + override fun observeViewModel() { + + with(viewModel) { + binding.splashProgress.visibility = View.GONE + collectionListLocal.observe(viewLifecycleOwner, Observer { + if (!goBack2) binding.splashProgress.visibility = View.GONE + println("sacador creada colecc") + for (l in it.list) { + println("sacador col ${l.collectionFk}") + println("sacador tic ${l.tickets}") + for (t in l.tickets) { + println("sacador id ticket${t.ticketFk}") + } + } + createCollectionList(it.list) + binding.splashProgress.visibility = View.GONE + goBack2 = false + }) + + response.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + + } else { + if (goBack) { + if (!it.response.isNullOrBlank()) addCollectionToList(it.response.toInt()) + } + } + goBack = false + callBack(type) + }) + + } + } + + private fun createCollectionList(collections: List) { + collectionsList = ArrayList() + collections.forEach { + collectionsList.add(it) + } + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + adapter = CollectionAdapterNew(collectionsList, onCollectionSelectedListener!!, type) + binding.fragmentSacadorCollections.layoutManager = lm + binding.fragmentSacadorCollections.adapter = adapter + + } + + private fun addCollectionToList(collection: Int) { + var isNew = true + + collectionsList.forEach { + if (it.collectionFk == collection) { + isNew = false + } + } + if (isNew) { + collectionsList.add( + CollectionTicket( + collectionFk = collection, + created = getString(R.string.newCreated) + ) + ) + + + adapter?.notifyDataSetChanged() + } else { + customDialog.setTitle(getString(R.string.info)) + .setDescription(getString(R.string.collectionPending) + collection) + .setOkButton(getString(R.string.accept)) { + customDialog.dismiss() + }.show() + } + adapter?.notifyDataSetChanged() + } +} diff --git a/app/src/main/res/layout/item_article_row_fragment.xml b/app/src/main/res/layout/item_article_row_fragment.xml index e35c9fa5..a3a56971 100644 --- a/app/src/main/res/layout/item_article_row_fragment.xml +++ b/app/src/main/res/layout/item_article_row_fragment.xml @@ -40,7 +40,7 @@ android:layout_below="@id/content_layout" android:layout_marginTop="6dp" android:visibility="visible" - tools:listitem="@layout/item_article_row_fragment"/> + /> + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/sale_row_fragment.xml b/app/src/main/res/layout/sale_row_fragment.xml new file mode 100644 index 00000000..bfd0ace9 --- /dev/null +++ b/app/src/main/res/layout/sale_row_fragment.xml @@ -0,0 +1,686 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 54dab328..55e86e11 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -72,6 +72,7 @@ Artículo para Ticket Escanea el carro para el item seleccionado Indica la nueva cantidad y la acción que quieres realizar con el resto. + Indica la nueva cantidad. Basura Indica nueva cantidad Indica nuevo packing para el item : @@ -659,6 +660,7 @@ Para usar esta aplicación, debes otorgar permisos de ubicación. Habilita manualmente el permiso de ubicación. El campo item es obligatorio + Sacador Test diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 3a671943..ea317d1c 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -72,6 +72,7 @@ Artículo para Ticket Escanea el carro para el item seleccionado Indica la nueva cantidad y la acción que quieres realizar con el resto. + Indica la nueva cantidad. Basura Indica nueva cantidad Indica nuevo packing para el item : @@ -531,7 +532,7 @@ Autoconsumo Autoconsumo Permite consumo de materiales del almacén - Reparto + Livraison Accede a las opciones de reparto Ver datos expedición Ver datos empresa @@ -659,5 +660,6 @@ Pour utiliser cette application, vous devez accorder des autorisations de localisation. Activez manuellement l\'autorisation de localisation. Le champ \'item\' est requis + Sacador Test diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 680fc3dd..a807fa93 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -72,6 +72,7 @@ Artículo para Ticket Escanea el carro para el item seleccionado Indica la nueva cantidad y la acción que quieres realizar con el resto. + Indicate la nueva cantidad. Basura Indica nueva cantidad Indica nuevo packing para el item : @@ -659,5 +660,6 @@ Para usar este aplicativo, você deve conceder permissões de localização. Habilite manualmente a permissão de localização. O campo \'item\' é obrigatório + Sacador Test diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8ee7314c..6392e0f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -83,6 +83,7 @@ Quantity Ticket Item Indicate the new quantity and the action you want to take with the rest. + Indicate the new quantity Garbage Indicate new quantity Indicate the quantity you take @@ -658,5 +659,6 @@ To use this application, you must grant location permissions. Manually Enable Location Permission. Item fiels is required + Sacador Test