feat: refs #8150 moveExpeditions

This commit is contained in:
Sergio De la torre 2024-11-08 10:51:11 +01:00
parent d0e5e5d748
commit 26e13bb7d0
12 changed files with 303 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import es.verdnatura.presentation.view.feature.delivery.model.DeliveryInfo
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLog
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoSummary
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionWithTicket
import es.verdnatura.presentation.view.feature.delivery.model.RouteAction
import es.verdnatura.presentation.view.feature.delivery.model.RouteComplement
import es.verdnatura.presentation.view.feature.delivery.model.RouteComplementAdd
@ -188,6 +189,18 @@ interface SalixService {
fun getRoutes(
): Call<MutableList<RouteInfo>>
@POST("Expeditions/moveExpeditions")
fun moveExpeditions(
@Query("clientId") clientId: Number,
@Query("warehouseId") warehouseId: Number,
@Query("addressId") addressId: Number,
@Query("agencyModeId") agencyModeId: Number,
@Query("routeId") routeId: Number,
@Query("expeditionIds") expeditionIds: ArrayList<Number>,
@Query("landed") landed: String
): Call<Any>
@GET("Workers/Summary")
fun getNameWorker(
@Query("filter") filter: String
@ -558,6 +571,11 @@ interface SalixService {
@Query("filter") filter: Any = """{"fields": {"id": true,"name": true,"price":true},"order": "name"}"""
): Call<List<RouteAction>>
@GET("Expeditions")
fun getDataFromExpedition(
@Query("filter") filter: Any,
): Call<List<ExpeditionWithTicket>>
@POST("RouteComplements")
fun addRouteComplements(
@Body params: RouteComplementAdd

View File

@ -7,9 +7,10 @@ import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemGeneralRowBinding
class GeneralAdapter(
private val items: List<GeneralItem>,
private val OnGeneralItemRowClickListener: OnGeneralItemRowClickListener,
// private var showDelete: Boolean = false
private var items: List<GeneralItem>,
private val onDeleteItemRowClickListener: OnGeneralItemRowClickListener,
private var showDelete: Boolean = false,
private val onRowClickListener: OnGeneralRowClickListener? = null
) : RecyclerView.Adapter<GeneralAdapter.ItemHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
@ -23,9 +24,9 @@ class GeneralAdapter(
override fun onBindViewHolder(holder: ItemHolder, position: Int) {
holder.bind(items[position])
holder.binding.root.setOnClickListener {
OnGeneralItemRowClickListener.onGeneralItemRowClickListener(items[position])
}
/*holder.binding.root.setOnClickListener {
onGeneralItemRowClickListener.onGeneralItemRowClickListener(items[position])
}*/
}
@ -36,11 +37,31 @@ class GeneralAdapter(
fun bind(item: GeneralItem) {
binding.apply {
this.item = item
/*if (showDelete) itemImage.visibility = View.VISIBLE
else itemImage.visibility = View.GONE*/
if (showDelete) itemImage.visibility = View.VISIBLE
else itemImage.visibility = View.GONE
itemCode.visibility = View.GONE
}
binding.itemImage.setOnClickListener {
onDeleteItemRowClickListener.onGeneralItemRowClickListener(item)
}
binding.itemCode.setOnClickListener {
onRowClickListener?.onRowClickListener(item)
}
binding.itemTitle.setOnClickListener {
onRowClickListener?.onRowClickListener(item)
}
}
}
fun updateItems(list: List<GeneralItem>) {
items = list
notifyDataSetChanged()
}
fun setShowDelete(hasVisibility: Boolean) {
showDelete = hasVisibility
notifyDataSetChanged()
}
}

View File

@ -107,6 +107,10 @@ interface OnGeneralItemRowClickListener {
fun onGeneralItemRowClickListener(item: GeneralItem)
}
interface OnGeneralRowClickListener {
fun onRowClickListener(item: GeneralItem)
}
interface OnImageTrashClickListener {
fun onImageTrashClickListener(item: Any)
}

View File

@ -5,9 +5,11 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ImageView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.gson.Gson
import es.verdnatura.R
import es.verdnatura.databinding.FragmentRouteBinding
@ -17,11 +19,18 @@ import es.verdnatura.domain.toDateString
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.base.database
import es.verdnatura.presentation.common.GeneralAdapter
import es.verdnatura.presentation.common.GeneralItem
import es.verdnatura.presentation.common.ItemDescorationCustomized
import es.verdnatura.presentation.common.OnGeneralItemRowClickListener
import es.verdnatura.presentation.common.OnGeneralRowClickListener
import es.verdnatura.presentation.common.OnItemImageRouteRowClickListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.common.hideKeyboard
import es.verdnatura.presentation.common.itemScanValue
import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.feature.delivery.adapters.RouteAdapter
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalixPosition
@ -45,6 +54,34 @@ class RoutesFragment(
private lateinit var myListRoute: MutableList<RouteInfo>
private lateinit var db: DeliveryDatabase
private lateinit var myListRouteLoaded: List<RouteLoaded>
private val customDialogList: CustomDialogList by lazy {
CustomDialogList(requireContext())
}
private var listExpeditionScan: ArrayList<GeneralItem> = ArrayList()
private var listMyRoutes: ArrayList<GeneralItem> = ArrayList()
private val expeditionScanAdapter: GeneralAdapter? by lazy {
GeneralAdapter(listExpeditionScan, object : OnGeneralItemRowClickListener {
override fun onGeneralItemRowClickListener(item: GeneralItem) {
listExpeditionScan.remove(item)
expeditionScanAdapter?.notifyDataSetChanged()
}
}, onRowClickListener = object : OnGeneralRowClickListener {
override fun onRowClickListener(item: GeneralItem) {
getDataForMoveExpeditions(item.code!!)
}
}, showDelete = true
)
}
private val recyclerViewConfigured: RecyclerView by lazy {
customDialogList.getRecyclerView().apply {
layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = expeditionScanAdapter
}
}
companion object {
fun newInstance(title: String) = RoutesFragment(title)
@ -108,7 +145,7 @@ class RoutesFragment(
}
}
private fun deleteExpeditionsPending(codeState: String) {
private fun deleteExpeditionsPending() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db.expedicionDao().getDeleteAllState()
@ -137,6 +174,13 @@ class RoutesFragment(
iconInfo.tooltipText = getTooltip(R.drawable.ic_info_delivery)
iconRefresh.tooltipText = getTooltip(R.drawable.ic_info_refresh)
iconSearch.tooltipText = getTooltip(R.drawable.expedition_find)
val iconMove = ImageView(context)
iconMove.setImageResource(R.drawable.ic_move_expedition)
iconMove.tooltipText = getString(R.string.moveExpedition)
//Tarea 8150
// listIcons.add(iconMove)
listIcons.add(iconInfo)
listIcons.add(iconRefresh)
listIcons.add(iconSearch)
@ -164,6 +208,10 @@ class RoutesFragment(
getString(R.string.titleLog)
)
}
iconMove.drawable -> {
showExpeditionScan()
}
}
}
})
@ -173,6 +221,81 @@ class RoutesFragment(
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
}
private fun showExpeditionScan() {
listExpeditionScan.clear()
listMyRoutes.clear()
expeditionScanAdapter!!.updateItems(listExpeditionScan)
expeditionScanAdapter!!.setShowDelete(true)
customDialogList.setTitle(getString(R.string.scanExpeditionForMove))
.setOkButton(getString(R.string.moveToRoute)) {
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.dismiss()
showRoutes()
}.setKoButton(getString(R.string.cancel)) {
customDialogList.dismiss()
requireContext().hideKeyboard(binding.scanInput)
}.setValue("").showDialog().show()
customDialogList.getEditText().requestFocus()
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (customDialogList.getValue().isNotEmpty()) {
val expeditionScan = itemScanValue(
customDialogList.getValue(), arrayOf("expeditionPallet"), "id"
).toString()
listExpeditionScan.add(
GeneralItem(
expeditionScan, expeditionScan
)
)
expeditionScanAdapter?.notifyItemChanged(0)
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
return@setOnEditorActionListener true
}
false
}
recyclerViewConfigured
requireContext().hideKeyboard(customDialogList.getEditText())
}
private fun showRoutes() {
listMyRoutes.clear()
expeditionScanAdapter!!.updateItems(
ArrayList(myListRoute.map { routeInfo ->
GeneralItem(
code = routeInfo.id.toString(), text = routeInfo.id.toString()
)
})
)
expeditionScanAdapter!!.setShowDelete(false)
customDialogList.setTitle(getString(R.string.selectRoute))
.setKoButton(getString(R.string.cancel)) {
customDialogList.dismiss()
requireContext().hideKeyboard(binding.scanInput)
}.setValue("").hideDialog().show()
requireContext().hideKeyboard(customDialogList.getEditText())
recyclerViewConfigured
}
private fun getDataForMoveExpeditions(routeId: String) {
val routeItem = myListRoute.find { it.id == routeId.toLong() }
for (expedition in listExpeditionScan) {
viewModel.getDataFromExpedition(
routeId = routeId.toLong(),
expeditionId = expedition.code!!.toLong(),
landed = routeItem!!.created.toString()
)
}
customDialogList.dismiss()
}
private fun setEvents() {
binding.mainToolbar.backButton.setOnClickListener {
ma.onMyBackPressed()
@ -189,7 +312,6 @@ class RoutesFragment(
}
override fun afterTextChanged(s: Editable?) {
}
})
@ -247,7 +369,7 @@ class RoutesFragment(
if (it) {
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
deleteExpeditionsPending("")
deleteExpeditionsPending()
}
}

View File

@ -105,3 +105,16 @@ data class RouteComplementAdd(
val routeActionFk: Number,
val dated: String,
)
data class ExpeditionWithTicket(
val id: Number,
val ticket: TicketExpedition,
)
data class TicketExpedition(
val clientFk: Number,
val warehouseFk: Number,
val addressFk: Number,
val agencyModeFk: Number
)

View File

@ -180,7 +180,8 @@ class RouteInfo(
var finished: String,
var header: Boolean = false,
//tarea 5867
var email: String? = null
var email: String? = null,
var agencyModeFk: Int
) : Serializable {
override fun toString(): String {
return "$driver$id$name$numberPlate$m3$created$hour$"

View File

@ -21,6 +21,7 @@ import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLog
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoSummary
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionList
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSummaryList
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionWithTicket
import es.verdnatura.presentation.view.feature.delivery.model.FreeLanceDeliveryInfoList
import es.verdnatura.presentation.view.feature.delivery.model.RouteAction
import es.verdnatura.presentation.view.feature.delivery.model.RouteActionList
@ -135,6 +136,39 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun getDataFromExpedition(expeditionId: Number, routeId: Number, landed: String) {
salix.getDataFromExpedition(
filter = """
|{
|"where":
|{"id":$expeditionId},
|"fields":["id","ticketFk"],
|"include":
|{
|"relation":"ticket",
|"scope":{
|"fields":["clientFk","addressFk","warehouseFk","agencyModeFk"]
| }
|}
|}""".trimMargin()
)
.enqueue(object : SalixCallback<List<ExpeditionWithTicket>>(context) {
override fun onSuccess(response: Response<List<ExpeditionWithTicket>>) {
val myTicketData = response.body()!![0]
moveExpeditions(
clientId = myTicketData.ticket.clientFk,
addressId = myTicketData.ticket.addressFk,
warehouseId = myTicketData.ticket.warehouseFk,
routeId = routeId,
agencyModeId = myTicketData.ticket.agencyModeFk,
expeditionsId = arrayListOf(expeditionId),
landed = landed
)
}
})
}
fun addRouteComplements(routeComplementAdd: RouteComplementAdd) {
salix.addRouteComplements(routeComplementAdd)
.enqueue(object : SalixCallback<Any>(context) {
@ -144,19 +178,60 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
routeComplementAdd.dated,
DateTimeFormatter.ofPattern("yyyy-MM-dd")
)
.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")),
workerFk = routeComplementAdd.workerFk
)
}
})
}
fun getRouteComplements(date: String) {
fun moveExpeditions(
clientId: Number,
warehouseId: Number,
addressId: Number,
agencyModeId: Number,
routeId: Number,
expeditionsId: ArrayList<Number>,
landed: String
) {
salix.moveExpeditions(
clientId, warehouseId, addressId, agencyModeId, routeId, expeditionsId, landed
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
}
})
}
fun getRouteComplements(date: String, workerFk: Number) {
val (startOfDay, endOfDay) = getDayBounds(date)
salix.getRouteComplements(
"""{"where": {"dated": {
"between": ["$startOfDay",
"$endOfDay"]}},"include":[{"relation":"routeAction","scope":{"fields":{"routeActionFk":true,"name":true}}}]}"""
"""{
|"where": {
|"and": [
|{
|"dated": {
|"between": ["$startOfDay", "$endOfDay"]
|}
|},
|{
|"workerFK": "$workerFk"
|}
|]
|},
|"include": [
|{
|"relation": "routeAction",
|"scope": {
|"fields": {
|"routeActionFk": true,
|"name": true
|}
|}
|}
|]
|}""".trimMargin()
)
.enqueue(object : SalixCallback<List<RouteComplement>>(context) {
override fun onSuccess(response: Response<List<RouteComplement>>) {
@ -167,11 +242,11 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun routeComplementDelete(id: Number, date: String) {
fun routeComplementDelete(id: Number, date: String, workerFk: Number) {
salix.routeComplementDelete(id)
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
getRouteComplements(date)
getRouteComplements(date, workerFk)
}
})

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorOnPrimaryFixed">
<path
android:fillColor="@android:color/white"
android:pathData="M280,840L280,597Q280,597 280,597Q280,597 280,597Q192,583 136,515.5Q80,448 80,360Q80,260 150,190Q220,120 320,120Q408,120 475.5,176Q543,232 557,320Q557,320 557,320Q557,320 557,320L727,320L664,256L720,200L880,360L720,520L663,464L727,400L556,400Q527,400 505,381Q483,362 478,333Q468,275 423.5,237.5Q379,200 320,200Q254,200 207,247Q160,294 160,360Q160,419 197.5,463.5Q235,508 293,518Q322,523 341,545Q360,567 360,596L360,840L280,840Z"/>
</vector>

View File

@ -897,6 +897,11 @@
<string name="salarySupplementTitle">Complementos salariales reparto</string>
<string name="complement">Tus complementos:</string>
<string name="supplementDelivery">Complementos reparto</string>
<string name="moveExpedition">Mueve expedición/es a otra ruta</string>
<string name="boxScanned">Caja ya escaneada</string>
<string name="selectRoute">Selecciona ruta destino</string>
<string name="moveToRoute">Mover a nueva ruta</string>
<string name="scanExpeditionForMove">Escanea la/s caja/s que cambia/n de ruta</string>
</resources>

View File

@ -897,5 +897,10 @@
<string name="salarySupplementTitle">Complementos salariales reparto</string>
<string name="complement">Tus complementos:</string>
<string name="supplementDelivery">Complementos reparto</string>
<string name="moveExpedition">Mueve expedición/es a otra ruta</string>
<string name="boxScanned">Caja ya escaneada</string>
<string name="selectRoute">Selecciona ruta destino</string>
<string name="moveToRoute">Mover a nueva ruta</string>
<string name="scanExpeditionForMove">Escanea la/s caja/s que cambia/n de ruta</string>
</resources>

View File

@ -897,5 +897,10 @@
<string name="salarySupplementTitle">Complementos salariales reparto</string>
<string name="complement">Tus complementos:</string>
<string name="supplementDelivery">Complementos reparto</string>
<string name="moveExpedition">Mueve expedición/es a otra ruta</string>
<string name="boxScanned">Caja ya escaneada</string>
<string name="selectRoute">Selecciona ruta destino</string>
<string name="moveToRoute">Mover a nueva ruta</string>
<string name="scanExpeditionForMove">Escanea la/s caja/s que cambia/n de ruta</string>
</resources>

View File

@ -900,5 +900,10 @@
<string name="salarySupplementTitle">Complementos salariales reparto</string>
<string name="complement">Tus complementos:</string>
<string name="supplementDelivery">Complementos reparto</string>
<string name="moveExpedition">Mueve expedición/es a otra ruta</string>
<string name="boxScanned">Caja ya escaneada</string>
<string name="selectRoute">Selecciona ruta destino</string>
<string name="moveToRoute">Mover a nueva ruta</string>
<string name="scanExpeditionForMove">Escanea la/s caja/s que cambia/n de ruta</string>
</resources>