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