|
@@ -1,6 +1,7 @@
|
|
|
package com.pan_american.android.ui.customer_resource.market_sales_revenue
|
|
|
|
|
|
import android.content.Intent
|
|
|
+import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
@@ -11,9 +12,12 @@ 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.CustomAlertDialog
|
|
|
import com.pan_american.android.base.ListAdapter
|
|
|
import com.pan_american.android.data.model.customer_resource.market_sales_revenue.entity.GroupListItem
|
|
|
import com.pan_american.android.data.model.customer_resource.market_sales_revenue.entity.YearQuarterlyData
|
|
|
+import com.pan_american.android.data.model.customer_resource.market_sales_revenue.network.GenerateMarketSalesDocumentRequest
|
|
|
+import com.pan_american.android.data.model.customer_resource.market_sales_revenue.network.GenerateMarketSalesDocumentResponse
|
|
|
import com.pan_american.android.data.model.customer_resource.market_sales_revenue.network.MarketSalesGroupListResponse
|
|
|
import com.pan_american.android.data.model.customer_resource.market_sales_revenue.network.MarketSalesStatisticsRequest
|
|
|
import com.pan_american.android.data.network.APIService
|
|
@@ -44,6 +48,8 @@ class SalesRevenueListFragment : BaseFragment<FragmentSalesRevenueListBinding>()
|
|
|
|
|
|
private val marketSalesStatisticsRequest = MarketSalesStatisticsRequest()
|
|
|
|
|
|
+ private val generateMarketSalesDocumentRequest = GenerateMarketSalesDocumentRequest()
|
|
|
+
|
|
|
private val groupList = ArrayList<GroupListItem>()
|
|
|
|
|
|
override fun getViewBinding(
|
|
@@ -128,6 +134,64 @@ class SalesRevenueListFragment : BaseFragment<FragmentSalesRevenueListBinding>()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ binding.generateDocument.setOnClickListener {
|
|
|
+
|
|
|
+ generateMarketSalesDocumentRequest.apply {
|
|
|
+ for (item in OASystem.marketSalesRevenueCompanyList) {
|
|
|
+ if (item.name == OASystem.userInfo.companyName) {
|
|
|
+ companyId = item.id
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ beginDt = "$year-01-01"
|
|
|
+ endDt = "$year-12-31"
|
|
|
+ }
|
|
|
+
|
|
|
+ apiService.generateMarketSalesGroupListDocument(generateMarketSalesDocumentRequest).enqueue(object : Callback<GenerateMarketSalesDocumentResponse> {
|
|
|
+ override fun onResponse(
|
|
|
+ call: Call<GenerateMarketSalesDocumentResponse>,
|
|
|
+ response: Response<GenerateMarketSalesDocumentResponse>
|
|
|
+ ) {
|
|
|
+ val urlResponse = response.body()
|
|
|
+
|
|
|
+ if (urlResponse != null) {
|
|
|
+ if (urlResponse.code == 200) {
|
|
|
+
|
|
|
+ CustomAlertDialog.Builder(OASystem.context).apply {
|
|
|
+ setTitle(resources.getString(R.string.hint))
|
|
|
+ setMessage(
|
|
|
+ String.format(
|
|
|
+ resources.getString(R.string.market_sales_revenue_group_excel_generated),
|
|
|
+ generateMarketSalesDocumentRequest.beginDt,
|
|
|
+ generateMarketSalesDocumentRequest.endDt
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setNegativeButtonAndListener(resources.getString(R.string.cancel)) { dialog, _ ->
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ setPositiveButtonAndListener(resources.getString(R.string.confirm)) { dialog, _ ->
|
|
|
+ val uri = Uri.parse(urlResponse.data.url)
|
|
|
+ startActivity(Intent(Intent.ACTION_VIEW, uri))
|
|
|
+
|
|
|
+ dialog.dismiss()
|
|
|
+ }
|
|
|
+ }.show()
|
|
|
+
|
|
|
+ } else {
|
|
|
+ showMessage(urlResponse.msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onFailure(
|
|
|
+ p0: Call<GenerateMarketSalesDocumentResponse>,
|
|
|
+ p1: Throwable
|
|
|
+ ) {
|
|
|
+ showErrorInfo(R.string.interface_request_error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private fun getGroupCustomerList(type: Int) {
|
|
@@ -154,6 +218,12 @@ class SalesRevenueListFragment : BaseFragment<FragmentSalesRevenueListBinding>()
|
|
|
groupList.add(item)
|
|
|
}
|
|
|
|
|
|
+ if (groupList.size == 0) {
|
|
|
+ showMessage(resources.getString(R.string.no_data))
|
|
|
+ } else {
|
|
|
+ binding.generateDocument.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+
|
|
|
when(type) {
|
|
|
1 -> {
|
|
|
totalPage = getTotalPage(listResponse.count)
|
|
@@ -206,7 +276,6 @@ class SalesRevenueListFragment : BaseFragment<FragmentSalesRevenueListBinding>()
|
|
|
private fun initList() {
|
|
|
|
|
|
if (groupList.size == 0) {
|
|
|
- showMessage(resources.getString(R.string.no_data))
|
|
|
return
|
|
|
}
|
|
|
|