diff --git a/app/src/main/java/es/verdnatura/db/database.kt b/app/src/main/java/es/verdnatura/db/database.kt index 5de0a7be..54fc4f0b 100644 --- a/app/src/main/java/es/verdnatura/db/database.kt +++ b/app/src/main/java/es/verdnatura/db/database.kt @@ -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 diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/adapters/ExpeditionLoadUnloadAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/adapters/ExpeditionLoadUnloadAdapter.kt index 5d937637..4a5f0eb4 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/adapters/ExpeditionLoadUnloadAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/adapters/ExpeditionLoadUnloadAdapter.kt @@ -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 } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt index bbed5251..16e2aa60 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt @@ -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 - 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, state: String) { scanning(false) - val mlist = mutableListOf() + /* val mlist = mutableListOf() + 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() 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) + val expeditionBackPosition = + hashMapOf("expeditions" to mlistPosition as List) + //val expeditionBack = hashMapOf("expeditions" to mlist as List) 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 = 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 c01dea76..0affd5c7 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 @@ -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) ) } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt index 6a6b690b..ca220953 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt @@ -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 private lateinit var myListSummary: List - 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, 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) } 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 aa6b5b14..7d8974e4 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 @@ -31,6 +31,17 @@ class ExpeditionSalix( val isScanned: Int? = 0 ) +data class ExpeditionsPosition( + val expeditions: List = listOf() +) + +data class ExpeditionSalixPosition( + val expeditionFk: Number, + val stateCode: String? = null, + val isScanned: Int? = 0, + val scanOrder: Int? = null +) + class ExpeditionInfoList( var list: List = 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 diff --git a/app/src/main/res/layout/item_expedition_loadunload_row.xml b/app/src/main/res/layout/item_expedition_loadunload_row.xml index 80e787af..8fa9666b 100644 --- a/app/src/main/res/layout/item_expedition_loadunload_row.xml +++ b/app/src/main/res/layout/item_expedition_loadunload_row.xml @@ -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"> - + - + + + + + diff --git a/app/src/main/res/layout/sale_row_fragment.xml b/app/src/main/res/layout/sale_row_fragment.xml index 21f7ffa5..2ce1cc86 100644 --- a/app/src/main/res/layout/sale_row_fragment.xml +++ b/app/src/main/res/layout/sale_row_fragment.xml @@ -448,6 +448,18 @@ android:textColor="@color/verdnatura_white" tool:text="Cantidad original 100" /> + + +