auto route to dashboard after print finished in sale

This commit is contained in:
moon 2026-07-20 21:18:03 +06:30
parent b2e8e13a81
commit beb6ddcba8
3 changed files with 36 additions and 11 deletions

View File

@ -5,3 +5,5 @@
* signature removed on void * signature removed on void
* "Enter Password" color to LegacyRed * "Enter Password" color to LegacyRed
* Amount and Card Number show in signature pad * Amount and Card Number show in signature pad
* fixed recent transaction only working for top 3
* routed to dashboard after printing receipt

View File

@ -801,6 +801,14 @@ fun AppNavGraph(
} }
launchSingleTop = true launchSingleTop = true
} }
},
onPrintFinished = {
navController.navigate(Routes.Dashboard.route) {
popUpTo(Routes.Dashboard.route) {
inclusive = false
}
launchSingleTop = true
}
} }
) )
} }

View File

@ -58,12 +58,12 @@ fun PrintReceiptScreen(
transactionResultViewModel: TransactionResultViewModel, transactionResultViewModel: TransactionResultViewModel,
sharedViewModel: SharedViewModel, sharedViewModel: SharedViewModel,
onPrint: () -> Unit, onPrint: () -> Unit,
onDone: () -> Unit onDone: () -> Unit,
onPrintFinished : () -> Unit,
) { ) {
val state by transactionResultViewModel.state.collectAsStateWithLifecycle() val state by transactionResultViewModel.state.collectAsStateWithLifecycle()
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val receiptOffsetY = remember { Animatable(0f) } val receiptOffsetY = remember { Animatable(0f) }
val animationDuration = 5000
val merchant_copy_autoprint = true val merchant_copy_autoprint = true
val customer_copy_autoprint = false val customer_copy_autoprint = false
var currentCopy by remember { mutableStateOf(ReceiptCopy.MERCHANT) } var currentCopy by remember { mutableStateOf(ReceiptCopy.MERCHANT) }
@ -73,7 +73,7 @@ fun PrintReceiptScreen(
suspend fun animatePrint() { suspend fun animatePrint() {
receiptOffsetY.animateTo( receiptOffsetY.animateTo(
targetValue = -1500f, targetValue = -1500f,
animationSpec = tween(durationMillis = animationDuration, easing = FastOutSlowInEasing) animationSpec = tween(durationMillis = 5000, easing = FastOutSlowInEasing)
) )
delay(1000.milliseconds) delay(1000.milliseconds)
receiptOffsetY.animateTo( receiptOffsetY.animateTo(
@ -84,21 +84,30 @@ fun PrintReceiptScreen(
fun isReprintMode() = sharedViewModel.isReprint.value == true fun isReprintMode() = sharedViewModel.isReprint.value == true
fun doPrint(copy: ReceiptCopy, onFinished: () -> Unit) { fun doPrint(copy: ReceiptCopy, onFinished: (printFinished: ReceiptCopy) -> Unit) {
val reprint = isReprintMode() val reprint = isReprintMode()
val actualCopy = if (reprint && copy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER else copy val actualCopy = if (reprint && copy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER else copy
currentCopy = actualCopy currentCopy = actualCopy
sharedViewModel.setPrintStatus( sharedViewModel.setPrintStatus(
if (actualCopy == ReceiptCopy.MERCHANT) PrintStatus.FIRST_PRINT else PrintStatus.SECOND_PRINT if (actualCopy == ReceiptCopy.MERCHANT)
PrintStatus.FIRST_PRINT
else
PrintStatus.SECOND_PRINT
) )
onPrint() onPrint()
scope.launch { scope.launch {
isPrinting = true isPrinting = true
animatePrint() animatePrint()
isPrinting = false isPrinting = false
nextCopy = if (reprint) ReceiptCopy.CUSTOMER val upcomingCopy = if (reprint) ReceiptCopy.CUSTOMER
else if (actualCopy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER else ReceiptCopy.MERCHANT else if (actualCopy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER
onFinished() else ReceiptCopy.MERCHANT
currentCopy = upcomingCopy
nextCopy = upcomingCopy
onFinished(actualCopy)
} }
} }
@ -174,7 +183,12 @@ fun PrintReceiptScreen(
), ),
shape = RoundedCornerShape(12.dp), shape = RoundedCornerShape(12.dp),
onClick = { onClick = {
doPrint(nextCopy) { } doPrint(nextCopy) { printFinished ->
if (printFinished == ReceiptCopy.CUSTOMER) {
onPrintFinished()
}
}
} }
) { ) {
Text( Text(
@ -295,7 +309,8 @@ fun PreviewPrintReceiptScreen() {
sharedViewModel = hiltViewModel(), sharedViewModel = hiltViewModel(),
transactionResultViewModel = hiltViewModel(), transactionResultViewModel = hiltViewModel(),
onPrint = {}, onPrint = {},
onDone = {} onDone = {},
onPrintFinished = {}
) )
} }
} }