feat: refactorResponse packaging refs #7827
This commit is contained in:
parent
6dc39d6611
commit
f3882c7f9a
|
@ -17,7 +17,7 @@ import es.verdnatura.presentation.view.feature.historicoshelvinglog.fragment.She
|
|||
import es.verdnatura.presentation.view.feature.historicovehiculo.fragment.HistoricoVehiculoViewModel
|
||||
import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryViewModel
|
||||
import es.verdnatura.presentation.view.feature.login.fragment.LoginViewModel
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.SupplierViewModel
|
||||
import es.verdnatura.presentation.view.feature.packingHolland.fragment.PackingHollandViewModel
|
||||
import es.verdnatura.presentation.view.feature.paletizador.fragment.CmrExpeditionPalletViewModel
|
||||
import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPalletDetailViewModel
|
||||
|
@ -179,7 +179,7 @@ val viewModelModule = module {
|
|||
PalletScanViewModel(androidContext())
|
||||
}
|
||||
viewModel {
|
||||
PackagingViewModel(androidContext())
|
||||
SupplierViewModel(androidContext())
|
||||
}
|
||||
viewModel {
|
||||
DeliveryViewModel(androidContext())
|
||||
|
|
|
@ -867,11 +867,6 @@ interface SalixService {
|
|||
@Query("filter") filter: String
|
||||
): Call<List<EntrySalix>>
|
||||
|
||||
@GET("Entries")
|
||||
fun addEntry(
|
||||
@Body entry: EntrySalix
|
||||
): Call<EntrySalix>
|
||||
|
||||
@PATCH("Entries/{entryId}")
|
||||
fun entryUpdateObserv(
|
||||
@Path("entryId") entryId: Int, @Body entry: ObervationEntry
|
||||
|
|
|
@ -35,7 +35,6 @@ import es.verdnatura.presentation.view.component.CustomDialog
|
|||
import es.verdnatura.presentation.view.component.CustomDialogList
|
||||
import es.verdnatura.presentation.view.feature.packaging.adapter.ListImageAdapter
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.ObservFragment.ImageUtils.getDrawableFromImageUri
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
|
||||
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
@ -50,8 +49,8 @@ import java.util.Locale
|
|||
class ObservFragment(
|
||||
var entryPoint: String = ""
|
||||
|
||||
) : BaseFragment<FragmentPackagingObsBinding, PackagingViewModel>(
|
||||
PackagingViewModel::class
|
||||
) : BaseFragment<FragmentPackagingObsBinding, SupplierViewModel>(
|
||||
SupplierViewModel::class
|
||||
) {
|
||||
|
||||
private var adapterListImage: ListImageAdapter? = null
|
||||
|
@ -240,7 +239,7 @@ class ObservFragment(
|
|||
val drawable = getDrawableFromImageUri(requireContext(), item.uri)
|
||||
val bitmap = drawable!!.toBitmap()
|
||||
|
||||
viewModel.entry_uploadPhotoSalix(
|
||||
viewModel.entryUploadPhotoSalix(
|
||||
idEntry = mobileApplication.dataStoreApp.readDataStoreKey<Int>(ENTRYID),
|
||||
warehouseId = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
|
||||
WAREHOUSEFK
|
||||
|
@ -279,7 +278,7 @@ class ObservFragment(
|
|||
val drawable = getDrawableFromImageUri(requireContext(), (item as Image).uri)
|
||||
val bitmap = drawable!!.toBitmap()
|
||||
|
||||
viewModel.entry_uploadPhotoSalix(
|
||||
viewModel.entryUploadPhotoSalix(
|
||||
idEntry = mobileApplication.dataStoreApp.readDataStoreKey<Int>(ENTRYID),
|
||||
warehouseId = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
|
||||
WAREHOUSEFK
|
||||
|
|
|
@ -24,15 +24,14 @@ import es.verdnatura.presentation.view.component.CustomDialog
|
|||
import es.verdnatura.presentation.view.component.CustomDialogInput
|
||||
import es.verdnatura.presentation.view.feature.articulo.fragment.ImageViewActivity
|
||||
import es.verdnatura.presentation.view.feature.packaging.adapter.ItemSupplierAdapter
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplier
|
||||
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
||||
|
||||
class PackagingCountFragment(
|
||||
var entryPoint: String = ""
|
||||
|
||||
) : BaseFragment<FragmentPackagingCountBinding, PackagingViewModel>(
|
||||
PackagingViewModel::class
|
||||
) : BaseFragment<FragmentPackagingCountBinding, SupplierViewModel>(
|
||||
SupplierViewModel::class
|
||||
) {
|
||||
|
||||
private var adapteritemsupplier: ItemSupplierAdapter? = null
|
||||
|
@ -106,23 +105,11 @@ class PackagingCountFragment(
|
|||
loadEntryAdd.observe(viewLifecycleOwner) { event ->
|
||||
event.getContentIfNotHandled().notNull {
|
||||
|
||||
//entryAdd.observe(viewLifecycleOwner) {
|
||||
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(it.errorMessage, isError = true, isPlayed = true)
|
||||
|
||||
} else {
|
||||
ma.messageWithSound(
|
||||
it.errorMessage,
|
||||
isError = false,
|
||||
isPlayed = true,
|
||||
isToasted = false
|
||||
)
|
||||
viewModel.getItemsPackaging(
|
||||
mobileApplication.dataStoreApp.readDataStoreKey(SUPPLIERID),
|
||||
mobileApplication.dataStoreApp.readDataStoreKey(ENTRYID)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,17 +164,12 @@ class PackagingCountFragment(
|
|||
if (customDialogInput.getValue().isNotEmpty()) {
|
||||
requireActivity().hideKeyboard()
|
||||
}
|
||||
viewModel.entry_addFromBuy(
|
||||
viewModel.entryAddFromBuy(
|
||||
mobileApplication.dataStoreApp.readDataStoreKey<Int>(ENTRYID),
|
||||
item = item.id!!.toInt(),
|
||||
item.printedStickers.plus(customDialogInput.getValue().toInt())
|
||||
)
|
||||
/* (if (mobileApplication.dataStoreApp.readDataStoreKey<String>("ENTRYTYPE") == "Rec") {
|
||||
(item.printedStickers.plus(customDialogInput.getValue().toInt()))
|
||||
} else {
|
||||
item.printedStickers.plus(customDialogInput.getValue().toInt())
|
||||
}) as Number
|
||||
)*/
|
||||
|
||||
customDialog.cancel()
|
||||
customDialogInput.dismiss()
|
||||
customDialogInput.setValue("")
|
||||
|
@ -215,7 +197,7 @@ class PackagingCountFragment(
|
|||
customDialog.cancel()
|
||||
customDialog.dismiss()
|
||||
|
||||
viewModel.entry_addFromBuy(
|
||||
viewModel.entryAddFromBuy(
|
||||
mobileApplication.dataStoreApp.readDataStoreKey<Int>("ENTRYID"),
|
||||
item = item.id!!.toInt(),
|
||||
printedStickers = 0
|
||||
|
|
|
@ -19,15 +19,14 @@ import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
|||
import es.verdnatura.presentation.common.addFragment
|
||||
import es.verdnatura.presentation.view.component.CustomDialog
|
||||
import es.verdnatura.presentation.view.feature.packaging.adapter.ItemSupplierAdapter
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
|
||||
import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class PackagingSummaryFragment(
|
||||
var entryPoint: String = ""
|
||||
|
||||
) : BaseFragment<FragmentPackagingSummaryBinding, PackagingViewModel>(
|
||||
PackagingViewModel::class
|
||||
) : BaseFragment<FragmentPackagingSummaryBinding, SupplierViewModel>(
|
||||
SupplierViewModel::class
|
||||
) {
|
||||
private var adapteritemsupplier: ItemSupplierAdapter? = null
|
||||
private lateinit var customDialog: CustomDialog
|
||||
|
@ -108,10 +107,16 @@ class PackagingSummaryFragment(
|
|||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
binding.itemsupplierRecyclerview.layoutManager = layoutManager
|
||||
}
|
||||
response.observe(viewLifecycleOwner) {
|
||||
|
||||
responseNotification.observe(viewLifecycleOwner) {
|
||||
if (it == true) {
|
||||
deleteDataEntry()
|
||||
|
||||
} else {
|
||||
ma.messageWithSound(
|
||||
getString(R.string.errorEntriesNotification),
|
||||
isError = true,
|
||||
isPlayed = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,365 +0,0 @@
|
|||
package es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.map
|
||||
import es.verdnatura.domain.SalixCallback
|
||||
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.ResponseItemVO
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntryList
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplier
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.NotificationQueue
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ObervationEntry
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.SupplierList
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.itemSupplierList
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
||||
|
||||
private val _itemSupplierList by lazy { MutableLiveData<itemSupplierList>() }
|
||||
val itemSupplierList: LiveData<itemSupplierList>
|
||||
get() = _itemSupplierList
|
||||
|
||||
private val _supplierList by lazy { MutableLiveData<SupplierList>() }
|
||||
val supplierList: LiveData<SupplierList>
|
||||
get() = _supplierList
|
||||
|
||||
private val _entryList by lazy { MutableLiveData<EntryList>() }
|
||||
val entryList: LiveData<EntryList>
|
||||
get() = _entryList
|
||||
|
||||
private val _entry by lazy { MutableLiveData<EntrySalix>() }
|
||||
val entry: LiveData<EntrySalix>
|
||||
get() = _entry
|
||||
|
||||
private val _entryUpdate by lazy { MutableLiveData<Boolean>() }
|
||||
val entryUpdate: LiveData<Boolean>
|
||||
get() = _entryUpdate
|
||||
|
||||
val loadEntryUpdate: LiveData<Event<Boolean>> = _entryUpdate.map { Event(it) }
|
||||
|
||||
private val _entryAdd by lazy { MutableLiveData<EntrySalix>() }
|
||||
val entryAdd: LiveData<EntrySalix>
|
||||
get() = _entryAdd
|
||||
|
||||
private val _uploadEntryImage by lazy { MutableLiveData<EntrySalix>() }
|
||||
val uploadEntryImage: LiveData<EntrySalix>
|
||||
get() = _uploadEntryImage
|
||||
|
||||
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
|
||||
val response: LiveData<ResponseItemVO>
|
||||
get() = _response
|
||||
|
||||
val loadEntryAdd: LiveData<Event<EntrySalix>> = _entryAdd.map { Event(it) }
|
||||
|
||||
fun getSuppliers() {
|
||||
salix.getSuppliers().enqueue(object : SalixCallback<List<Supplier>>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
val listError: ArrayList<Supplier> = ArrayList()
|
||||
listError.add(
|
||||
Supplier(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
)
|
||||
_supplierList.value = SupplierList(listError)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<List<Supplier>>) {
|
||||
if (response.body() != null) {
|
||||
_supplierList.value = response.body()?.let { SupplierList(it) }
|
||||
} else {
|
||||
val listError: ArrayList<Supplier> = ArrayList()
|
||||
listError.add(
|
||||
Supplier(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
)
|
||||
_supplierList.value = SupplierList(listError)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun uploadFile(entry: EntrySalix) {
|
||||
salix.addEntry(entry).enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entry.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
if (response.body() != null) {
|
||||
_entry.value = response.body()
|
||||
} else {
|
||||
_entry.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getEntriesFromSupplier(supplier: Int) {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 0)
|
||||
|
||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val today = dateFormat.format(calendar.time)
|
||||
|
||||
salix.getEntriesFromSupplier("""{"where": {"supplierFk": "$supplier","created":{"gte":"$today"},"typeFk":"packaging","order":"created ASC"},"include": [ { "relation": "travel", "scope": { "fields": ["landed"]}}]}""")
|
||||
.enqueue(object : SalixCallback<List<EntrySalix>>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<List<EntrySalix>>) {
|
||||
if (response.body() != null) {
|
||||
_entryList.value = response.body()?.let { EntryList(it) }
|
||||
} else {
|
||||
val listError: ArrayList<EntrySalix> = ArrayList()
|
||||
listError.add(
|
||||
EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
)
|
||||
_entryList.value = EntryList(listError)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun supplier_getItems(supplierFk: Any) {
|
||||
//pendiente de borrado si la tarea no se lleva a cabo
|
||||
/* silex.supplier_getItems(supplierFk)
|
||||
.enqueue(object : SilexCallback<List<ItemSupplier>>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
val listError: ArrayList<ItemSupplier> = ArrayList()
|
||||
listError.add(
|
||||
ItemSupplier(
|
||||
isError = true,
|
||||
errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this),
|
||||
t.message!!
|
||||
)
|
||||
)
|
||||
)
|
||||
_itemSupplierList.value = itemSupplierList(listError)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<List<ItemSupplier>>) {
|
||||
if (response.body() != null) {
|
||||
_itemSupplierList.value =
|
||||
response.body()?.let { itemSupplierList(it) }
|
||||
} else {
|
||||
val listError: ArrayList<ItemSupplier> = ArrayList()
|
||||
listError.add(ItemSupplier(null, null))
|
||||
_itemSupplierList.value = itemSupplierList(listError)
|
||||
}
|
||||
}
|
||||
|
||||
})*/
|
||||
}
|
||||
|
||||
fun entry_addSalix(entry: EntrySalix) {
|
||||
salix.addEntry(entry).enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entry.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
if (response.body() != null) {
|
||||
_entry.value = response.body()
|
||||
} else {
|
||||
_entry.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun entryUpdateObserv(entryId: Int, observation: String) {
|
||||
salix.entryUpdateObserv(entryId, ObervationEntry(observation))
|
||||
.enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
_entryUpdate.value = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun entry_uploadPhotoSalix(
|
||||
idEntry: Number,
|
||||
warehouseId: Number,
|
||||
companyId: Number,
|
||||
dmsTypeId: Number,
|
||||
reference: String,
|
||||
description: String,
|
||||
hasFile: Boolean,
|
||||
urlImage: String,
|
||||
|
||||
) {
|
||||
|
||||
val file = File(urlImage)
|
||||
val fileRequestBody: RequestBody = RequestBody.create(MediaType.parse("image/jpeg"), file)
|
||||
|
||||
salix.uploadEntryPhoto(
|
||||
idEntry,
|
||||
warehouseId,
|
||||
companyId,
|
||||
dmsTypeId,
|
||||
reference,
|
||||
description,
|
||||
hasFile,
|
||||
file = MultipartBody.Part.createFormData(
|
||||
"file", file.name, fileRequestBody
|
||||
)
|
||||
).enqueue(object : SalixCallback<Any>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_uploadEntryImage.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun entry_addFromBuy(id: Number, item: Number, printedStickers: Number) {
|
||||
println("entryID -- addFromBuy")
|
||||
salix.addFromBuy(id, item, printedStickers)
|
||||
.enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entryAdd.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
if (response.body() != null) {
|
||||
_entryAdd.value = response.body()
|
||||
} else {
|
||||
_entryAdd.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun notificationQueues(notification: String, workerfk: Int, bodyUrl: String) {
|
||||
salix.notificationQueues(NotificationQueue(notification, workerfk, bodyUrl))
|
||||
.enqueue(object : SalixCallback<Void>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_response.value = ResponseItemVO(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<Void>) {
|
||||
|
||||
_response.value = ResponseItemVO(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun entry_addFromPackaging(supplier: Int, isPackaging: Boolean) {
|
||||
salix.addFromPackaging(supplier, isPackaging)
|
||||
.enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entryAdd.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
if (response.body() != null) {
|
||||
_entryAdd.value = response.body()
|
||||
} else {
|
||||
_entryAdd.value = EntrySalix(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), response.message()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getItemsPackaging(supplierId: Int, entryId: Int) {
|
||||
salix.getItemsPackaging(supplierId, entryId)
|
||||
.enqueue(object : SalixCallback<List<ItemSupplier>>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
val listError: ArrayList<ItemSupplier> = ArrayList()
|
||||
listError.add(
|
||||
ItemSupplier(
|
||||
isError = true, errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this), t.message!!
|
||||
)
|
||||
)
|
||||
)
|
||||
_itemSupplierList.value = itemSupplierList(listError)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<List<ItemSupplier>>) {
|
||||
if (response.body() != null) {
|
||||
_itemSupplierList.value = response.body()?.let { itemSupplierList(it) }
|
||||
} else {
|
||||
val listError: ArrayList<ItemSupplier> = ArrayList()
|
||||
listError.add(ItemSupplier(null, null))
|
||||
_itemSupplierList.value = itemSupplierList(listError)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
|
@ -10,12 +10,10 @@ import es.verdnatura.domain.ConstAndValues.ENTRYID
|
|||
import es.verdnatura.domain.ConstAndValues.ENTRYOBSERVATIONORIGINAL
|
||||
import es.verdnatura.domain.ConstAndValues.SUPPLIERID
|
||||
import es.verdnatura.domain.ConstAndValues.SUPPLIERNAME
|
||||
import es.verdnatura.domain.notNull
|
||||
import es.verdnatura.presentation.base.BaseFragment
|
||||
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
|
||||
import es.verdnatura.presentation.view.component.CustomDialog
|
||||
import es.verdnatura.presentation.view.feature.inventario.fragment.SearchSupplierModel
|
||||
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
|
||||
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
||||
|
@ -26,8 +24,8 @@ import kotlinx.coroutines.runBlocking
|
|||
class SupplierFragment(
|
||||
var entryPoint: String = ""
|
||||
|
||||
) : BaseFragment<FragmentPackagingBinding, PackagingViewModel>(
|
||||
PackagingViewModel::class
|
||||
) : BaseFragment<FragmentPackagingBinding, SupplierViewModel>(
|
||||
SupplierViewModel::class
|
||||
) {
|
||||
|
||||
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
|
||||
|
@ -101,24 +99,6 @@ class SupplierFragment(
|
|||
ma.onMyBackPressed()
|
||||
}
|
||||
|
||||
/* binding.radiobuttonTypePackaging.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||
when (isChecked) {
|
||||
R.id.radioButtonRec -> {
|
||||
runBlocking {
|
||||
mobileApplication.dataStoreApp.editDataStoreKey("ENTRYTYPE", "Rec")
|
||||
}
|
||||
}
|
||||
|
||||
R.id.radioButtonDev -> {
|
||||
runBlocking {
|
||||
mobileApplication.dataStoreApp.editDataStoreKey("ENTRYTYPE", "Dev")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
binding.filterEntry.visibility = View.VISIBLE
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun setEntryDialog() {
|
||||
|
@ -132,11 +112,6 @@ class SupplierFragment(
|
|||
entries
|
||||
) { baseSearchDialogCompat, nombre, position ->
|
||||
binding.filterEntry.text = nombre.getName()
|
||||
binding.radiobuttonTypePackaging.visibility = View.VISIBLE
|
||||
|
||||
/* if (nombre.getName() == getString(R.string.newEntry)) {
|
||||
addEntry()
|
||||
} else {*/
|
||||
runBlocking {
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
ENTRYID,
|
||||
|
@ -168,47 +143,6 @@ class SupplierFragment(
|
|||
createEntryList(it.list)
|
||||
}
|
||||
|
||||
response.observe(viewLifecycleOwner) {
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(it.errorMessage, isError = true, isPlayed = false)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
loadEntryAdd.observe(viewLifecycleOwner) { event ->
|
||||
event.getContentIfNotHandled().notNull {
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(it.errorMessage, isError = true, isPlayed = false)
|
||||
|
||||
} else {
|
||||
runBlocking {
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
ENTRYID,
|
||||
it.id!!.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
ma.onPasillerosItemClickListener(
|
||||
PasillerosItemVO(title = getString(R.string.titlePackagingCount)),
|
||||
it.id!!.toString()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* entryAdd.observe(viewLifecycleOwner) {
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(it.errorMessage, true, false)
|
||||
|
||||
} else {
|
||||
saveDataInt("ENTRYID", it.id!!.toInt())
|
||||
ma.onPasillerosItemClickListener(
|
||||
PasillerosItemVO(title = getString(R.string.titlePackagingCount)),
|
||||
it.id!!.toString()
|
||||
)
|
||||
}
|
||||
}*/
|
||||
|
||||
entry.observe(viewLifecycleOwner) {
|
||||
if (it.isError) {
|
||||
|
@ -230,8 +164,10 @@ class SupplierFragment(
|
|||
|
||||
private fun createSupplierList(list: List<Supplier>) {
|
||||
suppliers.clear()
|
||||
if (list.isNotEmpty())
|
||||
|
||||
list.forEach { supplier ->
|
||||
if (!supplier.isError) {
|
||||
|
||||
try {
|
||||
suppliers.add(
|
||||
SearchSupplierModel(
|
||||
|
@ -247,7 +183,7 @@ class SupplierFragment(
|
|||
isPlayed = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,36 +212,8 @@ class SupplierFragment(
|
|||
}
|
||||
}
|
||||
|
||||
// entries.add(SearchSupplierModel(getString(R.string.newEntry), ""))
|
||||
setEntryDialog()
|
||||
}
|
||||
|
||||
/* private fun addEntry() {
|
||||
|
||||
customDialog.setTitle(getString(R.string.createEntryDescrip))
|
||||
.setDescription(getString(R.string.sure))
|
||||
.setOkButton(
|
||||
getString(
|
||||
R.string.accept
|
||||
)
|
||||
|
||||
) {
|
||||
customDialog.cancel()
|
||||
customDialog.dismiss()
|
||||
viewModel.entry_addFromPackaging(
|
||||
mobileApplication.dataStoreApp.readDataStoreKey("SUPPLIERID"),
|
||||
mobileApplication.dataStoreApp.readDataStoreKey<String>("ENTRYTYPE") == "Rec"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
.setKoButton(getString(R.string.cancel)) {
|
||||
customDialog.cancel()
|
||||
customDialog.dismiss()
|
||||
|
||||
}
|
||||
.show()
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
package es.verdnatura.presentation.view.feature.packaging.fragment
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.map
|
||||
import es.verdnatura.domain.SalixCallback
|
||||
import es.verdnatura.presentation.base.BaseViewModel
|
||||
import es.verdnatura.presentation.common.Event
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntryList
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplier
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplierList
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.NotificationQueue
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.ObervationEntry
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.SupplierList
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class SupplierViewModel(val context: Context) : BaseViewModel(context) {
|
||||
|
||||
private val _itemSupplierList by lazy { MutableLiveData<ItemSupplierList>() }
|
||||
val itemSupplierList: LiveData<ItemSupplierList>
|
||||
get() = _itemSupplierList
|
||||
|
||||
private val _supplierList by lazy { MutableLiveData<SupplierList>() }
|
||||
val supplierList: LiveData<SupplierList>
|
||||
get() = _supplierList
|
||||
|
||||
private val _entryList by lazy { MutableLiveData<EntryList>() }
|
||||
val entryList: LiveData<EntryList>
|
||||
get() = _entryList
|
||||
|
||||
private val _entry by lazy { MutableLiveData<EntrySalix>() }
|
||||
val entry: LiveData<EntrySalix>
|
||||
get() = _entry
|
||||
|
||||
private val _entryUpdate by lazy { MutableLiveData<Boolean>() }
|
||||
val entryUpdate: LiveData<Boolean>
|
||||
get() = _entryUpdate
|
||||
|
||||
val loadEntryUpdate: LiveData<Event<Boolean>> = _entryUpdate.map { Event(it) }
|
||||
|
||||
private val _entryAdd by lazy { MutableLiveData<Boolean>() }
|
||||
val entryAdd: LiveData<Boolean>
|
||||
get() = _entryAdd
|
||||
|
||||
private val _responseNotification by lazy { MutableLiveData<Boolean>() }
|
||||
val responseNotification: LiveData<Boolean>
|
||||
get() = _responseNotification
|
||||
|
||||
val loadEntryAdd: LiveData<Event<Boolean>> = _entryAdd.map { Event(it) }
|
||||
|
||||
fun getSuppliers() {
|
||||
salix.getSuppliers().enqueue(object : SalixCallback<List<Supplier>>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<List<Supplier>>) {
|
||||
_supplierList.value = response.body()?.let { SupplierList(it) }
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun getEntriesFromSupplier(supplier: Int) {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 0)
|
||||
|
||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val today = dateFormat.format(calendar.time)
|
||||
|
||||
salix.getEntriesFromSupplier("""{"where": {"supplierFk": "$supplier","created":{"gte":"$today"},"typeFk":"packaging","order":"created ASC"},"include": [ { "relation": "travel", "scope": { "fields": ["landed"]}}]}""")
|
||||
.enqueue(object : SalixCallback<List<EntrySalix>>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<List<EntrySalix>>) {
|
||||
_entryList.value = response.body()?.let { EntryList(it) }
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun entryUpdateObserv(entryId: Int, observation: String) {
|
||||
salix.entryUpdateObserv(entryId, ObervationEntry(observation))
|
||||
.enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
_entryUpdate.value = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun entryUploadPhotoSalix(
|
||||
idEntry: Number,
|
||||
warehouseId: Number,
|
||||
companyId: Number,
|
||||
dmsTypeId: Number,
|
||||
reference: String,
|
||||
description: String,
|
||||
hasFile: Boolean,
|
||||
urlImage: String,
|
||||
|
||||
) {
|
||||
|
||||
val file = File(urlImage)
|
||||
val fileRequestBody: RequestBody = RequestBody.create(MediaType.parse("image/jpeg"), file)
|
||||
|
||||
salix.uploadEntryPhoto(
|
||||
idEntry,
|
||||
warehouseId,
|
||||
companyId,
|
||||
dmsTypeId,
|
||||
reference,
|
||||
description,
|
||||
hasFile,
|
||||
file = MultipartBody.Part.createFormData(
|
||||
"file", file.name, fileRequestBody
|
||||
)
|
||||
).enqueue(object : SalixCallback<Any>(context) {})
|
||||
}
|
||||
|
||||
fun entryAddFromBuy(id: Number, item: Number, printedStickers: Number) {
|
||||
salix.addFromBuy(id, item, printedStickers)
|
||||
.enqueue(object : SalixCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entryAdd.value = false
|
||||
super.onError(t)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<EntrySalix>) {
|
||||
_entryAdd.value = true
|
||||
super.onSuccess(response)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun notificationQueues(notification: String, workerfk: Int, bodyUrl: String) {
|
||||
salix.notificationQueues(NotificationQueue(notification, workerfk, bodyUrl))
|
||||
.enqueue(object : SalixCallback<Void>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_responseNotification.value = false
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<Void>) {
|
||||
_responseNotification.value = true
|
||||
super.onSuccess(response)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun getItemsPackaging(supplierId: Int, entryId: Int) {
|
||||
salix.getItemsPackaging(supplierId, entryId)
|
||||
.enqueue(object : SalixCallback<List<ItemSupplier>>(context) {
|
||||
|
||||
override fun onSuccess(response: Response<List<ItemSupplier>>) {
|
||||
_itemSupplierList.value = response.body()?.let { ItemSupplierList(it) }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -2,9 +2,7 @@ package es.verdnatura.presentation.view.feature.packaging.model
|
|||
|
||||
data class Supplier(
|
||||
var id: Int? = null,
|
||||
var name: String? = null,
|
||||
var isError: Boolean = false,
|
||||
var errorMessage: String? = null
|
||||
var name: String? = null
|
||||
)
|
||||
|
||||
class SupplierList(
|
||||
|
@ -15,7 +13,7 @@ class EntryList(
|
|||
var list: List<EntrySalix> = listOf()
|
||||
)
|
||||
|
||||
class itemSupplierList(
|
||||
class ItemSupplierList(
|
||||
var list: List<ItemSupplier> = listOf()
|
||||
)
|
||||
|
||||
|
@ -27,8 +25,6 @@ data class ItemSupplier(
|
|||
var printedStickers: Int = 0,
|
||||
var buy: Int? = null,
|
||||
var url: String? = null,
|
||||
var isError: Boolean = false,
|
||||
var errorMessage: String? = null
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -62,41 +62,8 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radiobuttonTypePackaging"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
|
||||
>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioButtonRec"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:buttonTint="@color/verdnatura_white"
|
||||
android:minHeight="48dp"
|
||||
android:text="@string/reception"
|
||||
android:textColor="@color/verdnatura_white" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioButtonDev"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:buttonTint="@color/verdnatura_white"
|
||||
android:minHeight="48dp"
|
||||
android:text="@string/comeback"
|
||||
android:textColor="@color/verdnatura_white" />
|
||||
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -853,5 +853,6 @@
|
|||
<string name="errorScanItem">Error al escanea el artículo. Inténtalo de nuevo</string>
|
||||
<string name="errorSignActivity">Vuelve a pulsar para intentar firmar</string>
|
||||
<string name="runActivityStop">Iniciar parada</string>
|
||||
<string name="errorEntriesNotification">Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -853,5 +853,6 @@
|
|||
<string name="errorScanItem">Error al escanea el artículo. Inténtalo de nuevo</string>
|
||||
<string name="errorSignActivity">Vuelve a pulsar para intentar firmar</string>
|
||||
<string name="runActivityStop">Iniciar parada</string>
|
||||
<string name="errorEntriesNotification">Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -853,5 +853,6 @@
|
|||
<string name="errorScanItem">Error al escanea el artículo. Inténtalo de nuevo</string>
|
||||
<string name="errorSignActivity">Vuelve a pulsar para intentar firmar</string>
|
||||
<string name="runActivityStop">Iniciar parada</string>
|
||||
<string name="errorEntriesNotification">Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -855,5 +855,6 @@
|
|||
<string name="errorScanItem">Error al escanea el artículo. Inténtalo de nuevo</string>
|
||||
<string name="errorSignActivity">Vuelve a pulsar para intentar firmar</string>
|
||||
<string name="runActivityStop">Iniciar parada</string>
|
||||
<string name="errorEntriesNotification">Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue