Fix payment dan struk
This commit is contained in:
		
							parent
							
								
									a1f536b03e
								
							
						
					
					
						commit
						074a4b1f53
					
				@ -534,16 +534,18 @@ public class QrisActivity extends AppCompatActivity {
 | 
				
			|||||||
                    String transactionTime = midtransResponse.getString("transaction_time");
 | 
					                    String transactionTime = midtransResponse.getString("transaction_time");
 | 
				
			||||||
                    String acquirer = midtransResponse.getString("acquirer");
 | 
					                    String acquirer = midtransResponse.getString("acquirer");
 | 
				
			||||||
                    String merchantId = midtransResponse.getString("merchant_id");
 | 
					                    String merchantId = midtransResponse.getString("merchant_id");
 | 
				
			||||||
                    String exactGrossAmount = midtransResponse.getString("gross_amount");
 | 
					                    
 | 
				
			||||||
 | 
					                    // FIXED: Send raw amount as string without decimal conversion
 | 
				
			||||||
 | 
					                    String rawAmountString = String.valueOf(amount); // Keep original integer amount
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    // Log everything before launching activity
 | 
					                    // Log everything before launching activity
 | 
				
			||||||
                    Log.d("MidtransCharge", "=== LAUNCHING QRIS RESULT ACTIVITY ===");
 | 
					                    Log.d("MidtransCharge", "=== LAUNCHING QRIS RESULT ACTIVITY ===");
 | 
				
			||||||
                    Log.d("MidtransCharge", "qrImageUrl: " + qrImageUrl);
 | 
					                    Log.d("MidtransCharge", "qrImageUrl: " + qrImageUrl);
 | 
				
			||||||
                    Log.d("MidtransCharge", "amount: " + amount);
 | 
					                    Log.d("MidtransCharge", "amount (raw): " + amount);
 | 
				
			||||||
 | 
					                    Log.d("MidtransCharge", "rawAmountString: " + rawAmountString);
 | 
				
			||||||
                    Log.d("MidtransCharge", "referenceId: " + referenceId);
 | 
					                    Log.d("MidtransCharge", "referenceId: " + referenceId);
 | 
				
			||||||
                    Log.d("MidtransCharge", "transactionUuid (orderId): " + transactionUuid);
 | 
					                    Log.d("MidtransCharge", "transactionUuid (orderId): " + transactionUuid);
 | 
				
			||||||
                    Log.d("MidtransCharge", "transaction_id: " + transactionId);
 | 
					                    Log.d("MidtransCharge", "transaction_id: " + transactionId);
 | 
				
			||||||
                    Log.d("MidtransCharge", "exactGrossAmount: " + exactGrossAmount);
 | 
					 | 
				
			||||||
                    Log.d("MidtransCharge", "transactionTime: " + transactionTime);
 | 
					                    Log.d("MidtransCharge", "transactionTime: " + transactionTime);
 | 
				
			||||||
                    Log.d("MidtransCharge", "acquirer: " + acquirer);
 | 
					                    Log.d("MidtransCharge", "acquirer: " + acquirer);
 | 
				
			||||||
                    Log.d("MidtransCharge", "merchantId: " + merchantId);
 | 
					                    Log.d("MidtransCharge", "merchantId: " + merchantId);
 | 
				
			||||||
@ -552,11 +554,11 @@ public class QrisActivity extends AppCompatActivity {
 | 
				
			|||||||
                    // Launch QrisResultActivity
 | 
					                    // Launch QrisResultActivity
 | 
				
			||||||
                    Intent intent = new Intent(QrisActivity.this, QrisResultActivity.class);
 | 
					                    Intent intent = new Intent(QrisActivity.this, QrisResultActivity.class);
 | 
				
			||||||
                    intent.putExtra("qrImageUrl", qrImageUrl);
 | 
					                    intent.putExtra("qrImageUrl", qrImageUrl);
 | 
				
			||||||
                    intent.putExtra("amount", amount);
 | 
					                    intent.putExtra("amount", amount); // Keep as int
 | 
				
			||||||
                    intent.putExtra("referenceId", referenceId);
 | 
					                    intent.putExtra("referenceId", referenceId);
 | 
				
			||||||
                    intent.putExtra("orderId", transactionUuid); // Order ID
 | 
					                    intent.putExtra("orderId", transactionUuid); // Order ID
 | 
				
			||||||
                    intent.putExtra("transactionId", transactionId); // Actual Midtrans transaction_id
 | 
					                    intent.putExtra("transactionId", transactionId); // Actual Midtrans transaction_id
 | 
				
			||||||
                    intent.putExtra("grossAmount", exactGrossAmount); // Exact gross amount from response
 | 
					                    intent.putExtra("grossAmount", rawAmountString); // FIXED: Raw amount as string (no decimals)
 | 
				
			||||||
                    intent.putExtra("transactionTime", transactionTime); // For timestamp
 | 
					                    intent.putExtra("transactionTime", transactionTime); // For timestamp
 | 
				
			||||||
                    intent.putExtra("acquirer", acquirer);
 | 
					                    intent.putExtra("acquirer", acquirer);
 | 
				
			||||||
                    intent.putExtra("merchantId", merchantId);
 | 
					                    intent.putExtra("merchantId", merchantId);
 | 
				
			||||||
 | 
				
			|||||||
@ -513,11 +513,53 @@ public class QrisResultActivity extends AppCompatActivity {
 | 
				
			|||||||
        statusTextView.setText("✅ Payment Successful!\n\nTransaction ID: " + transactionId + 
 | 
					        statusTextView.setText("✅ Payment Successful!\n\nTransaction ID: " + transactionId + 
 | 
				
			||||||
                            "\nReference: " + referenceId + 
 | 
					                            "\nReference: " + referenceId + 
 | 
				
			||||||
                            "\nAmount: " + formatCurrency(grossAmount));
 | 
					                            "\nAmount: " + formatCurrency(grossAmount));
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Add receipt button
 | 
				
			||||||
 | 
					        Button showReceiptButton = new Button(this);
 | 
				
			||||||
 | 
					        showReceiptButton.setText("Show Receipt");
 | 
				
			||||||
 | 
					        showReceiptButton.setOnClickListener(v -> launchReceiptActivity());
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // You can add this button to your layout programmatically
 | 
				
			||||||
 | 
					        // or add it to your XML and show it here
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        returnMainButton.setVisibility(View.VISIBLE);
 | 
					        returnMainButton.setVisibility(View.VISIBLE);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        Toast.makeText(this, "Payment simulation completed successfully!", Toast.LENGTH_LONG).show();
 | 
					        Toast.makeText(this, "Payment simulation completed successfully!", Toast.LENGTH_LONG).show();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Fixed method for launching ReceiptActivity
 | 
				
			||||||
 | 
					    private void launchReceiptActivity() {
 | 
				
			||||||
 | 
					        Intent intent = new Intent(this, ReceiptActivity.class);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Add calling activity information for proper back navigation
 | 
				
			||||||
 | 
					        intent.putExtra("calling_activity", "QrisResultActivity");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Pass all the transaction data using available class variables
 | 
				
			||||||
 | 
					        intent.putExtra("transaction_id", transactionId); // Midtrans transaction_id
 | 
				
			||||||
 | 
					        intent.putExtra("reference_id", referenceId); // Your reference ID
 | 
				
			||||||
 | 
					        intent.putExtra("order_id", orderId); // Order ID (UUID)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Use grossAmount for both transaction_amount and gross_amount
 | 
				
			||||||
 | 
					        intent.putExtra("transaction_amount", grossAmount != null ? grossAmount : "0");
 | 
				
			||||||
 | 
					        intent.putExtra("gross_amount", grossAmount); // From Midtrans response
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        intent.putExtra("transaction_date", getCurrentDateTime());
 | 
				
			||||||
 | 
					        intent.putExtra("payment_method", "QRIS");
 | 
				
			||||||
 | 
					        intent.putExtra("card_type", "QRIS");
 | 
				
			||||||
 | 
					        intent.putExtra("channel_code", "QRIS");
 | 
				
			||||||
 | 
					        intent.putExtra("channel_category", "RETAIL_OUTLET");
 | 
				
			||||||
 | 
					        intent.putExtra("merchant_name", "Marcel Panjaitan"); // From your transaction data
 | 
				
			||||||
 | 
					        intent.putExtra("merchant_location", "Jakarta, Indonesia");
 | 
				
			||||||
 | 
					        intent.putExtra("acquirer", acquirer); // From Midtrans response
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        startActivity(intent);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String getCurrentDateTime() {
 | 
				
			||||||
 | 
					        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd MMMM yyyy HH:mm", new java.util.Locale("id", "ID"));
 | 
				
			||||||
 | 
					        return sdf.format(new java.util.Date());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onOptionsItemSelected(android.view.MenuItem item) {
 | 
					    public boolean onOptionsItemSelected(android.view.MenuItem item) {
 | 
				
			||||||
        if (item.getItemId() == android.R.id.home) {
 | 
					        if (item.getItemId() == android.R.id.home) {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,7 @@ import android.graphics.Color;
 | 
				
			|||||||
import android.os.Build;
 | 
					import android.os.Build;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import android.text.TextUtils;
 | 
					import android.text.TextUtils;
 | 
				
			||||||
 | 
					import android.util.Log; // ADD THIS IMPORT
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
import android.view.Window;
 | 
					import android.view.Window;
 | 
				
			||||||
import android.view.WindowManager;
 | 
					import android.view.WindowManager;
 | 
				
			||||||
@ -88,17 +89,17 @@ public class ReceiptActivity extends AppCompatActivity {
 | 
				
			|||||||
        serviceFee = findViewById(R.id.service_fee);
 | 
					        serviceFee = findViewById(R.id.service_fee);
 | 
				
			||||||
        finalTotal = findViewById(R.id.final_total);
 | 
					        finalTotal = findViewById(R.id.final_total);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Action buttons - Updated to LinearLayout
 | 
					        // Action buttons
 | 
				
			||||||
        printButton = findViewById(R.id.print_button);
 | 
					        printButton = findViewById(R.id.print_button);
 | 
				
			||||||
        emailButton = findViewById(R.id.email_button);
 | 
					        emailButton = findViewById(R.id.email_button);
 | 
				
			||||||
        finishButton = findViewById(R.id.finish_button);
 | 
					        finishButton = findViewById(R.id.finish_button);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void setupClickListeners() {
 | 
					    private void setupClickListeners() {
 | 
				
			||||||
        // Back navigation - Goes back to previous activity (PaymentActivity)
 | 
					        // Back navigation - Goes back to previous activity
 | 
				
			||||||
        backNavigation.setOnClickListener(v -> navigateBackToPrevious());
 | 
					        backNavigation.setOnClickListener(v -> handleBackNavigation());
 | 
				
			||||||
        backArrow.setOnClickListener(v -> navigateBackToPrevious());
 | 
					        backArrow.setOnClickListener(v -> handleBackNavigation());
 | 
				
			||||||
        toolbarTitle.setOnClickListener(v -> navigateBackToPrevious());
 | 
					        toolbarTitle.setOnClickListener(v -> handleBackNavigation());
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Action buttons
 | 
					        // Action buttons
 | 
				
			||||||
        printButton.setOnClickListener(v -> handlePrintReceipt());
 | 
					        printButton.setOnClickListener(v -> handlePrintReceipt());
 | 
				
			||||||
@ -109,7 +110,7 @@ public class ReceiptActivity extends AppCompatActivity {
 | 
				
			|||||||
    private void loadTransactionData() {
 | 
					    private void loadTransactionData() {
 | 
				
			||||||
        Intent intent = getIntent();
 | 
					        Intent intent = getIntent();
 | 
				
			||||||
        if (intent != null) {
 | 
					        if (intent != null) {
 | 
				
			||||||
            // Data dari TransactionActivity
 | 
					            // Data dari TransactionActivity atau QrisResultActivity
 | 
				
			||||||
            String amount = intent.getStringExtra("transaction_amount");
 | 
					            String amount = intent.getStringExtra("transaction_amount");
 | 
				
			||||||
            String merchantNameStr = intent.getStringExtra("merchant_name");
 | 
					            String merchantNameStr = intent.getStringExtra("merchant_name");
 | 
				
			||||||
            String merchantLocationStr = intent.getStringExtra("merchant_location");
 | 
					            String merchantLocationStr = intent.getStringExtra("merchant_location");
 | 
				
			||||||
@ -118,41 +119,214 @@ public class ReceiptActivity extends AppCompatActivity {
 | 
				
			|||||||
            String paymentMethodStr = intent.getStringExtra("payment_method");
 | 
					            String paymentMethodStr = intent.getStringExtra("payment_method");
 | 
				
			||||||
            String cardTypeStr = intent.getStringExtra("card_type");
 | 
					            String cardTypeStr = intent.getStringExtra("card_type");
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            // Set data ke view
 | 
					            // Additional data that might come from different sources
 | 
				
			||||||
            merchantName.setText(merchantNameStr != null ? merchantNameStr : "TOKO KLONTONG PAK EKO");
 | 
					            String referenceId = intent.getStringExtra("reference_id");
 | 
				
			||||||
            merchantLocation.setText(merchantLocationStr != null ? merchantLocationStr : "Ciputat Baru, Tangsel");
 | 
					            String orderId = intent.getStringExtra("order_id");
 | 
				
			||||||
            transactionNumber.setText(transactionId != null ? transactionId : "3429483635");
 | 
					            String grossAmount = intent.getStringExtra("gross_amount");
 | 
				
			||||||
            transactionDate.setText(transactionDateStr != null ? transactionDateStr : "13 Januari 2025 13:46");
 | 
					            String acquirer = intent.getStringExtra("acquirer");
 | 
				
			||||||
            paymentMethod.setText(paymentMethodStr != null ? paymentMethodStr : "Kartu Kredit");
 | 
					            String channelCode = intent.getStringExtra("channel_code");
 | 
				
			||||||
            cardType.setText(cardTypeStr != null ? cardTypeStr : "BCA");
 | 
					            String channelCategory = intent.getStringExtra("channel_category");
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            // Format nominal
 | 
					            // Set merchant data with defaults
 | 
				
			||||||
            if (amount != null) {
 | 
					            merchantName.setText(merchantNameStr != null ? merchantNameStr : "Marcel Panjaitan");
 | 
				
			||||||
 | 
					            merchantLocation.setText(merchantLocationStr != null ? merchantLocationStr : "Jakarta, Indonesia");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Set MID and TID with defaults
 | 
				
			||||||
 | 
					            midText.setText("71000026521"); // Default MID from your transaction code
 | 
				
			||||||
 | 
					            tidText.setText("73001500"); // Default TID from your transaction code
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Set transaction number - prefer reference_id, then transaction_id, then order_id
 | 
				
			||||||
 | 
					            String displayTransactionNumber = null;
 | 
				
			||||||
 | 
					            if (referenceId != null && !referenceId.isEmpty()) {
 | 
				
			||||||
 | 
					                displayTransactionNumber = referenceId;
 | 
				
			||||||
 | 
					            } else if (transactionId != null && !transactionId.isEmpty()) {
 | 
				
			||||||
 | 
					                displayTransactionNumber = transactionId;
 | 
				
			||||||
 | 
					            } else if (orderId != null && !orderId.isEmpty()) {
 | 
				
			||||||
 | 
					                displayTransactionNumber = orderId;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            transactionNumber.setText(displayTransactionNumber != null ? displayTransactionNumber : "3429483635");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Set transaction date
 | 
				
			||||||
 | 
					            transactionDate.setText(transactionDateStr != null ? transactionDateStr : getCurrentDateTime());
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Set payment method - determine from various sources
 | 
				
			||||||
 | 
					            String displayPaymentMethod = determinePaymentMethod(paymentMethodStr, channelCode, channelCategory);
 | 
				
			||||||
 | 
					            paymentMethod.setText(displayPaymentMethod);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Set card type - prefer acquirer, then cardType, then channelCode
 | 
				
			||||||
 | 
					            String displayCardType = null;
 | 
				
			||||||
 | 
					            if (acquirer != null && !acquirer.isEmpty()) {
 | 
				
			||||||
 | 
					                displayCardType = acquirer.toUpperCase();
 | 
				
			||||||
 | 
					            } else if (cardTypeStr != null && !cardTypeStr.isEmpty()) {
 | 
				
			||||||
 | 
					                displayCardType = cardTypeStr;
 | 
				
			||||||
 | 
					            } else if (channelCode != null && !channelCode.isEmpty()) {
 | 
				
			||||||
 | 
					                displayCardType = channelCode.toUpperCase();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            cardType.setText(displayCardType != null ? displayCardType : "QRIS");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Format and set amounts
 | 
				
			||||||
 | 
					            setAmountData(amount, grossAmount);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String determinePaymentMethod(String paymentMethodStr, String channelCode, String channelCategory) {
 | 
				
			||||||
 | 
					        // If payment method is already provided and formatted, use it
 | 
				
			||||||
 | 
					        if (paymentMethodStr != null && !paymentMethodStr.isEmpty()) {
 | 
				
			||||||
 | 
					            return paymentMethodStr;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Determine from channel code
 | 
				
			||||||
 | 
					        if (channelCode != null) {
 | 
				
			||||||
 | 
					            switch (channelCode.toUpperCase()) {
 | 
				
			||||||
 | 
					                case "QRIS":
 | 
				
			||||||
 | 
					                    return "QRIS";
 | 
				
			||||||
 | 
					                case "DEBIT":
 | 
				
			||||||
 | 
					                    return "Kartu Debit";
 | 
				
			||||||
 | 
					                case "CREDIT":
 | 
				
			||||||
 | 
					                    return "Kartu Kredit";
 | 
				
			||||||
 | 
					                case "BCA":
 | 
				
			||||||
 | 
					                case "MANDIRI":
 | 
				
			||||||
 | 
					                case "BNI":
 | 
				
			||||||
 | 
					                case "BRI":
 | 
				
			||||||
 | 
					                    return "Kartu " + channelCode.toUpperCase();
 | 
				
			||||||
 | 
					                case "CASH":
 | 
				
			||||||
 | 
					                    return "Tunai";
 | 
				
			||||||
 | 
					                case "EDC":
 | 
				
			||||||
 | 
					                    return "EDC";
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Determine from channel category
 | 
				
			||||||
 | 
					        if (channelCategory != null && !channelCategory.isEmpty()) {
 | 
				
			||||||
 | 
					            return channelCategory.toUpperCase();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Default
 | 
				
			||||||
 | 
					        return "QRIS";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void setAmountData(String amount, String grossAmount) {
 | 
				
			||||||
 | 
					        // Use gross amount if available, otherwise use amount
 | 
				
			||||||
 | 
					        String amountToUse = grossAmount != null ? grossAmount : amount;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("ReceiptActivity", "Setting amount data - amount: " + amount + 
 | 
				
			||||||
 | 
					            ", grossAmount: " + grossAmount + ", using: " + amountToUse);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if (amountToUse != null) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                    long amountValue = Long.parseLong(amount);
 | 
					                // Clean and parse the amount
 | 
				
			||||||
                    transactionTotal.setText(formatCurrency(amountValue));
 | 
					                String cleanAmount = cleanAmountString(amountToUse);
 | 
				
			||||||
 | 
					                Log.d("ReceiptActivity", "Cleaned amount: " + cleanAmount);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                    // Hitung total akhir (contoh: tambah pajak 11% dan biaya layanan 500)
 | 
					                // Parse as long integer (Indonesian Rupiah doesn't use decimal cents)
 | 
				
			||||||
                    long tax = (long) (amountValue * 0.11);
 | 
					                long amountLong = Long.parseLong(cleanAmount);
 | 
				
			||||||
                    long serviceFeeValue = 500;
 | 
					 | 
				
			||||||
                    long total = amountValue + tax + serviceFeeValue;
 | 
					 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                    taxPercentage.setText(formatCurrency(tax) + " (11%)");
 | 
					                // Set transaction total
 | 
				
			||||||
                    serviceFee.setText(formatCurrency(serviceFeeValue));
 | 
					                transactionTotal.setText("Rp " + formatCurrency(amountLong));
 | 
				
			||||||
                    finalTotal.setText(formatCurrency(total));
 | 
					                
 | 
				
			||||||
 | 
					                // Calculate tax and service fee (for QRIS, typically no additional fees)
 | 
				
			||||||
 | 
					                long tax = 0; // QRIS usually doesn't have tax
 | 
				
			||||||
 | 
					                long serviceFeeValue = 0; // QRIS usually doesn't have service fee
 | 
				
			||||||
 | 
					                long total = amountLong + tax + serviceFeeValue;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Set calculated values
 | 
				
			||||||
 | 
					                taxPercentage.setText("Rp 0");
 | 
				
			||||||
 | 
					                serviceFee.setText("Rp 0");
 | 
				
			||||||
 | 
					                finalTotal.setText("Rp " + formatCurrency(total));
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
            } catch (NumberFormatException e) {
 | 
					            } catch (NumberFormatException e) {
 | 
				
			||||||
                    transactionTotal.setText(amount);
 | 
					                Log.e("ReceiptActivity", "Error parsing amount: " + amountToUse, e);
 | 
				
			||||||
                    finalTotal.setText(amount);
 | 
					                // Fallback if parsing fails
 | 
				
			||||||
 | 
					                transactionTotal.setText("Rp " + amountToUse);
 | 
				
			||||||
 | 
					                taxPercentage.setText("Rp 0");
 | 
				
			||||||
 | 
					                serviceFee.setText("Rp 0");
 | 
				
			||||||
 | 
					                finalTotal.setText("Rp " + amountToUse);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            // Default values if no amount provided
 | 
				
			||||||
 | 
					            transactionTotal.setText("Rp 0");
 | 
				
			||||||
 | 
					            taxPercentage.setText("Rp 0");
 | 
				
			||||||
 | 
					            serviceFee.setText("Rp 0");
 | 
				
			||||||
 | 
					            finalTotal.setText("Rp 0");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * FIXED: Clean amount string to extract raw number correctly
 | 
				
			||||||
 | 
					     * Input examples: "1000", "1000.00", "Rp 1.000", "1.000"
 | 
				
			||||||
 | 
					     * Output: "1000"
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String cleanAmountString(String amount) {
 | 
				
			||||||
 | 
					        if (amount == null || amount.isEmpty()) {
 | 
				
			||||||
 | 
					            return "0";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove currency symbols and spaces first
 | 
				
			||||||
 | 
					        String cleaned = amount
 | 
				
			||||||
 | 
					                .replace("Rp. ", "")
 | 
				
			||||||
 | 
					                .replace("Rp ", "")
 | 
				
			||||||
 | 
					                .replace("IDR ", "")
 | 
				
			||||||
 | 
					                .replace(" ", "")
 | 
				
			||||||
 | 
					                .trim();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("ReceiptActivity", "After currency removal: '" + cleaned + "'");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Handle decimal cases properly
 | 
				
			||||||
 | 
					        if (cleaned.contains(".")) {
 | 
				
			||||||
 | 
					            // Check if it contains decimal cents (like "1000.00") or thousand separator (like "1.000")
 | 
				
			||||||
 | 
					            String[] parts = cleaned.split("\\.");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            if (parts.length == 2) {
 | 
				
			||||||
 | 
					                String beforeDot = parts[0];
 | 
				
			||||||
 | 
					                String afterDot = parts[1];
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // If after dot is "00" or "0", it's decimal cents - remove it
 | 
				
			||||||
 | 
					                if (afterDot.equals("00") || afterDot.equals("0")) {
 | 
				
			||||||
 | 
					                    cleaned = beforeDot;
 | 
				
			||||||
 | 
					                    Log.d("ReceiptActivity", "Removed decimal cents: '" + cleaned + "'");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // If after dot has 3 digits, it's thousand separator - combine them
 | 
				
			||||||
 | 
					                else if (afterDot.length() == 3) {
 | 
				
			||||||
 | 
					                    cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                    Log.d("ReceiptActivity", "Combined thousand separator: '" + cleaned + "'");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // For other cases, try to determine based on length
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    // If beforeDot is short (1-3 digits) and afterDot is 3 digits, it's thousand separator
 | 
				
			||||||
 | 
					                    if (beforeDot.length() <= 3 && afterDot.length() == 3) {
 | 
				
			||||||
 | 
					                        cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        // Otherwise, it's likely decimal - remove the decimal part
 | 
				
			||||||
 | 
					                        cleaned = beforeDot;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    Log.d("ReceiptActivity", "Processed mixed format: '" + cleaned + "'");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                // Multiple dots - remove all dots (treat as thousand separators)
 | 
				
			||||||
 | 
					                cleaned = cleaned.replace(".", "");
 | 
				
			||||||
 | 
					                Log.d("ReceiptActivity", "Removed multiple dots: '" + cleaned + "'");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove any remaining commas (some locales use comma as thousand separator)
 | 
				
			||||||
 | 
					        cleaned = cleaned.replace(",", "");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("ReceiptActivity", "Final cleaned amount: '" + amount + "' -> '" + cleaned + "'");
 | 
				
			||||||
 | 
					        return cleaned;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private String formatCurrency(long amount) {
 | 
					    private String formatCurrency(long amount) {
 | 
				
			||||||
 | 
					        // Use Indonesian locale formatting with dots as thousand separators
 | 
				
			||||||
        return String.format("%,d", amount).replace(',', '.');
 | 
					        return String.format("%,d", amount).replace(',', '.');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String getCurrentDateTime() {
 | 
				
			||||||
 | 
					        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd MMMM yyyy HH:mm", new java.util.Locale("id", "ID"));
 | 
				
			||||||
 | 
					        return sdf.format(new java.util.Date());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void handlePrintReceipt() {
 | 
					    private void handlePrintReceipt() {
 | 
				
			||||||
        // Handle print receipt action
 | 
					        // Handle print receipt action
 | 
				
			||||||
        // In real app, this would integrate with printer
 | 
					        // In real app, this would integrate with printer
 | 
				
			||||||
@ -170,16 +344,48 @@ public class ReceiptActivity extends AppCompatActivity {
 | 
				
			|||||||
        navigateToHomePage();
 | 
					        navigateToHomePage();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void navigateBackToPrevious() {
 | 
					    private void handleBackNavigation() {
 | 
				
			||||||
        // Navigate back to PaymentActivity (previous activity)
 | 
					        // Smart back navigation - go to the actual previous activity
 | 
				
			||||||
        Intent intent = new Intent(this, PaymentActivity.class);
 | 
					        // Check if we have a calling activity in the intent
 | 
				
			||||||
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
 | 
					        String callingActivity = getIntent().getStringExtra("calling_activity");
 | 
				
			||||||
        startActivity(intent);
 | 
					        
 | 
				
			||||||
 | 
					        if (callingActivity != null) {
 | 
				
			||||||
 | 
					            switch (callingActivity) {
 | 
				
			||||||
 | 
					                case "TransactionActivity":
 | 
				
			||||||
 | 
					                    // Go back to transaction list
 | 
				
			||||||
 | 
					                    Intent transactionIntent = new Intent(this, TransactionActivity.class);
 | 
				
			||||||
 | 
					                    transactionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
 | 
				
			||||||
 | 
					                    startActivity(transactionIntent);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                case "QrisResultActivity":
 | 
				
			||||||
 | 
					                    // Go back to main menu since QrisResultActivity is typically finished
 | 
				
			||||||
 | 
					                    navigateToHomePage();
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                case "PaymentActivity":
 | 
				
			||||||
 | 
					                case "QrisActivity":
 | 
				
			||||||
 | 
					                    // Go back to payment/qris activity
 | 
				
			||||||
 | 
					                    Intent paymentIntent = new Intent(this, QrisActivity.class);
 | 
				
			||||||
 | 
					                    paymentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
 | 
				
			||||||
 | 
					                    startActivity(paymentIntent);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                    // Default: use system back navigation
 | 
				
			||||||
 | 
					                    super.onBackPressed();
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            // No calling activity specified, use system back navigation
 | 
				
			||||||
 | 
					            super.onBackPressed();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        finish();
 | 
					        finish();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void navigateToHomePage() {
 | 
					    private void navigateToHomePage() {
 | 
				
			||||||
        // Navigate to MainActivity/Home Page when "Selesai" button is pressed
 | 
					        // Navigate to MainActivity/Home Page
 | 
				
			||||||
        Intent intent = new Intent(this, MainActivity.class);
 | 
					        Intent intent = new Intent(this, MainActivity.class);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Clear all previous activities from the stack and start fresh
 | 
					        // Clear all previous activities from the stack and start fresh
 | 
				
			||||||
@ -202,7 +408,7 @@ public class ReceiptActivity extends AppCompatActivity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onBackPressed() {
 | 
					    public void onBackPressed() {
 | 
				
			||||||
        // Back button behavior - goes back to previous activity
 | 
					        // Use the smart back navigation
 | 
				
			||||||
        navigateBackToPrevious();
 | 
					        handleBackNavigation();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -11,6 +11,7 @@ import android.widget.ImageButton;
 | 
				
			|||||||
import android.widget.ProgressBar;
 | 
					import android.widget.ProgressBar;
 | 
				
			||||||
import android.widget.Toast;
 | 
					import android.widget.Toast;
 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import androidx.annotation.Nullable;
 | 
					import androidx.annotation.Nullable;
 | 
				
			||||||
import androidx.appcompat.app.AppCompatActivity;
 | 
					import androidx.appcompat.app.AppCompatActivity;
 | 
				
			||||||
@ -291,21 +292,126 @@ public class TransactionActivity extends AppCompatActivity implements Transactio
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onPrintClick(Transaction transaction) {
 | 
					    public void onPrintClick(Transaction transaction) {
 | 
				
			||||||
        // Buka ReceiptActivity dengan data transaksi
 | 
					        // Open ReceiptActivity with transaction data
 | 
				
			||||||
        Intent intent = new Intent(this, ReceiptActivity.class);
 | 
					        Intent intent = new Intent(this, ReceiptActivity.class);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // Format data sesuai kebutuhan ReceiptActivity
 | 
					        // Add calling activity information for proper back navigation
 | 
				
			||||||
 | 
					        intent.putExtra("calling_activity", "TransactionActivity");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // FIXED: Extract and send raw amount properly
 | 
				
			||||||
 | 
					        String rawAmount = extractRawAmount(transaction.amount);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("TransactionActivity", "Opening receipt for transaction: " + transaction.referenceId + 
 | 
				
			||||||
 | 
					            ", original amount: '" + transaction.amount + "', extracted: '" + rawAmount + "'");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Send transaction data to ReceiptActivity
 | 
				
			||||||
        intent.putExtra("transaction_id", transaction.referenceId);
 | 
					        intent.putExtra("transaction_id", transaction.referenceId);
 | 
				
			||||||
        intent.putExtra("transaction_amount", transaction.amount.replace("Rp. ", "").replace(".", ""));
 | 
					        intent.putExtra("reference_id", transaction.referenceId);
 | 
				
			||||||
        intent.putExtra("transaction_date", formatDate(transaction.createdAt)); // Format tanggal jika perlu
 | 
					        intent.putExtra("transaction_amount", rawAmount); // Send raw amount
 | 
				
			||||||
        intent.putExtra("payment_method", "Kartu " + transaction.channelCode); // Contoh: "Kartu BCA"
 | 
					        intent.putExtra("gross_amount", rawAmount); // Consistent with transaction_amount
 | 
				
			||||||
 | 
					        intent.putExtra("transaction_date", formatDate(transaction.createdAt));
 | 
				
			||||||
 | 
					        intent.putExtra("payment_method", getPaymentMethodName(transaction.channelCode, transaction.channelCategory));
 | 
				
			||||||
        intent.putExtra("card_type", transaction.channelCategory);
 | 
					        intent.putExtra("card_type", transaction.channelCategory);
 | 
				
			||||||
 | 
					        intent.putExtra("channel_code", transaction.channelCode);
 | 
				
			||||||
 | 
					        intent.putExtra("channel_category", transaction.channelCategory);
 | 
				
			||||||
        intent.putExtra("merchant_name", transaction.merchantName);
 | 
					        intent.putExtra("merchant_name", transaction.merchantName);
 | 
				
			||||||
        intent.putExtra("merchant_location", "Lokasi Merchant"); // Tambahkan jika ada di data
 | 
					        intent.putExtra("merchant_location", "Jakarta, Indonesia");
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        startActivity(intent);
 | 
					        startActivity(intent);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * FIXED: Extract raw amount from formatted string properly
 | 
				
			||||||
 | 
					     * Handles various amount formats from backend
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String extractRawAmount(String formattedAmount) {
 | 
				
			||||||
 | 
					        if (formattedAmount == null || formattedAmount.isEmpty()) {
 | 
				
			||||||
 | 
					            return "0";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("TransactionActivity", "Extracting raw amount from: '" + formattedAmount + "'");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove currency symbols and spaces
 | 
				
			||||||
 | 
					        String cleaned = formattedAmount
 | 
				
			||||||
 | 
					                .replace("Rp. ", "")
 | 
				
			||||||
 | 
					                .replace("Rp ", "")
 | 
				
			||||||
 | 
					                .replace("IDR ", "")
 | 
				
			||||||
 | 
					                .replace(" ", "")
 | 
				
			||||||
 | 
					                .trim();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Handle dots correctly
 | 
				
			||||||
 | 
					        if (cleaned.contains(".")) {
 | 
				
			||||||
 | 
					            String[] parts = cleaned.split("\\.");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            if (parts.length == 2) {
 | 
				
			||||||
 | 
					                String beforeDot = parts[0];
 | 
				
			||||||
 | 
					                String afterDot = parts[1];
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // If after dot is "00" or single "0", it's decimal format
 | 
				
			||||||
 | 
					                if (afterDot.equals("00") || afterDot.equals("0")) {
 | 
				
			||||||
 | 
					                    cleaned = beforeDot;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // If after dot has 3 digits, it's thousand separator
 | 
				
			||||||
 | 
					                else if (afterDot.length() == 3) {
 | 
				
			||||||
 | 
					                    cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // Handle other cases based on context
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    // If beforeDot is 1-3 digits and afterDot is 3 digits, likely thousand separator
 | 
				
			||||||
 | 
					                    if (beforeDot.length() <= 3 && afterDot.length() == 3) {
 | 
				
			||||||
 | 
					                        cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        // Otherwise treat as decimal and remove decimal part
 | 
				
			||||||
 | 
					                        cleaned = beforeDot;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else if (parts.length > 2) {
 | 
				
			||||||
 | 
					                // Multiple dots - treat as thousand separators
 | 
				
			||||||
 | 
					                cleaned = String.join("", parts);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove any remaining commas
 | 
				
			||||||
 | 
					        cleaned = cleaned.replace(",", "");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Validate result is numeric
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            Long.parseLong(cleaned);
 | 
				
			||||||
 | 
					            Log.d("TransactionActivity", "Successfully extracted: '" + formattedAmount + "' -> '" + cleaned + "'");
 | 
				
			||||||
 | 
					            return cleaned;
 | 
				
			||||||
 | 
					        } catch (NumberFormatException e) {
 | 
				
			||||||
 | 
					            Log.e("TransactionActivity", "Invalid amount after cleaning: '" + cleaned + "' from '" + formattedAmount + "'");
 | 
				
			||||||
 | 
					            return "0";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String getPaymentMethodName(String channelCode, String channelCategory) {
 | 
				
			||||||
 | 
					        if (channelCode == null) return "Unknown";
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        switch (channelCode.toUpperCase()) {
 | 
				
			||||||
 | 
					            case "QRIS":
 | 
				
			||||||
 | 
					                return "QRIS";
 | 
				
			||||||
 | 
					            case "DEBIT":
 | 
				
			||||||
 | 
					                return "Kartu Debit";
 | 
				
			||||||
 | 
					            case "CREDIT":
 | 
				
			||||||
 | 
					                return "Kartu Kredit";
 | 
				
			||||||
 | 
					            case "BCA":
 | 
				
			||||||
 | 
					            case "MANDIRI":
 | 
				
			||||||
 | 
					            case "BNI":
 | 
				
			||||||
 | 
					            case "BRI":
 | 
				
			||||||
 | 
					                return "Kartu " + channelCode.toUpperCase();
 | 
				
			||||||
 | 
					            case "CASH":
 | 
				
			||||||
 | 
					                return "Tunai";
 | 
				
			||||||
 | 
					            case "EDC":
 | 
				
			||||||
 | 
					                return "EDC";
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                if (channelCategory != null && !channelCategory.isEmpty()) {
 | 
				
			||||||
 | 
					                    return channelCategory.toUpperCase();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return channelCode.toUpperCase();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private String formatDate(String rawDate) {
 | 
					    private String formatDate(String rawDate) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
 | 
					            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.example.bdkipoc;
 | 
					package com.example.bdkipoc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.util.Log; // ADD THIS IMPORT
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
import android.view.ViewGroup;
 | 
					import android.view.ViewGroup;
 | 
				
			||||||
@ -46,11 +47,22 @@ public class TransactionAdapter extends RecyclerView.Adapter<TransactionAdapter.
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        // Format the amount as Indonesian Rupiah
 | 
					        // Format the amount as Indonesian Rupiah
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            double amountValue = Double.parseDouble(t.amount);
 | 
					            // Clean and format amount
 | 
				
			||||||
            NumberFormat rupiahFormat = NumberFormat.getInstance(new Locale("id", "ID"));
 | 
					            String cleanAmount = cleanAmountString(t.amount);
 | 
				
			||||||
            holder.amount.setText("Rp. " + rupiahFormat.format(amountValue));
 | 
					            long amountValue = Long.parseLong(cleanAmount);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Format using Indonesian formatting (dots as thousand separators)
 | 
				
			||||||
 | 
					            String formattedAmount = formatRupiah(amountValue);
 | 
				
			||||||
 | 
					            holder.amount.setText(formattedAmount);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            Log.d("TransactionAdapter", "Original: '" + t.amount + "' -> Cleaned: '" + 
 | 
				
			||||||
 | 
					                cleanAmount + "' -> Formatted: '" + formattedAmount + "'");
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
        } catch (NumberFormatException e) {
 | 
					        } catch (NumberFormatException e) {
 | 
				
			||||||
            holder.amount.setText("Rp. " + t.amount);
 | 
					            Log.e("TransactionAdapter", "Error formatting amount: " + t.amount, e);
 | 
				
			||||||
 | 
					            // Fallback: show original amount with Rp prefix if not already present
 | 
				
			||||||
 | 
					            String fallback = t.amount.startsWith("Rp") ? t.amount : "Rp " + t.amount;
 | 
				
			||||||
 | 
					            holder.amount.setText(fallback);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set status with appropriate color
 | 
					        // Set status with appropriate color
 | 
				
			||||||
@ -61,13 +73,13 @@ public class TransactionAdapter extends RecyclerView.Adapter<TransactionAdapter.
 | 
				
			|||||||
        String paymentMethod = getPaymentMethodName(t.channelCode, t.channelCategory);
 | 
					        String paymentMethod = getPaymentMethodName(t.channelCode, t.channelCategory);
 | 
				
			||||||
        holder.paymentMethod.setText(paymentMethod);
 | 
					        holder.paymentMethod.setText(paymentMethod);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Set click listeners
 | 
				
			||||||
        holder.itemView.setOnClickListener(v -> {
 | 
					        holder.itemView.setOnClickListener(v -> {
 | 
				
			||||||
            if (printClickListener != null) {
 | 
					            if (printClickListener != null) {
 | 
				
			||||||
                printClickListener.onPrintClick(t);
 | 
					                printClickListener.onPrintClick(t);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set click listener for print button
 | 
					 | 
				
			||||||
        holder.printSection.setOnClickListener(v -> {
 | 
					        holder.printSection.setOnClickListener(v -> {
 | 
				
			||||||
            if (printClickListener != null) {
 | 
					            if (printClickListener != null) {
 | 
				
			||||||
                printClickListener.onPrintClick(t);
 | 
					                printClickListener.onPrintClick(t);
 | 
				
			||||||
@ -75,6 +87,71 @@ public class TransactionAdapter extends RecyclerView.Adapter<TransactionAdapter.
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * FIXED: Clean amount string to extract raw number correctly
 | 
				
			||||||
 | 
					     * Handles various input formats properly
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String cleanAmountString(String amount) {
 | 
				
			||||||
 | 
					        if (amount == null || amount.isEmpty()) {
 | 
				
			||||||
 | 
					            return "0";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("TransactionAdapter", "Cleaning amount: '" + amount + "'");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove currency symbols and spaces
 | 
				
			||||||
 | 
					        String cleaned = amount
 | 
				
			||||||
 | 
					                .replace("Rp. ", "")
 | 
				
			||||||
 | 
					                .replace("Rp ", "")
 | 
				
			||||||
 | 
					                .replace("IDR ", "")
 | 
				
			||||||
 | 
					                .replace(" ", "")
 | 
				
			||||||
 | 
					                .trim();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Handle dots properly
 | 
				
			||||||
 | 
					        if (cleaned.contains(".")) {
 | 
				
			||||||
 | 
					            // Split by dots
 | 
				
			||||||
 | 
					            String[] parts = cleaned.split("\\.");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            if (parts.length == 2) {
 | 
				
			||||||
 | 
					                String beforeDot = parts[0];
 | 
				
			||||||
 | 
					                String afterDot = parts[1];
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Check if it's decimal format (like "1000.00") or thousand separator (like "1.000")
 | 
				
			||||||
 | 
					                if (afterDot.length() <= 2 && (afterDot.equals("00") || afterDot.equals("0"))) {
 | 
				
			||||||
 | 
					                    // It's decimal format - keep only the integer part
 | 
				
			||||||
 | 
					                    cleaned = beforeDot;
 | 
				
			||||||
 | 
					                } else if (afterDot.length() == 3) {
 | 
				
			||||||
 | 
					                    // It's thousand separator format - combine parts
 | 
				
			||||||
 | 
					                    cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // Ambiguous case - assume thousand separator if beforeDot is short
 | 
				
			||||||
 | 
					                    if (beforeDot.length() <= 3) {
 | 
				
			||||||
 | 
					                        cleaned = beforeDot + afterDot;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        cleaned = beforeDot; // Assume decimal
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else if (parts.length > 2) {
 | 
				
			||||||
 | 
					                // Multiple dots - assume all are thousand separators
 | 
				
			||||||
 | 
					                cleaned = String.join("", parts);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // Remove any commas
 | 
				
			||||||
 | 
					        cleaned = cleaned.replace(",", "");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Log.d("TransactionAdapter", "Cleaned result: '" + cleaned + "'");
 | 
				
			||||||
 | 
					        return cleaned;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Format long amount to Indonesian Rupiah format
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private String formatRupiah(long amount) {
 | 
				
			||||||
 | 
					        // Use dots as thousand separators (Indonesian format)
 | 
				
			||||||
 | 
					        String formatted = String.format("%,d", amount).replace(',', '.');
 | 
				
			||||||
 | 
					        return "Rp. " + formatted;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void setStatusColor(TextView statusTextView, String status) {
 | 
					    private void setStatusColor(TextView statusTextView, String status) {
 | 
				
			||||||
        String statusLower = status.toLowerCase();
 | 
					        String statusLower = status.toLowerCase();
 | 
				
			||||||
        int color;
 | 
					        int color;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user