From fceab8c1820528d95343b246d897a96b4416a4a6 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:24:42 +0200 Subject: [PATCH 01/27] feat: boxPickingPrepared refs #7855 --- .../feature/boxPicking/BoxPickingFragment.kt | 120 +++++++++++------- .../feature/boxPicking/BoxPickingViewModel.kt | 46 +++++-- 2 files changed, 108 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt index 8b9e2faf..0d94833f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingFragment.kt @@ -5,15 +5,18 @@ import android.view.inputmethod.EditorInfo import es.verdnatura.R import es.verdnatura.databinding.FragmentGeneralBlackBinding import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.ExpeditionPrintOut import es.verdnatura.presentation.common.OnCollectionSelectedListener import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix +import es.verdnatura.presentation.view.feature.delivery.model.Expeditions +import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel class BoxPickingFragment(var title: String) : - BaseFragment(BoxPickingViewModel::class) { + BaseFragment(DeliveryViewModel::class) { private var onCollectionSelectedListener: OnCollectionSelectedListener? = null private var isBoxScanned: Boolean = false private lateinit var customDialogInput: CustomDialogInput + private var codeStateId: Number = 0 override fun getLayoutId(): Int = R.layout.fragment_general_black companion object { @@ -25,6 +28,7 @@ class BoxPickingFragment(var title: String) : binding.mainToolbar.toolbarTitle.text = title setEvents() customDialogInput = CustomDialogInput(requireContext()) + viewModel.getExpeditionStateId("CHECKED") super.init() } @@ -40,11 +44,20 @@ class BoxPickingFragment(var title: String) : if (!binding.scanInput.text.isNullOrEmpty()) { try { - showScanBarcode(binding.scanInput.text.toString().toLong()) - }catch (ex:Exception){ - ma.messageWithSound(message =getString(R.string.itemNotValid), isError = true, isPlayed = true, isToasted = false) - } + viewModel.findExpedition( + expedition = binding.scanInput.text.toString().toLong(), + expeditionStateId = codeStateId + ) + + } catch (ex: Exception) { + ma.messageWithSound( + message = getString(R.string.itemNotValid), + isError = true, + isPlayed = true, + isToasted = false + ) + } } binding.scanInput.setText("") @@ -61,10 +74,19 @@ class BoxPickingFragment(var title: String) : customDialogInput.setTitle(getString(R.string.scanItem)) .setOkButton(getString(R.string.accept)) { if (customDialogInput.getValue().isNotEmpty()) { - viewModel.isBoxPickingInPrintOut( - expeditionFk = expeditionFk, - customDialogInput.getValue() + + viewModel.expeditionStateAddSalix( + expeditions = Expeditions( + arrayListOf( + ExpeditionSalix( + expeditionFk = expeditionFk, + stateCode = "CHECKED", + isScanned = 1 + ) + ) + ) ) + } customDialogInput.dismiss() } @@ -76,15 +98,12 @@ class BoxPickingFragment(var title: String) : }.setValue("").show() - - customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { if (customDialogInput.getValue().isNotEmpty()) { - viewModel.isBoxPickingInPrintOut( - expeditionFk = expeditionFk, - customDialogInput.getValue() + viewModel.findExpedition( + expedition = expeditionFk, expeditionStateId = expeditionFk ) } customDialogInput.dismiss() @@ -101,50 +120,55 @@ class BoxPickingFragment(var title: String) : override fun observeViewModel() { with(viewModel) { - /*isBoxPickingInPrintOut.observe(viewLifecycleOwner) { + responseExpeditionStateId.observe(viewLifecycleOwner) { + codeStateId = it + } + responseFindExpeditionId.observe(viewLifecycleOwner) { + if (it != 0) { + showScanBarcode(it.toLong()) + } else { + ma.messageWithSound( + getString( + R.string.errorBoxPicking + ), isError = true, isPlayed = true, isToasted = true + ) + } + responseStateAdd.observe(viewLifecycleOwner) { + if (it) { + customDialogInput.dismiss() + binding.scanInput.requestFocus() + } + } + //Tarea 7751 + isBoxPickingInPrintOut.observe(viewLifecycleOwner) { + if (it.isChecked) { + ma.messageWithSound( + message = getString(R.string.errorBoxPicking), + isError = true, + isPlayed = true, + isToasted = false + + ) + } else { + + } + binding.scanInput.requestFocus() + } + responseCode.observe(viewLifecycleOwner) { ma.messageWithSound( message = getString(R.string.errorInput), - isError = !it, + isError = true, isPlayed = true, isToasted = null ) - binding.scanInput.requestFocus() - - }*/ - //Tarea 7751 - isBoxPickingInPrintOut.observe(viewLifecycleOwner) { - - if (it.isChecked){ - ma.messageWithSound( - message = getString(R.string.errorBoxPicking), - isError = true, - isPlayed = true, - isToasted = false - - ) - }else{ - viewModel.updateExpeditionPrint(it.expeditionFk, expeditionPrintOut = ExpeditionPrintOut(it.expeditionFk,it.itemFk, true)) - - } - binding.scanInput.requestFocus() - - } - responseCode.observe(viewLifecycleOwner) { - - ma.messageWithSound( - message = getString(R.string.errorInput), - isError = true, - isPlayed = true, - isToasted = null - - ) - binding.scanInput.requestFocus() + binding.scanInput.requestFocus() + } } } + } - } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt index 49afcaea..fc0a39ee 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/boxPicking/BoxPickingViewModel.kt @@ -12,8 +12,11 @@ import retrofit2.Response class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) + /*private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } val isBoxPickingInPrintOut: LiveData = _isBoxPickingInPrintOut*/ + private val _responseFindExpeditionId by lazy { MutableLiveData() } + val responseFindExpeditionId: LiveData = _responseFindExpeditionId //Tarea 7751 private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } @@ -28,16 +31,16 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { salix.isBoxPickingInPrintOut( filter = """{"where":{"expeditionFk":$expeditionFk,"itemFk":$itemFk}}""" - /* ).enqueue(object : SalixCallback(context) { + /* ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _isBoxPickingInPrintOut.value = true - } - override fun onError(t: Throwable) { - _isBoxPickingInPrintOut.value = false - } + override fun onSuccess(response: Response) { + _isBoxPickingInPrintOut.value = true + } + override fun onError(t: Throwable) { + _isBoxPickingInPrintOut.value = false + } - })*/ + })*/ //Tarea 7751 //isChecked ).enqueue(object : SalixCallback(context) { @@ -45,8 +48,9 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { _isBoxPickingInPrintOut.value = response.body() } + override fun onError(t: Throwable) { - _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0,0,false) + _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false) } }) @@ -70,8 +74,30 @@ class BoxPickingViewModel(val context: Context) : BaseViewModel(context) { } }) } + + fun findExpedition(expedition: Number, expeditionStateId: Number) { + salix.findExpedition( + filter = """{"where": + { + "expeditionFk":$expedition, + "typeFk":$expeditionStateId + } + }""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseFindExpeditionId.value = 0 + + } + + override fun onError(t: Throwable) { + _responseFindExpeditionId.value = expedition + } + + }) + } + fun updateExpeditionPrint(expeditionFk: Long, expeditionPrintOut: ExpeditionPrintOut) { - salix.update(expeditionFk, expeditionPrintOut) + salix.update(expeditionFk, expeditionPrintOut) .enqueue(object : SalixCallback(context) { }) From 3f8292c261edf948f515c61a7d935b19ff81f2bd Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:25:26 +0200 Subject: [PATCH 02/27] feat: boxPickingPrepared refs #7855 --- app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index dc56317c..b0df8288 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -866,6 +866,8 @@ Añade artículo en varios carros Añade artículos en varios carros Revisa que el elemento escaneado sea un código de compra (buyFk) + Expedición ya preparada + Caja duplicada diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d8a4ad89..2f3b7707 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -866,5 +866,7 @@ Añade artículo en varios carros Añade artículos en varios carros Revisa que el elemento escaneado sea un código de compra (buyFk) + Expedición ya preparada + Caja duplicada diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index e85654b2..8cbc4402 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -866,6 +866,8 @@ Añade artículo en varios carros Añade artículos en varios carros Revisa que el elemento escaneado sea un código de compra (buyFk) + Expedición ya preparada + Caja duplicada diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57942650..b89b5e70 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -869,5 +869,7 @@ Añade artículo en varios carros Añade artículos en varios carros Revisa que el elemento escaneado sea un código de compra (buyFk) + Expedición ya preparada + Caja duplicada From 9ce0349f4117c8fddfcf177f63c310491b7843ad Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:25:52 +0200 Subject: [PATCH 03/27] feat: boxPickingPrepared refs #7855 --- .../ExpeditionPreparedStateFragment.kt | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt index 11b8f088..12bac0ec 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt @@ -15,7 +15,7 @@ import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewM import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter @Suppress("UNUSED_ANONYMOUS_PARAMETER") -class ExpeditionPreparedStateFragment : +class ExpeditionPreparedStateFragment(var codeState: String, var title: String) : BaseFragment( DeliveryViewModel::class ) { @@ -24,19 +24,22 @@ class ExpeditionPreparedStateFragment : private var contador = 0 private var isScanned = false private val listExpeditions: ArrayList = arrayListOf() + private var expeditionStateTypeId: Number = 0 companion object { - fun newInstance() = ExpeditionPreparedStateFragment() + fun newInstance(codeState: String, title: String) = + ExpeditionPreparedStateFragment(codeState = codeState, title = title) } override fun getLayoutId(): Int = R.layout.fragment_automatic_add_expedition override fun init() { ma.hideBottomNavigation(View.GONE) - binding.mainToolbar.toolbarTitle.text = getString(R.string.scanExpeditions) + binding.mainToolbar.toolbarTitle.text = title setEvents() setViews() setToolBar() + viewModel.getExpeditionStateId(codeState) super.init() } @@ -46,7 +49,7 @@ class ExpeditionPreparedStateFragment : private fun setSubtitle() { binding.mainToolbar.toolbarSubtitle.text = - getString(R.string.countNumber, getString(R.string.label), contador) + getString(R.string.countNumber, getString(R.string.label), listExpeditions.size) } private fun setViews() { @@ -54,12 +57,12 @@ class ExpeditionPreparedStateFragment : AutomaticAdapter(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList, object : OnAutomaticItemClickListener { override fun onAutomaticItemClickListener(position: Int) { - contador -= 1 - setSubtitle() + if (listExpeditions.size > position) { listExpeditions.removeAt(position) } adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList) + setSubtitle() } }) binding.itemsRecyclerview.adapter = adapter @@ -75,21 +78,25 @@ class ExpeditionPreparedStateFragment : isScanned = event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER if (binding.editMatricula.text.toString().isNotEmpty()) { - contador += 1 - setSubtitle() try { - - listExpeditions.add( - ExpeditionSalix( - expeditionFk = itemScanValue( - textScanned_filterDouble(binding.editMatricula.text.toString()), - arrayOf("expedition"), - "id" - ).toString().toLong(), stateCode = "PREPARED", isScanned = 0 + val itemScaned = itemScanValue( + textScanned_filterDouble(binding.editMatricula.text.toString()), + arrayOf("expedition"), + "id" + ).toString().toLong() + if (!(listExpeditions.any { it.expeditionFk == itemScaned })) { + viewModel.findExpedition( + itemScaned, expeditionStateTypeId ) - ) - adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList) - binding.itemsRecyclerview.scrollToPosition(0) + binding.itemsRecyclerview.scrollToPosition(0) + } else { + ma.messageWithSound( + message = getString(R.string.boxDuplicated), + isError = true, + isPlayed = true, + isToasted = true + ) + } } catch (ex: Exception) { ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true) } @@ -108,12 +115,12 @@ class ExpeditionPreparedStateFragment : } binding.buttonFinalizar.setOnClickListener { - - if (listExpeditions.isNotEmpty()) viewModel.expeditionStateAddSalix( - Expeditions( - listExpeditions - ) - ) else ma.onMyBackPressed() + if (listExpeditions.isNotEmpty()) + viewModel.expeditionStateAddSalix( + Expeditions( + listExpeditions + ) + ) else ma.onMyBackPressed() } binding.mainToolbar.backButton.setOnClickListener { @@ -126,8 +133,34 @@ class ExpeditionPreparedStateFragment : responseStateAdd.observe(viewLifecycleOwner) { ma.onMyBackPressed() } + responseExpeditionStateId.observe(viewLifecycleOwner) { + expeditionStateTypeId = it + } + + responseFindExpeditionId.observe(viewLifecycleOwner) { + + if (it != 0) { + listExpeditions.add( + ExpeditionSalix( + expeditionFk = it, + stateCode = codeState, + isScanned = if (isScanned) 1 else 0 + ) + ) + setSubtitle() + adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList) + } else { + ma.messageWithSound( + if (codeState == "PREPARED") getString(R.string.expeditionPrepared) else getString( + R.string.errorBoxPicking + ), + isError = true, + isPlayed = true, + isToasted = true + ) + } + } } - } - } + From 50beca0cf3161a2ec58967bd7804b517a9a26df3 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:27:05 +0200 Subject: [PATCH 04/27] feat: boxPickingPrepared refs #7855 --- .../pasillero/fragment/PasilleroFragment.kt | 10 +++---- .../pasillero/fragment/PasilleroViewModel.kt | 26 ++++++------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt index 85aa0f39..934321f1 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroFragment.kt @@ -39,7 +39,6 @@ class PasilleroFragment( override fun init() { ma.hideBottomNavigation(View.VISIBLE) - if (getString(R.string.main) == tagName) { val myWorkSelected: String = mobileApplication.dataStoreApp.readDataStoreKey( @@ -47,7 +46,7 @@ class PasilleroFragment( ) binding.mainToolbarDesign.layoutTool.visibility = View.GONE - if ( myWorkSelected != "Producción" && myWorkSelected != "") { + if (myWorkSelected != "Producción" && myWorkSelected != "") { binding.pasillerosItems.setBackgroundColor(Color.RED) binding.mainToolbarDesign.toolbarTitle.setBackgroundColor(Color.RED) binding.mainToolbarDesign.toolbarTitle.text = @@ -88,9 +87,8 @@ class PasilleroFragment( ).ifBlank { tagName } when (showMenu) { - getString(R.string.titleCorridors) -> { + getString(R.string.titleCorridors) -> viewModel.inititializeDefaultData() - } getString(R.string.titlePalletizers) -> viewModel.inititializeDefaultPallet() getString(R.string.titleBufferManegement) -> viewModel.inititializeDefaultBuffer() @@ -117,7 +115,7 @@ class PasilleroFragment( PasillerosItemVO( R.drawable.ic_picker_ui, R.string.titlePickers, - R.string.titlePickersDescrip + R.string.titlePickersDescrip ) ) @@ -127,7 +125,7 @@ class PasilleroFragment( viewModel.inititializeDefaultDataInit() } } - + super.onCreate(savedInstanceState) } 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 d4a2ab7a..fb9eed9a 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 @@ -21,7 +21,7 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { val userId = (contextApp as MobileApplication).userId private val isOnReservationMode = (contextApp as MobileApplication).dataStoreApp.readDataStoreKey(RESERVATIONMODE) - + fun inititializeDefaultData() { workerActivityAdd(CodeWorkerAction.STORAGE) _pasillerositem.add( @@ -61,13 +61,13 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) //tarea 7855 - /* _pasillerositem.add( - PasillerosItemVO( - R.drawable.ic_scan_prepared, - R.string.scanPreparedExpedition), - R.string.scanPreparedExpedition) - ) - )*/ + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_scan_prepared, + R.string.scanPreparedExpedition, + R.string.scanPreparedExpedition + ) + ) _pasillerositem.add( @@ -423,16 +423,6 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) ) - if (userId == 19591) { - _pasillerositem.add( - PasillerosItemVO( - R.drawable.ic_previous_precontrol, - R.string.titlePreControlTest, - R.string.titlePreControlDescrip - ) - ) - } - _pasillerositem.add( PasillerosItemVO( R.drawable.ic_ticket, R.string.titleShowTicket, R.string.titleShowTicketDescrip From eb729acc59b345bd6c20555367955524ef0a2318 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:27:10 +0200 Subject: [PATCH 05/27] feat: boxPickingPrepared refs #7855 --- .../delivery/viewmodels/DeliveryViewModel.kt | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt index 60b0463c..ad6a5bcd 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt @@ -6,8 +6,10 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.map import es.verdnatura.R import es.verdnatura.domain.SalixCallback +import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.common.ExpeditionPrintOut import es.verdnatura.presentation.common.ResponseSign import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketList import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix @@ -36,6 +38,13 @@ import java.io.File class DeliveryViewModel(val context: Context) : BaseViewModel(context) { + private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) + private val _isBoxPickingInPrintOut by lazy { MutableLiveData() } + val isBoxPickingInPrintOut: LiveData = _isBoxPickingInPrintOut + + private val _responseCode by lazy { MutableLiveData() } + val responseCode: LiveData = _responseCode + private val _expeditionInfoList by lazy { MutableLiveData() } val expeditionInfoList: LiveData = _expeditionInfoList @@ -64,6 +73,12 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { val responseStateAdd: LiveData get() = _responseStateAdd + private val _responseExpeditionStateId by lazy { MutableLiveData() } + val responseExpeditionStateId: LiveData = _responseExpeditionStateId + + private val _responseFindExpeditionId by lazy { MutableLiveData() } + val responseFindExpeditionId: LiveData = _responseFindExpeditionId + private val _responseUpdateRoute by lazy { MutableLiveData() } val responseUpdateRoute: LiveData get() = _responseUpdateRoute @@ -228,6 +243,41 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { }) } + fun findExpedition(expedition: Number, expeditionStateId: Number) { + println("Expedition $expedition") + salix.findExpedition( + filter = """{"where": + { + "expeditionFk":$expedition, + "typeFk":$expeditionStateId + } + }""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseFindExpeditionId.value = 0 + + } + + override fun onError(t: Throwable) { + _responseFindExpeditionId.value = expedition + } + + }) + } + + fun getExpeditionStateId(stateCode: String) { + + salix.getExpeditionStateTypeId( + filter = """{"where":{"code":"$stateCode"}}""".trimMargin() + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseExpeditionStateId.value = + response.body()?.toString()?.let { JSONObject(it).getInt("id") } + } + + }) + } + fun getInfoFreelance( userId: Int ) { @@ -393,6 +443,46 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { }) } + + fun isBoxPickingInPrintOut(expeditionFk: Long, barcode: String) { + getItemFromBarcodeUseCase.execute(barcode) + .enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + + if (response.body() != null) { + isBoxPickingOk( + itemFk = response.body().toString().toLong(), + expeditionFk = expeditionFk + ) + } else { + _responseCode.value = false + } + + } + }) + } + + fun isBoxPickingOk( + expeditionFk: Long, itemFk: Long + + ) { + + salix.isBoxPickingInPrintOut( + filter = """{"where":{"expeditionFk":$expeditionFk,"itemFk":$itemFk}}""" + ).enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + _isBoxPickingInPrintOut.value = response.body() + } + + override fun onError(t: Throwable) { + _isBoxPickingInPrintOut.value = ExpeditionPrintOut(0, 0, false) + } + + }) + } + } fun createJSONObject(listTickets: MutableList, note: String): String { From 45e26bbd491defc49436a2d17bd70e3ba531ec71 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:30:13 +0200 Subject: [PATCH 06/27] feat: vehicleControl refs #7986 --- .../view/feature/sacador/fragment/SacadorFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 95f942fd..8ea4852a 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 @@ -101,7 +101,7 @@ class SacadorFragment( iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) if (type == "PREPARED") { - listIcons.add(iconVehicleIn) + //listIcons.add(iconVehicleIn) } else { listIcons.add(iconPrint) } From 28ad29c68668d3be3ab5cb4af1ce60bed918a89f Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:30:27 +0200 Subject: [PATCH 07/27] feat: boxPickingPrepared refs #7855 --- app/src/main/java/es/verdnatura/domain/SalixService.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index fd3d14ff..61bbf4dd 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -997,6 +997,16 @@ interface SalixService { @Body params: Any ): Call + @GET("ExpeditionStates/findOne") + fun findExpedition( + @Query("filter") filter: String + ): Call + + @GET("ExpeditionStateTypes/findOne") + fun getExpeditionStateTypeId( + @Query("filter") filter: String + ): Call + @POST("WorkerMistakes") fun workerMistakesAdd( @Body workerMistake: WorkerMistakeSalix From e6cf5ef2fbe250d82531b162d8c123ce7eb8149a Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 24 Sep 2024 10:31:04 +0200 Subject: [PATCH 08/27] feat reservas refs #6861 --- .../es/verdnatura/domain/ConstAndValues.kt | 8 +- .../collection/adapter/SaleAdapterNew.kt | 48 +- .../fragment/CollectionFragmentPickerNew.kt | 87 +- .../CollectionFragmentPickerPreviousNew.kt | 491 ++----- .../CollectionFragmentPreCheckerNew.kt | 1180 ----------------- .../fragment/CollectionViewModel.kt | 199 +-- .../feature/main/activity/MainActivity.kt | 31 +- .../main/res/layout/ticket_toast_layout.xml | 16 + 8 files changed, 246 insertions(+), 1814 deletions(-) delete mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreCheckerNew.kt create mode 100644 app/src/main/res/layout/ticket_toast_layout.xml diff --git a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt index ee166162..c0914d4a 100644 --- a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt +++ b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt @@ -12,7 +12,6 @@ object ConstAndValues { const val SERIALNUMBER = "SERIALNUMBER" const val ON_CHECKING = "ON_CHECKING" const val PRECHECKER = "PRECHECKER" - const val PRECHECKERNEW = "PRECHECKERNEW" const val MAINACTIVITY = "MAIN" const val VERTICKET = "SHOWTICKET" const val SECTORFKDEFAULT = -1 @@ -67,11 +66,6 @@ object ConstAndValues { const val LIMITRECORDSSHELVINGLOG = 50 const val RESERVATIONMODE = "operatorReservationMode" const val MODELWORKERTYPEACTIVITY = "APP" - val ACTIONNAMES = listOf( - "STOP", - "ON_CHECKING", - "Delivery" - ) - + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt index ac60ba19..0fbc3f48 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt @@ -14,12 +14,12 @@ import androidx.recyclerview.widget.RecyclerView import es.verdnatura.R import es.verdnatura.databinding.SaleRowFragmentBinding import es.verdnatura.domain.ConstAndValues.PREITEMPICKERTEST +import es.verdnatura.domain.ConstAndValues.PREPARED import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.toast import es.verdnatura.presentation.common.OnMistakeClickListener import es.verdnatura.presentation.common.OnPackingClickSaleListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.OnQuantityClickSaleListener import es.verdnatura.presentation.common.OnSaleClickSaleListener import es.verdnatura.presentation.common.OnTicketClickSaleListener import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO @@ -28,7 +28,6 @@ import es.verdnatura.presentation.view.feature.sacador.model.Sale class SaleAdapterNew( private val items: List, private val onPasillerosItemClickListener: OnPasillerosItemClickListener, - private val onQuantityClick: OnQuantityClickSaleListener, private val onSaleClickListener: OnSaleClickSaleListener, private val onMistakeClickListener: OnMistakeClickListener, private val onPackingClick: OnPackingClickSaleListener, @@ -66,7 +65,7 @@ class SaleAdapterNew( ) : RecyclerView.ViewHolder(binding.root) { fun bind(sale: Sale) { binding.apply { - // if (sale.reservedQuantity == null) sale.reservedQuantity = 0 + // if (sale.reservedQuantity == null) sale.reservedQuantity = 0 val childLayoutManager = LinearLayoutManager(context!!, RecyclerView.HORIZONTAL, false) @@ -121,10 +120,9 @@ class SaleAdapterNew( itemFirstToPicker.setOnClickListener { onPackingClick.onPackingClick(sale) - } - quantityReserved.setOnClickListener { - onQuantityClick.onQuantityClick(sale) - } + }/* quantityReserved.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + }*/ linearLayoutItem.setOnClickListener { @@ -134,6 +132,7 @@ class SaleAdapterNew( } } + println("type es $type") imageErrorMessage.setOnClickListener { // onMistakeClickListener.onMistakeClickListener(sale) @@ -203,7 +202,9 @@ class SaleAdapterNew( txtdeNew.visibility = View.VISIBLE itemArticleQuantityPicked.visibility = View.VISIBLE itemArticleQuantityLine3.visibility = View.VISIBLE*/ - if (type != SACADOR) { + + imageErrorMessage.visibility = View.GONE + if (type != SACADOR && type != PREITEMPICKERTEST) { val colorRes = if (sale.hasMistake == true) R.color.verdnatura_red_salix else R.color.verdnatura_black imageErrorMessage.imageTintList = @@ -221,7 +222,6 @@ class SaleAdapterNew( adapter = SaleAdapterNew( sale.sonSales, onPasillerosItemClickListener, - onQuantityClick, onSaleClickListener, onMistakeClickListener, onPackingClick @@ -271,7 +271,8 @@ class SaleAdapterNew( val textToConcat2: String - val result2: Int = sale.accumulatedQuantity % (sale.packing ?: sale.saleQuantity + 1) + val result2: Int = + sale.accumulatedQuantity % (sale.packing ?: sale.saleQuantity + 1) if (result2 != 0) { textToConcat2 = "${(sale.saleQuantity - sale.accumulatedQuantity) / (sale.grouping ?: 1)} x ${sale.grouping ?: "1"}" @@ -315,12 +316,19 @@ class SaleAdapterNew( "${sale.reservedQuantity} de ${sale.saleQuantity}" if (sale.isPicked == 1) { - contentLayout.setBackgroundColor( - //lolass - getColor( - context!!, R.color.verdnatura_dark_sky_blue + if (type == PREPARED) { + contentLayout.setBackgroundColor( + getColor( + context!!, R.color.verdnatura_orange_salix + ) ) - ) + } else { + contentLayout.setBackgroundColor( + getColor( + context!!, R.color.verdnatura_dark_sky_blue + ) + ) + } } else { contentLayout.setBackgroundColor( getColor( @@ -330,8 +338,8 @@ class SaleAdapterNew( } - binding.itemParkingCode.text = if (type == PREITEMPICKERTEST) - sale.parkingCodePrevia else sale.parkingCode + binding.itemParkingCode.text = + if (type == PREITEMPICKERTEST) sale.parkingCodePrevia else sale.parkingCode this.sale = sale @@ -344,13 +352,11 @@ class SaleAdapterNew( if (color.isNullOrBlank()) { DrawableCompat.setTint( - backgroundDrawableTicket, - Color.TRANSPARENT + backgroundDrawableTicket, Color.TRANSPARENT ) } else { DrawableCompat.setTint( - backgroundDrawableTicket, - Color.parseColor(color) + backgroundDrawableTicket, Color.parseColor(color) ) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt index d44f2094..dd31b066 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerNew.kt @@ -32,7 +32,6 @@ import es.verdnatura.presentation.common.OnMistakeClickListener import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPackingClickSaleListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.OnQuantityClickSaleListener import es.verdnatura.presentation.common.OnSaleClickSaleListener import es.verdnatura.presentation.common.OnTicketClickSaleListener import es.verdnatura.presentation.common.ToolBarAdapterTooltip @@ -398,46 +397,37 @@ class CollectionFragmentPickerNew( responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner) { - if (it.isError) { - ma.messageWithSound( - it.errorMessage, - isError = true, - isPlayed = true - ) - } - if (!it.isError) { - myGroupList[positionConfirm].isPicked = 1 - saleAdapter!!.notifyDataSetChanged() - lm!!.scrollToPositionWithOffset(storedPosition, 0) - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) - } - - } - - - responseItemShelvingSale.observe(viewLifecycleOwner) { myGroupList[positionConfirm].isPicked = 1 - myGroupList[positionConfirm].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionConfirm, 0) - ma.messageWithSound( - getString(R.string.operationSuccess), it.isError, !it.isError, isToasted = false - ) + saleAdapter!!.notifyDataSetChanged() + lm!!.scrollToPositionWithOffset(storedPosition, 0) + /* viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + )*/ + } - responseItemShelvingSaleUnPicked.observe(viewLifecycleOwner) { - myGroupList[positionUnmarked].isPicked = 1 - myGroupList[positionUnmarked].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionUnmarked, 0) - ma.messageWithSound( - getString(R.string.operationSuccess), it.isError, !it.isError, isToasted = false - ) + + /* + responseItemShelvingSale.observe(viewLifecycleOwner) { + myGroupList[positionConfirm].isPicked = 1 + myGroupList[positionConfirm].reservedQuantity = quantityConfirm + viewModel.collectionTicketGetSalix( + collection.collectionFk, print = false + ) + lm!!.scrollToPositionWithOffset(positionConfirm, 0) + ma.messageWithSound( + getString(R.string.operationSuccess), it.isError, !it.isError, isToasted = false + ) + }*/ + loadUnpicked.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + myGroupList[positionUnmarked].isPicked = 0 + myGroupList[positionUnmarked].reservedQuantity = quantityConfirm + saleAdapter!!.notifyItemChanged(positionUnmarked) + + lm!!.scrollToPositionWithOffset(positionUnmarked, 0) + + } } responseItemShelvingSaleGroup.observe(viewLifecycleOwner) { @@ -512,24 +502,7 @@ class CollectionFragmentPickerNew( saleAdapter = SaleAdapterNew( myGroupList, pasillerosItemClickListener!!, - object : OnQuantityClickSaleListener { - - override fun onQuantityClick(sale: Sale) { - sales.forEachIndexed { index, saleVO -> - - if (saleVO.saleFk == sale.saleFk) { - if (sale.isPicked == 1) { - showErrorMessage( - title = getString(R.string.info), - text = getString(R.string.unmarkForModify) - ) - } - - } - } - - } - }, + object : OnSaleClickSaleListener { override fun onSaleClick(mySale: Sale) { myGroupList.forEachIndexed { index, sale -> diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt index 7aa51b2d..1b095899 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt @@ -1,6 +1,5 @@ package es.verdnatura.presentation.view.feature.collection.fragment -import android.app.AlertDialog import android.content.Context import android.graphics.Color import android.graphics.drawable.Drawable @@ -10,6 +9,7 @@ import android.os.Bundle import android.text.InputType import android.view.Gravity import android.view.KeyEvent +import android.view.LayoutInflater import android.view.View import android.view.WindowManager import android.view.inputmethod.EditorInfo @@ -24,7 +24,6 @@ import es.verdnatura.R import es.verdnatura.databinding.FragmentCollectionNewBinding import es.verdnatura.domain.ConstAndValues.BASEURLSALIX import es.verdnatura.domain.ConstAndValues.PRESACADOR -import es.verdnatura.domain.ConstAndValues.PRINTERNAME import es.verdnatura.domain.ConstAndValues.SECTORFK import es.verdnatura.domain.notNull import es.verdnatura.domain.toast @@ -35,7 +34,6 @@ import es.verdnatura.presentation.common.OnMistakeClickListener import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPackingClickSaleListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.OnQuantityClickSaleListener import es.verdnatura.presentation.common.OnSaleClickSaleListener import es.verdnatura.presentation.common.OnTicketClickSaleListener import es.verdnatura.presentation.common.ToolBarAdapterTooltip @@ -68,7 +66,6 @@ class CollectionFragmentPickerPreviousNew( CollectionViewModel::class ) { private var sales: List = listOf() - private var salesParent: List = listOf() private var saleAdapter: SaleAdapterNew? = null private var lm: LinearLayoutManager? = null private var storedPosition: Int = 0 @@ -81,27 +78,15 @@ class CollectionFragmentPickerPreviousNew( private lateinit var customDialogThreeButtonsQuantity: CustomDialogThreeButtons private var ticketSelected: Int = 0 private lateinit var customDialog: CustomDialog - private var goBack: Boolean = false - private var goBack2: Boolean = false - private var goMistakeBack: Boolean = false var mperror: MediaPlayer? = null var mpok: MediaPlayer? = null - private var itemShelvingFkStored: Int = 0 private var storedBackPosition: Int = 0 private var tickets: ArrayList = ArrayList() - private var mistakeSale: SaleVO? = null - private var isMarking = false - private lateinit var ticketScanTxt: String private var lastScanned: Int = 0 - private var buttonPushedGetCollection = false private var positionUnmarked = -1 - private var state = 0 - private var originalItemScan: Long = 0 - private var workerFkFromTicket: String? = null private var isScanned: Boolean? = null private var positionConfirm = 0 private var quantityConfirm = 0 - private var positionMarkPrevia = 0 private lateinit var myGroupList: List private var quantityReserveToCheckItemScan = 0 @@ -119,11 +104,8 @@ class CollectionFragmentPickerPreviousNew( override fun getLayoutId(): Int = R.layout.fragment_collection_new override fun onCreate(savedInstanceState: Bundle?) { - mperror = MediaPlayer.create((activity as MainActivity), R.raw.error) mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok) - println("create onRunning") - super.onCreate(savedInstanceState) } @@ -139,7 +121,7 @@ class CollectionFragmentPickerPreviousNew( customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) customDialogThreeButtonsQuantity = CustomDialogThreeButtons(requireContext()) ma.hideBottomNavigation(View.GONE) - + println("type $type") setEvents() setToolBar() viewModel.collectionTicketGetSalix( @@ -149,13 +131,6 @@ class CollectionFragmentPickerPreviousNew( super.init() } - override fun onPause() { - super.onPause() - goBack = true - goBack2 = true - goMistakeBack = true - } - private fun setToolBar() { binding.mainToolbar.toolbarSubtitle.visibility = View.VISIBLE binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE @@ -165,47 +140,32 @@ class CollectionFragmentPickerPreviousNew( } val listIcons: ArrayList = ArrayList() - val iconPrint = ImageView(context) - iconPrint.setImageResource(R.drawable.ic_print_black_24dp) + val iconAdd = ImageView(context) iconAdd.setImageResource(R.drawable.ic_playlist_add_black_24dp) - val iconViewCollection = ImageView(context) - iconViewCollection.setImageResource(R.drawable.ic_collection) - val iconWorker = ImageView(context) - iconWorker.setImageResource(R.drawable.ic_worker) - val iconPhone = ImageView(context) - iconPhone.setImageResource(R.drawable.phone_call) val iconParking = ImageView(context) iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) val iconUpdate = ImageView(context) iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp) - iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) - iconViewCollection.tooltipText = getTooltip(R.drawable.ic_collection) - iconPhone.tooltipText = getTooltip(R.drawable.phone_call) iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) - // listIcons.add(iconPrint) listIcons.add(iconAdd) listIcons.add(iconParking) listIcons.add(iconUpdate) - // listIcons.remove(iconWorker) binding.mainToolbar.toolbarIcons.adapter = ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { override fun onOptionsItemSelected(item: Drawable) { when (item) { - //iconViewCollection.drawable -> getCollection() - iconPrint.drawable -> print() iconAdd.drawable -> addItem() - iconWorker.drawable -> showUser() iconUpdate.drawable -> updateScreen() iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( PasillerosItemVO( - title =R.string.Parking + title = R.string.Parking ), "" ) } @@ -222,44 +182,14 @@ class CollectionFragmentPickerPreviousNew( ) } - /* private fun markPrevia(saleGroupScanned: String): Boolean { - println("Sacador saleGroup $saleGroupScanned ") - try { - for (indice in sales.indices) { - println("Sacador saleGroup ${sales[indice].saleGroupFk}") - if (sales[indice].saleGroupFk != null && sales[indice].saleGroupFk == saleGroupScanned.toInt()) { - println("Sacador saleGroup ${sales[indice].itemShelvingSaleFk}") - viewModel.itemShelvingSaleSetSaleGroup(saleGroupScanned.toInt()) - positionMarkPrevia = indice - mpok!!.start() - return true - - } - } - } catch (ex: Exception) { - return false - } - return false - }*/ - private fun scanRequest() { binding.scanInput.requestFocus() hideKeyboards() } - private fun showUser() { - - ma.onPasillerosItemClickListener( - PasillerosItemVO(title = R.string.titleUserControlVehicle), - workerFkFromTicket.toString() - ) - - } - private fun setEvents() { binding.mainToolbar.backButton.setOnClickListener { - println("reserva fuera") ma.onMyBackPressed() } //ESCANER ========= @@ -274,12 +204,8 @@ class CollectionFragmentPickerPreviousNew( if (itemScanIsQr(binding.scanInput.text.toString())) { val myQr = ItemScanned(JSONObject(binding.scanInput.text.toString())) when (myQr.table) { - "saleGroup" -> {/* if (type == CONTROLADOR) { - markPrevia(myQr.id.toString()) - } else {*/ + "saleGroup" -> { binding.scanInput.setText(myQr.id.toString()) - //findSale(binding.scanInput.text.toString()) - // } } "buy" -> binding.scanInput.setText(myQr.more) @@ -289,7 +215,6 @@ class CollectionFragmentPickerPreviousNew( ma.hideKeyboard(binding.scanInput) findSale(binding.scanInput.text.toString()) } - buttonPushedGetCollection = false } binding.scanInput.setText("") hideKeyboards() @@ -302,16 +227,8 @@ class CollectionFragmentPickerPreviousNew( //LISTA ========= binding.collectionSwipe.setOnRefreshListener { - isMarking = false binding.collectionSwipe.isRefreshing = false - - updateScreen()/* viewModel.collectionTicketGet( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), - print = "0", - type - )*/ - buttonPushedGetCollection = false + updateScreen() binding.collectionSwipe.isRefreshing = false } @@ -336,11 +253,6 @@ class CollectionFragmentPickerPreviousNew( if (it.tickets.isNotEmpty()) { collection = it createCollectionList() - workerFkFromTicket = if (it.tickets[0].sales.isNotEmpty()) { - it.tickets[0].sales[0].workerFk.toString() - } else { - "" - } } else { binding.mainToolbar.toolbarSubtitle.text = "0/0" @@ -356,8 +268,18 @@ class CollectionFragmentPickerPreviousNew( } } - - responseExistsItemShelvingSale.observe(viewLifecycleOwner) { + loadExistsResponse.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + if (it.exists) { + markLine(it.position, it.quantity, true) + } else { + getString(R.string.updateSalesReserve).toast( + requireContext() + ) + viewModel.collectionTicketGetSalix(collection.collectionFk, false) + } + } + }/*responseExistsItemShelvingSale.observe(viewLifecycleOwner) { if (!goBack) { if (it.exists) { markLine(it.position, it.quantity, true) @@ -369,17 +291,8 @@ class CollectionFragmentPickerPreviousNew( } } - } - responseParking.observe(viewLifecycleOwner) { - if (!goBack) { - ma.messageWithSound( - if (it.isError) it.errorMessage else getString(R.string.Aparcado), - it.isError, - true - ) - } + }*/ - } loadResponseAddItem.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { updateScreen() @@ -387,117 +300,52 @@ class CollectionFragmentPickerPreviousNew( } - responsePrint.observe(viewLifecycleOwner) { - - if (!goBack) { - - if (it.isError) { - ma.messageWithSound( - it.errorMessage, isError = true, true - ) - } else { - (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( - PRINTERNAME - )).toast( - requireContext() - ) - } - } - - } - - responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner) { - - if (it.isError) { - ma.messageWithSound( - it.errorMessage, isError = true, true - ) - setTotalLines() - } else { + loadPicked.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { myGroupList[positionConfirm].isPicked = 1 saleAdapter!!.notifyItemChanged(positionConfirm) - //lolass - lm!!.scrollToPositionWithOffset(storedBackPosition, 0) - // lm!!.scrollToPositionWithOffset(storedBackPosition + 1, 0) - + lm!!.scrollToPositionWithOffset(positionConfirm, 0) + //lm!!.scrollToPositionWithOffset(storedBackPosition + 1, 0) setTotalLines() - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) + } - } - - responseItemShelvingSale.observe(viewLifecycleOwner) { - - myGroupList[positionConfirm].isPicked = 1 - myGroupList[positionConfirm].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionConfirm, 0) - //saleAdapter!!.notifyDataSetChanged() - ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError - ) - } loadUnpicked.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { - myGroupList[positionUnmarked].isPicked = 1 + myGroupList[positionUnmarked].isPicked = 0 myGroupList[positionUnmarked].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) + saleAdapter!!.notifyItemChanged(positionUnmarked) lm!!.scrollToPositionWithOffset(positionUnmarked, 0) - //saleAdapter!!.notifyDataSetChanged() - ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError - ) + } } - responseItemShelvingSaleGroup.observe(viewLifecycleOwner) { - - viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionMarkPrevia, 0) - - ma.messageWithSound( - getString(R.string.previousCollected), it.isError, !it.isError - ) - } responseCode.observe(viewLifecycleOwner) { - if (!goBack2) { - if (it == null) { - showErrorMessage(text = getString(R.string.codeNotExist)) - if (mperror != null) mperror?.start() + if (it == null) { + showErrorMessage(text = getString(R.string.codeNotExist)) + if (mperror != null) mperror?.start() + } else { + if (checkItemScan(it.toString(), positionConfirm)) { + scanRequest() + customDialogList.dismiss() + mpok?.start() + markLine(positionConfirm, quantityReserveToCheckItemScan, false) } else { - if (checkItemScan(it.toString())) { - scanRequest() - customDialogList.dismiss() - mpok?.start() - markLine(storedPosition, quantityReserveToCheckItemScan, false) - } else { - customDialogList.setValueTwo("") - showErrorMessage(text = getString(R.string.lineNotExist)) - if (mperror != null) mperror?.start() - } + customDialogList.setValueTwo("") + showErrorMessage(text = getString(R.string.lineNotExist)) + if (mperror != null) mperror?.start() } } - goBack2 = false - } } } private fun createCollectionList() { - state = 0 binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString() collection.map(requireContext()) @@ -509,8 +357,7 @@ class CollectionFragmentPickerPreviousNew( val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_TO") collection.tickets.forEach { ticket -> - if (observations.isNotEmpty()) observations = - observations + " " + ticket.observations + if (observations.isNotEmpty()) observations = observations + " " + ticket.observations ticket.sales.forEach { sale -> if (hasPickingOrder) { @@ -523,35 +370,12 @@ class CollectionFragmentPickerPreviousNew( } } - - sales = salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) - + // sales = salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) //quitar comentarios FALTA AGRUPAR LAS PREVIAS myGroupList = salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) - // sales //sales porque no se ggrupan las previas hay que cambiar los estados. + saleAdapter = SaleAdapterNew(myGroupList, pasillerosItemClickListener!!, - saleAdapter = SaleAdapterNew( - myGroupList, - pasillerosItemClickListener!!, - object : OnQuantityClickSaleListener { - - override fun onQuantityClick(sale: Sale) { - sales.forEachIndexed { index, saleVO -> - - if (saleVO.saleFk == sale.saleFk) { - if (sale.isPicked == 1) { - showErrorMessage( - title = getString(R.string.info), - text = getString(R.string.unmarkForModify) - ) - } - - } - } - - } - }, object : OnSaleClickSaleListener { override fun onSaleClick(sale: Sale) { @@ -565,48 +389,13 @@ class CollectionFragmentPickerPreviousNew( } } - /* myGroupList.forEachIndexed { index, sale -> - //sales.forEachIndexed { index, sale -> - // println("Sacador la sale es ${sale.saleFk}") - // println("Sacador la sale picked es ${sale.isPicked}") - // println("Sacador la sale group es ${sale.saleGroupFk}") - // println("Sacador la sale reserved es ${sale.reservedQuantity}") - if (sale.itemShelvingSaleFk == 0) { - println("Sacador Que hacemos en este caso ?? ") - } else { - - - if (sale.itemShelvingSaleFk == mysale.itemShelvingSaleFk) { - println("Sacador **** itemShelvingSale es ${sale.itemShelvingSaleFk}") - println("Sacador **** isPicked es ${sale.isPicked}") - println("Sacador **** saleGroup es ${sale.saleGroupFk}") - //println("Sacador la sale es ${sale.saleFk}") - //println("Sacador la sale picked es ${sale.isPicked}") - //println("Sacador la sale group es ${sale.saleGroupFk}") - //println("Sacador la sale reserved es ${sale.reservedQuantity}") - //println("Sacador la sale dentro es ${sale.saleFk}") - if (sale.isPicked != 1 && sale.saleGroupFk == null) { - println("Sacador **** showScanner") - showScanner(index, sale) - } else { - println("Sacador **** desmarcar") - unMarkLine(index, myGroupList[index]) - } - - } - } - - }*/ } - }, - object : OnMistakeClickListener { + }, object : OnMistakeClickListener { override fun onMistakeClickListener(sale: SaleVO) { } - }, - object : OnPackingClickSaleListener { + }, object : OnPackingClickSaleListener { override fun onPackingClick(sale: Sale) { - goBack = true if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener( PasillerosItemVO( @@ -614,8 +403,7 @@ class CollectionFragmentPickerPreviousNew( ), entryPoint = sale.code ) } - }, - object : OnTicketClickSaleListener { + }, object : OnTicketClickSaleListener { override fun onTicketClickListener(sale: Sale) { val entryPoint = Gson().toJson( mutableMapOf( @@ -632,8 +420,7 @@ class CollectionFragmentPickerPreviousNew( ), entryPoint = entryPoint ) } - }, - type = type + }, type = type ) @@ -642,7 +429,7 @@ class CollectionFragmentPickerPreviousNew( binding.fragmentSacadorCollections.layoutManager = lm setTotalLines() - setStoredPosition() + setListPosition() setScrollListener(lm!!) printObservations(observations) } @@ -652,7 +439,8 @@ class CollectionFragmentPickerPreviousNew( binding.fragmentSacadorCollections.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - storedBackPosition = lm.findFirstVisibleItemPosition() + // storedBackPosition = lm.findFirstVisibleItemPosition() + storedPosition = lm.findFirstVisibleItemPosition() super.onScrolled(recyclerView, dx, dy) } }) @@ -670,14 +458,12 @@ class CollectionFragmentPickerPreviousNew( private fun findSale(txtscan: String) { - var isFoundSale = false // markPrevia(txtscan) - + var isFoundSale = false //Se busca la matricula en las lineas for (indice in myGroupList.indices) { if (myGroupList[indice].isPicked != 1 && myGroupList[indice].code != null && myGroupList[indice].code!!.uppercase() == txtscan.uppercase()) { mpok!!.start() isFoundSale = true - positionMarkPrevia = indice printShelvingResult(indice) break } @@ -694,8 +480,6 @@ class CollectionFragmentPickerPreviousNew( if (sale.code!!.uppercase() == txtscan.uppercase()) { mpok!!.start() printShelvingResult(position) - //sale.isPicked = 1 - //saleAdapter!!.notifyItemChanged(position) } else { mperror!!.start() } @@ -704,30 +488,27 @@ class CollectionFragmentPickerPreviousNew( private fun markLine(position: Int, quantity: Int, isItemShelvingSaleEmpty: Boolean?) { - state = 0 isScanned = null positionConfirm = position quantityConfirm = quantity - isMarking = true runBlocking { - var sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) + val sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) viewModel.itemShelvingSaleSetQuantity( - myGroupList[position].itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty = isItemShelvingSaleEmpty, sectorFk = if (sectorFk == -1) null else sectorFk + myGroupList[position].itemShelvingSaleFk, + quantity, + isItemShelvingSaleEmpty = isItemShelvingSaleEmpty, + sectorFk = if (sectorFk == -1) null else sectorFk ) } - storedBackPosition = position/* var mySale = myGroupList[position].itemShelvingSaleFk - for (indice in myGroupList.indices) { - if (!myGroupList[indice].isParent && myGroupList[indice].itemShelvingSaleFk == mySale) { - storedBackPosition = indice - } - }*/ + // storedBackPosition = position } private fun setListPosition() { - if (storedPosition == 0 && storedBackPosition == 0) { // se inicia lista, se busca porqué item vamos. + //if (storedPosition == 0 && storedBackPosition == 0) { // se inicia lista, se busca porqué item vamos. + if (storedPosition == 0) { for (indice in myGroupList.indices) { if (myGroupList[indice].isPicked == 0) { //storedPosition = indice @@ -737,12 +518,13 @@ class CollectionFragmentPickerPreviousNew( } } else { - lm!!.scrollToPositionWithOffset(storedBackPosition, 0) + // lm!!.scrollToPositionWithOffset(storedBackPosition, 0) + lm!!.scrollToPositionWithOffset(storedPosition, 0) } } private fun unMarkLine(position: Int, sale: Sale) { - state = 0 + customDialog.setTitle(getString(R.string.unmarkLine)).setDescription( getString(R.string.goUnmark) + sale.itemFk + getString( R.string.sure @@ -750,17 +532,10 @@ class CollectionFragmentPickerPreviousNew( ).setOkButton(getString(R.string.unmark)) { if (!sale.isParent && sale.reservedQuantity == 0 && sale.originalQuantity != sale.saleQuantity) { getString(R.string.unmarkError).toast(requireContext()) - } else {/* saleAdapter!!.notifyDataSetChanged() - var mySale = sale.saleFk - for (indice in myGroupList.indices) { - if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { - d("VERDNATURA::", "la pos del index de la sale es" + indice) - storedBackPosition = indice - } - }*/ - storedBackPosition = position - setListPosition() - + } else { + //storedBackPosition = position + //storedPosition = position + // setListPosition() viewModel.itemShelvingSaleUnpicked(myGroupList[position].itemShelvingSaleFk) sale.isPicked = 0 positionUnmarked = position @@ -777,9 +552,8 @@ class CollectionFragmentPickerPreviousNew( } - //SHELVINGS - private fun printShelvingResult(pos: Int) { + storedPosition = pos customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_TEXT customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) @@ -789,7 +563,6 @@ class CollectionFragmentPickerPreviousNew( val item = myGroupList[pos].itemFk val longName = myGroupList[pos].longName val totalReserved = myGroupList[pos].reservedQuantity - val itemShelvingFk = myGroupList[pos].itemShelvingSaleFk try { customDialogList.setTitle("$shelving($item) $totalReserved de $longName").setOkButton( @@ -797,7 +570,7 @@ class CollectionFragmentPickerPreviousNew( R.string.take ) ) { - customDialogTakeAction(pos, itemShelvingFk, totalReserved, false) + customDialogTakeAction(pos, totalReserved, false) }.setKoButton(getString(R.string.close)) { requireActivity().hideKeyboard(customDialogList.getEditTextTwo()) @@ -812,7 +585,6 @@ class CollectionFragmentPickerPreviousNew( customDialogTakeAction( pos, - itemShelvingFk, totalReserved, event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER ) @@ -828,9 +600,8 @@ class CollectionFragmentPickerPreviousNew( } private fun customDialogTakeAction( - position: Int, itemShelvingFk: Int, totalReserved: Int, isItemScanned: Boolean? + position: Int, totalReserved: Int, isItemScanned: Boolean? ) { - goBack = false isScanned = isItemScanned if (customDialogList.getValueTwo().isNotEmpty()) { @@ -843,7 +614,7 @@ class CollectionFragmentPickerPreviousNew( if (quantityToReserve < totalReserved) { - if (customDialogList.getValueTwo() in sales[position].Barcodes || customDialogList.getValueTwo() == sales[position].itemFk.toString()) { + if (customDialogList.getValueTwo() in myGroupList[position].Barcodes || customDialogList.getValueTwo() == myGroupList[position].itemFk.toString()) { customDialogList.dismiss() showQuestionUbicationEmpty(position, quantityToReserve) } else { @@ -862,22 +633,19 @@ class CollectionFragmentPickerPreviousNew( } if (quantityToReserve == totalReserved) { try { - originalItemScan = customDialogList.getValueTwo().toLong() - if (checkItemScan(customDialogList.getValueTwo())) { + if (checkItemScan(customDialogList.getValueTwo(), position)) { - markLine(storedPosition, quantityToReserve, false) + markLine(position, quantityToReserve, false) mpok?.start() ma.hideKeyboard(customDialogList.getEditTextTwo()) customDialogList.dismiss() - showTicket(sales[position].ticketFk) + showTicket(myGroupList[position].ticketFk) scanRequest() } else { - itemShelvingFkStored = itemShelvingFk - quantityReserveToCheckItemScan = quantityToReserve viewModel.getIdFromCodeSalix( code = customDialogList.getValueTwo(), @@ -895,29 +663,30 @@ class CollectionFragmentPickerPreviousNew( } } - private fun showTicket(ticketFk:Int) { - - val toast = Toast.makeText(requireContext(), "$ticketFk", Toast.LENGTH_LONG) - val view = toast.view - val text = view?.findViewById(android.R.id.message) - text?.setTextColor(requireContext().getColor(R.color.verdnatura_orange_salix)) - text?.textSize = 18f + private fun showTicket(ticketFk: Int) { + val inflater = LayoutInflater.from(requireContext()) + val layout = inflater.inflate(R.layout.ticket_toast_layout, null) + val text = layout.findViewById(R.id.toast_text) + text.text = "$ticketFk" + text.setTextColor(requireContext().getColor(R.color.verdnatura_orange_salix)) + text.textSize = 18f val background = GradientDrawable() background.setColor(Color.parseColor("#000000")) background.cornerRadius = 16f - view?.background = background + layout.background = background + val toast = Toast(requireContext()) + toast.duration = Toast.LENGTH_LONG + toast.view = layout toast.setGravity(Gravity.CENTER, 0, 0) toast.show() } - private fun setStoredPosition() { - setListPosition()/*if (goBack) setListPosition(storedBackPosition, isFromBack) else { - setListPosition(storedPosition, isFromBack)*/ - } - - private fun checkItemScan(valueToCheck: String): Boolean { - - val saleToCheck = myGroupList[storedPosition] + private fun checkItemScan(valueToCheck: String, position: Int): Boolean { + println("CheckItemScan $valueToCheck") + val saleToCheck = myGroupList[position] + println("CheckItemScan saleTocheck$saleToCheck") + println("CheckItemScan saleTocheck Item ${saleToCheck.itemFk}") + println("CheckItemScan saleTocheck ItemBarcodes ${saleToCheck.Barcodes}") if (saleToCheck.itemFk.toString() == valueToCheck) return true else { saleToCheck.Barcodes.forEach { barcode -> @@ -929,12 +698,11 @@ class CollectionFragmentPickerPreviousNew( } private fun showQuestionUbicationEmpty(position: Int, quantity: Int = 0) { - customDialogThreeButtonsQuantity.setTitle( getString( - R.string.changeQuantity, quantity, sales[position].itemFk + R.string.changeQuantity, quantity, myGroupList[position].itemFk ) - ).setDescription(getString(R.string.questionItemShelving, sales[position].itemFk)) + ).setDescription(getString(R.string.questionItemShelving, myGroupList[position].itemFk)) .setValue("").setCustomDialogValue(View.GONE) customDialogThreeButtonsQuantity.setOkButtonAdd(text = getString(R.string.yes)) { scanRequest() @@ -942,7 +710,7 @@ class CollectionFragmentPickerPreviousNew( getString(R.string.errorQuantityShelving).toast(requireContext()) customDialogThreeButtonsQuantity.dismiss() showQuestionUbicationEmpty(position, quantity) - }.setOkButtonTwo("NO") { + }.setOkButtonTwo(getString(R.string.no)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() if (quantity == 0) { @@ -959,25 +727,6 @@ class CollectionFragmentPickerPreviousNew( customDialogThreeButtons.setFocusDialogValue() } - //OPTIONS - private fun print() { - - if (ma.havePrinter() && ma.haveSector()) { - showDialogLabelCount() - - } else { - ma.messageWithSound( - getString(R.string.printerFault), - isError = true, - true, - getString(R.string.printError), - false - ) - - } - - } - private fun addItem() { listPlacementSupply = ArrayList() collection.tickets.forEach { @@ -1023,7 +772,6 @@ class CollectionFragmentPickerPreviousNew( } - customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { customDialogAddItem() @@ -1096,27 +844,17 @@ class CollectionFragmentPickerPreviousNew( } private fun setTotalLines() { - - val totalMark = sales.count { it.isPicked == 1 } - + val totalMark = myGroupList.count { it.isPicked == 1 } binding.mainToolbar.toolbarTitle.text = if (collection.collectionFk != 0) collection.collectionFk.toString() else "" - - binding.mainToolbar.toolbarSubtitle.text = - getString(R.string.totalsPicker, totalMark, sales.size) - - if (totalMark == sales.size) { + getString(R.string.totalsPicker, totalMark, myGroupList.size) + if (totalMark == myGroupList.size) { getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) - changeTicketState() + viewModel.saleTrackingAddPrevOK(collection.collectionFk) } } - private fun changeTicketState() { - - viewModel.saleTrackingAddPrevOK(collection.collectionFk) - } - private fun showScanner(index: Int, sale: Sale) { customDialogInput.getEditText().inputType = InputType.TYPE_CLASS_TEXT customDialogInput.setTitle("" + sale.itemFk) @@ -1150,7 +888,6 @@ class CollectionFragmentPickerPreviousNew( scanInput.requestFocus() customDialogInput.dismiss() scanInput.requestFocus() - } private fun showErrorMessage(title: String = getString(R.string.errorMarkLine), text: String) { @@ -1158,38 +895,4 @@ class CollectionFragmentPickerPreviousNew( customDialog.dismiss() }.show() } - - private fun showDialogLabelCount() { - var isTicket = false - for (t in collection.tickets) { - if (t.ticketFk == (collection.collectionFk)) { - isTicket = true - } - } - if (isTicket) { - val builder = AlertDialog.Builder(context) - builder.setTitle(getString(R.string.selectLabeltoPrint)) - val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") - builder.setItems(labelCount) { dialog, which -> - viewModel.collectionStickerPrint( - collectionFk = collection.collectionFk, labelCount = (which + 1) - ) - (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( - PRINTERNAME - )).toast(requireContext()) - - } - val dialog = builder.create() - dialog.show() - } else { - viewModel.collectionStickerPrint( - collectionFk = collection.collectionFk, null - ) - - } - - } - -} - - +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreCheckerNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreCheckerNew.kt deleted file mode 100644 index 11f2b522..00000000 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPreCheckerNew.kt +++ /dev/null @@ -1,1180 +0,0 @@ -package es.verdnatura.presentation.view.feature.collection.fragment - -import android.app.AlertDialog -import android.content.Context -import android.graphics.drawable.Drawable -import android.media.MediaPlayer -import android.os.Bundle -import android.text.InputType -import android.view.KeyEvent -import android.view.View -import android.view.WindowManager -import android.view.inputmethod.EditorInfo -import android.widget.EditText -import android.widget.ImageView -import android.widget.Toast -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.google.gson.Gson -import es.verdnatura.R -import es.verdnatura.databinding.FragmentCollectionNewBinding -import es.verdnatura.domain.ConstAndValues.BASEURLSALIX -import es.verdnatura.domain.ConstAndValues.PRECHECKERNEW -import es.verdnatura.domain.ConstAndValues.PRINTERNAME -import es.verdnatura.domain.ConstAndValues.SECTORFK -import es.verdnatura.domain.notNull -import es.verdnatura.domain.toast -import es.verdnatura.presentation.base.BaseFragment -import es.verdnatura.presentation.common.ItemScanned -import es.verdnatura.presentation.common.OnBarcodeRowClickListener -import es.verdnatura.presentation.common.OnMistakeClickListener -import es.verdnatura.presentation.common.OnOptionsSelectedListener -import es.verdnatura.presentation.common.OnPackingClickSaleListener -import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.OnQuantityClickSaleListener -import es.verdnatura.presentation.common.OnSaleClickSaleListener -import es.verdnatura.presentation.common.OnTicketClickSaleListener -import es.verdnatura.presentation.common.ToolBarAdapterTooltip -import es.verdnatura.presentation.common.hideKeyboard -import es.verdnatura.presentation.common.itemScanIsQr -import es.verdnatura.presentation.common.itemScanValue -import es.verdnatura.presentation.view.component.CustomDialog -import es.verdnatura.presentation.view.component.CustomDialogInput -import es.verdnatura.presentation.view.component.CustomDialogList -import es.verdnatura.presentation.view.component.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 -import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapterNew -import es.verdnatura.presentation.view.feature.collection.mapper.map -import es.verdnatura.presentation.view.feature.main.activity.MainActivity -import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO -import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket -import es.verdnatura.presentation.view.feature.sacador.model.Sale -import es.verdnatura.presentation.view.feature.sacador.model.SaleVO -import kotlinx.coroutines.runBlocking -import org.json.JSONObject - -class CollectionFragmentPreCheckerNew( - var collection: CollectionTicket?, - var type: String = PRECHECKERNEW, - private var hasPickingOrder: Boolean = false -) : BaseFragment( - CollectionViewModel::class -) { - private var sales: List = listOf() - private var salesParent: List = listOf() - private var saleAdapter: SaleAdapterNew? = null - private var lm: LinearLayoutManager? = null - private var storedPosition: Int = 0 - private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null - private lateinit var customDialogList: CustomDialogList - private var placementSupplyAdapter: BarcodeAdapter? = null - private var listPlacementSupply: ArrayList = ArrayList() - private lateinit var customDialogInput: CustomDialogInput - private lateinit var customDialogThreeButtons: CustomDialogThreeButtons - private lateinit var customDialogThreeButtonsQuantity: CustomDialogThreeButtons - private var ticketSelected: Int = 0 - private lateinit var customDialog: CustomDialog - private var goBack: Boolean = false - private var goBack2: Boolean = false - private var goMistakeBack: Boolean = false - var mperror: MediaPlayer? = null - var mpok: MediaPlayer? = null - private var itemShelvingFkStored: Int = 0 - private var storedBackPosition: Int = 0 - private var tickets: ArrayList = ArrayList() - private var mistakeSale: SaleVO? = null - private var isMarking = false - private lateinit var ticketScanTxt: String - private var lastScanned: Int = 0 - private var buttonPushedGetCollection = false - private var positionUnmarked = -1 - private var state = 0 - private var originalItemScan: Long = 0 - private var workerFkFromTicket: String? = null - private var isScanned: Boolean? = null - private var positionConfirm = 0 - private var quantityConfirm = 0 - private var positionMarkPrevia = 0 - private lateinit var myGroupList: List - private var quantityReserveToCheckItemScan = 0 - - companion object { - fun newInstance( - collection: CollectionTicket? = null, type: String, hasPickingOrder: Boolean = false - ) = CollectionFragmentPreCheckerNew(collection, type, hasPickingOrder) - } - - override fun onAttach(context: Context) { - if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context - super.onAttach(context) - } - - override fun getLayoutId(): Int = R.layout.fragment_collection_new - - override fun onCreate(savedInstanceState: Bundle?) { - - mperror = MediaPlayer.create((activity as MainActivity), R.raw.error) - mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok) - println("create onRunning") - - super.onCreate(savedInstanceState) - } - - override fun onResume() { - super.onResume() - scanRequest() - } - - override fun init() { - customDialogList = CustomDialogList(requireContext()) - customDialogInput = CustomDialogInput(requireContext()) - customDialog = CustomDialog(requireContext()) - customDialogThreeButtons = CustomDialogThreeButtons(requireContext()) - customDialogThreeButtonsQuantity = CustomDialogThreeButtons(requireContext()) - ma.hideBottomNavigation(View.GONE) - - setEvents() - setToolBar() - /* viewModel.collectionTicketGetSalix( - collection.collectionFk, print = false - )*/ - - super.init() - } - - override fun onPause() { - super.onPause() - goBack = true - goBack2 = true - goMistakeBack = true - } - - private fun setToolBar() { - binding.mainToolbar.toolbarSubtitle.visibility = View.VISIBLE - binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE - binding.mainToolbar.backButton.visibility = View.VISIBLE - collection?.collectionFk.let { - binding.mainToolbar.toolbarTitle.text = collection?.collectionFk.toString() - } - - val listIcons: ArrayList = ArrayList() - val iconPrint = ImageView(context) - iconPrint.setImageResource(R.drawable.ic_print_black_24dp) - val iconAdd = ImageView(context) - iconAdd.setImageResource(R.drawable.ic_playlist_add_black_24dp) - val iconViewCollection = ImageView(context) - iconViewCollection.setImageResource(R.drawable.ic_collection) - val iconWorker = ImageView(context) - iconWorker.setImageResource(R.drawable.ic_worker) - val iconPhone = ImageView(context) - iconPhone.setImageResource(R.drawable.phone_call) - val iconParking = ImageView(context) - iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) - val iconUpdate = ImageView(context) - iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp) - - iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) - iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) - iconViewCollection.tooltipText = getTooltip(R.drawable.ic_collection) - iconPhone.tooltipText = getTooltip(R.drawable.phone_call) - iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) - iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) - - // listIcons.add(iconPrint) - listIcons.add(iconAdd) - listIcons.add(iconParking) - listIcons.add(iconUpdate) - // listIcons.remove(iconWorker) - - binding.mainToolbar.toolbarIcons.adapter = - ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { - override fun onOptionsItemSelected(item: Drawable) { - - when (item) { - //iconViewCollection.drawable -> getCollection() - iconPrint.drawable -> print() - iconAdd.drawable -> addItem() - iconWorker.drawable -> showUser() - iconUpdate.drawable -> updateScreen() - iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( - PasillerosItemVO( - title = R.string.Parking - ), "" - ) - } - - } - }) - binding.mainToolbar.toolbarIcons.layoutManager = - LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) - } - - private fun updateScreen() { - collection?.let { - viewModel.collectionTicketGetSalix( - it.collectionFk, print = false - ) - } - - } - - private fun markPrevia(saleGroupScanned: String): Boolean { - println("Sacador saleGroup $saleGroupScanned ") - try { - for (indice in sales.indices) { - println("Sacador saleGroup ${sales[indice].saleGroupFk}") - if (sales[indice].saleGroupFk != null && sales[indice].saleGroupFk == saleGroupScanned.toInt()) { - println("Sacador saleGroup ${sales[indice].itemShelvingSaleFk}") - viewModel.itemShelvingSaleSetSaleGroup(saleGroupScanned.toInt()) - positionMarkPrevia = indice - mpok!!.start() - return true - - } - } - } catch (ex: Exception) { - return false - } - return false - } - - private fun scanRequest() { - binding.scanInput.requestFocus() - hideKeyboards() - } - - private fun showUser() { - - ma.onPasillerosItemClickListener( - PasillerosItemVO(title = R.string.titleUserControlVehicle), - workerFkFromTicket.toString() - ) - - } - - private fun setEvents() { - - binding.mainToolbar.backButton.setOnClickListener { - println("reserva fuera") - ma.onMyBackPressed() - } - //ESCANER ========= - - binding.scanInput.requestFocus() - binding.scanInput.setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {//ID=0 ACTION_NEXT ID=5 ACTION_UNESPECEFIED) - if (binding.scanInput.text.toString().isNotEmpty()) { - binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) - isScanned = - event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER - if (itemScanIsQr(binding.scanInput.text.toString())) { - val myQr = ItemScanned(JSONObject(binding.scanInput.text.toString())) - when (myQr.table) { - "saleGroup" -> {/* if (type == CONTROLADOR) { - markPrevia(myQr.id.toString()) - } else {*/ - binding.scanInput.setText(myQr.id.toString()) - //findSale(binding.scanInput.text.toString()) - // } - } - - "buy" -> binding.scanInput.setText(myQr.more) - } - - } else { - ma.hideKeyboard(binding.scanInput) - viewModel.collectionTicketGetSalix( - binding.scanInput.text.toString().toInt(), print = false - ) - //findSale(binding.scanInput.text.toString()) - } - buttonPushedGetCollection = false - } - binding.scanInput.setText("") - hideKeyboards() - return@setOnEditorActionListener true - } - true - } - - hideKeyboards() - - //LISTA ========= - binding.collectionSwipe.setOnRefreshListener { - isMarking = false - binding.collectionSwipe.isRefreshing = false - - updateScreen()/* viewModel.collectionTicketGet( - collection.collectionFk, - mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), - print = "0", - type - )*/ - buttonPushedGetCollection = false - binding.collectionSwipe.isRefreshing = false - - } - } - - private fun hideKeyboards() { - try { - requireActivity().hideKeyboard() - } catch (e: Exception) { - println(e.message) - } - } - - override fun observeViewModel() { - - with(viewModel) { - - loadCollectionTicketSalix.observe(viewLifecycleOwner) { event -> - event.getContentIfNotHandled().notNull { - if (!it.isError) { - - if (it.tickets.isNotEmpty()) { - collection = it - createCollectionList() - workerFkFromTicket = if (it.tickets[0].sales.isNotEmpty()) { - it.tickets[0].sales[0].workerFk.toString() - } else { - "" - } - - } else { - binding.mainToolbar.toolbarSubtitle.text = "0/0" - } - } else { - customDialog.setTitle(getString(R.string.error)) - .setDescription(it.errorMessage) - .setOkButton(getString(R.string.accept)) { - customDialog.dismiss() - if (activity != null) ma.onMyBackPressed() - }.show() - } - - } - } - - responseExistsItemShelvingSale.observe(viewLifecycleOwner) { - if (!goBack) { - if (it.exists) { - markLine(it.position, it.quantity, true) - } else { - getString(R.string.updateSalesReserve).toast( - requireContext() - ) - viewModel.collectionTicketGetSalix(collection!!.collectionFk, false) - } - } - - } - responseParking.observe(viewLifecycleOwner) { - if (!goBack) { - ma.messageWithSound( - if (it.isError) it.errorMessage else getString(R.string.Aparcado), - it.isError, - true - ) - } - - } - loadResponseAddItem.observe(viewLifecycleOwner) { event -> - event.getContentIfNotHandled().notNull { - updateScreen() - } - - } - - responsePrint.observe(viewLifecycleOwner) { - - if (!goBack) { - - if (it.isError) { - ma.messageWithSound( - it.errorMessage, isError = true, true - ) - } else { - (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( - PRINTERNAME - )).toast( - requireContext() - ) - } - } - - } - - responseConfirmReservedItemShelvingSale.observe(viewLifecycleOwner) { - - if (it.isError) { - ma.messageWithSound( - it.errorMessage, isError = true, true - ) - setTotalLines() - } else { - myGroupList[positionConfirm].isPicked = 1 - saleAdapter!!.notifyItemChanged(positionConfirm) - //lolass - lm!!.scrollToPositionWithOffset(storedBackPosition, 0) - // lm!!.scrollToPositionWithOffset(storedBackPosition + 1, 0) - - setTotalLines() - viewModel.collectionTicketGetSalix( - collection!!.collectionFk, print = false - ) - } - - } - - - responseItemShelvingSale.observe(viewLifecycleOwner) { - - myGroupList[positionConfirm].isPicked = 1 - myGroupList[positionConfirm].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection!!.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionConfirm, 0) - //saleAdapter!!.notifyDataSetChanged() - ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError - ) - } - loadUnpicked.observe(viewLifecycleOwner) { event -> - event.getContentIfNotHandled().notNull { - - myGroupList[positionUnmarked].isPicked = 1 - myGroupList[positionUnmarked].reservedQuantity = quantityConfirm - viewModel.collectionTicketGetSalix( - collection!!.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionUnmarked, 0) - //saleAdapter!!.notifyDataSetChanged() - ma.messageWithSound( - "Confirmada acción", it.isError, !it.isError - ) - } - } - responseItemShelvingSaleGroup.observe(viewLifecycleOwner) { - - viewModel.collectionTicketGetSalix( - collection!!.collectionFk, print = false - ) - lm!!.scrollToPositionWithOffset(positionMarkPrevia, 0) - - ma.messageWithSound( - getString(R.string.previousCollected), it.isError, !it.isError - ) - } - - responseCode.observe(viewLifecycleOwner) { - - if (!goBack2) { - if (it == null) { - showErrorMessage(text = getString(R.string.codeNotExist)) - if (mperror != null) mperror?.start() - } else { - if (checkItemScan(it.toString())) { - scanRequest() - customDialogList.dismiss() - mpok?.start() - markLine(storedPosition, quantityReserveToCheckItemScan, null) - } else { - customDialogList.setValueTwo("") - showErrorMessage(text = getString(R.string.lineNotExist)) - if (mperror != null) mperror?.start() - } - } - } - - goBack2 = false - - } - - } - } - - private fun createCollectionList() { - state = 0 - binding.mainToolbar.toolbarTitle.text = collection?.collectionFk.toString() - - collection!!.map(requireContext()) - val salesList: ArrayList = ArrayList() - - tickets = ArrayList() - var observations = "" - val myPickingFrom = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_FROM") - val myPickingTo = mobileApplication.dataStoreApp.readDataStoreKey("PICKING_TO") - collection!!.tickets.forEach { ticket -> - - if (observations.isNotEmpty()) observations = - observations + " " + ticket.observations - ticket.sales.forEach { sale -> - - if (hasPickingOrder) { - if (sale.pickingOrder != null && sale.pickingOrder in myPickingFrom..myPickingTo) { - salesList.add(sale) - } - } else { - salesList.add(sale) - } - - } - } - - sales = salesList.sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) - - //quitar comentarios FALTA AGRUPAR LAS PREVIAS - myGroupList = - salesList.sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) - // sales //sales porque no se ggrupan las previas hay que cambiar los estados. - - saleAdapter = SaleAdapterNew( - myGroupList, - pasillerosItemClickListener!!, - object : OnQuantityClickSaleListener { - - override fun onQuantityClick(sale: Sale) { - sales.forEachIndexed { index, saleVO -> - - if (saleVO.saleFk == sale.saleFk) { - if (sale.isPicked == 1) { - showErrorMessage( - title = getString(R.string.info), - text = getString(R.string.unmarkForModify) - ) - } - - } - } - - } - }, - object : OnSaleClickSaleListener { - override fun onSaleClick(sale: Sale) { - - val position = - myGroupList.indexOfFirst { it.itemShelvingSaleFk == sale.itemShelvingSaleFk } - if (position > -1) { - if (sale.isPicked == 1) { - unMarkLine(position, myGroupList[position]) - } else { - showScanner(position, sale) - } - } - - /* myGroupList.forEachIndexed { index, sale -> - //sales.forEachIndexed { index, sale -> - // println("Sacador la sale es ${sale.saleFk}") - // println("Sacador la sale picked es ${sale.isPicked}") - // println("Sacador la sale group es ${sale.saleGroupFk}") - // println("Sacador la sale reserved es ${sale.reservedQuantity}") - if (sale.itemShelvingSaleFk == 0) { - println("Sacador Que hacemos en este caso ?? ") - } else { - - - if (sale.itemShelvingSaleFk == mysale.itemShelvingSaleFk) { - println("Sacador **** itemShelvingSale es ${sale.itemShelvingSaleFk}") - println("Sacador **** isPicked es ${sale.isPicked}") - println("Sacador **** saleGroup es ${sale.saleGroupFk}") - //println("Sacador la sale es ${sale.saleFk}") - //println("Sacador la sale picked es ${sale.isPicked}") - //println("Sacador la sale group es ${sale.saleGroupFk}") - //println("Sacador la sale reserved es ${sale.reservedQuantity}") - //println("Sacador la sale dentro es ${sale.saleFk}") - if (sale.isPicked != 1 && sale.saleGroupFk == null) { - println("Sacador **** showScanner") - showScanner(index, sale) - } else { - println("Sacador **** desmarcar") - unMarkLine(index, myGroupList[index]) - } - - } - } - - }*/ - } - - }, - object : OnMistakeClickListener { - override fun onMistakeClickListener(sale: SaleVO) { - } - }, - object : OnPackingClickSaleListener { - override fun onPackingClick(sale: Sale) { - goBack = true - - if (!sale.code.isNullOrEmpty()) ma.onPasillerosItemClickListener( - PasillerosItemVO( - title = R.string.titleUbicator, - ), entryPoint = sale.code - ) - } - }, - object : OnTicketClickSaleListener { - override fun onTicketClickListener(sale: Sale) { - val entryPoint = Gson().toJson( - mutableMapOf( - "entryPoint" to sale.ticketFk, "web" to "${ - mobileApplication.dataStoreApp.readDataStoreKey( - BASEURLSALIX - ) - }/#!/ticket/${sale.ticketFk}/sale" - ) - ) - ma.onPasillerosItemClickListener( - PasillerosItemVO( - title = R.string.titleWebViewer, - ), entryPoint = entryPoint - ) - } - }, - type = type - ) - - - lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) - binding.fragmentSacadorCollections.adapter = saleAdapter - binding.fragmentSacadorCollections.layoutManager = lm - - setTotalLines() - setStoredPosition() - setScrollListener(lm!!) - printObservations(observations) - } - - private fun setScrollListener(lm: LinearLayoutManager) { - binding.fragmentSacadorCollections.clearOnScrollListeners() - binding.fragmentSacadorCollections.addOnScrollListener(object : - RecyclerView.OnScrollListener() { - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - storedBackPosition = lm.findFirstVisibleItemPosition() - super.onScrolled(recyclerView, dx, dy) - } - }) - } - - private fun printObservations(observations: String) { - if (observations.trim().isNotEmpty()) { - customDialog.setTitle(getString(R.string.observations)).setDescription(observations) - .setOkButton(getString(R.string.accept)) { - customDialog.hide() - customDialog.dismiss() - }.show() - } - } - - private fun findSale(txtscan: String) { - - var isFoundSale = false // markPrevia(txtscan) - - //Se busca la matricula en las lineas - for (indice in myGroupList.indices) { - if (myGroupList[indice].isPicked != 1 && myGroupList[indice].code != null && myGroupList[indice].code!!.uppercase() == txtscan.uppercase()) { - mpok!!.start() - isFoundSale = true - positionMarkPrevia = indice - printShelvingResult(indice) - break - } - } - - if (!isFoundSale) mperror!!.start() - - } - - private fun findSale(txtscan: String, position: Int, sale: Sale) { - - storedPosition = position - - if (sale.code!!.uppercase() == txtscan.uppercase()) { - mpok!!.start() - printShelvingResult(position) - //sale.isPicked = 1 - //saleAdapter!!.notifyItemChanged(position) - } else { - mperror!!.start() - } - - } - - private fun markLine(position: Int, quantity: Int, isItemShelvingSaleEmpty: Boolean?) { - - state = 0 - isScanned = null - positionConfirm = position - quantityConfirm = quantity - isMarking = true - - runBlocking { - var sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) - viewModel.itemShelvingSaleSetQuantity( - myGroupList[position].itemShelvingSaleFk, - quantity, - isItemShelvingSaleEmpty, - sectorFk = if (sectorFk == -1) null else sectorFk - ) - } - storedBackPosition = position/* var mySale = myGroupList[position].itemShelvingSaleFk - for (indice in myGroupList.indices) { - if (!myGroupList[indice].isParent && myGroupList[indice].itemShelvingSaleFk == mySale) { - storedBackPosition = indice - } - }*/ - - } - - private fun setListPosition() { - - if (storedPosition == 0 && storedBackPosition == 0) { // se inicia lista, se busca porqué item vamos. - for (indice in myGroupList.indices) { - if (myGroupList[indice].isPicked == 0) { - //storedPosition = indice - lm!!.scrollToPositionWithOffset(indice - 1, 0) - break - } - } - - } else { - lm!!.scrollToPositionWithOffset(storedBackPosition, 0) - } - } - - private fun unMarkLine(position: Int, sale: Sale) { - state = 0 - customDialog.setTitle(getString(R.string.unmarkLine)).setDescription( - getString(R.string.goUnmark) + sale.itemFk + getString( - R.string.sure - ) - ).setOkButton(getString(R.string.unmark)) { - if (!sale.isParent && sale.reservedQuantity == 0 && sale.originalQuantity != sale.saleQuantity) { - getString(R.string.unmarkError).toast(requireContext()) - } else {/* saleAdapter!!.notifyDataSetChanged() - var mySale = sale.saleFk - for (indice in myGroupList.indices) { - if (!myGroupList[indice].isParent && myGroupList[indice].saleFk == mySale) { - d("VERDNATURA::", "la pos del index de la sale es" + indice) - storedBackPosition = indice - } - }*/ - storedBackPosition = position - setListPosition() - - viewModel.itemShelvingSaleUnpicked(myGroupList[position].itemShelvingSaleFk) - sale.isPicked = 0 - positionUnmarked = position - setTotalLines() - scanRequest() - } - - - customDialog.dismiss() - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialog.dismiss() - }.show() - - } - - //SHELVINGS - - private fun printShelvingResult(pos: Int) { - storedPosition = pos - customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_TEXT - customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) - customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) - customDialogList.getEditTextTwo().requestFocus() - val shelving = myGroupList[pos].code - val item = myGroupList[pos].itemFk - val longName = myGroupList[pos].longName - val totalReserved = myGroupList[pos].reservedQuantity - val itemShelvingFk = myGroupList[pos].itemShelvingSaleFk - - try { - customDialogList.setTitle("$shelving($item) $totalReserved de $longName").setOkButton( - getString( - R.string.take - ) - ) { - customDialogTakeAction(pos, itemShelvingFk, totalReserved, false) - - }.setKoButton(getString(R.string.close)) { - requireActivity().hideKeyboard(customDialogList.getEditTextTwo()) - customDialogList.dismiss() - scanRequest() - - }.setHintValue(getString(R.string.quantitySelect)).setValue(totalReserved.toString()) - .setHintValueTwo(getString(R.string.scanItem)).setValueTwo("").show() - - customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - - customDialogTakeAction( - pos, - itemShelvingFk, - totalReserved, - event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER - ) - - return@setOnEditorActionListener true - - } - false - } - } catch (e: Exception) { - ma.messageWithSound(e.message.toString(), isError = true, true) - } - } - - private fun customDialogTakeAction( - position: Int, itemShelvingFk: Int, totalReserved: Int, isItemScanned: Boolean? - ) { - goBack = false - isScanned = isItemScanned - if (customDialogList.getValueTwo().isNotEmpty()) { - - customDialogList.setValueTwo( - itemScanValue( - customDialogList.getValueTwo(), arrayOf("buy"), "more" - ).toString() - ) - val quantityToReserve = customDialogList.getValue().toInt() - - if (quantityToReserve < totalReserved) { - - if (customDialogList.getValueTwo() in sales[position].Barcodes || customDialogList.getValueTwo() == sales[position].itemFk.toString()) { - customDialogList.dismiss() - showQuestionUbicationEmpty(position, quantityToReserve) - } else { - ma.messageWithSound( - message = getString(R.string.errorItem), - isError = true, - isPlayed = true, - isToasted = false - ) - } - } - - if (quantityToReserve > totalReserved) { - ma.hideKeyboard(customDialogList.getEditTextTwo()) - getString(R.string.quantityHigh).toast(requireContext()) - } - if (quantityToReserve == totalReserved) { - originalItemScan = customDialogList.getValueTwo().toLong() - if (checkItemScan(customDialogList.getValueTwo())) { - - markLine(storedPosition, quantityToReserve, null) - - mpok?.start() - ma.hideKeyboard(customDialogList.getEditTextTwo()) - customDialogList.dismiss() - scanRequest() - - } else { - - itemShelvingFkStored = itemShelvingFk - - quantityReserveToCheckItemScan = quantityToReserve - viewModel.getIdFromCodeSalix( - code = customDialogList.getValueTwo(), - ) - customDialogList.dismiss() - } - } - - } else { - getString(R.string.scanItemValidate).toast(requireContext()) - } - } - - private fun setStoredPosition() { - setListPosition()/*if (goBack) setListPosition(storedBackPosition, isFromBack) else { - setListPosition(storedPosition, isFromBack)*/ - } - - private fun checkItemScan(valueToCheck: String): Boolean { - - val saleToCheck = myGroupList[storedPosition] - if (saleToCheck.itemFk.toString() == valueToCheck) return true - else { - saleToCheck.Barcodes.forEach { barcode -> - if (barcode == valueToCheck) return true - } - } - - return false - } - - private fun showQuestionUbicationEmpty(position: Int, quantity: Int = 0) { - - customDialogThreeButtonsQuantity.setTitle( - getString( - R.string.changeQuantity, quantity, sales[position].itemFk - ) - ).setDescription(getString(R.string.questionItemShelving, sales[position].itemFk)) - .setValue("").setCustomDialogValue(View.GONE) - customDialogThreeButtonsQuantity.setOkButtonAdd(text = getString(R.string.yes)) { - scanRequest() - customDialogThreeButtonsQuantity.dismiss() - getString(R.string.errorQuantityShelving).toast(requireContext()) - customDialogThreeButtonsQuantity.dismiss() - showQuestionUbicationEmpty(position, quantity) - }.setOkButtonTwo("NO") { - scanRequest() - customDialogThreeButtonsQuantity.dismiss() - if (quantity == 0) { - viewModel.itemShelvingSaleExists( - myGroupList[position].itemShelvingSaleFk, position, quantity - ) - } else { - markLine(position, quantity, true) - } - }.setKoButton(getString(R.string.cancel)) { - scanRequest() - customDialogThreeButtonsQuantity.dismiss() - }.show() - customDialogThreeButtons.setFocusDialogValue() - } - - //OPTIONS - private fun print() { - - if (ma.havePrinter() && ma.haveSector()) { - showDialogLabelCount() - - } else { - ma.messageWithSound( - getString(R.string.printerFault), - isError = true, - true, - getString(R.string.printError), - false - ) - - } - - } - - private fun addItem() { - listPlacementSupply = ArrayList() - collection!!.tickets.forEach { - listPlacementSupply.add(BarcodeVO(code = it.ticketFk.toString())) - } - if (listPlacementSupply.size == 1) { - ticketSelected = listPlacementSupply[0].code!!.toInt() - } - customDialogList.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_NUMBER - customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) - customDialogList.setTitle(getString(R.string.Agregarartículoparaticket) + " " + ticketSelected) - .setOkButton(getString(R.string.Agregar)) { - customDialogAddItem() - }.setKoButton(getString(R.string.close)) { - scanRequest() - customDialogList.dismiss() - }.setHintValue(getString(R.string.Artículo)).setValue("") - .setHintValueTwo(getString(R.string.Cantidad)).setValueTwo("").show() - customDialogList.getEditText().requestFocus() - requireActivity().hideKeyboard() - - customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - if (customDialogList.getValue().isNotEmpty()) { - try { - customDialogList.setValue( - itemScanValue( - customDialogList.getValue(), arrayOf("buy"), "more" - ).toString() - ) - - } catch (e: Exception) { - ma.messageWithSound(e.message.toString(), isError = true, true) - } - customDialogList.getEditTextTwo().requestFocus() - } - - return@setOnEditorActionListener true - - } - false - - } - - - customDialogList.getEditTextTwo().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - customDialogAddItem() - return@setOnEditorActionListener true - - } - false - } - - placementSupplyAdapter = - BarcodeAdapter(listPlacementSupply, object : OnBarcodeRowClickListener { - override fun onBarcodeRowClickListener(item: BarcodeVO) { - customDialogInput.setTitle(getString(R.string.ArtículoparaTicket) + " " + item.code!!) - ticketSelected = item.code!!.toInt() - customDialogList.setTitle(getString(R.string.Agregarartículoparaticket) + " " + ticketSelected) - } - }, showDelete = false) - - customDialogList.getRecyclerView().adapter = placementSupplyAdapter - - customDialogList.getRecyclerView().layoutManager = - LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) - - } - - private fun customDialogAddItem() { - - if (customDialogList.getValueTwo().isNotEmpty()) { - if (ticketSelected == 0) { - getString(R.string.Seleccionaunticketdelaista).toast(requireContext()) - } else if (customDialogList.getValue().isEmpty() || customDialogList.getValueTwo() - .isEmpty() - ) { - getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) - } else { - val saleGroupSelected = - collection!!.tickets.find { it.ticketFk == ticketSelected }?.sales?.get(0)?.saleGroupFk - ?: 0 - - runBlocking { - viewModel.collectionAddWithReservation( - customDialogList.getValue().toInt(), - customDialogList.getValueTwo().toInt(), - ticketSelected, - saleGroupFk = saleGroupSelected, - sectorFk = mobileApplication.dataStoreApp.readDataStoreKey( - SECTORFK - ) - ) - } - - customDialogList.dismiss() - hideKeyboards() - scanRequest() - } - } else { - getString(R.string.scanItem).toast(requireContext()) - } - - } - - private fun toastDisponibility(item: ItemVO) { - if (item.available.isEmpty()) { - item.available = "0" - } - customDialog.setTitle(getString(R.string.itemPoints) + item.id) - .setDescription(getString(R.string.available) + ":" + item.available) - .setOkButton(getString(R.string.accept)) { - scanRequest() - customDialog.dismiss() - }.show() - - } - - private fun setTotalLines() { - - val totalMark = sales.count { it.isPicked == 1 } - - binding.mainToolbar.toolbarTitle.text = - if (collection!!.collectionFk != 0) collection!!.collectionFk.toString() else "" - - - binding.mainToolbar.toolbarSubtitle.text = - getString(R.string.totalsPicker, totalMark, sales.size) - - if (totalMark == sales.size) { - getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) - changeTicketState() - } - } - - private fun changeTicketState() { - - viewModel.saleTrackingAddPrevOK(collection!!.collectionFk) - } - - private fun showScanner(index: Int, sale: Sale) { - customDialogInput.getEditText().inputType = InputType.TYPE_CLASS_TEXT - customDialogInput.setTitle("" + sale.itemFk) - .setDescription(getString(R.string.scanWagonForItem)) - .setOkButton(getString(R.string.accept)) { - findSaleAction(index, sale) - }.setKoButton(getString(R.string.cancel)) { - closeCustomDialog(binding.scanInput, customDialogInput) - }.setValue("").show() - - - customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { - findSaleAction(index, sale) - return@setOnEditorActionListener false - } - false - } - customDialogInput.getEditText().requestFocus() - } - - private fun findSaleAction(index: Int, sale: Sale) { - if (customDialogInput.getValue().isNotEmpty()) { - findSale(customDialogInput.getValue(), index, sale) - } - closeCustomDialog(binding.scanInput, customDialogInput) - } - - private fun closeCustomDialog(scanInput: EditText, customDialogInput: CustomDialogInput) { - requireContext().hideKeyboard(customDialogInput.getEditText()) - scanInput.requestFocus() - customDialogInput.dismiss() - scanInput.requestFocus() - - } - - private fun showErrorMessage(title: String = getString(R.string.errorMarkLine), text: String) { - customDialog.setTitle(title).setDescription(text).setKoButton(getString(R.string.close)) { - customDialog.dismiss() - }.show() - } - - private fun showDialogLabelCount() { - var isTicket = false - for (t in collection!!.tickets) { - if (t.ticketFk == (collection!!.collectionFk)) { - isTicket = true - } - } - if (isTicket) { - val builder = AlertDialog.Builder(context) - builder.setTitle(getString(R.string.selectLabeltoPrint)) - val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") - builder.setItems(labelCount) { dialog, which -> - viewModel.collectionStickerPrint( - collectionFk = collection!!.collectionFk, labelCount = (which + 1) - ) - (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( - PRINTERNAME - )).toast(requireContext()) - - } - val dialog = builder.create() - dialog.show() - } else { - viewModel.collectionStickerPrint( - collectionFk = collection!!.collectionFk, null - ) - - } - - } - -} - - 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 a45e1270..02fe38e6 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 @@ -44,14 +44,13 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val collectionTicketList: LiveData get() = _collectionTicketList - private val _responseCollectionId by lazy { MutableLiveData() } - val responseCollectionId: LiveData - get() = _responseCollectionId - private val _responseExistsItemShelvingSale by lazy { MutableLiveData() } val responseExistsItemShelvingSale: LiveData get() = _responseExistsItemShelvingSale + val loadExistsResponse: LiveData> = + _responseExistsItemShelvingSale.map { Event(it) } + private val _collectionTicketSalix by lazy { MutableLiveData() } val collectionTicketSalix: LiveData get() = _collectionTicketSalix @@ -63,10 +62,6 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val loadCollectionTicketSalix: LiveData> = _collectionTicketSalix.map { Event(it) } - private val _collectionTicketListLocal by lazy { MutableLiveData() } - val collectionTicketListLocal: LiveData - get() = _collectionTicketListLocal - private val _placementSuppleyList by lazy { MutableLiveData() } val placementSuppleyList: LiveData get() = _placementSuppleyList @@ -91,29 +86,27 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseSaleTracking_mark: LiveData get() = _responseSaleTracking_mark - private val _responseConfirmReservedItemShelvingSale by lazy { MutableLiveData() } - val responseConfirmReservedItemShelvingSale: LiveData + private val _responseConfirmReservedItemShelvingSale by lazy { MutableLiveData() } + val responseConfirmReservedItemShelvingSale: LiveData get() = _responseConfirmReservedItemShelvingSale + val loadPicked: LiveData> = + _responseConfirmReservedItemShelvingSale.map { Event(it) } + private val _responseItemShelvingSale by lazy { MutableLiveData() } val responseItemShelvingSale: LiveData get() = _responseItemShelvingSale - private val _responseItemShelvingSaleUnPicked by lazy { MutableLiveData() } - val responseItemShelvingSaleUnPicked: LiveData + private val _responseItemShelvingSaleUnPicked by lazy { MutableLiveData() } + val responseItemShelvingSaleUnPicked: LiveData get() = _responseItemShelvingSaleUnPicked - val loadUnpicked: LiveData> = - _responseItemShelvingSaleUnPicked.map { Event(it) } + val loadUnpicked: LiveData> = _responseItemShelvingSaleUnPicked.map { Event(it) } - private val _responseCollectionAddItem by lazy { MutableLiveData() } - val responseCollectionAddItem: LiveData + private val _responseCollectionAddItem by lazy { MutableLiveData() } + val responseCollectionAddItem: LiveData get() = _responseCollectionAddItem - private val _responseConfirmReservedUpdate by lazy { MutableLiveData() } - val responseConfirmReservedUpdate: LiveData - get() = _responseConfirmReservedUpdate - private val _responseParking by lazy { MutableLiveData() } val responseParking: LiveData get() = _responseParking @@ -145,10 +138,6 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseItemShelvingSaleGroup: LiveData get() = _responseItemShelvingSaleGroup - private val _responsecheckfully by lazy { MutableLiveData() } - val responsecheckfully: LiveData - get() = _responsecheckfully - private val _responseTicketClosure by lazy { MutableLiveData() } val responseTicketClosure: LiveData get() = _responseTicketClosure @@ -157,10 +146,6 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseCollectionUnchecked: LiveData get() = _responseCollectionUnchecked - /* private val _responseMissingTrash by lazy { MutableLiveData() } - val responseMissingTrash: LiveData - get() = _responseMissingTrash*/ - private val _responseSplit by lazy { MutableLiveData() } val responseSplit: LiveData get() = _responseSplit @@ -187,7 +172,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val loadResponseDel: LiveData> = _responseDel.map { Event(it) } - val loadResponseAddItem: LiveData> = + val loadResponseAddItem: LiveData> = _responseCollectionAddItem.map { Event(it) } val loadResponseSaleTrackingMark: LiveData> = @@ -394,28 +379,14 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ) { salix.itemShelvingSaleSetquantitySalix( params = arrayListOf(itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty, sectorFk) - //salix.itemShelvingSaleSetQuantity( - // params = ItemShelvingSaleSalix(itemShelvingSaleFk, quantity, isItemShelvingSaleEmpty) ).enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _responseConfirmReservedItemShelvingSale.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } override fun onSuccess(response: Response) { - if (!response.isSuccessful) { - _responseConfirmReservedItemShelvingSale.value = ResponseItemVO( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), response.message() - ) - ) - } else { - _responseConfirmReservedItemShelvingSale.value = - ResponseItemVO(isError = false, response = "") + _responseConfirmReservedItemShelvingSale.value = true + + if (isItemShelvingSaleEmpty == true) + _responseCollectionAddItem.value = true - } } }) } @@ -429,44 +400,9 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ) ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _responseCollectionAddItem.value = ResponseItemVO(isError = false, response = "") + _responseCollectionAddItem.value = true } - /* override fun onError(t: Throwable) { - _responseCollectionAddItem.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - }*/ - - }) - } - - fun confirmItemShelvingReservedUpdate( - itemShelvingSaleFk: Int, isPicked: Boolean - ) { - salix.itemShelvingsReservedUpdate( - id = itemShelvingSaleFk, params = hashMapOf("isPicked" to isPicked) - ).enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _responseConfirmReservedUpdate.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } - - override fun onSuccess(response: Response) { - if (!response.isSuccessful) { - _responseConfirmReservedUpdate.value = ResponseItemVO( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), response.message() - ) - ) - } else { - _responseConfirmReservedUpdate.value = - ResponseItemVO(isError = false, response = "") - } - } }) } @@ -562,15 +498,10 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { itemShelvingSaleFk ) ).enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _responseItemShelvingSaleUnPicked.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } override fun onSuccess(response: Response) { - _responseItemShelvingSaleUnPicked.value = ResponseItemVO(isError = false) + _responseItemShelvingSaleUnPicked.value = true + super.onSuccess(response) } }) } @@ -602,13 +533,11 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { saleGroupFk: Number ) { salix.saleGroupUpdate( - id = saleGroupFk, - params = hashMapOf("parkingFk" to null) - ) - .enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - } - }) + id = saleGroupFk, params = hashMapOf("parkingFk" to null) + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + } + }) } fun itemShelvingSaleSetSaleGroup( @@ -671,20 +600,19 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { SaleTrackingDelSalix( saleFk = saleFk, stateCodes = listOf("CHECKED", "OK", "PREPARED") ) - ) - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _responseDel.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) - } + ).enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + _responseDel.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } - override fun onSuccess(response: Response) { - _responseDel.value = - ResponseItemVO(isError = false, response = response.message()) - } - }) + override fun onSuccess(response: Response) { + _responseDel.value = + ResponseItemVO(isError = false, response = response.message()) + } + }) } fun itemShelvingUpdateFromSale( @@ -746,13 +674,12 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun getIdFromCodeSalix(code: String) { - getItemFromBarcodeUseCase.execute(code) - .enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _responseCode.value = response.body() + getItemFromBarcodeUseCase.execute(code).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseCode.value = response.body() - } - }) + } + }) } fun collectionIncreaseQuantitySalix( @@ -785,9 +712,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { salix.saleMistakeAdd( SaleMistakeSalix( - userFk = (context as MobileApplication).userId!!, - saleFk = saleFk, - typeFk = typeFk + userFk = (context as MobileApplication).userId!!, saleFk = saleFk, typeFk = typeFk ) ).enqueue(object : SalixCallback(context) { override fun onError(t: Throwable) { @@ -807,25 +732,23 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun mistakeType() { - salix.getMistakeTypes() - .enqueue(object : SalixCallback>(context) { - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _mistakeList.value = - response.body()?.let { MistakeTypeListVO(it) } - } else { - val listError: ArrayList = ArrayList() - listError.add(MistakeTypeVO(0, "")) - _mistakeList.value = MistakeTypeListVO(listError) - } - } - - override fun onError(t: Throwable) { + salix.getMistakeTypes().enqueue(object : SalixCallback>(context) { + override fun onSuccess(response: Response>) { + if (response.body() != null) { + _mistakeList.value = response.body()?.let { MistakeTypeListVO(it) } + } else { val listError: ArrayList = ArrayList() listError.add(MistakeTypeVO(0, "")) _mistakeList.value = MistakeTypeListVO(listError) } - }) + } + + override fun onError(t: Throwable) { + val listError: ArrayList = ArrayList() + listError.add(MistakeTypeVO(0, "")) + _mistakeList.value = MistakeTypeListVO(listError) + } + }) } fun ticketIsOutClosureZone( @@ -885,9 +808,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { _responseTicketClosure.value = ResponseItemVO( - isError = false, - response = response.body()!!.toString(), - errorMessage = "" + isError = false, response = response.body()!!.toString(), errorMessage = "" ) } @@ -913,9 +834,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { if (response.body() != null) { _responseCollectionUnchecked.value = ResponseItemVO( - isError = false, - response = response.body()!!, - errorMessage = "" + isError = false, response = response.body()!!, errorMessage = "" ) } else { _responseCollectionUnchecked.value = ResponseItemVO( 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 77ad4f90..9760681a 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 @@ -22,7 +22,6 @@ import es.verdnatura.R import es.verdnatura.databinding.ActivityMainBinding import es.verdnatura.domain.ConstAndValues.MAINACTIVITY import es.verdnatura.domain.ConstAndValues.MENUBYDEFAULTSELECTED -import es.verdnatura.domain.ConstAndValues.PRECHECKERNEW import es.verdnatura.domain.ConstAndValues.PREITEMPICKER import es.verdnatura.domain.ConstAndValues.PRINTERFK import es.verdnatura.domain.ConstAndValues.PRINTERFKDEFAULT @@ -67,7 +66,6 @@ import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFra import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPickerNew import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPickerPreviousNew import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPreChecker -import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPreCheckerNew import es.verdnatura.presentation.view.feature.collection.fragment.CollectionShowTicketFragment import es.verdnatura.presentation.view.feature.controlador.fragment.ControladorFragment import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoFragment @@ -513,8 +511,9 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL } getString(R.string.historicals) -> { + addFragmentOnTop( - PasilleroFragment.newInstance(itemTitle, isInitMenu = false), + PasilleroFragment.newInstance(itemTitle, isInitMenu = false) ) } @@ -658,7 +657,12 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL //Tarea 7855 getString(R.string.scanPreparedExpedition) -> { - addFragmentOnTop(ExpeditionPreparedStateFragment.newInstance()) + addFragmentOnTop( + ExpeditionPreparedStateFragment.newInstance( + "PREPARED", + getString(R.string.scanExpeditions) + ) + ) } getString(R.string.titleAuto) -> { @@ -674,8 +678,8 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL }*/ getString(R.string.titlePickers) -> { - //addFragmentOnTop(SacadorFragment.newInstance()) - addFragmentOnTop(ControlVehiculoFragment.newInstance("")) + addFragmentOnTop(SacadorFragment.newInstance("PREPARED")) + //addFragmentOnTop(ControlVehiculoFragment.newInstance("")) } "Sacador Test" -> { @@ -721,15 +725,6 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL addFragmentOnTop(PreControladorFragment.newInstance()) } - getString(R.string.titlePreControlTest) -> { - addFragmentOnTop( - CollectionFragmentPreCheckerNew.newInstance( - null, - type = PRECHECKERNEW - ) - ) - } - getString(R.string.titleShelvingHistorical) -> { addFragmentOnTop(ItemShelvingLogFragment.newInstance(itemTitle)) @@ -900,6 +895,12 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.reviewBoxPicking) -> { addFragmentOnTop(BoxPickingFragment.newInstance(itemTitle)) + /* addFragmentOnTop( + ExpeditionPreparedStateFragment.newInstance( + "CHECKED", + getString(item.title) + ) + )*/ } getString(R.string.pickerHelper) -> { diff --git a/app/src/main/res/layout/ticket_toast_layout.xml b/app/src/main/res/layout/ticket_toast_layout.xml new file mode 100644 index 00000000..c9f2715e --- /dev/null +++ b/app/src/main/res/layout/ticket_toast_layout.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file From c4bbffc98f1f1a157fcd4490c4d642edc2479c09 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Wed, 2 Oct 2024 10:55:21 +0200 Subject: [PATCH 09/27] feat: boxPicking refs #7855 --- .../fragment/ExpeditionPreparedStateFragment.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt index 12bac0ec..e647c0ce 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPreparedStateFragment.kt @@ -1,5 +1,7 @@ package es.verdnatura.presentation.view.feature.paletizador.fragment +import android.content.pm.ActivityInfo +import android.os.Bundle import android.view.KeyEvent import android.view.View import android.view.inputmethod.EditorInfo @@ -15,7 +17,7 @@ import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewM import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter @Suppress("UNUSED_ANONYMOUS_PARAMETER") -class ExpeditionPreparedStateFragment(var codeState: String, var title: String) : +class ExpeditionPreparedStateFragment(var codeState: String = "PREPARED", var title: String = "") : BaseFragment( DeliveryViewModel::class ) { @@ -29,9 +31,20 @@ class ExpeditionPreparedStateFragment(var codeState: String, var title: String) companion object { fun newInstance(codeState: String, title: String) = ExpeditionPreparedStateFragment(codeState = codeState, title = title) + + fun newInstance() = ExpeditionPreparedStateFragment() } override fun getLayoutId(): Int = R.layout.fragment_automatic_add_expedition + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + } + + override fun onDestroyView() { + super.onDestroyView() + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } override fun init() { ma.hideBottomNavigation(View.GONE) From aa04349845358f3ffc14616b6155521a30f2b08e Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 8 Oct 2024 08:20:48 +0200 Subject: [PATCH 10/27] feat: refs #8085 restaurant --- .../pasillero/fragment/PasilleroViewModel.kt | 39 +++-- .../feature/restaurant/RestaurantActivity.kt | 61 +++++++ app/src/main/res/drawable/ic_restaurant.xml | 10 ++ .../res/layout/activity_restaurant_view.xml | 151 ++++++++++++++++++ 4 files changed, 251 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/restaurant/RestaurantActivity.kt create mode 100644 app/src/main/res/drawable/ic_restaurant.xml create mode 100644 app/src/main/res/layout/activity_restaurant_view.xml 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 fb9eed9a..2db81abc 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 @@ -264,23 +264,22 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) ) - //val working_in_testMenu = false - if (userId == 19591) { + if (userId == 19591 || isOnReservationMode) { _pasillerositem.add( PasillerosItemVO( R.drawable.ic_picker_ui, R.string.sacador_test, R.string.sacador_test ) ) - if (userId == 19591) { - _pasillerositem.add( - PasillerosItemVO( - R.drawable.ic_picker_helper, - R.string.pickerHelper, - R.string.pickerHelperDescrip - ) + } + if (userId == 19591) { + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_picker_helper, + R.string.pickerHelper, + R.string.pickerHelperDescrip ) - } + ) } _pasillerositem.add( @@ -423,6 +422,17 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) ) + /* Para preControl de reservas, faltan cosas no se puede todavía. + if (userId == 19591) { + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_previous_precontrol, R.string.preControlNew, + + R.string.preControlNew + ) + ) + }*/ + _pasillerositem.add( PasillerosItemVO( R.drawable.ic_ticket, R.string.titleShowTicket, R.string.titleShowTicketDescrip @@ -441,6 +451,7 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { ) ) + _pasillerositem.add( PasillerosItemVO( R.drawable.ic_review_boxpicking, @@ -470,6 +481,14 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { fun inititializeDefaultOther() { + _pasillerositem.add( + PasillerosItemVO( + R.drawable.ic_restaurant, + R.string.titleRestaurant, + R.string.resturantDescrip + ) + ) + _pasillerositem.add( PasillerosItemVO( R.drawable.ic_packaging, R.string.titlePackingHolland, R.string.titleUbicatorDescrip diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/restaurant/RestaurantActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/restaurant/RestaurantActivity.kt new file mode 100644 index 00000000..3e95ea3e --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/restaurant/RestaurantActivity.kt @@ -0,0 +1,61 @@ +package es.verdnatura.presentation.view.feature.restaurant + +import android.view.View +import android.widget.Button +import com.google.gson.Gson +import com.google.zxing.BarcodeFormat +import com.journeyapps.barcodescanner.BarcodeEncoder +import es.verdnatura.R +import es.verdnatura.databinding.ActivityRestaurantViewBinding +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseActivity +import es.verdnatura.presentation.view.feature.restaurant.model.UserMenu + +class RestaurantActivity : BaseActivity() { + + override fun getLayoutId(): Int = R.layout.activity_restaurant_view + + override fun init() { + binding.mainToolbar.toolbarTitle.text = getString(R.string.selectMenu) + /* try { + binding.imgView.loadUrl(intent.getStringExtra(getString(R.string.url))!!) + } catch (ex: Exception) { + getString(R.string.errorImage).toast(this) + finish() + }*/ + + binding.mainToolbar.backButton.setOnClickListener { + finish() + } + } + + fun generateQr(view: View) { + binding.imageQr.visibility = View.VISIBLE + binding.txtOption.visibility = View.VISIBLE + binding.txtOption.text = (view as Button).text.toString() + val userMenu = UserMenu( + user = mobileApplication.userId!!, + menu_id = view.tag.toString().toInt(), + menu = view.text.toString(), + name = mobileApplication.userName!! + ) + try { + val barcodeEncoder = BarcodeEncoder() + val bitmap = barcodeEncoder.encodeBitmap( + Gson().toJson(userMenu), + BarcodeFormat.QR_CODE, + 400, + 400 + ) + val imageViewQrCode = binding.imageQr + imageViewQrCode.setImageBitmap(bitmap) + } catch (e: Exception) { + e.toString().toast(this) + } + + } + + private fun showQr() { + + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_restaurant.xml b/app/src/main/res/drawable/ic_restaurant.xml new file mode 100644 index 00000000..b6a55b6c --- /dev/null +++ b/app/src/main/res/drawable/ic_restaurant.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_restaurant_view.xml b/app/src/main/res/layout/activity_restaurant_view.xml new file mode 100644 index 00000000..dd031854 --- /dev/null +++ b/app/src/main/res/layout/activity_restaurant_view.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + +