Compare commits

..

3 Commits

Author SHA1 Message Date
moon
83047648b4 diable/enable loop fixed, reversal sale records removed after settelement 2026-09-15 14:21:28 +06:30
moon
1d132c481f card holder align fix 2026-09-15 13:50:05 +06:30
moon
c4f49bc440 settlement fixed 2026-09-10 22:54:39 +06:30
16 changed files with 146 additions and 101 deletions

1
.gitignore vendored
View File

@ -14,7 +14,6 @@
.cxx
local.properties
/.idea
/.idea
/sunmiui-lib
/paysdk-lib
/app/uat

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-05-07T16:25:07.233027800Z">
<DropdownSelection timestamp="2026-09-15T06:58:26.019801800Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=PB0219AQ60954" />
<DeviceId pluginId="PhysicalDevice" identifier="serial=PB13216J53652" />
</handle>
</Target>
</DropdownSelection>

View File

@ -1,62 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="UsePropertyAccessSyntax" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK" />
</project>

View File

@ -39,7 +39,9 @@ class DashboardViewModel @Inject constructor(
val isCurrentBusinessSettlement = latestSettlement?.isCurrentBusinessSettlement() == true
_uiState.update {
it.copy(
recentTransactions = payDetails.map { pd -> pd.toRecord() },
recentTransactions = payDetails
.filterNot { it.isSettlementTransaction() }
.map { pd -> pd.toRecord() },
totalSaleCount = payDetails.totalSaleCount(),
totalSaleAmount = payDetails.totalSaleAmount(),
settlementStatusText = if (isCurrentBusinessSettlement) {
@ -151,6 +153,11 @@ private fun PayDetail.isSaleTransaction(): Boolean {
(transactionType == TransactionsType.WAVEPAY.value && qrTransStatus == 1)
}
private fun PayDetail.isSettlementTransaction(): Boolean {
return transactionType == TransactionsType.SETTLEMENT.value ||
transType?.contains("SETTLEMENT", ignoreCase = true) == true
}
private fun formatTypeLabel(raw: String): String = when {
raw.equals("CASH_OUT", ignoreCase = true) -> "CASH_ADV"
raw.contains("SALE", ignoreCase = true) -> "Sale"

View File

@ -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
@ -167,6 +168,7 @@ fun AppNavGraph(
LaunchedEffect(tmsSetupUiState.isTerminalDisabled) {
if (tmsSetupUiState.isTerminalDisabled) {
tmsSetupViewModel.clearTerminalDisabledState()
navController.navigate(Routes.TmsSetup.route) {
popUpTo(Routes.Dashboard.route) {
inclusive = true
@ -842,7 +844,9 @@ fun AppNavGraph(
},
onShowError = {},
onShowSuccess = {},
onShowPrinterDialog = {}
onShowPrinterDialog = { message ->
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
}
)
}

View File

@ -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
@ -239,6 +240,8 @@ class SettlementViewModel @Inject constructor(
repository.deletePayDetail(pay)
}
repository.deleteReversalTransactions()
deleteTrans.forEach { pay ->
repository.deletePayDetail(pay)
}
@ -269,6 +272,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 +414,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 +462,12 @@ class SettlementViewModel @Inject constructor(
flag = false
batchIndex = 0
updateDB()
insertPayDetail(currentPayDetail)
if (errorFlag) {
postStatus(TransactionStatus.ON_ERROR)
} else {
if (!errorFlag && settlementApproved) {
updateDB()
insertPayDetail(currentPayDetail)
postStatus(TransactionStatus.ON_SUCCESS)
} else {
postStatus(TransactionStatus.ON_ERROR)
}
_uiState.update {
@ -520,4 +534,4 @@ class SettlementViewModel @Inject constructor(
_events.send(SettlementEvent.ShowStatus(status))
}
}
}
}

View File

@ -44,6 +44,10 @@ fun TmsSetupRoute(
) {
val state by viewModel.uiState.collectAsState()
LaunchedEffect(viewModel) {
viewModel.initialize()
}
LaunchedEffect(viewModel) {
viewModel.navigateToDashboard.collect { onNavigateDashboard() }
}

View File

@ -49,7 +49,7 @@ class TmsSetupViewModel @Inject constructor(
private val emvParamOperation: EmvParamOperation,
@ApplicationContext private val context: Context
) : ViewModel() {
private val TAG = TmsSetupViewModel::class.simpleName;
private val TAG = TmsSetupViewModel::class.simpleName
private val _uiState = MutableStateFlow(TmsSetupUiState())
private val _dashboardUiState = MutableStateFlow(DashboardUiState())
val uiState: StateFlow<TmsSetupUiState> = _uiState.asStateFlow()
@ -65,8 +65,14 @@ class TmsSetupViewModel @Inject constructor(
private val disposables = CompositeDisposable()
private val tmsSetups = TMSSetupsImpl()
private var requestInProgress = false
private var initialized = false
fun initialize() {
if (initialized) return
initialized = true
init {
viewModelScope.launch {
waitForHardware()
TMSUtil.getInstance().generateFinalVersion()
@ -75,20 +81,29 @@ class TmsSetupViewModel @Inject constructor(
}
fun downloadConfigs(onSuccess: () -> Unit = {}) {
// Do not use isLoading here because it also covers the hardware startup phase.
if (requestInProgress) return
requestInProgress = true
_uiState.update {
it.copy(isLoading = true, isError = false, statusText = "Connecting to TMS server...")
it.copy(
isLoading = true,
isError = false,
isTerminalDisabled = false,
statusText = "Connecting to TMS server..."
)
}
val disposable = repository.getParams(buildRequest())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doFinally { requestInProgress = false }
.subscribe(
{ response ->
_uiState.update { it.copy(
statusText = "Applying configuration...")
}
val appResponse = SiriusResponse(
serial = response.serial.orEmpty(),
ecrKey = response.ecrKey.orEmpty(),
@ -111,7 +126,6 @@ class TmsSetupViewModel @Inject constructor(
"Empty error response (${error.code()})"
}
} catch (e: Exception) {
// Server returned non-JSON (HTML 404 page, plain text, etc.)
"Server error: ${error.code()}"
}
} else {
@ -138,7 +152,6 @@ class TmsSetupViewModel @Inject constructor(
delay(500.milliseconds)
elapsed += 500
}
}
private fun onConfigApplied(onSuccess: () -> Unit) {
@ -148,6 +161,7 @@ class TmsSetupViewModel @Inject constructor(
LogUtil.d(TAG, "isActive ${ops.isActive}")
val msg = ops.disabledMsg.takeIf { it.isNotEmpty() }
?: "This terminal has been disabled. Please contact your administrator."
_uiState.update {
it.copy(
isLoading = false,
@ -157,6 +171,11 @@ class TmsSetupViewModel @Inject constructor(
errorMessage = msg
)
}
// FIX 2: Actually trigger the navigation event so the UI leaves this screen
viewModelScope.launch {
_navigateToDisable.emit(msg)
}
return
}
@ -188,6 +207,10 @@ class TmsSetupViewModel @Inject constructor(
viewModelScope.launch { _navigateToDashboard.emit(Unit) }
}
fun clearTerminalDisabledState() {
_uiState.update { it.copy(isTerminalDisabled = false) }
}
@SuppressLint("MissingPermission")
private fun buildRequest(): SiriusRequest {
return try {

View File

@ -1,6 +1,7 @@
package com.mob.utsmyanmar.ui.transaction_result
import androidx.lifecycle.ViewModel
import androidx.lifecycle.Observer
import androidx.lifecycle.viewModelScope
import com.mob.utsmyanmar.model.ecr.ECRResultStatus
import com.mob.utsmyanmar.utils.CoreUtils
@ -47,6 +48,8 @@ class TransactionResultViewModel @Inject constructor(
private var started = false
private var resultTimeoutJob: Job? = null
private var printStatusObserver: Observer<PrintStatus?>? = null
private var observedSharedViewModel: SharedViewModel? = null
fun onEvent(
event: TransactionResultEvent,
@ -196,7 +199,11 @@ class TransactionResultViewModel @Inject constructor(
}
private fun observePrintStatus(sharedViewModel: SharedViewModel) {
sharedViewModel.printXStatus.observeForever { status ->
printStatusObserver?.let { observer ->
observedSharedViewModel?.printXStatus?.removeObserver(observer)
}
printStatusObserver = Observer<PrintStatus?> { status ->
status ?: return@Observer
when (status) {
PrintStatus.EMPTY_PAPER_ROLL -> {
startPrintProcess(sharedViewModel, false)
@ -209,6 +216,18 @@ class TransactionResultViewModel @Inject constructor(
else -> Unit
}
}
observedSharedViewModel = sharedViewModel
sharedViewModel.printXStatus.observeForever(printStatusObserver!!)
}
override fun onCleared() {
resultTimeoutJob?.cancel()
printStatusObserver?.let { observer ->
observedSharedViewModel?.printXStatus?.removeObserver(observer)
}
printStatusObserver = null
observedSharedViewModel = null
super.onCleared()
}
private fun startPrintProcess(
@ -220,7 +239,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()
}

View File

@ -43,7 +43,7 @@ object MockData {
cardNo="6244310039574344",
expDate="3011",
cardScheme="MPU",
cardHolderName="Htin Kyaw Win",
cardHolderName="Nay Nwe Ei Kyaw Phyo",
iccData="6244310039574344=30112011558125900000"
)

View File

@ -78,6 +78,8 @@ class SharedViewModel @Inject constructor(
val isEmv = SingleLiveEvent<Boolean>()
private val settlementStatus = MutableLiveData<Boolean>()
private var settlementPrintInProgress = false
private var settlementPrintCompletedKey: String? = null
private val wavePayStatus = MutableLiveData<Boolean>()
@ -419,17 +421,46 @@ class SharedViewModel @Inject constructor(
}
}
fun startPrintProcessSettlement() {
fun startPrintProcessSettlement(
onSuccess: () -> Unit,
onFailure: () -> Unit
) {
val detail = payDetail.value ?: return
val detail = payDetail.value ?: run {
onFailure()
return
}
val printKey = "${detail.batchNo}:${detail.voucherNo}"
synchronized(this) {
if (settlementPrintCompletedKey == printKey || settlementPrintInProgress) {
return
}
settlementPrintInProgress = true
}
PrintXReceipt.getInstance()
.printSmileSettlementReport(detail, object : PrintXStatus {
private var callbackHandled = false
override fun onSuccess() {
synchronized(this) {
if (callbackHandled) return
callbackHandled = true
settlementPrintInProgress = false
settlementPrintCompletedKey = printKey
}
onSuccess()
}
override fun onFailure() {
synchronized(this) {
if (callbackHandled) return
callbackHandled = true
settlementPrintInProgress = false
}
onFailure()
}
})
}

View File

@ -37,6 +37,9 @@ public interface PayDetailDao {
@Delete
void deletePayDetail(PayDetail payDetail);
@Query("DELETE FROM paydetail WHERE transactionType = 10")
void deleteReversalTransactions();
// 13 = CASH DEPOSIT & 9 = CASH ADVANCE & 14 = FUND TRANSFER
@Query("SELECT * FROM paydetail WHERE isSettle = 0 AND transactionType = 13 OR transactionType = 9 AND isSettle = 0 OR transactionType = 14 AND isSettle = 0")
LiveData<List<PayDetail>> getSettlement();

View File

@ -209,5 +209,9 @@ public class Repository {
payDetailDao.deletePayDetail(payDetail);
}
public void deleteReversalTransactions() {
payDetailDao.deleteReversalTransactions();
}
public LiveData<List<PayDetail>> getAllTrans() { return payDetailDao.getAllTrans(); }
}

View File

@ -13,8 +13,6 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import sunmi.sunmiui.utils.LogUtil;
public class PrintUtils {
public static PrintUtils getInstance() {
@ -265,18 +263,18 @@ public class PrintUtils {
public String processNameSpaceSecondLine(String input) {
String[] words = input.split(" ");
if (input.length() < 15) {
if (input.length() < 20) {
return "";
}
if (words.length == 3 && input.length() > 15) {
if (words.length == 3 && input.length() > 20) {
return words[2];
} else if (words.length == 2 && input.length() <= 15) {
} else if (words.length == 2 && input.length() <= 20) {
return "";
} else if (words.length == 2 && input.length() > 15) {
} else if (words.length == 2 && input.length() > 20) {
return words[1];
} else {
return input.substring(15);
return input.substring(20);
}
}
}