feat: refs #7266 printItem

This commit is contained in:
Sergio De la torre 2024-11-04 09:17:24 +01:00
parent 1f4663e68f
commit 7c2e418e87
11 changed files with 357 additions and 117 deletions

View File

@ -14,7 +14,15 @@ import java.util.Date
import java.util.Locale import java.util.Locale
fun List<Any?>.formatWithQuotes(): String { fun List<Any?>.formatWithQuotes(): String {
return "[" + joinToString(", ") { if (it is String) "\"$it\"" else it.toString() } + "]" return "[" + joinToString(", ") {
when {
it is String && (it.trim().startsWith("{") && it.trim()
.endsWith("}")) -> "\"$it\""
it is String -> "\"$it\""
else -> it.toString()
}
} + "]"
} }
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
@ -45,6 +53,7 @@ fun String.isParking(): Boolean {
val regex = Regex("^[^ ]+-[^ ]+$") val regex = Regex("^[^ ]+-[^ ]+$")
return this.length > 4 && regex.matches(this) return this.length > 4 && regex.matches(this)
} }
fun String.isShelving(): Boolean { fun String.isShelving(): Boolean {
val regex = Regex("\\S{0,4}") val regex = Regex("\\S{0,4}")
return regex.matches(this) return regex.matches(this)

View File

@ -1,12 +1,20 @@
package es.verdnatura.domain.userCases package es.verdnatura.domain.userCases
import es.verdnatura.domain.SalixService import es.verdnatura.domain.SalixService
import retrofit2.Call import retrofit2.Call
class GetItemFromBarcodeUseCase(private val salixService: SalixService) { class GetItemFromBarcodeUseCase(private val salixService: SalixService) {
fun execute(barcode: String): Call<Int?> { fun execute(barcode: String): Call<Int?> {
return salixService.barcodesToItem(barcode) return salixService.barcodesToItem(barcode)
} }
} }
class GetItemPrintItemUseCase(private val salixService: SalixService) {
fun execute(params: Any?): Call<Unit> {
return salixService.printItem(params)
}
fun executeBuyUltimate(params: Any): Call<Long> {
return salixService.buyUltimate(params)
}
}

View File

@ -8,49 +8,43 @@ import com.google.android.material.textfield.TextInputEditText
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.databinding.ComponentCustomListDialogBinding import es.verdnatura.databinding.ComponentCustomListDialogBinding
//import kotlinx.android.synthetic.main.component_custom_list_dialog.*
class CustomDialogList(context: Context) : Dialog(context, R.style.DialogTheme) { class CustomDialogList(context: Context) : Dialog(context, R.style.DialogTheme) {
private var binding: ComponentCustomListDialogBinding = private var binding: ComponentCustomListDialogBinding =
ComponentCustomListDialogBinding.inflate(layoutInflater) ComponentCustomListDialogBinding.inflate(layoutInflater)
init { init {
setContentView(binding.root) setContentView(binding.root)
getEditText().requestFocus() getEditText().requestFocus()
//setContentView(R.layout.component_custom_list_dialog)
} }
fun getRecyclerView(): RecyclerView { fun getRecyclerView(): RecyclerView {
return binding.itemRecyclerview return binding.itemRecyclerview
//return item_recyclerview
} }
fun getEditText(): TextInputEditText { fun getEditText(): TextInputEditText {
return binding.customDialogValue return binding.customDialogValue
//return custom_dialog_value
} }
fun getEditTextTwo(): TextInputEditText { fun getEditTextTwo(): TextInputEditText {
return binding.customDialogValueTwo return binding.customDialogValueTwo
//return custom_dialog_value_two }
fun getEditTextThree(): TextInputEditText {
return binding.customDialogValueThree
} }
fun getValue(): String { fun getValue(): String {
return binding.customDialogValue.text.toString() return binding.customDialogValue.text.toString()
//return custom_dialog_value.text.toString() }
fun getValueOptional(): String {
return binding.customDialogValueThree.text.toString()
} }
fun setValue(value: String): CustomDialogList { fun setValue(value: String): CustomDialogList {
binding.customDialogValue.setText(value) binding.customDialogValue.setText(value)
binding.textinputlayoutUsername.visibility = View.VISIBLE binding.textinputlayoutUsername.visibility = View.VISIBLE
/*custom_dialog_value.setText(value)
textinputlayout_username.visibility = View.VISIBLE*/
return this return this
} }
@ -61,96 +55,92 @@ class CustomDialogList(context: Context) : Dialog(context, R.style.DialogTheme)
fun getValueTwo(): String { fun getValueTwo(): String {
return binding.customDialogValueTwo.text.toString() return binding.customDialogValueTwo.text.toString()
//return custom_dialog_value_two.text.toString()
} }
fun setValueTwo(value: String): CustomDialogList { fun setValueTwo(value: String): CustomDialogList {
binding.customDialogValueTwo.setText(value) binding.customDialogValueTwo.setText(value)
binding.textinputlayoutTwo.visibility = View.VISIBLE binding.textinputlayoutTwo.visibility = View.VISIBLE
/* custom_dialog_value_two.setText(value)
textinputlayout_two.visibility = View.VISIBLE*/
return this return this
} }
fun setTitle(title: String): CustomDialogList { fun setTitle(title: String): CustomDialogList {
binding.customDialogTitle.visibility = View.VISIBLE binding.customDialogTitle.visibility = View.VISIBLE
binding.customDialogTitle.text = title binding.customDialogTitle.text = title
/* custom_dialog_title.visibility = View.VISIBLE
custom_dialog_title.text = title*/
return this return this
} }
fun setDescription(title: String): CustomDialogList { fun setDescription(title: String): CustomDialogList {
binding.customDialogDescription.visibility = View.VISIBLE binding.customDialogDescription.visibility = View.VISIBLE
binding.customDialogDescription.text = title binding.customDialogDescription.text = title
/*custom_dialog_description.visibility = View.VISIBLE
custom_dialog_description.text = title*/
return this return this
} }
fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogList { fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogList {
binding.customDialogButtonOk.visibility = View.VISIBLE binding.customDialogButtonOk.visibility = View.VISIBLE
binding.customDialogButtonOk.text = text binding.customDialogButtonOk.text = text
/*custom_dialog_button_ok.visibility = View.VISIBLE
custom_dialog_button_ok.text = text
custom_dialog_button_ok.setOnClickListener { onButtonClicked() }*/
binding.customDialogButtonOk.setOnClickListener { onButtonClicked() } binding.customDialogButtonOk.setOnClickListener { onButtonClicked() }
return this return this
} }
fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogList { fun setOkTwoButton(text: String, onButtonClicked: () -> Unit): CustomDialogList {
binding.customDialogButtonOkTwo.visibility = View.VISIBLE
binding.customDialogButtonOkTwo.text = text
binding.customDialogButtonOkTwo.setOnClickListener { onButtonClicked() }
return this
}
fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogList {
binding.customDialogButtonKo.visibility = View.VISIBLE binding.customDialogButtonKo.visibility = View.VISIBLE
binding.customDialogButtonKo.text = text binding.customDialogButtonKo.text = text
/*custom_dialog_button_ko.visibility = View.VISIBLE
custom_dialog_button_ko.text = text*/
binding.customDialogButtonKo.setOnClickListener { binding.customDialogButtonKo.setOnClickListener {
onButtonClicked() onButtonClicked()
dismiss() dismiss()
} }
return this return this
} }
fun setHintValue(text: String): CustomDialogList { fun setHintValue(text: String): CustomDialogList {
binding.customDialogValue.hint = text binding.customDialogValue.hint = text
// custom_dialog_value.hint = text
return this return this
} }
fun setHintValueTwo(text: String): CustomDialogList { fun setHintValueTwo(text: String): CustomDialogList {
binding.customDialogValueTwo.hint = text binding.customDialogValueTwo.hint = text
//custom_dialog_value_two.hint = text
return this return this
} }
fun setTextTwoGone(): CustomDialogList { fun setHintValueThree(text: String): CustomDialogList {
binding.textinputlayoutTwo.visibility = View.GONE binding.customDialogValueThree.hint = text
//textinputlayout_two.visibility = View.GONE return this
}
fun setTextTwoVisibility(visibility: Int): CustomDialogList {
binding.textinputlayoutTwo.visibility = visibility
return this
}
fun setTextThree(visibility: Int): CustomDialogList {
binding.textinputlayoutThree.visibility = visibility
return this return this
} }
fun hideDialog(): CustomDialogList { fun hideDialog(): CustomDialogList {
binding.customDialogValue.visibility = View.GONE binding.customDialogValue.visibility = View.GONE
//custom_dialog_value.visibility = View.GONE
return this return this
} }
fun hideDescription(): CustomDialogList { fun hideDescription(): CustomDialogList {
binding.customDialogDescription.visibility = View.GONE binding.customDialogDescription.visibility = View.GONE
return this return this
} }
fun hideTextInput(visibility:Int = View.INVISIBLE): CustomDialogList { fun hideTextInput(visibility: Int = View.INVISIBLE): CustomDialogList {
binding.textinputlayoutUsername.visibility = visibility binding.textinputlayoutUsername.visibility = visibility
return this return this
} }
fun getFocusThree() {
binding.customDialogValueThree.requestFocus()
}
} }

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson import com.google.gson.Gson
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.databinding.FragmentItemCardBinding import es.verdnatura.databinding.FragmentItemCardBinding
import es.verdnatura.domain.ConstAndValues.PRINTERFK
import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK
import es.verdnatura.domain.notNull import es.verdnatura.domain.notNull
import es.verdnatura.domain.toast import es.verdnatura.domain.toast
@ -19,7 +20,9 @@ import es.verdnatura.presentation.common.OnBarcodeRowClickListener
import es.verdnatura.presentation.common.OnClickDynamic import es.verdnatura.presentation.common.OnClickDynamic
import es.verdnatura.presentation.common.OnItemCardRowClickListener import es.verdnatura.presentation.common.OnItemCardRowClickListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.PrinterDialogManager
import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.common.hideKeyboard
import es.verdnatura.presentation.common.itemScanValue import es.verdnatura.presentation.common.itemScanValue
import es.verdnatura.presentation.common.loadUrl import es.verdnatura.presentation.common.loadUrl
import es.verdnatura.presentation.view.component.CustomDialogDynamicButtons import es.verdnatura.presentation.view.component.CustomDialogDynamicButtons
@ -53,6 +56,8 @@ class ItemCardFragment(
private var quantityToDiscard = 0 private var quantityToDiscard = 0
private var itemInfoG: ItemCardVO? = null private var itemInfoG: ItemCardVO? = null
private var positionToReturnY = 0 private var positionToReturnY = 0
private var originalScan: String? = null
private var buyToPrint: Long? = null
companion object { companion object {
fun newInstance(entryPoint: String) = ItemCardFragment(entryPoint) fun newInstance(entryPoint: String) = ItemCardFragment(entryPoint)
@ -95,15 +100,20 @@ class ItemCardFragment(
iconHistory.setImageResource(R.drawable.ic_history_black_24dp) iconHistory.setImageResource(R.drawable.ic_history_black_24dp)
val iconSalix = ImageView(context) val iconSalix = ImageView(context)
iconSalix.setImageResource(R.drawable.ic_logo_salix) iconSalix.setImageResource(R.drawable.ic_logo_salix)
val iconPrint = ImageView(context)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
iconReload.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp) iconReload.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp)
iconHistory.tooltipText = getTooltip(R.drawable.ic_history_black_24dp) iconHistory.tooltipText = getTooltip(R.drawable.ic_history_black_24dp)
iconSalix.tooltipText = getTooltip(R.drawable.ic_logo_salix) iconSalix.tooltipText = getTooltip(R.drawable.ic_logo_salix)
// Tarea 7266
// iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp)
listIcons.add(iconSalix) listIcons.add(iconSalix)
listIcons.add(iconReload) listIcons.add(iconReload)
listIcons.add(iconHistory) listIcons.add(iconHistory)
listIcons.add(iconPrint)
binding.mainToolbar.toolbarIcons.adapter = binding.mainToolbar.toolbarIcons.adapter =
@ -112,6 +122,25 @@ class ItemCardFragment(
override fun onOptionsItemSelected(item: Drawable) { override fun onOptionsItemSelected(item: Drawable) {
when (item) { when (item) {
iconPrint.drawable -> {
if (buyToPrint != null) {
val printerDialogManager = PrinterDialogManager(requireContext())
printerDialogManager.showPrintDialog(
itemInfoG!!.id.toLong(),
itemInfoG?.longName ?: ""
) { id, labelType, copies, packing ->
printItem(id, labelType, copies, packing)
}
} else ma.messageWithSound(
getString(R.string.errorPrintBuy),
isError = true,
isPlayed = true
)
}
iconReload.drawable -> { iconReload.drawable -> {
getItemCard(itemInfoG!!.id.toString()) getItemCard(itemInfoG!!.id.toString())
} }
@ -152,16 +181,38 @@ class ItemCardFragment(
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
} }
private fun printItem(id: Long, labelType: String, packing: Int?, copies: Int?) {
try {
viewModel.printItem(
reportName = "LabelBuy",
printerFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
PRINTERFK
),
userFk = mobileApplication.userId!!,
priority = "normal",
params = """{'copies':$copies,'id':$id,'labelType':'$labelType','packing':$packing}"""
)
} catch (ex: Exception) {
ma.messageWithSound(message = ex.message.toString(), isError = true, isPlayed = true)
}
customDialogList.dismiss()
hideKeyboard()
}
private fun setEvents() { private fun setEvents() {
binding.editItemFk.requestFocus() binding.editItemFk.requestFocus()
binding.editItemFk.setOnEditorActionListener { _, actionId, _ -> binding.editItemFk.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (binding.editItemFk.text.toString().isNotEmpty()) try { if (binding.editItemFk.text.toString().isNotEmpty())
getItemCard( try {
itemScanValue( originalScan = itemScanValue(
binding.editItemFk.text.toString(), arrayOf("buy"), "more" binding.editItemFk.text.toString(), arrayOf("buy"), "more"
).toString() ).toString()
getItemCard(
originalScan!!
) )
} catch (ex: Exception) { } catch (ex: Exception) {
ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true) ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true)
@ -196,7 +247,6 @@ class ItemCardFragment(
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) as Int warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) as Int
itemFk = itemValueFk itemFk = itemValueFk
viewModel.getItemCard(itemFk.toLong(), warehouseFk!!) viewModel.getItemCard(itemFk.toLong(), warehouseFk!!)
} }
@ -210,6 +260,19 @@ class ItemCardFragment(
binding.itemcardLayout.visibility = View.VISIBLE binding.itemcardLayout.visibility = View.VISIBLE
setItemCard(it) setItemCard(it)
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
/* Tarea 7266
if (originalScan == null || it.id == originalScan!!.toInt()) {
viewModel.buyUltimate(
itemFk = it.id,
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(
WAREHOUSEFK
),
dated = LocalDate.now()
.format(DateTimeFormatter.ofPattern("yyyy-dd-MM"))
)
} else {
buyToPrint = originalScan!!.toLong()
}*/
} else { } else {
binding.itemcardLayout.visibility = GONE binding.itemcardLayout.visibility = GONE
binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard) binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard)
@ -237,6 +300,11 @@ class ItemCardFragment(
} }
} }
loadBuyUltimateResponse.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
buyToPrint = it
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import androidx.lifecycle.map
import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
import es.verdnatura.domain.userCases.GetItemPrintItemUseCase
import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.ItemBarCodeSalix import es.verdnatura.presentation.common.ItemBarCodeSalix
@ -25,6 +26,7 @@ import java.io.File
class ItemCardViewModel(var context: Context) : BaseViewModel(context) { class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
private val printItemUseCase = GetItemPrintItemUseCase(salix)
private val _itemCard by lazy { MutableLiveData<ItemCardVO>() } private val _itemCard by lazy { MutableLiveData<ItemCardVO>() }
val itemCard: LiveData<ItemCardVO> val itemCard: LiveData<ItemCardVO>
@ -48,6 +50,10 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
val loadAddressLosesList: LiveData<Event<AddressLosesList>> = val loadAddressLosesList: LiveData<Event<AddressLosesList>> =
_addressLosesList.map { Event(it) } _addressLosesList.map { Event(it) }
private val _buyUltimateResponse by lazy { MutableLiveData<Long>() }
val buyUltimateResponse: LiveData<Long> = _buyUltimateResponse
val loadBuyUltimateResponse: LiveData<Event<Long>> = _buyUltimateResponse.map { Event(it) }
fun getItemCard( fun getItemCard(
itemFk: Number, itemFk: Number,
warehouseFk: Int, warehouseFk: Int,
@ -63,6 +69,28 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
}) })
} }
fun printItem(
reportName: String,
printerFk: Int,
userFk: Int,
params: Any,
priority: String
) {
printItemUseCase.execute(
params = arrayListOf(
reportName,
printerFk,
userFk,
params,
priority
).formatWithQuotes()
)
.enqueue(object : SalixCallback<Unit>(context) {
})
}
fun itemGetSimilar( fun itemGetSimilar(
itemFk: Int, itemFk: Int,
warehouseFk: Int, warehouseFk: Int,
@ -210,4 +238,15 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
} }
}) })
} }
fun buyUltimate(
itemFk: Int, warehouseFk: Int, dated: String
) {
salix.buyUltimate(params = arrayListOf(itemFk, warehouseFk, dated).formatWithQuotes())
.enqueue(object : SalixCallback<Long>(context) {
override fun onSuccess(response: Response<Long>) {
_buyUltimateResponse.value = response.body()
}
})
}
} }

View File

@ -10,7 +10,7 @@ class ItemCardVO(
var size: Int? = null, var size: Int? = null,
var stems: String? = null, var stems: String? = null,
var itemCost: String? = null, var itemCost: String? = null,
var category:String? = null, var category: String? = null,
var producer: String? = null, var producer: String? = null,
var origin: String? = null, var origin: String? = null,
var reserva: Int? = null, var reserva: Int? = null,
@ -46,13 +46,20 @@ class ItemCardRowVO(
class BarcodeVO( class BarcodeVO(
var code: String? var code: String?
) )
data class ItemDetails( data class ItemDetails(
var itemFk: Int? = null, var itemFk: Int? = null,
var vShelvingFK: String = "", var vShelvingFK: String = "",
var itemCost: Double = 0.0, var itemCost: Double = 0.0,
var visible: Int = 0, var visible: Int = 0,
)
data class ItemPrint(
val id: Int,
val labelType: String,
val packing: Int? = null,
val copies: Int? = 1
) )

View File

@ -15,6 +15,7 @@ import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.databinding.FragmentUbicadorBinding import es.verdnatura.databinding.FragmentUbicadorBinding
import es.verdnatura.domain.ConstAndValues
import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK
import es.verdnatura.domain.isShelving import es.verdnatura.domain.isShelving
import es.verdnatura.domain.notNull import es.verdnatura.domain.notNull
@ -28,6 +29,7 @@ import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.OnVisibleClickListenerNew import es.verdnatura.presentation.common.OnVisibleClickListenerNew
import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.common.hideKeyboard
import es.verdnatura.presentation.common.itemScanValue import es.verdnatura.presentation.common.itemScanValue
import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogInput import es.verdnatura.presentation.view.component.CustomDialogInput
@ -39,6 +41,7 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapterNew
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import kotlin.math.ceil
@Suppress("UNUSED_ANONYMOUS_PARAMETER") @Suppress("UNUSED_ANONYMOUS_PARAMETER")
class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>( class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewModel>(
@ -519,15 +522,27 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
with(viewModel) { with(viewModel) {
loadShelvingListNew.observe(viewLifecycleOwner) { event -> loadShelvingListNew.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { event.getContentIfNotHandled().notNull { it ->
if (isShelvinLogfromMainScreen) { if (isShelvinLogfromMainScreen) {
viewModel.shelvingLogAdd(shelvingFk) viewModel.shelvingLogAdd(shelvingFk)
} }
listItems = ArrayList()
val totalStickers = it.list.sumOf { item -> item.stickers }
parking = it.list.firstOrNull { item -> item.code != null }?.code ?: ""
listItems.addAll(it.list) listItems.addAll(it.list)
listItems.forEach { item ->
println("description **************************${item.description}")
println("description ${item.description}")
println("description longName${item.longName}")
println("description name ${item.name}")
println("description size ${item.size ?: ""}")
if (item.description.isNullOrEmpty()) {
item.description =
item.longName ?: "${item.name ?: ""} ${item.size ?: ""}"
}
item.stickers =
if (item.packing == null) 0 else ceil((item.visible.toDouble() / item.packing!!.toDouble())).toInt()
}
val totalStickers = listItems.sumOf { item -> item.stickers }
parking = it.list.firstOrNull { item -> item.code != null }?.code ?: ""
binding.mainToolbar.toolbarTitle.text = binding.mainToolbar.toolbarTitle.text =
shelvingFk.uppercase() + getString(R.string.pUppercase) + parking + getString( shelvingFk.uppercase() + getString(R.string.pUppercase) + parking + getString(
@ -649,7 +664,15 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
}.show() }.show()
} }
} }
loadBuyUltimateResponse.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
ma.messageWithSound(
getString(R.string.errorPrintBuy),
isError = true,
isPlayed = true
)
}
}
} }
} }
@ -1049,7 +1072,46 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
customDialogTwoButtons.dismiss() customDialogTwoButtons.dismiss()
} }
customDialogConfirm.show() customDialogConfirm.show()
}//Tarea 7763 }
//Tarea 7266
/* .setOkButtonThree(getString(R.string.print)) {
val printerDialogManager = PrinterDialogManager(requireContext())
printerDialogManager.showPrintDialog(
item.item,
item.description ?: ""
) { id, labelType, packing, copies ->
if (item.buyFk == null) {
viewModel.buyUltimate(
itemFk = item.id,
warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey(
WAREHOUSEFK
),
dated = LocalDate.now()
.format(
DateTimeFormatter.ofPattern("yyyy-dd-MM")
),
reportName = "LabelBuy",
printerFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
ConstAndValues.PRINTERFK
),
userFk = mobileApplication.userId!!,
priority = "normal",
copies = copies,
labelType = labelType,
packing = packing
)
customDialogTwoButtons.dismiss()
} else {
printItem(
item.buyFk!!, labelType, packing, copies
)
customDialogTwoButtons.dismiss()
}
}
customDialogInput.getEditText().requestFocus()
}*/
//Tarea 7763
/* /*
.setOkButtonThree(getString(R.string.rename)) { .setOkButtonThree(getString(R.string.rename)) {
customDialogInput.setTitle(getString(R.string.itemNew)) customDialogInput.setTitle(getString(R.string.itemNew))
@ -1080,6 +1142,24 @@ class UbicadorFragmentNew : BaseFragment<FragmentUbicadorBinding, UbicadorViewMo
customDialogTwoButtons.show() customDialogTwoButtons.show()
} }
private fun printItem(id: Number?, labelType: String, packing: Int?, copies: Int?) {
try {
viewModel.printItem(
reportName = "LabelBuy",
printerFk = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
ConstAndValues.PRINTERFK
),
userFk = mobileApplication.userId!!,
priority = "normal",
params = """{'copies':$copies,'id':$id,'labelType':'$labelType','packing':$packing}"""
)
} catch (ex: Exception) {
ma.messageWithSound(message = ex.message.toString(), isError = true, isPlayed = true)
}
hideKeyboard()
}
private fun actionRename(item: ItemUbicador, itemScan: String) { private fun actionRename(item: ItemUbicador, itemScan: String) {
if (itemScan.isNotEmpty()) { if (itemScan.isNotEmpty()) {

View File

@ -9,9 +9,8 @@ import es.verdnatura.R
import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
import es.verdnatura.domain.userCases.GetItemPrintItemUseCase
import es.verdnatura.presentation.base.BaseViewModel 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.Event
import es.verdnatura.presentation.common.ItemShelvingSalix import es.verdnatura.presentation.common.ItemShelvingSalix
import es.verdnatura.presentation.common.ResponseHasOlder import es.verdnatura.presentation.common.ResponseHasOlder
@ -22,16 +21,13 @@ import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewerList
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListNew import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListNew
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListVO
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
import es.verdnatura.presentation.view.feature.workermistake.model.MakeMultiSalix import es.verdnatura.presentation.view.feature.workermistake.model.MakeMultiSalix
import retrofit2.Call import retrofit2.Call
import retrofit2.Response import retrofit2.Response
class UbicadorViewModel(val context: Context) : BaseViewModel(context) { class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix) private val getItemFromBarcodeUseCase = GetItemFromBarcodeUseCase(salix)
private val printItemUseCase = GetItemPrintItemUseCase(salix)
private val _shelvingList by lazy { MutableLiveData<ItemUbicadorListVO>() }
private val _responseUbicator by lazy { MutableLiveData<Boolean>() } private val _responseUbicator by lazy { MutableLiveData<Boolean>() }
val responseUbicator: LiveData<Boolean> val responseUbicator: LiveData<Boolean>
@ -43,8 +39,6 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
val loadResponseHasOlder: LiveData<Event<ResponseHasOlder>> = val loadResponseHasOlder: LiveData<Event<ResponseHasOlder>> =
_responseHasOlder.map { Event(it) } _responseHasOlder.map { Event(it) }
val loadShelvingList: LiveData<Event<ItemUbicadorListVO>> = _shelvingList.map { Event(it) }
private val _shelvingListNew by lazy { MutableLiveData<ItemUbicadorListNew>() } private val _shelvingListNew by lazy { MutableLiveData<ItemUbicadorListNew>() }
val loadShelvingListNew: LiveData<Event<ItemUbicadorListNew>> = val loadShelvingListNew: LiveData<Event<ItemUbicadorListNew>> =
_shelvingListNew.map { Event(it) } _shelvingListNew.map { Event(it) }
@ -65,40 +59,15 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
private val _responseAddList by lazy { MutableLiveData<Boolean>() } private val _responseAddList by lazy { MutableLiveData<Boolean>() }
val responseAddList: LiveData<Boolean> = _responseAddList val responseAddList: LiveData<Boolean> = _responseAddList
val loadAddList: LiveData<Event<Boolean>> = _responseAddList.map { Event(it) } val loadAddList: LiveData<Event<Boolean>> = _responseAddList.map { Event(it) }
private val _responseLogAdd by lazy { MutableLiveData<Any>() } private val _responseLogAdd by lazy { MutableLiveData<Any>() }
val responseLogAdd: LiveData<Any> val responseLogAdd: LiveData<Any>
get() = _responseLogAdd get() = _responseLogAdd
fun itemShelvingList( private val _buyUltimateResponse by lazy { MutableLiveData<Boolean>() }
vShelvingFk: String val buyUltimateResponse: LiveData<Boolean> = _buyUltimateResponse
) { val loadBuyUltimateResponse: LiveData<Event<Boolean>> = _buyUltimateResponse.map { Event(it) }
salix.itemShelvingList(params = listOf(vShelvingFk.uppercase()).formatWithQuotes()).enqueue(
object : SalixCallback<List<ItemUbicadorVO>>(context) {
override fun onSuccess(response: Response<List<ItemUbicadorVO>>) {
_shelvingList.value = response.body()?.let { ItemUbicadorListVO(it) }
}
override fun onError(t: Throwable) {
val listError: ArrayList<ItemUbicadorVO> = ArrayList()
listError.add(
ItemUbicadorVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!,
),
),
)
_shelvingList.value = ItemUbicadorListVO(listError)
}
},
)
}
fun itemShelvingListNew( fun itemShelvingListNew(
vShelvingFk: String vShelvingFk: String
@ -430,6 +399,67 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) {
}) })
} }
fun printItem(
reportName: String,
printerFk: Int,
userFk: Int,
params: Any,
priority: String
) {
printItemUseCase.execute(
params = arrayListOf(
reportName,
printerFk,
userFk,
params,
priority
).formatWithQuotes()
)
.enqueue(object : SalixCallback<Unit>(context) {
})
}
fun buyUltimate(
itemFk: Number,
warehouseFk: Int,
dated: String,
reportName: String,
printerFk: Int,
priority: String,
userFk: Int,
copies: Int,
labelType: String,
packing: Int?
) {
printItemUseCase.executeBuyUltimate(
params = arrayListOf(
itemFk,
warehouseFk,
dated
).formatWithQuotes()
)
.enqueue(object : SalixCallback<Long>(context) {
override fun onSuccess(response: Response<Long>) {
if (response.body() == null) _buyUltimateResponse.value = false
else {
val params =
"""{'copies':$copies,'id':${response.body()},'labelType':'$labelType','packing':$packing}"""
printItem(
reportName = reportName,
printerFk = printerFk,
priority = priority,
userFk = userFk,
params = params
)
}
}
})
}
fun itemShelvingMakeMulti( fun itemShelvingMakeMulti(
shelvingFk: String, items: List<Long>, warehouseFk: Int shelvingFk: String, items: List<Long>, warehouseFk: Int
) { ) {

View File

@ -22,7 +22,10 @@ class ItemUbicadorVO(
class ItemUbicador( class ItemUbicador(
var item: Long, var item: Long,
var description: String = "", var description: String? = null,
var size: Int? = null,
var name: String? = null,
var longName: String? = null,
var visible: Int = 0, var visible: Int = 0,
var stickers: Int = 0, var stickers: Int = 0,
var packing: Int? = null, var packing: Int? = null,
@ -39,7 +42,8 @@ class ItemUbicador(
var isNew: Boolean = false, var isNew: Boolean = false,
var isChecked: Int? = null, var isChecked: Int? = null,
var url: String = "", var url: String = "",
var units: Int = 0 var units: Int = 0,
var buyFk: Long? = null
) )
class ItemEscanerVO( class ItemEscanerVO(

View File

@ -82,6 +82,7 @@
android:textColor="@color/verdnatura_black" android:textColor="@color/verdnatura_black"
android:textSize="@dimen/h8" android:textSize="@dimen/h8"
android:textStyle="bold" android:textStyle="bold"
app:drawableEndCompat="@drawable/ic_click_black"
tool:text="123456789" tool:text="123456789"
/> />
@ -182,14 +183,14 @@
<TextView <TextView
android:id="@+id/item_article_itemFk" android:id="@+id/item_article_itemFk"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="24dp"
android:layout_marginStart="@dimen/layout_margin_min_to_modify" android:layout_marginStart="@dimen/layout_margin_min_to_modify"
android:layout_marginEnd="@dimen/layout_margin_min"
android:maxLines="1" android:maxLines="1"
android:text="@{Long.toString(sale.itemFk)}" android:text="@{Long.toString(sale.itemFk)}"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/body1" android:textSize="@dimen/body1"
android:textStyle="bold" android:textStyle="bold"
app:drawableEndCompat="@drawable/ic_click"
app:layout_constraintStart_toEndOf="@+id/linearLayout3" app:layout_constraintStart_toEndOf="@+id/linearLayout3"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tool:text="85478" /> tool:text="85478" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"> xmlns:tool="http://schemas.android.com/tools">
<data> <data>
@ -8,63 +9,66 @@
name="item" name="item"
type="es.verdnatura.presentation.view.feature.sacador.model.PlacementVO" /> type="es.verdnatura.presentation.view.feature.sacador.model.PlacementVO" />
</data> </data>
<LinearLayout <LinearLayout
android:id="@+id/item_root_layout" android:id="@+id/item_root_layout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/layout_margin_1"
android:gravity="center"
android:layout_marginEnd="@dimen/layout_margin_min" android:layout_marginEnd="@dimen/layout_margin_min"
android:background="@color/verdnatura_background_item_picker"> android:background="@color/verdnatura_background_item_picker"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/layout_margin_1">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/layout_margin_min"
android:text="@{item.placement}" android:text="@{item.placement}"
tool:text="053-05"
android:textColor="@color/verdnatura_pumpkin_orange" android:textColor="@color/verdnatura_pumpkin_orange"
android:textStyle="bold"
android:textSize="@dimen/h7" android:textSize="@dimen/h7"
android:layout_marginEnd="@dimen/layout_margin_min"/> android:textStyle="bold"
tool:text="053-05" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{item.shelving}" android:text="@{item.shelving}"
tool:text="YIC"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h8"
android:textStyle="bold" android:textStyle="bold"
android:textSize="@dimen/h8"/> app:drawableEndCompat="@drawable/ic_click"
tool:text="YIC" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/layout_margin_min"
android:text="@{item.created}" android:text="@{item.created}"
tool:text="28/05 "
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h8" android:textSize="@dimen/h8"
android:layout_marginEnd="@dimen/layout_margin_min"/> tool:text="28/05 " />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{item.visible}" android:text="@{item.visible}"
tool:text="260"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h8"/> android:textSize="@dimen/h8"
tool:text="260" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</layout> </layout>