feat: refs #7922 scanOrder

This commit is contained in:
Sergio De la torre 2024-10-29 08:57:25 +01:00
parent 3f88449718
commit 8e0ffe8f49
8 changed files with 232 additions and 97 deletions

View File

@ -1,7 +1,16 @@
package es.verdnatura.db
import android.content.Context
import androidx.room.*
import androidx.room.Dao
import androidx.room.Database
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
@ -68,6 +77,9 @@ interface ExpedicionDao {
@Query("DELETE FROM expeditionPending WHERE code = :codeState")
suspend fun getDeleteByState(codeState: String)
@Query("DELETE FROM expeditionPending")
suspend fun getDeleteAllState()
}
@Dao

View File

@ -1,6 +1,7 @@
package es.verdnatura.presentation.view.feature.delivery.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat.getColor
import androidx.recyclerview.widget.RecyclerView
@ -57,8 +58,14 @@ class ExpeditionLoadUnloadAdapter(
)
}
}
binding.scanOrderTxt.visibility =
if (item.scanOrder == null) View.GONE else View.VISIBLE
binding.scanOrderLabel.visibility =
if (item.scanOrder == null) View.GONE else View.VISIBLE
this.item = item
}

View File

@ -24,12 +24,14 @@ import es.verdnatura.presentation.common.OnBackPressedListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogThreeButtons
import es.verdnatura.presentation.view.feature.delivery.activity.SignedActivity
import es.verdnatura.presentation.view.feature.delivery.adapters.ExpeditionLoadUnloadAdapter
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoPending
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalixPosition
import es.verdnatura.presentation.view.feature.delivery.model.RouteLoaded
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
import kotlinx.coroutines.Dispatchers
@ -51,12 +53,11 @@ class LoadUnloadFragment(
private var adapter: ExpeditionLoadUnloadAdapter? = null
private var originalItem: Int = 0
private lateinit var myList: MutableList<ExpeditionInfoLoadUnload>
private var counterCalls = 0
private var counterResponse = 0
private var route = 0
private var addressFk = 0
private lateinit var db: DeliveryDatabase
private lateinit var backDispatcher: OnBackPressedDispatcher
private lateinit var customDialogConfirmExpedition: CustomDialogThreeButtons
companion object {
var scanned = false
@ -75,8 +76,7 @@ class LoadUnloadFragment(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner,
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (!onBackPressedHandled()) {
@ -101,6 +101,7 @@ class LoadUnloadFragment(
setSwitchButon()
binding.scanInput.requestFocus()
viewModel.getExpeditionFromRoute(route)
customDialogConfirmExpedition = CustomDialogThreeButtons(requireContext())
super.init()
}
@ -178,25 +179,43 @@ class LoadUnloadFragment(
private fun setExpeditionsState(list: MutableList<ExpeditionInfoLoadUnload>, state: String) {
scanning(false)
val mlist = mutableListOf<ExpeditionSalix>()
/* val mlist = mutableListOf<ExpeditionSalix>()
for (l in list) {
mlist.add(
ExpeditionSalix(
expeditionFk = l.id,
stateCode = if (l.code != state && l.code != "FOUND" && l.code != "DELIVERED") {
if (state == "ON DELIVERY") "NOT SCANNED" else "LOST"
} else {
l.code
},
isScanned = l.isScanned
)
)
}*/
val mlistPosition = mutableListOf<ExpeditionSalixPosition>()
for (l in list) {
mlist.add(
ExpeditionSalix(
mlistPosition.add(
ExpeditionSalixPosition(
expeditionFk = l.id,
stateCode = if (l.code != state && l.code != "FOUND" && l.code != "DELIVERED") {
"LOST"
} else {
l.code
stateCode = if (l.code == "FOUND") (l.code) else {
if (state == "ON DELIVERY" && l.code != "ON DELIVERY" && l.code != "DELIVERED" && l.code != "LOST") {
"NOT SCANNED"
} else {
if (state == "DELIVERED" && l.code != "DELIVERED") "LOST" else l.code
}
},
isScanned = l.isScanned
isScanned = l.isScanned,
scanOrder = l.scanOrder
)
)
}
val expeditionBack = hashMapOf("expeditions" to mlist as List<ExpeditionSalix>)
val expeditionBackPosition =
hashMapOf("expeditions" to mlistPosition as List<ExpeditionSalixPosition>)
//val expeditionBack = hashMapOf("expeditions" to mlist as List<ExpeditionSalix>)
if (list.any { it.code == state }) {
if (list.filter { it.code == state }.size == list.size) {
viewModel.expeditionStateAddSalix(expeditionBack)
counterCalls = 1
viewModel.expeditionStateAddSalix(expeditionBackPosition)
} else {
val alertDialog = android.app.AlertDialog.Builder(requireContext()).create()
alertDialog.setTitle(getString(R.string.info))
@ -204,8 +223,7 @@ class LoadUnloadFragment(
alertDialog.setButton(
android.app.AlertDialog.BUTTON_NEUTRAL, getString(R.string.save)
) { _, _ ->
counterCalls = 1
viewModel.expeditionStateAddSalix(expeditionBack)
viewModel.expeditionStateAddSalix(expeditionBackPosition)
}
alertDialog.setButton(
android.app.AlertDialog.BUTTON_POSITIVE, getString(R.string.ordenar)
@ -261,6 +279,8 @@ class LoadUnloadFragment(
if (!binding.scanInput.text.isNullOrEmpty()) {
val isScanned =
event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER
//Tarea 8152
// showconfirmExpedition(binding.scanInput.text.toString().toInt(), isScanned)
try {
markExpedition(
binding.scanInput.text.toString().toInt(),
@ -295,6 +315,70 @@ class LoadUnloadFragment(
binding.scanInput.requestFocus()
}
private fun showconfirmExpedition(expeditionFk: Int, isScanned: Boolean) {
try {
customDialogConfirmExpedition.setHintDialogValue("Indica expedición")
customDialogConfirmExpedition.setDescription("No está escanenado la caja. Escríbala de nuevo:")
.setValue("").setOkButtonAdd(getString(R.string.confirm)) {
try {
if (expeditionFk == customDialogConfirmExpedition.getValue().toInt()) {
takeActionConfirmed(isScanned)
binding.scanInput.requestFocus()
customDialogConfirmExpedition.dismiss()
} else {
}
} catch (ex: Exception) {
ma.messageWithSound(
message = getString(R.string.errorInputQuantity),
isPlayed = true,
isError = true,
isToasted = true
)
}
}.setKoButton(getString(R.string.cancel)) {
binding.scanInput.requestFocus()
binding.scanInput.setText("")
customDialogConfirmExpedition.dismiss()
}.show()
customDialogConfirmExpedition.setFocusDialogValue()
} catch (ex: Exception) {
ex.message!!.toast(requireContext())
}
}
private fun takeActionConfirmed(isScanned: Boolean) {
try {
markExpedition(
binding.scanInput.text.toString().toInt(),
if (!binding.mainToolbar.switchButton.isChecked) {
state
} else {
"FOUND"
},
isScanned = if (isScanned) 1 else 0
)
if (state != "DELIVERED") {
binding.mainToolbar.toolbarTitle.text =
if (!binding.mainToolbar.switchButton.isChecked) {
getString(R.string.loading)
} else {
getString(R.string.unloading)
}
}
} catch (ex: Exception) {
getString(R.string.errorExpedition).toast(context, Toast.LENGTH_SHORT)
}
binding.scanInput.setText("")
}
private fun markExpedition(expedNumber: Int, state: String, isScanned: Int) {
var found = false
@ -307,15 +391,14 @@ class LoadUnloadFragment(
found = true
exped.code = state
exped.isScanned = isScanned
if (state == "ON DELIVERY") exped.scanOrder =
myList.filter { it.code == state }.size
break
}
}
if (found) {
ma.messageWithSound(
message = "",
isError = false,
isPlayed = true,
isToasted = false
message = "", isError = false, isPlayed = true, isToasted = false
)
scanning(true)
} else {
@ -324,7 +407,6 @@ class LoadUnloadFragment(
}
if (binding.mainToolbar.switchButton.isChecked) {
counterCalls = 1
val pendingExpeditionSend = myList.map { l ->
ExpeditionSalix(
expeditionFk = l.id, stateCode = l.code, isScanned = l.isScanned
@ -353,20 +435,17 @@ class LoadUnloadFragment(
}
responseStateAdd.observe(viewLifecycleOwner) {
if (it) {
counterResponse += 1
if (counterResponse == counterCalls) {
if (!binding.mainToolbar.switchButton.isChecked) {
if (state == "DELIVERED") {
openSignActivity()
} else {
ma.onMyBackPressed()
}
if (!binding.mainToolbar.switchButton.isChecked) {
if (state == "DELIVERED") {
openSignActivity()
} else {
binding.mainToolbar.switchButton.isChecked = false
ma.onMyBackPressed()
}
counterResponse = 0
counterCalls = 0
} else {
binding.mainToolbar.switchButton.isChecked = false
}
} else {
openSignActivity()
}
@ -456,6 +535,7 @@ class LoadUnloadFragment(
it.routeFk == route
}
}
adapter = ExpeditionLoadUnloadAdapter(myList)
binding.expeditionloadunloadRecyclerview.adapter = adapter
binding.expeditionloadunloadRecyclerview.layoutManager =

View File

@ -24,7 +24,7 @@ import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
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.ExpeditionSalix
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalixPosition
import es.verdnatura.presentation.view.feature.delivery.model.RouteInfo
import es.verdnatura.presentation.view.feature.delivery.model.RouteLoaded
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
@ -78,30 +78,15 @@ class RoutesFragment(
}
val pendingExpedition = db.expedicionDao().getAllPendingExpeditions()
val pendingExpeditionSend = pendingExpedition.map { l ->
ExpeditionSalix(
expeditionFk = l.id, stateCode = l.code, l.isScanned
)
}
if (pendingExpedition.isNotEmpty()) {
val pendingExpeditionSend = pendingExpedition.map { l ->
ExpeditionSalixPosition(
expeditionFk = l.id, stateCode = l.code, l.isScanned, l.scanOrder
)
}
if (pendingExpeditionSend.any { it.stateCode == "DELIVERED" }) {
viewModel.expeditionStateAddSalix(
hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == "DELIVERED" })
)
}
if (pendingExpeditionSend.any { it.stateCode == "ON DELIVERY" }) {
viewModel.expeditionStateAddSalix(
hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == "ON DELIVERY" })
)
}
if (pendingExpeditionSend.any { it.stateCode == "LOST" }) {
viewModel.expeditionStateAddSalix(
hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == "LOST" })
)
}
if (pendingExpeditionSend.any { it.stateCode == "FOUND" }) {
viewModel.expeditionStateAddSalix(
hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == "FOUND" })
hashMapOf("expeditions" to pendingExpeditionSend)
)
}
@ -126,7 +111,7 @@ class RoutesFragment(
private fun deleteExpeditionsPending(codeState: String) {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
db.expedicionDao().getDeleteByState(codeState)
db.expedicionDao().getDeleteAllState()
}
}
@ -302,8 +287,7 @@ class RoutesFragment(
"showTickets" -> {
ma.onPasillerosItemClickListener(
PasillerosItemVO(title = R.string.tickets),
Gson().toJson(item)
PasillerosItemVO(title = R.string.tickets), Gson().toJson(item)
)
}
}

View File

@ -22,7 +22,7 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.feature.delivery.adapters.ExpeditionSummaryAdapter
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoSummary
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalix
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionSalixPosition
import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
@ -39,8 +39,6 @@ class SummaryFragment(
private var originalItem: Int = 0
private lateinit var myList: MutableList<ExpeditionInfoLoadUnload>
private lateinit var myListSummary: List<ExpeditionInfoSummary>
private var counterCalls = 0
private var counterResponse = 0
private var positionOnScreen = 0
private var addressFkSelected = 0
private var routeSelected = 0
@ -151,19 +149,20 @@ class SummaryFragment(
list: MutableList<ExpeditionInfoLoadUnload>, state: String, address: Int
) {
val listExpedition = list.filter { it.addressFk == address }.map { l ->
ExpeditionSalix(
expeditionFk = l.id, stateCode = if (l.code == state && l.code != "DELIVERED") {
state
} else {
"FOUND"
},
isScanned = l.isScanned
ExpeditionSalixPosition(
expeditionFk = l.id, stateCode = if (l.code == "FOUND") (l.code) else {
if (state == "ON DELIVERY" && l.code != "ON DELIVERY" && l.code != "DELIVERED" && l.code != "LOST") {
"NOT SCANNED"
} else {
if (state == "DELIVERED" && l.code != "DELIVERED") "LOST" else l.code
}
}, isScanned = l.isScanned, scanOrder = l.scanOrder
)
}
if (list.filter { it.addressFk == address }
.filter { it.code == state }.size == list.filter { it.addressFk == address }.size) {
counterCalls = 1
viewModel.expeditionStateAddSalix(
hashMapOf("expeditions" to listExpedition.filter { it.stateCode == state })
)
@ -178,8 +177,7 @@ class SummaryFragment(
android.app.AlertDialog.BUTTON_POSITIVE, getString(R.string.save)
) { _, _ ->
counterCalls = 1
viewModel.expeditionStateAddSalix(hashMapOf("expeditions" to listExpedition.filter { it.stateCode == state }))
viewModel.expeditionStateAddSalix(hashMapOf("expeditions" to listExpedition))
}
alertDialog.setButton(
@ -235,15 +233,22 @@ class SummaryFragment(
found = true
exped.code = state
exped.isScanned = isScanned
println(
"scanOrder markExpedition${
myList.filter { it.addressFk == addressFkSelected }
.filter { it.code == state }.size
}"
)
exped.scanOrder = myList.filter { it.addressFk == addressFkSelected }
.filter { it.code == state }.size
break
}
}
if (found) {
ma.messageWithSound(
message = "",
isError = false,
isPlayed = true,
isToasted = false
message = "", isError = false, isPlayed = true, isToasted = false
)
} else {
ma.messageWithSound(message = "", isError = true, isPlayed = true, isToasted = null)
@ -279,13 +284,10 @@ class SummaryFragment(
}
responseStateAdd.observe(viewLifecycleOwner) {
if (it) {
counterResponse += 1
if (counterResponse == counterCalls) {
viewModel.routeGetExpeditionSummary(routeSelected)
counterResponse = 0
counterCalls = 0
checkNextAddress()
}
viewModel.routeGetExpeditionSummary(routeSelected)
checkNextAddress()
}
}
@ -338,7 +340,14 @@ class SummaryFragment(
viewModel.getExpeditionFromRoute(routeSelected)
}
println("address $addressFkSelected")
println("address isScanning $isScanning")
if (addressFkSelected != item.addressFk && isScanning) {
println("address isScanning $isScanning")
println("address setSTATE $state")
println("address address $addressFkSelected")
setExpeditionsState(myList, state, addressFkSelected)
}

View File

@ -31,6 +31,17 @@ class ExpeditionSalix(
val isScanned: Int? = 0
)
data class ExpeditionsPosition(
val expeditions: List<ExpeditionSalixPosition> = listOf()
)
data class ExpeditionSalixPosition(
val expeditionFk: Number,
val stateCode: String? = null,
val isScanned: Int? = 0,
val scanOrder: Int? = null
)
class ExpeditionInfoList(
var list: List<ExpeditionInfoLog> = listOf()
)
@ -106,7 +117,8 @@ class ExpeditionInfoLoadUnload(
var code: String?,
var nickname: String,
var postalCode: String,
var isScanned: Int? = null
var isScanned: Int? = null,
var scanOrder: Int? = null
) : Serializable
@Entity(tableName = "expeditionPending")
@ -121,7 +133,8 @@ class ExpeditionInfoPending(
var code: String?,
var nickname: String,
var postalCode: String,
var isScanned: Int? = 0
var isScanned: Int? = 0,
var scanOrder: Int? = null
) : Serializable

View File

@ -14,17 +14,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/ef_padding_small"
>
android:padding="@dimen/ef_padding_small">
<LinearLayout
android:id="@+id/expeditionDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/verdnatura_white"
android:orientation="horizontal" />
<LinearLayout
android:id="@+id/expeditionDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/verdnatura_white"
android:orientation="horizontal" />
<LinearLayout
<LinearLayout
android:id="@+id/expeditionConsign"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -84,6 +83,7 @@
/>
</LinearLayout>
<LinearLayout
android:id="@+id/expeditionViewAdress"
android:layout_width="match_parent"
@ -95,7 +95,7 @@
android:id="@+id/itemStreet"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="4"
android:gravity="start"
android:text="@{item.street + ` - ` + item.city + ` - ` + String.valueOf(item.postalCode)}"
android:textColor="@color/verdnatura_white"
@ -103,6 +103,24 @@
/>
<TextView
android:id="@+id/scanOrderLabel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="Orden:"
android:textColor="@color/verdnatura_white"
android:textSize="@dimen/delivery_body_2" />
<TextView
android:id="@+id/scanOrderTxt"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@{String.valueOf(item.scanOrder)}"
android:textColor="@color/verdnatura_white"
android:textSize="@dimen/delivery_body_2" />
</LinearLayout>

View File

@ -448,6 +448,18 @@
android:textColor="@color/verdnatura_white"
tool:text="Cantidad original 100" />
<ImageView
android:id="@+id/addItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/verdnatura_red"
android:gravity="end"
android:src="@drawable/ic_add_black_24dp"
android:visibility="gone"
tools:visibility="visible" />
<ImageView
android:id="@+id/delete_reserve"
android:layout_width="0dp"
@ -456,7 +468,7 @@
android:background="@color/verdnatura_red"
android:gravity="end"
android:src="@drawable/ic_delete_black_24dp"
android:visibility="invisible"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>