diff --git a/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt index 520e5a6b..adb74a52 100644 --- a/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt +++ b/app/src/main/java/es/verdnatura/domain/GetItemCardUserCase.kt @@ -21,4 +21,20 @@ class GetItemCardUserCase : RestClient() { params.add(isTrash) return restClient!!.itemStockUpdate("json","1",usuario,password,"application/json",params = params)!! } + + fun itemPlacementSave(usuario:String,password:String,itemFk:String,warehouseFk:String,value:String ) : Call { + val params:ArrayList = ArrayList(); + params.add(itemFk) + params.add(warehouseFk) + params.add(value) + return restClient!!.itemPlacementSave("json","1",usuario,password,"application/json",params = params)!! + } + + fun updateGrouping(usuario:String,password:String,itemFk:String,value:String ,warehouseFk:String) : Call { + val params:ArrayList = ArrayList(); + params.add(itemFk) + params.add(value) + params.add(warehouseFk) + return restClient!!.updateGrouping("json","1",usuario,password,"application/json",params = 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 efe512ac..65266116 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -52,11 +52,29 @@ interface VerdnaturaService { @POST("almacenv2/item_Stock_Update") fun itemStockUpdate(@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): + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call + + @POST("almacenv2/item_placement_save") + fun itemPlacementSave(@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("almacenv2/buy_updateGrouping") + fun updateGrouping(@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/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index 1871b88d..7e6d1e0c 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 @@ -35,6 +35,8 @@ class ItemCardFragment : BaseFragment private var password = "" private var warehouseFk = "" private var itemFk = "" + private var adapter : ItemCardAdapter? = null + private var listItemsRow:ArrayList = ArrayList() companion object { fun newInstance() = ItemCardFragment() @@ -122,8 +124,6 @@ class ItemCardFragment : BaseFragment customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Cerrar"){ customDialog.hide() }.show() - }else{ - this@ItemCardFragment.getItemCard(itemFk) } }) } @@ -139,25 +139,25 @@ class ItemCardFragment : BaseFragment itemcard_tag2.text = itemInfo.value5 itemcard_tag3.text = itemInfo.value6 itemcard_tag4.text = itemInfo.value7 + " " + itemInfo.origin - val listItemsRow:ArrayList = ArrayList() + listItemsRow = ArrayList() listItemsRow.add(ItemCardRowVO(title = "Total",value = itemInfo.total,isEditable = false)) listItemsRow.add(ItemCardRowVO(title = "Disponible",value = itemInfo.available,isEditable = false)) listItemsRow.add(ItemCardRowVO(title = "Ubicado",value = itemInfo.enAltillo,isEditable = false)) //EDITABLES listItemsRow.add(ItemCardRowVO(title = "SIN UBICAR",value = itemInfo.enNicho,isEditable = true, action = "itemStockUpdate")) - listItemsRow.add(ItemCardRowVO(title = "NICHO",value = itemInfo.nicho,isEditable = true)) - listItemsRow.add(ItemCardRowVO(title = "RESERVA",value = itemInfo.reserva,isEditable = true)) - listItemsRow.add(ItemCardRowVO(title = "GROUPING",value = itemInfo.grouping,isEditable = true)) + listItemsRow.add(ItemCardRowVO(title = "NICHO",value = itemInfo.nicho,isEditable = true, action = "itemPlacementSave")) + listItemsRow.add(ItemCardRowVO(title = "RESERVA",value = itemInfo.reserva,isEditable = true, action = "itemPlacementSave")) + listItemsRow.add(ItemCardRowVO(title = "GROUPING",value = itemInfo.grouping,isEditable = true, action = "updateGrouping")) listItemsRow.add(ItemCardRowVO(title = "PACKING",value = itemInfo.packing,isEditable = true)) listItemsRow.add(ItemCardRowVO(title = "MINIMO",value = itemInfo.min,isEditable = true)) listItemsRow.add(ItemCardRowVO(title = "BARCODE",barcodes = itemInfo.barcodes,isEditable = true)) - itemcard_recyclerview.adapter = ItemCardAdapter(listItemsRow,object: OnItemCardRowClickListener{ + adapter = ItemCardAdapter(listItemsRow,object: OnItemCardRowClickListener{ override fun onItemCardRowClickListener(item: ItemCardRowVO) { customDialogInput.setTitle(item.title!!).setDescription("Valor actual: "+item.value!!).setOkButton("Guardar"){ (activity as MainActivity).hideKeyboard(customDialogInput.getEditText()) - editItemCardRow(item.action!!,customDialogInput.getValue()) + editItemCardRow(item,customDialogInput.getValue()) customDialogInput.hide() }.setKoButton("Cancelar"){ @@ -168,7 +168,7 @@ class ItemCardFragment : BaseFragment customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { if (!customDialogInput.getValue().isNullOrEmpty()) - editItemCardRow(item.action!!,customDialogInput.getValue()) + editItemCardRow(item,customDialogInput.getValue()) customDialogInput.setValue("") customDialogInput.hide() (activity as MainActivity).hideKeyboard(customDialogInput.getEditText()) @@ -178,6 +178,7 @@ class ItemCardFragment : BaseFragment } } }) + itemcard_recyclerview.adapter = adapter itemcard_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) scroll_view.post(Runnable { @@ -189,12 +190,27 @@ class ItemCardFragment : BaseFragment } - private fun editItemCardRow(action:String,value:String){ - splash_progress.visibility = View.VISIBLE - when (action){ - "itemStockUpdate" -> viewModel.itemStockUpdate(itemFk = itemFk,warehouseFk = warehouseFk,user = user,password = password,newValue = value,isTrash = "0") + private fun editItemCardRow(item:ItemCardRowVO,value:String){ + when (item.action){ + "itemStockUpdate" -> viewModel.itemStockUpdate(itemFk = itemFk,warehouseFk = warehouseFk,user = user,password = password,newValue = value,isTrash = "0") + "itemPlacementSave" -> viewModel.itemPlacementSave(itemFk = itemFk, warehouseFk = warehouseFk, user = user, password = password, value = value) + "updateGrouping" -> viewModel.updateGrouping(itemFk = itemFk, user = user, password = password, value = value,warehouseFk = warehouseFk) } + changeOfflineValue(item,value) + } + + private fun changeOfflineValue(item:ItemCardRowVO,newValue:String){ + var i = 0 + var position = 0 + listItemsRow.forEach { + if (it.title == item.title) { + position = i + } + i = i.plus(1) + } + listItemsRow.get(position).value = newValue + adapter?.notifyDataSetChanged() } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt index 8bb890ee..88f4be50 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt @@ -58,4 +58,40 @@ class ItemCardViewModel : BaseViewModel() { }) } + + fun itemPlacementSave(itemFk:String,warehouseFk:String,user:String,password:String,value:String){ + getItemCardUserCase.itemPlacementSave(user,password,itemFk,warehouseFk,value).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada itemStockUpdate") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + + } + + }) + } + + fun updateGrouping(itemFk:String,user:String,password:String,value:String,warehouseFk: String){ + getItemCardUserCase.updateGrouping(user,password,itemFk,value,warehouseFk).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage = t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada itemStockUpdate") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + + } + + }) + } }