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