diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index 67ca5ea6..dd0466c8 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -2,6 +2,7 @@ package es.verdnatura.domain import com.google.gson.JsonObject import es.verdnatura.presentation.common.ItemBarCodeSalix +import es.verdnatura.presentation.common.TicketState import es.verdnatura.presentation.common.packingSiteSalix import es.verdnatura.presentation.view.feature.ajustes.model.Printers import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO @@ -445,7 +446,13 @@ interface SalixService { fun ticketIsOutClosureZone( @Query("params") params: Any, @Query("schema") schema: String = "vn" - ): Call + ): Call + + @GET("TicketStates") + fun ticketState( + @Query("filter") filter: Any, + @Query("schema") schema: String = "vn" + ): Call> @POST("Applications/workerMachinery_isRegistered/execute-func") fun workerMachineryIsRegistered( diff --git a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt index 53914aca..6d47bb52 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt @@ -4,6 +4,7 @@ class ItemBarCodeSalix( var itemFk: Int, var code: String ) + data class SaleTrackingReplaceSalix( var saleFk: Int, var originalQuantity: Int, @@ -12,6 +13,7 @@ data class SaleTrackingReplaceSalix( var buyFk: Long, var isScanned: Boolean, ) + data class SaleTrackingSalix( var saleFk: Int, var originalQuantity: Int, @@ -62,3 +64,14 @@ data class CollectionItemSalix( var warehouseFk: Int ) + +data class TicketState( + val ticketFk: Int = 0, + val code: String = "", + val user: UserSalix = UserSalix() +) { + data class UserSalix( + val id: Int = 0, + val username: String = "" + ) +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt index 76fde6cf..58fb7267 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragment.kt @@ -140,6 +140,8 @@ class CollectionFragment( collection.collectionFk ) + //tarea 6458 + //viewModel.ticketState(collection.collectionFk) workerFkFromTicket = collection.tickets.get(0).sales.get(0).workerFk } @@ -644,22 +646,27 @@ class CollectionFragment( goBack2 = false }) + responseTicketState.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = GONE + if (!goBack) { + if ((it.code == "ON_CHECKING" || it.code == "CHECKED") && it.user.id != mobileApplication.userId) { + var customDialogWarningChecking = CustomDialog(requireContext()) + customDialogWarningChecking.setTitle(getString(R.string.info)) + customDialogWarningChecking.setDescription( + if (it.code == "ON_CHECKING") { + getString(R.string.checkingByUser, it.user.username) + } else { + getString(R.string.checkedByUser, it.user.username) + } + ) + .setOkButton(getString(R.string.aware)) { + customDialogWarningChecking.dismiss() + }.show() + } + } - /* responseMissingTrash.observe(viewLifecycleOwner, Observer { + } - if (!goBack) { - if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, true) - - } else { - - missingTrashSuccesful() - - } - } - - })*/ - //Tarea 4280 responseTicketClosure.observe(viewLifecycleOwner, Observer { binding.splashProgress.visibility = GONE if (!goBack) { @@ -1255,11 +1262,12 @@ class CollectionFragment( } if (type.equals(CONTROLADOR)) { - //Tarea #4280 cambiar a ticket_isOutClosureZone viewModel.ticketIsOutClosureZone( txtscan.toInt() - ) + //Tarea 6458 + //viewModel.ticketState(txtscan.toInt()) + } } @@ -2147,8 +2155,6 @@ class CollectionFragment( } - - //FALTAS / BASURA / SPLIT private fun showQuantityDialog(position: Int) { 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 385d7739..ff674a75 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 @@ -13,6 +13,7 @@ import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.ResponseItemVO +import es.verdnatura.presentation.common.TicketState import es.verdnatura.presentation.view.feature.collection.ItemVO import es.verdnatura.presentation.view.feature.collection.SalesModifiedList import es.verdnatura.presentation.view.feature.collection.SalixSaleQuantity @@ -110,9 +111,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseItemShelvingUpdate: LiveData get() = _responseItemShelvingUpdate - /* private val _responseSaleMove by lazy { MutableLiveData() } - val responseSaleMove: LiveData - get() = _responseSaleMove*/ + private val _responseTicketState by lazy { MutableLiveData() } + val responseTicketState: LiveData = _responseTicketState private val _responseUsedShelves by lazy { MutableLiveData() } val responseUsedShelves: LiveData @@ -922,11 +922,11 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { salix.ticketIsOutClosureZone( arrayListOf(ticketFk) ).enqueue(object : - SalixCallback(context) { - override fun onSuccess(response: Response) { + SalixCallback(context) { + override fun onSuccess(response: Response) { _responseTicketClosure.value = ResponseItemVO( isError = false, - response = response.body()!!.toString(), + response = response.body()?.toString() ?: "false", errorMessage = "" ) } @@ -940,28 +940,22 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { }) } - fun ticket_isOutClosureZoneNew( + fun ticketState( ticketFk: Int ) { - salix.ticketIsOutClosureZone( - params = arrayListOf(ticketFk) + salix.ticketState( + """{"where": {"ticketFk": "$ticketFk"},"include":[{"relation":"user","scope":{"fields":["username"]}}]}""" + ).enqueue(object : - SalixCallback(context) { - override fun onError(t: Throwable) { - _responseTicketClosure.value = ResponseItemVO( - isError = true, - errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) - ) + SalixCallback>(context) { + override fun onSuccess(response: Response>) { + _responseTicketState.value = if (response.body()!!.isEmpty()) { + TicketState() + } else { + response.body()!![0] + } } - override fun onSuccess(response: Response) { - _responseTicketClosure.value = ResponseItemVO( - isError = false, - response = response.body()!!.toString(), - errorMessage = "" - ) - - } }) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt index 9c706182..3754b405 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt @@ -8,9 +8,10 @@ import androidx.lifecycle.Observer import es.verdnatura.R import es.verdnatura.databinding.FragmentGeneralBlackBinding import es.verdnatura.domain.ConstAndValues -import es.verdnatura.domain.ConstAndValues.SECTORFK import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnCollectionSelectedListener +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionViewModel import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO @Suppress("UNUSED_ANONYMOUS_PARAMETER") @@ -19,6 +20,7 @@ class ControladorFragment : private var goBack: Boolean = false private var onCollectionSelectedListener: OnCollectionSelectedListener? = null + private var collectionViewModel: CollectionViewModel? = null override fun getLayoutId(): Int = R.layout.fragment_general_black companion object { @@ -34,7 +36,6 @@ class ControladorFragment : binding.splashProgress.visibility = View.GONE binding.scanInput.visibility = VISIBLE - binding.mainToolbar.toolbarTitle.text = getString(R.string.controlticket) setEvents() ma.hideBottomNavigation(VISIBLE) @@ -47,6 +48,7 @@ class ControladorFragment : } private fun setEvents() { + binding.mainToolbar.backButton.setOnClickListener { requireActivity().onBackPressed() } @@ -57,21 +59,51 @@ class ControladorFragment : goBack = false if (!binding.scanInput.text.isNullOrEmpty()) { binding.splashProgress.visibility = VISIBLE - - //sergio: para ver si ha marcado dos veces el mismo ticket. El laser falla binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString())) - - viewModel.collectionTicketGet( - sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK), - collectionFk = binding.scanInput.text.toString().toInt(), - print = "0", - type = ConstAndValues.CONTROLADOR - ) + //Tarea 6458 + collectionViewModel = CollectionViewModel(mobileApplication) + collectionViewModel!!.ticketState(binding.scanInput.text.toString().toInt()) + collectionViewModel!!.responseTicketState.observe(viewLifecycleOwner, Observer { it -> + binding.splashProgress.visibility = View.GONE + if ((it.code == "ON_CHECKING" || it.code == "CHECKED") && it.user.id != mobileApplication.userId) { + var customDialogWarning = CustomDialog(requireContext()) + customDialogWarning.setTitle(getString(R.string.info)) + customDialogWarning.setDescription( + if (it.code == "ON_CHECKING") { + getString(R.string.checkingByUser, it.user.username) + } else { + getString(R.string.checkedByUser, it.user.username) + } + ) + .setOkButton(getString(R.string.aware)) { + customDialogWarning.dismiss() + binding.splashProgress.visibility= VISIBLE + viewModel.collectionTicketGet( + sectorFk = mobileApplication.dataStoreApp.readDataStoreKey( + ConstAndValues.SECTORFK + ), + collectionFk = binding.scanInput.text.toString().toInt(), + print = "0", + type = ConstAndValues.CONTROLADOR + ) + }.show() + customDialogWarning.currentFocus + } else { + viewModel.collectionTicketGet( + sectorFk = mobileApplication.dataStoreApp.readDataStoreKey( + ConstAndValues.SECTORFK + ), + collectionFk = binding.scanInput.text.toString().toInt(), + print = "0", + type = ConstAndValues.CONTROLADOR + ) + } + }) } - binding.scanInput.setText("") + ma.hideKeyboard(binding.scanInput) - return@setOnEditorActionListener true + return@setOnEditorActionListener false } false } @@ -81,6 +113,7 @@ class ControladorFragment : with(viewModel) { collectionTicketList.observe(viewLifecycleOwner, Observer { binding.splashProgress.visibility = View.GONE + binding.scanInput.setText("") if (it.isError) { ma.messageWithSound(it.errorMessage, isError = true, isPlayed = false) } else { @@ -92,6 +125,7 @@ class ControladorFragment : }) } + } private fun navigateToCollectionList(collection: CollectionVO) { diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 11fc987a..0328c790 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -693,6 +693,8 @@ Añadir... Apellidos Confirmada reserva + Está siendo revisado por %1$s + Ha sido revisado por %1$s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9b4dd5a9..2a437e04 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -693,6 +693,8 @@ Añadir... Nom de famille Confirmada reserva + Está siendo revisado por %1$s + Ha sido revisado por %1$s diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index cc7a7840..5f8cdb3a 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -693,6 +693,8 @@ Añadir... Sobrenome Confirmada reserva + Está siendo revisado por %1$s + Ha sido revisado por %1$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 23c54421..abda7836 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -692,5 +692,7 @@ Añadir... Surname Confirmada reserva + Ticket on checking by %1$s + ticket checked by %1$s