From d0b8c97b1fc969dfdabf85c134f37844d6db7f22 Mon Sep 17 00:00:00 2001 From: Enrique Blasco Date: Fri, 24 Jul 2020 11:14:37 +0200 Subject: [PATCH] Pre-sacador --- app/build.gradle | 4 +- .../java/es/verdnatura/di/viewModelModule.kt | 10 + .../java/es/verdnatura/domain/ApiUtils.kt | 2 +- .../es/verdnatura/domain/ConstAndValues.kt | 1 + .../verdnatura/domain/GetPreSacadorUseCase.kt | 15 + .../es/verdnatura/domain/VerdnaturaService.kt | 13 + .../presentation/common/BindingAdapter.kt | 22 + .../collection/adapter/PlacementAdapter.kt | 4 + .../collection/fragment/CollectionFragment.kt | 7 + .../feature/main/activity/MainActivity.kt | 9 + .../feature/parking/adapter/ParkingAdapter.kt | 42 ++ .../parking/fragment/ParkingFragment.kt | 146 ++++ .../parking/fragment/ParkingViewModel.kt | 53 ++ .../pasillero/fragment/PasilleroViewModel.kt | 13 + .../presacador/adapter/PreSacadorAdapter.kt | 93 +++ .../presacador/fragment/PreSacadorFragment.kt | 621 ++++++++++++++++++ .../fragment/PreSacadorViewModel.kt | 176 +++++ .../feature/presacador/mapper/SaleMapper.kt | 26 + .../presacador/model/PreSacadorItemVO.kt | 18 + .../feature/sacador/model/TicketItemVO.kt | 2 + .../drawable/ic_local_parking_black_24dp.xml | 4 +- .../drawable/ic_local_parking_orange_24dp.xml | 5 + .../res/drawable/ic_streetview_black_24dp.xml | 7 + .../res/drawable/ic_swap_horiz_black_24dp.xml | 5 + app/src/main/res/layout/fragment_parking.xml | 97 +++ .../main/res/layout/fragment_pre_sacador.xml | 86 +++ app/src/main/res/layout/item_article_row.xml | 7 - .../res/layout/item_pasilleros_main_menu.xml | 3 +- 28 files changed, 1478 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/es/verdnatura/domain/GetPreSacadorUseCase.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/common/BindingAdapter.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/parking/adapter/ParkingAdapter.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingFragment.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingViewModel.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/presacador/adapter/PreSacadorAdapter.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorFragment.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/presacador/mapper/SaleMapper.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/presacador/model/PreSacadorItemVO.kt create mode 100644 app/src/main/res/drawable/ic_local_parking_orange_24dp.xml create mode 100644 app/src/main/res/drawable/ic_streetview_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_swap_horiz_black_24dp.xml create mode 100644 app/src/main/res/layout/fragment_parking.xml create mode 100644 app/src/main/res/layout/fragment_pre_sacador.xml diff --git a/app/build.gradle b/app/build.gradle index 6d597bc4..8fe85f30 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "es.verdnatura" minSdkVersion 21 targetSdkVersion 29 - versionCode 16 - versionName "5.0.16" + versionCode 19 + versionName "5.0.19" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index f823577e..a7f04252 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -13,7 +13,9 @@ import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPa import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPalletViewModel import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionScanViewModel import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionTruckListViewModel +import es.verdnatura.presentation.view.feature.parking.fragment.ParkingViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel +import es.verdnatura.presentation.view.feature.presacador.fragment.PreSacadorViewModel import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorViewModel import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemViewModel @@ -105,4 +107,12 @@ val viewModelModule = module{ viewModel { ControladorViewModel() } + + viewModel { + ParkingViewModel() + } + + viewModel { + PreSacadorViewModel() + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt index dcc8943b..68eac4c2 100644 --- a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt +++ b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit class ApiUtils { companion object { - //const val BASE_URL:String = "http://192.168.1.101:8009/" + //const val BASE_URL:String = "http://192.168.1.104:8009/" const val BASE_URL:String = "https://app.verdnatura.es/" fun getApiService():VerdnaturaService{ val retrofit = Retrofit.Builder() diff --git a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt index 9ae9c45d..cabcfba2 100644 --- a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt +++ b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt @@ -7,5 +7,6 @@ object ConstAndValues { const val PREPARED = "PREPARED" const val ON_PREPARATION = "ON_PREPARATION" const val CHECKED = "CHECKED" + const val PRESACADOR = "PRESACADOR" } diff --git a/app/src/main/java/es/verdnatura/domain/GetPreSacadorUseCase.kt b/app/src/main/java/es/verdnatura/domain/GetPreSacadorUseCase.kt new file mode 100644 index 00000000..796d5789 --- /dev/null +++ b/app/src/main/java/es/verdnatura/domain/GetPreSacadorUseCase.kt @@ -0,0 +1,15 @@ +package es.verdnatura.domain + +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO +import retrofit2.Call + +class GetPreSacadorUseCase() : RestClient() { + + fun ticketToPrePrepare(usuario:String,password:String,ticketFk:String,sectorFk:String) : Call> { + val params:ArrayList = ArrayList(); + params.add(ticketFk) + params.add(sectorFk) + return restClient!!.ticketToPrePrepare("json","1",usuario,password,"application/json",params) + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index c2d273e7..62e3352e 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -10,6 +10,7 @@ import es.verdnatura.presentation.view.feature.faltas.model.ItemFaltasVO import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.paletizador.model.* +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO @@ -52,6 +53,18 @@ interface VerdnaturaService { @Header("pass") pass: String, @Header("Content-Type") content_type: String): Call> + //PRESACADORES ========================================================================> + + @POST("almacennew/ticketToPrePrepare") + fun ticketToPrePrepare(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call> + + //SACADORES / CONTROLADORES ========================================================================> diff --git a/app/src/main/java/es/verdnatura/presentation/common/BindingAdapter.kt b/app/src/main/java/es/verdnatura/presentation/common/BindingAdapter.kt new file mode 100644 index 00000000..b52460bf --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/common/BindingAdapter.kt @@ -0,0 +1,22 @@ +package es.verdnatura.presentation.common + +import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE +import androidx.databinding.BindingAdapter +import org.koin.core.KoinComponent + +object BindingAdapter : KoinComponent { + + /** + * Set view visibility depending boolean + * + * @param isVisible - If true, set view to VISIBLE, else set view to GONE + */ + @BindingAdapter("isVisible") + @JvmStatic + fun View.isVisible(isVisible: Boolean) { + visibility = if (isVisible) VISIBLE else GONE + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/PlacementAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/PlacementAdapter.kt index f1ead86d..04482862 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/PlacementAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/PlacementAdapter.kt @@ -32,6 +32,10 @@ class PlacementAdapter ( ) : RecyclerView.ViewHolder(binding.root){ fun bind(placement: PlacementVO) { binding.apply { + if (placement.placement.isNullOrEmpty()) + placement.placement = placement.parking + if (placement.visible.isNullOrEmpty()) + placement.visible = "("+placement.stockTotal+")" this.item = placement itemRootLayout.setOnClickListener { onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = "Ubicador"),placement.shelving) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt index d3c77636..d449f2ee 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt @@ -248,6 +248,7 @@ class CollectionFragment( onQuantityOfShelvingSelected(itemShelvingFkStored) }else{ customDialogList.setValueTwo("") + showErrorMessage("El resultado del procedimiento barcodeToItem de la etiqueta escaneada es: " +it.response) mperror?.start() } } @@ -1066,6 +1067,12 @@ class CollectionFragment( } } + + private fun showErrorMessage(text:String){ + customDialog.setTitle("Error al marcar la linea").setDescription(text).setKoButton("Cerrar"){ + customDialog.dismiss() + }.show() + } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index c56800c6..cab325bd 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -27,8 +27,10 @@ import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionSc import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionTruckListFragment import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO +import es.verdnatura.presentation.view.feature.parking.fragment.ParkingFragment import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.presacador.fragment.PreSacadorFragment import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorFragment import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment @@ -163,9 +165,16 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick override fun onPasillerosItemClickListener(item: PasillerosItemVO, entryPoint: String) { when (item.title){ + + "Pre Sacador" -> { + addFragmentOnTop(PreSacadorFragment.newInstance()) + } "Consultar artículo" -> { addFragmentOnTop(ItemCardFragment.newInstance(entryPoint)) } + "Parking" -> { + addFragmentOnTop(ParkingFragment.newInstance()) + } "Buscar item" -> { addFragmentOnTop(BuscarItemFragment.newInstance(entryPoint)) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/parking/adapter/ParkingAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/adapter/ParkingAdapter.kt new file mode 100644 index 00000000..9b82cc85 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/adapter/ParkingAdapter.kt @@ -0,0 +1,42 @@ +package es.verdnatura.presentation.view.feature.parking.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemBarcodeRowBinding +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO + + +class ParkingAdapter ( + private val items: List, + private val onBarcodeRowClickListener: OnBarcodeRowClickListener +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemBarcodeRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onBarcodeRowClickListener.onBarcodeRowClickListener(items[position]) + } + } + + + inner class ItemHolder( + val binding: ItemBarcodeRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + fun bind(item: BarcodeVO) { + binding.apply { + this.item = item + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingFragment.kt new file mode 100644 index 00000000..fa25a31b --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingFragment.kt @@ -0,0 +1,146 @@ +package es.verdnatura.presentation.view.feature.parking.fragment + +import android.content.SharedPreferences +import android.media.MediaPlayer +import android.os.Bundle +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentParkingBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.hideKeyboard +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.parking.adapter.ParkingAdapter +import kotlinx.android.synthetic.main.fragment_parking.* +import kotlinx.android.synthetic.main.toolbar.* + +class ParkingFragment : BaseFragment(ParkingViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private lateinit var customDialog: CustomDialog + private var scanerList:ArrayList = ArrayList() + private var adapter : ParkingAdapter? = null + private var numParking : Int = 0 + var mperror: MediaPlayer? = null + var mpok: MediaPlayer? = null + + + override fun getLayoutId(): Int = R.layout.fragment_parking + companion object { + fun newInstance() = ParkingFragment() + } + + + override fun init() { + setEvents() + toolbar_title.text = "Parking" + viewModel.hideProgressLoading() + setList() + customDialog = CustomDialog(requireContext()) + super.init() + } + + private fun setEvents(){ + scan_input.requestFocus() + scan_input.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!scan_input.text.isNullOrEmpty()) { + checkScan(scan_input.text.toString()) + } + scan_input.setText("") + requireActivity().hideKeyboard() + return@setOnEditorActionListener true + } + false + } + + backButton.setOnClickListener { + activity!!.onBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel){ + response.observe(viewLifecycleOwner, Observer { + if (it.isError){ + mperror?.start() + splash_progress.visibility = View.GONE + customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Cerrar"){ + customDialog.hide() + }.show() + }else{ + numParking -= 1 + if (numParking <= 0) { + splash_progress.visibility = View.GONE + viewModel.hideProgressLoading() + mpok?.start() + setList() + } + } + }) + } + } + + private fun setList(){ + scanerList = ArrayList() + adapter = ParkingAdapter(scanerList,object: OnBarcodeRowClickListener{ + override fun onBarcodeRowClickListener(item: BarcodeVO) { + scanerList.removeAt(scanerList.indexOf(item)) + adapter?.notifyDataSetChanged() + } + }) + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + fragment_parking_scan_list.adapter = adapter + fragment_parking_scan_list.layoutManager = lm + } + + private fun checkScan(txtScan:String){ + var isParking:Boolean = false + if (txtScan.trim().length == 4 && isLetter(txtScan.substring(txtScan.length - 1)) || txtScan.contains("-")){ + isParking = true + } + + if (isParking){ + numParking = scanerList.size + scanerList.forEach { + splash_progress.visibility = View.VISIBLE + viewModel.parking( + usuario = user, + password = password, + parking = txtScan, + scanItem = it.code!! + ) + } + }else{ + scanerList.add(BarcodeVO(code = txtScan)) + adapter?.notifyDataSetChanged() + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + mperror = MediaPlayer.create((activity as MainActivity),R.raw.error) + mpok = MediaPlayer.create((activity as MainActivity),R.raw.ok) + super.onCreate(savedInstanceState) + } + + @Throws(NumberFormatException::class) + fun isLetter(text: String): Boolean { + return text.matches("[a-zA-Z ]+".toRegex()) + } + + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingViewModel.kt new file mode 100644 index 00000000..4f8f8d8e --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/parking/fragment/ParkingViewModel.kt @@ -0,0 +1,53 @@ +package es.verdnatura.presentation.view.feature.parking.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetUbicadorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.ResponseItemVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class ParkingViewModel : BaseViewModel() { + private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() + + private val _response by lazy { MutableLiveData() } + val response: LiveData + get() = _response + + private val _isLoading by lazy { MutableLiveData() } + val isLoading: LiveData = _isLoading + + private fun showProgressLoading() { + _isLoading.value = true + } + + fun hideProgressLoading() { + _isLoading.value = false + } + + + fun parking(usuario: String,password: String,scanItem: String,parking:String){ + showProgressLoading() + getUbicadorUserCase.shelvingPark(usuario,password,scanItem,parking).enqueue(object : + Callback { + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada shelvingPark") + }else{ + if (response.body() == "Finish") + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + else + _response.value = ResponseItemVO(isError = true,errorMessage = "No existe el parking en la Base de Datos (shelvingPark)") + } + } + }) + } + + +} 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 6cc429d6..ebfe63c6 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 @@ -12,12 +12,25 @@ class PasilleroViewModel : BaseViewModel() { fun inititializeDefaultData() { + + _pasillerositem.add( + PasillerosItemVO(7, + R.drawable.ic_streetview_black_24dp, + "Pre Sacador") + ) + _pasillerositem.add( PasillerosItemVO(0, R.drawable.ic_loyalty_black_24dp, "Consultar artículo") ) + _pasillerositem.add( + PasillerosItemVO(6, + R.drawable.ic_local_parking_orange_24dp, + "Parking") + ) + _pasillerositem.add( PasillerosItemVO(2, R.drawable.ic_visibility_black_24dp, diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/adapter/PreSacadorAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/adapter/PreSacadorAdapter.kt new file mode 100644 index 00000000..246e886b --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/adapter/PreSacadorAdapter.kt @@ -0,0 +1,93 @@ +package es.verdnatura.presentation.view.feature.presacador.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.ItemArticleRowBinding +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.common.OnQuantityClickListener +import es.verdnatura.presentation.common.OnSaleClickListener +import es.verdnatura.presentation.view.feature.collection.adapter.PlacementAdapter +import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapter +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.presacador.mapper.toSale +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO +import es.verdnatura.presentation.view.feature.sacador.model.SaleVO + +class PreSacadorAdapter ( + private val items: List, + private val onPasillerosItemClickListener: OnPasillerosItemClickListener, + private val onSaleClickListener: OnSaleClickListener +): RecyclerView.Adapter () { + var context: Context? = null + var position:Int = 0 + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { + this.context = parent.context + return AjustesItemHolder( + ItemArticleRowBinding.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: ItemArticleRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + fun bind(preSale: PreSacadorItemVO) { + binding.apply { + + val sale : SaleVO = preSale.toSale() + + if (sale.pickedQuantity.isNullOrEmpty()) + sale.pickedQuantity = "0" + + val childLayoutManager = LinearLayoutManager(context!!, RecyclerView.HORIZONTAL, false) + + itemArticlePlacements.apply { + layoutManager = childLayoutManager + adapter = PlacementAdapter(sale.placements,onPasillerosItemClickListener) + } + + //CLICK EVENTS + contentLayout.setOnClickListener { + onSaleClickListener.onSaleClick(sale) + } + + itemArticleItemFk.setOnClickListener { + onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = "Consultar artículo"),sale.itemFk) + } + + + //SEMAFORO + if (sale.isPreviousPrepared == "1"){ + itemArticleRowSemaforoPre.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_dark_sky_blue)) + }else{ + itemArticleRowSemaforoPre.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_warm_grey)) + } + + + + if (sale.isPreviousPrepared == "1"){ + contentLayout.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_dark_sky_blue)) + }else{ + contentLayout.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_black)) + } + + + //ASIGNAMOS VALOR A LA VSITA + this.sale = sale + + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorFragment.kt new file mode 100644 index 00000000..a8e19b6c --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorFragment.kt @@ -0,0 +1,621 @@ +package es.verdnatura.presentation.view.feature.presacador.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.graphics.drawable.Drawable +import android.media.MediaPlayer +import android.os.Bundle +import android.view.View +import android.view.inputmethod.EditorInfo +import android.view.inputmethod.InputMethodManager +import android.widget.Toast +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.FragmentPreSacadorBinding +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.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.inventario.adapter.ToolBarAdapter +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.presacador.adapter.PreSacadorAdapter +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO +import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyListVO +import es.verdnatura.presentation.view.feature.sacador.model.SaleVO +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_pre_sacador.* +import kotlinx.android.synthetic.main.toolbar.* +import es.verdnatura.domain.ConstAndValues.PRESACADOR +import es.verdnatura.presentation.view.component.CustomDialogInput + +class PreSacadorFragment : BaseFragment(PreSacadorViewModel::class) { + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + var mperror: MediaPlayer? = null + var mpok: MediaPlayer? = null + private var sales:ArrayList = ArrayList() + private lateinit var customDialog: CustomDialog + private lateinit var customDialogList: CustomDialogList + private var saleAdapter: PreSacadorAdapter? = null + private var ticket:String = "" + private var lm : LinearLayoutManager? = null + private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null + private var storedPosition: Int = 0 + private var storedBackPosition : Int = 0 + private var storedShelvingPosition:Int = 0 + private var itemShelvingFkStored : String = "" + private var goBack:Boolean = false + private var goBack2:Boolean = false + private var listPlacementSupply:ArrayList = ArrayList() + private var placementSupplyAdapter : BarcodeAdapter? = null + private lateinit var customDialogInput: CustomDialogInput + + override fun onAttach(context: Context) { + if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context + super.onAttach(context) + } + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + mperror = MediaPlayer.create((activity as MainActivity),R.raw.error) + mpok = MediaPlayer.create((activity as MainActivity),R.raw.ok) + + super.onCreate(savedInstanceState) + } + + override fun init() { + customDialog = CustomDialog(requireContext()) + customDialogList = CustomDialogList(requireContext()) + customDialogInput = CustomDialogInput(requireContext()) + activity!!.main_bottom_navigation.visibility = View.GONE + splash_progress.visibility = View.GONE + toolbar_title.text = "ticketToPrePrepare" + setToolBar() + setEvents() + super.init() + } + + private fun setEvents(){ + backButton.setOnClickListener { + activity!!.onBackPressed() + } + //ESCANER ========= + hideKeyboards() + scan_input.requestFocus() + scan_input.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!scan_input.text.toString().isNullOrEmpty()){ + if (scan_input.text.contains("-")){ + //es parking + parkingTicket(scan_input.text.toString()) + }else{ + if (scan_input.text.length > 6){ + //es ticket + searchTicket(scan_input.text.toString()) + }else{ + //es sale + findSale(scan_input.text.toString()) + } + } + + + } + scan_input.setText("") + hideKeyboards() + return@setOnEditorActionListener true + } + true + } + + hideKeyboards() + + //LISTA ========= + collection_swipe.setOnRefreshListener { + splash_progress.visibility = View.VISIBLE + searchTicket(ticket) + collection_swipe.isRefreshing = false + } + } + + override fun observeViewModel() { + with(viewModel){ + salesList.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + createSaleList(it) + }) + + placementSuppleyList.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if (!goBack) printShelvingResult(it) + goBack = false + }) + + responseCode.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if (!goBack2){ + if (it.isError){ + customDialog.setTitle("Error").setDescription(it.errorMessage).setKoButton("Cerrar"){ + scanRequest() + customDialog.dismiss() + }.show() + }else{ + if (checkItemScan(it.response)){ + scanRequest() + customDialogList.dismiss() + mpok?.start() + onQuantityOfShelvingSelected(itemShelvingFkStored) + }else{ + customDialogList.setValueTwo("") + showErrorMessage("El resultado del procedimiento barcodeToItem de la etiqueta escaneada es: " +it.response) + mperror?.start() + } + } + } + + goBack2 = false + + }) + } + } + + //CREATE LIST + private fun searchTicket(ticketFk:String){ + ticket = ticketFk + splash_progress.visibility = View.VISIBLE + viewModel.ticketToPrePrepare( + usuario = user, + password = password, + ticketFk = ticketFk, + sectorFk = sectorFk + ) + } + + private fun createSaleList(salesList : List){ + splash_progress.visibility = View.GONE + if (salesList.isNullOrEmpty()){ + customDialog.setTitle("Pre Sacador").setDescription("No hemos podido obtener movimientos para el ticket escaneado").setKoButton("Cancelar"){ + customDialog.dismiss() + }.show() + }else{ + toolbar_title.text = ticket + sales = ArrayList() + salesList.forEach { + sales.add(it) + } + lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + saleAdapter = PreSacadorAdapter(sales,pasillerosItemClickListener!!,object : + OnSaleClickListener { + override fun onSaleClick(sale: SaleVO) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.idMovimiento == sale.saleFk) { + if (saleVO.quantity != saleVO.picked) { + showScanner(index, saleVO) + } else { + unMarkLine(index) + } + } + } + } + }) + fragment_sacador_collections.adapter = saleAdapter + fragment_sacador_collections.layoutManager = lm + + setTotalLines() + if (storedPosition != 0) + setListPosition(storedPosition) + else if (storedBackPosition != 0) + setListPosition(storedBackPosition) + + setScrollListener(lm!!) + } + } + + private fun setScrollListener(lm: LinearLayoutManager){ + fragment_sacador_collections.addOnScrollListener(object : RecyclerView.OnScrollListener(){ + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + storedBackPosition = lm.findFirstVisibleItemPosition() + super.onScrolled(recyclerView, dx, dy) + } + }) + } + + private fun setTotalLines(){ + var totalMark = 0 + sales.forEach { + if (it.quantity == it.picked) + totalMark += 1 + } + toolbar_title.text = ticket + toolbar_subtitle.text = "" +totalMark + "/" + sales.size + if (totalMark == sales.size) { + "Ticket completo".toast(this.context, Toast.LENGTH_SHORT) + } + } + + private fun setListPosition(position:Int){ + storedPosition = position + fragment_sacador_collections.addViewObserver { + lm!!.scrollToPositionWithOffset(position,0) + } + } + + //SEARCH AND MARK + private fun findSale(txtscan:String){ + var index = 0 + var isBreak = false + var isOk = false + + for (saleVO in sales) { + if(saleVO.quantity != saleVO.picked){ + //1- Por carro + var shelvingIndex = 0 + for (placementVO in saleVO.carros){ + if (txtscan.toUpperCase() == placementVO.shelving.toUpperCase()){ + mpok!!.start() + isOk = true + showShelving(index,shelvingIndex) + isBreak = true + break + } + shelvingIndex+=1 + } + if (isBreak) break + } + index += 1 + } + + if (!isOk) { + mperror!!.start() + ("Elemento escaneado no encontrado: "+txtscan).toast(requireContext()) + } + + } + + private fun findSale(txtscan:String,position: Int){ + var index = 0 + var isBreak = false + var isOk = false + + val saleVO = sales[position] + + if(saleVO.quantity != saleVO.picked){ + //1- Por carro + var shelvingIndex = 0 + for (placementVO in saleVO.carros){ + if (txtscan.toUpperCase() == placementVO.shelving.toUpperCase()){ + mpok!!.start() + isOk = true + showShelving(position,shelvingIndex) + isBreak = true + break + } + shelvingIndex+=1 + } + } + index += 1 + + + if (!isOk) { + mperror!!.start() + ("Elemento escaneado no encontrado: "+txtscan).toast(requireContext()) + } + + } + + private fun markLine(position:Int){ + + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + saleTrackingReplace(position) + setTotalLines() + } + + private fun saleTrackingReplace(position: Int){ + viewModel.saleTrackingReplace( + usuario = user, + password = password, + saleFk = sales[position].idMovimiento, + vIsChecked = if (sales[position].picked == sales[position].quantity) "1" else "0", + vOriginalQuantity = sales[position].picked.toString(), + vStateFk = PRESACADOR + ) + } + + private fun unMarkLine(position: Int){ + + if (sales[position].quantity == sales[position].picked){ + customDialog.setTitle("Desmarcar linea").setDescription("Vas a desmarcar la linea: "+sales[position].itemFk+ " ¿Estás seguro?").setOkButton("Desmarcar"){ + sales[position].picked = 0 + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + viewModel.saleTrackingDel( + usuario = user, + password = password, + saleFk = sales[position].idMovimiento + ) + setTotalLines() + scanRequest() + customDialog.dismiss() + }.setKoButton("Cancelar"){ + scanRequest() + customDialog.dismiss() + }.show() + } + + + + } + + //SHELVINGS + private fun showShelving(position:Int,shelvingPosition:Int){ + storedShelvingPosition = shelvingPosition + storedPosition = position + splash_progress.visibility = View.VISIBLE + var quantityGet = "0" + try{ + quantityGet = (sales[position].quantity - sales[position].picked).toString() + }catch (e:Exception){} + viewModel.itemPlacementSupplyAiming( + usuario = user, + password = password, + itemFk = sales[position].itemFk, + quantity = quantityGet, + shelvingFk = sales[position].carros[shelvingPosition].shelving + ) + } + + private fun printShelvingResult(placementSupplyListVO: PlacementSupplyListVO){ + var shelving = "" + var item = "" + var longName = "" + var total = "0" + var itemShelvingFk = "0" + if (!placementSupplyListVO.list.isEmpty()){ + val placement = placementSupplyListVO.list[0] + shelving = placement.shelving + item = placement.itemFk + longName = placement.longName + total = placement.total + itemShelvingFk = placement.itemShelvingFk + } + listPlacementSupply = ArrayList() + placementSupplyListVO.list.forEach { + listPlacementSupply.add(BarcodeVO(code = it.proposal)) + } + + customDialogList.setTitle("$shelving($item) $total de $longName").setOkButton("Coger"){ + if (customDialogList.getValueTwo().isNotEmpty()){ + if (checkItemScan(customDialogList.getValueTwo())){ + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + }else{ + itemShelvingFkStored = itemShelvingFk + splash_progress.visibility = View.VISIBLE + viewModel.getIdFromCode( + usuario = user, + password = password, + code = customDialogList.getValueTwo() + ) + customDialogList.dismiss() + } + scanRequest() + hideKeyboards() + }else{ + "Escanea item para validar".toast(requireContext()) + } + + + }.setKoButton("Cerrar"){ + scanRequest() + hideKeyboards() + customDialogList.dismiss() + }.setHintValue("Cantidad que coges:").setValue(total).setHintValueTwo("Escanea item").setValueTwo("").show() + + + customDialogList.getEditTextTwo().post(Runnable { + customDialogList.getEditTextTwo().requestFocusFromTouch() + val lManager: InputMethodManager = + activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + lManager.hideSoftInputFromWindow(customDialogList.getEditTextTwo().windowToken, InputMethodManager.SHOW_FORCED) + }) + + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (customDialogList.getValueTwo().isNotEmpty()){ + if (checkItemScan(customDialogList.getValueTwo())){ + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + customDialogList.dismiss() + }else{ + itemShelvingFkStored = itemShelvingFk + splash_progress.visibility = View.VISIBLE + viewModel.getIdFromCode( + usuario = user, + password = password, + code = customDialogList.getValueTwo() + ) + customDialogList.dismiss() + } + }else{ + "Escanea item para validar".toast(requireContext()) + } + scanRequest() + hideKeyboards() + return@setOnEditorActionListener true + + } + false + } + + 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 onQuantityOfShelvingSelected(itemShelvingFk:String){ + //1 - MODIFICAR CANTIDAD DEL CARRO + try { + val shelvingVisible = sales[storedPosition].carros[storedShelvingPosition].stockTotal + + sales[storedPosition].carros[storedShelvingPosition].stockTotal = (shelvingVisible.toInt() - customDialogList.getValue().toInt()).toString() + + viewModel.itemShelvingSaleSupplyAdd( + usuario = user, + password = password, + itemShelvingFk = itemShelvingFk, + saleFk = sales[storedPosition].idMovimiento, + quantity = customDialogList.getValue() + ) + + }catch (e:Exception){} + + //2- MODIFICAR EL PICKED DEL SALE + try{ + sales[storedPosition].picked = sales[storedPosition].picked + customDialogList.getValue().toInt() + }catch (e:Exception){} + + //3- MARCAR LINEA + markLine(storedPosition) + + + } + + private fun checkItemScan(valueToCheck:String):Boolean{ + val saleToCheck = sales[storedPosition] + return saleToCheck.itemFk == valueToCheck + } + + private fun showScanner(index:Int, sale:PreSacadorItemVO){ + customDialogInput.setTitle(""+sale.itemFk).setDescription("Escanea el carro para el item seleccionado").setOkButton("Aceptar"){ + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(),index) + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + }.setKoButton("Cancelar"){ + customDialogInput.dismiss() + }.setValue("").show() + customDialogInput.getEditText().requestFocus() + customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!customDialogInput.getValue().isNullOrEmpty()) { + findSale(customDialogInput.getValue(),index) + } + customDialogInput.setValue("") + scanRequest() + customDialogInput.dismiss() + hideKeyboards() + return@setOnEditorActionListener true + } + false + } + + } + + //OPTIONS + private fun print(){ + viewModel.collectionStickerPrint( + usuario = user, + password = password, + collectionFk = ticket, + sectorFk = sectorFk + ) + "Imprimiendo...".toast(requireContext()) + } + + //OTROS + private fun setToolBar(){ + toolbar_subtitle.visibility = View.VISIBLE + + val listIcons:ArrayList = ArrayList() + val iconPrint : Drawable = resources.getDrawable(R.drawable.ic_print_black_24dp,resources.newTheme()) + val iconParking : Drawable = resources.getDrawable(R.drawable.ic_local_parking_black_24dp,resources.newTheme()) + val iconTransferir : Drawable = resources.getDrawable(R.drawable.ic_swap_horiz_black_24dp,resources.newTheme()) + + listIcons.add(iconPrint) + listIcons.add(iconParking) + listIcons.add(iconTransferir) + + toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + if (item == iconPrint){ + print() + }else if (item == iconParking){ + pasillerosItemClickListener?.onPasillerosItemClickListener(PasillerosItemVO(title = "Parking"),"") + }else if (item == iconTransferir){ + "Transferir".toast(requireContext()) + } + } + }) + toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun scanRequest(){ + scan_input.requestFocus() + hideKeyboards() + } + + private fun hideKeyboards(){ + requireActivity().hideKeyboard() + } + + private fun parkingTicket(parking:String){ + viewModel.parking( + usuario = user, + password = password, + ticketFk = ticket, + parking = parking + ) + mpok!!.start() + "Ticket aparcado".toast(requireContext()) + } + + companion object { + fun newInstance() = PreSacadorFragment() + } + + override fun getLayoutId(): Int = R.layout.fragment_pre_sacador + + override fun onPause() { + goBack = true + goBack2 = true + super.onPause() + } + + private fun showErrorMessage(text:String){ + customDialog.setTitle("Error al marcar la linea").setDescription(text).setKoButton("Cerrar"){ + customDialog.dismiss() + }.show() + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt new file mode 100644 index 00000000..bb9d3b37 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/PreSacadorViewModel.kt @@ -0,0 +1,176 @@ +package es.verdnatura.presentation.view.feature.presacador.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetPreSacadorUseCase +import es.verdnatura.domain.GetSacadorControladorUserCase +import es.verdnatura.domain.GetUbicadorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.ResponseItemVO +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO +import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyListVO +import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class PreSacadorViewModel : BaseViewModel() { + private val getPreSacadorUseCase: GetPreSacadorUseCase = GetPreSacadorUseCase() + private val getSacadorControladorUserCase: GetSacadorControladorUserCase = GetSacadorControladorUserCase() + private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() + + private val _salesList by lazy { MutableLiveData>() } + val salesList: LiveData> + get() = _salesList + + private val _response by lazy { MutableLiveData() } + val response: LiveData + get() = _response + + private val _placementSuppleyList by lazy { MutableLiveData() } + val placementSuppleyList: LiveData + get() = _placementSuppleyList + + private val _responseCode by lazy { MutableLiveData() } + val responseCode: LiveData + get() = _responseCode + + + fun ticketToPrePrepare(usuario:String,password:String,ticketFk:String,sectorFk:String){ + getPreSacadorUseCase.ticketToPrePrepare(usuario,password,ticketFk,sectorFk).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + _salesList.value = listOf() + } + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _salesList.value = response.body()?.let { it } + }else{ + _salesList.value = listOf() + } + } + }) + } + + fun collectionStickerPrint(usuario:String,password:String,collectionFk: String,sectorFk: String){ + getSacadorControladorUserCase.collectionStickerPrint(usuario,password,collectionFk,sectorFk).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada collectionStickerPrint") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun parking(usuario: String,password: String,ticketFk: String,parking:String){ + getUbicadorUserCase.shelvingPark(usuario,password,ticketFk,parking).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada shelvingPark") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun itemPlacementSupplyAiming(usuario:String,password:String,shelvingFk:String,quantity:String,itemFk:String){ + getSacadorControladorUserCase.itemPlacementSupplyAiming(usuario,password,shelvingFk,quantity,itemFk).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(PlacementSupplyVO(isError = true,errorMessage = t.message!!)) + _placementSuppleyList.value = PlacementSupplyListVO(listError) + } + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _placementSuppleyList.value = response.body()?.let { PlacementSupplyListVO(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(PlacementSupplyVO(isError = true,errorMessage = "Error en la llamada de itemPlacementSupplyAiming")) + _placementSuppleyList.value = PlacementSupplyListVO(listError) + } + } + }) + } + + fun itemShelvingSaleSupplyAdd(usuario:String,password:String,itemShelvingFk:String,saleFk:String,quantity:String){ + getSacadorControladorUserCase.itemShelvingSaleSupplyAdd(usuario,password,itemShelvingFk,saleFk,quantity).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada itemShelvingSaleSupplyAdd") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun saleTrackingReplace(usuario:String,password:String,saleFk:String,vOriginalQuantity:String,vStateFk:String,vIsChecked:String){ + getSacadorControladorUserCase.saleTrackingReplace(usuario,password,saleFk,vOriginalQuantity,vStateFk,vIsChecked).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada saleTracking_Replace") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun getIdFromCode(usuario:String,password:String,code: String){ + getSacadorControladorUserCase.getIdFromCode(usuario,password,code).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _responseCode.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _responseCode.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada barcodeToItem") + }else{ + _responseCode.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun saleTrackingDel(usuario:String,password:String,saleFk: String){ + getSacadorControladorUserCase.saleTrackingDel(usuario,password,saleFk).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = ""+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada collectionMissingTrash") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/mapper/SaleMapper.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/mapper/SaleMapper.kt new file mode 100644 index 00000000..56020ef2 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/mapper/SaleMapper.kt @@ -0,0 +1,26 @@ +package es.verdnatura.presentation.view.feature.presacador.mapper + +import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO +import es.verdnatura.presentation.view.feature.sacador.model.SaleVO + +fun PreSacadorItemVO.toSale() : SaleVO { + return SaleVO( + ticketFk = id, + level = "1", + saleFk = idMovimiento, + itemFk = itemFk, + quantity = saldo.toString(), + longName = longName, + isPreviousPrepared = if (quantity == picked) "1" else "0", + line1 = longName, + line2 = if (subName.isNullOrEmpty()) "" else subName, + pickedQuantity = picked.toString(), + workerFk = trabajador, + originalQuantity = quantity.toString(), + placements = carros, + agencyName = trabajador + ) +} + + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/model/PreSacadorItemVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/model/PreSacadorItemVO.kt new file mode 100644 index 00000000..ef96fa67 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/model/PreSacadorItemVO.kt @@ -0,0 +1,18 @@ +package es.verdnatura.presentation.view.feature.presacador.model + +import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO + +class PreSacadorItemVO ( + var id : String = "", + var itemFk : String = "", + var longName : String = "", + var subName : String = "", + var quantity : Int = 0, + var saldo : Int = 0, + var picked : Int = 45, + var idMovimiento : String = "", + var trabajador : String = "", + var carros : List = listOf() +) + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt index 97f5906e..e9bfdadf 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt @@ -56,6 +56,8 @@ class PlacementVO( var saleFk : String = "", var itemFk : String = "", var placement : String = "", + var parking : String = "", + var stockTotal : String = "", var shelving : String = "", var created : String = "", var visible : String = "", diff --git a/app/src/main/res/drawable/ic_local_parking_black_24dp.xml b/app/src/main/res/drawable/ic_local_parking_black_24dp.xml index 94b2874b..1592149d 100644 --- a/app/src/main/res/drawable/ic_local_parking_black_24dp.xml +++ b/app/src/main/res/drawable/ic_local_parking_black_24dp.xml @@ -1,5 +1,5 @@ - - + diff --git a/app/src/main/res/drawable/ic_local_parking_orange_24dp.xml b/app/src/main/res/drawable/ic_local_parking_orange_24dp.xml new file mode 100644 index 00000000..393893fb --- /dev/null +++ b/app/src/main/res/drawable/ic_local_parking_orange_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_streetview_black_24dp.xml b/app/src/main/res/drawable/ic_streetview_black_24dp.xml new file mode 100644 index 00000000..775a9039 --- /dev/null +++ b/app/src/main/res/drawable/ic_streetview_black_24dp.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_swap_horiz_black_24dp.xml b/app/src/main/res/drawable/ic_swap_horiz_black_24dp.xml new file mode 100644 index 00000000..e357d4a9 --- /dev/null +++ b/app/src/main/res/drawable/ic_swap_horiz_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_parking.xml b/app/src/main/res/layout/fragment_parking.xml new file mode 100644 index 00000000..e1d0471e --- /dev/null +++ b/app/src/main/res/layout/fragment_parking.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_pre_sacador.xml b/app/src/main/res/layout/fragment_pre_sacador.xml new file mode 100644 index 00000000..cc58710f --- /dev/null +++ b/app/src/main/res/layout/fragment_pre_sacador.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_article_row.xml b/app/src/main/res/layout/item_article_row.xml index 38f14c8d..7861870c 100644 --- a/app/src/main/res/layout/item_article_row.xml +++ b/app/src/main/res/layout/item_article_row.xml @@ -70,13 +70,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> - + android:orientation="vertical" + style="@style/LayoutClickable">