refs #6531feat:show last Tickets

This commit is contained in:
Sergio De la torre 2024-02-08 13:44:27 +01:00
parent b759d8a3dd
commit 0445ac0442
11 changed files with 282 additions and 27 deletions

View File

@ -52,6 +52,7 @@ import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO
import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix
@ -92,6 +93,11 @@ interface SalixService {
@Query("filter") filter: String
): Call<List<BuyerVO>>
@GET("ticketStates")
fun lastTicketGetByWorker(
@Query("filter") filter: String
): Call<List<TicketStateSalix>>
@POST("Applications/{routine}/execute-func")
fun executeFunc(
@Path("routine") routine: String,

View File

@ -0,0 +1,43 @@
package es.verdnatura.presentation.view.feature.sacador.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemLastTicketRowBinding
import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
class TicketLastStateAdapter(
private val items: List<TicketStateSalix>,
private val onCollectionSelected: OnCollectionSelectedListener,
private val type: String
) : RecyclerView.Adapter<TicketLastStateAdapter.AjustesItemHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder {
return AjustesItemHolder(
ItemLastTicketRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
}
override fun getItemCount() = items.size
override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
holder.bind(items[position])
holder.binding.root.setOnClickListener {
onCollectionSelected.onCollectionSelected(CollectionVO(items[position].ticketFk), type)
}
}
class AjustesItemHolder(
val binding: ItemLastTicketRowBinding
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: TicketStateSalix) {
binding.apply {
this.item = item
}
}
}
}

View File

@ -5,25 +5,29 @@ import android.os.Bundle
import android.text.InputType.TYPE_CLASS_NUMBER
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentGeneralBlackBinding
import es.verdnatura.databinding.FragmentShowTicketBinding
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.feature.precontrol.ShowTicketViewModel
import es.verdnatura.presentation.view.feature.sacador.adapter.TicketLastStateAdapter
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ShowTicketFragment(var menuOrigin: String) :
BaseFragment<FragmentGeneralBlackBinding, ShowTicketViewModel>(
BaseFragment<FragmentShowTicketBinding, ShowTicketViewModel>(
ShowTicketViewModel::class
) {
private var goBack: Boolean = false
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
override fun getLayoutId(): Int = R.layout.fragment_general_black
override fun getLayoutId(): Int = R.layout.fragment_show_ticket
private var type = ""
private var adapter: TicketLastStateAdapter? = null
companion object {
fun newInstance(menuOrigin: String) = ShowTicketFragment(menuOrigin = menuOrigin)
@ -42,9 +46,8 @@ class ShowTicketFragment(var menuOrigin: String) :
if (menuOrigin == getString(R.string.main)) {
hideBackButton(binding.mainToolbar)
}
setEvents()
viewModel.lastTicketGetByWorker(mobileApplication.userId!!)
super.init()
}
@ -64,6 +67,11 @@ class ShowTicketFragment(var menuOrigin: String) :
binding.mainToolbar.backButton.setOnClickListener {
requireActivity().onBackPressed()
}
binding.sacadorSwipe.setOnRefreshListener {
binding.sacadorSwipe.isRefreshing = true
viewModel.lastTicketGetByWorker(mobileApplication.userId!!)
binding.sacadorSwipe.isRefreshing = false
}
binding.scanInput.requestFocus()
binding.scanInput.setRawInputType(TYPE_CLASS_NUMBER)
@ -80,6 +88,7 @@ class ShowTicketFragment(var menuOrigin: String) :
print = "0",
type = type
)
binding.splashProgress.visibility = View.VISIBLE
} catch (ex: Exception) {
ma.messageWithSound(
@ -98,6 +107,15 @@ class ShowTicketFragment(var menuOrigin: String) :
}
}
private fun createCollectionList(listTickets: List<TicketStateSalix>) {
val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = TicketLastStateAdapter(listTickets, onCollectionSelectedListener!!, type)
binding.lastTicketsRecyclerview.layoutManager = lm
binding.lastTicketsRecyclerview.adapter = adapter
}
override fun observeViewModel() {
with(viewModel) {
collectionTicketList.observe(viewLifecycleOwner) {
@ -110,7 +128,13 @@ class ShowTicketFragment(var menuOrigin: String) :
}
}
lastTicketList.observe(viewLifecycleOwner) {
if (it.list.isNotEmpty()) {
createCollectionList(it.list)
} else {
binding.txtLastTickets.visibility = View.INVISIBLE
}
}
}
}

View File

@ -3,49 +3,63 @@ package es.verdnatura.presentation.view.feature.precontrol
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.SilexCallback
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.view.feature.collection.mapper.map
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateList
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
import retrofit2.Response
class ShowTicketViewModel(val context: Context) : BaseViewModel(context) {
private val _collectionTicketList by lazy { MutableLiveData<CollectionVO>() }
val collectionTicketList: LiveData<CollectionVO>
get() = _collectionTicketList
val collectionTicketList: LiveData<CollectionVO> = _collectionTicketList
private val _lastTicketList by lazy { MutableLiveData<TicketStateList>() }
val lastTicketList: LiveData<TicketStateList> = _lastTicketList
fun collectionTicketGet(collectionFk: Int, sectorFk: Int, print: String, type: String) {
//Tarea 6276
//salix.collectionGetTickets(collectionFk,sectorFk,print.toInt(),type)
silex.collection_getTickets(collectionFk, sectorFk, print, type)
.enqueue(object :
SilexCallback<CollectionVO>(context) {
override fun onError(t: Throwable) {
_collectionTicketList.value = CollectionVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<CollectionVO>) {
if (response.body() != null) {
_collectionTicketList.value = response.body()?.let { it.map(context) }
} else {
SilexCallback<CollectionVO>(context) {
override fun onError(t: Throwable) {
_collectionTicketList.value = CollectionVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
}
})
override fun onSuccess(response: Response<CollectionVO>) {
if (response.body() != null) {
_collectionTicketList.value = response.body()?.let { it.map(context) }
} else {
_collectionTicketList.value = CollectionVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
}
}
})
}
fun lastTicketGetByWorker(userId: Int) {
salix.lastTicketGetByWorker("""{"where": {"userFk": $userId},"order":"updated DESC","limit": 5}""")
.enqueue(object : SalixCallback<List<TicketStateSalix>>(context) {
override fun onSuccess(response: Response<List<TicketStateSalix>>) {
_lastTicketList.value = response.body()?.let { TicketStateList(it) }
}
})
}
}

View File

@ -1,5 +1,9 @@
package es.verdnatura.presentation.view.feature.sacador.model
import android.os.Build
import androidx.annotation.RequiresApi
import es.verdnatura.domain.isoToString
//Tarea 5890
// Sacado reservado
@ -295,3 +299,23 @@ var collectionLocal = CollectionTicket(
3,
tickets = ticketLocal
)
class TicketStateList(
var list: List<TicketStateSalix> = listOf()
)
data class TicketStateSalix(
val ticketFk: Int,
val alertLevel: Int,
val code: String,
val stateFk: Int,
val userFk: Int
) {
@RequiresApi(Build.VERSION_CODES.O)
var updated: String = ""
@RequiresApi(Build.VERSION_CODES.O)
get() {
return field.isoToString()
}
}

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/verdnatura_black">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/sacador_swipe"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/scan_input"
style="@style/ScanLineTextSearch"
android:layout_width="match_parent"
android:hint="@string/Escaneaetiqueta"
android:inputType="textVisiblePassword"
android:lines="1"
android:maxLines="1"
android:textColorHint="@android:color/white"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/main_toolbar" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/txt_last_tickets"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/lastTicketsText"
android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h7"></com.google.android.material.textview.MaterialTextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/last_tickets_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
tools:listitem="@layout/item_last_ticket_row" />
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<include
android:id="@+id/main_toolbar"
layout="@layout/toolbar_fragment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/splash_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/verdnatura_black_8_alpha_6"
android:gravity="center"
android:orientation="vertical"
android:visibility="invisible">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="wrap_content"
android:layout_height="@dimen/verdnatura_logo_large_height"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/orange_loading"
app:lottie_speed="2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
>
<data>
<variable
name="item"
type="es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/LayoutClickable">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/verdnatura_black_5"
android:padding="@dimen/pasilleros_margin_main_menu">
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@{Integer.toString(item.ticketFk)}"
android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h7"
android:gravity="center_vertical"
android:layout_marginLeft="@dimen/pasilleros_margin_main_menu"
android:textStyle="bold"/>
<TextView
android:id="@+id/item_selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@{item.updated}"
android:textColor="@color/verdnatura_pumpkin_orange"
android:textSize="@dimen/h7"
android:gravity="center_vertical"
android:layout_marginLeft="@dimen/pasilleros_margin_main_menu"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/verdnatura_black_9"/>
</LinearLayout>
</layout>

View File

@ -697,6 +697,7 @@
<string name="checkingByUser">Está siendo revisado por %1$s</string>
<string name="checkedByUser">Ha sido revisado por %1$s</string>
<string name="previousText">PREVIA:%1$s</string>
<string name="lastTicketsText">Últimos tickets modificados :</string>
</resources>

View File

@ -696,6 +696,7 @@
<string name="checkingByUser">Está siendo revisado por %1$s</string>
<string name="checkedByUser">Ha sido revisado por %1$s</string>
<string name="previousText">PREVIA:%1$s</string>
<string name="lastTicketsText">Últimos tickets modificados :</string>
</resources>

View File

@ -696,6 +696,7 @@
<string name="checkingByUser">Está siendo revisado por %1$s</string>
<string name="checkedByUser">Ha sido revisado por %1$s</string>
<string name="previousText">PREVIA:%1$s</string>
<string name="lastTicketsText">Últimos tickets modificados :</string>
</resources>

View File

@ -696,5 +696,6 @@
<string name="checkingByUser">Ticket on checking by %1$s</string>
<string name="checkedByUser">ticket checked by %1$s</string>
<string name="previousText">PREVIA:%1$s</string>
<string name="lastTicketsText">Últimos tickets modificados :</string>
</resources>