refs #4021
This commit is contained in:
parent
7b1508eed0
commit
c50e803993
|
@ -120,25 +120,32 @@ interface SalixService {
|
|||
"\"scope\":{" +
|
||||
"\"fields\":[\"email\"],\"order\":\"id DESC\",\"limit\":1," +
|
||||
"\"where\":{ \"email\":{\"neq\":null } }}}]})"*/
|
||||
//@Query("filter") filter:String? = """""\"order\":\"name DESC\""""
|
||||
|
||||
):
|
||||
Call<List<Supplier>>
|
||||
|
||||
fun getEntries(
|
||||
/* fun getEntries(
|
||||
//@Body params:JSONObject=JSONObject("""filter"={"fields":{"id":true,"name":true},"include":[{"relation":"contacts","scope":{"fields":["email"],"order":"id DESC","limit":1,"where":{"email":{"neq":null}}}}]}""")
|
||||
/* @Query("filter") filter:String="{\"fields\":{\"id\":true,\"name\":true},\"include\":[{\"relation\":\"contacts\"," +
|
||||
*//* @Query("filter") filter:String="{\"fields\":{\"id\":true,\"name\":true},\"include\":[{\"relation\":\"contacts\"," +
|
||||
"\"scope\":{" +
|
||||
"\"fields\":[\"email\"],\"order\":\"id DESC\",\"limit\":1," +
|
||||
"\"where\":{ \"email\":{\"neq\":null } }}}]})"*/
|
||||
"\"where\":{ \"email\":{\"neq\":null } }}}]})"*//*
|
||||
|
||||
):
|
||||
Call<List<EntrySalix>>
|
||||
Call<List<EntrySalix>>*/
|
||||
|
||||
@PUT("Entries")//REVISADA
|
||||
fun Entries(
|
||||
@Body entry: EntrySalix
|
||||
@Body supplier: Any
|
||||
):
|
||||
Call<EntrySalix>
|
||||
Call<List<EntrySalix>>
|
||||
|
||||
@GET("Entries")//REVISADA
|
||||
fun getEntries_fromSupplier(
|
||||
@Query("filter") filter:String
|
||||
):
|
||||
Call<List<EntrySalix>>
|
||||
|
||||
@GET("Shelvings")
|
||||
fun Shelvings(
|
||||
|
|
|
@ -9,8 +9,6 @@ import es.verdnatura.presentation.base.getMessageFromAllResponse
|
|||
import es.verdnatura.presentation.base.nameofFunction
|
||||
import es.verdnatura.presentation.common.ResponseItemVO
|
||||
import es.verdnatura.presentation.view.feature.packaging.model.*
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
||||
|
@ -24,6 +22,10 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
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
|
||||
|
@ -72,14 +74,14 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
})
|
||||
}
|
||||
|
||||
fun getEntries() {
|
||||
salix.getSuppliers()
|
||||
fun getEntries_fromSupplier(supplier: Int) {
|
||||
salix.getEntries_fromSupplier("""{"where": {"supplierFk": "$supplier","isReceived":"false"},"limit":5}""")
|
||||
.enqueue(object :
|
||||
SilexCallback<List<Supplier>>(context) {
|
||||
SilexCallback<List<EntrySalix>>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
val listError: ArrayList<Supplier> = ArrayList()
|
||||
val listError: ArrayList<EntrySalix> = ArrayList()
|
||||
listError.add(
|
||||
Supplier(
|
||||
EntrySalix(
|
||||
isError = true,
|
||||
errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this),
|
||||
|
@ -87,16 +89,16 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
)
|
||||
)
|
||||
)
|
||||
_supplierList.value = SupplierList(listError)
|
||||
_entryList.value = EntryList(listError)
|
||||
}
|
||||
|
||||
override fun onSuccess(response: Response<List<Supplier>>) {
|
||||
override fun onSuccess(response: Response<List<EntrySalix>>) {
|
||||
if (response.body() != null) {
|
||||
_supplierList.value = response.body()?.let { SupplierList(it) }
|
||||
_entryList.value = response.body()?.let { EntryList(it) }
|
||||
} else {
|
||||
val listError: ArrayList<Supplier> = ArrayList()
|
||||
val listError: ArrayList<EntrySalix> = ArrayList()
|
||||
listError.add(
|
||||
Supplier(
|
||||
EntrySalix(
|
||||
isError = true,
|
||||
errorMessage = getMessageFromAllResponse(
|
||||
nameofFunction(this),
|
||||
|
@ -104,7 +106,7 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
)
|
||||
)
|
||||
)
|
||||
_supplierList.value = SupplierList(listError)
|
||||
_entryList.value = EntryList(listError)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -144,10 +146,10 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
})
|
||||
}
|
||||
|
||||
fun entry_addSalix(entry: EntrySalix) {
|
||||
salix.Entries(entry = entry)
|
||||
/* fun entry_addSalix(entry: EntrySalix) {
|
||||
salix.getEntries(entry)
|
||||
.enqueue(object :
|
||||
SilexCallback<EntrySalix> (context){
|
||||
SilexCallback<EntrySalix>(context) {
|
||||
override fun onError(t: Throwable) {
|
||||
_entry.value = EntrySalix(
|
||||
isError = true,
|
||||
|
@ -173,5 +175,5 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
|
|||
|
||||
}
|
||||
})
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package es.verdnatura.presentation.view.feature.packaging.fragment
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log.d
|
||||
|
@ -10,12 +9,12 @@ import es.verdnatura.R
|
|||
import es.verdnatura.databinding.FragmentPackagingBinding
|
||||
import es.verdnatura.presentation.base.BaseFragment
|
||||
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
|
||||
import es.verdnatura.presentation.common.convertToDateString
|
||||
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
|
||||
import ir.mirrajabi.searchdialog.SimpleSearchDialogCompat
|
||||
|
||||
|
||||
|
@ -31,6 +30,7 @@ class SupplierFragment(
|
|||
private var layoutManager: LinearLayoutManager? = null
|
||||
private var onBack = false
|
||||
private val suppliers = ArrayList<SearchSupplierModel>()
|
||||
private val entries = ArrayList<SearchSupplierModel>()
|
||||
private lateinit var customDialog: CustomDialog
|
||||
|
||||
|
||||
|
@ -47,8 +47,8 @@ class SupplierFragment(
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
viewModel.getSuppliers(
|
||||
)
|
||||
viewModel.getSuppliers()
|
||||
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
@ -74,15 +74,17 @@ class SupplierFragment(
|
|||
binding.radiobuttonTypePackaging.visibility = View.VISIBLE
|
||||
saveData("SUPPLIERNAME", nombre.getName())
|
||||
saveData("SUPPLIERID", nombre.getId())
|
||||
viewModel.getEntries_fromSupplier(nombre.getId().toInt())
|
||||
baseSearchDialogCompat.dismiss()
|
||||
}.show()
|
||||
}
|
||||
|
||||
|
||||
ma.hideBottomNavigation(View.GONE)
|
||||
setToolBar()
|
||||
setEvents()
|
||||
|
||||
val entry = EntrySalix(supplierFk = "591", travelFk = "186025", companyFk = "442")
|
||||
val entry = EntrySalix(supplierFk = 591, travelFk = 186025, companyFk = 442)
|
||||
// viewModel.entry_addSalix(entry)
|
||||
|
||||
super.init()
|
||||
|
@ -97,46 +99,47 @@ class SupplierFragment(
|
|||
binding.mainToolbar.backButton.setOnClickListener {
|
||||
requireActivity().onBackPressed()
|
||||
}
|
||||
binding.filterEntry.setOnClickListener {
|
||||
/*binding.filterEntry.setOnClickListener {
|
||||
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(getString(R.string.selectEntryToFill))
|
||||
val labelCount = arrayOf("Entrada 1", "Entrada 2", "Añadir Nueva")
|
||||
builder.setItems(labelCount) { dialog, which ->
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(getString(R.string.selectEntryToFill))
|
||||
val labelCount = arrayOf("Entrada 1", "Entrada 2", "Añadir Nueva")
|
||||
builder.setItems(labelCount) { dialog, which ->
|
||||
|
||||
if (labelCount[which] == "Añadir Nueva") {
|
||||
customDialog = CustomDialog(requireContext())
|
||||
customDialog.setTitle(getString(R.string.newEntry))
|
||||
.setDescription(getString(R.string.confirmEntry))
|
||||
.setOkButton(
|
||||
getString(
|
||||
R.string.createEntry
|
||||
)
|
||||
) {
|
||||
d("VERDNATURA::", "borrado")
|
||||
}
|
||||
if (labelCount[which] == "Añadir Nueva") {
|
||||
customDialog = CustomDialog(requireContext())
|
||||
customDialog.setTitle(getString(R.string.newEntry))
|
||||
.setDescription(getString(R.string.confirmEntry))
|
||||
.setOkButton(
|
||||
getString(
|
||||
R.string.createEntry
|
||||
)
|
||||
) {
|
||||
d("VERDNATURA::", "borrado")
|
||||
}
|
||||
|
||||
.setKoButton(getString(R.string.cancel)) {
|
||||
customDialog.cancel()
|
||||
customDialog.dismiss()
|
||||
.setKoButton(getString(R.string.cancel)) {
|
||||
customDialog.cancel()
|
||||
customDialog.dismiss()
|
||||
|
||||
|
||||
}
|
||||
customDialog.show()
|
||||
}
|
||||
customDialog.show()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ma.onPasillerosItemClickListener(
|
||||
PasillerosItemVO(title = getString(R.string.titlePackagingCount)),
|
||||
getString(R.string.titlePackagingCount)
|
||||
)
|
||||
ma.onPasillerosItemClickListener(
|
||||
PasillerosItemVO(title = getString(R.string.titlePackagingCount)),
|
||||
getString(R.string.titlePackagingCount)
|
||||
)
|
||||
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
binding.radiobuttonTypePackaging.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||
when (isChecked) {
|
||||
R.id.radioButtonRec -> {
|
||||
|
@ -161,6 +164,24 @@ class SupplierFragment(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setEntryDialog() {
|
||||
binding.filterEntry.setOnClickListener {
|
||||
SimpleSearchDialogCompat(
|
||||
context,
|
||||
getString(R.string.Entrada),
|
||||
getString(R.string.escribirparteNombre),
|
||||
null,
|
||||
entries
|
||||
) { baseSearchDialogCompat, nombre, position ->
|
||||
binding.filterEntry.setText((nombre.getName()))
|
||||
binding.radiobuttonTypePackaging.visibility = View.VISIBLE
|
||||
saveData("ENTRYID", nombre.getId())
|
||||
baseSearchDialogCompat.dismiss()
|
||||
}.show()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun observeViewModel() {
|
||||
with(viewModel) {
|
||||
|
@ -168,6 +189,10 @@ class SupplierFragment(
|
|||
binding.splashProgress.visibility = View.GONE
|
||||
createSupplierList(it.list)
|
||||
}
|
||||
entryList.observe(viewLifecycleOwner) {
|
||||
binding.splashProgress.visibility = View.GONE
|
||||
createEntryList(it.list)
|
||||
}
|
||||
|
||||
response.observe(viewLifecycleOwner) {
|
||||
if (it.isError) {
|
||||
|
@ -191,5 +216,25 @@ class SupplierFragment(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createEntryList(list: List<EntrySalix>) {
|
||||
entries.clear()
|
||||
list.forEach { entry ->
|
||||
if (!entry.isError!!) {
|
||||
try {
|
||||
entries.add(
|
||||
SearchSupplierModel(
|
||||
entry.id.toString() + "->" + convertToDateString( entry.dated.toString()),
|
||||
id = entry.id.toString()
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entries.add(SearchSupplierModel("Añadir Nueva", ""))
|
||||
setEntryDialog()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,28 @@
|
|||
package es.verdnatura.presentation.view.feature.packaging.model
|
||||
|
||||
import android.content.Context
|
||||
import es.verdnatura.presentation.common.convertToDateString
|
||||
import java.util.ArrayList
|
||||
|
||||
class EntrySalix(
|
||||
var id: Int? = null,
|
||||
var dated: String? = null,
|
||||
var supplierFk: Int? = null,
|
||||
var travelFk: Int? = null,
|
||||
var companyFk: Int? = null,
|
||||
var isError: Boolean? = null,
|
||||
var errorMessage: String? = null
|
||||
var isError: Boolean = false,
|
||||
var errorMessage: String = ""
|
||||
)
|
||||
|
||||
fun List<EntrySalix>.toDateFormat(): ArrayList<EntrySalix> {
|
||||
val entries: ArrayList<EntrySalix> = ArrayList()
|
||||
this.forEach {
|
||||
entries.add(
|
||||
EntrySalix(
|
||||
dated = convertToDateString(it.dated),
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
return entries.sortedBy{it.dated} as ArrayList
|
||||
}
|
|
@ -13,7 +13,9 @@ data class Supplier(
|
|||
class SupplierList(
|
||||
var list: List<Supplier> = listOf()
|
||||
)
|
||||
|
||||
class EntryList(
|
||||
var list: List<EntrySalix> = listOf()
|
||||
)
|
||||
class itemSupplierList(
|
||||
var list: List<ItemSupplier> = listOf()
|
||||
)
|
||||
|
|
|
@ -28,4 +28,4 @@ private fun getCalendarFromDate(date: String, context: Context): Calendar {
|
|||
val cal = Calendar.getInstance()
|
||||
cal.time = sdf.parse(date)!!
|
||||
return cal
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue