diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index cf2a7d8a..c56efb00 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -7,7 +7,9 @@ import es.verdnatura.presentation.view.feature.buffer.fragment.BufferFragmentVie import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemViewModel import es.verdnatura.presentation.view.feature.category.ChangeCategoryViewModel import es.verdnatura.presentation.view.feature.claim.fragment.ubication.ClaimViewModel +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionCheckerViewModel import es.verdnatura.presentation.view.feature.collection.fragment.CollectionViewModel +import es.verdnatura.presentation.view.feature.collection.fragment.CollectionViewModelCheckerPreviosNew import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.ControlVehiculoViewModel import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewModel import es.verdnatura.presentation.view.feature.diadeventa.fragment.DayOfSaleViewModel @@ -137,6 +139,12 @@ val viewModelModule = module { viewModel { CollectionViewModel(androidContext()) } + viewModel { + CollectionViewModelCheckerPreviosNew(androidContext()) + } + viewModel { + CollectionCheckerViewModel(androidContext()) + } viewModel { ParkingViewModel(androidContext()) diff --git a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt index c0914d4a..7f38a4be 100644 --- a/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt +++ b/app/src/main/java/es/verdnatura/domain/ConstAndValues.kt @@ -18,6 +18,7 @@ object ConstAndValues { const val PRINTERFKDEFAULT = -1 const val WAREHOUSEFKDEFAULT = 60 const val SECTORFK = "sectorFk" + const val SECTORISONRESERVATIONMODE = "sectorIsOnReservationMode" const val TAG = "VERDNATURA::" const val USERFK = "userFk" const val USER = "user" @@ -26,6 +27,7 @@ object ConstAndValues { const val TTL = "ttl" const val TOKENCREATED = "tokenCreated" const val SECTORDESCRIP = "sectordescrip" + const val HOLDPOSITION = "holdPosition" const val NUMBEROFWAGONS = "operatorNumberOfWagons" const val PRINTERNAME = "printername" const val PRINTERFK = "printerFk" @@ -66,6 +68,6 @@ object ConstAndValues { const val LIMITRECORDSSHELVINGLOG = 50 const val RESERVATIONMODE = "operatorReservationMode" const val MODELWORKERTYPEACTIVITY = "APP" - + } diff --git a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt index 945ad08e..6c9d4049 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/SalixBackItems.kt @@ -38,11 +38,19 @@ data class ItemShelvingSaleSalix( var isItemShelvingSaleEmpty: Boolean? ) +data class ItemShelving( + var id: Int, + var itemFk: Int, + var shelvingFk: String, + var position: Int, + var quantity: Int +) + data class ItemShelvingSalix( var visible: Int, var packing: Int?, var grouping: Int?, - var available : Int? + var available: Int? ) @@ -65,12 +73,13 @@ data class CollectionItemSalix( var warehouseFk: Int ) + //Tarea 6889 data class ItemAddSale( var barcode: String, var quantity: Int, -) + ) data class TicketState( val ticketFk: Int = 0, @@ -82,8 +91,9 @@ data class TicketState( val username: String = "" ) } + data class ExpeditionPrintOut( - val expeditionFk:Long, - val itemFk:Int, + val expeditionFk: Long, + val itemFk: Int, val isChecked: Boolean ) \ No newline at end of file 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 0daa0cb4..c5d5bec6 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -267,6 +267,10 @@ interface OnTicketClickSaleListener { fun onTicketClickListener(sale: Sale) } +interface OnSaleReserveClickListener { + fun onSaleReserveListener(sale: Sale) +} + interface OnBuyerSelectedListener { fun onBuyerSelected(userFk: String) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt index 0fbc3f48..185c1b28 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/adapter/SaleAdapterNew.kt @@ -6,6 +6,9 @@ import android.graphics.Color import android.graphics.drawable.Drawable import android.view.LayoutInflater import android.view.View +import android.view.View.GONE +import android.view.View.INVISIBLE +import android.view.View.VISIBLE import android.view.ViewGroup import androidx.core.content.ContextCompat.getColor import androidx.core.graphics.drawable.DrawableCompat @@ -21,6 +24,7 @@ import es.verdnatura.presentation.common.OnMistakeClickListener import es.verdnatura.presentation.common.OnPackingClickSaleListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener import es.verdnatura.presentation.common.OnSaleClickSaleListener +import es.verdnatura.presentation.common.OnSaleReserveClickListener import es.verdnatura.presentation.common.OnTicketClickSaleListener import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.sacador.model.Sale @@ -33,6 +37,7 @@ class SaleAdapterNew( private val onPackingClick: OnPackingClickSaleListener, private var onTicketClick: OnTicketClickSaleListener? = null, private var saleAdapter: SaleAdapterNew? = null, + private var onReserveSaleClick: OnSaleReserveClickListener? = null, private var type: String? = null, ) : RecyclerView.Adapter() { @@ -117,16 +122,15 @@ class SaleAdapterNew( itemArticleFirstAccumulate.setOnClickListener { //onQuantityClick.onQuantityClick(sale) } - itemFirstToPicker.setOnClickListener { - onPackingClick.onPackingClick(sale) + /* itemFirstToPicker.setOnClickListener { + onPackingClick.onPackingClick(sale) - }/* quantityReserved.setOnClickListener { - onQuantityClick.onQuantityClick(sale) - }*/ + }/* quantityReserved.setOnClickListener { + onQuantityClick.onQuantityClick(sale) + }*/*/ linearLayoutItem.setOnClickListener { - println("El ticket es ${sale.ticketFk}") if (onTicketClick != null) { onTicketClick!!.onTicketClickListener(sale) } @@ -139,27 +143,31 @@ class SaleAdapterNew( } //ERROR - println("Sacador sale item ${sale.itemFk} sale ${sale.saleFk} cantidad ${sale.saleQuantity} original ${sale.originalQuantity}") if (sale.originalQuantity != sale.saleQuantity && sale.originalQuantity != null && !sale.isParent) { - layoutError.visibility = View.VISIBLE + layoutError.visibility = VISIBLE txtError.text = binding.root.context.getString(R.string.originalQuantity) + sale.originalQuantity } else { - layoutError.visibility = View.GONE + layoutError.visibility = GONE } + binding.deleteReserve.visibility = if (sale.isAdded == 1) VISIBLE else INVISIBLE + if (sale.isAdded == 1) { - layoutError.visibility = View.VISIBLE + layoutError.visibility = VISIBLE txtError.text = binding.root.context.getString(R.string.newItem) + binding.deleteReserve.setOnClickListener { + onReserveSaleClick!!.onSaleReserveListener(sale) + } } paintTicketcolor(sale.rgb, binding.itemTicketColor.background) - if (sale.isAdded == 1 && sale.reservedQuantity != sale.saleQuantity) { - layoutError.visibility = View.GONE - } + /*if (sale.isAdded == 1 && sale.reservedQuantity != sale.saleQuantity) { + layoutError.visibility = GONE + }*/ if (isExpanded) { @@ -339,9 +347,13 @@ class SaleAdapterNew( } binding.itemParkingCode.text = - if (type == PREITEMPICKERTEST) sale.parkingCodePrevia else sale.parkingCode + // if (type == PREITEMPICKERTEST) sale.parkingCodePrevia else sale.parkingCode + sale.parkingCodePrevia + println("parkingCodePrevia ${sale.parkingCodePrevia}") + println("parkingCode ${sale.parkingCode}") + this.sale = sale } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt index 1b095899..d55992a2 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionFragmentPickerPreviousNew.kt @@ -1,11 +1,14 @@ package es.verdnatura.presentation.view.feature.collection.fragment +import android.app.AlertDialog import android.content.Context import android.graphics.Color import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable import android.media.MediaPlayer import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.text.InputType import android.view.Gravity import android.view.KeyEvent @@ -13,6 +16,7 @@ import android.view.LayoutInflater import android.view.View import android.view.WindowManager import android.view.inputmethod.EditorInfo +import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.ImageView import android.widget.TextView @@ -22,8 +26,12 @@ import androidx.recyclerview.widget.RecyclerView import com.google.gson.Gson import es.verdnatura.R import es.verdnatura.databinding.FragmentCollectionNewBinding +import es.verdnatura.domain.ConstAndValues import es.verdnatura.domain.ConstAndValues.BASEURLSALIX +import es.verdnatura.domain.ConstAndValues.PREITEMPICKERTEST +import es.verdnatura.domain.ConstAndValues.PREPARED import es.verdnatura.domain.ConstAndValues.PRESACADOR +import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.ConstAndValues.SECTORFK import es.verdnatura.domain.notNull import es.verdnatura.domain.toast @@ -35,6 +43,7 @@ import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPackingClickSaleListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener import es.verdnatura.presentation.common.OnSaleClickSaleListener +import es.verdnatura.presentation.common.OnSaleReserveClickListener import es.verdnatura.presentation.common.OnTicketClickSaleListener import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.hideKeyboard @@ -58,6 +67,16 @@ import kotlinx.coroutines.runBlocking import org.json.JSONObject @Suppress("UNUSED_ANONYMOUS_PARAMETER") + +/*CAMBIO DEL SACADOR AL PRESACADOR, FUNCIONES EXTRA AL FINAL DEL FICHERO +1- EL SACADOR AGRUPA LINEAS EL PRESACADOR NO +2- AL AÑADIR ITEM A A LA COLECCIÓN , EL SACADOR SALEGROUPFK Y SECTORFK SON NULOS. +3-VERIFICAR COLECCIÓN +4-IMPRIMIR + +variables: +isVerifiedCollection + */ class CollectionFragmentPickerPreviousNew( var collection: CollectionTicket, var type: String = PRESACADOR, @@ -89,6 +108,7 @@ class CollectionFragmentPickerPreviousNew( private var quantityConfirm = 0 private lateinit var myGroupList: List private var quantityReserveToCheckItemScan = 0 + private var isVerifiedCollection = false companion object { fun newInstance( @@ -147,20 +167,25 @@ class CollectionFragmentPickerPreviousNew( iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp) val iconUpdate = ImageView(context) iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp) + val iconPrint = ImageView(context) + iconPrint.setImageResource(R.drawable.ic_print_black_24dp) iconAdd.tooltipText = getTooltip(R.drawable.ic_playlist_add_black_24dp) iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp) iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) + iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) + listIcons.add(iconAdd) - listIcons.add(iconParking) listIcons.add(iconUpdate) + if (type == PREPARED) listIcons.add(iconPrint) else listIcons.add(iconParking) binding.mainToolbar.toolbarIcons.adapter = ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { override fun onOptionsItemSelected(item: Drawable) { when (item) { + iconPrint.drawable -> print() iconAdd.drawable -> addItem() iconUpdate.drawable -> updateScreen() iconParking.drawable -> pasillerosItemClickListener?.onPasillerosItemClickListener( @@ -268,30 +293,31 @@ class CollectionFragmentPickerPreviousNew( } } + loadExistsResponse.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { - if (it.exists) { - markLine(it.position, it.quantity, true) - } else { - getString(R.string.updateSalesReserve).toast( - requireContext() - ) - viewModel.collectionTicketGetSalix(collection.collectionFk, false) - } - } - }/*responseExistsItemShelvingSale.observe(viewLifecycleOwner) { - if (!goBack) { - if (it.exists) { - markLine(it.position, it.quantity, true) - } else { - getString(R.string.updateSalesReserve).toast( - requireContext() - ) - viewModel.collectionTicketGetSalix(collection.collectionFk, false) - } - } - }*/ + getString(R.string.updateSalesReserve).toast( + requireContext() + ) + updateScreen() + } + } + + loadFindItemShelvingResponse.observe(viewLifecycleOwner) { event -> + event.getContentIfNotHandled().notNull { + + if (it.shelvingFk != myGroupList[it.position].code) { + getString(R.string.updateSalesReserve).toast( + requireContext() + ) + updateScreen() + } else { + markLine(it.position, it.quantity, true) + } + } + } + loadResponseAddItem.observe(viewLifecycleOwner) { event -> event.getContentIfNotHandled().notNull { @@ -372,8 +398,21 @@ class CollectionFragmentPickerPreviousNew( } // sales = salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) //quitar comentarios FALTA AGRUPAR LAS PREVIAS - myGroupList = - salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) + + when (type) { + PREITEMPICKERTEST -> { + myGroupList = + salesList.sortedWith(compareBy { it.pickingOrderPrevia }.thenBy { it.itemFk }) + } + + SACADOR -> { + myGroupList = + groupSaleGroup(salesList).sortedWith(compareBy { it.pickingOrder }.thenBy { it.itemFk }) + } + + } + + saleAdapter = SaleAdapterNew(myGroupList, pasillerosItemClickListener!!, object : OnSaleClickSaleListener { @@ -420,6 +459,11 @@ class CollectionFragmentPickerPreviousNew( ), entryPoint = entryPoint ) } + }, onReserveSaleClick = object : OnSaleReserveClickListener { + override fun onSaleReserveListener(sale: Sale) { + showDeleteItemShelving(sale) + } + }, type = type ) @@ -432,6 +476,29 @@ class CollectionFragmentPickerPreviousNew( setListPosition() setScrollListener(lm!!) printObservations(observations) + if (!isVerifiedCollection && type == PREPARED) { + binding.fragmentSacadorCollections.visibility = View.INVISIBLE + verifyCollection() + } + } + + private fun showDeleteItemShelving(sale: Sale) { + customDialog.setTitle(getString(R.string.deleteSale)) + .setDescription( + getString(R.string.deleteSaleDescrip) + getString( + R.string.sure + ) + ).setOkButton(getString(R.string.delete)) { + + viewModel.itemShelvingSaleDeleteIsAdded(sale.itemShelvingSaleFk) + scanRequest() + customDialog.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + scanRequest() + customDialog.dismiss() + }.show() + } private fun setScrollListener(lm: LinearLayoutManager) { @@ -555,6 +622,7 @@ class CollectionFragmentPickerPreviousNew( private fun printShelvingResult(pos: Int) { storedPosition = pos + customDialogList = CustomDialogList(requireContext()) customDialogList.getEditTextTwo().inputType = InputType.TYPE_CLASS_TEXT customDialogList.getEditTextTwo().setRawInputType(InputType.TYPE_CLASS_NUMBER) customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) @@ -713,13 +781,27 @@ class CollectionFragmentPickerPreviousNew( }.setOkButtonTwo(getString(R.string.no)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() - if (quantity == 0) { - viewModel.itemShelvingSaleExists( - myGroupList[position].itemShelvingSaleFk, position, quantity - ) - } else { - markLine(position, quantity, true) - } + viewModel.itemShelvingSaleExists( + myGroupList[position].itemShelvingSaleFk, + myGroupList[position].itemShelvingFk, + position, + quantity + ) + /* if (quantity == 0) { + + /* viewModel.itemShelvingGet( + myGroupList[position].itemShelvingFk, + position = position, + quantity = quantity + )*/ + } else { + //markLine(position, quantity, true) + viewModel.itemShelvingGet( + myGroupList[position].itemShelvingFk, + position = position, + quantity = quantity + ) + }*/ }.setKoButton(getString(R.string.cancel)) { scanRequest() customDialogThreeButtonsQuantity.dismiss() @@ -742,13 +824,13 @@ class CollectionFragmentPickerPreviousNew( .setOkButton(getString(R.string.Agregar)) { customDialogAddItem() }.setKoButton(getString(R.string.close)) { - scanRequest() customDialogList.dismiss() + scanRequest() + hideKeyboardFragment() }.setHintValue(getString(R.string.Artículo)).setValue("") .setHintValueTwo(getString(R.string.Cantidad)).setValueTwo("").show() customDialogList.getEditText().requestFocus() - requireActivity().hideKeyboard() - + hideKeyboardFragment() customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (customDialogList.getValue().isNotEmpty()) { @@ -807,22 +889,24 @@ class CollectionFragmentPickerPreviousNew( ) { getString(R.string.Todosloscampossonobligatorios).toast(requireContext()) } else { - val saleGroupSelected = - collection.tickets.find { it.ticketFk == ticketSelected }?.sales?.get(0)?.saleGroupFk - ?: 0 - runBlocking { - viewModel.collectionAddWithReservation( - customDialogList.getValue().toInt(), - customDialogList.getValueTwo().toInt(), - ticketSelected, - saleGroupFk = saleGroupSelected, - sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK) + viewModel.collectionAddWithReservation( + customDialogList.getValue().toInt(), + customDialogList.getValueTwo().toInt(), + ticketSelected, + saleGroupFk = if (type == PREPARED) null else collection.tickets.find { it.ticketFk == ticketSelected }?.sales?.get( + 0 + )?.saleGroupFk + ?: 0, + sectorFk = if (type == PREPARED) null else mobileApplication.dataStoreApp.readDataStoreKey( + SECTORFK ) - } + ) + customDialogList.dismiss() - hideKeyboards() - scanRequest() + customDialogList.cancel() + binding.scanInput.requestFocus() + hideKeyboardFragment() } } else { getString(R.string.scanItem).toast(requireContext()) @@ -830,6 +914,14 @@ class CollectionFragmentPickerPreviousNew( } + private fun hideKeyboardFragment() { + Handler(Looper.getMainLooper()).postDelayed({ + val inputMethodManager = + requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow(binding.scanInput.windowToken, 0) + }, 300L) + } + private fun toastDisponibility(item: ItemVO) { if (item.available.isEmpty()) { item.available = "0" @@ -844,6 +936,8 @@ class CollectionFragmentPickerPreviousNew( } private fun setTotalLines() { + println("total Mark ${myGroupList.count { it.isPicked == 1 }}") + println("total size ${myGroupList.size}") val totalMark = myGroupList.count { it.isPicked == 1 } binding.mainToolbar.toolbarTitle.text = if (collection.collectionFk != 0) collection.collectionFk.toString() else "" @@ -851,7 +945,20 @@ class CollectionFragmentPickerPreviousNew( getString(R.string.totalsPicker, totalMark, myGroupList.size) if (totalMark == myGroupList.size) { getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT) - viewModel.saleTrackingAddPrevOK(collection.collectionFk) + when (type) { + PREPARED -> { + tickets.forEach { + viewModel.ticketStateTodaySetState( + ticketFk = it.toInt(), state = "PREPARED" + ) + } + } + + PREITEMPICKERTEST -> { + viewModel.saleTrackingAddPrevOK(collection.collectionFk) + } + + } } } @@ -895,4 +1002,171 @@ class CollectionFragmentPickerPreviousNew( customDialog.dismiss() }.show() } + + private fun groupSaleGroup(salesList: ArrayList): MutableList { + val myMap = salesList.groupBy { it.saleGroupFk } + val myList: MutableList = mutableListOf() + + for ((key, value) in myMap.entries) { + if (key == null) { // si no tiene saleGroup se añaden las líneas + for (s in value) { + myList.add(s) + } + } else { // si tiene saleGroup se crea el padre con el tamaño e indicando que es padre, como ejemplo se toma el primer elemento + /*crea padre*/ + if (value.size > 1) { + val mySale = //= value[0] + Sale( + level = value[0].level, + isPicked = value[0].isPicked, + parkingCode = getString(R.string.linesSaelGroup, value.size), + pickingOrder = value[0].pickingOrder, + workerFk = value[0].workerFk, + originalQuantity = value[0].originalQuantity, + saleQuantity = 0, + saleFk = value[0].saleFk, + saleGroupFk = value[0].saleGroupFk, + semaphore = value[0].semaphore, + ticketFk = value[0].ticketFk, + itemFk = value[0].saleGroupFk!!, + isAdded = value[0].isAdded, + hasMistake = value[0].hasMistake, + origin = value[0].origin, + size = value[0].size, + itemShelvingSaleFk = value[0].itemShelvingSaleFk, + longName = value[0].parkingCode ?: "", + itemShelvingFk = 0 + ) + + //prime elemento//hay que hacer una copia si no queda la referencia + mySale.totalSales = value.size //total líneas + mySale.isParent = true + value as MutableList + mySale.sonSales = + value.sortedWith(compareBy { it.isPicked }) as MutableList + + myList.add(mySale) + } else { + for (s in value) { + myList.add(s) + } + } + + } + + } + + return myList + } + + /* FUNCIONES PROPIAS DE LOS SACADORES */ + private fun verifyCollection() { + + customDialogList.setTitle( + getString(R.string.verifyCollection) + ) + customDialogList.setDescription( + + getString(R.string.scanTicketsVerifyCollection, collection.collectionFk) + ).setKoButton(getString(R.string.cancel)) { + ma.hideKeyboard(customDialogList.getEditText()) + customDialogList.dismiss() + ma.onMyBackPressed() + }.setValue("").setOkButton(getString(R.string.print)) { + print() + }.show() + + customDialogList.getEditText().requestFocus() + ma.hideKeyboard(customDialogList.getEditText()) + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (customDialogList.getValue().isNotEmpty()) { + try { + customDialogList.setValue( + itemScanValue( + customDialogList.getValue(), arrayOf("ticket", "saleGroup"), "id" + ).toString() + ) + + val foundTicketInCollection = + collection.tickets.find { + it.ticketFk == customDialogList.getValue().toInt() + } + if (foundTicketInCollection != null) { + isVerifiedCollection = true + ma.hideKeyboard(customDialogList.getEditText()) + binding.fragmentSacadorCollections.visibility = View.VISIBLE + customDialogList.dismiss() + binding.scanInput.requestFocus() + } else { + + throw Exception(getString(R.string.ticketErrorCollection)) + } + + } catch (ex: Exception) { + ma.messageWithSound( + ex.message.toString(), isError = true, isPlayed = true, isToasted = true + ) + } + + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + + private fun print() { + if (ma.havePrinter() && ma.haveSector()) { + showDialogLabelCount() + } else { + ma.messageWithSound( + getString(R.string.printerFault), + isError = true, + true, + getString(R.string.printError), + false + ) + + } + + } + + private fun showDialogLabelCount() { + var isTicket = false + for (t in collection.tickets) { + if (t.ticketFk == (collection.collectionFk)) { + isTicket = true + } + } + if (isTicket) { + val builder = AlertDialog.Builder(context) + builder.setTitle(getString(R.string.selectLabeltoPrint)) + val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") + builder.setItems(labelCount) { dialog, which -> + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, labelCount = (which + 1) + ) + (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( + ConstAndValues.PRINTERNAME + )).toast(requireContext()) + + } + val dialog = builder.create() + dialog.show() + } else { + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, null + ) + + } + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt index 02fe38e6..516f1c8f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/CollectionViewModel.kt @@ -14,7 +14,7 @@ import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction import es.verdnatura.presentation.common.Event -import es.verdnatura.presentation.common.ResponseItemExistsItemShelvingSale +import es.verdnatura.presentation.common.ItemShelving import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.common.SaleTrackingReplaceSalix import es.verdnatura.presentation.common.SaleTrackingSalix @@ -44,13 +44,20 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val collectionTicketList: LiveData get() = _collectionTicketList - private val _responseExistsItemShelvingSale by lazy { MutableLiveData() } - val responseExistsItemShelvingSale: LiveData + private val _responseExistsItemShelvingSale by lazy { MutableLiveData() } + val responseExistsItemShelvingSale: LiveData get() = _responseExistsItemShelvingSale - val loadExistsResponse: LiveData> = + val loadExistsResponse: LiveData> = _responseExistsItemShelvingSale.map { Event(it) } + private val _responseItemShelvingFind by lazy { MutableLiveData() } + val responseItemShelvingFind: LiveData + get() = _responseItemShelvingFind + + val loadFindItemShelvingResponse: LiveData> = + _responseItemShelvingFind.map { Event(it) } + private val _collectionTicketSalix by lazy { MutableLiveData() } val collectionTicketSalix: LiveData get() = _collectionTicketSalix @@ -73,6 +80,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { private val _responseSaleMistakeAdd by lazy { MutableLiveData() } val responseSaleMistakeAdd: LiveData get() = _responseSaleMistakeAdd + val loadSaleMistakeAdd: LiveData> = + _responseSaleMistakeAdd.map { Event(it) } private val _responseItemShelvingSaleSupplyAdd by lazy { MutableLiveData() } val responseItemShelvingSaleSupplyAdd: LiveData @@ -107,10 +116,17 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseCollectionAddItem: LiveData get() = _responseCollectionAddItem + private val _responseItemShelvingSaleDelete by lazy { MutableLiveData() } + val responseItemShelvingSaleDelete: LiveData = _responseItemShelvingSaleDelete + val loadResponseDelete: LiveData> = + _responseItemShelvingSaleDelete.map { Event(it) } + private val _responseParking by lazy { MutableLiveData() } val responseParking: LiveData get() = _responseParking + val loadParking: LiveData> = _responseParking.map { Event(it) } + private val _responsePrint by lazy { MutableLiveData() } val responsePrint: LiveData get() = _responsePrint @@ -126,6 +142,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { private val _responseTicketState by lazy { MutableLiveData() } val responseTicketState: LiveData = _responseTicketState + val loadTicketState: LiveData> = _responseTicketState.map { Event(it) } + private val _responseUsedShelves by lazy { MutableLiveData() } val responseUsedShelves: LiveData get() = _responseUsedShelves @@ -134,6 +152,9 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseSaleGroup: LiveData get() = _responseSaleGroup + val loadResponseSaleGroup: LiveData> = + _responseSaleGroup.map { Event(it) } + private val _responseItemShelvingSaleGroup by lazy { MutableLiveData() } val responseItemShelvingSaleGroup: LiveData get() = _responseItemShelvingSaleGroup @@ -141,6 +162,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { private val _responseTicketClosure by lazy { MutableLiveData() } val responseTicketClosure: LiveData get() = _responseTicketClosure + val loadTicketClousure: LiveData> = + _responseTicketClosure.map { Event(it) } private val _responseCollectionUnchecked by lazy { MutableLiveData() } val responseCollectionUnchecked: LiveData @@ -154,6 +177,8 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { val responseNew: LiveData get() = _responseNew + val loadAddNew: LiveData> = _responseNew.map { Event(it) } + private val _responseCode by lazy { MutableLiveData() } val responseCode: LiveData get() = _responseCode @@ -161,6 +186,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { private val _responseIncQuantity by lazy { MutableLiveData() } val responseIncQuantity: LiveData get() = _responseIncQuantity + val loadIncQuantity: LiveData> = _responseIncQuantity.map { Event(it) } private val _mistakeList by lazy { MutableLiveData() } val mistakeList: LiveData @@ -286,7 +312,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { } fun itemShelvingSaleExists( - itemShelvingSaleFk: Number, position: Int, quantity: Int + itemShelvingSaleFk: Number, itemShelvingFk: Number, position: Int, quantity: Int ) { salix.itemShelvingSaleExists( @@ -294,9 +320,39 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { ).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _responseExistsItemShelvingSale.value = ResponseItemExistsItemShelvingSale( + + if (response.body()!!.entrySet().first().value.asBoolean) { + itemShelvingGet(itemShelvingFk, position, quantity) + } else { + _responseExistsItemShelvingSale.value = false + } + /*_responseExistsItemShelvingSale.value = ResponseItemExistsItemShelvingSale( response.body()!!.entrySet().first().value.asBoolean, position, quantity + )*/ + } + }) + } + + fun itemShelvingGet( + itemShelvingFk: Number, position: Int, quantity: Int + + ) { + salix.itemShelvingGet( + id = itemShelvingFk + ).enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + val itemShelving: ItemShelving = response.body()!! + itemShelving.position = position + itemShelving.quantity = quantity + _responseItemShelvingFind.value = ItemShelving( + itemShelving.id, + itemFk = itemShelving.itemFk, + shelvingFk = itemShelving.shelvingFk, + position = position, + quantity = quantity ) + } }) } @@ -391,6 +447,21 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { }) } + fun itemShelvingSaleDeleteIsAdded( + itemShelvingSale: Number + ) { + salix.itemShelvingSaleDeleteAdded( + params = arrayListOf( + itemShelvingSale + ) + ).enqueue(object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _responseCollectionAddItem.value = true + } + + }) + } + fun collectionAddWithReservation( item: Int, quantity: Int, ticketSelected: Int, saleGroupFk: Int?, sectorFk: Int? ) { @@ -523,7 +594,7 @@ class CollectionViewModel(val context: Context) : BaseViewModel(context) { override fun onSuccess(response: Response) { //Tarea 7926 - updateParkingFromSaleGroup(saleGroupFk) + // updateParkingFromSaleGroup(saleGroupFk) _responseSaleGroup.value = ResponseItemVO(isError = false) } }) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt index 3827f7da..b15ed2f5 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/controlador/fragment/ControladorFragment.kt @@ -31,7 +31,6 @@ class ControladorFragment : } override fun init() { - binding.scanInput.visibility = VISIBLE binding.mainToolbar.toolbarTitle.text = getString(R.string.controlticket) setEvents() @@ -107,7 +106,7 @@ class ControladorFragment : } responseTicketState.observe( - viewLifecycleOwner + viewLifecycleOwner ) { if ((it.code == "ON_CHECKING" || it.code == "CHECKED") && it.user.id != mobileApplication.userId) { val customDialogWarning = CustomDialog(requireContext()) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt index d570f67b..9c24830b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/presacador/fragment/SectorCollectionReserveFragment.kt @@ -11,7 +11,6 @@ import es.verdnatura.R import es.verdnatura.databinding.FragmentGeneralBlackBinding import es.verdnatura.domain.ConstAndValues import es.verdnatura.domain.notNull -import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener @@ -38,6 +37,8 @@ class SectorCollectionReserveFragment( private var listSaleGroupAdapter: BarcodeAdapter? = null private var onBack = false private var isReserved = false + private var listTickets: ArrayList = ArrayList() + private var listTicketsAdapter: BarcodeAdapter? = null val listIcons: ArrayList = ArrayList() @@ -146,9 +147,18 @@ class SectorCollectionReserveFragment( try { //Reservar colección if (!hasToAdd) { + /* if (listTickets.isNotEmpty()) { + listTickets.forEach { item -> + viewModel.getReserveBySectorCollection(item.code!!.toInt()) + } + }*/ viewModel.getReserveBySectorCollection(collectionFk) + } else { - gotoPicker() + hasToAdd = false + viewModel.getReserveBySectorCollection(collectionFk) + + //gotoPicker() } } catch (ex: Exception) { ma.messageWithSound( @@ -235,27 +245,27 @@ class SectorCollectionReserveFragment( } binding.scanInput.requestFocus() - binding.scanInput.setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + /* binding.scanInput.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { - if (binding.scanInput.text.toString().isNotEmpty()) { + if (binding.scanInput.text.toString().isNotEmpty()) { - try { - navigateToCollectionList(binding.scanInput.text.toString().toInt()) + try { + navigateToCollectionList(binding.scanInput.text.toString().toInt()) - } catch (ex: Exception) { - ex.message!!.toast(requireContext()) + } catch (ex: Exception) { + ex.message!!.toast(requireContext()) - } + } - binding.scanInput.setText("") - ma.hideKeyboard(binding.scanInput) - } - return@setOnEditorActionListener true - } - return@setOnEditorActionListener false - } + binding.scanInput.setText("") + ma.hideKeyboard(binding.scanInput) + } + return@setOnEditorActionListener true + } + return@setOnEditorActionListener false + }*/ } @@ -310,7 +320,7 @@ class SectorCollectionReserveFragment( listSaleGroupAdapter!!.notifyItemInserted(listSalesGroup.size - 1) if (hasToAdd) { - viewModel.getReserveBySaleGroup(it) + // viewModel.getReserveBySaleGroup(it) } } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt index 7bd00646..c1ba0760 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorFragmentNew.kt @@ -27,8 +27,7 @@ import java.util.Calendar class SacadorFragmentNew( var type: String -) : - BaseFragment(SacadorViewModel::class) { +) : BaseFragment(SacadorViewModel::class) { private var onCollectionSelectedListener: OnCollectionTicketSelectedListener? = null private var goBack: Boolean = false @@ -107,7 +106,7 @@ class SacadorFragmentNew( iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) if (type == "PREPARED") { - listIcons.add(iconVehicleIn) + // listIcons.add(iconVehicleIn) } else { listIcons.add(iconPrint) } @@ -122,12 +121,10 @@ class SacadorFragmentNew( iconAdd.drawable -> { if (type == "PREPARED") { - if (hasSector()) - viewModel.collection_assignNew( + if (hasSector()) viewModel.collection_assignNew( ) } else { - if (hasSector()) - viewModel.sectorCollectionNew( + if (hasSector()) viewModel.sectorCollectionNew( mobileApplication.dataStoreApp.readDataStoreKey( SECTORFK ) @@ -151,8 +148,7 @@ class SacadorFragmentNew( customDialogInput.setInputText(InputType.TYPE_CLASS_NUMBER) customDialogInput.setTitle(getString(R.string.printTicket)) - customDialogInput.setDescription(getString(R.string.printPreviousGroup)) - .setValue("") + customDialogInput.setDescription(getString(R.string.printPreviousGroup)).setValue("") .setOkButton(getString(R.string.print)) { print() @@ -178,8 +174,7 @@ class SacadorFragmentNew( private fun print() { try { - if (customDialogInput.getValue().isNotEmpty() - ) { + if (customDialogInput.getValue().isNotEmpty()) { if (ma.havePrinter()) { viewModel.ticketPrintLabelPrevious(customDialogInput.getValue().toInt()) (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( @@ -224,7 +219,8 @@ class SacadorFragmentNew( it.list.forEach { //lolass - var myDate = getCalendarForDateMinusOneDay(requireContext()).convertToDateString() + var myDate = + getCalendarForDateMinusOneDay(requireContext()).convertToDateString() if (!it.created.contains(myDate)) { myCollectionsList.add(CollectionTicket(it.collectionFk, it.created)) } @@ -236,11 +232,20 @@ class SacadorFragmentNew( response.observe(viewLifecycleOwner) { if (it.isError) { - ma.messageWithSound(it.errorMessage, isError = true, isPlayed = false) + ma.messageWithSound( + it.errorMessage, + isError = true, + isPlayed = true, + isToasted = true + ) } else { if (it.response.isNotBlank()) { - addCollectionToList(it.response.toInt()) + if (collectionsList.isNotEmpty()) { + addCollectionToList(it.response.toInt()) + } else { + callBack(type) + } } else { when (type) { @@ -306,8 +311,7 @@ class SacadorFragmentNew( if (isNew) { collectionsList.add( CollectionTicket( - collectionFk = collection, - created = getString(R.string.newCreated) + collectionFk = collection, created = getString(R.string.newCreated) ) ) } else { @@ -319,6 +323,7 @@ class SacadorFragmentNew( } adapter?.notifyDataSetChanged() } + private fun hasSector(): Boolean { return if (ma.haveSector()) { true diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt index 4e809f79..654b9b3b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/fragment/SacadorViewModel.kt @@ -123,7 +123,6 @@ class SacadorViewModel(val context: Context) : BaseViewModel(context) { fun collection_assignNew() { salix.collectionAssigned() - // silex.collection_assign() .enqueue( object : SalixCallback(context) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt index 2246aa91..157576ff 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/sacador/model/TicketItemVO.kt @@ -30,6 +30,7 @@ data class Ticket( data class Sale( val itemShelvingSaleFk: Int, + val itemShelvingFk: Int, val ticketFk: Int, val saleGroupFk: Int?, val saleFk: Int, diff --git a/app/src/main/res/layout/fragment_collection.xml b/app/src/main/res/layout/fragment_collection.xml index baead6cd..918af63c 100644 --- a/app/src/main/res/layout/fragment_collection.xml +++ b/app/src/main/res/layout/fragment_collection.xml @@ -51,11 +51,12 @@ android:id="@+id/fragment_sacador_collections" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="8dp" + android:layout_marginTop="4dp" tools:listitem="@layout/item_article_row_fragment" /> + - + android:orientation="vertical"> + android:textColor="@color/verdnatura_black"> + android:orientation="horizontal"> + + android:contentDescription="@string/selectAction" + android:rotation="180" + android:src="@drawable/ic_arrow_down" /> + + android:contentDescription="@string/error" + app:srcCompat="@drawable/emoticon_error_fragment" /> - + app:layout_constraintTop_toTopOf="parent"> @@ -226,9 +215,9 @@ android:layout_height="wrap_content" android:layout_marginEnd="@dimen/layout_margin_min" android:text="@string/de" - android:visibility="gone" android:textColor="@color/verdnatura_white" android:textSize="@dimen/body1" + android:visibility="gone" app:layout_constraintEnd_toStartOf="@+id/item_article_quantityOld" app:layout_constraintTop_toTopOf="parent" /> @@ -239,12 +228,12 @@ android:layout_marginEnd="22dp" android:paddingStart="10dp" android:paddingEnd="10dp" - android:visibility="gone" - android:text="@{Integer.toString(sale.quantity)}" + android:textColor="@color/verdnatura_white" android:textSize="@dimen/body1" android:textStyle="bold" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" tool:text="10" /> @@ -354,8 +343,8 @@ android:text="@{sale.cel2}" android:textColor="@color/verdnatura_white" android:textSize="@dimen/body3" - android:visibility="gone" android:textStyle="bold" + android:visibility="gone" app:layout_constraintEnd_toEndOf="@+id/item_article_quantity_line2" app:layout_constraintTop_toTopOf="@+id/item_article_quantity_line2" tool:text="cel2" /> @@ -365,17 +354,16 @@ android:id="@+id/item_article_quantity" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingStart="@dimen/layout_collection_quantity" android:paddingTop="@dimen/layout_margin_minest" android:paddingBottom="@dimen/default_layout_margin" - android:paddingStart="@dimen/layout_collection_quantity" android:text="@{Integer.toString(sale.quantity)}" android:textColor="@color/verdnatura_white" android:textSize="@dimen/body3" android:textStyle="bold" app:layout_constraintEnd_toEndOf="@+id/item_article_quantity_line2" app:layout_constraintTop_toTopOf="@+id/item_article_quantity_line2" - tool:text="100" - /> + tool:text="100" /> - + android:layout_height="@dimen/layout_margin_prepicker" + android:orientation="horizontal"> - - - - + + android:visibility="gone" + tool:visibility="visible"> + + + 2dp 1dp 4dp - 8dp + 4dp 10dp 16dp 20dp @@ -118,7 +118,7 @@ - 90dp + 80dp 10dp