From 91f3da78cfb068e73350da85840c4f508bf31711 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Wed, 16 Oct 2024 11:30:53 +0200 Subject: [PATCH] feat: refs #8090 deleteEpxpedition --- .../feature/delivery/model/InfoCompany.kt | 2 +- .../delivery/viewmodels/DeliveryViewModel.kt | 44 ++++-- .../fragment/ExpeditionDeleteFragment.kt | 148 ++++++++++++++++++ .../pasillero/fragment/PasilleroViewModel.kt | 47 ++++-- .../res/drawable/ic_delete_expedition.xml | 10 ++ 5 files changed, 220 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionDeleteFragment.kt create mode 100644 app/src/main/res/drawable/ic_delete_expedition.xml diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt index 4a560240..aa6b5b14 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt @@ -27,7 +27,7 @@ class Expeditions( class ExpeditionSalix( val expeditionFk: Number, - val stateCode: String?, + val stateCode: String? = null, val isScanned: Int? = 0 ) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt index ad6a5bcd..db8ace6b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt @@ -79,6 +79,9 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { private val _responseFindExpeditionId by lazy { MutableLiveData() } val responseFindExpeditionId: LiveData = _responseFindExpeditionId + private val _responseDeleteExpedition by lazy { MutableLiveData() } + val responseDeleteExpedition: LiveData = _responseDeleteExpedition + private val _responseUpdateRoute by lazy { MutableLiveData() } val responseUpdateRoute: LiveData get() = _responseUpdateRoute @@ -221,8 +224,6 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { } fun expeditionStateAddSalix(expeditions: Any) { - - // No se quita ResponseItem ya que en caso de fallo hay que guardar datos salix.addExpeditionState(expeditions).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { super.onSuccess(response) @@ -244,7 +245,6 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { } fun findExpedition(expedition: Number, expeditionStateId: Number) { - println("Expedition $expedition") salix.findExpedition( filter = """{"where": { @@ -265,6 +265,19 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { }) } + fun deleteExpedition(expeditionIds: ArrayList) { + salix.deleteExpedition( + hashMapOf("expeditionIds" to expeditionIds) + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + super.onSuccess(response) + _responseDeleteExpedition.value = true + + } + + }) + } + fun getExpeditionStateId(stateCode: String) { salix.getExpeditionStateTypeId( @@ -445,22 +458,21 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { } fun isBoxPickingInPrintOut(expeditionFk: Long, barcode: String) { - getItemFromBarcodeUseCase.execute(barcode) - .enqueue(object : SalixCallback(context) { + getItemFromBarcodeUseCase.execute(barcode).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - - if (response.body() != null) { - isBoxPickingOk( - itemFk = response.body().toString().toLong(), - expeditionFk = expeditionFk - ) - } else { - _responseCode.value = false - } + override fun onSuccess(response: Response) { + if (response.body() != null) { + isBoxPickingOk( + itemFk = response.body().toString().toLong(), + expeditionFk = expeditionFk + ) + } else { + _responseCode.value = false } - }) + + } + }) } fun isBoxPickingOk( diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionDeleteFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionDeleteFragment.kt new file mode 100644 index 00000000..7c5c0275 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionDeleteFragment.kt @@ -0,0 +1,148 @@ +package es.verdnatura.presentation.view.feature.paletizador.fragment + +import android.content.pm.ActivityInfo +import android.os.Bundle +import android.view.KeyEvent +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentAutomaticAddExpeditionBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnAutomaticItemClickListener +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix +import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel +import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class ExpeditionDeleteFragment(var title: String = "") : + BaseFragment( + DeliveryViewModel::class + ) { + + private var adapter: AutomaticAdapter? = null + private var contador = 0 + private var isScanned = false + private val listExpeditions: ArrayList = arrayListOf() + private var expeditionStateTypeId: Number = 0 + + companion object { + fun newInstance(title: String) = ExpeditionDeleteFragment(title = title) + + fun newInstance() = ExpeditionDeleteFragment() + } + + override fun getLayoutId(): Int = R.layout.fragment_automatic_add_expedition + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + } + + override fun onDestroyView() { + super.onDestroyView() + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } + + override fun init() { + ma.hideBottomNavigation(View.GONE) + binding.mainToolbar.toolbarTitle.text = title + setEvents() + setViews() + setToolBar() + super.init() + } + + private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = View.VISIBLE + } + + private fun setSubtitle() { + binding.mainToolbar.toolbarSubtitle.text = + getString(R.string.countNumber, getString(R.string.label), listExpeditions.size) + } + + private fun setViews() { + adapter = + AutomaticAdapter(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList, + object : OnAutomaticItemClickListener { + override fun onAutomaticItemClickListener(position: Int) { + + if (listExpeditions.size > position) { + listExpeditions.removeAt(position) + } + adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList) + setSubtitle() + } + }) + binding.itemsRecyclerview.adapter = adapter + binding.itemsRecyclerview.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + } + + private fun setEvents() { + binding.editMatricula.requestFocus() + binding.editMatricula.setOnEditorActionListener { v, actionId, event -> + + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + isScanned = + event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER + if (binding.editMatricula.text.toString().isNotEmpty()) { + try { + val itemScaned = itemScanValue( + textScanned_filterDouble(binding.editMatricula.text.toString()), + arrayOf("expedition"), + "id" + ).toString().toLong() + if (!(listExpeditions.any { it.expeditionFk == itemScaned })) { + listExpeditions.add( + ExpeditionSalix( + expeditionFk = itemScaned, + ) + ) + binding.itemsRecyclerview.scrollToPosition(0) + adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList) + } else { + ma.messageWithSound( + message = "Caja ya escaneada", + isError = true, + isPlayed = true, + isToasted = true + ) + } + } catch (ex: Exception) { + ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true) + } + } + binding.editMatricula.setText("") + ma.hideKeyboard(binding.editMatricula) + return@setOnEditorActionListener true + } else { + ma.messageWithSound( + getString(R.string.diferentAction), isError = true, isPlayed = true + ) + + } + + return@setOnEditorActionListener false + } + + binding.buttonFinalizar.setOnClickListener { + if (listExpeditions.isNotEmpty()) viewModel.deleteExpedition(listExpeditions.map { it.expeditionFk } as ArrayList) else ma.onMyBackPressed() + } + + binding.mainToolbar.backButton.setOnClickListener { + ma.onMyBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel) { + responseDeleteExpedition.observe(viewLifecycleOwner) { + ma.onMyBackPressed() + } + + } + } +} + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt index 2db81abc..7ebb926f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt @@ -5,11 +5,13 @@ import android.content.Context import es.verdnatura.MobileApplication import es.verdnatura.R import es.verdnatura.domain.ConstAndValues.RESERVATIONMODE +import es.verdnatura.domain.ConstAndValues.SECTORISONRESERVATIONMODE import es.verdnatura.domain.SalixCallback import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.view.feature.pasillero.model.CodeWorkerAction import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.WorkerActionSalix +import kotlinx.coroutines.runBlocking import retrofit2.Response class PasilleroViewModel(context: Context) : BaseViewModel(context) { @@ -21,6 +23,18 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { val userId = (contextApp as MobileApplication).userId private val isOnReservationMode = (contextApp as MobileApplication).dataStoreApp.readDataStoreKey(RESERVATIONMODE) + private val isOnReservationModeSector = + (contextApp as MobileApplication).dataStoreApp.readDataStoreKey( + SECTORISONRESERVATIONMODE + ) + private var existSectorOnReservationMode: Boolean = false + + init { + runBlocking { + existSectorOnReservationMode = + (contextApp as MobileApplication).dataStoreApp.isPreferenceExists((SECTORISONRESERVATIONMODE)) + } + } fun inititializeDefaultData() { workerActivityAdd(CodeWorkerAction.STORAGE) @@ -257,20 +271,21 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { R.string.titleCorridorsDescrip ) ) - //precontrol - _pasillerositem.add( - PasillerosItemVO( - R.drawable.ic_picker_ui, R.string.titlePickers, R.string.titlePickersDescrip - - ) - ) - - if (userId == 19591 || isOnReservationMode) { + //sacador + if (isOnReservationModeSector == true || (!existSectorOnReservationMode && isOnReservationMode)) { _pasillerositem.add( PasillerosItemVO( R.drawable.ic_picker_ui, R.string.sacador_test, R.string.sacador_test ) ) + } else { + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_picker_ui, R.string.titlePickers, R.string.titlePickersDescrip + + ) + ) + } if (userId == 19591) { _pasillerositem.add( @@ -392,9 +407,8 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { fun inititializeDefaultPrevia() { workerActivityAdd(CodeWorkerAction.PREVIOUS) - //lolass - if (isOnReservationMode) { - // if (userId == 19591 || userId == 18404 || userId == 9) { + + if (isOnReservationModeSector == true || (!existSectorOnReservationMode && isOnReservationMode)) { _pasillerositem.add( PasillerosItemVO( R.drawable.ic_previous_presacador, @@ -402,7 +416,6 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { R.string.titlePickerDescrip ) ) - //} } else { _pasillerositem.add( PasillerosItemVO( @@ -466,7 +479,13 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) ) - + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_delete_expedition, + R.string.deleteExpedition, + R.string.deleleExpeditionDescrip + ) + ) _pasillerositem.add( diff --git a/app/src/main/res/drawable/ic_delete_expedition.xml b/app/src/main/res/drawable/ic_delete_expedition.xml new file mode 100644 index 00000000..cb0a7493 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_expedition.xml @@ -0,0 +1,10 @@ + + +