diff --git a/app/build.gradle b/app/build.gradle index a143f30e..0623c5cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "es.verdnatura" minSdkVersion 21 targetSdkVersion 29 - versionCode 2 - versionName "5.0.1" + versionCode 4 + versionName "5.0.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index 450145aa..ce2c3f88 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -4,8 +4,11 @@ import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesViewModel import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardViewModel import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemViewModel import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasViewModel +import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoViewModel import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryViewModel import es.verdnatura.presentation.view.feature.login.fragment.LoginViewModel +import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPalletViewModel +import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionTruckListViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemViewModel @@ -29,6 +32,11 @@ val viewModelModule = module{ ItemCardViewModel() } + // Pasilleros / Item Card / Historico + viewModel { + HistoricoViewModel() + } + // Pasilleros / Buscar Item viewModel { BuscarItemViewModel() @@ -62,4 +70,13 @@ val viewModelModule = module{ viewModel { AjustesViewModel() } + + // PALETIZADOR + viewModel { + ExpeditionTruckListViewModel() + } + + viewModel { + ExpeditionPalletViewModel() + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt index da71638f..9f3228eb 100644 --- a/app/src/main/java/es/verdnatura/domain/ApiUtils.kt +++ b/app/src/main/java/es/verdnatura/domain/ApiUtils.kt @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit class ApiUtils { companion object { - //const val BASE_URL:String = "http://192.168.1.108:8000/" + //const val BASE_URL:String = "http://192.168.1.108:8008/" const val BASE_URL:String = "https://app.verdnatura.es/" fun getApiService():VerdnaturaService{ val retrofit = Retrofit.Builder() diff --git a/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt index 8ea18dd2..6ae7a494 100644 --- a/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt +++ b/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt @@ -1,6 +1,7 @@ package es.verdnatura.domain import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO import retrofit2.Call class GetItemCardUserCase : RestClient() { @@ -60,4 +61,11 @@ class GetItemCardUserCase : RestClient() { params.add(delete) return restClient!!.barcodes_edit("json","1",usuario,password,"application/json",params = params) } + + fun itemDiary(usuario:String,password:String,itemFk:String,warehouseFk: String) : Call> { + val params:ArrayList = ArrayList(); + params.add(itemFk) + params.add(warehouseFk) + return restClient!!.itemDiary("json","1",usuario,password,"application/json",params = params) + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/GetPaletizadoresUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetPaletizadoresUserCase.kt new file mode 100644 index 00000000..dee48fc4 --- /dev/null +++ b/app/src/main/java/es/verdnatura/domain/GetPaletizadoresUserCase.kt @@ -0,0 +1,35 @@ +package es.verdnatura.domain + +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO +import retrofit2.Call + +class GetPaletizadoresUserCase: RestClient() { + + fun expeditionTruckList(usuario:String,password:String) : Call> { + val params:ArrayList = ArrayList(); + return restClient!!.expeditionTruckList("json","1",usuario,password,"application/json") + } + + fun expeditionTruckAdd(usuario:String,password:String,vHour:String,vDescription:String) : Call { + val params:ArrayList = ArrayList(); + params.add(vHour) + params.add(vDescription) + return restClient!!.expeditionTruckAdd("json","1",usuario,password,"application/json",params) + } + + fun expeditionPallet_List(usuario:String,password:String,vTruckFk:String) : Call> { + val params:ArrayList = ArrayList(); + params.add(vTruckFk) + return restClient!!.expeditionPallet_List("json","1",usuario,password,"application/json",params) + } + + fun expeditionScanAdd(usuario:String,password:String,vPalletFk:String,vTruckFk:String) : Call> { + val params:ArrayList = ArrayList(); + params.add(vPalletFk) + params.add(vTruckFk) + return restClient!!.expeditionScanAdd("json","1",usuario,password,"application/json",params) + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index b870106f..316ed7cc 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -6,7 +6,11 @@ import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO import es.verdnatura.presentation.view.feature.faltas.model.ItemFaltasVO +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import retrofit2.Call @@ -51,13 +55,22 @@ interface VerdnaturaService { //PASILLEROS ========================================================================> //CONSULTAR ARTICULO ========================================================================> - @POST("almacennew/item_card") - fun getItemCard(@Header("aplicacion") aplicacion: String, + @POST("almacennew/itemDiary") + fun itemDiary(@Header("aplicacion") aplicacion: String, @Header("version") version: String, @Header("user") user: String, @Header("pass") pass: String, @Header("Content-Type") content_type: String, @Body params: List): + Call> + + @POST("almacennew/item_card") + fun getItemCard(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): Call @POST("almacennew/itemStockUpdate") @@ -236,5 +249,40 @@ interface VerdnaturaService { @Body params: List): Call + //PALETIZADORES ========================================================================> + @POST("almacennew/expeditionTruckList") + fun expeditionTruckList(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String): + Call> + + @POST("almacennew/expeditionTruckAdd") + fun expeditionTruckAdd(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call + + @POST("almacennew/expeditionPalletList") + fun expeditionPallet_List(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call> + + @POST("almacennew/expeditionScanAdd") + fun expeditionScanAdd(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call> } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt index cdfa81ae..74bcd7b5 100644 --- a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt @@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment import org.koin.androidx.viewmodel.ext.android.viewModel import kotlin.reflect.KClass + abstract class BaseFragment(viewModelClass: KClass) : Fragment() { @@ -59,4 +60,6 @@ abstract class BaseFragment(viewModelCla lifecycle.addObserver(this@BaseFragment.viewModel) addBindingVariables() } + + } diff --git a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index 7f2d3a09..f2aea39c 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -7,6 +7,8 @@ import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO import es.verdnatura.presentation.view.feature.faltas.model.ItemFaltasVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO @@ -57,4 +59,12 @@ interface OnVisibleClickListener { interface OnMoreClickListener { fun onMoreClickListener(item: ItemUbicadorVO) +} + +interface OnTruckClickListener { + fun onTruckClickListener(item: ItemExpeditionTruckVO,entryPoint: String) +} + +interface OnPalletClickListener { + fun onPalletClickListener(item: ItemPalletVO,entryPoint: String) } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogHour.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogHour.kt new file mode 100644 index 00000000..5ac7a84b --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogHour.kt @@ -0,0 +1,84 @@ +package es.verdnatura.presentation.view.component + +import android.app.Dialog +import android.app.TimePickerDialog +import android.content.Context +import android.view.View +import com.google.android.material.textfield.TextInputEditText +import es.verdnatura.R +import kotlinx.android.synthetic.main.component_custom_hour.* +import java.text.SimpleDateFormat +import java.util.* + + +class CustomDialogHour(context: Context) : Dialog(context, R.style.DialogTheme) { + + init { + setContentView(R.layout.component_custom_hour) + } + + fun getDestinoEditText(): TextInputEditText { + return custom_dialog_destino_value + } + + fun getDestinoValue(): String { + return custom_dialog_destino_value.text.toString() + } + + fun setDestinoValue(value: String): CustomDialogHour { + custom_dialog_destino_value.setText(value) + custom_dialog_destino_value.visibility = View.VISIBLE + return this + } + + + fun getHoraEditText(): TextInputEditText { + return custom_dialog_hour_value + } + + fun getHoraValue(): String { + return custom_dialog_hour_value.text.toString() + } + + fun setHoraValue(value: String): CustomDialogHour { + custom_dialog_hour_value.setText(value) + custom_dialog_hour_value.visibility = View.VISIBLE + ib_obtener_hora.setOnClickListener { + val cal = Calendar.getInstance() + val timeSetListener = TimePickerDialog.OnTimeSetListener { timePicker, hour, minute -> + cal.set(Calendar.HOUR_OF_DAY, hour) + cal.set(Calendar.MINUTE, minute) + custom_dialog_hour_value.setText(SimpleDateFormat("HH:mm").format(cal.time)) + } + TimePickerDialog(context, timeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true).show() + } + return this + } + + fun setTitle(title: String): CustomDialogHour { + custom_dialog_title.visibility = View.VISIBLE + custom_dialog_title.text = title + return this + } + + fun setDescription(description: String): CustomDialogHour { + custom_dialog_description.visibility = View.VISIBLE + custom_dialog_description.text = description + return this + } + + fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogHour { + custom_dialog_button_ok.visibility = View.VISIBLE + custom_dialog_button_ok.text = text + custom_dialog_button_ok.setOnClickListener { onButtonClicked() } + return this + } + + fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogHour { + custom_dialog_button_ko.visibility = View.VISIBLE + custom_dialog_button_ko.text = text + custom_dialog_button_ko.setOnClickListener { onButtonClicked() } + return this + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index a132d19f..551d535b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt @@ -11,6 +11,7 @@ import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R import es.verdnatura.databinding.FragmentItemCardBinding +import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.OnItemCardRowClickListener @@ -73,16 +74,28 @@ class ItemCardFragment( super.init() } + + private fun setToolBar(){ val listIcons:ArrayList = ArrayList() val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + val iconHistory : Drawable = resources.getDrawable(R.drawable.ic_history_black_24dp,resources.newTheme()) listIcons.add(iconReload) + listIcons.add(iconHistory) toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { override fun onOptionsItemSelected(item: Drawable) { if (item == iconReload){ splash_progress.visibility = View.VISIBLE getItemCard(itemFk) } + if (item == iconHistory){ + if (itemFk.isNullOrEmpty()){ + "Escanea un item".toast(activity!!) + }else{ + (activity as MainActivity).onPasillerosItemClickListener( PasillerosItemVO(title = "Historico"),itemFk) + } + + } } }) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemCardVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemCardVO.kt index ad2640ab..67f8495f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemCardVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/model/ItemCardVO.kt @@ -44,3 +44,5 @@ class BarcodeVO( var code:String? = "" ) + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/adapter/HistoricoAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/adapter/HistoricoAdapter.kt new file mode 100644 index 00000000..a40b0f69 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/adapter/HistoricoAdapter.kt @@ -0,0 +1,46 @@ +package es.verdnatura.presentation.view.feature.historico.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.ItemHistoricoRowBinding +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO +import java.text.SimpleDateFormat +import java.util.* + +class HistoricoAdapter ( + private val items: List +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemHistoricoRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + } + + inner class ItemHolder( + val binding: ItemHistoricoRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + private val res = binding.root.context.resources + fun bind(item: ItemHistoricoVO) { + binding.apply { + this.item = item + val sdf = SimpleDateFormat("yyyy-MM-dd") + val currentDate = sdf.format(Date()) + if (currentDate == item.date){ + historicoDate.setBackgroundColor(res.getColor(R.color.verdnatura_pumpkin_orange)) + }else{ + historicoDate.setBackgroundColor(res.getColor(R.color.verdnatura_black_5)) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoFragment.kt new file mode 100644 index 00000000..2d499e01 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoFragment.kt @@ -0,0 +1,94 @@ +package es.verdnatura.presentation.view.feature.historico.fragment + +import android.content.SharedPreferences +import android.view.View +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentHistoricoBinding +import es.verdnatura.domain.notNull +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.feature.historico.adapter.HistoricoAdapter +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoListVO +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_historico.* +import kotlinx.android.synthetic.main.toolbar.* +import java.text.SimpleDateFormat +import java.util.* + +class HistoricoFragment( + var itemFk:String = "" +) : BaseFragment( + HistoricoViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var adapter : HistoricoAdapter? = null + private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialog: CustomDialog + + + companion object { + fun newInstance(entryPoint:String) = HistoricoFragment(entryPoint) + } + + override fun getLayoutId(): Int = R.layout.fragment_historico + + + override fun init() { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + customDialogInput = CustomDialogInput(requireContext()) + customDialog = CustomDialog(requireContext()) + activity!!.main_bottom_navigation.visibility = View.GONE + viewModel.itemDiary(user,password,itemFk,warehouseFk) + toolbar_title.text = "itemDiary" + setEvents() + super.init() + } + + + private fun setEvents(){ + backButton.setOnClickListener { + activity!!.onBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel){ + loadHistoricoList.observe(viewLifecycleOwner, Observer { event -> + event.getContentIfNotHandled().notNull { + splash_progress.visibility = View.GONE + adapter = HistoricoAdapter(it.list) + historico_recyclerview.adapter = adapter + historico_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + navigateToToday(it) + + } + }) + } + } + + private fun navigateToToday(it:ItemHistoricoListVO){ + var positionToday = 0 + val sdf = SimpleDateFormat("yyyy-MM-dd") + val currentDate = sdf.format(Date()) + + for (item in it.list){ + if (currentDate == item.date){ + break + } + positionToday += 1 + } + + historico_recyclerview.scrollToPosition(positionToday) + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt new file mode 100644 index 00000000..9c14a6f8 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/fragment/HistoricoViewModel.kt @@ -0,0 +1,56 @@ +package es.verdnatura.presentation.view.feature.historico.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Transformations +import es.verdnatura.domain.GetItemCardUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoListVO +import es.verdnatura.presentation.view.feature.historico.model.ItemHistoricoVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class HistoricoViewModel : BaseViewModel() { + private val getItemCardUserCase: GetItemCardUserCase = GetItemCardUserCase() + + + + private val _historicoList by lazy { MutableLiveData() } + val historicoList: LiveData + get() = _historicoList + + + val loadHistoricoList = Transformations.map(_historicoList) { Event(it) } + + + fun itemDiary(usuario:String,password:String,itemFk:String,vWarehouseFk:String){ + getItemCardUserCase.itemDiary(usuario,password,itemFk,vWarehouseFk).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(ItemHistoricoVO(isError = true,errorMessage = t.message!!)) + _historicoList.value = ItemHistoricoListVO(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _historicoList.value = response.body()?.let { ItemHistoricoListVO(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(ItemHistoricoVO(isError = true,errorMessage = "Error en la llamada de shelvingParking_get")) + _historicoList.value = ItemHistoricoListVO(listError) + } + } + + }) + } + + + + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historico/model/ItemHistoricoVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/model/ItemHistoricoVO.kt new file mode 100644 index 00000000..22f16505 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historico/model/ItemHistoricoVO.kt @@ -0,0 +1,19 @@ +package es.verdnatura.presentation.view.feature.historico.model + +class ItemHistoricoVO ( + var date:String = "", + var stateName:String = "", + var origin:String = "", + var reference: String = "", + var clientFk: String = "", + var name:String = "", + var invalue:String = "-", + var out:String = "-", + var balance:String = "-", + var isError:Boolean = false, + var errorMessage:String = "" +) + +class ItemHistoricoListVO( + var list:List = listOf() +) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt index 3998db85..8e826038 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt @@ -98,7 +98,7 @@ class LoginFragment : BaseFragment (LoginVi }.show() }else{ - customDialog.setTitle("Error").setDescription("Existe una versión nueva, es recomendable actualizar.").setOkButton("Actualizar"){ + customDialog.setTitle("Actualizar").setDescription("Existe una versión nueva, es recomendable actualizar.").setOkButton("Actualizar"){ val openURL = Intent(Intent.ACTION_VIEW) openURL.data = Uri.parse("https://app.verdnatura.es/bin/vn-pickingV2.apk") startActivity(openURL) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index ca7552b0..f42e1868 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -10,16 +10,19 @@ import es.verdnatura.R import es.verdnatura.databinding.ActivityMainBinding import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseActivity -import es.verdnatura.presentation.common.OnPasillerosItemClickListener -import es.verdnatura.presentation.common.TAG -import es.verdnatura.presentation.common.addFragment +import es.verdnatura.presentation.common.* import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesFragment import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardFragment import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment import es.verdnatura.presentation.view.feature.faltas.fragment.FaltasFragment +import es.verdnatura.presentation.view.feature.historico.fragment.HistoricoFragment import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryFragment import es.verdnatura.presentation.view.feature.main.model.ItemMenuVO +import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionPalletFragment +import es.verdnatura.presentation.view.feature.paletizador.fragment.ExpeditionTruckListFragment +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment @@ -31,7 +34,8 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -class MainActivity : BaseActivity() , OnPasillerosItemClickListener { +class MainActivity : BaseActivity() , OnPasillerosItemClickListener, + OnTruckClickListener, OnPalletClickListener { private var lastBottomMenuItemSelected: ItemMenuVO? = null private lateinit var customDialog: CustomDialog @@ -73,7 +77,11 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick applicationContext,R.drawable.ic_verified_user_black_24dp),selectedImage = ContextCompat.getDrawable( applicationContext,R.drawable.ic_verified_user_black_24dp_selected))) - bottomMenuItems.add(ItemMenuVO(3,title = "Ajustes",defaultImage = ContextCompat.getDrawable( + bottomMenuItems.add(ItemMenuVO(3,title = "Paletizadores",defaultImage = ContextCompat.getDrawable( + applicationContext,R.drawable.ic_local_shipping_black_24dp),selectedImage = ContextCompat.getDrawable( + applicationContext,R.drawable.ic_local_shipping_black_24dp_selected))) + + bottomMenuItems.add(ItemMenuVO(4,title = "Ajustes",defaultImage = ContextCompat.getDrawable( applicationContext,R.drawable.ic_build_black_24dp),selectedImage = ContextCompat.getDrawable( applicationContext,R.drawable.ic_build_black_24dp_selected))) @@ -123,6 +131,11 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick "Función Controladores desactivada".toast(this@MainActivity) true } + "Paletizadores" -> { + fm.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE) + addFragment(ExpeditionTruckListFragment.newInstance(),R.id.main_frame_layout, ExpeditionTruckListFragment.TAG,false) + true + } "Ajustes" -> { fm.popBackStack(null,FragmentManager.POP_BACK_STACK_INCLUSIVE) addFragment(AjustesFragment.newInstance(),R.id.main_frame_layout, AjustesFragment.TAG,false) @@ -148,6 +161,9 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick "Buscar item" -> { addFragmentOnTop(BuscarItemFragment.newInstance(entryPoint)) } + "Historico" -> { + addFragmentOnTop(HistoricoFragment.newInstance(entryPoint)) + } "Inventario" -> { addFragmentOnTop(InventaryFragment.newInstance()) } @@ -192,4 +208,12 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick } + override fun onTruckClickListener(item: ItemExpeditionTruckVO, entryPoint: String) { + addFragmentOnTop(ExpeditionPalletFragment.newInstance(item)) + } + + override fun onPalletClickListener(item: ItemPalletVO, entryPoint: String) { + // addFragmentOnTop(ItemCardFragment.newInstance(entryPoint)) + } + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionListAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionListAdapter.kt new file mode 100644 index 00000000..3fc6ab2f --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionListAdapter.kt @@ -0,0 +1,41 @@ +package es.verdnatura.presentation.view.feature.paletizador.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemExpeditiontruckRowBinding +import es.verdnatura.presentation.common.OnTruckClickListener +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO + +class ExpeditionListAdapter ( + private val items: List, + private val onTruckClickListener: OnTruckClickListener +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemExpeditiontruckRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onTruckClickListener.onTruckClickListener(items[position],"") + } + } + + inner class ItemHolder( + val binding: ItemExpeditiontruckRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + private val res = binding.root.context.resources + fun bind(item: ItemExpeditionTruckVO) { + binding.apply { + this.item = item + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionPalletAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionPalletAdapter.kt new file mode 100644 index 00000000..97faebbd --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/adapter/ExpeditionPalletAdapter.kt @@ -0,0 +1,50 @@ +package es.verdnatura.presentation.view.feature.paletizador.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.R +import es.verdnatura.databinding.ItemExpeditionpalletRowBinding +import es.verdnatura.presentation.common.OnPalletClickListener +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO + +class ExpeditionPalletAdapter ( + private val items: List, + private val onPalletClickListener: OnPalletClickListener +): RecyclerView.Adapter () { + + private var context:Context? = null + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + this.context = parent.context + return ItemHolder( + ItemExpeditionpalletRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onPalletClickListener.onPalletClickListener(items[position],"") + } + } + + inner class ItemHolder( + val binding: ItemExpeditionpalletRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + private val res = binding.root.context.resources + fun bind(item: ItemPalletVO) { + binding.apply { + this.item = item + if (item.Rutas != "1"){ + expeditionPalletRutas.setTextColor(ContextCompat.getColor(context!!, R.color.verdnatura_red)) + }else { + expeditionPalletRutas.setTextColor(ContextCompat.getColor(context!!, R.color.verdnatura_white)) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletFragment.kt new file mode 100644 index 00000000..fb44434f --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletFragment.kt @@ -0,0 +1,195 @@ +package es.verdnatura.presentation.view.feature.paletizador.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentExpeditionPalletBinding +import es.verdnatura.domain.notNull +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnBarcodeRowClickListener +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnPalletClickListener +import es.verdnatura.presentation.view.component.CustomDialogHour +import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO +import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.paletizador.adapter.ExpeditionPalletAdapter +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletListVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_expedition_pallet.* +import kotlinx.android.synthetic.main.toolbar.* +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList + +class ExpeditionPalletFragment( + var itemExpeditionTruckVO: ItemExpeditionTruckVO? = null +) : BaseFragment( + ExpeditionPalletViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var adapter : ExpeditionPalletAdapter? = null + private var onPalletClickListener: OnPalletClickListener? = null + private lateinit var customDialogList: CustomDialogList + private var listExpeditions:ArrayList = ArrayList() + private var expeditionAdapter : BarcodeAdapter? = null + + + companion object { + fun newInstance(item: ItemExpeditionTruckVO) = + ExpeditionPalletFragment(item) + } + + override fun onAttach(context: Context) { + if (context is OnPalletClickListener) onPalletClickListener = context + super.onAttach(context) + } + + override fun getLayoutId(): Int = R.layout.fragment_expedition_pallet + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + + super.onCreate(savedInstanceState) + } + + override fun init() { + + customDialogList = CustomDialogList(requireContext()) + splash_progress.visibility = View.VISIBLE + activity!!.main_bottom_navigation.visibility = View.GONE + toolbar_title.text = getCURDATE(itemExpeditionTruckVO!!.ETD) + " " + itemExpeditionTruckVO!!.Destino + setToolBar() + setEvents() + viewModel.expeditionPallet_List(user,password,itemExpeditionTruckVO!!.truckFk) + super.init() + } + + private fun setEvents(){ + backButton.setOnClickListener { + activity!!.onBackPressed() + } + + } + + private fun setToolBar(){ + val listIcons:ArrayList = ArrayList() + val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + val iconPlus : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) + listIcons.add(iconReload) + listIcons.add(iconPlus) + toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + if (item == iconReload){ + splash_progress.visibility = View.VISIBLE + viewModel.expeditionPallet_List(user,password,itemExpeditionTruckVO!!.truckFk) + }else if(item == iconPlus){ + expeditionScanAdd() + } + } + }) + toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun getCURDATE(date:String):String{ + val c = Calendar.getInstance() + val df = SimpleDateFormat("yyyy-mm-dd HH:mm") + val df2 = SimpleDateFormat("HH:mm") + c.time = df.parse(date) + return df2.format(c.time); + } + + override fun observeViewModel() { + with(viewModel){ + loadExpeditionPalletList.observe(viewLifecycleOwner, Observer { event -> + event.getContentIfNotHandled().notNull {printExpeditionList(it) } + }) + + loadScanList.observe(viewLifecycleOwner, Observer { event -> + event.getContentIfNotHandled().notNull {showScanExpeditions(it) } + }) + } + } + + private fun printExpeditionList(it: ItemPalletListVO){ + splash_progress.visibility = View.GONE + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + adapter = ExpeditionPalletAdapter(it.list,onPalletClickListener!!) + expedition_pallet_recyclerview.adapter = adapter + expedition_pallet_recyclerview.layoutManager = lm + } + + private fun expeditionScanAdd(){ + splash_progress.visibility = View.VISIBLE + viewModel.expeditionScanAdd(usuario = user,password = password,vPalletFk = "0",vTruckFk = itemExpeditionTruckVO!!.truckFk) + } + + private fun showScanExpeditions(it:ItemScanList){ + splash_progress.visibility = View.GONE + it.list.forEach { + listExpeditions.add(BarcodeVO(code = it.expeditionFk)) + } + + customDialogList.setTitle("Expedition ("+toolbar_title.text+")").setOkButton("Comprobar"){ + (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) + splash_progress.visibility = View.VISIBLE + viewModel.expeditionPallet_List(user,password,itemExpeditionTruckVO!!.truckFk) + listExpeditions = ArrayList() + customDialogList.hide() + + }.setKoButton("Cerrar"){ + (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) + splash_progress.visibility = View.VISIBLE + viewModel.expeditionPallet_List(user,password,itemExpeditionTruckVO!!.truckFk) + listExpeditions = ArrayList() + customDialogList.hide() + }.setValue("").show() + + customDialogList.getEditText().requestFocus() + (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!customDialogList.getValue().isNullOrEmpty()){ + listExpeditions.add(BarcodeVO(code = customDialogList.getValue())) + expeditionAdapter!!.notifyDataSetChanged() + } + customDialogList.setValue("") + (activity as MainActivity).hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + expeditionAdapter = BarcodeAdapter(listExpeditions,object: OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + listExpeditions.remove(item) + expeditionAdapter!!.notifyDataSetChanged() + } + }) + customDialogList.getRecyclerView().adapter = expeditionAdapter + + customDialogList.getRecyclerView().layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletViewModel.kt new file mode 100644 index 00000000..b77a2d57 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionPalletViewModel.kt @@ -0,0 +1,79 @@ +package es.verdnatura.presentation.view.feature.paletizador.fragment + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Transformations +import es.verdnatura.domain.GetPaletizadoresUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletListVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList +import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class ExpeditionPalletViewModel : BaseViewModel() { + + private val getPaletizadoresUserCase: GetPaletizadoresUserCase = GetPaletizadoresUserCase() + + private val _expeditionPalletList by lazy { MutableLiveData() } + val loadExpeditionPalletList = Transformations.map(_expeditionPalletList) { Event(it) } + + + private val _scanList by lazy { MutableLiveData() } + val loadScanList = Transformations.map(_scanList) { Event(it) } + + fun expeditionPallet_List(usuario:String,password:String,vTruckFk:String){ + getPaletizadoresUserCase.expeditionPallet_List(usuario,password,vTruckFk).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(ItemPalletVO(isError = true,errorMessage = t.message!!)) + _expeditionPalletList.value = ItemPalletListVO(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _expeditionPalletList.value = response.body()?.let { ItemPalletListVO(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(ItemPalletVO(isError = true,errorMessage = "Error en la llamada de expeditionTruck_List")) + _expeditionPalletList.value = ItemPalletListVO(listError) + } + } + + }) + } + + fun expeditionScanAdd(usuario:String,password:String,vPalletFk:String,vTruckFk:String){ + getPaletizadoresUserCase.expeditionScanAdd(usuario,password,vPalletFk,vTruckFk).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(ItemScanVO(isError = true,errorMessage = t.message!!)) + _scanList.value = ItemScanList(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _scanList.value = response.body()?.let { ItemScanList(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(ItemScanVO(isError = true,errorMessage = "Error en la llamada de expeditionTruck_List")) + _scanList.value = ItemScanList(listError) + } + } + + }) + } + + + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListFragment.kt new file mode 100644 index 00000000..fe4906b8 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListFragment.kt @@ -0,0 +1,160 @@ +package es.verdnatura.presentation.view.feature.paletizador.fragment + +import android.content.Context +import android.content.SharedPreferences +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentExpeditionTruckListBinding +import es.verdnatura.domain.notNull +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnOptionsSelectedListener +import es.verdnatura.presentation.common.OnTruckClickListener +import es.verdnatura.presentation.view.component.CustomDialogHour +import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.paletizador.adapter.ExpeditionListAdapter +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckList +import kotlinx.android.synthetic.main.fragment_expedition_truck_list.* +import kotlinx.android.synthetic.main.toolbar.* +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList +import java.util.Calendar.getInstance as getInstance1 + + +class ExpeditionTruckListFragment : BaseFragment( + ExpeditionTruckListViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var adapter : ExpeditionListAdapter? = null + private lateinit var customDialogHor: CustomDialogHour + private var onTruckClickListener: OnTruckClickListener? = null + + + companion object { + fun newInstance() = ExpeditionTruckListFragment() + } + + override fun onAttach(context: Context) { + if (context is OnTruckClickListener) onTruckClickListener = context + super.onAttach(context) + } + + override fun getLayoutId(): Int = R.layout.fragment_expedition_truck_list + + override fun onCreate(savedInstanceState: Bundle?) { + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + super.onCreate(savedInstanceState) + } + + override fun init() { + customDialogHor = CustomDialogHour(requireContext()) + splash_progress.visibility = View.VISIBLE + toolbar_title.text = "PScan: "+getCURDATE() + backButton.visibility = View.GONE + setToolBar() + viewModel.expeditionTruckList(user,password) + super.init() + } + + private fun setToolBar(){ + val listIcons:ArrayList = ArrayList() + val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + val iconPlus : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) + listIcons.add(iconReload) + listIcons.add(iconPlus) + toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { + override fun onOptionsItemSelected(item: Drawable) { + if (item == iconReload){ + splash_progress.visibility = View.VISIBLE + viewModel.expeditionTruckList(user,password) + }else if(item == iconPlus){ + addTruck() + } + } + }) + toolbar_icons.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + } + + private fun getCURDATE():String{ + val c: Date = getInstance1().getTime() + val df = SimpleDateFormat("dd/MM/yyyy") + return df.format(c); + } + + override fun observeViewModel() { + with(viewModel){ + loadExpeditionTruckList.observe(viewLifecycleOwner, Observer { event -> + event.getContentIfNotHandled().notNull {printExpeditionList(it) } + }) + loadResponseExpeditionAdd.observe(viewLifecycleOwner, Observer { event -> + viewModel.expeditionTruckList(user,password) + }) + } + } + + private fun printExpeditionList(it: ItemExpeditionTruckList){ + splash_progress.visibility = View.GONE + val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + adapter = ExpeditionListAdapter(it.list,onTruckClickListener!!) + expedition_truck_recyclerview.adapter = adapter + expedition_truck_recyclerview.layoutManager = lm + } + + private fun addTruck(){ + customDialogHor.setTitle("Nuevo Camión").setOkButton("Guardar"){ + (activity as MainActivity).hideKeyboard(customDialogHor.getDestinoEditText()) + if (!customDialogHor.getDestinoValue().isNullOrEmpty() && !customDialogHor.getHoraValue().isNullOrEmpty()){ + viewModel.expeditionTruckAdd(user,password,customDialogHor.getHoraValue(),customDialogHor.getDestinoValue()) + splash_progress.visibility = View.VISIBLE + customDialogHor.dismiss() + } + (activity as MainActivity).hideKeyboard(customDialogHor.getDestinoEditText()) + customDialogHor.dismiss() + }.setKoButton("Cancelar"){ + customDialogHor.dismiss() + }.setHoraValue("").setDestinoValue("").show() + + customDialogHor.getDestinoEditText().requestFocus() + customDialogHor.getDestinoEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (!customDialogHor.getDestinoValue().isNullOrEmpty() && !customDialogHor.getHoraValue().isNullOrEmpty()){ + viewModel.expeditionTruckAdd(user,password,customDialogHor.getHoraValue(),customDialogHor.getDestinoValue()) + splash_progress.visibility = View.VISIBLE + customDialogHor.dismiss() + } + + return@setOnEditorActionListener true + } + (activity as MainActivity).hideKeyboard(customDialogHor.getDestinoEditText()) + false + } + } + + + + +} + + + + + + + + + + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListViewModel.kt new file mode 100644 index 00000000..9192e478 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/fragment/ExpeditionTruckListViewModel.kt @@ -0,0 +1,72 @@ +package es.verdnatura.presentation.view.feature.paletizador.fragment + + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Transformations +import es.verdnatura.domain.GetPaletizadoresUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.common.ResponseItemVO +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckList +import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class ExpeditionTruckListViewModel : BaseViewModel() { + + private val getPaletizadoresUserCase: GetPaletizadoresUserCase = GetPaletizadoresUserCase() + + private val _expeditionTruckList by lazy { MutableLiveData() } + val loadExpeditionTruckList = Transformations.map(_expeditionTruckList) { Event(it) } + + private val _response by lazy { MutableLiveData() } + val loadResponseExpeditionAdd = Transformations.map(_response) { Event(it) } + + + + + fun expeditionTruckList(usuario:String,password:String){ + getPaletizadoresUserCase.expeditionTruckList(usuario,password).enqueue(object : + Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(ItemExpeditionTruckVO(isError = true,errorMessage = t.message!!)) + _expeditionTruckList.value = ItemExpeditionTruckList(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _expeditionTruckList.value = response.body()?.let { ItemExpeditionTruckList(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(ItemExpeditionTruckVO(isError = true,errorMessage = "Error en la llamada de expeditionTruck_List")) + _expeditionTruckList.value = ItemExpeditionTruckList(listError) + } + } + + }) + } + + fun expeditionTruckAdd(usuario:String,password:String,vHour:String,vDescription:String){ + getPaletizadoresUserCase.expeditionTruckAdd(usuario,password,vHour,vDescription).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = "Error al guardar CAMIÓN "+vDescription+ " Respuesta:"+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada expeditionTruckAdd") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + + } + + }) + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemExpeditionTruckVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemExpeditionTruckVO.kt new file mode 100644 index 00000000..04d087ee --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemExpeditionTruckVO.kt @@ -0,0 +1,15 @@ +package es.verdnatura.presentation.view.feature.paletizador.model + +class ItemExpeditionTruckVO ( + var truckFk:String = "", + var ETD:String = "", + var Destino:String = "", + var isError:Boolean = false, + var errorMessage:String = "" +) + + +class ItemExpeditionTruckList( + var list: List = listOf() +) + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemPalletVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemPalletVO.kt new file mode 100644 index 00000000..90f4b6cd --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemPalletVO.kt @@ -0,0 +1,14 @@ +package es.verdnatura.presentation.view.feature.paletizador.model + +class ItemPalletVO( + var Pallet:String = "", + var Rutas:String = "", + var Eti:String = "", + var isError: Boolean = false, + var errorMessage: String = "" + +) + +class ItemPalletListVO( + var list:List = listOf() +) \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemScanVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemScanVO.kt new file mode 100644 index 00000000..a36b1378 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/paletizador/model/ItemScanVO.kt @@ -0,0 +1,12 @@ +package es.verdnatura.presentation.view.feature.paletizador.model + +class ItemScanVO ( + var expeditionFk:String = "", + var palletFk:String = "", + var isError:Boolean = false, + var errorMessage:String = "" +) + +class ItemScanList( + var list:List = listOf() +) diff --git a/app/src/main/res/drawable/ic_history_black_24dp.xml b/app/src/main/res/drawable/ic_history_black_24dp.xml new file mode 100644 index 00000000..009248ba --- /dev/null +++ b/app/src/main/res/drawable/ic_history_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_local_shipping_black_24dp.xml b/app/src/main/res/drawable/ic_local_shipping_black_24dp.xml new file mode 100644 index 00000000..0020ffde --- /dev/null +++ b/app/src/main/res/drawable/ic_local_shipping_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_local_shipping_black_24dp_selected.xml b/app/src/main/res/drawable/ic_local_shipping_black_24dp_selected.xml new file mode 100644 index 00000000..3d8c2da0 --- /dev/null +++ b/app/src/main/res/drawable/ic_local_shipping_black_24dp_selected.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/round_av_timer_24.xml b/app/src/main/res/drawable/round_av_timer_24.xml new file mode 100644 index 00000000..6214334f --- /dev/null +++ b/app/src/main/res/drawable/round_av_timer_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/component_custom_hour.xml b/app/src/main/res/layout/component_custom_hour.xml new file mode 100644 index 00000000..4eca420d --- /dev/null +++ b/app/src/main/res/layout/component_custom_hour.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +