187 lines
7.7 KiB
Dart
187 lines
7.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../controllers/companies_management_controller.dart';
|
|
import 'add_company_view.dart';
|
|
import '../../../core/utils/app_snackbar.dart';
|
|
import '../../../app/routes/app_pages.dart';
|
|
|
|
class CompaniesManagementView extends StatelessWidget {
|
|
const CompaniesManagementView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Put controller directly so we don't strictly need a binding for this nested route
|
|
final controller = Get.put(CompaniesManagementController());
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('إدارة الشركات', style: TextStyle(fontFamily: 'El Messiri')),
|
|
centerTitle: true,
|
|
backgroundColor: const Color(0xFF0F4C81),
|
|
foregroundColor: Colors.white,
|
|
elevation: 0,
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.add),
|
|
onPressed: () {
|
|
Get.to(() => const AddCompanyView());
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: Obx(() {
|
|
if (controller.isLoading.value) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
if (controller.companies.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.business_center_outlined, size: 80, color: Colors.grey.shade400),
|
|
const SizedBox(height: 16),
|
|
const Text('لا يوجد شركات مسجلة', style: TextStyle(fontSize: 18, color: Colors.grey)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: controller.fetchCompanies,
|
|
child: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: controller.companies.length,
|
|
itemBuilder: (context, index) {
|
|
final company = controller.companies[index];
|
|
return Card(
|
|
elevation: 2,
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF0F4C81).withValues(alpha: 0.1),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(Icons.business, color: Color(0xFF0F4C81)),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
company['name'] ?? 'شركة',
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
PopupMenuButton(
|
|
icon: const Icon(Icons.more_vert),
|
|
itemBuilder: (context) => [
|
|
const PopupMenuItem(value: 'edit', child: Text('تعديل البيانات')),
|
|
const PopupMenuItem(value: 'employees', child: Text('إدارة الموظفين')),
|
|
const PopupMenuItem(value: 'delete', child: Text('حذف الشركة', style: TextStyle(color: Colors.red))),
|
|
],
|
|
onSelected: (value) {
|
|
if (value == 'delete') {
|
|
_confirmDelete(context, controller, company['id']);
|
|
} else if (value == 'employees') {
|
|
Get.toNamed(AppRoutes.USERS_MANAGEMENT);
|
|
} else {
|
|
AppSnackbar.showInfo('قريباً', 'سيتم تفعيل هذه الميزة قريباً');
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
_buildDetailChip(Icons.numbers, company['tax_identification_number'] ?? 'غير محدد', isDark),
|
|
const SizedBox(width: 8),
|
|
if (company['is_jofotara_connected'] == true || company['is_jofotara_connected'] == 1) ...[
|
|
_buildDetailChip(Icons.link, 'مرتبطة بجوفوتارا', isDark, color: const Color(0xFF10B981)),
|
|
const SizedBox(width: 8),
|
|
],
|
|
if (company['tenant_name'] != null)
|
|
Expanded(
|
|
child: _buildDetailChip(Icons.account_balance, company['tenant_name'], isDark, color: Colors.blueAccent),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton.icon(
|
|
onPressed: () => AppSnackbar.showInfo('إحصائيات', 'عرض إحصائيات الشركة'),
|
|
icon: const Icon(Icons.bar_chart, size: 18),
|
|
label: const Text('الإحصائيات'),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
Widget _buildDetailChip(IconData icon, String text, bool isDark, {Color? color}) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: (color ?? Colors.grey).withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 14, color: color ?? (isDark ? Colors.white70 : Colors.black54)),
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
color: color ?? (isDark ? Colors.white70 : Colors.black87),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _confirmDelete(BuildContext context, CompaniesManagementController controller, String id) {
|
|
Get.defaultDialog(
|
|
title: 'حذف الشركة',
|
|
middleText: 'هل أنت متأكد من رغبتك في حذف هذه الشركة نهائياً؟',
|
|
textConfirm: 'حذف',
|
|
textCancel: 'إلغاء',
|
|
confirmTextColor: Colors.white,
|
|
buttonColor: Colors.red,
|
|
onConfirm: () {
|
|
Get.back();
|
|
controller.deleteCompany(id);
|
|
},
|
|
);
|
|
}
|
|
}
|