MID & TID Settlement Detail

This commit is contained in:
Rizqika 2025-08-11 13:21:14 +07:00
parent ccfd3a09eb
commit ad08e80ae0

View File

@ -9,7 +9,6 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.content.Intent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -30,6 +29,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import com.example.bdkipoc.BuildConfig; import com.example.bdkipoc.BuildConfig;
import com.example.bdkipoc.LoginActivity;
import com.example.bdkipoc.R; import com.example.bdkipoc.R;
public class SettlementDetailActivity extends AppCompatActivity { public class SettlementDetailActivity extends AppCompatActivity {
@ -44,35 +44,44 @@ public class SettlementDetailActivity extends AppCompatActivity {
private Button btnSendSettlement; private Button btnSendSettlement;
// Summary totals // Summary totals
private long totalMasuk = 0; private long totalMasuk = 0; // Set to 0
private long totalKeluar = 0; private long totalKeluar = 0;
private long biayaAdmin = 15000; // Default admin fee private long biayaAdmin = 0; // Set to 0
private long grandTotal = 0; private long grandTotal = 0;
// User data
private JSONObject userData;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settlement_detail); setContentView(R.layout.activity_settlement_detail);
// Load user data from login session
loadUserData();
initViews(); initViews();
setupRecyclerView(); setupRecyclerView();
fetchApiData(); // Fetch from API instead of loading sample data fetchApiData();
setupClickListeners(); setupClickListeners();
updateDateTime(); updateDateTime();
} }
private void loadUserData() {
userData = LoginActivity.getUserDataAsJson(this);
}
private void fetchApiData() { private void fetchApiData() {
// Get current date in yyyy-MM-dd format (same as SettlementActivity) // Get current date in yyyy-MM-dd format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
String currentDate = sdf.format(new Date()); String currentDate = sdf.format(new Date());
// Build API URL with current date and credentials from BuildConfig // Build API URL with current date
String apiUrl = BuildConfig.BACKEND_BASE_URL + "/transactions/performa-chanel-pembayaran" + String apiUrl = BuildConfig.BACKEND_BASE_URL + "/transactions/performa-chanel-pembayaran" +
"?from_date=" + currentDate + "?from_date=" + currentDate +
"&to_date=" + currentDate + "&to_date=" + currentDate +
"&location_id=0&merchant_id=0"; "&location_id=0&merchant_id=0";
// Execute network call in background thread
new ApiTask().execute(apiUrl); new ApiTask().execute(apiUrl);
} }
@ -81,9 +90,7 @@ public class SettlementDetailActivity extends AppCompatActivity {
settlementDetailList.clear(); settlementDetailList.clear();
long totalAmount = 0; long totalAmount = 0;
int totalTransactions = 0;
// Process each channel from API data
for (int i = 0; i < dataArray.length(); i++) { for (int i = 0; i < dataArray.length(); i++) {
JSONObject item = dataArray.getJSONObject(i); JSONObject item = dataArray.getJSONObject(i);
@ -91,7 +98,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
int transactions = item.getInt("total_transactions"); int transactions = item.getInt("total_transactions");
long maxAmount = item.getLong("max_transastions"); long maxAmount = item.getLong("max_transastions");
// Use channel code with formatting
String displayName = formatChannelName(channelCode); String displayName = formatChannelName(channelCode);
settlementDetailList.add(new SettlementDetailItem( settlementDetailList.add(new SettlementDetailItem(
@ -101,13 +107,10 @@ public class SettlementDetailActivity extends AppCompatActivity {
)); ));
totalAmount += maxAmount; totalAmount += maxAmount;
totalTransactions += transactions;
} }
// Calculate totals based on API data calculateTotalsFromApiData(totalAmount);
calculateTotalsFromApiData(totalAmount, totalTransactions);
// Update UI on main thread
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -122,95 +125,60 @@ public class SettlementDetailActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
Toast.makeText(SettlementDetailActivity.this, "Error parsing data", Toast.LENGTH_SHORT).show(); Toast.makeText(SettlementDetailActivity.this, "Error parsing data", Toast.LENGTH_SHORT).show();
loadSampleData(); // Fallback to sample data loadSampleData();
} }
}); });
} }
} }
private void calculateTotalsFromApiData(long totalAmount, int totalTransactions) { private void calculateTotalsFromApiData(long totalAmount) {
// Calculate totals based on actual API data totalMasuk = 0; // Set to 0 temporarily
// You can adjust this logic based on your business requirements totalKeluar = totalAmount;
biayaAdmin = 0; // Set to 0 temporarily
// For example, split transactions into incoming/outgoing based on transaction type
// This is a simplified calculation - adjust according to your actual data structure
totalKeluar = totalAmount; // All transactions as outgoing for now
totalMasuk = (long) (totalAmount * 0.3); // 30% as incoming (adjust as needed)
biayaAdmin = 15000; // Fixed admin fee
// Calculate grand total
grandTotal = totalKeluar - totalMasuk - biayaAdmin; grandTotal = totalKeluar - totalMasuk - biayaAdmin;
if (grandTotal < 0) {
grandTotal = totalAmount - biayaAdmin; // Fallback calculation
}
} }
private String formatChannelName(String channelCode) { private String formatChannelName(String channelCode) {
// Format channel code to be more readable (same as SettlementActivity)
switch (channelCode) { switch (channelCode) {
case "GO-PAY": case "GO-PAY": return "GoPay";
return "GoPay"; case "SHOPEEPAY": return "ShopeePay";
case "SHOPEEPAY": case "LINKAJA": return "LinkAja";
return "ShopeePay"; case "MASTERCARD": return "Mastercard";
case "LINKAJA": case "VISA": return "Visa";
return "LinkAja"; case "QRIS": return "QRIS";
case "MASTERCARD": case "DANA": return "Dana";
return "Mastercard"; case "OVO": return "OVO";
case "VISA": case "DEBIT": return "Kartu Debit";
return "Visa"; case "GPN": return "GPN";
case "QRIS": case "OTHER": return "Lainnya";
return "QRIS"; case "CREDIT": return "Kartu Kredit";
case "DANA": case "TRANSFER": return "Transfer";
return "Dana"; case "E_MONEY": return "Uang Elektronik";
case "OVO": case "CASH_DEPOSIT": return "Setoran Tunai";
return "OVO"; case "BILL_PAYMENT": return "Pembayaran Tagihan";
case "DEBIT": case "CASH_WITHDRAWAL": return "Penarikan Tunai";
return "Kartu Debit"; case "TOP_UP": return "Top-up Saldo";
case "GPN": case "REFUND": return "Refund (void)";
return "GPN";
case "OTHER":
return "Lainnya";
case "CREDIT":
return "Kartu Kredit";
case "TRANSFER":
return "Transfer";
case "E_MONEY":
return "Uang Elektronik";
case "CASH_DEPOSIT":
return "Setoran Tunai";
case "BILL_PAYMENT":
return "Pembayaran Tagihan";
case "CASH_WITHDRAWAL":
return "Penarikan Tunai";
case "TOP_UP":
return "Top-up Saldo";
case "REFUND":
return "Refund (void)";
default: default:
// Capitalize first letter and make rest lowercase
return channelCode.substring(0, 1).toUpperCase() + return channelCode.substring(0, 1).toUpperCase() +
channelCode.substring(1).toLowerCase(); channelCode.substring(1).toLowerCase();
} }
} }
private void initViews() { private void initViews() {
// Store info
tvStoreName = findViewById(R.id.tv_store_name); tvStoreName = findViewById(R.id.tv_store_name);
tvStoreLocation = findViewById(R.id.tv_store_location); tvStoreLocation = findViewById(R.id.tv_store_location);
tvMid = findViewById(R.id.tv_mid); tvMid = findViewById(R.id.tv_mid);
tvTid = findViewById(R.id.tv_tid); tvTid = findViewById(R.id.tv_tid);
// Date and time
tvSettlementDate = findViewById(R.id.tv_settlement_date); tvSettlementDate = findViewById(R.id.tv_settlement_date);
tvSettlementTime = findViewById(R.id.tv_settlement_time); tvSettlementTime = findViewById(R.id.tv_settlement_time);
// Summary totals
tvTotalMasuk = findViewById(R.id.tv_total_masuk); tvTotalMasuk = findViewById(R.id.tv_total_masuk);
tvTotalKeluar = findViewById(R.id.tv_total_keluar); tvTotalKeluar = findViewById(R.id.tv_total_keluar);
tvBiayaAdmin = findViewById(R.id.tv_biaya_admin); tvBiayaAdmin = findViewById(R.id.tv_biaya_admin);
tvGrandTotal = findViewById(R.id.tv_grand_total); tvGrandTotal = findViewById(R.id.tv_grand_total);
// RecyclerView and navigation
recyclerView = findViewById(R.id.recycler_settlement_details); recyclerView = findViewById(R.id.recycler_settlement_details);
backNavigation = findViewById(R.id.back_navigation); backNavigation = findViewById(R.id.back_navigation);
btnSendSettlement = findViewById(R.id.btn_send_settlement); btnSendSettlement = findViewById(R.id.btn_send_settlement);
@ -225,7 +193,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
} }
private void loadSampleData() { private void loadSampleData() {
// Sample data as fallback (same structure as API data would provide)
settlementDetailList.clear(); settlementDetailList.clear();
settlementDetailList.add(new SettlementDetailItem("Kartu Kredit", 200000, 14)); settlementDetailList.add(new SettlementDetailItem("Kartu Kredit", 200000, 14));
@ -239,11 +206,10 @@ public class SettlementDetailActivity extends AppCompatActivity {
settlementDetailList.add(new SettlementDetailItem("Top-up Saldo", 200000, 14)); settlementDetailList.add(new SettlementDetailItem("Top-up Saldo", 200000, 14));
settlementDetailList.add(new SettlementDetailItem("Refund (void)", 200000, 14)); settlementDetailList.add(new SettlementDetailItem("Refund (void)", 200000, 14));
// Calculate sample totals totalMasuk = 0; // Set to 0 temporarily
totalMasuk = 1800000; totalKeluar = 2000000; // Total from sample data
totalKeluar = 5800000; biayaAdmin = 0; // Set to 0 temporarily
biayaAdmin = 15000; grandTotal = totalKeluar - totalMasuk - biayaAdmin;
grandTotal = 3506500;
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateSummary(); updateSummary();
@ -257,7 +223,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
} }
private void updateDateTime() { private void updateDateTime() {
// Set current date and time
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", new Locale("id", "ID")); SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", new Locale("id", "ID"));
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
@ -265,11 +230,24 @@ public class SettlementDetailActivity extends AppCompatActivity {
tvSettlementDate.setText(dateFormat.format(now)); tvSettlementDate.setText(dateFormat.format(now));
tvSettlementTime.setText(timeFormat.format(now)); tvSettlementTime.setText(timeFormat.format(now));
// Set store info (these could come from SharedPreferences or API) // Set store info from user data
tvStoreName.setText("TOKO KLONTONG PAK EKO"); if (userData != null) {
tvStoreLocation.setText("Ciputat Baru, Tangsel"); String storeName = userData.optString("store_name", "TOKO KLONTONG PAK EKO");
tvMid.setText("12345678901"); String storeAddress = userData.optString("store_address", "Ciputat Baru, Tangsel");
tvTid.setText("12345678901"); String mid = userData.optString("mid", "12345678901");
String tid = userData.optString("tid", "12345678901");
tvStoreName.setText(storeName);
tvStoreLocation.setText(storeAddress);
tvMid.setText(mid);
tvTid.setText(tid);
} else {
// Fallback to default values
tvStoreName.setText("TOKO KLONTONG PAK EKO");
tvStoreLocation.setText("Ciputat Baru, Tangsel");
tvMid.setText("12345678901");
tvTid.setText("12345678901");
}
} }
private void setupClickListeners() { private void setupClickListeners() {
@ -289,16 +267,11 @@ public class SettlementDetailActivity extends AppCompatActivity {
} }
private void sendSettlement() { private void sendSettlement() {
// Show loading or confirmation dialog
Toast.makeText(this, "Mengirim settlement...", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Mengirim settlement...", Toast.LENGTH_SHORT).show();
// TODO: Implement actual settlement sending logic // TODO: Implement actual settlement sending logic
// This could involve API call to send settlement data
// For now, just show success message
Toast.makeText(this, "Settlement berhasil dikirim!", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Settlement berhasil dikirim!", Toast.LENGTH_LONG).show();
// Optionally close the activity or navigate back
finish(); finish();
} }
@ -307,7 +280,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
return formatter.format(amount); return formatter.format(amount);
} }
// AsyncTask for API call (same as SettlementActivity)
private class ApiTask extends AsyncTask<String, Void, String> { private class ApiTask extends AsyncTask<String, Void, String> {
@Override @Override
protected String doInBackground(String... urls) { protected String doInBackground(String... urls) {
@ -318,9 +290,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.setReadTimeout(5000); connection.setReadTimeout(5000);
// Add authorization header if needed
// connection.setRequestProperty("Authorization", BuildConfig.MIDTRANS_SANDBOX_AUTH);
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
@ -364,7 +333,6 @@ public class SettlementDetailActivity extends AppCompatActivity {
} }
} }
// SettlementDetailItem class
class SettlementDetailItem { class SettlementDetailItem {
private String paymentMethod; private String paymentMethod;
private long totalNominal; private long totalNominal;
@ -376,18 +344,15 @@ class SettlementDetailItem {
this.jumlahTransaksi = jumlahTransaksi; this.jumlahTransaksi = jumlahTransaksi;
} }
// Getters
public String getPaymentMethod() { return paymentMethod; } public String getPaymentMethod() { return paymentMethod; }
public long getTotalNominal() { return totalNominal; } public long getTotalNominal() { return totalNominal; }
public int getJumlahTransaksi() { return jumlahTransaksi; } public int getJumlahTransaksi() { return jumlahTransaksi; }
// Setters
public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; } public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; }
public void setTotalNominal(long totalNominal) { this.totalNominal = totalNominal; } public void setTotalNominal(long totalNominal) { this.totalNominal = totalNominal; }
public void setJumlahTransaksi(int jumlahTransaksi) { this.jumlahTransaksi = jumlahTransaksi; } public void setJumlahTransaksi(int jumlahTransaksi) { this.jumlahTransaksi = jumlahTransaksi; }
} }
// SettlementDetailAdapter class
class SettlementDetailAdapter extends RecyclerView.Adapter<SettlementDetailAdapter.SettlementDetailViewHolder> { class SettlementDetailAdapter extends RecyclerView.Adapter<SettlementDetailAdapter.SettlementDetailViewHolder> {
private List<SettlementDetailItem> settlementDetailList; private List<SettlementDetailItem> settlementDetailList;