diff --git a/app/build.gradle b/app/build.gradle index 79a50907..99372ed6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "es.verdnatura" minSdkVersion 21 targetSdkVersion 29 - versionCode 7 - versionName "5.0.7" + versionCode 9 + versionName "5.0.9" 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 9204a681..f823577e 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -4,6 +4,7 @@ import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesViewModel import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardViewModel import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemViewModel import es.verdnatura.presentation.view.feature.collection.fragment.CollectionViewModel +import es.verdnatura.presentation.view.feature.controlador.fragment.ControladorViewModel import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasViewModel import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoViewModel import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryViewModel @@ -100,4 +101,8 @@ val viewModelModule = module{ viewModel { CollectionViewModel() } + + viewModel { + ControladorViewModel() + } } \ 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 6aa08224..296370a2 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.107:8009/" + const val BASE_URL:String = "http://192.168.1.111:8008/" //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 79e6822a..9ae9c45d 100644 --- a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt +++ b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt @@ -1,8 +1,11 @@ package es.verdnatura.domain object ConstAndValues { - const val SACADOR = 14 - const val CONTROLADOR = 8 - const val OK = 3 + const val SACADOR = "PREPARED" + const val CONTROLADOR = "CHECKED" + const val OK = "OK" + const val PREPARED = "PREPARED" + const val ON_PREPARATION = "ON_PREPARATION" + const val CHECKED = "CHECKED" } diff --git a/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt index 4646f9e2..499be909 100644 --- a/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt +++ b/app/src/main/java/es/verdnatura/domain/GetSacadorControladorUserCase.kt @@ -7,10 +7,11 @@ import retrofit2.Call class GetSacadorControladorUserCase : RestClient() { - fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String) : Call { + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String,print:String) : Call { val params:ArrayList = ArrayList(); params.add(collectionFk) params.add(sectorFk) + params.add(print) return restClient!!.collectionTicketGet("json","1",usuario,password,"application/json",params) } @@ -67,4 +68,42 @@ class GetSacadorControladorUserCase : RestClient() { return restClient!!.collectionAddItem("json","1",usuario,password,"application/json",params) } + fun saleMove(usuario:String,password:String,saleFk: String,quantity: String,originalQuantity:String) : Call { + val params:ArrayList = ArrayList() + params.add(saleFk) + params.add(quantity) + params.add(originalQuantity) + return restClient!!.saleMove("json","1",usuario,password,"application/json",params) + } + + fun collectionMissingTrash(usuario:String,password:String,saleFk: String,quantity: String,type:String,warehouseFk:String,originalQuantity: String) : Call { + val params:ArrayList = ArrayList() + params.add(saleFk) + params.add(quantity) + params.add(type) + params.add(warehouseFk) + params.add(originalQuantity) + return restClient!!.collectionMissingTrash("json","1",usuario,password,"application/json",params) + } + + fun saleTrackingDel(usuario:String,password:String,saleFk: String) : Call { + val params:ArrayList = ArrayList() + params.add(saleFk) + return restClient!!.saleTrackingDel("json","1",usuario,password,"application/json",params) + } + + fun collectionUpdateState(usuario:String,password:String,collectionFk: String,state : String) : Call { + val params:ArrayList = ArrayList() + params.add(collectionFk) + params.add(state) + return restClient!!.collectionUpdateState("json","1",usuario,password,"application/json",params) + } + + fun getIdFromCode(usuario:String,password:String,code: String) : Call { + val params:ArrayList = ArrayList() + params.add(code) + return restClient!!.getIdFromCode("json","1",usuario,password,"application/json",params) + } + + } diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index edba7974..83d23330 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -126,6 +126,51 @@ interface VerdnaturaService { @Body params: List): Call + @POST("almacennew/saleMove") + fun saleMove(@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 + + @POST("almacennew/collectionMissingTrash") + fun collectionMissingTrash(@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 + + @POST("almacennew/saleTrackingDel") + fun saleTrackingDel(@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 + + @POST("almacennew/collectionUpdateState") + fun collectionUpdateState(@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 + + @POST("almacennew/barcodeToItem") + fun getIdFromCode(@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 + //PASILLEROS ========================================================================> //CONSULTAR ARTICULO ========================================================================> @@ -250,6 +295,8 @@ interface VerdnaturaService { @Body params: List): Call> + + //UBICADOR ========================================================================> @POST("almacennew/itemShelvingList") fun itemShelvingList(@Header("aplicacion") aplicacion: String, diff --git a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index 01761a56..f6ad5ef9 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -13,6 +13,7 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import es.verdnatura.presentation.view.feature.sacador.model.SaleVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO interface OnOptionsSelectedListener { @@ -81,5 +82,13 @@ interface OnScanLongClickListener { } interface OnCollectionSelectedListener { - fun onCollectionSelected(collection: CollectionVO,type:Int) + fun onCollectionSelected(collection: CollectionVO,type:String) +} + +interface OnQuantityClickListener { + fun onQuantityClick(sale: SaleVO) +} + +interface OnSaleClickListener { + fun onSaleClick(sale: SaleVO) } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogList.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogList.kt index b590aa13..158b2527 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogList.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogList.kt @@ -33,7 +33,7 @@ class CustomDialogList (context: Context) : Dialog(context, R.style.DialogTheme) fun setValue(value : String): CustomDialogList{ custom_dialog_value.setText(value) - custom_dialog_value.visibility = View.VISIBLE + textinputlayout_username.visibility = View.VISIBLE return this } @@ -43,7 +43,7 @@ class CustomDialogList (context: Context) : Dialog(context, R.style.DialogTheme) fun setValueTwo(value : String): CustomDialogList{ custom_dialog_value_two.setText(value) - custom_dialog_value_two.visibility = View.VISIBLE + textinputlayout_two.visibility = View.VISIBLE return this } @@ -78,4 +78,9 @@ class CustomDialogList (context: Context) : Dialog(context, R.style.DialogTheme) return this } + fun setTextTwoGone():CustomDialogList{ + textinputlayout_two.visibility = View.GONE + return this + } + } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogThreeButtons.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogThreeButtons.kt new file mode 100644 index 00000000..c51ebd38 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogThreeButtons.kt @@ -0,0 +1,73 @@ +package es.verdnatura.presentation.view.component + +import android.app.Dialog +import android.content.Context +import android.view.View +import es.verdnatura.R +import kotlinx.android.synthetic.main.component_custom_three_dialog.* +import kotlinx.android.synthetic.main.component_custom_two_dialog.* +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ko +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ok +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ok_two +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_description +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_title + +class CustomDialogThreeButtons (context: Context) : Dialog(context, R.style.DialogTheme) { + + init { + setContentView(R.layout.component_custom_three_dialog) + } + + + fun setTitle(title: String): CustomDialogThreeButtons { + custom_dialog_title.visibility = View.VISIBLE + custom_dialog_title.text = title + return this + } + + fun setDescription(description: String): CustomDialogThreeButtons { + custom_dialog_description.visibility = View.VISIBLE + custom_dialog_description.text = description + return this + } + + fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogThreeButtons { + custom_dialog_button_ok.visibility = View.VISIBLE + custom_dialog_button_ok.text = text + custom_dialog_button_ok.setOnClickListener { onButtonClicked() } + return this + } + + + fun getValue() : String { + return custom_dialog_value.text.toString() + } + + fun setValue(value : String): CustomDialogThreeButtons{ + custom_dialog_value.setText(value) + textinputlayout.visibility = View.VISIBLE + return this + } + + fun setOkButtonTwo(text: String, onButtonClicked: () -> Unit): CustomDialogThreeButtons { + custom_dialog_button_ok_two.visibility = View.VISIBLE + custom_dialog_button_ok_two.text = text + custom_dialog_button_ok_two.setOnClickListener { onButtonClicked() } + return this + } + + fun setOkButtonThree(text: String, onButtonClicked: () -> Unit): CustomDialogThreeButtons { + custom_dialog_button_ok_three.visibility = View.VISIBLE + custom_dialog_button_ok_three.text = text + custom_dialog_button_ok_three.setOnClickListener { onButtonClicked() } + return this + } + + fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogThreeButtons { + custom_dialog_button_ko.visibility = View.VISIBLE + custom_dialog_button_ko.text = text + custom_dialog_button_ko.setOnClickListener { onButtonClicked() } + return this + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogTwoButtons.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogTwoButtons.kt index d308aa3a..f2b1bc13 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogTwoButtons.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogTwoButtons.kt @@ -4,7 +4,11 @@ import android.app.Dialog import android.content.Context import android.view.View import es.verdnatura.R -import kotlinx.android.synthetic.main.component_custom_two_dialog.* +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ko +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ok +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_button_ok_two +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_description +import kotlinx.android.synthetic.main.component_custom_two_dialog.custom_dialog_title class CustomDialogTwoButtons (context: Context) : Dialog(context, R.style.DialogTheme) { 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 ccd636f0..f1ead86d 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 @@ -5,10 +5,13 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import es.verdnatura.databinding.ItemPlacementRowBinding +import es.verdnatura.presentation.common.OnPasillerosItemClickListener +import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO class PlacementAdapter ( - private val items: List + private val items: List, + private val onPasillerosItemClickListener: OnPasillerosItemClickListener ): RecyclerView.Adapter () { var context: Context? = null override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder { @@ -30,6 +33,9 @@ class PlacementAdapter ( fun bind(placement: PlacementVO) { binding.apply { 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/adapter/SaleAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapter.kt index b4a6d889..a9e944ad 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapter.kt @@ -2,6 +2,7 @@ package es.verdnatura.presentation.view.feature.collection.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 @@ -9,14 +10,19 @@ 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.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.sacador.model.SaleVO class SaleAdapter ( private val items: List, - private val onPasillerosItemClickListener: OnPasillerosItemClickListener + private val onPasillerosItemClickListener: OnPasillerosItemClickListener, + private val onQuantityClick: OnQuantityClickListener, + 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( @@ -27,6 +33,7 @@ class SaleAdapter ( override fun getItemCount() =items.size override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) { + this.position = position holder.bind(items[position]) } @@ -37,12 +44,17 @@ class SaleAdapter ( binding.apply { if (sale.startQuantity.isNullOrEmpty()) sale.startQuantity = "0" - this.sale = sale val childLayoutManager = LinearLayoutManager(context!!, RecyclerView.HORIZONTAL, false) + itemArticlePlacements.apply { layoutManager = childLayoutManager - adapter = PlacementAdapter(sale.placements) + adapter = PlacementAdapter(sale.placements,onPasillerosItemClickListener) + } + + //CLICK EVENTS + contentLayout.setOnClickListener { + onSaleClickListener.onSaleClick(sale) } itemArticleItemFk.setOnClickListener { @@ -50,6 +62,38 @@ class SaleAdapter ( } + itemArticleQuantity.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + itemArticleQuantityPicked.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + txtde.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + } + + //ERROR + if (sale.originalQuantity != sale.quantity){ + layoutError.visibility = View.VISIBLE + txtError.text = "Cantidad original: "+sale.quantity + if (sale.isPrepared == "1" || sale.isControlled == "1") + sale.startQuantity = sale.originalQuantity + } + + if (sale.isNew){ + layoutError.visibility = View.VISIBLE + txtError.text = "Artículo nuevo" + + } + + if (!sale.isNew && sale.originalQuantity == sale.quantity){ + layoutError.visibility = View.GONE + } + + + //SEMAFORO if (sale.isPreviousPrepared == "1"){ itemArticleRowSemaforoPre.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_dark_sky_blue)) }else{ @@ -78,6 +122,10 @@ class SaleAdapter ( contentLayout.setBackgroundColor(ContextCompat.getColor(context!!, R.color.verdnatura_black)) } + + //ASIGNAMOS VALOR A LA VSITA + this.sale = sale + } } } 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 49140653..92880619 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 @@ -10,20 +10,22 @@ import android.view.inputmethod.EditorInfo 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.FragmentCollectionBinding +import es.verdnatura.domain.ConstAndValues.CHECKED import es.verdnatura.domain.ConstAndValues.CONTROLADOR import es.verdnatura.domain.ConstAndValues.OK +import es.verdnatura.domain.ConstAndValues.ON_PREPARATION +import es.verdnatura.domain.ConstAndValues.PREPARED import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.OnBarcodeRowClickListener -import es.verdnatura.presentation.common.OnOptionsSelectedListener -import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.addViewObserver +import es.verdnatura.presentation.common.* import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialogInput import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.component.CustomDialogThreeButtons import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO import es.verdnatura.presentation.view.feature.collection.ItemVO @@ -40,7 +42,7 @@ import kotlinx.android.synthetic.main.toolbar.* class CollectionFragment( var collection : CollectionVO = CollectionVO(), - var type:Int = SACADOR + var type:String = SACADOR ) : BaseFragment(CollectionViewModel::class){ private var user = "" private var password = "" @@ -56,14 +58,19 @@ class CollectionFragment( private var listPlacementSupply:ArrayList = ArrayList() private var storedShelvingPosition:Int = 0 private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialogThreeButtons: CustomDialogThreeButtons private var ticketSelected:String = "" private lateinit var customDialog: CustomDialog private var goBack:Boolean = false + private var goBack2:Boolean = false var mperror: MediaPlayer? = null var mpok: MediaPlayer? = null + private var itemShelvingFkStored : String = "" + private var storedBackPosition : Int = 0 + companion object { - fun newInstance(collection:CollectionVO,type:Int) = CollectionFragment(collection,type) + fun newInstance(collection:CollectionVO,type:String) = CollectionFragment(collection,type) } override fun onAttach(context: Context) { @@ -83,8 +90,6 @@ class CollectionFragment( mpok = MediaPlayer.create((activity as MainActivity),R.raw.ok) if (collection.tickets.isEmpty()){ viewModel.collectionTicketGet(user,password,collection.collectionFk,sectorFk) - }else{ - createCollectionList() } super.onCreate(savedInstanceState) @@ -94,20 +99,27 @@ class CollectionFragment( customDialogList = CustomDialogList(requireContext()) customDialogInput = CustomDialogInput(requireContext()) customDialog = CustomDialog(requireContext()) + customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) activity!!.main_bottom_navigation.visibility = View.GONE splash_progress.visibility = View.VISIBLE toolbar_title.text = "collectionTicket_get" setToolBar() setEvents() + if (collection.tickets.isNotEmpty()){ + createCollectionList() + } super.init() } override fun onPause() { goBack = true + goBack2 = true super.onPause() } 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 iconSearch : Drawable = resources.getDrawable(R.drawable.ic_visibility,resources.newTheme()) @@ -131,6 +143,11 @@ class CollectionFragment( toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) } + private fun scanRequest(){ + scan_input.requestFocus() + (activity as MainActivity).hideKeyboard(scan_input) + } + private fun setEvents(){ backButton.setOnClickListener { activity!!.onBackPressed() @@ -159,22 +176,22 @@ class CollectionFragment( override fun observeViewModel() { with(viewModel){ + scanRequest() collectionTicketList.observe(viewLifecycleOwner, Observer { splash_progress.visibility = View.GONE - if(it.tickets.isEmpty()){ - if (R.id.collection_empty_text == collection_switcher.nextView.id){ - collection_switcher.showNext() - } - }else{ + if(it.tickets.isNotEmpty()){ collection = it createCollectionList() + }else{ + toolbar_subtitle.text = "0/0" } }) placementSuppleyList.observe(viewLifecycleOwner, Observer { splash_progress.visibility = View.GONE - printShelvingResult(it) + if (!goBack) printShelvingResult(it) + goBack = false }) item.observe(viewLifecycleOwner, Observer { @@ -188,6 +205,7 @@ class CollectionFragment( if (!goBack){ if (it.isError){ customDialog.setTitle("Disponibilidad").setDescription(it.errorMessage).setKoButton("Cerrar"){ + scanRequest() customDialog.hide() }.show() }else{ @@ -198,7 +216,30 @@ class CollectionFragment( 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.hide() + }.show() + }else{ + if (checkItemScan(it.response)){ + scanRequest() + customDialogList.hide() + mpok?.start() + onQuantityOfShelvingSelected(itemShelvingFkStored) + }else{ + customDialogList.setValueTwo("") + mperror?.start() + } + } + } + + goBack2 = false }) @@ -217,13 +258,46 @@ class CollectionFragment( } sales = salesList.sortedWith(compareBy({ it.saleOrder })) - saleAdapter = SaleAdapter(sales,pasillerosItemClickListener!!) + saleAdapter = SaleAdapter(sales,pasillerosItemClickListener!!,object: OnQuantityClickListener{ + override fun onQuantityClick(sale: SaleVO) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.saleFk == sale.saleFk){ + showQuantityDialog(index) + } + } + + } + + },object : OnSaleClickListener{ + override fun onSaleClick(sale: SaleVO) { + sales.forEachIndexed { index, saleVO -> + if (saleVO.saleFk == sale.saleFk){ + if (type == CONTROLADOR) markLine(index,type) + else if (type == SACADOR) unMarkLine(index, OK) + } + } + } + + }) lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) 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) + } + }) } //SEARCH AND MARK @@ -273,12 +347,16 @@ class CollectionFragment( if(saleVO.isControlled == "0"){ //1- Por itemFk if (txtscan == saleVO.itemFk){ + mpok!!.start() + isOk = true markLine(index,type) break } //2- Por barcode saleVO.Barcodes.forEach { barcode -> if (txtscan == barcode){ + mpok!!.start() + isOk = true markLine(index,type) isBreak = true } @@ -287,17 +365,31 @@ class CollectionFragment( } index += 1 } + //Lo escaneado no encontrado miramos si es parking o ticket + if (!isOk){ + if (txtscan.contains("-")){ + viewModel.parking( + usuario = user, + password = password, + ticketFk = collection.collectionFk, + parking = txtscan + ) + mpok!!.start() + "Ticket aparcado".toast(requireContext()) + }else{ + splash_progress.visibility = View.VISIBLE + viewModel.collectionTicketGet(user,password,txtscan,sectorFk) + } + } } } - private fun markLine(position:Int,newType: Int){ + private fun markLine(position:Int,newType: String){ if (type == SACADOR){ sales[position].isPrepared = if (sales[position].isPrepared == "1") "0" else "1" if (sales[position].isPrepared == "1"){ - sales[position].startQuantity = sales[position].quantity - }else{ - sales[position].startQuantity = if(sales[position].startQuantity == sales[position].quantity) "0" else sales[position].startQuantity + sales[position].startQuantity = sales[position].originalQuantity } }else if (type == CONTROLADOR) sales[position].isControlled = if (sales[position].isControlled == "1") "0" else "1" @@ -311,36 +403,52 @@ class CollectionFragment( private fun setListPosition(position:Int){ storedPosition = position - fragment_sacador_collections.addViewObserver { - lm!!.scrollToPositionWithOffset(position,0) + if (type == SACADOR){ + fragment_sacador_collections.addViewObserver { + lm!!.scrollToPositionWithOffset(position,0) + } } + } - private fun saleTrackingReplace(position: Int,type: Int){ + private fun saleTrackingReplace(position: Int,type: String){ viewModel.saleTrackingReplace( usuario = user, password = password, saleFk = sales[position].saleFk, - vIsChecked = if (type == SACADOR) sales[position].isPrepared else sales[position].isControlled, + vIsChecked = if (type == SACADOR) sales[position].isPrepared else if(type == CONTROLADOR) sales[position].isControlled else "1", vOriginalQuantity = sales[position].startQuantity, vStateFk = type.toString() ) } - private fun setTotalLines(){ - var totalMark = 0 - sales.forEach { - if (type == SACADOR) - if (it.isPrepared == "1" || it.isControlled == "1" || it.isPreviousPrepared == "1") - totalMark += 1 - else if (type == CONTROLADOR) - if (it.isControlled == "1") - totalMark += 1 + private fun unMarkLine(position: Int,newType: String){ + + if (sales[position].isPrepared == "1"){ + customDialog.setTitle("Desmarcar linea").setDescription("Vas a desmarcar la linea: "+sales[position].itemFk+ " ¿Estás seguro?").setOkButton("Desmarcar"){ + sales[position].isPrepared = "0" + sales[position].startQuantity = "0" + saleAdapter!!.notifyDataSetChanged() + setListPosition(position) + viewModel.saleTrackingDel( + usuario = user, + password = password, + saleFk = sales[position].saleFk + ) + setTotalLines() + scanRequest() + customDialog.hide() + }.setKoButton("Cancelar"){ + scanRequest() + customDialog.hide() + }.show() } - toolbar_title.text = "" + totalMark + "/" + sales.size - if (totalMark == sales.size) "Colección completa".toast(this.context,Toast.LENGTH_SHORT) + + + } + //SHELVINGS private fun showShelving(position:Int,shelvingPosition:Int){ storedShelvingPosition = shelvingPosition @@ -348,7 +456,7 @@ class CollectionFragment( splash_progress.visibility = View.VISIBLE var quantityGet = "0" try{ - quantityGet = (sales[position].quantity.toInt() - sales[position].startQuantity.toInt()).toString() + quantityGet = (sales[position].originalQuantity.toInt() - sales[position].startQuantity.toInt()).toString() }catch (e:Exception){} viewModel.itemPlacementSupplyAiming( usuario = user, @@ -378,27 +486,65 @@ class CollectionFragment( listPlacementSupply.add(BarcodeVO(code = it.proposal)) } - customDialogList.setTitle(""+shelving+ "("+item+")"+" "+total+" de "+longName).setOkButton("Coger"){ - onQuantityOfShelvingSelected(itemShelvingFk) - customDialogList.hide() + customDialogList.setTitle("$shelving($item) $total de $longName").setOkButton("Coger"){ + if (customDialogList.getValueTwo().isNotEmpty()){ + if (checkItemScan(customDialogList.getValueTwo())){ + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + scanRequest() + customDialogList.hide() + }else{ + itemShelvingFkStored = itemShelvingFk + splash_progress.visibility = View.VISIBLE + viewModel.getIdFromCode( + usuario = user, + password = password, + code = customDialogList.getValueTwo() + ) + } + + + }else{ + "Escanea item para validar".toast(requireContext()) + } + }.setKoButton("Cerrar"){ + scanRequest() customDialogList.hide() - }.setHintValue("Cantidad que coges:").setValue(total).show() + }.setHintValue("Cantidad que coges:").setValue(total).setHintValueTwo("Escanea item").setValueTwo("").show() - customDialogList.getEditText().requestFocus() - (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) - customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + customDialogList.getEditTextTwo().requestFocus() + (activity as MainActivity).hideKeyboard(customDialogList.getEditTextTwo()) + + customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - if (!customDialogList.getValue().isNullOrEmpty()){ - onQuantityOfShelvingSelected(itemShelvingFk) + if (customDialogList.getValueTwo().isNotEmpty()){ + if (checkItemScan(customDialogList.getValueTwo())){ + onQuantityOfShelvingSelected(itemShelvingFk) + mpok?.start() + scanRequest() + customDialogList.hide() + }else{ + itemShelvingFkStored = itemShelvingFk + splash_progress.visibility = View.VISIBLE + viewModel.getIdFromCode( + usuario = user, + password = password, + code = customDialogList.getValueTwo() + ) + } + + + + }else{ + "Escanea item para validar".toast(requireContext()) } - customDialogList.setValue("") - (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) + (activity as MainActivity).hideKeyboard(customDialogList.getEditTextTwo()) return@setOnEditorActionListener true - customDialogList.hide() + } false } @@ -421,10 +567,24 @@ class CollectionFragment( } + private fun checkItemScan(valueToCheck:String):Boolean{ + val saleToCheck = sales[storedPosition] + if (saleToCheck.itemFk == valueToCheck) + return true + else{ + saleToCheck.Barcodes.forEach { barcode -> + if (barcode == valueToCheck) + return true + } + } + return false + } + private fun onQuantityOfShelvingSelected(itemShelvingFk:String){ //1 - MODIFICAR CANTIDAD DEL CARRO try { val shelvingVisible = sales[storedPosition].placements[storedShelvingPosition].visible.substring(1,sales[storedPosition].placements[storedShelvingPosition].visible.indexOf(")")) + sales[storedPosition].placements[storedShelvingPosition].visible = "("+(shelvingVisible.toInt() - customDialogList.getValue().toInt()).toString()+")" @@ -444,7 +604,7 @@ class CollectionFragment( }catch (e:Exception){} //3- MARCAR LINEA - if (sales[storedPosition].startQuantity != sales[storedPosition].quantity){ + if (sales[storedPosition].startQuantity != sales[storedPosition].originalQuantity){ sales[storedPosition].isPrepared = "1" markLine(storedPosition, OK) }else{ @@ -489,11 +649,13 @@ class CollectionFragment( quantityFk = customDialogList.getValueTwo(), warehouseFk = warehouseFk ) + scanRequest() customDialogList.hide() } }.setKoButton("Cerrar"){ + scanRequest() customDialogList.hide() }.setHintValue("Artículo:").setValue("").setHintValueTwo("Cantidad:").setValueTwo("").show() @@ -528,11 +690,13 @@ class CollectionFragment( quantityFk = customDialogList.getValueTwo(), warehouseFk = warehouseFk ) + scanRequest() customDialogList.hide() } } (activity as MainActivity).hideKeyboard(customDialogList.getEditTextTwo()) return@setOnEditorActionListener true + scanRequest() customDialogList.hide() } false @@ -564,11 +728,13 @@ class CollectionFragment( itemFk = customDialogInput.getValue(), warehouseFk = warehouseFk ) + scanRequest() customDialogInput.hide() }.setKoButton("Cancelar"){ splash_progress.visibility = View.GONE (activity as MainActivity).hideKeyboard(customDialogInput.getEditText()) + scanRequest() customDialogInput.hide() }.setValue("").show() customDialogInput.getEditText().requestFocus() @@ -584,6 +750,7 @@ class CollectionFragment( ) } customDialogInput.setValue("") + scanRequest() customDialogInput.hide() (activity as MainActivity).hideKeyboard(customDialogInput.getEditText()) return@setOnEditorActionListener true @@ -598,10 +765,160 @@ class CollectionFragment( } customDialog.setTitle("Artículo: "+item.id).setDescription("Disponible: "+item.available).setOkButton("Aceptar"){ + scanRequest() customDialog.hide() }.show() } + + private fun setTotalLines(){ + var totalMark = 0 + sales.forEach { + if (type == SACADOR){ + if (it.isPrepared == "1" || it.isControlled == "1" || it.isPreviousPrepared == "1") + totalMark += 1 + }else if (type == CONTROLADOR){ + if (it.isControlled == "1") + totalMark += 1 + } + } + //toolbar_title.text = "" + totalMark + "/" + sales.size + toolbar_title.text = collection.collectionFk + toolbar_subtitle.text = "" +totalMark + "/" + sales.size + if (totalMark == sales.size) { + "Colección completa".toast(this.context,Toast.LENGTH_SHORT) + changeTicketState() + }else if(totalMark == 0){ + setPreparedTicket() + } + } + + //FALTAS / BASURA / SPLIT + private fun showQuantityDialog(position:Int) { + customDialogThreeButtons.setTitle("Nueva cantidad").setDescription("Indica la nueva cantidad y la acción que quieres realizar con el resto.").setValue("") + .setOkButton("Faltas"){ + if (customDialogThreeButtons.getValue().trim().isNullOrEmpty()){ + "Indica nueva cantidad".toast(requireContext()) + }else{ + trash(position,customDialogThreeButtons.getValue()) + scanRequest() + customDialogThreeButtons.hide() + } + }.setOkButtonTwo("Basura"){ + if (customDialogThreeButtons.getValue().trim().isNullOrEmpty()){ + "Indica nueva cantidad".toast(requireContext()) + }else{ + missing(position,customDialogThreeButtons.getValue()) + scanRequest() + customDialogThreeButtons.hide() + } + }.setOkButtonThree("Split"){ + if (customDialogThreeButtons.getValue().trim().isNullOrEmpty()){ + "Indica nueva cantidad".toast(requireContext()) + }else{ + split(position,customDialogThreeButtons.getValue()) + scanRequest() + customDialogThreeButtons.hide() + } + + }.setKoButton("Cancelar"){ + scanRequest() + customDialogThreeButtons.hide() + }.show() + } + + private fun split(position: Int,quantity:String){ + var totalQuantity: Int = 0 + try { + totalQuantity = sales[position].originalQuantity.toInt() - quantity.toInt() + }catch (e:Exception){} + viewModel.saleMove( + usuario = user, + password = password, + saleFk = sales[position].saleFk, + quantity = totalQuantity.toString(), + originalQuantity = quantity + ) + sales[position].originalQuantity = quantity + sales[position].quantity = quantity + //sales[position].startQuantity = quantity + + if (quantity == "0") + markLine(position,type) + saleAdapter!!.notifyDataSetChanged() + + + } + + private fun trash(position: Int,quantity:String){ + var totalQuantity: Int = 0 + try { + totalQuantity = sales[position].originalQuantity.toInt() - quantity.toInt() + }catch (e:Exception){} + viewModel.collectionMissingTrash( + usuario = user, + password = password, + saleFk = sales[position].saleFk, + quantity = totalQuantity.toString(), + warehouseFk = warehouseFk, + type = "FALSE", + originalQuantity = quantity + ) + sales[position].originalQuantity = quantity + sales[position].quantity = quantity + //sales[position].startQuantity = quantity + saleAdapter!!.notifyDataSetChanged() + if (quantity == "0") + markLine(position,type) + } + + private fun missing(position: Int,quantity:String){ + var totalQuantity: Int = 0 + try { + totalQuantity = sales[position].originalQuantity.toInt() - quantity.toInt() + }catch (e:Exception){} + viewModel.collectionMissingTrash( + usuario = user, + password = password, + saleFk = sales[position].saleFk, + quantity = totalQuantity.toString(), + warehouseFk = warehouseFk, + type = "TRUE", + originalQuantity = quantity + ) + sales[position].originalQuantity = quantity + sales[position].quantity = quantity + //sales[position].startQuantity = quantity + + if (quantity == "0") + markLine(position,type) + saleAdapter!!.notifyDataSetChanged() + } + + //ESTADOS + + private fun changeTicketState(){ + if (type == CONTROLADOR){ + viewModel.collectionUpdateState( + usuario = user, + password = password, + collectionFk = collection.collectionFk, + state = CHECKED + ) + } + } + + private fun setPreparedTicket(){ + if (type == CONTROLADOR){ + viewModel.collectionUpdateState( + usuario = user, + password = password, + collectionFk = collection.collectionFk, + state = PREPARED + ) + } + } + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt index dfac0f66..b75cad24 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt @@ -3,6 +3,8 @@ package es.verdnatura.presentation.view.feature.collection.fragment import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import es.verdnatura.domain.GetSacadorControladorUserCase +import es.verdnatura.domain.GetShelvingParkingUserCase +import es.verdnatura.domain.GetUbicadorUserCase import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.view.feature.collection.ItemVO @@ -19,6 +21,7 @@ class CollectionViewModel : BaseViewModel() { val emptyMessage = "La colección no tiene tickets"; private val getSacadorControladorUserCase: GetSacadorControladorUserCase = GetSacadorControladorUserCase() + private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() private val _collectionTicketList by lazy { MutableLiveData() } val collectionTicketList: LiveData @@ -36,6 +39,11 @@ class CollectionViewModel : BaseViewModel() { val responseNew: LiveData get() = _responseNew + private val _responseCode by lazy { MutableLiveData() } + val responseCode: LiveData + get() = _responseCode + + private val _item by lazy { MutableLiveData() } val item: LiveData @@ -43,7 +51,7 @@ class CollectionViewModel : BaseViewModel() { fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String){ - getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk).enqueue(object : + getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk,"0").enqueue(object : Callback { override fun onFailure(call: Call, t: Throwable) { _collectionTicketList.value = CollectionVO(isError = true,errorMessage = t.message!!) @@ -156,11 +164,108 @@ class CollectionViewModel : BaseViewModel() { override fun onResponse(call: Call, response: Response) { if (response.body() == null){ - _responseNew.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada collectionStickerPrint") + _responseNew.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada collectionAddItem") }else{ _responseNew.value = ResponseItemVO(isError = false,response = response.body()!!) } } }) } + + fun saleMove(usuario:String,password:String,saleFk: String,quantity: String,originalQuantity : String){ + getSacadorControladorUserCase.saleMove(usuario,password,saleFk,quantity,originalQuantity).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 saleMove") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + } + }) + } + + fun collectionMissingTrash(usuario:String,password:String,saleFk: String,quantity: String,type:String,warehouseFk:String,originalQuantity: String){ + getSacadorControladorUserCase.collectionMissingTrash(usuario,password,saleFk,quantity,type,warehouseFk,originalQuantity).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()!!) + } + } + }) + } + + + 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()!!) + } + } + }) + } + + 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 collectionUpdateState(usuario:String,password:String,collectionFk: String,state : String){ + getSacadorControladorUserCase.collectionUpdateState(usuario,password,collectionFk,state).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 collectionUpdateState") + }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()!!) + } + } + }) + } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/mapper/CollectionMapper.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/mapper/CollectionMapper.kt index 49553715..46992d1f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/mapper/CollectionMapper.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/mapper/CollectionMapper.kt @@ -13,17 +13,25 @@ fun CollectionVO.map() : CollectionVO{ it.level = ticket.level it.agencyName = ticket.agencyName it.quantity = it.quantity.substring(0,it.quantity.indexOf(".")) - if (it.placements.isNotEmpty()){ - try{ - it.saleOrder = it.placements[0].saleOrder.toInt() - }catch (e:NumberFormatException){ - it.saleOrder = 9999 + it.isNew = it.isAdded == "1" + it.originalQuantity = if (it.originalQuantity != "-1") it.originalQuantity.substring(0,it.originalQuantity.indexOf(".")) else it.quantity + it.startQuantity = if (it.isPrepared == "1" || it.isPreviousPrepared == "1" || it.isControlled == "1") it.quantity else it.startQuantity + if (!it.placements.isNullOrEmpty()){ + it.placements.forEachIndexed { index, placement -> + if (index == 0){ + try{ + it.saleOrder = placement.saleOrder.toInt() + }catch (e:NumberFormatException){ + it.saleOrder = 9999 + } + } + placement.created = getCalendarFromDate(placement.created).convertToDateString() + placement.visible = "("+placement.visible+")" } + }else{ + it.placements = listOf() } - it.placements.forEach { placement -> - placement.created = getCalendarFromDate(placement.created).convertToDateString() - placement.visible = "("+placement.visible+")" - } + } } return this diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt new file mode 100644 index 00000000..e305b8c9 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt @@ -0,0 +1,103 @@ +package es.verdnatura.presentation.view.feature.controlador.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.os.Bundle +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import es.verdnatura.R +import es.verdnatura.databinding.FragmentControladorBinding +import es.verdnatura.domain.ConstAndValues +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnCollectionSelectedListener +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import kotlinx.android.synthetic.main.fragment_controlador.* +import kotlinx.android.synthetic.main.toolbar.* + +class ControladorFragment : BaseFragment(ControladorViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var goBack:Boolean = false + private var onCollectionSelectedListener : OnCollectionSelectedListener? = null + override fun getLayoutId(): Int = R.layout.fragment_controlador + private lateinit var customDialog: CustomDialog + + companion object { + fun newInstance() = ControladorFragment() + } + + override fun onAttach(context: Context) { + super.onAttach(context) + if (context is OnCollectionSelectedListener) onCollectionSelectedListener = context + } + + override fun init() { + splash_progress.visibility = View.GONE + customDialog = CustomDialog(requireContext()) + toolbar_title.text = "collection_get" + setEvents() + super.init() + } + + override fun onPause() { + goBack = true + super.onPause() + } + + 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() + super.onCreate(savedInstanceState) + } + + 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()) { + splash_progress.visibility = View.VISIBLE + viewModel.collectionTicketGet( + usuario = user, + password = password, + sectorFk = sectorFk, + collectionFk = scan_input.text.toString() + ) + } + scan_input.setText("") + (activity as MainActivity).hideKeyboard(scan_input) + return@setOnEditorActionListener true + } + false + } + } + + override fun observeViewModel() { + with(viewModel){ + collectionTicketList.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if (it.isError){ + customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Aceptar"){ + customDialog.hide() + }.show() + }else{ + if (!goBack)navigateToCollectionList(it) + goBack = false + } + + }) + } + } + + private fun navigateToCollectionList(collection: CollectionVO){ + onCollectionSelectedListener?.onCollectionSelected(collection, ConstAndValues.CONTROLADOR) + } +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorViewModel.kt new file mode 100644 index 00000000..3e298aba --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorViewModel.kt @@ -0,0 +1,39 @@ +package es.verdnatura.presentation.view.feature.controlador.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetSacadorControladorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.view.feature.collection.mapper.map +import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class ControladorViewModel : BaseViewModel() { + + private val _collectionTicketList by lazy { MutableLiveData() } + private val getSacadorControladorUserCase: GetSacadorControladorUserCase = GetSacadorControladorUserCase() + + val collectionTicketList: LiveData + get() = _collectionTicketList + + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String){ + getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk,"0").enqueue(object : + Callback { + override fun onFailure(call: Call, t: Throwable) { + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = t.message!!) + } + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null){ + _collectionTicketList.value = response.body()?.let { it.map() } + }else{ + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = "No hay tickets para sacar") + } + } + }) + } +} 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 ed67aa17..c56800c6 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 @@ -16,6 +16,7 @@ import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesFragment import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardFragment import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragment +import es.verdnatura.presentation.view.feature.controlador.fragment.ControladorFragment import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasFragment import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoFragment import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryFragment @@ -134,7 +135,8 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick true } "Controladores" -> { - "Función Controladores desactivada".toast(this@MainActivity) + fm.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE) + addFragment(ControladorFragment.newInstance(),R.id.main_frame_layout, ControladorFragment.TAG,false) true } "Paletizadores" -> { @@ -229,7 +231,7 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick addFragmentOnTop(ExpeditionPalletDetailFragment.newInstance(itemTruck,itemPallet)) } - override fun onCollectionSelected(collection: CollectionVO,type:Int) { + override fun onCollectionSelected(collection: CollectionVO,type:String) { addFragmentOnTop(CollectionFragment.newInstance(collection,type)) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt index 7c5c8fcf..36da22a9 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragment.kt @@ -13,6 +13,7 @@ import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnCollectionSelectedListener import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter import es.verdnatura.presentation.view.feature.sacador.adapter.CollectionAdapter import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO @@ -29,6 +30,11 @@ class SacadorFragment : BaseFragment(Sa private var sectorFk = "" private var warehouseFk = "" private var onCollectionSelectedListener : OnCollectionSelectedListener? = null + private var goBack:Boolean = false + private var goBack2:Boolean = false + private lateinit var customDialog: CustomDialog + private var collectionsList:ArrayList = ArrayList() + private var adapter: CollectionAdapter? = null companion object { @@ -47,75 +53,89 @@ class SacadorFragment : BaseFragment(Sa password = prefs.getString(PASSWORD,"").toString() sectorFk = prefs.getInt(SECTORFK,1).toString() warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() - viewModel.collectionGet(user,password) + super.onCreate(savedInstanceState) } override fun init() { + customDialog = CustomDialog(requireContext()) splash_progress.visibility = View.VISIBLE toolbar_title.text = "collection_get" setToolBar() setEvents() + viewModel.collectionGet(user,password) super.init() } + override fun onPause() { + goBack = true + goBack2 = true + super.onPause() + } + private fun setToolBar(){ backButton.visibility = View.GONE val listIcons:ArrayList = ArrayList() - val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) val iconAdd : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) - listIcons.add(iconReload) listIcons.add(iconAdd) toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { override fun onOptionsItemSelected(item: Drawable) { - if (item == iconReload){ + if(item == iconAdd){ splash_progress.visibility = View.VISIBLE - viewModel.collectionGet(user,password) - }else if(item == iconAdd){ - splash_progress.visibility = View.VISIBLE - viewModel.collectionTicketGet(user,password,"",sectorFk) + viewModel.collectionTicketGet(user,password,"",sectorFk,"1") } } - }) toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) } private fun setEvents(){ - + sacador_swipe.setOnRefreshListener { + splash_progress.visibility = View.VISIBLE + viewModel.collectionGet(user,password) + sacador_swipe.isRefreshing = false + } } override fun observeViewModel() { with(viewModel){ collectionList.observe(viewLifecycleOwner, Observer { - splash_progress.visibility = View.GONE - if(it.list.isEmpty()){ - if (R.id.sacador_empty_text == sacador_switcher.nextView.id){ - sacador_switcher.showNext() - } - }else { - createCollectionList(it.list) - } - + if (!goBack2)splash_progress.visibility = View.GONE + createCollectionList(it.list) + goBack2 = false }) collectionTicketList.observe(viewLifecycleOwner, Observer { - navigateToCollectionList(it) + splash_progress.visibility = View.GONE + if (it.isError){ + customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Aceptar"){ + customDialog.hide() + }.show() + }else{ + if (!goBack)navigateToCollectionList(it) + + } + goBack = false }) } } private fun createCollectionList(collections:List){ - + collectionsList = ArrayList() + collections.forEach { + collectionsList.add(it) + } val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) - val adapter = CollectionAdapter(collections,onCollectionSelectedListener!!) + adapter = CollectionAdapter(collectionsList,onCollectionSelectedListener!!) fragment_sacador_collections.layoutManager = lm fragment_sacador_collections.adapter = adapter + } - private fun navigateToCollectionList(collection:CollectionVO){ - viewModel.collectionGet(user,password) - + collectionsList.add(collection) + adapter?.notifyDataSetChanged() + onCollectionSelectedListener?.onCollectionSelected(collection, SACADOR) + //viewModel.collectionGet(user,password) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt index 0ce71572..8cc2328b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import es.verdnatura.domain.GetSacadorControladorUserCase import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.view.feature.collection.mapper.map import es.verdnatura.presentation.view.feature.sacador.mapper.toDateFormat import es.verdnatura.presentation.view.feature.sacador.model.CollectionListVO import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO @@ -27,8 +28,8 @@ class SacadorViewModel : BaseViewModel() { get() = _collectionTicketList - fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String){ - getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk).enqueue(object : + fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String,print:String){ + getSacadorControladorUserCase.collectionTicketGet(usuario,password,collectionFk,sectorFk,print).enqueue(object : Callback { override fun onFailure(call: Call, t: Throwable) { _collectionTicketList.value = CollectionVO(isError = true,errorMessage = t.message!!) @@ -38,9 +39,9 @@ class SacadorViewModel : BaseViewModel() { response: Response ) { if (response.body() != null){ - _collectionTicketList.value = response.body()?.let { it } + _collectionTicketList.value = response.body()?.let { it.map() } }else{ - _collectionTicketList.value = CollectionVO(isError = true,errorMessage = "Error en la llamada de collection_get") + _collectionTicketList.value = CollectionVO(isError = true,errorMessage = "No hay tickets para sacar") } } }) 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 f4d0b7f2..ad1955d8 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 @@ -48,7 +48,8 @@ class SaleVO( var startQuantity : String = "", var workerFk : String = "", var placements : List = listOf(), - var Barcodes : List = listOf() + var Barcodes : List = listOf(), + var isNew : Boolean = false ) class PlacementVO( diff --git a/app/src/main/res/layout/component_custom_list_dialog.xml b/app/src/main/res/layout/component_custom_list_dialog.xml index 628ccb99..f4d7a19b 100644 --- a/app/src/main/res/layout/component_custom_list_dialog.xml +++ b/app/src/main/res/layout/component_custom_list_dialog.xml @@ -44,7 +44,6 @@ style="@style/InputLineTextSearch" android:layout_width="match_parent" android:backgroundTint="@android:color/white" - android:hint="Nuevo valor" android:inputType="text" android:lines="1" android:maxLines="1" @@ -66,7 +65,6 @@ style="@style/InputLineTextSearch" android:layout_width="match_parent" android:backgroundTint="@android:color/white" - android:hint="Cantidad" android:inputType="number" android:lines="1" android:maxLines="1" diff --git a/app/src/main/res/layout/component_custom_three_dialog.xml b/app/src/main/res/layout/component_custom_three_dialog.xml new file mode 100644 index 00000000..41916832 --- /dev/null +++ b/app/src/main/res/layout/component_custom_three_dialog.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + +