fixed amount screen issues
This commit is contained in:
parent
ff9450a50c
commit
d76b48d4ca
File diff suppressed because one or more lines are too long
@ -28,6 +28,9 @@
|
|||||||
tools:ignore="ProtectedPermissions" />
|
tools:ignore="ProtectedPermissions" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||||
|
|
||||||
|
<!-- Permission for exact alarms on Android 12+ -->
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||||
|
|
||||||
<!-- android:noHistory="true"-->
|
<!-- android:noHistory="true"-->
|
||||||
<!-- android:excludeFromRecents="true"-->
|
<!-- android:excludeFromRecents="true"-->
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,25 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||||
|
|
||||||
public class AutoAlarmReceiver extends BroadcastReceiver {
|
public class AutoAlarmReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String TAG = AutoAlarmReceiver.class.getSimpleName();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
LogUtil.d(TAG, "AutoAlarmReceiver triggered at: " + new java.util.Date().toString());
|
||||||
|
|
||||||
|
boolean isTestAlarm = intent.getBooleanExtra("TEST_ALARM", false);
|
||||||
|
if (isTestAlarm) {
|
||||||
|
LogUtil.d(TAG, "This is a test alarm - AutoAlarmReceiver is working correctly!");
|
||||||
|
}
|
||||||
|
|
||||||
// Start the service to send the API request
|
// Start the service to send the API request
|
||||||
Intent serviceIntent = new Intent(context, AutoSettleService.class);
|
Intent serviceIntent = new Intent(context, AutoSettleService.class);
|
||||||
context.startService(serviceIntent);
|
context.startService(serviceIntent);
|
||||||
|
|
||||||
|
LogUtil.d(TAG, "AutoSettleService started");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,10 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint;
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
|
||||||
|
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX;
|
||||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||||
|
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
public class AutoSettleService extends Service {
|
public class AutoSettleService extends Service {
|
||||||
@ -72,218 +75,189 @@ public class AutoSettleService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
// Perform the Settlement request here
|
// Perform the Settlement request here
|
||||||
// ...
|
LogUtil.d(TAG, "<<<<<<<<<<<<<<< Auto Settlement Service Started >>>>>>>>>>>>>>>>.");
|
||||||
|
|
||||||
LogUtil.d(TAG,"<<<<<<<<<<<<<<< This action was called >>>>>>>>>>>>>>>>.");
|
try {
|
||||||
|
sendDataToViewModel("Hello there");
|
||||||
|
createNotification();
|
||||||
|
|
||||||
|
if (SystemParamsOperation.getInstance().getSettlementStatus()) {
|
||||||
|
performSettlement();
|
||||||
|
} else {
|
||||||
|
LogUtil.d(TAG, "Settlement is disabled in system parameters");
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.e(TAG, "Error in onStartCommand: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
|
||||||
sendDataToViewModel("Hello there");
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
createNotification();
|
private void performSettlement() {
|
||||||
|
final ISOMsgX isoMsgX = new ISOMsgX.ISOMsgXBuilder(
|
||||||
|
com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion.VERSION_1993,
|
||||||
|
com.utsmyanmar.paylibs.isobuilder.ISOMode.BOTH_HEADER_TPDU,
|
||||||
|
com.utsmyanmar.paylibs.utils.enums.HostName.BPC
|
||||||
|
).build();
|
||||||
|
|
||||||
// Observer<List<PayDetail>> settleObserver = new Observer<List<PayDetail>>() {
|
repository.getSettlementPOS().observeForever(list -> {
|
||||||
// @Override
|
int saleCount = 0;
|
||||||
// public void onChanged(List<PayDetail> list) {
|
long saleAmount = 0L;
|
||||||
//
|
int preCount = 0;
|
||||||
//
|
long preAmount = 0L;
|
||||||
// if(list == null || list.size() == 0) {
|
int refundCount = 0;
|
||||||
// LogUtil.d(TAG, "Settle is null");
|
long refundAmount = 0L;
|
||||||
// return;
|
int caCount = 0;
|
||||||
// }
|
long caAmount = 0L;
|
||||||
// LogUtil.d(TAG,"Size Settle : "+list.size());
|
|
||||||
//
|
|
||||||
// for (PayDetail pay:list) {
|
|
||||||
// repository.deletePayDetail(pay);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// repository.getSettlementPOS().observeForever(settleObserver);
|
|
||||||
//
|
|
||||||
// repository.getSettlementPOS().removeObserver(settleObserver);
|
|
||||||
//
|
|
||||||
// Observer<List<PayDetail>> deleteTransObserver = new Observer<List<PayDetail>>() {
|
|
||||||
// @Override
|
|
||||||
// public void onChanged(List<PayDetail> lists) {
|
|
||||||
// if(lists == null || lists.size() == 0) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// LogUtil.d(TAG,"Size Delete Trans : "+lists.size());
|
|
||||||
// for (PayDetail pay:lists) {
|
|
||||||
// repository.deletePayDetail(pay);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// repository.getDeleteTrans(SystemParamsOperation.getInstance().getCurrentBatchNum()).observeForever(deleteTransObserver);
|
|
||||||
//
|
|
||||||
// repository.getDeleteTrans(SystemParamsOperation.getInstance().getCurrentBatchNum()).removeObserver(deleteTransObserver);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
// try{
|
if (list != null && !list.isEmpty()) {
|
||||||
// handler.post(new Runnable() {
|
for (com.utsmyanmar.paylibs.model.PayDetail pay : list) {
|
||||||
// @Override
|
if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SALE && !pay.isCanceled) {
|
||||||
// public void run() {
|
saleCount++;
|
||||||
// // Create and show the dialog
|
saleAmount += pay.getAmount();
|
||||||
// AlertDialog.Builder builder = new AlertDialog.Builder(SmileSettleService.this);
|
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
||||||
// builder.setTitle("Auto Settle!")
|
preCount++;
|
||||||
// .setMessage("Settlement process is going to start!")
|
preAmount += pay.getAmount();
|
||||||
// .setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.REFUND) {
|
||||||
// @Override
|
refundCount++;
|
||||||
// public void onClick(DialogInterface dialog, int which) {
|
refundAmount += pay.getAmount();
|
||||||
// // Handle OK button click
|
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.CASH_ADVANCE) {
|
||||||
// dialog.dismiss(); // Dismiss the dialog
|
caCount++;
|
||||||
// }
|
caAmount += pay.getAmount();
|
||||||
// })
|
|
||||||
// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// // Handle Cancel button click
|
|
||||||
// dialog.dismiss(); // Dismiss the dialog
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// AlertDialog dialog = builder.create();
|
|
||||||
//// dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
|
||||||
//// dialog.show();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }catch (Exception e){
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getSettlementStatus()) {
|
|
||||||
final com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX isoMsgX = new com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX.ISOMsgXBuilder(
|
|
||||||
com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion.VERSION_1993,
|
|
||||||
com.utsmyanmar.paylibs.isobuilder.ISOMode.BOTH_HEADER_TPDU,
|
|
||||||
com.utsmyanmar.paylibs.utils.enums.HostName.BPC
|
|
||||||
).build();
|
|
||||||
|
|
||||||
repository.getSettlementPOS().observeForever(list -> {
|
|
||||||
int saleCount = 0;
|
|
||||||
long saleAmount = 0L;
|
|
||||||
int preCount = 0;
|
|
||||||
long preAmount = 0L;
|
|
||||||
int refundCount = 0;
|
|
||||||
long refundAmount = 0L;
|
|
||||||
int caCount = 0;
|
|
||||||
long caAmount = 0L;
|
|
||||||
|
|
||||||
if(list != null && !list.isEmpty()) {
|
|
||||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : list) {
|
|
||||||
if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SALE && !pay.isCanceled) {
|
|
||||||
saleCount++;
|
|
||||||
saleAmount += pay.getAmount();
|
|
||||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
|
||||||
preCount++;
|
|
||||||
preAmount += pay.getAmount();
|
|
||||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.REFUND) {
|
|
||||||
refundCount++;
|
|
||||||
refundAmount += pay.getAmount();
|
|
||||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.CASH_ADVANCE) {
|
|
||||||
caCount++;
|
|
||||||
caAmount += pay.getAmount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(true);
|
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(true);
|
||||||
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
||||||
|
|
||||||
String bitmap = com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig.BPC_SETTLEMENT;
|
String bitmap = com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig.BPC_SETTLEMENT;
|
||||||
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.name);
|
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.name);
|
||||||
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SETTLEMENT);
|
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SETTLEMENT);
|
||||||
payDetail.setProcessCode(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.processCode);
|
payDetail.setProcessCode(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.processCode);
|
||||||
payDetail.setBatchNo(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
payDetail.setBatchNo(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||||
|
|
||||||
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
||||||
saleCount,
|
saleCount,
|
||||||
saleAmount,
|
saleAmount,
|
||||||
preCount,
|
preCount,
|
||||||
preAmount,
|
preAmount,
|
||||||
refundCount,
|
refundCount,
|
||||||
refundAmount,
|
refundAmount,
|
||||||
caCount,
|
caCount,
|
||||||
caAmount
|
caAmount
|
||||||
);
|
);
|
||||||
payDetail.setSettleDataObj(settleData);
|
payDetail.setSettleDataObj(settleData);
|
||||||
|
|
||||||
long totalAmount = saleAmount + preAmount + refundAmount + caAmount;
|
long totalAmount = saleAmount + preAmount + refundAmount + caAmount;
|
||||||
String settlementData;
|
String settlementData;
|
||||||
if (refundAmount != 0L) {
|
if (refundAmount != 0L) {
|
||||||
long creditTotal = saleAmount + preAmount + caAmount;
|
long creditTotal = saleAmount + preAmount + caAmount;
|
||||||
long subTotal = creditTotal - refundAmount;
|
long subTotal = creditTotal - refundAmount;
|
||||||
if (subTotal < 0L) {
|
if (subTotal < 0L) {
|
||||||
settlementData = "D" + String.format(java.util.Locale.getDefault(), "%012d", Math.abs(subTotal));
|
settlementData = "D" + String.format(java.util.Locale.getDefault(), "%012d", Math.abs(subTotal));
|
||||||
} else {
|
|
||||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", subTotal);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", totalAmount);
|
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", subTotal);
|
||||||
}
|
}
|
||||||
payDetail.setSettleData(settlementData);
|
} else {
|
||||||
payDetail.setAmount(totalAmount);
|
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", totalAmount);
|
||||||
|
}
|
||||||
|
payDetail.setSettleData(settlementData);
|
||||||
|
payDetail.setAmount(totalAmount);
|
||||||
|
|
||||||
tradeData.setPayDetail(payDetail);
|
tradeData.setPayDetail(payDetail);
|
||||||
tradeData.setField60(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
tradeData.setField60(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||||
|
|
||||||
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, com.utsmyanmar.paylibs.utils.MessageType.SETTLEMENT);
|
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, com.utsmyanmar.paylibs.utils.MessageType.SETTLEMENT);
|
||||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new com.utsmyanmar.paylibs.network.ISOCallback() {
|
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new com.utsmyanmar.paylibs.network.ISOCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(byte[] bytes, int length) {
|
public void onReceive(byte[] bytes, int length) {
|
||||||
java.util.Map<String, com.utsmyanmar.paylibs.model.MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
java.util.Map<String, com.utsmyanmar.paylibs.model.MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
||||||
if (responseMap != null) {
|
if (responseMap != null) {
|
||||||
String resultStr = "";
|
String resultStr = "";
|
||||||
try {
|
try {
|
||||||
resultStr = responseMap.get("F039").getDataStr();
|
resultStr = responseMap.get("F039").getDataStr();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
payDetail.setIsNeedReversal(true);
|
payDetail.setIsNeedReversal(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
payDetail.setTradeAnswerCode(resultStr);
|
payDetail.setTradeAnswerCode(resultStr);
|
||||||
if (TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_APPROVED)) {
|
if (TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_APPROVED)) {
|
||||||
payDetail.setIsNeedReversal(false);
|
payDetail.setIsNeedReversal(false);
|
||||||
} else if (TextUtils.equals(resultStr, "95") || TextUtils.equals(resultStr, "095")) {
|
} else if (TextUtils.equals(resultStr, "95") || TextUtils.equals(resultStr, "095")) {
|
||||||
payDetail.setIsNeedReversal(true);
|
payDetail.setIsNeedReversal(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(String msg) {
|
public void onError(String msg) {
|
||||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().switchIp();
|
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().switchIp();
|
||||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
if(list != null && !list.isEmpty()) {
|
LogUtil.d(TAG, "Auto settlement transaction completed successfully");
|
||||||
for (com.utsmyanmar.paylibs.model.PayDetail p : list) {
|
|
||||||
repository.deletePayDetail(p);
|
if (list != null && !list.isEmpty()) {
|
||||||
}
|
for (com.utsmyanmar.paylibs.model.PayDetail p : list) {
|
||||||
|
repository.deletePayDetail(p);
|
||||||
}
|
}
|
||||||
repository.insertPayDetail(payDetail);
|
}
|
||||||
|
repository.insertPayDetail(payDetail);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Remove the non-serializable SettleData object before passing through Intent
|
||||||
|
// Create a clean copy of PayDetail without the problematic SettleData object
|
||||||
|
com.utsmyanmar.paylibs.model.PayDetail cleanPayDetail = new com.utsmyanmar.paylibs.model.PayDetail();
|
||||||
|
cleanPayDetail.setTransType(payDetail.getTransType());
|
||||||
|
cleanPayDetail.setTransactionType(payDetail.getTransactionType());
|
||||||
|
cleanPayDetail.setProcessCode(payDetail.getProcessCode());
|
||||||
|
cleanPayDetail.setBatchNo(payDetail.getBatchNo());
|
||||||
|
cleanPayDetail.setSettleData(payDetail.getSettleData());
|
||||||
|
cleanPayDetail.setAmount(payDetail.getAmount());
|
||||||
|
cleanPayDetail.setTradeAnswerCode(payDetail.getTradeAnswerCode());
|
||||||
|
cleanPayDetail.setIsNeedReversal(payDetail.getIsNeedReversal());
|
||||||
|
// Note: Not setting SettleDataObj as it's not serializable
|
||||||
|
|
||||||
Intent uiIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
Intent uiIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||||
uiIntent.putExtra("AUTO_SETTLEMENT", true);
|
uiIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||||
uiIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
uiIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||||
uiIntent.putExtra("EXTRA_PAY_DETAIL", payDetail);
|
uiIntent.putExtra("EXTRA_PAY_DETAIL", cleanPayDetail);
|
||||||
uiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
uiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
startActivity(uiIntent);
|
startActivity(uiIntent);
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
LogUtil.d(TAG, "MainActivity started successfully with auto settlement result");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.e(TAG, "Error starting MainActivity: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
// Fallback: start MainActivity without the PayDetail extra
|
||||||
|
try {
|
||||||
|
Intent fallbackIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||||
|
fallbackIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||||
|
fallbackIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||||
|
fallbackIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
startActivity(fallbackIntent);
|
||||||
|
|
||||||
|
LogUtil.d(TAG, "MainActivity started with fallback approach");
|
||||||
|
|
||||||
|
} catch (Exception fallbackException) {
|
||||||
|
LogUtil.e(TAG, "Fallback also failed: " + fallbackException.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop the service
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -101,33 +101,19 @@ public class InputAmountViewModel extends ViewModel {
|
|||||||
inputAmount.deleteCharAt(inputAmount.length() - 1);
|
inputAmount.deleteCharAt(inputAmount.length() - 1);
|
||||||
inputAmountView.setValue(inputAmount.toString());
|
inputAmountView.setValue(inputAmount.toString());
|
||||||
} else if (!inputAmountView.getValue().equals("0")) {
|
} else if (!inputAmountView.getValue().equals("0")) {
|
||||||
StringBuilder inputAmount = new StringBuilder();
|
String currentValue = inputAmountView.getValue();
|
||||||
inputAmount.append(inputAmountView.getValue());
|
|
||||||
if (inputAmount.length() > 4) {
|
|
||||||
|
|
||||||
if(inputAmount.toString().contains(",")) {
|
String rawNumber = currentValue.replace(",", "");
|
||||||
int commaIndex = inputAmount.indexOf(",");
|
|
||||||
inputAmount.deleteCharAt(commaIndex);
|
|
||||||
} else {
|
|
||||||
inputAmount.deleteCharAt(inputAmount.length() - 1);
|
|
||||||
}
|
|
||||||
inputAmountView.setValue(inputAmount.toString());
|
|
||||||
|
|
||||||
|
if (rawNumber.length() > 1) {
|
||||||
|
rawNumber = rawNumber.substring(0, rawNumber.length() - 1);
|
||||||
|
|
||||||
// inputAmount.deleteCharAt(inputAmount.toString().length() - 4);
|
double amt = Double.parseDouble(rawNumber);
|
||||||
// if (inputAmount.charAt(inputAmount.toString().length() - 4) == ',') {
|
DecimalFormat formatter = new DecimalFormat("#,###");
|
||||||
// inputAmount.deleteCharAt(inputAmount.toString().length() - 4);
|
inputAmountView.setValue(formatter.format(amt));
|
||||||
// }
|
|
||||||
// inputAmountView.setValue(inputAmount.toString());
|
|
||||||
} else if(inputAmount.length() == 1) {
|
|
||||||
inputAmountView.setValue("0");
|
|
||||||
} else {
|
} else {
|
||||||
StringBuilder currentAmount = new StringBuilder();
|
inputAmountView.setValue("0");
|
||||||
currentAmount.append(inputAmountView.getValue());
|
|
||||||
currentAmount.deleteCharAt(currentAmount.length() - 1);
|
|
||||||
inputAmountView.setValue(currentAmount.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package com.utsmm.kbz.ui.tms;
|
package com.utsmm.kbz.ui.tms;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@ -27,6 +31,7 @@ import com.utsmm.kbz.util.enums.TMSDownloadStatus;
|
|||||||
import com.utsmm.kbz.util.tms.TMSUtil;
|
import com.utsmm.kbz.util.tms.TMSUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
@ -228,11 +233,14 @@ public class TMSProcessFragment extends DataBindingFragment {
|
|||||||
|
|
||||||
private void scheduleAutoSettlement() {
|
private void scheduleAutoSettlement() {
|
||||||
String timeStr = SystemParamsOperation.getInstance().getClearBatchTime();
|
String timeStr = SystemParamsOperation.getInstance().getClearBatchTime();
|
||||||
|
LogUtil.d(TAG,"timeStr:" + timeStr );
|
||||||
if(timeStr == null || timeStr.trim().isEmpty()) {
|
if(timeStr == null || timeStr.trim().isEmpty()) {
|
||||||
|
LogUtil.d(TAG, "Clear batch time is empty, skipping auto settlement scheduling");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String[] parts = timeStr.trim().split(":");
|
String[] parts = timeStr.trim().split(":");
|
||||||
if(parts.length != 2) {
|
if(parts.length != 2) {
|
||||||
|
LogUtil.d(TAG, "Invalid time format: " + timeStr + ", expected HH:MM");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int hour;
|
int hour;
|
||||||
@ -240,34 +248,97 @@ public class TMSProcessFragment extends DataBindingFragment {
|
|||||||
try {
|
try {
|
||||||
hour = Integer.parseInt(parts[0]);
|
hour = Integer.parseInt(parts[0]);
|
||||||
minute = Integer.parseInt(parts[1]);
|
minute = Integer.parseInt(parts[1]);
|
||||||
|
|
||||||
|
// Validate time range
|
||||||
|
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
||||||
|
LogUtil.d(TAG, "Invalid time values - hour: " + hour + ", minute: " + minute);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
LogUtil.d(TAG, "Error parsing time string: " + timeStr + ", error: " + e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
android.app.AlarmManager alarmManager = (android.app.AlarmManager) requireContext().getSystemService(android.content.Context.ALARM_SERVICE);
|
LogUtil.d(TAG, "Scheduling auto settlement for hour:" + hour + " minute:" + minute);
|
||||||
if(alarmManager == null) return;
|
AlarmManager alarmManager = (AlarmManager) requireContext().getSystemService(Context.ALARM_SERVICE);
|
||||||
|
if (alarmManager == null) {
|
||||||
|
LogUtil.d(TAG, "AlarmManager is null, cannot schedule alarm");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
java.util.Calendar calendar = java.util.Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
calendar.set(java.util.Calendar.HOUR_OF_DAY, hour);
|
calendar.set(java.util.Calendar.HOUR_OF_DAY, hour);
|
||||||
calendar.set(java.util.Calendar.MINUTE, minute);
|
calendar.set(java.util.Calendar.MINUTE, minute);
|
||||||
calendar.set(java.util.Calendar.SECOND, 0);
|
calendar.set(java.util.Calendar.SECOND, 0);
|
||||||
|
calendar.set(java.util.Calendar.MILLISECOND, 0);
|
||||||
|
|
||||||
long triggerAtMillis = calendar.getTimeInMillis();
|
long triggerAtMillis = calendar.getTimeInMillis();
|
||||||
if(System.currentTimeMillis() > triggerAtMillis) {
|
long currentTime = System.currentTimeMillis();
|
||||||
calendar.add(java.util.Calendar.DAY_OF_YEAR, 1);
|
|
||||||
|
LogUtil.d(TAG, "Current time: " + new java.util.Date(currentTime).toString());
|
||||||
|
LogUtil.d(TAG, "Initial trigger time: " + new java.util.Date(triggerAtMillis).toString());
|
||||||
|
|
||||||
|
if (currentTime > triggerAtMillis) {
|
||||||
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
triggerAtMillis = calendar.getTimeInMillis();
|
triggerAtMillis = calendar.getTimeInMillis();
|
||||||
|
LogUtil.d(TAG, "Trigger time is in the past, scheduling for next day: " + new java.util.Date(triggerAtMillis).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
android.content.Intent intent = new android.content.Intent(requireContext(), AutoAlarmReceiver.class);
|
Intent intent = new Intent(requireContext(), AutoAlarmReceiver.class);
|
||||||
android.app.PendingIntent pendingIntent = android.app.PendingIntent.getBroadcast(
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
1001,
|
1001,
|
||||||
intent,
|
intent,
|
||||||
android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||||
);
|
);
|
||||||
|
|
||||||
alarmManager.setRepeating(android.app.AlarmManager.RTC_WAKEUP, triggerAtMillis, android.app.AlarmManager.INTERVAL_DAY, pendingIntent);
|
try {
|
||||||
|
// For Android 12+ (API 31+), we need to handle exact alarms differently
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
|
// Check if the app can schedule exact alarms
|
||||||
|
if (alarmManager.canScheduleExactAlarms()) {
|
||||||
|
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||||
|
LogUtil.d(TAG, "Auto settlement alarm scheduled successfully for: " + new java.util.Date(triggerAtMillis).toString());
|
||||||
|
} else {
|
||||||
|
LogUtil.d(TAG, "App doesn't have permission to schedule exact alarms. Using inexact alarm.");
|
||||||
|
// Use inexact alarm as fallback
|
||||||
|
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||||
|
LogUtil.d(TAG, "Auto settlement inexact alarm scheduled for: " + new java.util.Date(triggerAtMillis).toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For older Android versions
|
||||||
|
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||||
|
LogUtil.d(TAG, "Auto settlement alarm scheduled successfully for: " + new java.util.Date(triggerAtMillis).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also try to schedule a test alarm 30 seconds from now for debugging
|
||||||
|
long testTriggerTime = currentTime + 30000; // 30 seconds from now
|
||||||
|
Intent testIntent = new Intent(requireContext(), AutoAlarmReceiver.class);
|
||||||
|
testIntent.putExtra("TEST_ALARM", true);
|
||||||
|
PendingIntent testPendingIntent = PendingIntent.getBroadcast(
|
||||||
|
requireContext(),
|
||||||
|
1002,
|
||||||
|
testIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||||
|
);
|
||||||
|
|
||||||
|
// Schedule test alarm
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
|
if (alarmManager.canScheduleExactAlarms()) {
|
||||||
|
alarmManager.setExact(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||||
|
} else {
|
||||||
|
alarmManager.set(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alarmManager.set(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||||
|
}
|
||||||
|
LogUtil.d(TAG, "Test alarm scheduled for: " + new java.util.Date(testTriggerTime).toString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.d(TAG, "Error scheduling alarm: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -285,8 +285,8 @@ public class NetworkModule {
|
|||||||
tmsAddress = getTMSUrlFromNative();
|
tmsAddress = getTMSUrlFromNative();
|
||||||
}
|
}
|
||||||
|
|
||||||
// String baseUrl = tmsAddress.trim() + "/api/v1/";
|
String baseUrl = tmsAddress.trim() + "/api/v1/";
|
||||||
String baseUrl = tmsAddress.trim() + "/";
|
// String baseUrl = tmsAddress.trim() + "/";
|
||||||
|
|
||||||
final Gson gson =
|
final Gson gson =
|
||||||
new GsonBuilder().create();
|
new GsonBuilder().create();
|
||||||
|
|||||||
@ -42,8 +42,8 @@ public class SystemParamsSettings implements Serializable {
|
|||||||
|
|
||||||
// private String tmsAddress = "https://tms.smile-mm.com";
|
// private String tmsAddress = "https://tms.smile-mm.com";
|
||||||
// private String tmsAddress = "http://128.199.170.203";
|
// private String tmsAddress = "http://128.199.170.203";
|
||||||
// private String tmsAddress = "http://sirius-nest.utsmyanmar.com";
|
private String tmsAddress = "http://sirius-nest.utsmyanmar.com";
|
||||||
private String tmsAddress = "https://api-tms-uat.kbzbank.com:8443/sirius";
|
// private String tmsAddress = "https://api-tms-uat.kbzbank.com:8443/sirius";
|
||||||
private String ereceiptAddress = "http://receipt-nest.utsmyanmar.com";
|
private String ereceiptAddress = "http://receipt-nest.utsmyanmar.com";
|
||||||
|
|
||||||
private String terminalCapability = "E0E8C8";
|
private String terminalCapability = "E0E8C8";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user