settlement fixed
This commit is contained in:
parent
70f2913989
commit
c4f49bc440
@ -2,6 +2,7 @@ package com.mob.utsmyanmar.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.runtime.Composable
|
||||
@ -842,7 +843,9 @@ fun AppNavGraph(
|
||||
},
|
||||
onShowError = {},
|
||||
onShowSuccess = {},
|
||||
onShowPrinterDialog = {}
|
||||
onShowPrinterDialog = { message ->
|
||||
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +82,7 @@ class SettlementViewModel @Inject constructor(
|
||||
|
||||
private var flag = false
|
||||
private var errorFlag = false
|
||||
private var settlementApproved = false
|
||||
private var isSecondCall = false
|
||||
private var batchIndex = 0
|
||||
|
||||
@ -269,6 +270,10 @@ class SettlementViewModel @Inject constructor(
|
||||
private fun requestOnlineProcessSettlement() {
|
||||
val state = _uiState.value
|
||||
|
||||
// Keep the local batch until this request receives an approved response.
|
||||
settlementApproved = false
|
||||
errorFlag = false
|
||||
|
||||
val hostName = HostName.MPU
|
||||
val field60 = SystemParamsOperation.getInstance().getCurrentBatchNum()
|
||||
|
||||
@ -407,15 +412,23 @@ class SettlementViewModel @Inject constructor(
|
||||
when {
|
||||
resultStr == Constant.ANSWER_CODE_ACCEPT ||
|
||||
resultStr == Constant.ANSWER_CODE_APPROVED -> {
|
||||
settlementApproved = true
|
||||
currentPayDetail.isNeedReversal = false
|
||||
}
|
||||
|
||||
resultStr == "95" || resultStr == "095" -> {
|
||||
settlementApproved = false
|
||||
currentPayDetail.isNeedReversal = !flag
|
||||
}
|
||||
|
||||
else -> {
|
||||
settlementApproved = false
|
||||
currentPayDetail.isNeedReversal = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errorFlag = true
|
||||
settlementApproved = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -447,13 +460,12 @@ class SettlementViewModel @Inject constructor(
|
||||
flag = false
|
||||
batchIndex = 0
|
||||
|
||||
if (!errorFlag && settlementApproved) {
|
||||
updateDB()
|
||||
insertPayDetail(currentPayDetail)
|
||||
|
||||
if (errorFlag) {
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
} else {
|
||||
postStatus(TransactionStatus.ON_SUCCESS)
|
||||
} else {
|
||||
postStatus(TransactionStatus.ON_ERROR)
|
||||
}
|
||||
|
||||
_uiState.update {
|
||||
|
||||
@ -220,7 +220,16 @@ class TransactionResultViewModel @Inject constructor(
|
||||
|
||||
override fun paperRollIsReady() {
|
||||
if (isSettlement) {
|
||||
sharedViewModel.startPrintProcessSettlement()
|
||||
sharedViewModel.startPrintProcessSettlement(
|
||||
onSuccess = ::navigateMain,
|
||||
onFailure = {
|
||||
sendUiEvent(
|
||||
TransactionResultUiEvent.ShowPrinterDialog(
|
||||
"Settlement report printing failed"
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
sharedViewModel.startPrintProcess()
|
||||
}
|
||||
|
||||
@ -419,17 +419,25 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun startPrintProcessSettlement() {
|
||||
fun startPrintProcessSettlement(
|
||||
onSuccess: () -> Unit,
|
||||
onFailure: () -> Unit
|
||||
) {
|
||||
|
||||
val detail = payDetail.value ?: return
|
||||
val detail = payDetail.value ?: run {
|
||||
onFailure()
|
||||
return
|
||||
}
|
||||
|
||||
PrintXReceipt.getInstance()
|
||||
.printSmileSettlementReport(detail, object : PrintXStatus {
|
||||
|
||||
override fun onSuccess() {
|
||||
onSuccess()
|
||||
}
|
||||
|
||||
override fun onFailure() {
|
||||
onFailure()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user