settlement's unsettle data fixed

This commit is contained in:
moon 2026-09-21 17:26:20 +06:30
parent 4dee4bb6f9
commit 3e6a0707d8

View File

@ -25,10 +25,14 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mob.utsmyanmar.ui.components.appbar.AppBar
import com.mob.utsmyanmar.ui.history_functions.displayAmountWithSign
import com.mob.utsmyanmar.ui.theme.Color
import com.mob.utsmyanmar.ui.theme.MOBPOSTheme
import com.mob.utsmyanmar.utils.convertDateString
import com.mob.utsmyanmar.viewmodel.SharedViewModel
import com.utsmyanmar.paylibs.model.PayDetail
import com.utsmyanmar.paylibs.utils.POSUtil
@ -42,6 +46,22 @@ fun SettlementScreen(
autoStartSettlement: Boolean = false
) {
val records by settlementViewMode.getSettlementPOS().observeAsState(emptyList())
SettlementContent(
records = records,
onBack = onBack,
onStartSettlement = onStartSettlement,
autoStartSettlement = autoStartSettlement
)
}
@Composable
private fun SettlementContent(
records: List<PayDetail>,
onBack: () -> Unit,
onStartSettlement: () -> Unit,
autoStartSettlement: Boolean = false
) {
val totalAmount = records.sumOf { it.amount }
LaunchedEffect(autoStartSettlement, records) {
@ -116,7 +136,7 @@ fun SettlementScreen(
verticalArrangement = Arrangement.spacedBy(0.dp)
) {
items(records) { record ->
SettlementRecordRow(record = record)
SettlementRecordRow(payDetail = record)
}
}
}
@ -164,40 +184,87 @@ private fun SummaryRow(
}
@Composable
private fun SettlementRecordRow(record: PayDetail) {
private fun SettlementRecordRow(payDetail: PayDetail) {
Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Spacer(Modifier.height(4.dp))
Text(
text = record.transType
text = payDetail.transType
.orEmpty()
.ifBlank { "UNKNOWN" }
.replace("CASH_OUT", "CASH_ADV", ignoreCase = true),
color = Color.LegacyRed,
style = MaterialTheme.typography.titleSmall
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = POSUtil.getInstance().getDecimalAmountSeparatorFormat(record.amount),
color = Color.Black,
text = "Date & Time",
style = MaterialTheme.typography.titleSmall
)
Text(
text = "${convertDateString(payDetail.transDate.orEmpty())} ${payDetail.transTime.orEmpty()}".trim().ifBlank { "-" },
style = MaterialTheme.typography.titleSmall
)
}
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "Trace ${record.voucherNo.ifBlank { "-" }}",
color = Color.Black,
style = MaterialTheme.typography.bodySmall
text = "Amount",
style = MaterialTheme.typography.titleSmall
)
Text(
text = "Card ${maskCardNumber(record.cardNo)}",
color = Color.Gray,
style = MaterialTheme.typography.bodySmall
text = displayAmountWithSign(payDetail),
style = MaterialTheme.typography.titleSmall
)
Spacer(modifier = Modifier.height(12.dp))
}
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "Trace No",
style = MaterialTheme.typography.titleSmall
)
Text(
text = payDetail.voucherNo.orEmpty().ifBlank { "-" },
style = MaterialTheme.typography.titleSmall
)
}
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "Reference No",
style = MaterialTheme.typography.titleSmall
)
Text(
text = payDetail.referNo.orEmpty().ifBlank { "-" },
style = MaterialTheme.typography.titleSmall
)
}
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "Approval Code",
style = MaterialTheme.typography.titleSmall
)
Text(
text = payDetail.approvalCode.orEmpty().ifBlank { "-" },
style = MaterialTheme.typography.titleSmall
)
}
Spacer(Modifier.height(4.dp))
HorizontalDivider(color = Color.Gray.copy(alpha = 0.25f))
}
}
@ -209,3 +276,29 @@ private fun maskCardNumber(cardNo: String?): String {
val stars = "*".repeat(pan.length - 8)
return pan.take(4) + stars + pan.takeLast(4)
}
@Preview(showBackground = true)
@Composable
private fun SettlementScreenPreview() {
val sampleRecords = listOf(
PayDetail().apply {
transType = "SALE"
amount = 150000L
voucherNo = "000001"
cardNo = "9503036867315548"
},
PayDetail().apply {
transType = "CASH_OUT"
amount = 50000L
voucherNo = "000002"
cardNo = "9503036867311234"
}
)
MOBPOSTheme {
SettlementContent(
records = sampleRecords,
onBack = {},
onStartSettlement = {}
)
}
}