From 26e13bb7d009caa56300d5486f0c9096aae1d3ee Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Fri, 8 Nov 2024 10:51:11 +0100 Subject: [PATCH] feat: refs #8150 moveExpeditions --- .../java/es/verdnatura/domain/SalixService.kt | 18 +++ .../presentation/common/GeneralAdapter.kt | 37 +++-- .../presentation/common/UICallbacks.kt | 4 + .../delivery/fragments/RoutesFragment.kt | 128 +++++++++++++++++- .../feature/delivery/model/ClientTicket.kt | 13 ++ .../feature/delivery/model/InfoCompany.kt | 3 +- .../delivery/viewmodels/DeliveryViewModel.kt | 89 +++++++++++- .../main/res/drawable/ic_move_expedition.xml | 10 ++ app/src/main/res/values-es/strings.xml | 5 + app/src/main/res/values-fr/strings.xml | 5 + app/src/main/res/values-pt/strings.xml | 5 + app/src/main/res/values/strings.xml | 5 + 12 files changed, 303 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/drawable/ic_move_expedition.xml diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index d003f199..cb454d7b 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -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> + @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, + @Query("landed") landed: String + + ): Call + @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> + @GET("Expeditions") + fun getDataFromExpedition( + @Query("filter") filter: Any, + ): Call> + @POST("RouteComplements") fun addRouteComplements( @Body params: RouteComplementAdd diff --git a/app/src/main/java/es/verdnatura/presentation/common/GeneralAdapter.kt b/app/src/main/java/es/verdnatura/presentation/common/GeneralAdapter.kt index eb39382f..09e1f6fe 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/GeneralAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/GeneralAdapter.kt @@ -7,9 +7,10 @@ import androidx.recyclerview.widget.RecyclerView import es.verdnatura.databinding.ItemGeneralRowBinding class GeneralAdapter( - private val items: List, - private val OnGeneralItemRowClickListener: OnGeneralItemRowClickListener, - // private var showDelete: Boolean = false + private var items: List, + private val onDeleteItemRowClickListener: OnGeneralItemRowClickListener, + private var showDelete: Boolean = false, + private val onRowClickListener: OnGeneralRowClickListener? = null ) : RecyclerView.Adapter() { 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) { + items = list + notifyDataSetChanged() + } + + fun setShowDelete(hasVisibility: Boolean) { + showDelete = hasVisibility + notifyDataSetChanged() + } } diff --git a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index b000b533..facac1e2 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -107,6 +107,10 @@ interface OnGeneralItemRowClickListener { fun onGeneralItemRowClickListener(item: GeneralItem) } +interface OnGeneralRowClickListener { + fun onRowClickListener(item: GeneralItem) +} + interface OnImageTrashClickListener { fun onImageTrashClickListener(item: Any) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt index 0affd5c7..2363253c 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt @@ -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 private lateinit var db: DeliveryDatabase private lateinit var myListRouteLoaded: List + private val customDialogList: CustomDialogList by lazy { + CustomDialogList(requireContext()) + } + private var listExpeditionScan: ArrayList = ArrayList() + private var listMyRoutes: ArrayList = 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() } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/ClientTicket.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/ClientTicket.kt index b90a2aa8..77c5e4b1 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/ClientTicket.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/ClientTicket.kt @@ -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 +) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt index 7d8974e4..c3cf8ef3 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/model/InfoCompany.kt @@ -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$" 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 8c515ed6..9877d417 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 @@ -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>(context) { + override fun onSuccess(response: Response>) { + 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(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, + landed: String + ) { + salix.moveExpeditions( + clientId, warehouseId, addressId, agencyModeId, routeId, expeditionsId, landed + + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + } + }) + } + + 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>(context) { override fun onSuccess(response: Response>) { @@ -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(context) { override fun onSuccess(response: Response) { - getRouteComplements(date) + getRouteComplements(date, workerFk) } }) diff --git a/app/src/main/res/drawable/ic_move_expedition.xml b/app/src/main/res/drawable/ic_move_expedition.xml new file mode 100644 index 00000000..4a3957d7 --- /dev/null +++ b/app/src/main/res/drawable/ic_move_expedition.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 482d3fc6..d6b398cb 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -897,6 +897,11 @@ Complementos salariales reparto Tus complementos: Complementos reparto + Mueve expedición/es a otra ruta + Caja ya escaneada + Selecciona ruta destino + Mover a nueva ruta + Escanea la/s caja/s que cambia/n de ruta diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d2950433..d5b7b5b7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -897,5 +897,10 @@ Complementos salariales reparto Tus complementos: Complementos reparto + Mueve expedición/es a otra ruta + Caja ya escaneada + Selecciona ruta destino + Mover a nueva ruta + Escanea la/s caja/s que cambia/n de ruta diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index c53fec11..2d6b58fe 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -897,5 +897,10 @@ Complementos salariales reparto Tus complementos: Complementos reparto + Mueve expedición/es a otra ruta + Caja ya escaneada + Selecciona ruta destino + Mover a nueva ruta + Escanea la/s caja/s que cambia/n de ruta diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4973969a..263b6121 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -900,5 +900,10 @@ Complementos salariales reparto Tus complementos: Complementos reparto + Mueve expedición/es a otra ruta + Caja ya escaneada + Selecciona ruta destino + Mover a nueva ruta + Escanea la/s caja/s que cambia/n de ruta