diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index b3b03808..507e18bc 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt @@ -37,6 +37,9 @@ import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingType import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import org.json.JSONObject +import java.time.LocalDate +import java.time.format.DateTimeFormatter class ItemCardFragment( var itemFk: String = "" @@ -108,12 +111,12 @@ class ItemCardFragment( iconHistory.tooltipText = getTooltip(R.drawable.ic_history_black_24dp) iconSalix.tooltipText = getTooltip(R.drawable.ic_logo_salix) // Tarea 7266 - // iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) + iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp) listIcons.add(iconSalix) listIcons.add(iconReload) listIcons.add(iconHistory) - // listIcons.add(iconPrint) + listIcons.add(iconPrint) binding.mainToolbar.toolbarIcons.adapter = ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { @@ -128,7 +131,7 @@ class ItemCardFragment( val printerDialogManager = PrinterDialogManager(requireContext()) printerDialogManager.showPrintDialog( - itemInfoG!!.id.toLong(), + buyToPrint ?: itemInfoG!!.id.toLong(), itemInfoG?.longName ?: "" ) { id, labelType, copies, packing -> printItem(id, labelType, copies, packing) @@ -183,7 +186,6 @@ class ItemCardFragment( private fun printItem(id: Long, labelType: String, packing: Int?, copies: Int?) { try { - viewModel.printItem( reportName = "LabelBuy", printerFk = mobileApplication.dataStoreApp.readDataStoreKey( @@ -191,7 +193,12 @@ class ItemCardFragment( ), userFk = mobileApplication.userId!!, priority = "normal", - params = """{'copies':$copies,'id':$id,'labelType':'$labelType','packing':$packing}""" + params = JSONObject().apply { + put("copies", copies) + put("id", id) + put("labelType", labelType) + put("packing", packing) + }.toString().replace("\"", "\\\"") ) } catch (ex: Exception) { ma.messageWithSound(message = ex.message.toString(), isError = true, isPlayed = true) @@ -259,19 +266,19 @@ class ItemCardFragment( binding.itemcardLayout.visibility = View.VISIBLE setItemCard(it) binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE - /* Tarea 7266 + // 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() - }*/ + viewModel.buyUltimate( + itemFk = it.id, + warehouseFk = mobileApplication.dataStoreApp.readDataStoreKey( + WAREHOUSEFK + ), + dated = LocalDate.now() + .format(DateTimeFormatter.ofPattern("yyyy-dd-MM")) + ) + } else { + buyToPrint = originalScan!!.toLong() + } } else { binding.itemcardLayout.visibility = GONE binding.mainToolbar.toolbarTitle.text = getString(R.string.itemCard) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt index 5d4640de..eed51820 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt @@ -28,6 +28,7 @@ import es.verdnatura.presentation.common.OnMoreClickListenerNew import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPasillerosItemClickListener import es.verdnatura.presentation.common.OnVisibleClickListenerNew +import es.verdnatura.presentation.common.PrinterDialogManager import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.hideKeyboard import es.verdnatura.presentation.common.itemScanValue @@ -41,6 +42,9 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO 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.model.ItemUbicador +import org.json.JSONObject +import java.time.LocalDate +import java.time.format.DateTimeFormatter import kotlin.math.ceil @Suppress("UNUSED_ANONYMOUS_PARAMETER") @@ -120,7 +124,7 @@ class UbicadorFragmentNew : BaseFragment event.getContentIfNotHandled().notNull { @@ -677,9 +684,7 @@ class UbicadorFragmentNew : BaseFragment event.getContentIfNotHandled().notNull { ma.messageWithSound( - getString(R.string.errorPrintBuy), - isError = true, - isPlayed = true + getString(R.string.errorPrintBuy), isError = true, isPlayed = true ) } } @@ -792,8 +797,7 @@ class UbicadorFragmentNew : BaseFragment + //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( - 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() - }*/ + 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( + 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)) { @@ -1162,7 +1166,12 @@ class UbicadorFragmentNew : BaseFragment> = _shelvingListNew.map { Event(it) } + private val _shelvingGet by lazy { MutableLiveData() } + val loadShelvingGet: LiveData> = + _shelvingGet.map { Event(it) } + + private val _imageConfig by lazy { MutableLiveData() } + val loadImageConfig: LiveData> = + _imageConfig.map { Event(it) } + private val _shelvingListItemNewer by lazy { MutableLiveData() } val loadShelvingListItemNewer: LiveData> = _shelvingListItemNewer.map { Event(it) } @@ -85,63 +95,44 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { //Tarea 6869 fun itemShelvingGet( - shelvingFk: String + shelvingCode: String ) { salix.shelvingGet( filter = """{ - "fields":[ - "priority", - "parkingFk", - "code" - ], + "fields": + ["priority","parkingFk","code","id"], "include":[ - { - "relation":"parking", - "scope":{ - "fields":[ - "code" - ] - } - }, - { - "relation":"itemShelving", - "scope":{ - "fields":[ - "id", - "itemFk", - "visible", - "packing", - "grouping", - "isChecked", - "available", - "buyFk" - ], - "include":{ - "relation":"item", - "scope":{ - "fields":[ - "name", - "longName", - "size" - ] - } - } - } - } - ], - "where":{ - "code":"$shelvingFk" - } - }""".trim() - ) - .enqueue( - object : SalixCallback>(context) { - override fun onSuccess(response: Response>) { - _shelvingListNew.value = response.body()?.let { ItemUbicadorListNew(it) } - } + {"relation":"parking", + "scope":{"fields":["code"]}}, + {"relation":"itemShelving", + "scope":{"fields":["id","itemFk","visible","packing","grouping","isChecked","available","buyFk","shelvingFk"], + "include": + {"relation":"item", + "scope":{"fields":["name","longName","size"]}}}}], + "where":{"code":"$shelvingCode"}}""".trim() + ).enqueue( + object : SalixCallback(context) { + override fun onSuccess(response: Response) { + _shelvingGet.value = response.body() + } - }, - ) + }, + ) + } + + fun getImageConfig( + ) { + salix.getImageConfig( + ).enqueue( + object : SalixCallback(context) { + override fun onSuccess(response: Response) { + + _imageConfig.value = + response.body()!!.entrySet().first().value.asString + } + + }, + ) } fun shelvingPriorityUpdate( @@ -340,7 +331,12 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { .enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { - _responseLogAdd.value = response.message() + _responseLogAdd.value = true + } + + override fun onError(t: Throwable) { + _responseLogAdd.value = false + super.onError(t) } }) @@ -472,7 +468,7 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } - fun itemShelvingSelfConsumption(shelvingFk: String, itemFk: Int, quantity: Int) { + fun itemShelvingSelfConsumption(shelvingFk: String, itemFk: Number, quantity: Int) { salix.itemShelvingSelfConsumption( arrayListOf( shelvingFk, itemFk, quantity @@ -544,7 +540,12 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { if (response.body() == null) _buyUltimateResponse.value = false else { val params = - """{'copies':$copies,'id':${response.body()},'labelType':'$labelType','packing':$packing}""" + JSONObject().apply { + put("copies", copies) + put("id", response.body()) + put("labelType", labelType) + put("packing", packing) + }.toString().replace("\"", "\\\"") printItem( reportName = reportName, printerFk = printerFk,