auto settlement fixed

This commit is contained in:
moon 2026-08-26 16:17:07 +06:30
parent 2093fb214a
commit 962bfbc6c5
7 changed files with 125 additions and 25 deletions

View File

@ -19,3 +19,15 @@
* show reversal status in trans records
* error_slip_print enable/disable in tms
* auto_settlement enable/disable in tms
### version 3.5
* "always with you" in mob receipt logo
* "..." full width in both P2 and P3 preview screens
* JCB logo added in Card Capture Screen
* "-" in void, refund and cash adv amounts
* disable sale button if amount is 0 or 0.00
* changed date formats to dd/mm/yy to dd/mm/yyyy
* changed keyboard design in reprint any transactions
### version 3.6
* auto-settlement for both P2 and P3

View File

@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.CAMERA" />
@ -43,6 +44,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.MOBPOS">
<receiver android:name=".auto_settlement.AlarmReceiver" android:exported="false"/>
<receiver android:name=".auto_settlement.BootReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".auto_settlement.AutoSettleService" android:exported="false" android:foregroundServiceType="dataSync" />
<activity
android:name="com.mob.utsmyanmar.MainActivity"

View File

@ -75,7 +75,7 @@ class MainActivity : ComponentActivity() {
private fun scheduleSettlementAlarm() {
if (!SystemParamsOperation.getInstance().isAutoSettlement()) {
SettlementScheduler.schedule(this)
SettlementScheduler.cancel(this)
return
}
@ -91,6 +91,7 @@ class MainActivity : ComponentActivity() {
)
)
}
SettlementScheduler.scheduleFallback(this)
return
}
}

View File

@ -0,0 +1,16 @@
package com.mob.utsmyanmar.auto_settlement
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import sunmi.sunmiui.utils.LogUtil
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action != Intent.ACTION_BOOT_COMPLETED) return
val appContext = context ?: return
LogUtil.d(BootReceiver::class.java.simpleName, "Boot completed, rescheduling settlement alarm")
SettlementScheduler.schedule(appContext)
}
}

View File

@ -11,6 +11,7 @@ import java.util.Calendar
object SettlementScheduler {
private const val FALLBACK_ALERT_TIME = "23:30:00"
private const val REQUEST_CODE = 100
fun schedule(context: Context): Boolean {
if (!SystemParamsOperation.getInstance().isAutoSettlement()) {
@ -24,15 +25,49 @@ object SettlementScheduler {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
!alarmManager.canScheduleExactAlarms()
) {
return scheduleFallback(context)
}
val calendar = nextAlarmCalendar() ?: return false
val pendingIntent = alarmPendingIntent(context)
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
pendingIntent
)
return true
}
fun scheduleFallback(context: Context): Boolean {
if (!SystemParamsOperation.getInstance().isAutoSettlement()) {
cancel(context)
return false
}
val configuredTime = parseTime(
// SystemParamsOperation.getInstance().clearBatchTime
"21:35:00"
) ?: parseTime(FALLBACK_ALERT_TIME)!!
val alarmManager =
context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val calendar = Calendar.getInstance().apply {
val calendar = nextAlarmCalendar() ?: return false
val pendingIntent = alarmPendingIntent(context)
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
pendingIntent
)
return true
}
private fun nextAlarmCalendar(): Calendar? {
val configuredTime = parseTime(
SystemParamsOperation.getInstance().clearBatchTime
// "15:45:00"
) ?: parseTime(FALLBACK_ALERT_TIME) ?: return null
return Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, configuredTime.first)
set(Calendar.MINUTE, configuredTime.second)
set(Calendar.SECOND, configuredTime.third)
@ -42,30 +77,18 @@ object SettlementScheduler {
add(Calendar.DAY_OF_MONTH, 1)
}
}
}
private fun alarmPendingIntent(context: Context): PendingIntent {
val intent = Intent(context, AlarmReceiver::class.java)
val intent = Intent(
return PendingIntent.getBroadcast(
context,
AlarmReceiver::class.java
)
val pendingIntent = PendingIntent.getBroadcast(
context,
100,
REQUEST_CODE,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or
PendingIntent.FLAG_IMMUTABLE
)
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
pendingIntent
)
return true
}
private fun parseTime(value: String): Triple<Int, Int, Int>? {

View File

@ -3,6 +3,8 @@ package com.mob.utsmyanmar.ui.dashboard
import android.os.Build
import android.os.Handler
import android.os.Looper
import androidmads.library.qrgenearator.QRGContents
import androidmads.library.qrgenearator.QRGEncoder
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
@ -46,6 +48,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
@ -359,6 +362,38 @@ fun DashboardScreen2(
trailingIcon = {},
)
Spacer(modifier = Modifier.height(16.dp))
val adUrl = "https://www.mobmyanmar.com/"
val qrBitmap = remember {
runCatching {
val encoder = QRGEncoder(adUrl, null, QRGContents.Type.TEXT, 256)
encoder.colorBlack = android.graphics.Color.BLACK
encoder.colorWhite = android.graphics.Color.WHITE
encoder.bitmap.asImageBitmap()
}.getOrNull()
}
qrBitmap?.let { bitmap ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Image(
bitmap = bitmap,
contentDescription = "Scan for User Guide",
modifier = Modifier.size(150.dp)
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = "Scan for Offers",
style = MaterialTheme.typography.labelSmall,
color = Color.Gray
)
}
}
Spacer(modifier = Modifier.height(8.dp))
Spacer(modifier = Modifier.weight(1f))
Text(
text = "v${BuildConfig.VERSION_NAME}",

View File

@ -436,7 +436,14 @@ fun AppNavGraph(
SettlementScreen(
sharedViewModel = sharedViewModel,
settlementViewMode = settlementViewMode,
onBack = { navController.popBackStack(Routes.Dashboard.route,false) },
onBack = {
onAutoSettlementHandled()
if (!navController.popBackStack(Routes.Dashboard.route, false)) {
navController.navigate(Routes.Dashboard.route) {
launchSingleTop = true
}
}
},
autoStartSettlement = autoSettlementRequested,
onStartSettlement = {
sharedViewModel.transactionsType.value = TransactionsType.SETTLEMENT