diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index 0a7a1c3a..e1392b8b 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -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()) diff --git a/app/src/main/java/es/verdnatura/domain/SalixService.kt b/app/src/main/java/es/verdnatura/domain/SalixService.kt index c6e01f60..0d41c7a1 100644 --- a/app/src/main/java/es/verdnatura/domain/SalixService.kt +++ b/app/src/main/java/es/verdnatura/domain/SalixService.kt @@ -867,11 +867,6 @@ interface SalixService { @Query("filter") filter: String ): Call> - @GET("Entries") - fun addEntry( - @Body entry: EntrySalix - ): Call - @PATCH("Entries/{entryId}") fun entryUpdateObserv( @Path("entryId") entryId: Int, @Body entry: ObervationEntry diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/ObservFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/ObservFragment.kt index 4b2a3a54..07ccf98c 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/ObservFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/ObservFragment.kt @@ -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( - PackagingViewModel::class +) : BaseFragment( + 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(ENTRYID), warehouseId = mobileApplication.dataStoreApp.readDataStoreKey( 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(ENTRYID), warehouseId = mobileApplication.dataStoreApp.readDataStoreKey( WAREHOUSEFK diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingCountFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingCountFragment.kt index 43eda33e..d46a0183 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingCountFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingCountFragment.kt @@ -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( - PackagingViewModel::class +) : BaseFragment( + 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(ENTRYID), item = item.id!!.toInt(), item.printedStickers.plus(customDialogInput.getValue().toInt()) ) - /* (if (mobileApplication.dataStoreApp.readDataStoreKey("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("ENTRYID"), item = item.id!!.toInt(), printedStickers = 0 diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingSummaryFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingSummaryFragment.kt index 0b78cf6f..04af6f2e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingSummaryFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingSummaryFragment.kt @@ -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( - PackagingViewModel::class +) : BaseFragment( + 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) { - - deleteDataEntry() - + responseNotification.observe(viewLifecycleOwner) { + if (it == true) { + deleteDataEntry() + } else { + ma.messageWithSound( + getString(R.string.errorEntriesNotification), + isError = true, + isPlayed = true + ) + } } } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingViewModel/SupplierViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingViewModel/SupplierViewModel.kt deleted file mode 100644 index b08f07ea..00000000 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/PackagingViewModel/SupplierViewModel.kt +++ /dev/null @@ -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() } - val itemSupplierList: LiveData - get() = _itemSupplierList - - private val _supplierList by lazy { MutableLiveData() } - val supplierList: LiveData - get() = _supplierList - - private val _entryList by lazy { MutableLiveData() } - val entryList: LiveData - get() = _entryList - - private val _entry by lazy { MutableLiveData() } - val entry: LiveData - get() = _entry - - private val _entryUpdate by lazy { MutableLiveData() } - val entryUpdate: LiveData - get() = _entryUpdate - - val loadEntryUpdate: LiveData> = _entryUpdate.map { Event(it) } - - private val _entryAdd by lazy { MutableLiveData() } - val entryAdd: LiveData - get() = _entryAdd - - private val _uploadEntryImage by lazy { MutableLiveData() } - val uploadEntryImage: LiveData - get() = _uploadEntryImage - - private val _response by lazy { MutableLiveData() } - val response: LiveData - get() = _response - - val loadEntryAdd: LiveData> = _entryAdd.map { Event(it) } - - fun getSuppliers() { - salix.getSuppliers().enqueue(object : SalixCallback>(context) { - override fun onError(t: Throwable) { - val listError: ArrayList = ArrayList() - listError.add( - Supplier( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - ) - _supplierList.value = SupplierList(listError) - } - - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _supplierList.value = response.body()?.let { SupplierList(it) } - } else { - val listError: ArrayList = 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(context) { - override fun onError(t: Throwable) { - _entry.value = EntrySalix( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - } - - override fun onSuccess(response: Response) { - 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>(context) { - - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _entryList.value = response.body()?.let { EntryList(it) } - } else { - val listError: ArrayList = 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>(context) { - override fun onError(t: Throwable) { - val listError: ArrayList = ArrayList() - listError.add( - ItemSupplier( - isError = true, - errorMessage = getMessageFromAllResponse( - nameofFunction(this), - t.message!! - ) - ) - ) - _itemSupplierList.value = itemSupplierList(listError) - } - - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _itemSupplierList.value = - response.body()?.let { itemSupplierList(it) } - } else { - val listError: ArrayList = ArrayList() - listError.add(ItemSupplier(null, null)) - _itemSupplierList.value = itemSupplierList(listError) - } - } - - })*/ - } - - fun entry_addSalix(entry: EntrySalix) { - salix.addEntry(entry).enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _entry.value = EntrySalix( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - } - - override fun onSuccess(response: Response) { - 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(context) { - - override fun onSuccess(response: Response) { - _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(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(context) { - override fun onError(t: Throwable) { - _entryAdd.value = EntrySalix( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - } - - override fun onSuccess(response: Response) { - 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(context) { - override fun onError(t: Throwable) { - _response.value = ResponseItemVO( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - } - - override fun onSuccess(response: Response) { - - _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(context) { - override fun onError(t: Throwable) { - _entryAdd.value = EntrySalix( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - } - - override fun onSuccess(response: Response) { - 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>(context) { - override fun onError(t: Throwable) { - val listError: ArrayList = ArrayList() - listError.add( - ItemSupplier( - isError = true, errorMessage = getMessageFromAllResponse( - nameofFunction(this), t.message!! - ) - ) - ) - _itemSupplierList.value = itemSupplierList(listError) - } - - override fun onSuccess(response: Response>) { - if (response.body() != null) { - _itemSupplierList.value = response.body()?.let { itemSupplierList(it) } - } else { - val listError: ArrayList = ArrayList() - listError.add(ItemSupplier(null, null)) - _itemSupplierList.value = itemSupplierList(listError) - } - } - - }) - } -} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierFragment.kt index aed2bc4f..154867c8 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierFragment.kt @@ -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( - PackagingViewModel::class +) : BaseFragment( + 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) { suppliers.clear() - list.forEach { supplier -> - if (!supplier.isError) { + if (list.isNotEmpty()) + + list.forEach { supplier -> + try { suppliers.add( SearchSupplierModel( @@ -247,8 +183,8 @@ class SupplierFragment( isPlayed = true ) } + } - } } private fun createEntryList(list: List) { @@ -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("ENTRYTYPE") == "Rec" - ) - - } - - .setKoButton(getString(R.string.cancel)) { - customDialog.cancel() - customDialog.dismiss() - - } - .show() - }*/ - } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierViewModel.kt new file mode 100644 index 00000000..9b2c92ef --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/fragment/SupplierViewModel.kt @@ -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() } + val itemSupplierList: LiveData + get() = _itemSupplierList + + private val _supplierList by lazy { MutableLiveData() } + val supplierList: LiveData + get() = _supplierList + + private val _entryList by lazy { MutableLiveData() } + val entryList: LiveData + get() = _entryList + + private val _entry by lazy { MutableLiveData() } + val entry: LiveData + get() = _entry + + private val _entryUpdate by lazy { MutableLiveData() } + val entryUpdate: LiveData + get() = _entryUpdate + + val loadEntryUpdate: LiveData> = _entryUpdate.map { Event(it) } + + private val _entryAdd by lazy { MutableLiveData() } + val entryAdd: LiveData + get() = _entryAdd + + private val _responseNotification by lazy { MutableLiveData() } + val responseNotification: LiveData + get() = _responseNotification + + val loadEntryAdd: LiveData> = _entryAdd.map { Event(it) } + + fun getSuppliers() { + salix.getSuppliers().enqueue(object : SalixCallback>(context) { + + override fun onSuccess(response: Response>) { + _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>(context) { + + override fun onSuccess(response: Response>) { + _entryList.value = response.body()?.let { EntryList(it) } + } + + }) + } + + fun entryUpdateObserv(entryId: Int, observation: String) { + salix.entryUpdateObserv(entryId, ObervationEntry(observation)) + .enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + _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(context) {}) + } + + fun entryAddFromBuy(id: Number, item: Number, printedStickers: Number) { + salix.addFromBuy(id, item, printedStickers) + .enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + _entryAdd.value = false + super.onError(t) + } + + override fun onSuccess(response: Response) { + _entryAdd.value = true + super.onSuccess(response) + + } + }) + } + + fun notificationQueues(notification: String, workerfk: Int, bodyUrl: String) { + salix.notificationQueues(NotificationQueue(notification, workerfk, bodyUrl)) + .enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + _responseNotification.value = false + } + + override fun onSuccess(response: Response) { + _responseNotification.value = true + super.onSuccess(response) + + } + }) + } + + fun getItemsPackaging(supplierId: Int, entryId: Int) { + salix.getItemsPackaging(supplierId, entryId) + .enqueue(object : SalixCallback>(context) { + + override fun onSuccess(response: Response>) { + _itemSupplierList.value = response.body()?.let { ItemSupplierList(it) } + } + }) + } +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/model/Supplier.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/model/Supplier.kt index f7cde9cb..2e09e8cc 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/model/Supplier.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packaging/model/Supplier.kt @@ -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 = listOf() ) -class itemSupplierList( +class ItemSupplierList( var list: List = 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 ) diff --git a/app/src/main/res/layout/fragment_packaging.xml b/app/src/main/res/layout/fragment_packaging.xml index 316b19d6..f8b291e6 100644 --- a/app/src/main/res/layout/fragment_packaging.xml +++ b/app/src/main/res/layout/fragment_packaging.xml @@ -62,41 +62,8 @@ - - - - - - - - - - - Error al escanea el artículo. Inténtalo de nuevo Vuelve a pulsar para intentar firmar Iniciar parada + Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 98de2cf4..98701b87 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -853,5 +853,6 @@ Error al escanea el artículo. Inténtalo de nuevo Vuelve a pulsar para intentar firmar Iniciar parada + Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index bd9346ab..a40d6de8 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -853,5 +853,6 @@ Error al escanea el artículo. Inténtalo de nuevo Vuelve a pulsar para intentar firmar Iniciar parada + Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3536aa7b..dc4ec934 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -855,5 +855,6 @@ Error al escanea el artículo. Inténtalo de nuevo Vuelve a pulsar para intentar firmar Iniciar parada + Vuelve a intentarlo. Datos guardados pero no se ha enviado notificación