From 7bfd17d1f7a8714201c4a6c58ecc63e7038b0e0a Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 26 Nov 2024 10:56:53 +0100 Subject: [PATCH] feat: refs #6869 itemShelvingGet --- .../ubicador/adapter/UbicadorAdapter6869.kt | 131 ++ .../ubicador/fragment/UbicadorFragment6869.kt | 1231 +++++++++++++++++ .../res/layout/item_ubication_row_6869.xml | 137 ++ 3 files changed, 1499 insertions(+) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/UbicadorAdapter6869.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment6869.kt create mode 100644 app/src/main/res/layout/item_ubication_row_6869.xml diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/UbicadorAdapter6869.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/UbicadorAdapter6869.kt new file mode 100644 index 00000000..cf11beae --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/UbicadorAdapter6869.kt @@ -0,0 +1,131 @@ +package es.verdnatura.presentation.view.feature.ubicador.adapter + +import android.annotation.SuppressLint +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.ItemUbicationRow6869Binding +import es.verdnatura.presentation.common.OnMoreClickListener6869 +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.OnVisibleClickListener6869 +import es.verdnatura.presentation.common.loadUrl +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelving + +class UbicadorAdapter6869( + private val items: List, + private val onPasillerosItemClickListener: OnPasillerosItemClickListener, + private val onVisibleClickListener: OnVisibleClickListener6869, + private val onMoreClickListener: OnMoreClickListener6869, + private val urlImage: String? = null +) : RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemUbicationRow6869Binding.inflate(LayoutInflater.from(parent.context), parent, false) + ) + } + + override fun getItemCount() = items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + } + + inner class ItemHolder( + val binding: ItemUbicationRow6869Binding + ) : RecyclerView.ViewHolder(binding.root) { + private val res = binding.root.context.resources + + @SuppressLint("SetTextI18n") + fun bind(item: ItemShelving) { + binding.apply { + this.item = item + multiText.text = "${item.stickers}x${item.packing}" + + if (urlImage != null) imgItem.loadUrl("http:$urlImage/catalog/200x200/${item.item.id}") + imgItem.setOnClickListener { + onPasillerosItemClickListener.onPasillerosItemClickListener( + PasillerosItemVO( + title = + R.string.itemSearch + + ), item.item.id.toString() + ) + } + + layerVisible.setOnClickListener { + onVisibleClickListener.onVisibleClickListener(item) + } + + if (item.visible == 0) { + visibleText.setTextColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_brown_grey + ) + ) + + } else { + visibleText.setTextColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_pumpkin_orange + ) + ) + } + + moreImg.setOnClickListener { + onMoreClickListener.onMoreClickListener(item) + } + namelayout.setOnClickListener { + onPasillerosItemClickListener.onPasillerosItemClickListener( + PasillerosItemVO( + title = R.string.itemSearch + ), item.item.id.toString() + ) + } + + if (item.isChecked != null) { + + when (item.isChecked) { + 0 -> itemRowLayout.setBackgroundColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_red_salix + ) + ) + + in 1..Int.MAX_VALUE -> + if (item.visible == 0) { + itemRowLayout.setBackgroundColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_dark_sky_blue + ) + ) + } else { + itemRowLayout.setBackgroundColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_dark_green_verdnatura + ) + ) + } + + } + } else { + itemRowLayout.setBackgroundColor( + ContextCompat.getColor( + visibleText.context, + R.color.verdnatura_black_5 + ) + ) + } + + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment6869.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment6869.kt new file mode 100644 index 00000000..7992fc59 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment6869.kt @@ -0,0 +1,1231 @@ +package es.verdnatura.presentation.view.feature.ubicador.fragment + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.text.InputType +import android.text.TextWatcher +import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE +import android.view.inputmethod.EditorInfo +import android.widget.ImageView +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentUbicadorBinding +import es.verdnatura.domain.ConstAndValues +import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK +import es.verdnatura.domain.isShelving +import es.verdnatura.domain.notNull +import es.verdnatura.domain.toInt +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.Action +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.OnMoreClickListener6869 +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.OnVisibleClickListener6869 +import es.verdnatura.presentation.common.PrinterDialogManager +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +import es.verdnatura.presentation.common.hideKeyboard +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.component.CustomDialogTwoButtons +import es.verdnatura.presentation.view.component.CustomDialogUbicadorNew +import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter6869 +import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelving +import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador +import org.json.JSONObject +import java.time.LocalDate +import java.time.format.DateTimeFormatter +import kotlin.math.ceil + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class UbicadorFragment6869 : BaseFragment( + UbicadorViewModel::class +) { + private var shelvingFk: String = "" + private var isAutoSelf: Boolean = false + private var urlImage = "" + private var adapter: UbicadorAdapter6869? = null + private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialogUbicador: CustomDialogUbicadorNew + private lateinit var customDialogTwoButtons: CustomDialogTwoButtons + private var listItems: MutableList = mutableListOf() + private var listLocalItems: ArrayList = ArrayList() + private lateinit var customDialog: CustomDialog + private lateinit var customDialogOlder: CustomDialog + private var parking: String = "" + private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null + private var isShelvinLogfromMainScreen = false + private var modeCheckUbication = false + private var itemScannedScreen: Long = 0 + private var isBack = false + var listIcons: ArrayList = ArrayList() + private lateinit var textWatcher: TextWatcher + private var buyScanned: String = "" + private lateinit var customDialogList: CustomDialogList + private var listShelvings: ArrayList = ArrayList() + private var listShelvingsAdapter: BarcodeAdapter? = null + private var locateMultipleShelvings: Boolean = false + + companion object { + private const val ARG_SHELVINGFK = "shelvingFk" + private const val ARG_ISAUTOSELF = "autoSelf" + fun newInstance(shelvingFk: String, isAutoSelf: Boolean = false) = + UbicadorFragment6869().apply { + arguments = Bundle().apply { + putString(ARG_SHELVINGFK, shelvingFk) + putBoolean(ARG_ISAUTOSELF, isAutoSelf) + } + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + shelvingFk = it.getString(ARG_SHELVINGFK).toString() + isAutoSelf = it.getBoolean(ARG_ISAUTOSELF) + } + } + + /*fun newInstance(entryPoint: String, autoSelf: Boolean = false) = + UbicadorFragmentNew(entryPoint, autoSelf) + }*/ + + override fun getLayoutId(): Int = R.layout.fragment_ubicador + override fun onPause() { + super.onPause() + isBack = true + } + + override fun onAttach(context: Context) { + if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context + super.onAttach(context) + + } + + override fun init() { + + setDialogs() + setEvents() + setToolBar() + println("Ubicador nuevo") + ma.hideBottomNavigation(GONE) + viewModel.getImageConfig() + + if (shelvingFk.isNotEmpty()) { + isShelvinLogfromMainScreen = false + setIconsActions(true) + binding.mainToolbar.toolbarTitle.text = shelvingFk + viewModel.itemShelvingGet(shelvingFk) + binding.mainToolbar.switchButton.visibility = VISIBLE + } else { + isShelvinLogfromMainScreen = true + setIconsActions(false) + } + super.init() + } + + private fun setIconsActions(showIcons: Boolean) { + + binding.layoutIconsActions.visibility = if (showIcons) { + VISIBLE + } else { + GONE + } + setIcons(!showIcons) + } + + private fun setDialogs() { + customDialogInput = CustomDialogInput(requireContext()) + customDialog = CustomDialog(requireContext()) + customDialogOlder = CustomDialog(requireContext()) + customDialogTwoButtons = CustomDialogTwoButtons(requireContext()) + } + + private fun setToolBar() { + binding.mainToolbar.switchButton.visibility = GONE + binding.mainToolbar.toolbarTitle.text = if (!isAutoSelf) { + getString(R.string.locator) + } else { + getString(R.string.selfConsumption) + } + } + + private fun setIcons(isInitMenu: Boolean = false) { + + listIcons.clear() + val iconAdd = ImageView(context) + iconAdd.setImageResource(R.drawable.ic_add_black_24dp) + val iconAddMultiple = ImageView(context) + iconAddMultiple.setImageResource(R.drawable.ic_add_multiple) + val iconReload = ImageView(context) + iconReload.setImageResource(R.drawable.ic_autorenew_black_24dp) + val iconReset = ImageView(context) + iconReset.setImageResource(R.drawable.ic_remove_checks) + + binding.mainToolbar.switchButton.setOnCheckedChangeListener { buttonView, isChecked -> + if (binding.mainToolbar.toolbarTitle.text == getString(R.string.titleUbicator)) { + getString(R.string.scanShelving).toast(requireContext()) + binding.mainToolbar.switchButton.isChecked = false + } else { + modeCheckUbication = isChecked + binding.mainToolbar.switchButton.tooltipText = + if (isChecked) getString(R.string.activateModoChecking) else getString(R.string.allowCheckingMode) + binding.textinputlayoutMatricula.hint = + if (isChecked) getString(R.string.scanItem) else { + getString(R.string.scanPlate) + + } + if (!isChecked) { + listIcons.removeAt(listIcons.size - 1) + binding.mainToolbar.toolbarIcons.adapter!!.notifyItemRemoved(listIcons.size) + + } else { + listIcons.add(iconReset) + binding.mainToolbar.toolbarIcons.adapter!!.notifyItemInserted(listIcons.size - 1) + + } + } + } + + + iconReload.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) + iconAdd.tooltipText = + if (isInitMenu) getString(R.string.addItemMultipleShelving) else getString(R.string.addItemShelving) + iconAddMultiple.tooltipText = getTooltip(R.drawable.ic_add_multiple) + iconReset.tooltipText = getTooltip(R.drawable.ic_remove_checks) + + listIcons.add(iconAdd) + + if (!isInitMenu) { + listIcons.add(iconReload) + } else { + listIcons.add(iconAddMultiple) + } + locateMultipleShelvings = isInitMenu + + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + listItems.clear() + when (item) { + iconAdd.drawable -> showAddItemNew( + isEditItem = false, null + ) + + iconAddMultiple.drawable -> { + + ma.onPasillerosItemClickListener( + PasillerosItemVO( + title = R.string.addItemMultipleShelving, + ), entryPoint = getString(R.string.addItemMultipleShelving) + ) + } + + iconReload.drawable -> { + + if (shelvingFk.isNotBlank()) { + binding.editPrioridad.setText("") + viewModel.itemShelvingGet( + shelvingFk + ) + } else { + getString(R.string.scanShelving).toast( + requireActivity(), Toast.LENGTH_SHORT + ) + } + } + + iconReset.drawable -> { + if (shelvingFk.isNotBlank()) { + val customDialogReset = CustomDialog(requireContext()) + customDialogReset.setTitle(getString(R.string.checkItemShelvingDescrip)) + .setDescription(getString(R.string.checkItemShelving)) + .setOkButton(getString(R.string.ok)) { + viewModel.itemShelvingDeleteChecked(shelvingFk) + customDialogReset.dismiss() + }.setKoButton(getString(R.string.cancel)) { + customDialogReset.dismiss() + + }.show() + } else { + ma.messageWithSound( + getString(R.string.scanPlate), + isError = true, + isPlayed = true, + isToasted = true + ) + } + } + } + } + + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + @SuppressLint("SetTextI18n") + private fun setEvents() { + binding.mainToolbar.backButton.setOnClickListener { + ma.onMyBackPressed() + } + + setTooltips() + binding.editMatricula.requestFocus() + binding.editMatricula.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (binding.editMatricula.text.toString().isNotEmpty()) { + setIconsActions(true) + if (!modeCheckUbication || (modeCheckUbication && (binding.editMatricula.text.toString() + .isShelving()) && !binding.editMatricula.text!![0].isDigit()) + ) { + binding.mainToolbar.toolbarTitle.text = + binding.editMatricula.text.toString() + shelvingFk = binding.editMatricula.text.toString() + parking = "" + binding.editPrioridad.setText("") + isShelvinLogfromMainScreen = true + viewModel.itemShelvingGet( + binding.editMatricula.text.toString() + ) + } else { + try { + buyScanned = itemScanValue( + binding.editMatricula.text.toString(), arrayOf("buy"), "more" + ).toString() + viewModel.getIdFromCode( + code = buyScanned + ) + } catch (ex: Exception) { + ma.messageWithSound( + ex.message.toString(), isError = true, isPlayed = true + ) + } + + } + } + binding.mainToolbar.switchButton.visibility = VISIBLE + + binding.editMatricula.setText("") + ma.hideKeyboard(binding.editMatricula) + return@setOnEditorActionListener true + } + + return@setOnEditorActionListener false + } + + binding.editPrioridad.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (binding.editPrioridad.text.toString().isNotEmpty()) { + viewModel.shelvingPriorityUpdate( + binding.editPrioridad.toInt(), shelvingFk + ) + isBack = false + + } + ma.hideKeyboard(binding.editPrioridad) + } + + binding.editMatricula.requestFocus() + return@setOnEditorActionListener false + } + + + binding.automaticImg.setOnClickListener { + + if (shelvingFk.isNotBlank()) ma.onPasillerosItemClickListener( + PasillerosItemVO(title = R.string.titleAuto), entryPoint = shelvingFk + ) + else getString(R.string.scanShelving).toast( + requireActivity(), Toast.LENGTH_SHORT + ) + } + + binding.parkingImg.setOnClickListener { + if (shelvingFk.isNotBlank()) { + customDialogInput.setTitle(getString(R.string.parkingShelving)).setValue("") + .setOkButton( + getString( + R.string.parking + ) + ) { + customDialogActionParking() + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + } else { + + getString(R.string.errorShelving).toast( + requireContext() + ) + } + customDialogInput.getEditText().requestFocus() + ma.hideKeyboard(customDialogInput.getEditText()) + + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + customDialogActionParking() + + return@setOnEditorActionListener true + } + false + } + + } + + binding.editImg.setOnClickListener { + if (shelvingFk.isNotBlank()) { + customDialogInput = CustomDialogInput(requireContext()) + customDialogInput.setTitle(getString(R.string.changeShelving)).setValue("") + .setOkButton(getString(R.string.save)) { + if (customDialogInput.getValue().isNotBlank()) { + customDialogActionChange() + } else { + getString(R.string.errorShelving).toast( + requireContext() + ) + } + customDialogInput.dismiss() + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + } else { + getString(R.string.errorShelving).toast( + requireContext() + ) + } + customDialogInput.getEditText().requestFocus() + ma.hideKeyboard(customDialogInput.getEditText()) + + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + customDialogActionChange() + return@setOnEditorActionListener true + } + false + } + + } + + binding.deleteImg.setOnClickListener { + if (shelvingFk.isNotBlank()) { + val customDialogDelete = CustomDialog(requireContext()) + customDialogDelete.setTitle(getString(R.string.empty)) + .setDescription(getString(R.string.operationNoReturn)) + .setOkButton(getString(R.string.empty)) { + if (listItems.isNotEmpty()) { + viewModel.clearShelvingList( + //Tarea 7920 + listItems[0].shelvingFk.toString() ?: shelvingFk + ) + } + + listItems.forEach { + it.stickers = 0 + it.visible = 0 + it.available = 0 + } + + + if (adapter != null) { + adapter!!.notifyDataSetChanged() + } + customDialogDelete.dismiss() + } + + customDialogDelete.setKoButton(getString(R.string.cancel)) { + customDialogDelete.dismiss() + }.show() + } else { + getString(R.string.errorShelving).toast( + requireContext() + ) + + } + + } + } + + private fun customDialogActionParking() { + parking = customDialogInput.getValue() + //tarea 6964 + viewModel.hasItemOlder( + shelvingFk, customDialogInput.getValue(), + ) + + customDialogInput.dismiss() + } + + private fun customDialogActionChange() { + + //Tarea 7920 + if (listItems.isNotEmpty()) { + viewModel.shelvingChangeSalix( + shelvingFk, customDialogInput.getValue() + ) + } else { + viewModel.getShelvingFkFromCode( + listItems[0].shelvingFk, customDialogInput.getValue() + ) + } + shelvingFk = customDialogInput.getValue() + + customDialogInput.dismiss() + } + + private fun checkUbications(itemScanned: Long) { + itemScannedScreen = itemScanned + val listInt: ArrayList = ArrayList() + + if (listItems.none { it.item.id == itemScanned }) { + try { + listInt.add(buyScanned.toLong()) + } catch (_: Exception) { + } + + } else { + listItems.sortedBy { it.isChecked }.forEachIndexed { index, item -> + if (item.item.id == itemScanned) { + item.isChecked = 1 + listInt.add(item.item.id) + ma.messageWithSound( + "", isError = false, isPlayed = true, titleWithError = "", false + ) + } + } + + } + if (listInt.isNotEmpty()) { + viewModel.itemShelvingAddList( + shelvingFk, + "" + listInt + "", + true, + mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + ) + } + + adapter!!.notifyDataSetChanged() + } + + private fun setTooltips() { + + binding.editImg.tooltipText = getTooltip(R.drawable.ic_mode_edit_black_24dp) + binding.deleteImg.tooltipText = getTooltip(R.drawable.ic_delete_forever_black_24dp) + binding.editPrioridad.tooltipText = getString(R.string.changePriority) + binding.parkingImg.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) + binding.automaticImg.tooltipText = getTooltip(R.drawable.ic_flash_auto_black_24dp) + + } + + @SuppressLint("SetTextI18n") + override fun observeViewModel() { + + with(viewModel) { + + loadShelvingGet.observe(viewLifecycleOwner) { event -> + listItems.clear() + event.getContentIfNotHandled().notNull { + if (isShelvinLogfromMainScreen) { + viewModel.shelvingLogAdd(shelvingFk) + } + listItems.addAll(it.itemShelving!!) + listItems.forEach { itemShelvings -> + if (itemShelvings.description.isNullOrEmpty()) { + itemShelvings.description = itemShelvings.item.longName + ?: "${itemShelvings.item.name ?: ""} ${itemShelvings.item.size ?: ""}" + } + itemShelvings.stickers = + ceil(((itemShelvings.visible).toDouble() / itemShelvings.packing.toDouble())).toInt() + } + val totalStickers = listItems.sumOf { item -> item.stickers!! } + parking = it.parking?.code ?: "" + + binding.mainToolbar.toolbarTitle.text = + shelvingFk.uppercase() + getString(R.string.pUppercase) + parking + getString( + R.string.label + ) + totalStickers + if (listItems.isNotEmpty()) binding.editPrioridad.setText(it.priority.toString()) + + if (!binding.mainToolbar.switchButton.isChecked && listItems.isNotEmpty()) { + listItems = listItems.asReversed() + } + + if (listItems.isNotEmpty()) { + binding.deleteImg.visibility = VISIBLE + + } else { + binding.deleteImg.visibility = View.INVISIBLE + } + setAdapter(listItems) + setPosition() + + } + } + loadAddList.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + viewModel.itemShelvingGet(shelvingFk) + } + } + + //parking, isChecked, responseOlder, responseMake Add + responseUbicator.observe(viewLifecycleOwner) { + + if (shelvingFk.isNotEmpty()) { + binding.mainToolbar.toolbarTitle.text = shelvingFk + viewModel.itemShelvingGet( + shelvingFk + ) + + } + } + responseLogAdd.observe(viewLifecycleOwner) { + isShelvinLogfromMainScreen = false + if (it == false) { + setIconsActions(false) + } + } + loadResponseCode.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + checkUbications(it.toLong()) + } + } + + loadImageConfig.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + urlImage = it + println("urrrr $it") + } + } + + loadAddList.observe(viewLifecycleOwner) { + + if (shelvingFk.isNotEmpty()) { + binding.mainToolbar.toolbarTitle.text = shelvingFk + viewModel.itemShelvingGet( + shelvingFk + ) + + } + } + + loadShelvingListItemNewer.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + if (it.list.isNotEmpty()) { + val formattedList = it.list.map { item -> + val itemFk = item.itemFk + val shelvingFk = item.shelvingFk + "$itemFk (${shelvingFk.uppercase()})" + } + val resultString = formattedList.joinToString(separator = "\n") + val finalOutput = "\n$resultString" + customDialogOlder.setTitle(getString(R.string.info)).setDescription( + getString( + R.string.itemOlderInfo, Action.PARKINEAR + ) + getString(R.string.listItems) + finalOutput + ).setOkButton( + getString(R.string.ok) + ) { + viewModel.setParking( + it.originalShelvingFk, it.originalParking + ) + + customDialogOlder.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + customDialogOlder.dismiss() + }.show() + + } + } + } + + loadResponseHasOlder.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + customDialogOlder.setTitle(getString(R.string.info)).setDescription( + getString( + R.string.itemOlderInfo, responseHasOlder.value!!.action + ) + ).setOkButton( + getString(R.string.ok) + ) { + when (responseHasOlder.value!!.action) { + Action.PARKINEAR -> viewModel.setParking( + responseHasOlder.value!!.shelvingFkIn, parking + ) + + Action.TRANSFERIR -> viewModel.itemShelvingTransfer( + responseHasOlder.value!!.itemFk!!, + responseHasOlder.value!!.shelvingFkOut!! + ) + } + customDialogOlder.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + customDialogOlder.dismiss() + }.show() + } + } + loadBuyUltimateResponse.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + ma.messageWithSound( + getString(R.string.errorPrintBuy), isError = true, isPlayed = true + ) + } + } + } + + } + + private fun setPosition() { + if (modeCheckUbication) { + listItems.sortedBy { it.isChecked }.forEachIndexed { index, item -> + if (item.item.id == itemScannedScreen) { + binding.locationRecyclerview.scrollToPosition( + index + ) + } + } + + } else { + (binding.locationRecyclerview.layoutManager as LinearLayoutManager).scrollToPosition( + 0 + ) + } + } + + private fun setAdapter(listItems: MutableList) { + listItems.sortWith { item1, item2 -> + val compareItem = item1.item.id.compareTo(item2.item.id) + if (compareItem == 0) { + item2.visible.compareTo(item1.visible) // Invertir el orden + } else { + compareItem + } + } + adapter = UbicadorAdapter6869( + listItems.sortedBy { it.isChecked }, + onPasillerosItemClickListener = pasillerosItemClickListener!!, + onVisibleClickListener = object : OnVisibleClickListener6869 { + override fun onVisibleClickListener(item: ItemShelving) { + + if (!isAutoSelf) { + + if (item.isChecked == 0) { + viewModel.updateIsChecked(itemShelvingFk = item.id) + } + + showAddItemNew( + itemUbicador = item, isEditItem = true + ) + } else { + + showAutoSelfConsumption(item) + } + + } + + }, + onMoreClickListener = object : OnMoreClickListener6869 { + + override fun onMoreClickListener(item: ItemShelving) { + showMoreOptions(item) + } + + }, + urlImage = urlImage + ) + + binding.locationRecyclerview.adapter = adapter + binding.locationRecyclerview.layoutManager = LinearLayoutManager( + requireContext(), LinearLayoutManager.VERTICAL, false + ) + } + + private fun showAutoSelfConsumption(item: ItemShelving) { + + customDialogInput.setInputText(InputType.TYPE_CLASS_NUMBER) + customDialogInput.setTitle(getString(R.string.selfConsumption)) + customDialogInput.setDescription(getString(R.string.quantityTake)).setValue("") + .setOkButton(getString(R.string.take)) { + try { + if (customDialogInput.getValue().toInt() > 0) { + val quantity = + if (item.visible - customDialogInput.getValue().toInt() > 0) { + item.visible - customDialogInput.getValue().toInt() + } else { + 0 + } + viewModel.itemShelvingSelfConsumption( + shelvingFk, item.item.id, quantity + ) + } else { + throw Exception("") + } + } catch (err: Exception) { + (getString(R.string.errorQuantity).toast(requireContext())) + } + customDialogInput.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + customDialogInput.setFocusText() + } + + private fun showAddItemNew( + isEditItem: Boolean, + itemUbicador: ItemShelving?, + ) { + customDialogUbicador = CustomDialogUbicadorNew(requireContext()) + + + if (isEditItem) { + customDialogUbicador.setTitle(getString(R.string.editItem) + itemUbicador!!.item) + .setItemValue(itemUbicador.item.id.toString()) + .setPackingValue(itemUbicador.packing.toString()) + .setVisibleValue(itemUbicador.visible.toString()) + //.setEtiquetaValue((itemUbicador.visible / (itemUbicador.packing ?: 0)).toString()) + .setEtiquetaValue(itemUbicador.stickers.toString()).setUnits( + if (itemUbicador.stickers != null && itemUbicador.stickers != 0) { + (itemUbicador.visible % itemUbicador.stickers!!).toString() + } else { + "0" + } + ).setOkButton(getString(R.string.save)) { + setShowAddItemAction(itemUbicador) + }.setKoButton(getString(R.string.close)) { + customDialogUbicador.dismiss() + }.show() + } else { + customDialogUbicador.setTitle(getString(R.string.newItem)) + .setOkButton(getString(R.string.save)) { + setShowAddItemAction(null) + }.setKoButton(getString(R.string.close)) { + customDialogUbicador.dismiss() + }.show() + } + + customDialogUbicador.getEditItem().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + + if (customDialogUbicador.getItemValue().isNotEmpty()) { + try { + + customDialogUbicador.setItemValue( + itemScanValue( + customDialogUbicador.getItemValue(), arrayOf("buy"), "more" + ).toString() + ) + + } catch (ex: Exception) { + ma.messageWithSound( + ex.message.toString(), isError = true, isPlayed = true + ) + customDialogUbicador.setItemValue("") + } + } + + return@setOnEditorActionListener true + } + + customDialogUbicador.getPackingItem().requestFocus() + } + + setWatcher() + customDialogUbicador.getEditItem().requestFocus() + ma.hideKeyboard(customDialogUbicador.getEditItem()) + + } + + private fun setShowAddItemAction(itemUbicador: ItemShelving?) { + try { + + if (customDialogUbicador.getItemValue() + .isEmpty() || customDialogUbicador.getPackingValue().isBlank() + ) { + getString(R.string.itemAndPackingMandatory).toast(context) + } else { + saveItemCall(customDialogUbicador, itemUbicador) + customDialogUbicador.dismiss() + } + } catch (ex: Exception) { + ex.message.toString().toast(requireContext()) + } + } + + private fun saveItemCall( + customDialogUbicador: CustomDialogUbicadorNew, + itemUbicador: ItemShelving?, + ) { + + if (itemUbicador?.id == null) { + //item nuevo sin shelving + try { + if (locateMultipleShelvings) insertShelvingsForUbicator( + customDialogUbicador.getItemValue().toLong(), + customDialogUbicador.getVisibleValue().toInt(), + customDialogUbicador.getPackingValue().toIntOrNull() + + ) else { + + viewModel.itemShelvingAdd( + shelving = shelvingFk, + item = customDialogUbicador.getItemValue().toLong(), + quantity = customDialogUbicador.getVisibleValue().toInt(), + packing = customDialogUbicador.getPackingValue().toIntOrNull(), + warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK), + grouping = null + ) + } + + } catch (ex: Exception) { + ma.messageWithSound( + getString(R.string.reviewData), + isError = true, + isPlayed = true, + isToasted = true + ) + } + } else { + viewModel.itemShelvingMakeEdit( + customDialogUbicador.getVisibleValue().toIntOrNull()!!, + customDialogUbicador.getPackingValue().toInt(), + itemUbicador.id, + itemUbicador.grouping, + updateAvailable( + itemUbicador.available, + customDialogUbicador.getVisibleValue().toIntOrNull(), + itemUbicador.visible + ) + ) + + } + + } + + private fun updateAvailable(newAvailable: Int?, newVisible: Int?, oldVisible: Int?): Int { + val available = newAvailable ?: 0 + val visible = newVisible ?: 0 + val old = oldVisible ?: 0 + return maxOf(available + visible - old, 0) + } + + private fun insertShelvingsForUbicator(barCode: Number, visible: Int, packing: Int?) { + if (listShelvings.isNotEmpty()) listShelvings.clear() + customDialogList = CustomDialogList(requireContext()) + customDialogList.setTitle( + getString(R.string.shelvingsLocate) + ) + customDialogList.setDescription( + getString(R.string.scanShelvingsLocate) + ).setOkButton(getString(R.string.locate)) { + listShelvings.forEach { + viewModel.itemShelvingAdd( + shelving = it.code!!, + item = barCode, + quantity = visible, + packing = packing, + warehouse = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK), + grouping = null + ) + + } + customDialogList.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + 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) { + if (customDialogList.getValue().isNotEmpty()) { + + try { + customDialogList.setValue( + itemScanValue( + customDialogList.getValue(), arrayOf("saleGroup"), field = "id" + ).toString() + ) + if (customDialogList.getValue().isShelving()) { + if (listShelvings.firstOrNull { it.code == customDialogList.getValue() } == null) { + listShelvings.add(BarcodeVO(code = customDialogList.getValue()))/*viewModel.sectorCollectionSaleGroupAdd( + customDialogList.getValue().toInt(), collectionFk + )*/ + } else { + throw Exception(getString(R.string.errorRepeatedShelving)) + } + } else { + throw Exception() + } + + } catch (ex: Exception) { + ma.messageWithSound( + getString(R.string.errorInput), + isError = true, + isPlayed = true, + isToasted = true + ) + listShelvings.removeAt(0) + } + + listShelvingsAdapter!!.notifyItemChanged(0) + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + listShelvingsAdapter = BarcodeAdapter( + listShelvings, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + + } + }, showDelete = false + ) + customDialogList.getRecyclerView().adapter = listShelvingsAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + + private fun setWatcher() { + customDialogUbicador.addTextWatcher(customDialogUbicador.getPackingItem()) { s -> + + setValueVisible() + } + + customDialogUbicador.addTextWatcher(customDialogUbicador.getEtiquetaItem()) { s -> + + setValueVisible() + } + + customDialogUbicador.addTextWatcher(customDialogUbicador.getUnitsItem()) { s -> + + setValueVisible() + } + + } + + private fun setValueVisible() { + customDialogUbicador.setVisibleValue("") + customDialogUbicador.setVisibleValue( + (((customDialogUbicador.getEtiquetaValue().toIntOrNull() + ?: 0) * (customDialogUbicador.getPackingValue().toIntOrNull() + ?: 0)) + (customDialogUbicador.getUnitsValue().toIntOrNull() ?: 0)).toString() + ) + } + + private fun showMoreOptions(item: ItemShelving) { + customDialogTwoButtons.setTitle(item.item.id.toString()) + .setDescription(getString(R.string.selectAction)) + .setOkButton(getString(R.string.transfer)) { + customDialogInput.setTitle(getString(R.string.shelvingNew)) + .setDescription(getString(R.string.selectDestiny) + item.item.id).setValue("") + .setOkButton(getString(R.string.transfer)) { + customDialogTransferAction(item) + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + customDialogInput.getEditText().requestFocus() + ma.hideKeyboard(customDialogInput.getEditText()) + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + customDialogTransferAction(item) + return@setOnEditorActionListener true + } + false + } + customDialogTwoButtons.dismiss() + }.setOkButtonTwo(getString(R.string.delete)) { + val customDialogConfirm = CustomDialog(requireContext()) + customDialogConfirm.setTitle(getString(R.string.confirm)).setDescription( + if (!isAutoSelf) { + getString(R.string.itemDeleteConfirm) + item.item.id + "?" + } else { + getString(R.string.deleteQuantity) + item.item.id + } + ).setOkButton(getString(R.string.delete)) { + if (!isAutoSelf) { + listItems.remove(item) + adapter!!.notifyItemRemoved(listItems.indexOf(item)) + viewModel.itemShelvingDelete( + item.id + ) + customDialogTwoButtons.dismiss() + customDialogConfirm.dismiss() + } else { + viewModel.itemShelvingSelfConsumption( + shelvingFk, item.id, 0 + ) + customDialogConfirm.dismiss() + customDialogTwoButtons.dismiss() + } + }.setKoButton(getString(R.string.cancel)) { + customDialogConfirm.dismiss() + customDialogTwoButtons.dismiss() + } + customDialogConfirm.show() + } + //Tarea 7266 + .setOkButtonThree(getString(R.string.print)) { + val printerDialogManager = PrinterDialogManager(requireContext()) + printerDialogManager.showPrintDialog( + item.item.id, + item.description ?: "" + ) { id, labelType, packing, copies -> + + if (item.buyFk == null) { + viewModel.buyUltimate( + itemFk = item.id, + warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( + WAREHOUSEFK + ), + dated = LocalDate.now() + .format( + DateTimeFormatter.ofPattern("yyyy-dd-MM") + ), + reportName = "LabelBuy", + printerFk = mobileApplication.dataStoreApp.readDataStoreKey( + ConstAndValues.PRINTERFK + ), + userFk = mobileApplication.userId!!, + priority = "normal", + copies = copies, + labelType = labelType, + packing = packing + ) + customDialogTwoButtons.dismiss() + } else { + printItem( + item.buyFk!!, labelType, packing, copies + ) + customDialogTwoButtons.dismiss() + } + } + customDialogInput.getEditText().requestFocus() + } + //Tarea 7763 + /* + .setOkButtonThree(getString(R.string.rename)) { + customDialogInput.setTitle(getString(R.string.itemNew)) + .setDescription(getString(R.string.scanItem)).setValue("") + .setOkButton(getString(R.string.rename)) { + + actionRename(item, customDialogInput.getValue()) + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + customDialogTwoButtons.dismiss() + }.show() + customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + + actionRename(item, customDialogInput.getValue()) + return@setOnEditorActionListener true + } + false + } + customDialogInput.getEditText().requestFocus() + } + */ + customDialogTwoButtons.setKoButton(getString(R.string.cancel)) { + customDialogTwoButtons.dismiss() + } + + customDialogTwoButtons.show() + } + + private fun printItem(id: Number?, labelType: String, packing: Int?, copies: Int?) { + + try { + viewModel.printItem( + reportName = "LabelBuy", + printerFk = mobileApplication.dataStoreApp.readDataStoreKey( + ConstAndValues.PRINTERFK + ), + userFk = mobileApplication.userId!!, + priority = "normal", + params = JSONObject().apply { + put("copies", copies) + put("id", id) + put("labelType", labelType) + put("packing", packing) + }.toString().replace("\"", "\\\"") + ) + } catch (ex: Exception) { + ma.messageWithSound(message = ex.message.toString(), isError = true, isPlayed = true) + } + hideKeyboard() + } + + private fun actionRename(item: ItemUbicador, itemScan: String) { + + if (itemScan.isNotEmpty()) { + + renameItem( + item, itemScanValue( + itemScan, arrayOf("buy"), "id" + ).toString().toLong() + ) + customDialogInput.dismiss() + customDialogTwoButtons.dismiss() + } else { + getString(R.string.scanItem).toast(requireContext()) + } + + } + + private fun renameItem(item: ItemUbicador, barCode: Long) { + try { + viewModel.getInfoFromBuy(item.id, buyFk = barCode) + } catch (ex: Exception) { + ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true) + + } + + } + + private fun customDialogTransferAction(item: ItemShelving) { + if (customDialogInput.getValue().isNotEmpty()) {/*tearea 6964*//* + viewModel.hasItemOlder( + shelvingFkIn = shelvingFk, + shelvingFkOut = customDialogInput.getValue(), + itemFk = item.id, + action = Action.TRANSFERIR + )*/ + viewModel.itemShelvingTransfer( + item.id, customDialogInput.getValue() + ) + listItems.remove(item) + adapter!!.notifyItemRemoved(listItems.indexOf(item)) + //adapter!!.notifyDataSetChanged() + customDialogInput.dismiss() + } else { + getString(R.string.wagonIncorrect).toast(requireContext()) + + } + } +} diff --git a/app/src/main/res/layout/item_ubication_row_6869.xml b/app/src/main/res/layout/item_ubication_row_6869.xml new file mode 100644 index 00000000..ae0d6582 --- /dev/null +++ b/app/src/main/res/layout/item_ubication_row_6869.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file