semua fitur selesai
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_akun_bank_controller.dart';
|
||||
import '../../../data/providers/aset_provider.dart';
|
||||
|
||||
class PetugasAkunBankBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
// Register AsetProvider if not already registered
|
||||
if (!Get.isRegistered<AsetProvider>()) {
|
||||
Get.put(AsetProvider(), permanent: true);
|
||||
}
|
||||
|
||||
// Register PetugasAkunBankController
|
||||
Get.lazyPut<PetugasAkunBankController>(() => PetugasAkunBankController());
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_detail_penyewa_controller.dart';
|
||||
|
||||
class PetugasDetailPenyewaBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<PetugasDetailPenyewaController>(
|
||||
() => PetugasDetailPenyewaController(),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_laporan_controller.dart';
|
||||
import '../../../data/providers/aset_provider.dart';
|
||||
|
||||
class PetugasLaporanBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
// Register AsetProvider if not already registered
|
||||
if (!Get.isRegistered<AsetProvider>()) {
|
||||
Get.put(AsetProvider(), permanent: true);
|
||||
}
|
||||
|
||||
// Register PetugasLaporanController
|
||||
Get.lazyPut<PetugasLaporanController>(() => PetugasLaporanController());
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_penyewa_controller.dart';
|
||||
|
||||
class PetugasPenyewaBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.put<PetugasPenyewaController>(
|
||||
PetugasPenyewaController(),
|
||||
permanent: true,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../data/providers/aset_provider.dart';
|
||||
|
||||
class PetugasAkunBankController extends GetxController {
|
||||
final AsetProvider asetProvider = Get.find<AsetProvider>();
|
||||
|
||||
// Observable variables
|
||||
final isLoading = true.obs;
|
||||
final bankAccounts = <Map<String, dynamic>>[].obs;
|
||||
final errorMessage = ''.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadBankAccounts();
|
||||
}
|
||||
|
||||
// Load bank accounts from the database
|
||||
Future<void> loadBankAccounts() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
errorMessage.value = '';
|
||||
|
||||
debugPrint('🏦 Loading bank accounts...');
|
||||
|
||||
// Fetch all bank accounts from the database
|
||||
final response = await asetProvider.client
|
||||
.from('akun_bank')
|
||||
.select('id, nama_bank, nama_akun, no_rekening')
|
||||
.order('nama_bank', ascending: true);
|
||||
|
||||
if (response is List) {
|
||||
bankAccounts.value = List<Map<String, dynamic>>.from(response);
|
||||
debugPrint('✅ Loaded ${bankAccounts.length} bank accounts');
|
||||
} else {
|
||||
bankAccounts.value = [];
|
||||
errorMessage.value = 'Failed to load bank accounts';
|
||||
debugPrint('❌ Failed to load bank accounts: Invalid response format');
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessage.value = 'Error loading bank accounts: $e';
|
||||
debugPrint('❌ Error loading bank accounts: $e');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a new bank account
|
||||
Future<bool> addBankAccount(Map<String, dynamic> accountData) async {
|
||||
try {
|
||||
debugPrint('🏦 Adding new bank account: ${accountData['nama_bank']}');
|
||||
|
||||
final response = await asetProvider.client
|
||||
.from('akun_bank')
|
||||
.insert(accountData)
|
||||
.select('id');
|
||||
|
||||
if (response is List && response.isNotEmpty) {
|
||||
debugPrint('✅ Bank account added successfully');
|
||||
await loadBankAccounts(); // Reload the list
|
||||
return true;
|
||||
} else {
|
||||
debugPrint('❌ Failed to add bank account: No response');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ Error adding bank account: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update an existing bank account
|
||||
Future<bool> updateBankAccount(
|
||||
String id,
|
||||
Map<String, dynamic> accountData,
|
||||
) async {
|
||||
try {
|
||||
debugPrint('🏦 Updating bank account ID: $id');
|
||||
|
||||
final response = await asetProvider.client
|
||||
.from('akun_bank')
|
||||
.update(accountData)
|
||||
.eq('id', id);
|
||||
|
||||
debugPrint('✅ Bank account updated successfully');
|
||||
await loadBankAccounts(); // Reload the list
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint('❌ Error updating bank account: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a bank account
|
||||
Future<bool> deleteBankAccount(String id) async {
|
||||
try {
|
||||
debugPrint('🏦 Deleting bank account ID: $id');
|
||||
|
||||
final response = await asetProvider.client
|
||||
.from('akun_bank')
|
||||
.delete()
|
||||
.eq('id', id);
|
||||
|
||||
debugPrint('✅ Bank account deleted successfully');
|
||||
await loadBankAccounts(); // Reload the list
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint('❌ Error deleting bank account: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -222,8 +222,63 @@ class PetugasAsetController extends GetxController {
|
||||
}
|
||||
|
||||
// Delete an asset
|
||||
void deleteAset(String id) {
|
||||
asetList.removeWhere((aset) => aset['id'] == id);
|
||||
applyFilters();
|
||||
Future<bool> deleteAset(String id) async {
|
||||
try {
|
||||
debugPrint('🗑️ Starting deletion process for asset ID: $id');
|
||||
|
||||
// Show loading indicator
|
||||
Get.dialog(
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
|
||||
// Call the provider to delete the asset
|
||||
final success = await _asetProvider.deleteAset(id);
|
||||
|
||||
// Close the loading dialog
|
||||
Get.back();
|
||||
|
||||
if (success) {
|
||||
// Remove the asset from our local list
|
||||
asetList.removeWhere((aset) => aset['id'] == id);
|
||||
// Apply filters to update the UI
|
||||
applyFilters();
|
||||
|
||||
// Show success message
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Aset berhasil dihapus',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
// Show error message
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat menghapus aset',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
// Close the loading dialog if still open
|
||||
if (Get.isDialogOpen ?? false) {
|
||||
Get.back();
|
||||
}
|
||||
|
||||
// Show error message
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal menghapus aset: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import '../../../services/sewa_service.dart';
|
||||
import '../../../services/service_manager.dart';
|
||||
import '../../../data/models/pembayaran_model.dart';
|
||||
import '../../../services/pembayaran_service.dart';
|
||||
import '../../../data/providers/aset_provider.dart';
|
||||
import '../../../data/providers/pesanan_provider.dart';
|
||||
|
||||
class PetugasBumdesDashboardController extends GetxController {
|
||||
AuthProvider? _authProvider;
|
||||
@ -16,38 +18,45 @@ class PetugasBumdesDashboardController extends GetxController {
|
||||
final userName = ''.obs;
|
||||
|
||||
// Revenue Statistics
|
||||
final totalPendapatanBulanIni = 'Rp 8.500.000'.obs;
|
||||
final totalPendapatanBulanLalu = 'Rp 7.200.000'.obs;
|
||||
final persentaseKenaikan = '18%'.obs;
|
||||
final totalPendapatanBulanIni = ''.obs;
|
||||
final totalPendapatanBulanLalu = ''.obs;
|
||||
final persentaseKenaikan = ''.obs;
|
||||
final isKenaikanPositif = true.obs;
|
||||
|
||||
// Revenue by Category
|
||||
final pendapatanSewa = 'Rp 5.200.000'.obs;
|
||||
final persentaseSewa = 100.obs;
|
||||
final pendapatanSewa = ''.obs;
|
||||
final persentaseSewa = 0.obs;
|
||||
|
||||
// Revenue Trends (last 6 months)
|
||||
final trendPendapatan = <double>[].obs; // 6 bulan terakhir
|
||||
|
||||
// Status Counters for Sewa Aset
|
||||
final terlaksanaCount = 5.obs;
|
||||
final dijadwalkanCount = 1.obs;
|
||||
final aktifCount = 1.obs;
|
||||
final dibatalkanCount = 3.obs;
|
||||
final terlaksanaCount = 0.obs;
|
||||
final dijadwalkanCount = 0.obs;
|
||||
final aktifCount = 0.obs;
|
||||
final dibatalkanCount = 0.obs;
|
||||
|
||||
// Additional Sewa Aset Status Counters
|
||||
final menungguPembayaranCount = 2.obs;
|
||||
final periksaPembayaranCount = 1.obs;
|
||||
final diterimaCount = 3.obs;
|
||||
final pembayaranDendaCount = 1.obs;
|
||||
final menungguPembayaranCount = 0.obs;
|
||||
final periksaPembayaranCount = 0.obs;
|
||||
final diterimaCount = 0.obs;
|
||||
final pembayaranDendaCount = 0.obs;
|
||||
final periksaPembayaranDendaCount = 0.obs;
|
||||
final selesaiCount = 4.obs;
|
||||
final selesaiCount = 0.obs;
|
||||
|
||||
// Status counts for Sewa
|
||||
final pengajuanSewaCount = 5.obs;
|
||||
final pemasanganCountSewa = 3.obs;
|
||||
final sewaAktifCount = 10.obs;
|
||||
final tagihanAktifCountSewa = 7.obs;
|
||||
final periksaPembayaranCountSewa = 2.obs;
|
||||
final pengajuanSewaCount = 0.obs;
|
||||
final pemasanganCountSewa = 0.obs;
|
||||
final sewaAktifCount = 0.obs;
|
||||
final tagihanAktifCountSewa = 0.obs;
|
||||
final periksaPembayaranCountSewa = 0.obs;
|
||||
|
||||
// Tenant (Penyewa) Statistics
|
||||
final penyewaPendingCount = 0.obs;
|
||||
final penyewaActiveCount = 0.obs;
|
||||
final penyewaSuspendedCount = 0.obs;
|
||||
final penyewaTotalCount = 0.obs;
|
||||
final isPenyewaStatsLoading = true.obs;
|
||||
|
||||
// Statistik pendapatan
|
||||
final totalPendapatan = 0.obs;
|
||||
@ -76,6 +85,7 @@ class PetugasBumdesDashboardController extends GetxController {
|
||||
print('\u2705 PetugasBumdesDashboardController initialized successfully');
|
||||
countSewaByStatus();
|
||||
fetchPembayaranStats();
|
||||
fetchPenyewaStats();
|
||||
}
|
||||
|
||||
Future<void> countSewaByStatus() async {
|
||||
@ -172,6 +182,55 @@ class PetugasBumdesDashboardController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchPenyewaStats() async {
|
||||
isPenyewaStatsLoading.value = true;
|
||||
try {
|
||||
if (_authProvider == null || _authProvider!.client == null) {
|
||||
print('Auth provider or client is null');
|
||||
return;
|
||||
}
|
||||
|
||||
final data = await _authProvider!.client
|
||||
.from('warga_desa')
|
||||
.select('status, user_id')
|
||||
.not('user_id', 'is', null);
|
||||
|
||||
if (data != null) {
|
||||
final List<dynamic> penyewaList = data as List<dynamic>;
|
||||
|
||||
// Count penyewa by status
|
||||
penyewaPendingCount.value =
|
||||
penyewaList
|
||||
.where(
|
||||
(p) => p['status']?.toString().toLowerCase() == 'pending',
|
||||
)
|
||||
.length;
|
||||
|
||||
penyewaActiveCount.value =
|
||||
penyewaList
|
||||
.where((p) => p['status']?.toString().toLowerCase() == 'active')
|
||||
.length;
|
||||
|
||||
penyewaSuspendedCount.value =
|
||||
penyewaList
|
||||
.where(
|
||||
(p) => p['status']?.toString().toLowerCase() == 'suspended',
|
||||
)
|
||||
.length;
|
||||
|
||||
penyewaTotalCount.value = penyewaList.length;
|
||||
|
||||
print(
|
||||
'Penyewa stats - Pending: ${penyewaPendingCount.value}, Active: ${penyewaActiveCount.value}, Suspended: ${penyewaSuspendedCount.value}, Total: ${penyewaTotalCount.value}',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching penyewa stats: $e');
|
||||
} finally {
|
||||
isPenyewaStatsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void changeTab(int index) {
|
||||
try {
|
||||
currentTabIndex.value = index;
|
||||
@ -194,6 +253,10 @@ class PetugasBumdesDashboardController extends GetxController {
|
||||
// Navigate to Sewa page
|
||||
navigateToSewa();
|
||||
break;
|
||||
case 4:
|
||||
// Navigate to Penyewa page
|
||||
navigateToPenyewa();
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error changing tab: $e');
|
||||
@ -224,11 +287,42 @@ class PetugasBumdesDashboardController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void navigateToPenyewa() {
|
||||
try {
|
||||
Get.offAllNamed(Routes.PETUGAS_PENYEWA);
|
||||
} catch (e) {
|
||||
print('Error navigating to Penyewa: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void logout() async {
|
||||
try {
|
||||
// Clear providers data
|
||||
if (_authProvider != null) {
|
||||
// Sign out from Supabase
|
||||
await _authProvider!.signOut();
|
||||
|
||||
// Clear auth provider data
|
||||
_authProvider!.clearAuthData();
|
||||
|
||||
// Clear aset provider data
|
||||
try {
|
||||
final asetProvider = Get.find<AsetProvider>();
|
||||
asetProvider.clearCache();
|
||||
} catch (e) {
|
||||
print('Error clearing AsetProvider: $e');
|
||||
}
|
||||
|
||||
// Clear pesanan provider data
|
||||
try {
|
||||
final pesananProvider = Get.find<PesananProvider>();
|
||||
pesananProvider.clearCache();
|
||||
} catch (e) {
|
||||
print('Error clearing PesananProvider: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate to login screen
|
||||
Get.offAllNamed(Routes.LOGIN);
|
||||
} catch (e) {
|
||||
print('Error during logout: $e');
|
||||
|
@ -0,0 +1,232 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../../../data/providers/auth_provider.dart';
|
||||
|
||||
class PetugasDetailPenyewaController extends GetxController {
|
||||
final AuthProvider _authProvider = Get.find<AuthProvider>();
|
||||
|
||||
final isLoading = true.obs;
|
||||
final penyewaDetail = Rx<Map<String, dynamic>>({});
|
||||
final sewaHistory = <Map<String, dynamic>>[].obs;
|
||||
final userId = ''.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (Get.arguments != null && Get.arguments['userId'] != null) {
|
||||
userId.value = Get.arguments['userId'];
|
||||
fetchPenyewaDetail();
|
||||
fetchSewaHistory();
|
||||
} else {
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Data penyewa tidak ditemukan',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchPenyewaDetail() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
final data =
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.select('*')
|
||||
.eq('user_id', userId.value)
|
||||
.single();
|
||||
|
||||
if (data != null) {
|
||||
penyewaDetail.value = Map<String, dynamic>.from(data);
|
||||
print('Penyewa detail fetched: ${penyewaDetail.value}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching penyewa detail: $e');
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memuat data penyewa',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchSewaHistory() async {
|
||||
try {
|
||||
final data = await _authProvider.client
|
||||
.from('sewa_aset')
|
||||
.select('*')
|
||||
.eq('user_id', userId.value)
|
||||
.order('created_at', ascending: false);
|
||||
|
||||
if (data != null) {
|
||||
sewaHistory.value = List<Map<String, dynamic>>.from(data);
|
||||
print('Sewa history fetched: ${sewaHistory.length} items');
|
||||
|
||||
// Process data for each item
|
||||
for (int i = 0; i < sewaHistory.length; i++) {
|
||||
final item = sewaHistory[i];
|
||||
|
||||
// Fetch tagihan data for this sewa_aset
|
||||
try {
|
||||
final tagihanResponse =
|
||||
await _authProvider.client
|
||||
.from('tagihan_sewa')
|
||||
.select('tagihan_awal, denda, tagihan_dibayar')
|
||||
.eq('sewa_aset_id', item['id'])
|
||||
.maybeSingle();
|
||||
|
||||
if (tagihanResponse != null) {
|
||||
// Add tagihan data to the item
|
||||
sewaHistory[i] = {...item, 'tagihan_sewa': tagihanResponse};
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching tagihan for sewa_aset ${item['id']}: $e');
|
||||
}
|
||||
|
||||
// Get the updated item after adding tagihan data
|
||||
final updatedItem = sewaHistory[i];
|
||||
|
||||
// If this is a package rental (aset_id is null and paket_id exists)
|
||||
if (updatedItem['aset_id'] == null &&
|
||||
updatedItem['paket_id'] != null) {
|
||||
final String paketId = updatedItem['paket_id'];
|
||||
|
||||
try {
|
||||
// Get package name from paket table
|
||||
final paketResponse =
|
||||
await _authProvider.client
|
||||
.from('paket')
|
||||
.select('nama')
|
||||
.eq('id', paketId)
|
||||
.maybeSingle();
|
||||
|
||||
// Get package photo from foto_aset table
|
||||
final fotoResponse =
|
||||
await _authProvider.client
|
||||
.from('foto_aset')
|
||||
.select('foto_aset')
|
||||
.eq('id_paket', paketId)
|
||||
.limit(1)
|
||||
.maybeSingle();
|
||||
|
||||
// Create a synthetic aset object for paket
|
||||
Map<String, dynamic> syntheticAset = {};
|
||||
|
||||
if (paketResponse != null) {
|
||||
syntheticAset['nama'] = paketResponse['nama'] ?? 'Paket';
|
||||
}
|
||||
|
||||
if (fotoResponse != null) {
|
||||
syntheticAset['foto_utama'] = fotoResponse['foto_aset'];
|
||||
}
|
||||
|
||||
// Update the item with the synthetic aset
|
||||
sewaHistory[i] = {
|
||||
...updatedItem,
|
||||
'aset': syntheticAset,
|
||||
'tipe_pesanan': 'paket',
|
||||
};
|
||||
} catch (e) {
|
||||
print('Error fetching package details: $e');
|
||||
}
|
||||
}
|
||||
// If this is an asset rental (aset_id exists and paket_id is null)
|
||||
else if (updatedItem['aset_id'] != null &&
|
||||
updatedItem['paket_id'] == null) {
|
||||
final String asetId = updatedItem['aset_id'];
|
||||
|
||||
try {
|
||||
// Get asset name from aset table
|
||||
final asetResponse =
|
||||
await _authProvider.client
|
||||
.from('aset')
|
||||
.select('nama')
|
||||
.eq('id', asetId)
|
||||
.maybeSingle();
|
||||
|
||||
// Get asset photo from foto_aset table using id_aset
|
||||
final fotoResponse =
|
||||
await _authProvider.client
|
||||
.from('foto_aset')
|
||||
.select('foto_aset')
|
||||
.eq('id_aset', asetId)
|
||||
.limit(1)
|
||||
.maybeSingle();
|
||||
|
||||
// Create aset object for individual asset
|
||||
Map<String, dynamic> asetData = {};
|
||||
|
||||
if (asetResponse != null) {
|
||||
asetData['nama'] = asetResponse['nama'] ?? 'Aset';
|
||||
}
|
||||
|
||||
if (fotoResponse != null) {
|
||||
asetData['foto_utama'] = fotoResponse['foto_aset'];
|
||||
}
|
||||
|
||||
// Update the item with the aset data
|
||||
sewaHistory[i] = {
|
||||
...updatedItem,
|
||||
'aset': asetData,
|
||||
'tipe_pesanan': 'aset',
|
||||
};
|
||||
} catch (e) {
|
||||
print('Error fetching asset details: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching sewa history: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updatePenyewaStatus(String status, String keterangan) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.update({
|
||||
'status': status,
|
||||
'keterangan': keterangan,
|
||||
'updated_at': DateTime.now().toIso8601String(),
|
||||
})
|
||||
.eq('user_id', userId.value);
|
||||
|
||||
// Refresh data
|
||||
await fetchPenyewaDetail();
|
||||
|
||||
Get.snackbar(
|
||||
'Berhasil',
|
||||
'Status penyewa berhasil diperbarui',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Error updating penyewa status: $e');
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memperbarui status penyewa',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
String getStatusLabel(String? status) {
|
||||
switch (status?.toLowerCase()) {
|
||||
case 'active':
|
||||
return 'Aktif';
|
||||
case 'pending':
|
||||
return 'Menunggu Verifikasi';
|
||||
case 'suspended':
|
||||
return 'Dinonaktifkan';
|
||||
default:
|
||||
return 'Tidak diketahui';
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@ import 'package:bumrent_app/app/data/providers/aset_provider.dart';
|
||||
class PetugasPaketController extends GetxController {
|
||||
// Dependencies
|
||||
final AsetProvider _asetProvider = Get.find<AsetProvider>();
|
||||
|
||||
|
||||
// State
|
||||
final RxBool isLoading = false.obs;
|
||||
final RxString searchQuery = ''.obs;
|
||||
@ -16,7 +16,7 @@ class PetugasPaketController extends GetxController {
|
||||
final RxString sortBy = 'Terbaru'.obs;
|
||||
final RxList<PaketModel> packages = <PaketModel>[].obs;
|
||||
final RxList<PaketModel> filteredPackages = <PaketModel>[].obs;
|
||||
|
||||
|
||||
// Sort options for the dropdown
|
||||
final List<String> sortOptions = [
|
||||
'Terbaru',
|
||||
@ -26,18 +26,19 @@ class PetugasPaketController extends GetxController {
|
||||
'Nama A-Z',
|
||||
'Nama Z-A',
|
||||
];
|
||||
|
||||
|
||||
// For backward compatibility
|
||||
final RxList<Map<String, dynamic>> paketList = <Map<String, dynamic>>[].obs;
|
||||
final RxList<Map<String, dynamic>> filteredPaketList = <Map<String, dynamic>>[].obs;
|
||||
|
||||
final RxList<Map<String, dynamic>> filteredPaketList =
|
||||
<Map<String, dynamic>>[].obs;
|
||||
|
||||
// Logger
|
||||
late final Logger _logger;
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
|
||||
// Initialize logger
|
||||
_logger = Logger(
|
||||
printer: PrettyPrinter(
|
||||
@ -47,39 +48,42 @@ class PetugasPaketController extends GetxController {
|
||||
printEmojis: true,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// Load initial data
|
||||
fetchPackages();
|
||||
}
|
||||
|
||||
|
||||
/// Fetch packages from the API
|
||||
Future<void> fetchPackages() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
_logger.i('🔄 [fetchPackages] Fetching packages...');
|
||||
|
||||
|
||||
final result = await _asetProvider.getAllPaket();
|
||||
|
||||
|
||||
if (result.isEmpty) {
|
||||
_logger.w('ℹ️ [fetchPackages] No packages found');
|
||||
packages.clear();
|
||||
filteredPackages.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
packages.assignAll(result);
|
||||
filteredPackages.assignAll(result);
|
||||
|
||||
|
||||
// Update legacy list for backward compatibility
|
||||
_updateLegacyPaketList();
|
||||
|
||||
_logger.i('✅ [fetchPackages] Successfully loaded ${result.length} packages');
|
||||
|
||||
|
||||
_logger.i(
|
||||
'✅ [fetchPackages] Successfully loaded ${result.length} packages',
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [fetchPackages] Error fetching packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
|
||||
_logger.e(
|
||||
'❌ [fetchPackages] Error fetching packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memuat data paket. Silakan coba lagi.',
|
||||
@ -91,97 +95,113 @@ class PetugasPaketController extends GetxController {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Update legacy paketList for backward compatibility
|
||||
void _updateLegacyPaketList() {
|
||||
try {
|
||||
_logger.d('🔄 [_updateLegacyPaketList] Updating legacy paketList...');
|
||||
|
||||
final List<Map<String, dynamic>> legacyList = packages.map((pkg) {
|
||||
return {
|
||||
'id': pkg.id,
|
||||
'nama': pkg.nama,
|
||||
'deskripsi': pkg.deskripsi,
|
||||
'harga': pkg.harga,
|
||||
'kuantitas': pkg.kuantitas,
|
||||
'status': pkg.status, // Add status to legacy mapping
|
||||
'foto': pkg.foto,
|
||||
'foto_paket': pkg.foto_paket,
|
||||
'images': pkg.images,
|
||||
'satuanWaktuSewa': pkg.satuanWaktuSewa,
|
||||
'created_at': pkg.createdAt,
|
||||
'updated_at': pkg.updatedAt,
|
||||
};
|
||||
}).toList();
|
||||
|
||||
|
||||
final List<Map<String, dynamic>> legacyList =
|
||||
packages.map((pkg) {
|
||||
return {
|
||||
'id': pkg.id,
|
||||
'nama': pkg.nama,
|
||||
'deskripsi': pkg.deskripsi,
|
||||
'harga': pkg.harga,
|
||||
'kuantitas': pkg.kuantitas,
|
||||
'status': pkg.status, // Add status to legacy mapping
|
||||
'foto': pkg.foto,
|
||||
'foto_paket': pkg.foto_paket,
|
||||
'images': pkg.images,
|
||||
'satuanWaktuSewa': pkg.satuanWaktuSewa,
|
||||
'created_at': pkg.createdAt,
|
||||
'updated_at': pkg.updatedAt,
|
||||
};
|
||||
}).toList();
|
||||
|
||||
paketList.assignAll(legacyList);
|
||||
filteredPaketList.assignAll(legacyList);
|
||||
|
||||
_logger.d('✅ [_updateLegacyPaketList] Updated ${legacyList.length} packages');
|
||||
|
||||
|
||||
_logger.d(
|
||||
'✅ [_updateLegacyPaketList] Updated ${legacyList.length} packages',
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [_updateLegacyPaketList] Error updating legacy list',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
_logger.e(
|
||||
'❌ [_updateLegacyPaketList] Error updating legacy list',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// For backward compatibility
|
||||
Future<void> loadPaketData() async {
|
||||
_logger.d('ℹ️ [loadPaketData] Using fetchPackages() instead');
|
||||
await fetchPackages();
|
||||
}
|
||||
|
||||
|
||||
/// Filter packages based on search query and category
|
||||
void filterPaket() {
|
||||
try {
|
||||
_logger.d('🔄 [filterPaket] Filtering packages...');
|
||||
|
||||
|
||||
if (searchQuery.value.isEmpty && selectedCategory.value == 'Semua') {
|
||||
filteredPackages.value = List.from(packages);
|
||||
filteredPaketList.value = List.from(paketList);
|
||||
} else {
|
||||
// Filter new packages
|
||||
filteredPackages.value = packages.where((paket) {
|
||||
final matchesSearch = searchQuery.value.isEmpty ||
|
||||
paket.nama.toLowerCase().contains(searchQuery.value.toLowerCase());
|
||||
|
||||
// For now, we're not using categories in the new model
|
||||
// You can add category filtering if needed
|
||||
final matchesCategory = selectedCategory.value == 'Semua';
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}).toList();
|
||||
|
||||
filteredPackages.value =
|
||||
packages.where((paket) {
|
||||
final matchesSearch =
|
||||
searchQuery.value.isEmpty ||
|
||||
paket.nama.toLowerCase().contains(
|
||||
searchQuery.value.toLowerCase(),
|
||||
);
|
||||
|
||||
// For now, we're not using categories in the new model
|
||||
// You can add category filtering if needed
|
||||
final matchesCategory = selectedCategory.value == 'Semua';
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}).toList();
|
||||
|
||||
// Also update legacy list for backward compatibility
|
||||
filteredPaketList.value = paketList.where((paket) {
|
||||
final matchesSearch = searchQuery.value.isEmpty ||
|
||||
(paket['nama']?.toString() ?? '').toLowerCase()
|
||||
.contains(searchQuery.value.toLowerCase());
|
||||
|
||||
// For legacy support, check if category exists
|
||||
final matchesCategory = selectedCategory.value == 'Semua' ||
|
||||
(paket['kategori']?.toString() ?? '') == selectedCategory.value;
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}).toList();
|
||||
filteredPaketList.value =
|
||||
paketList.where((paket) {
|
||||
final matchesSearch =
|
||||
searchQuery.value.isEmpty ||
|
||||
(paket['nama']?.toString() ?? '').toLowerCase().contains(
|
||||
searchQuery.value.toLowerCase(),
|
||||
);
|
||||
|
||||
// For legacy support, check if category exists
|
||||
final matchesCategory =
|
||||
selectedCategory.value == 'Semua' ||
|
||||
(paket['kategori']?.toString() ?? '') ==
|
||||
selectedCategory.value;
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
|
||||
sortFilteredList();
|
||||
_logger.d('✅ [filterPaket] Filtered to ${filteredPackages.length} packages');
|
||||
|
||||
_logger.d(
|
||||
'✅ [filterPaket] Filtered to ${filteredPackages.length} packages',
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [filterPaket] Error filtering packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
_logger.e(
|
||||
'❌ [filterPaket] Error filtering packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Sort the filtered list based on the selected sort option
|
||||
void sortFilteredList() {
|
||||
try {
|
||||
_logger.d('🔄 [sortFilteredList] Sorting packages by ${sortBy.value}');
|
||||
|
||||
|
||||
// Sort new packages
|
||||
switch (sortBy.value) {
|
||||
case 'Terbaru':
|
||||
@ -203,44 +223,63 @@ class PetugasPaketController extends GetxController {
|
||||
filteredPackages.sort((a, b) => b.nama.compareTo(a.nama));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Also sort legacy list for backward compatibility
|
||||
switch (sortBy.value) {
|
||||
case 'Terbaru':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((b['created_at'] ?? '') as String).compareTo((a['created_at'] ?? '') as String));
|
||||
filteredPaketList.sort(
|
||||
(a, b) => ((b['created_at'] ?? '') as String).compareTo(
|
||||
(a['created_at'] ?? '') as String,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 'Terlama':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((a['created_at'] ?? '') as String).compareTo((b['created_at'] ?? '') as String));
|
||||
filteredPaketList.sort(
|
||||
(a, b) => ((a['created_at'] ?? '') as String).compareTo(
|
||||
(b['created_at'] ?? '') as String,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 'Harga Tertinggi':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((b['harga'] ?? 0) as int).compareTo((a['harga'] ?? 0) as int));
|
||||
filteredPaketList.sort(
|
||||
(a, b) =>
|
||||
((b['harga'] ?? 0) as int).compareTo((a['harga'] ?? 0) as int),
|
||||
);
|
||||
break;
|
||||
case 'Harga Terendah':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((a['harga'] ?? 0) as int).compareTo((b['harga'] ?? 0) as int));
|
||||
filteredPaketList.sort(
|
||||
(a, b) =>
|
||||
((a['harga'] ?? 0) as int).compareTo((b['harga'] ?? 0) as int),
|
||||
);
|
||||
break;
|
||||
case 'Nama A-Z':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((a['nama'] ?? '') as String).compareTo((b['nama'] ?? '') as String));
|
||||
filteredPaketList.sort(
|
||||
(a, b) => ((a['nama'] ?? '') as String).compareTo(
|
||||
(b['nama'] ?? '') as String,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case 'Nama Z-A':
|
||||
filteredPaketList.sort((a, b) =>
|
||||
((b['nama'] ?? '') as String).compareTo((a['nama'] ?? '') as String));
|
||||
filteredPaketList.sort(
|
||||
(a, b) => ((b['nama'] ?? '') as String).compareTo(
|
||||
(a['nama'] ?? '') as String,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
_logger.d('✅ [sortFilteredList] Sorted ${filteredPackages.length} packages');
|
||||
|
||||
|
||||
_logger.d(
|
||||
'✅ [sortFilteredList] Sorted ${filteredPackages.length} packages',
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [sortFilteredList] Error sorting packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
_logger.e(
|
||||
'❌ [sortFilteredList] Error sorting packages',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set search query dan filter paket
|
||||
void setSearchQuery(String query) {
|
||||
searchQuery.value = query;
|
||||
@ -263,7 +302,7 @@ class PetugasPaketController extends GetxController {
|
||||
Future<void> addPaket(Map<String, dynamic> paketData) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
|
||||
// Convert to PaketModel
|
||||
final newPaket = PaketModel.fromJson({
|
||||
...paketData,
|
||||
@ -271,12 +310,12 @@ class PetugasPaketController extends GetxController {
|
||||
'created_at': DateTime.now().toIso8601String(),
|
||||
'updated_at': DateTime.now().toIso8601String(),
|
||||
});
|
||||
|
||||
|
||||
// Add to the list
|
||||
packages.add(newPaket);
|
||||
_updateLegacyPaketList();
|
||||
filterPaket();
|
||||
|
||||
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
@ -285,12 +324,13 @@ class PetugasPaketController extends GetxController {
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [addPaket] Error adding package',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
|
||||
_logger.e(
|
||||
'❌ [addPaket] Error adding package',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal menambahkan paket. Silakan coba lagi.',
|
||||
@ -307,23 +347,28 @@ class PetugasPaketController extends GetxController {
|
||||
Future<void> editPaket(String id, Map<String, dynamic> updatedData) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
|
||||
final index = packages.indexWhere((pkg) => pkg.id == id);
|
||||
if (index >= 0) {
|
||||
// Update the package
|
||||
final updatedPaket = packages[index].copyWith(
|
||||
nama: updatedData['nama']?.toString() ?? packages[index].nama,
|
||||
deskripsi: updatedData['deskripsi']?.toString() ?? packages[index].deskripsi,
|
||||
kuantitas: (updatedData['kuantitas'] is int)
|
||||
? updatedData['kuantitas']
|
||||
: (int.tryParse(updatedData['kuantitas']?.toString() ?? '0') ?? packages[index].kuantitas),
|
||||
deskripsi:
|
||||
updatedData['deskripsi']?.toString() ?? packages[index].deskripsi,
|
||||
kuantitas:
|
||||
(updatedData['kuantitas'] is int)
|
||||
? updatedData['kuantitas']
|
||||
: (int.tryParse(
|
||||
updatedData['kuantitas']?.toString() ?? '0',
|
||||
) ??
|
||||
packages[index].kuantitas),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
|
||||
packages[index] = updatedPaket;
|
||||
_updateLegacyPaketList();
|
||||
filterPaket();
|
||||
|
||||
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
@ -334,10 +379,12 @@ class PetugasPaketController extends GetxController {
|
||||
);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [editPaket] Error updating package',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
|
||||
_logger.e(
|
||||
'❌ [editPaket] Error updating package',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal memperbarui paket. Silakan coba lagi.',
|
||||
@ -353,39 +400,76 @@ class PetugasPaketController extends GetxController {
|
||||
// Hapus paket
|
||||
Future<void> deletePaket(String id) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
// Remove from the main list
|
||||
packages.removeWhere((pkg) => pkg.id == id);
|
||||
_updateLegacyPaketList();
|
||||
filterPaket();
|
||||
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Paket berhasil dihapus',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
_logger.i(
|
||||
'🔄 [deletePaket] Starting deletion process for package ID: $id',
|
||||
);
|
||||
|
||||
|
||||
// Show a loading dialog
|
||||
Get.dialog(
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
|
||||
// Call the provider to delete the package and all related data from Supabase
|
||||
final success = await _asetProvider.deletePaket(id);
|
||||
|
||||
// Close the loading dialog
|
||||
Get.back();
|
||||
|
||||
if (success) {
|
||||
_logger.i('✅ [deletePaket] Package deleted successfully from database');
|
||||
|
||||
// Remove the package from the UI lists
|
||||
packages.removeWhere((pkg) => pkg.id == id);
|
||||
_updateLegacyPaketList();
|
||||
filterPaket();
|
||||
|
||||
// Show success message
|
||||
Get.snackbar(
|
||||
'Sukses',
|
||||
'Paket berhasil dihapus dari sistem',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
} else {
|
||||
_logger.e('❌ [deletePaket] Failed to delete package from database');
|
||||
|
||||
// Show error message
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat menghapus paket',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_logger.e('❌ [deletePaket] Error deleting package',
|
||||
error: e,
|
||||
stackTrace: stackTrace);
|
||||
|
||||
_logger.e(
|
||||
'❌ [deletePaket] Error deleting package',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
// Close the loading dialog if still open
|
||||
if (Get.isDialogOpen ?? false) {
|
||||
Get.back();
|
||||
}
|
||||
|
||||
// Show error message
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Gagal menghapus paket. Silakan coba lagi.',
|
||||
'Gagal menghapus paket: ${e.toString()}',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Format price to Rupiah currency
|
||||
String formatPrice(num price) {
|
||||
return 'Rp ${NumberFormat('#,##0', 'id_ID').format(price)}';
|
||||
|
@ -0,0 +1,196 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../../../data/providers/auth_provider.dart';
|
||||
|
||||
class PetugasPenyewaController extends GetxController {
|
||||
final AuthProvider _authProvider = Get.find<AuthProvider>();
|
||||
|
||||
// Reactive variables
|
||||
final isLoading = true.obs;
|
||||
final penyewaList = <Map<String, dynamic>>[].obs;
|
||||
final filteredPenyewaList = <Map<String, dynamic>>[].obs;
|
||||
final filterStatus = 'all'.obs;
|
||||
final currentTabIndex = 0.obs;
|
||||
final searchQuery = ''.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchPenyewaList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
// Refresh data when the page is first loaded
|
||||
refreshData();
|
||||
}
|
||||
|
||||
// Method to refresh data when returning to the page
|
||||
void refreshData() {
|
||||
fetchPenyewaList();
|
||||
}
|
||||
|
||||
void changeTab(int index) {
|
||||
currentTabIndex.value = index;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
void updateSearchQuery(String query) {
|
||||
searchQuery.value = query;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
void applyFilters() {
|
||||
if (penyewaList.isEmpty) return;
|
||||
|
||||
// First apply status filter based on current tab
|
||||
String statusFilter;
|
||||
switch (currentTabIndex.value) {
|
||||
case 0: // Verifikasi
|
||||
statusFilter = 'pending';
|
||||
break;
|
||||
case 1: // Aktif
|
||||
statusFilter = 'active';
|
||||
break;
|
||||
case 2: // Ditangguhkan
|
||||
statusFilter = 'suspended';
|
||||
break;
|
||||
default:
|
||||
statusFilter = 'all';
|
||||
}
|
||||
|
||||
// Filter by status
|
||||
var result =
|
||||
statusFilter == 'all'
|
||||
? penyewaList
|
||||
: penyewaList
|
||||
.where((p) => p['status']?.toLowerCase() == statusFilter)
|
||||
.toList();
|
||||
|
||||
// Then apply search filter if there's a query
|
||||
if (searchQuery.value.isNotEmpty) {
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
result =
|
||||
result
|
||||
.where(
|
||||
(p) =>
|
||||
(p['nama_lengkap']?.toString().toLowerCase().contains(
|
||||
query,
|
||||
) ??
|
||||
false) ||
|
||||
(p['email']?.toString().toLowerCase().contains(query) ??
|
||||
false),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
filteredPenyewaList.value = result;
|
||||
}
|
||||
|
||||
Future<void> fetchPenyewaList() async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
// Get all penyewa data without filtering
|
||||
final data =
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.select(
|
||||
'user_id, nama_lengkap, email, nik, no_hp, avatar, status, keterangan',
|
||||
)
|
||||
as List<dynamic>;
|
||||
|
||||
// Filter out rows where user_id is null
|
||||
final filteredData = data.where((row) => row['user_id'] != null).toList();
|
||||
|
||||
// Get total sewa count for each user
|
||||
final enrichedData = await _enrichWithSewaCount(filteredData);
|
||||
|
||||
penyewaList.value = enrichedData;
|
||||
|
||||
// Apply filters to update filteredPenyewaList
|
||||
applyFilters();
|
||||
} catch (e) {
|
||||
print('Error fetching penyewa list: $e');
|
||||
penyewaList.value = [];
|
||||
filteredPenyewaList.value = [];
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> _enrichWithSewaCount(
|
||||
List<dynamic> penyewaData,
|
||||
) async {
|
||||
final result = <Map<String, dynamic>>[];
|
||||
|
||||
for (var penyewa in penyewaData) {
|
||||
final userId = penyewa['user_id'];
|
||||
|
||||
// Count total sewa for this user
|
||||
final sewaCount = await _countUserSewa(userId);
|
||||
|
||||
// Create a new map with all the original data plus the total_sewa count
|
||||
final enrichedPenyewa = Map<String, dynamic>.from(penyewa);
|
||||
enrichedPenyewa['total_sewa'] = sewaCount;
|
||||
|
||||
result.add(enrichedPenyewa);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<int> _countUserSewa(String userId) async {
|
||||
try {
|
||||
final response = await _authProvider.client
|
||||
.from('sewa_aset')
|
||||
.select('id')
|
||||
.eq('user_id', userId);
|
||||
|
||||
return (response as List).length;
|
||||
} catch (e) {
|
||||
print('Error counting sewa for user $userId: $e');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void viewPenyewaDetail(String userId) {
|
||||
// Navigate to penyewa detail page (to be implemented)
|
||||
print('View detail for penyewa with ID: $userId');
|
||||
|
||||
// Get.toNamed(Routes.PETUGAS_PENYEWA_DETAIL, arguments: {'user_id': userId});
|
||||
}
|
||||
|
||||
void updatePenyewaStatus(
|
||||
String userId,
|
||||
String newStatus,
|
||||
String keterangan,
|
||||
) async {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
|
||||
await _authProvider.client
|
||||
.from('warga_desa')
|
||||
.update({'status': newStatus, 'keterangan': keterangan})
|
||||
.eq('user_id', userId);
|
||||
|
||||
// Refresh the list
|
||||
await fetchPenyewaList();
|
||||
|
||||
Get.snackbar(
|
||||
'Berhasil',
|
||||
'Status penyewa berhasil diperbarui',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Error updating penyewa status: $e');
|
||||
Get.snackbar(
|
||||
'Gagal',
|
||||
'Terjadi kesalahan saat memperbarui status penyewa',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -50,22 +50,24 @@ class PetugasSewaController extends GetxController {
|
||||
void _updateFilteredList() {
|
||||
filteredSewaList.value =
|
||||
sewaList.where((sewa) {
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
// Apply search filter: nama warga, id pesanan, atau asetId
|
||||
final matchesSearch =
|
||||
sewa.wargaNama.toLowerCase().contains(query) ||
|
||||
sewa.id.toLowerCase().contains(query) ||
|
||||
(sewa.asetId != null &&
|
||||
sewa.asetId!.toLowerCase().contains(query));
|
||||
final query = searchQuery.value.toLowerCase();
|
||||
// Apply search filter: nama warga, id pesanan, atau asetId
|
||||
final matchesSearch =
|
||||
sewa.wargaNama.toLowerCase().contains(query) ||
|
||||
sewa.id.toLowerCase().contains(query) ||
|
||||
(sewa.asetId != null &&
|
||||
sewa.asetId!.toLowerCase().contains(query));
|
||||
|
||||
// Apply status filter if not 'Semua'
|
||||
final matchesStatus =
|
||||
selectedStatusFilter.value == 'Semua' ||
|
||||
sewa.status.toUpperCase() ==
|
||||
selectedStatusFilter.value.toUpperCase();
|
||||
// Apply status filter if not 'Semua'
|
||||
final matchesStatus =
|
||||
selectedStatusFilter.value == 'Semua' ||
|
||||
sewa.status.toUpperCase() ==
|
||||
selectedStatusFilter.value.toUpperCase();
|
||||
|
||||
return matchesSearch && matchesStatus;
|
||||
}).toList();
|
||||
return matchesSearch && matchesStatus;
|
||||
}).toList()
|
||||
// Sort filtered results by tanggal_pemesanan in descending order (newest first)
|
||||
..sort((a, b) => b.tanggalPemesanan.compareTo(a.tanggalPemesanan));
|
||||
}
|
||||
|
||||
// Load sewa data (mock data for now)
|
||||
@ -74,6 +76,8 @@ class PetugasSewaController extends GetxController {
|
||||
|
||||
try {
|
||||
final data = await SewaService().fetchAllSewa();
|
||||
// Sort data by tanggal_pemesanan in descending order (newest first)
|
||||
data.sort((a, b) => b.tanggalPemesanan.compareTo(a.tanggalPemesanan));
|
||||
sewaList.assignAll(data);
|
||||
} catch (e) {
|
||||
print('Error loading sewa data: $e');
|
||||
@ -101,23 +105,27 @@ class PetugasSewaController extends GetxController {
|
||||
void resetFilters() {
|
||||
selectedStatusFilter.value = 'Semua';
|
||||
searchQuery.value = '';
|
||||
filteredSewaList.value = sewaList;
|
||||
// Assign a sorted copy of sewaList to filteredSewaList
|
||||
filteredSewaList.value = List<SewaModel>.from(sewaList)
|
||||
..sort((a, b) => b.tanggalPemesanan.compareTo(a.tanggalPemesanan));
|
||||
}
|
||||
|
||||
void applyFilters() {
|
||||
filteredSewaList.value =
|
||||
sewaList.where((sewa) {
|
||||
bool matchesStatus =
|
||||
selectedStatusFilter.value == 'Semua' ||
|
||||
sewa.status.toUpperCase() ==
|
||||
selectedStatusFilter.value.toUpperCase();
|
||||
bool matchesSearch =
|
||||
searchQuery.value.isEmpty ||
|
||||
sewa.wargaNama.toLowerCase().contains(
|
||||
searchQuery.value.toLowerCase(),
|
||||
);
|
||||
return matchesStatus && matchesSearch;
|
||||
}).toList();
|
||||
bool matchesStatus =
|
||||
selectedStatusFilter.value == 'Semua' ||
|
||||
sewa.status.toUpperCase() ==
|
||||
selectedStatusFilter.value.toUpperCase();
|
||||
bool matchesSearch =
|
||||
searchQuery.value.isEmpty ||
|
||||
sewa.wargaNama.toLowerCase().contains(
|
||||
searchQuery.value.toLowerCase(),
|
||||
);
|
||||
return matchesStatus && matchesSearch;
|
||||
}).toList()
|
||||
// Sort filtered results by tanggal_pemesanan in descending order (newest first)
|
||||
..sort((a, b) => b.tanggalPemesanan.compareTo(a.tanggalPemesanan));
|
||||
}
|
||||
|
||||
// Format price to rupiah
|
||||
|
365
lib/app/modules/petugas_bumdes/views/petugas_akun_bank_view.dart
Normal file
365
lib/app/modules/petugas_bumdes/views/petugas_akun_bank_view.dart
Normal file
@ -0,0 +1,365 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_akun_bank_controller.dart';
|
||||
import '../controllers/petugas_bumdes_dashboard_controller.dart';
|
||||
import '../widgets/petugas_side_navbar.dart';
|
||||
import '../../../theme/app_colors_petugas.dart';
|
||||
|
||||
class PetugasAkunBankView extends GetView<PetugasAkunBankController> {
|
||||
const PetugasAkunBankView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Get dashboard controller for side navbar
|
||||
final dashboardController = Get.find<PetugasBumdesDashboardController>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Kelola Akun Bank'),
|
||||
backgroundColor: AppColorsPetugas.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
),
|
||||
body: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (controller.errorMessage.value.isNotEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 48, color: Colors.red[300]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
controller.errorMessage.value,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: controller.loadBankAccounts,
|
||||
child: const Text('Coba Lagi'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (controller.bankAccounts.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.account_balance, size: 48, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Belum ada akun bank',
|
||||
style: TextStyle(fontSize: 18, color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _showAddEditBankAccountDialog(context),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Tambah Akun Bank'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
RefreshIndicator(
|
||||
onRefresh: controller.loadBankAccounts,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: controller.bankAccounts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final account = controller.bankAccounts[index];
|
||||
return _buildBankAccountCard(context, account);
|
||||
},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
right: 16,
|
||||
child: FloatingActionButton(
|
||||
onPressed: () => _showAddEditBankAccountDialog(context),
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBankAccountCard(
|
||||
BuildContext context,
|
||||
Map<String, dynamic> account,
|
||||
) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.blueGrotto.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.account_balance,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
account['nama_bank'] ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
account['nama_akun'] ?? '',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (value) {
|
||||
if (value == 'edit') {
|
||||
_showAddEditBankAccountDialog(context, account);
|
||||
} else if (value == 'delete') {
|
||||
_showDeleteConfirmationDialog(context, account);
|
||||
}
|
||||
},
|
||||
itemBuilder:
|
||||
(context) => [
|
||||
const PopupMenuItem(
|
||||
value: 'edit',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.edit, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('Edit'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete, size: 18, color: Colors.red),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Hapus',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.credit_card, size: 16, color: Colors.grey),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'No. Rekening: ${account['no_rekening'] ?? ''}',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddEditBankAccountDialog(
|
||||
BuildContext context, [
|
||||
Map<String, dynamic>? account,
|
||||
]) {
|
||||
final isEditing = account != null;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
String bankName = account?['nama_bank'] ?? '';
|
||||
String accountName = account?['nama_akun'] ?? '';
|
||||
String accountNumber = account?['no_rekening'] ?? '';
|
||||
|
||||
Get.dialog(
|
||||
Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isEditing ? 'Edit Akun Bank' : 'Tambah Akun Bank',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Form(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
initialValue: bankName,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nama Bank',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.account_balance),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Nama bank tidak boleh kosong';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) => bankName = value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
initialValue: accountName,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nama Pemilik Rekening',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.person),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Nama pemilik rekening tidak boleh kosong';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) => accountName = value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
initialValue: accountNumber,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nomor Rekening',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.credit_card),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Nomor rekening tidak boleh kosong';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) => accountNumber = value,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (formKey.currentState!.validate()) {
|
||||
final accountData = {
|
||||
'nama_bank': bankName,
|
||||
'nama_akun': accountName,
|
||||
'no_rekening': accountNumber,
|
||||
};
|
||||
|
||||
if (isEditing) {
|
||||
controller.updateBankAccount(
|
||||
account['id'],
|
||||
accountData,
|
||||
);
|
||||
} else {
|
||||
controller.addBankAccount(accountData);
|
||||
}
|
||||
|
||||
Get.back();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: Text(isEditing ? 'Simpan' : 'Tambah'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteConfirmationDialog(
|
||||
BuildContext context,
|
||||
Map<String, dynamic> account,
|
||||
) {
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Konfirmasi Hapus'),
|
||||
content: Text(
|
||||
'Apakah Anda yakin ingin menghapus akun bank ${account['nama_bank']} - ${account['nama_akun']}?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Get.back(), child: const Text('Batal')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.deleteBankAccount(account['id']);
|
||||
Get.back();
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
child: const Text('Hapus'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -267,7 +267,6 @@ class _PetugasAsetViewState extends State<PetugasAsetView>
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _showAssetDetails(context, aset),
|
||||
child: Row(
|
||||
children: [
|
||||
// Asset image
|
||||
@ -671,366 +670,11 @@ class _PetugasAsetViewState extends State<PetugasAsetView>
|
||||
}
|
||||
}
|
||||
|
||||
void _showAssetDetails(BuildContext context, Map<String, dynamic> aset) {
|
||||
final isAvailable = aset['tersedia'] == true;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Header with gradient
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(24, 16, 24, 24),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColorsPetugas.blueGrotto,
|
||||
AppColorsPetugas.navyBlue,
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Close button and availability badge
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
isAvailable
|
||||
? AppColorsPetugas.successLight
|
||||
: AppColorsPetugas.errorLight,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color:
|
||||
isAvailable
|
||||
? AppColorsPetugas.success
|
||||
: AppColorsPetugas.error,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
isAvailable ? Icons.check_circle : Icons.cancel,
|
||||
color:
|
||||
isAvailable
|
||||
? AppColorsPetugas.success
|
||||
: AppColorsPetugas.error,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
isAvailable ? 'Tersedia' : 'Tidak Tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color:
|
||||
isAvailable
|
||||
? AppColorsPetugas.success
|
||||
: AppColorsPetugas.error,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Category badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
aset['kategori'],
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Asset name
|
||||
Text(
|
||||
aset['nama'],
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Price
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.monetization_on,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${controller.formatPrice(aset['harga'])} ${aset['satuan']}',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Asset details
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Quick info cards
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoCard(
|
||||
Icons.inventory_2,
|
||||
'Stok',
|
||||
'${aset['stok']} unit',
|
||||
flex: 1,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
_buildInfoCard(
|
||||
Icons.category,
|
||||
'Jenis',
|
||||
aset['jenis'],
|
||||
flex: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Description section
|
||||
Text(
|
||||
'Deskripsi',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
aset['deskripsi'],
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColorsPetugas.textPrimary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Action buttons
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColorsPetugas.shadowColor,
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, -5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_showAddEditAssetDialog(context, aset: aset);
|
||||
},
|
||||
icon: const Icon(Icons.edit),
|
||||
label: const Text('Edit'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColorsPetugas.blueGrotto,
|
||||
side: BorderSide(color: AppColorsPetugas.blueGrotto),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_showDeleteConfirmation(context, aset);
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Hapus'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoCard(
|
||||
IconData icon,
|
||||
String label,
|
||||
String value, {
|
||||
int flex = 1,
|
||||
}) {
|
||||
return Expanded(
|
||||
flex: flex,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.babyBlueBright,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColorsPetugas.babyBlue),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: AppColorsPetugas.blueGrotto),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailItem(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColorsPetugas.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddEditAssetDialog(
|
||||
BuildContext context, {
|
||||
Map<String, dynamic>? aset,
|
||||
}) {
|
||||
final isEditing = aset != null;
|
||||
final jenisOptions = ['Sewa', 'Langganan'];
|
||||
final typeOptions = ['Elektronik', 'Furniture', 'Kendaraan', 'Lainnya'];
|
||||
|
||||
// In a real app, this would have proper form handling with controllers
|
||||
showDialog(
|
||||
@ -1333,22 +977,11 @@ class _PetugasAsetViewState extends State<PetugasAsetView>
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
controller.deleteAset(aset['id']);
|
||||
Get.snackbar(
|
||||
'Aset Dihapus',
|
||||
'Aset berhasil dihapus dari sistem',
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
margin: const EdgeInsets.all(16),
|
||||
borderRadius: 10,
|
||||
icon: const Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
// Let the controller handle the deletion and showing the snackbar
|
||||
await controller.deleteAset(aset['id']);
|
||||
// The controller will show appropriate success or error messages
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
|
@ -327,7 +327,7 @@ class PetugasBumdesCbpView extends GetView<PetugasBumdesCbpController> {
|
||||
leading: const Icon(Icons.subscriptions_outlined),
|
||||
title: const Text('Kelola Langganan'),
|
||||
onTap: () {
|
||||
Get.offAllNamed(Routes.PETUGAS_LANGGANAN);
|
||||
Get.offAllNamed(Routes.PETUGAS_BUMDES_DASHBOARD);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
|
@ -6,6 +6,7 @@ import '../widgets/petugas_bumdes_bottom_navbar.dart';
|
||||
import '../widgets/petugas_side_navbar.dart';
|
||||
import '../../../theme/app_colors_petugas.dart';
|
||||
import '../../../utils/format_utils.dart';
|
||||
import '../views/petugas_penyewa_view.dart';
|
||||
|
||||
class PetugasBumdesDashboardView
|
||||
extends GetView<PetugasBumdesDashboardController> {
|
||||
@ -64,6 +65,8 @@ class PetugasBumdesDashboardView
|
||||
case 3:
|
||||
return 'Permintaan Sewa';
|
||||
case 4:
|
||||
return 'Penyewa';
|
||||
case 5:
|
||||
return 'Profil BUMDes';
|
||||
default:
|
||||
return 'Dashboard Petugas BUMDES';
|
||||
@ -81,6 +84,8 @@ class PetugasBumdesDashboardView
|
||||
case 3:
|
||||
return _buildSewaTab();
|
||||
case 4:
|
||||
return const PetugasPenyewaView();
|
||||
case 5:
|
||||
return _buildBumdesTab();
|
||||
default:
|
||||
return _buildDashboardTab();
|
||||
@ -96,6 +101,16 @@ class PetugasBumdesDashboardView
|
||||
_buildWelcomeCard(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Tenant Statistics Section
|
||||
_buildSectionHeader(
|
||||
'Statistik Penyewa',
|
||||
AppColorsPetugas.blueGrotto,
|
||||
Icons.people_outline,
|
||||
),
|
||||
_buildTenantStatistics(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Detail Status Sewa Aset section with improved header
|
||||
_buildSectionHeader(
|
||||
'Detail Status Sewa Aset',
|
||||
@ -771,33 +786,29 @@ class PetugasBumdesDashboardView
|
||||
}
|
||||
|
||||
Widget _buildRevenueSummary() {
|
||||
return Row(
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Obx(() {
|
||||
final stats = controller.pembayaranStats;
|
||||
final totalTunai = stats['totalTunai'] ?? 0.0;
|
||||
return _buildRevenueQuickInfo(
|
||||
'Tunai',
|
||||
formatRupiah(totalTunai),
|
||||
AppColorsPetugas.navyBlue,
|
||||
Icons.payments,
|
||||
);
|
||||
}),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Obx(() {
|
||||
final stats = controller.pembayaranStats;
|
||||
final totalTransfer = stats['totalTransfer'] ?? 0.0;
|
||||
return _buildRevenueQuickInfo(
|
||||
'Transfer',
|
||||
formatRupiah(totalTransfer),
|
||||
AppColorsPetugas.blueGrotto,
|
||||
Icons.account_balance,
|
||||
);
|
||||
}),
|
||||
),
|
||||
Obx(() {
|
||||
final stats = controller.pembayaranStats;
|
||||
final totalTunai = stats['totalTunai'] ?? 0.0;
|
||||
return _buildRevenueQuickInfo(
|
||||
'Tunai',
|
||||
formatRupiah(totalTunai),
|
||||
AppColorsPetugas.navyBlue,
|
||||
Icons.payments,
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 12),
|
||||
Obx(() {
|
||||
final stats = controller.pembayaranStats;
|
||||
final totalTransfer = stats['totalTransfer'] ?? 0.0;
|
||||
return _buildRevenueQuickInfo(
|
||||
'Transfer',
|
||||
formatRupiah(totalTransfer),
|
||||
AppColorsPetugas.blueGrotto,
|
||||
Icons.account_balance,
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
@ -976,7 +987,13 @@ class PetugasBumdesDashboardView
|
||||
children: [
|
||||
Container(
|
||||
width: 35,
|
||||
height: 170 * percentage,
|
||||
height:
|
||||
percentage.isNaN || percentage <= 0
|
||||
? 10.0
|
||||
: (170 * percentage).clamp(
|
||||
10.0,
|
||||
170.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
const BorderRadius.vertical(
|
||||
@ -1243,6 +1260,288 @@ class PetugasBumdesDashboardView
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// New widget for tenant statistics
|
||||
Widget _buildTenantStatistics() {
|
||||
return Obx(() {
|
||||
if (controller.isPenyewaStatsLoading.value) {
|
||||
return const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20.0),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Card(
|
||||
elevation: 2,
|
||||
shadowColor: AppColorsPetugas.shadowColor,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
// Use LayoutBuilder to make the grid responsive
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 3,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisSpacing: 14,
|
||||
mainAxisSpacing: 14,
|
||||
childAspectRatio: 0.75,
|
||||
children: [
|
||||
_buildTenantStatusItem(
|
||||
'Menunggu Verifikasi',
|
||||
controller.penyewaPendingCount.value.toString(),
|
||||
AppColorsPetugas.warning,
|
||||
Icons.pending_outlined,
|
||||
),
|
||||
_buildTenantStatusItem(
|
||||
'Aktif',
|
||||
controller.penyewaActiveCount.value.toString(),
|
||||
AppColorsPetugas.success,
|
||||
Icons.check_circle_outline,
|
||||
),
|
||||
_buildTenantStatusItem(
|
||||
'Ditangguhkan',
|
||||
controller.penyewaSuspendedCount.value.toString(),
|
||||
AppColorsPetugas.error,
|
||||
Icons.block_outlined,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Tenant distribution visualization
|
||||
_buildTenantDistributionBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildTenantStatusItem(
|
||||
String title,
|
||||
String value,
|
||||
Color color,
|
||||
IconData icon,
|
||||
) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.15),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 3),
|
||||
),
|
||||
],
|
||||
border: Border.all(color: color.withOpacity(0.1), width: 1),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
height: 1.2,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTenantDistributionBar() {
|
||||
// Calculate the total count for all tenant statuses
|
||||
final total = controller.penyewaTotalCount.value;
|
||||
|
||||
// Calculate percentages for each status (avoid division by zero)
|
||||
final pendingPercent =
|
||||
total > 0 ? controller.penyewaPendingCount.value / total : 0.0;
|
||||
final activePercent =
|
||||
total > 0 ? controller.penyewaActiveCount.value / total : 0.0;
|
||||
final suspendedPercent =
|
||||
total > 0 ? controller.penyewaSuspendedCount.value / total : 0.0;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Distribusi Status Penyewa',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Only show distribution bar if there are any tenants
|
||||
if (total > 0)
|
||||
Stack(
|
||||
children: [
|
||||
// Background for the progress bar
|
||||
Container(
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
// Actual progress bar segments
|
||||
Row(
|
||||
children: [
|
||||
if (pendingPercent > 0)
|
||||
_buildProgressSegment(
|
||||
pendingPercent,
|
||||
AppColorsPetugas.warning,
|
||||
isFirst: true,
|
||||
),
|
||||
if (activePercent > 0)
|
||||
_buildProgressSegment(
|
||||
activePercent,
|
||||
AppColorsPetugas.success,
|
||||
),
|
||||
if (suspendedPercent > 0)
|
||||
_buildProgressSegment(
|
||||
suspendedPercent,
|
||||
AppColorsPetugas.error,
|
||||
isLast: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Container(
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Belum ada data penyewa',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Use row layout for legends
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (pendingPercent > 0 || total == 0)
|
||||
_buildStatusLegend(
|
||||
'Menunggu Verifikasi',
|
||||
AppColorsPetugas.warning,
|
||||
pendingPercent,
|
||||
),
|
||||
if (activePercent > 0 || total == 0)
|
||||
_buildStatusLegend(
|
||||
'Aktif',
|
||||
AppColorsPetugas.success,
|
||||
activePercent,
|
||||
),
|
||||
if (suspendedPercent > 0 || total == 0)
|
||||
_buildStatusLegend(
|
||||
'Ditangguhkan',
|
||||
AppColorsPetugas.error,
|
||||
suspendedPercent,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProgressSegment(
|
||||
double percentage,
|
||||
Color color, {
|
||||
bool isFirst = false,
|
||||
bool isLast = false,
|
||||
}) {
|
||||
final flex = (percentage * 100).round();
|
||||
if (flex <= 0) return const SizedBox.shrink();
|
||||
|
||||
return Flexible(
|
||||
flex: flex,
|
||||
child: Container(
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.horizontal(
|
||||
left: isFirst ? const Radius.circular(6) : Radius.zero,
|
||||
right: isLast ? const Radius.circular(6) : Radius.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusLegend(String text, Color color, double percentage) {
|
||||
final count = (percentage * 100).round();
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'$text ${count > 0 ? '($count%)' : ''}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.black87,
|
||||
fontWeight: count > 20 ? FontWeight.w500 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom clipper for creating pie/donut chart segments
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1070,7 +1070,8 @@ class _PetugasDetailSewaViewState extends State<PetugasDetailSewaView> {
|
||||
),
|
||||
)
|
||||
: ((sewa.status == 'MENUNGGU PEMBAYARAN' ||
|
||||
sewa.status == 'PERIKSA PEMBAYARAN'))
|
||||
sewa.status == 'PERIKSA PEMBAYARAN' ||
|
||||
sewa.status == 'DITERIMA'))
|
||||
? Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 20),
|
||||
child: Row(
|
||||
@ -1078,14 +1079,68 @@ class _PetugasDetailSewaViewState extends State<PetugasDetailSewaView> {
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
controller.rejectSewa(sewa.id);
|
||||
await refreshSewaData();
|
||||
Get.snackbar(
|
||||
'Sewa Dibatalkan',
|
||||
'Status sewa telah diubah menjadi DIBATALKAN',
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
// Show confirmation dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Konfirmasi Pembatalan'),
|
||||
content: Text(
|
||||
'Apakah Anda yakin ingin membatalkan sewa ini?',
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop(); // Close dialog
|
||||
},
|
||||
child: Text(
|
||||
'Batal',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop(); // Close dialog
|
||||
|
||||
// Update status to DIBATALKAN
|
||||
final asetProvider =
|
||||
Get.find<AsetProvider>();
|
||||
await asetProvider.updateSewaAsetStatus(
|
||||
sewaAsetId: sewa.id,
|
||||
status: 'DIBATALKAN',
|
||||
);
|
||||
|
||||
// Update local state
|
||||
controller.rejectSewa(sewa.id);
|
||||
await refreshSewaData();
|
||||
|
||||
// Show success notification
|
||||
Get.snackbar(
|
||||
'Sewa Dibatalkan',
|
||||
'Status sewa telah diubah menjadi DIBATALKAN',
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text('Konfirmasi'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
@ -1275,7 +1330,7 @@ class _PetugasDetailSewaViewState extends State<PetugasDetailSewaView> {
|
||||
}
|
||||
|
||||
// Always add cancel option if not already completed or canceled
|
||||
if (status != 'Selesai' && status != 'Dibatalkan') {
|
||||
if (status != 'SELESAI' && status != 'DIBATALKAN') {
|
||||
menuItems.add(
|
||||
PopupMenuItem(
|
||||
value: 'cancel',
|
||||
@ -1384,14 +1439,57 @@ class _PetugasDetailSewaViewState extends State<PetugasDetailSewaView> {
|
||||
|
||||
case 'cancel':
|
||||
// Update status to "Dibatalkan"
|
||||
controller.rejectSewa(sewa.id);
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Sewa Dibatalkan',
|
||||
'Sewa aset telah dibatalkan',
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Konfirmasi Pembatalan'),
|
||||
content: Text('Apakah Anda yakin ingin membatalkan sewa ini?'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close dialog
|
||||
},
|
||||
child: Text('Batal', style: TextStyle(color: Colors.grey)),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop(); // Close dialog
|
||||
|
||||
// Update status to DIBATALKAN
|
||||
final asetProvider = Get.find<AsetProvider>();
|
||||
await asetProvider.updateSewaAsetStatus(
|
||||
sewaAsetId: sewa.id,
|
||||
status: 'DIBATALKAN',
|
||||
);
|
||||
|
||||
// Update local state
|
||||
controller.rejectSewa(sewa.id);
|
||||
await refreshSewaData();
|
||||
|
||||
// Show success notification
|
||||
Get.snackbar(
|
||||
'Sewa Dibatalkan',
|
||||
'Status sewa telah diubah menjadi DIBATALKAN',
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text('Konfirmasi'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
275
lib/app/modules/petugas_bumdes/views/petugas_laporan_view.dart
Normal file
275
lib/app/modules/petugas_bumdes/views/petugas_laporan_view.dart
Normal file
@ -0,0 +1,275 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import '../controllers/petugas_laporan_controller.dart';
|
||||
import '../controllers/petugas_bumdes_dashboard_controller.dart';
|
||||
import '../widgets/petugas_side_navbar.dart';
|
||||
import '../../../theme/app_colors_petugas.dart';
|
||||
|
||||
class PetugasLaporanView extends GetView<PetugasLaporanController> {
|
||||
const PetugasLaporanView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Get dashboard controller for side navbar
|
||||
final dashboardController = Get.find<PetugasBumdesDashboardController>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Laporan Bulanan'),
|
||||
backgroundColor: AppColorsPetugas.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Filter Section
|
||||
Card(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Filter Laporan',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => DropdownButtonFormField<int>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Bulan',
|
||||
border: OutlineInputBorder(),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
value: controller.selectedMonth.value,
|
||||
items:
|
||||
controller.months.map<DropdownMenuItem<int>>((
|
||||
month,
|
||||
) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: month['value'] as int,
|
||||
child: Text(month['label'] as String),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: controller.onMonthChanged,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => DropdownButtonFormField<int>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Tahun',
|
||||
border: OutlineInputBorder(),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
value: controller.selectedYear.value,
|
||||
items:
|
||||
controller.years.map<DropdownMenuItem<int>>((
|
||||
year,
|
||||
) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: year,
|
||||
child: Text(year.toString()),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: controller.onYearChanged,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => ElevatedButton.icon(
|
||||
onPressed:
|
||||
controller.isLoading.value
|
||||
? null
|
||||
: controller.generateReport,
|
||||
icon:
|
||||
controller.isLoading.value
|
||||
? Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
padding: const EdgeInsets.all(2.0),
|
||||
child: const CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 3,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
label: Text(
|
||||
controller.isLoading.value
|
||||
? 'Memproses...'
|
||||
: 'Generate Laporan',
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 12,
|
||||
),
|
||||
disabledBackgroundColor: AppColorsPetugas
|
||||
.blueGrotto
|
||||
.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Report Preview Section
|
||||
Expanded(
|
||||
child: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Menghasilkan laporan...'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!controller.isPdfReady.value ||
|
||||
controller.pdfBytes.value == null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.description_outlined,
|
||||
size: 80,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Belum ada laporan',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Pilih bulan dan tahun lalu klik "Generate Laporan"',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Preview Laporan',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: Card(
|
||||
elevation: 2,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: PdfPreview(
|
||||
build: (format) => controller.pdfBytes.value!,
|
||||
canChangeOrientation: false,
|
||||
canChangePageFormat: false,
|
||||
canDebug: false,
|
||||
allowPrinting: false,
|
||||
allowSharing: false,
|
||||
initialPageFormat: PdfPageFormat.a4,
|
||||
pdfFileName:
|
||||
'Laporan_${controller.reportData['period']?['monthName'] ?? ''}_${controller.reportData['period']?['year'] ?? ''}.pdf',
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: controller.savePdf,
|
||||
icon: const Icon(Icons.save_alt),
|
||||
label: const Text('Simpan PDF'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: controller.printPdf,
|
||||
icon: const Icon(Icons.print),
|
||||
label: const Text('Cetak'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -376,7 +376,6 @@ class PetugasPaketView extends GetView<PetugasPaketController> {
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _showPaketDetails(context, paket),
|
||||
child: Row(
|
||||
children: [
|
||||
// Paket image or icon
|
||||
@ -796,294 +795,104 @@ class PetugasPaketView extends GetView<PetugasPaketController> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showPaketDetails(BuildContext context, dynamic paket) {
|
||||
// Handle both Map and PaketModel for backward compatibility
|
||||
final isPaketModel = paket is PaketModel;
|
||||
final String nama =
|
||||
isPaketModel
|
||||
? paket.nama
|
||||
: (paket['nama']?.toString() ?? 'Paket Tanpa Nama');
|
||||
final String? deskripsi =
|
||||
isPaketModel ? paket.deskripsi : paket['deskripsi']?.toString();
|
||||
final bool isAvailable =
|
||||
isPaketModel
|
||||
? (paket.kuantitas > 0)
|
||||
: ((paket['kuantitas'] as int?) ?? 0) > 0;
|
||||
final dynamic harga =
|
||||
isPaketModel
|
||||
? (paket.satuanWaktuSewa.isNotEmpty
|
||||
? paket.satuanWaktuSewa.first['harga']
|
||||
: paket.harga)
|
||||
: (paket['harga'] ?? 0);
|
||||
// Items are not part of the PaketModel, so we'll use an empty list
|
||||
final List<Map<String, dynamic>> items = [];
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.75,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
nama,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: AppColorsPetugas.blueGrotto),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Card(
|
||||
margin: EdgeInsets.zero,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDetailItem(
|
||||
'Harga',
|
||||
'Rp ${_formatPrice(harga)}',
|
||||
),
|
||||
_buildDetailItem(
|
||||
'Status',
|
||||
isAvailable ? 'Tersedia' : 'Tidak Tersedia',
|
||||
),
|
||||
_buildDetailItem('Deskripsi', deskripsi ?? '-'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Item dalam Paket',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
margin: EdgeInsets.zero,
|
||||
child: ListView.separated(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: items.length,
|
||||
separatorBuilder:
|
||||
(context, index) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: AppColorsPetugas.babyBlue,
|
||||
child: Icon(
|
||||
Icons.inventory_2_outlined,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
title: Text(item['nama']),
|
||||
trailing: Text(
|
||||
'${item['jumlah']} unit',
|
||||
style: TextStyle(
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Get.toNamed(
|
||||
Routes.PETUGAS_TAMBAH_PAKET,
|
||||
arguments: paket,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.edit),
|
||||
label: const Text('Edit'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColorsPetugas.blueGrotto,
|
||||
side: BorderSide(color: AppColorsPetugas.blueGrotto),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_showDeleteConfirmation(context, paket);
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Hapus'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailItem(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 14, color: AppColorsPetugas.blueGrotto),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddEditPaketDialog(BuildContext context, {dynamic paket}) {
|
||||
// Handle both Map and PaketModel for backward compatibility
|
||||
final isPaketModel = paket is PaketModel;
|
||||
final String? id = isPaketModel ? paket.id : paket?['id'];
|
||||
final String title = id == null ? 'Tambah Paket' : 'Edit Paket';
|
||||
final isEditing = paket != null;
|
||||
|
||||
// This would be implemented with proper form validation in a real app
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(color: AppColorsPetugas.navyBlue),
|
||||
),
|
||||
content: const Text(
|
||||
'Form pengelolaan paket akan ditampilkan di sini dengan field untuk nama, kategori, harga, deskripsi, status, dan item-item dalam paket.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(
|
||||
'Batal',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
// In a real app, we would save the form data
|
||||
Get.snackbar(
|
||||
isEditing ? 'Paket Diperbarui' : 'Paket Ditambahkan',
|
||||
isEditing
|
||||
? 'Paket berhasil diperbarui'
|
||||
: 'Paket baru berhasil ditambahkan',
|
||||
backgroundColor: AppColorsPetugas.success,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.blueGrotto,
|
||||
),
|
||||
child: Text(isEditing ? 'Simpan' : 'Tambah'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteConfirmation(BuildContext context, dynamic paket) {
|
||||
// Handle both Map and PaketModel for backward compatibility
|
||||
final isPaketModel = paket is PaketModel;
|
||||
final String id = isPaketModel ? paket.id : (paket['id']?.toString() ?? '');
|
||||
final String nama =
|
||||
isPaketModel ? paket.nama : (paket['nama']?.toString() ?? 'Paket');
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
'Konfirmasi Hapus',
|
||||
style: TextStyle(color: AppColorsPetugas.navyBlue),
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
content: Text('Apakah Anda yakin ingin menghapus paket "$nama"?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(
|
||||
'Batal',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Warning icon
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.errorLight,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.delete_forever,
|
||||
color: AppColorsPetugas.error,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Title and message
|
||||
Text(
|
||||
'Konfirmasi Hapus',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
Text(
|
||||
'Apakah Anda yakin ingin menghapus paket "$nama"? Tindakan ini tidak dapat dibatalkan.',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColorsPetugas.textPrimary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Action buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColorsPetugas.textPrimary,
|
||||
side: BorderSide(color: AppColorsPetugas.divider),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
controller.deletePaket(id);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: const Text('Hapus'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
controller.deletePaket(id);
|
||||
Get.snackbar(
|
||||
'Paket Dihapus',
|
||||
'Paket berhasil dihapus dari sistem',
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
colorText: Colors.white,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColorsPetugas.error,
|
||||
),
|
||||
child: const Text('Hapus'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
724
lib/app/modules/petugas_bumdes/views/petugas_penyewa_view.dart
Normal file
724
lib/app/modules/petugas_bumdes/views/petugas_penyewa_view.dart
Normal file
@ -0,0 +1,724 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/petugas_penyewa_controller.dart';
|
||||
import '../controllers/petugas_bumdes_dashboard_controller.dart';
|
||||
import '../../../theme/app_colors_petugas.dart';
|
||||
import '../widgets/petugas_bumdes_bottom_navbar.dart';
|
||||
import '../widgets/petugas_side_navbar.dart';
|
||||
import '../../../routes/app_routes.dart';
|
||||
|
||||
class PetugasPenyewaView extends StatefulWidget {
|
||||
const PetugasPenyewaView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PetugasPenyewaView> createState() => _PetugasPenyewaViewState();
|
||||
}
|
||||
|
||||
class _PetugasPenyewaViewState extends State<PetugasPenyewaView>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
late PetugasPenyewaController controller;
|
||||
late PetugasBumdesDashboardController dashboardController;
|
||||
|
||||
final List<String> tabTitles = ['Verifikasi', 'Aktif', 'Ditangguhkan'];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = Get.find<PetugasPenyewaController>();
|
||||
dashboardController = Get.find<PetugasBumdesDashboardController>();
|
||||
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
|
||||
// Add listener to sync tab selection with controller's filter
|
||||
_tabController.addListener(_onTabChanged);
|
||||
}
|
||||
|
||||
void _onTabChanged() {
|
||||
if (!_tabController.indexIsChanging) {
|
||||
controller.changeTab(_tabController.index);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.removeListener(_onTabChanged);
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
dashboardController.changeTab(0);
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'Daftar Penyewa',
|
||||
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
|
||||
),
|
||||
backgroundColor: AppColorsPetugas.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(60),
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: true,
|
||||
indicator: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicatorPadding: const EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
horizontal: 4,
|
||||
),
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white.withOpacity(0.7),
|
||||
labelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
unselectedLabelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 14,
|
||||
),
|
||||
tabs:
|
||||
tabTitles
|
||||
.map(
|
||||
(title) => Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
child: Tab(text: title),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
dividerColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
drawer: PetugasSideNavbar(controller: dashboardController),
|
||||
drawerEdgeDragWidth: 60,
|
||||
drawerScrimColor: Colors.black.withOpacity(0.6),
|
||||
backgroundColor: Colors.grey.shade50,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildSearchBar(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children:
|
||||
[0, 1, 2].map((index) {
|
||||
return Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
strokeWidth: 3,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Memuat data...',
|
||||
style: TextStyle(
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (controller.filteredPenyewaList.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return _buildPenyewaList();
|
||||
});
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: Obx(
|
||||
() => PetugasBumdesBottomNavbar(
|
||||
selectedIndex: dashboardController.currentTabIndex.value,
|
||||
onItemTapped: (index) => dashboardController.changeTab(index),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
// Add controller for TextField so it can be cleared
|
||||
final TextEditingController searchController = TextEditingController(
|
||||
text: controller.searchQuery.value,
|
||||
);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.03),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
controller: searchController,
|
||||
onChanged: controller.updateSearchQuery,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Cari nama atau email...',
|
||||
hintStyle: TextStyle(color: Colors.grey.shade400, fontSize: 14),
|
||||
prefixIcon: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Icon(
|
||||
Icons.search_rounded,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.grey.shade50,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
isDense: true,
|
||||
suffixIcon: Obx(
|
||||
() =>
|
||||
controller.searchQuery.value.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
searchController.clear();
|
||||
controller.updateSearchQuery('');
|
||||
},
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.people_outline, size: 80, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Obx(() {
|
||||
String message = 'Belum ada data penyewa';
|
||||
|
||||
if (controller.searchQuery.isNotEmpty) {
|
||||
message = 'Tidak ada hasil yang cocok dengan pencarian';
|
||||
} else {
|
||||
switch (controller.currentTabIndex.value) {
|
||||
case 0:
|
||||
message = 'Tidak ada penyewa yang menunggu verifikasi';
|
||||
break;
|
||||
case 1:
|
||||
message = 'Tidak ada penyewa aktif';
|
||||
break;
|
||||
case 2:
|
||||
message = 'Tidak ada penyewa yang ditangguhkan';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Data penyewa akan muncul di sini',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPenyewaList() {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: controller.filteredPenyewaList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final penyewa = controller.filteredPenyewaList[index];
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header with avatar and badge
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.babyBlueLight.withOpacity(0.2),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar with border
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: CircleAvatar(
|
||||
radius: 24,
|
||||
backgroundColor: AppColorsPetugas.babyBlueLight,
|
||||
backgroundImage:
|
||||
penyewa['avatar'] != null &&
|
||||
penyewa['avatar']
|
||||
.toString()
|
||||
.isNotEmpty
|
||||
? NetworkImage(penyewa['avatar'])
|
||||
: null,
|
||||
child:
|
||||
penyewa['avatar'] == null ||
|
||||
penyewa['avatar'].toString().isEmpty
|
||||
? const Icon(
|
||||
Icons.person,
|
||||
color: Colors.white,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// Name and email
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
penyewa['nama_lengkap'] ??
|
||||
'Nama tidak tersedia',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.navyBlue,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.email_outlined,
|
||||
size: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
penyewa['email'] ??
|
||||
'Email tidak tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildStatusBadge(penyewa['status']),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Content section
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Show additional info only for Aktif and Ditangguhkan tabs
|
||||
if (controller.currentTabIndex.value != 0) ...[
|
||||
Row(
|
||||
children: [
|
||||
_buildInfoChip(
|
||||
Icons.credit_card_outlined,
|
||||
'NIK: ${penyewa['nik'] ?? 'Tidak tersedia'}',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildInfoChip(
|
||||
Icons.phone_outlined,
|
||||
penyewa['no_hp'] ?? 'No. HP tidak tersedia',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildInfoTile(
|
||||
'Total Sewa',
|
||||
penyewa['total_sewa']?.toString() ?? '0',
|
||||
Icons.shopping_bag_outlined,
|
||||
AppColorsPetugas.blueGrotto,
|
||||
),
|
||||
if (controller.currentTabIndex.value == 1 ||
|
||||
controller.currentTabIndex.value == 2)
|
||||
_buildActionChip(
|
||||
label: 'Lihat Detail',
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
icon: Icons.visibility,
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
Routes.PETUGAS_DETAIL_PENYEWA,
|
||||
arguments: {
|
||||
'userId': penyewa['user_id'],
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
// Add "Detail" button for Verifikasi tab
|
||||
if (controller.currentTabIndex.value == 0) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildActionChip(
|
||||
label: 'Lihat Detail & Verifikasi',
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
icon: Icons.visibility,
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
Routes.PETUGAS_DETAIL_PENYEWA,
|
||||
arguments: {
|
||||
'userId': penyewa['user_id'],
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoChip(IconData icon, String label) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: Colors.grey[600]),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[700],
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionChip({
|
||||
required String label,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
IconData? icon,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: color.withOpacity(0.5)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (icon != null) ...[
|
||||
Icon(icon, size: 14, color: color),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoTile(
|
||||
String label,
|
||||
String value,
|
||||
IconData icon,
|
||||
Color color,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, size: 14, color: color),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 11, color: Colors.grey[600]),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusBadge(String? status) {
|
||||
Color bgColor;
|
||||
Color textColor;
|
||||
String label;
|
||||
|
||||
switch (status?.toLowerCase()) {
|
||||
case 'active':
|
||||
bgColor = Colors.green[100]!;
|
||||
textColor = Colors.green[800]!;
|
||||
label = 'Aktif';
|
||||
break;
|
||||
case 'pending':
|
||||
bgColor = Colors.orange[100]!;
|
||||
textColor = Colors.orange[800]!;
|
||||
label = 'Menunggu';
|
||||
break;
|
||||
case 'suspended':
|
||||
bgColor = Colors.red[100]!;
|
||||
textColor = Colors.red[800]!;
|
||||
label = 'Dinonaktifkan';
|
||||
break;
|
||||
default:
|
||||
bgColor = Colors.grey[100]!;
|
||||
textColor = Colors.grey[800]!;
|
||||
label = 'Tidak diketahui';
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showApproveDialog(BuildContext context, String userId) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('Konfirmasi Aktivasi'),
|
||||
content: const Text(
|
||||
'Apakah Anda yakin ingin mengaktifkan penyewa ini?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
controller.updatePenyewaStatus(
|
||||
userId,
|
||||
'active',
|
||||
'Akun diaktifkan oleh petugas',
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Aktifkan'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showRejectDialog(BuildContext context, String userId) {
|
||||
final reasonController = TextEditingController();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('Konfirmasi Penolakan'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Apakah Anda yakin ingin menolak penyewa ini?'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: reasonController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Alasan Penolakan',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
maxLines: 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Batal'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
final reason =
|
||||
reasonController.text.isNotEmpty
|
||||
? reasonController.text
|
||||
: 'Ditolak oleh petugas';
|
||||
controller.updatePenyewaStatus(userId, 'suspended', reason);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Tolak'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -481,25 +481,26 @@ class _PetugasSewaViewState extends State<PetugasSewaView>
|
||||
),
|
||||
),
|
||||
|
||||
// Price
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.blueGrotto.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
controller.formatPrice(sewa.totalTagihan),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
// Price - only show if total_tagihan > 0
|
||||
if (sewa.totalTagihan > 0)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColorsPetugas.blueGrotto.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
controller.formatPrice(sewa.totalTagihan),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColorsPetugas.blueGrotto,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -574,7 +575,7 @@ class _PetugasSewaViewState extends State<PetugasSewaView>
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${sewa.waktuMulai.toIso8601String().substring(0, 10)} - ${sewa.waktuSelesai.toIso8601String().substring(0, 10)}',
|
||||
_formatDateRange(sewa),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColorsPetugas.textSecondary,
|
||||
@ -602,6 +603,37 @@ class _PetugasSewaViewState extends State<PetugasSewaView>
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDateRange(SewaModel sewa) {
|
||||
final startDate = sewa.waktuMulai;
|
||||
final endDate = sewa.waktuSelesai;
|
||||
|
||||
// Format dates as dd-mm-yyyy
|
||||
String formattedStartDate =
|
||||
'${startDate.day.toString().padLeft(2, '0')}-${startDate.month.toString().padLeft(2, '0')}-${startDate.year}';
|
||||
String formattedEndDate =
|
||||
'${endDate.day.toString().padLeft(2, '0')}-${endDate.month.toString().padLeft(2, '0')}-${endDate.year}';
|
||||
|
||||
// Check if rental unit is "jam" (hour)
|
||||
if (sewa.namaSatuanWaktu?.toLowerCase() == 'jam') {
|
||||
// Format as "dd-mm-yyyy icon jam 09.00-15.00"
|
||||
String startTime =
|
||||
'${startDate.hour.toString().padLeft(2, '0')}.${startDate.minute.toString().padLeft(2, '0')}';
|
||||
String endTime =
|
||||
'${endDate.hour.toString().padLeft(2, '0')}.${endDate.minute.toString().padLeft(2, '0')}';
|
||||
return '$formattedStartDate ⏱ $startTime-$endTime';
|
||||
}
|
||||
// If same day but not hourly, just show the date
|
||||
else if (startDate.day == endDate.day &&
|
||||
startDate.month == endDate.month &&
|
||||
startDate.year == endDate.year) {
|
||||
return formattedStartDate;
|
||||
}
|
||||
// Different days - show date range
|
||||
else {
|
||||
return '$formattedStartDate - $formattedEndDate';
|
||||
}
|
||||
}
|
||||
|
||||
void _showFilterBottomSheet() {
|
||||
Get.bottomSheet(
|
||||
Container(
|
||||
|
@ -64,6 +64,14 @@ class PetugasBumdesBottomNavbar extends StatelessWidget {
|
||||
isSelected: selectedIndex == 3,
|
||||
onTap: () => onItemTapped(3),
|
||||
),
|
||||
_buildNavItem(
|
||||
context: context,
|
||||
icon: Icons.people_outlined,
|
||||
activeIcon: Icons.people,
|
||||
label: 'Penyewa',
|
||||
isSelected: selectedIndex == 4,
|
||||
onTap: () => onItemTapped(4),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -79,7 +87,7 @@ class PetugasBumdesBottomNavbar extends StatelessWidget {
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
final primaryColor = AppColors.primary;
|
||||
final tabWidth = MediaQuery.of(context).size.width / 4;
|
||||
final tabWidth = MediaQuery.of(context).size.width / 5;
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
|
@ -3,6 +3,7 @@ import 'package:get/get.dart';
|
||||
import '../../../theme/app_colors.dart';
|
||||
import '../../../theme/app_colors_petugas.dart';
|
||||
import '../controllers/petugas_bumdes_dashboard_controller.dart';
|
||||
import '../../../routes/app_routes.dart';
|
||||
|
||||
class PetugasSideNavbar extends StatelessWidget {
|
||||
final PetugasBumdesDashboardController controller;
|
||||
@ -148,6 +149,30 @@ class PetugasSideNavbar extends StatelessWidget {
|
||||
isSelected: controller.currentTabIndex.value == 3,
|
||||
onTap: () => controller.changeTab(3),
|
||||
),
|
||||
_buildMenuItem(
|
||||
icon: Icons.people_outlined,
|
||||
activeIcon: Icons.people,
|
||||
title: 'Penyewa',
|
||||
subtitle: 'Kelola data penyewa',
|
||||
isSelected: controller.currentTabIndex.value == 4,
|
||||
onTap: () => controller.changeTab(4),
|
||||
),
|
||||
_buildMenuItem(
|
||||
icon: Icons.account_balance_outlined,
|
||||
activeIcon: Icons.account_balance,
|
||||
title: 'Kelola Akun Bank',
|
||||
subtitle: 'Kelola akun bank BUMDes',
|
||||
isSelected: false,
|
||||
onTap: () => Get.toNamed(Routes.PETUGAS_AKUN_BANK),
|
||||
),
|
||||
_buildMenuItem(
|
||||
icon: Icons.bar_chart_outlined,
|
||||
activeIcon: Icons.bar_chart,
|
||||
title: 'Laporan Bulanan',
|
||||
subtitle: 'Cetak laporan bulanan',
|
||||
isSelected: false,
|
||||
onTap: () => Get.toNamed(Routes.PETUGAS_LAPORAN),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user