diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index 11831c1d..06e88a3b 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -176,6 +176,12 @@ interface SalixService { @Query("params") params: Any? = null ): Call + @POST("Applications/itemShelvingSale_reserveBySectorCollection/execute-proc") + fun getReserveBySectorCollection( + @Query("schema") schema: String = "vn", + @Query("params") params: Any? = null + ): Call + @POST("Applications/collection_addWithReservation/execute-proc") fun collectionAddWithReservation( @Query("schema") schema: String = "vn", @@ -201,6 +207,17 @@ interface SalixService { @Query("schema") schema: String = "vn" ): Call + @POST("TicketObservations") + fun addNoteFromDropOff( + @Body params: Any + ): Call + + @POST("TicketObservations/upsertWithWhere") + fun updateNoteFromDropOff( + @Query("where") where: Any? = null, + @Body params: Any //description + ): Call + @POST("Applications/item_getBalance/execute-proc") fun itemGetBalance( @Query("params") params: Any? = null, @@ -982,6 +999,8 @@ interface SalixService { @Body params: Any ): Call + + @GET("ItemShelvingSales/{id}/exists") fun itemShelvingSaleExists( @Path("id") id: Number, diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt new file mode 100644 index 00000000..b8fb8875 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt @@ -0,0 +1,292 @@ +package es.verdnatura.presentation.view.feature.presacador.fragment + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.drawable.Drawable +import android.view.View +import android.view.inputmethod.EditorInfo +import android.widget.ImageView +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentGeneralBlackBinding +import es.verdnatura.domain.ConstAndValues +import es.verdnatura.domain.notNull +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.ToolBarAdapterTooltip +import es.verdnatura.presentation.view.component.CustomDialogList +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.sacador.model.CollectionTicket + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class SectorCollectionReserveFragment( + var title: String = "", var collectionFk: Int = 0 +) : BaseFragment( + PreSacadorViewModel::class +) { + private var onCollectionSelectedListener: OnCollectionTicketSelectedListener? = null + private lateinit var customDialogList: CustomDialogList + private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null + private var listSalesGroup: ArrayList = ArrayList() + private var listSaleGroupAdapter: BarcodeAdapter? = null + + val listIcons: ArrayList = ArrayList() + + companion object { + fun newInstance(title: String, collectionFk: Int) = + SectorCollectionReserveFragment(title, collectionFk) + } + + override fun getLayoutId(): Int = R.layout.fragment_general_black + + override fun onAttach(context: Context) { + super.onAttach(context) + if (context is OnCollectionTicketSelectedListener) onCollectionSelectedListener = context + } + + override fun init() { + + customDialogList = CustomDialogList(requireContext()) + ma.hideBottomNavigation(View.GONE) + binding.mainToolbar.toolbarTitle.text = title + setEvents() + setToolBar() + checkParkingsToPicker() + println("reserve collec $collectionFk") + super.init() + } + + private fun checkParkingsToPicker() { + //Habrá que ver si tiene tickets ya asociados + binding.mainToolbar.toolbarTitle.text = collectionFk.toString() + showDialogLinkTickets() + + } + + private fun setToolBar() { + val listIcons: ArrayList = ArrayList() + + val iconReset = ImageView(context) + iconReset.setImageResource(R.drawable.ic_delete_black_24dp) + + val iconParkingFrom = ImageView(context) + iconParkingFrom.setImageResource(R.drawable.ic_mode_edit_black_24dp) + + iconParkingFrom.tooltipText = getString(R.string.editParking) + iconReset.tooltipText = getString(R.string.resetParking) + + listIcons.add(iconReset) + listIcons.add(iconParkingFrom) + + binding.mainToolbar.toolbarIcons.adapter = + ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + + when (item) { + + iconReset.drawable -> { + + } + + iconParkingFrom.drawable -> { + + showDialogLinkTickets() + } + + } + } + + }) + binding.mainToolbar.toolbarIcons.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun showDialogLinkTickets() { + + customDialogList.setTitle( + getString(R.string.tickets) + ) + customDialogList.setDescription( + + getString(R.string.scanTicketsAssociate) + ).setOkButton(getString(R.string.book)) { + try { + //Reservar colección + viewModel.getReserveBySectorCollection(collectionFk) + } catch (ex: Exception) { + ma.messageWithSound( + message = getString(R.string.errorInput), + isError = true, + isPlayed = true, + isToasted = true + ) + } + + }.setKoButton(getString(R.string.cancel)) { + ma.hideKeyboard(customDialogList.getEditText()) + listSalesGroup = ArrayList() + customDialogList.dismiss() + ma.onMyBackPressed() + }.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 { + + if (listSalesGroup.firstOrNull { it.code == customDialogList.getValue() } == null) { + listSalesGroup.add(0, BarcodeVO(code = customDialogList.getValue())) + viewModel.sectorCollectionSaleGroupAdd( + customDialogList.getValue().toInt(), + collectionFk + ) + } else { + throw Exception(getString(R.string.ticketScanned)) + } + + } catch (e: Exception) { + ma.messageWithSound( + getString(R.string.errorInput), + isError = true, + isPlayed = true, + isToasted = true + ) + listSalesGroup.removeAt(0) + } + + listSaleGroupAdapter!!.notifyItemChanged(0) + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + listSaleGroupAdapter = BarcodeAdapter( + listSalesGroup, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + + } + }, showDelete = false + ) + customDialogList.getRecyclerView().adapter = listSaleGroupAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + + @SuppressLint("SetTextI18n") + private fun setEvents() { + + binding.scanInput.visibility = View.VISIBLE + binding.scanInput.setHint(getString(R.string.scanCollection)) + binding.mainToolbar.backButton.setOnClickListener { + ma.onMyBackPressed() + } + + binding.scanInput.requestFocus() + binding.scanInput.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + + if (binding.scanInput.text.toString().isNotEmpty()) { + + try { + navigateToCollectionList(binding.scanInput.text.toString().toInt()) + + } catch (ex: Exception) { + ex.message!!.toast(requireContext()) + + } + + + binding.scanInput.setText("") + ma.hideKeyboard(binding.scanInput) + } + return@setOnEditorActionListener true + } + return@setOnEditorActionListener false + } + + } + + private fun navigateToCollectionList(collectionFk: Int) { + onCollectionSelectedListener!!.onCollectionSelected( + CollectionTicket(collectionFk = collectionFk), ConstAndValues.PREPARED, true + ) + } + + @SuppressLint("SetTextI18n") + override fun observeViewModel() { + + with(viewModel) { + + loadResponseSaleGropAdd.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + + if (it.isError) { + listSalesGroup.removeAt(0) + ma.messageWithSound( + getString(R.string.errorTicketAdd) + it.errorMessage, + isError = true, + true, + isToasted = true + ) + + } else { + ma.messageWithSound( + message = "", + isError = false, + isPlayed = true, + isToasted = false + ) + } + + } + } + loadResponseReserveSectorCollection.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + + if (it.isError) { + ma.messageWithSound( + it.errorMessage, + isError = true, + true, + isToasted = true + ) + + } else { + ma.messageWithSound( + message = "", + isError = false, + isPlayed = true, + isToasted = false + ) + customDialogList.dismiss() + ma.onPasillerosItemClickListener( + PasillerosItemVO(title = "PREITEMPICKERTEST"), + entryPoint = collectionFk.toString() + ) + + //anar a SacadorFragmentNew + + } + + } + } + + } + } +} \ No newline at end of file