|
@@ -1,14 +1,20 @@
|
|
|
package com.pan_american.android.ui.financial_module.expense_approval
|
|
|
|
|
|
import android.os.Bundle
|
|
|
+import android.text.Html
|
|
|
+import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import android.widget.CheckedTextView
|
|
|
+import android.widget.PopupWindow
|
|
|
+import android.widget.TextView
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.pan_american.android.OASystem
|
|
|
import com.pan_american.android.R
|
|
|
import com.pan_american.android.base.BaseFragment
|
|
|
+import com.pan_american.android.base.BaseResponse
|
|
|
+import com.pan_american.android.base.CustomAlertDialog
|
|
|
import com.pan_american.android.base.ListAdapter
|
|
|
import com.pan_american.android.data.model.common.entity.SiftListItem
|
|
|
import com.pan_american.android.data.model.financial_module.expense_approval.adapter.ExpenseApprovalPaymentListAdapter
|
|
@@ -18,9 +24,11 @@ import com.pan_american.android.data.model.financial_module.expense_approval.net
|
|
|
import com.pan_american.android.data.model.financial_module.expense_approval.network.ExpenseApprovalPaymentListRequest
|
|
|
import com.pan_american.android.data.model.financial_module.expense_approval.network.ExpenseApprovalPaymentListResponse
|
|
|
import com.pan_american.android.data.model.financial_module.expense_approval.network.ExpenseApprovalPaymentTypeResponse
|
|
|
+import com.pan_american.android.data.model.financial_module.expense_approval.network.UpdatePaymentListExpenseApprovalRequest
|
|
|
import com.pan_american.android.data.network.APIService
|
|
|
import com.pan_american.android.data.network.ServiceCreator
|
|
|
import com.pan_american.android.databinding.FragmentExpenseApprovalBinding
|
|
|
+import com.pan_american.android.util.CommitButton
|
|
|
import retrofit2.Call
|
|
|
import retrofit2.Callback
|
|
|
import retrofit2.Response
|
|
@@ -43,6 +51,8 @@ class ExpenseApprovalFragment : BaseFragment<FragmentExpenseApprovalBinding>() {
|
|
|
|
|
|
private var groupBaseInfoShown = false
|
|
|
|
|
|
+ private var paymentIdList = ArrayList<Int>()
|
|
|
+
|
|
|
override fun getViewBinding(
|
|
|
inflater: LayoutInflater,
|
|
|
container: ViewGroup?,
|
|
@@ -80,6 +90,18 @@ class ExpenseApprovalFragment : BaseFragment<FragmentExpenseApprovalBinding>() {
|
|
|
groupBaseInfoShown = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ binding.revoke.setOnClickListener {
|
|
|
+ showListUpdateAlertDialog(2)
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.pass.setOnClickListener {
|
|
|
+ showListUpdateAlertDialog(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.reject.setOnClickListener {
|
|
|
+ showListUpdateAlertDialog(2)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private fun getPaymentType() {
|
|
@@ -162,6 +184,10 @@ class ExpenseApprovalFragment : BaseFragment<FragmentExpenseApprovalBinding>() {
|
|
|
paymentList.clear()
|
|
|
}
|
|
|
|
|
|
+ if (paymentIdList.size != 0) {
|
|
|
+ paymentIdList.clear()
|
|
|
+ }
|
|
|
+
|
|
|
expenseApprovalPaymentListRequest.label = labelId
|
|
|
|
|
|
getPaymentItemByLabel()
|
|
@@ -215,23 +241,56 @@ class ExpenseApprovalFragment : BaseFragment<FragmentExpenseApprovalBinding>() {
|
|
|
|
|
|
adapter.onItemClick = object : ExpenseApprovalPaymentListAdapter.OnItemClick {
|
|
|
override fun onItemCheck(position: Int) {
|
|
|
-
|
|
|
+ paymentList[position].apply {
|
|
|
+ if (isChecked) {
|
|
|
+ paymentIdList.add(id)
|
|
|
+ } else {
|
|
|
+ paymentIdList.remove(id)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onItemClick(position: Int) {
|
|
|
+ val detailPopup = View.inflate(OASystem.context, R.layout.popup_expense_approval_paayment_detail, null)
|
|
|
+ popupWindow = PopupWindow(detailPopup, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
+
|
|
|
+ showPopupWindow {
|
|
|
+ val detailText = detailPopup.findViewById<TextView>(R.id.payment_detail)
|
|
|
+ val commitButton = detailPopup.findViewById<CommitButton>(R.id.commit)
|
|
|
+
|
|
|
+ detailText.text = Html.fromHtml(paymentList[position].priceMsgContent.trimIndent(), Html.FROM_HTML_MODE_LEGACY)
|
|
|
+ commitButton.apply {
|
|
|
+ setText(resources.getString(R.string.confirm))
|
|
|
|
|
|
+ setOnClickListener {
|
|
|
+ popupWindow.dismiss()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ popupWindow.showAtLocation(binding.root, Gravity.CENTER, 0, 0)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onItemReject(position: Int) {
|
|
|
-
|
|
|
+ showSingleUpdateAlertDialog(
|
|
|
+ String.format(resources.getString(R.string.approval_reject_hint), paymentList[position].priceNameContent),
|
|
|
+ position, 2
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
override fun onItemPass(position: Int) {
|
|
|
+ showSingleUpdateAlertDialog(
|
|
|
+ String.format(resources.getString(R.string.approval_pass_hint), paymentList[position].priceNameContent),
|
|
|
+ position, 1
|
|
|
+ )
|
|
|
|
|
|
}
|
|
|
|
|
|
override fun onItemRevoke(position: Int) {
|
|
|
-
|
|
|
+ showSingleUpdateAlertDialog(
|
|
|
+ String.format(resources.getString(R.string.approval_revoke_hint), paymentList[position].priceNameContent),
|
|
|
+ position, 2
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -270,4 +329,117 @@ class ExpenseApprovalFragment : BaseFragment<FragmentExpenseApprovalBinding>() {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ private fun showSingleUpdateAlertDialog(string: String, position: Int, auditStatus: Int) {
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.alert))
|
|
|
+ setMessage(string)
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { dialog, _ ->
|
|
|
+ updateExpenseApproval(position, auditStatus)
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateExpenseApproval(position: Int, auditStatus: Int) {
|
|
|
+ apiService.updatePaymentListApproval(UpdatePaymentListExpenseApprovalRequest(paymentList[position].id.toString(), auditStatus)).enqueue(object : Callback<BaseResponse> {
|
|
|
+ override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
|
|
|
+ val updateResponse = response.body()
|
|
|
+
|
|
|
+ if (updateResponse != null) {
|
|
|
+ if (updateResponse.code == 200) {
|
|
|
+
|
|
|
+ binding.segmentPaymentList.adapter!!.notifyItemRangeRemoved(0, paymentList.size)
|
|
|
+
|
|
|
+ paymentList.clear()
|
|
|
+
|
|
|
+ getPaymentItemByLabel()
|
|
|
+
|
|
|
+ showMessage(resources.getString(R.string.update_success))
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(updateResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(call: Call<BaseResponse>, t: Throwable) {
|
|
|
+ showErrorInfo(R.string.update_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showListUpdateAlertDialog(auditStatus: Int) {
|
|
|
+
|
|
|
+ var paymentNameList = ""
|
|
|
+
|
|
|
+ for (id in paymentIdList) {
|
|
|
+ for (item in paymentList) {
|
|
|
+ if (id == item.id) {
|
|
|
+ paymentNameList += item.priceNameContent
|
|
|
+ paymentNameList += "\n"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ paymentNameList.trim()
|
|
|
+
|
|
|
+ var modelName = ""
|
|
|
+
|
|
|
+ for (item in filterList) {
|
|
|
+ if (labelId == item.id) {
|
|
|
+ modelName = item.name
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ val groupName = binding.groupName.text
|
|
|
+
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.alert))
|
|
|
+ setMessage(String.format(resources.getString(R.string.approval_payment_list_update_hint), groupName, modelName, paymentNameList))
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { dialog, _ ->
|
|
|
+ updatePaymentListApproval(paymentIdList, auditStatus)
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updatePaymentListApproval(idList: ArrayList<Int>, auditStatus: Int) {
|
|
|
+
|
|
|
+ val creditString = idList.toString().replace("[", "").replace("]", "")
|
|
|
+
|
|
|
+ apiService.updatePaymentListApproval(UpdatePaymentListExpenseApprovalRequest(creditString, auditStatus)).enqueue(object : Callback<BaseResponse> {
|
|
|
+ override fun onResponse(call: Call<BaseResponse>, response: Response<BaseResponse>) {
|
|
|
+ val updateResponse = response.body()
|
|
|
+
|
|
|
+ if (updateResponse != null) {
|
|
|
+ if (updateResponse.code == 200) {
|
|
|
+
|
|
|
+ binding.segmentPaymentList.adapter!!.notifyItemRangeRemoved(0, paymentList.size)
|
|
|
+
|
|
|
+ paymentList.clear()
|
|
|
+
|
|
|
+ getPaymentItemByLabel()
|
|
|
+
|
|
|
+ showMessage(resources.getString(R.string.update_success))
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(updateResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(call: Call<BaseResponse>, t: Throwable) {
|
|
|
+ showErrorInfo(R.string.update_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ paymentIdList.clear()
|
|
|
+ }
|
|
|
}
|