Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
// transit_admin_controller.dart — تحكم شاشات مواصلاتي (لوحة إدارة سيرو)
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'transit_admin_models.dart';
|
||||
import 'transit_admin_service.dart';
|
||||
|
||||
class TransitAdminController extends GetxController {
|
||||
bool isLoadingList = false;
|
||||
List<TransitOrgSummary> orgs = [];
|
||||
String? filterCountry;
|
||||
String? filterType;
|
||||
String? filterStatus;
|
||||
String searchQuery = '';
|
||||
|
||||
bool isLoadingDetails = false;
|
||||
TransitOrgDetails? selectedOrgDetails;
|
||||
|
||||
bool isCreating = false;
|
||||
|
||||
// ── مشرفو المؤسسة ────────────────────────────────────────────
|
||||
bool isLoadingAdmins = false;
|
||||
List<Map<String, dynamic>> orgAdmins = [];
|
||||
bool isSavingAdmin = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchOrgs();
|
||||
}
|
||||
|
||||
Future<void> fetchOrgs() async {
|
||||
isLoadingList = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.listOrgs(
|
||||
country: filterCountry,
|
||||
type: filterType,
|
||||
contractStatus: filterStatus,
|
||||
search: searchQuery,
|
||||
);
|
||||
if (res.success) orgs = res.data ?? [];
|
||||
isLoadingList = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> loadOrgDetails(int orgId) async {
|
||||
isLoadingDetails = true;
|
||||
selectedOrgDetails = null;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.getOrgDetails(orgId);
|
||||
if (res.success) selectedOrgDetails = res.data;
|
||||
isLoadingDetails = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> createOrg({
|
||||
required String type,
|
||||
required String country,
|
||||
required String city,
|
||||
required String nameAr,
|
||||
required String nameEn,
|
||||
required String adminName,
|
||||
required String adminPhone,
|
||||
}) async {
|
||||
isCreating = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.createOrg(
|
||||
type: type,
|
||||
country: country,
|
||||
city: city,
|
||||
nameAr: nameAr,
|
||||
nameEn: nameEn,
|
||||
adminName: adminName,
|
||||
adminPhone: adminPhone,
|
||||
);
|
||||
|
||||
isCreating = false;
|
||||
update();
|
||||
|
||||
if (res.success) {
|
||||
await fetchOrgs();
|
||||
return true;
|
||||
}
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> fetchOrgAdmins(int orgId) async {
|
||||
isLoadingAdmins = true;
|
||||
update();
|
||||
final res = await TransitAdminService.listOrgAdmins(orgId);
|
||||
if (res.success) orgAdmins = res.data ?? [];
|
||||
isLoadingAdmins = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> addOrgAdmin({
|
||||
required int orgId,
|
||||
required String name,
|
||||
required String phone,
|
||||
required String role,
|
||||
}) async {
|
||||
isSavingAdmin = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.addOrgAdmin(
|
||||
orgId: orgId,
|
||||
name: name,
|
||||
phone: phone,
|
||||
role: role,
|
||||
);
|
||||
|
||||
isSavingAdmin = false;
|
||||
update();
|
||||
|
||||
if (res.success) {
|
||||
await fetchOrgAdmins(orgId);
|
||||
return true;
|
||||
}
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> toggleOrgAdmin(int orgId, int adminId, bool isActive) async {
|
||||
final res = await TransitAdminService.toggleOrgAdmin(adminId: adminId, isActive: isActive);
|
||||
if (res.success) {
|
||||
await fetchOrgAdmins(orgId);
|
||||
} else {
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// transit_admin_models.dart — نماذج بيانات مواصلاتي (لوحة إدارة سيرو)
|
||||
|
||||
class TransitOrgSummary {
|
||||
final int id;
|
||||
final String type;
|
||||
final String country;
|
||||
final String city;
|
||||
final String nameAr;
|
||||
final String nameEn;
|
||||
final String? logoUrl;
|
||||
final String contractStatus;
|
||||
final String? trialEndsAt;
|
||||
final int driversCount;
|
||||
final int vehiclesCount;
|
||||
final int activeRoutes;
|
||||
final int activeEnrollments;
|
||||
|
||||
TransitOrgSummary({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.country,
|
||||
required this.city,
|
||||
required this.nameAr,
|
||||
required this.nameEn,
|
||||
required this.contractStatus,
|
||||
this.logoUrl,
|
||||
this.trialEndsAt,
|
||||
this.driversCount = 0,
|
||||
this.vehiclesCount = 0,
|
||||
this.activeRoutes = 0,
|
||||
this.activeEnrollments = 0,
|
||||
});
|
||||
|
||||
factory TransitOrgSummary.fromJson(Map<String, dynamic> j) => TransitOrgSummary(
|
||||
id: int.tryParse(j['id'].toString()) ?? 0,
|
||||
type: j['type']?.toString() ?? '',
|
||||
country: j['country']?.toString() ?? '',
|
||||
city: j['city']?.toString() ?? '',
|
||||
nameAr: j['name_ar']?.toString() ?? '',
|
||||
nameEn: j['name_en']?.toString() ?? '',
|
||||
logoUrl: j['logo_url']?.toString(),
|
||||
contractStatus: j['contract_status']?.toString() ?? '',
|
||||
trialEndsAt: j['trial_ends_at']?.toString(),
|
||||
driversCount: int.tryParse(j['drivers_count']?.toString() ?? '0') ?? 0,
|
||||
vehiclesCount: int.tryParse(j['vehicles_count']?.toString() ?? '0') ?? 0,
|
||||
activeRoutes: int.tryParse(j['active_routes']?.toString() ?? '0') ?? 0,
|
||||
activeEnrollments: int.tryParse(j['active_enrollments']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class TransitOrgDetails {
|
||||
final Map<String, dynamic> org;
|
||||
final Map<String, dynamic> counts;
|
||||
final Map<String, dynamic> trips;
|
||||
final List<dynamic> routes;
|
||||
|
||||
TransitOrgDetails({
|
||||
required this.org,
|
||||
required this.counts,
|
||||
required this.trips,
|
||||
required this.routes,
|
||||
});
|
||||
|
||||
factory TransitOrgDetails.fromJson(Map<String, dynamic> j) => TransitOrgDetails(
|
||||
org: Map<String, dynamic>.from(j['org'] ?? {}),
|
||||
counts: Map<String, dynamic>.from(j['counts'] ?? {}),
|
||||
trips: Map<String, dynamic>.from(j['trips'] ?? {}),
|
||||
routes: (j['routes'] is List) ? List<dynamic>.from(j['routes']) : [],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// transit_admin_service.dart — طبقة الاتصال بـ backend/Admin/transit (لوحة إدارة سيرو)
|
||||
import '../functions/crud.dart';
|
||||
import '../../constant/links.dart';
|
||||
import 'transit_admin_models.dart';
|
||||
|
||||
class TransitApiResult<T> {
|
||||
final bool success;
|
||||
final T? data;
|
||||
final String message;
|
||||
TransitApiResult(this.success, this.data, this.message);
|
||||
}
|
||||
|
||||
class TransitAdminService {
|
||||
static String get _base => '${AppLink.server}/Admin/transit';
|
||||
|
||||
static String _errMsg(dynamic res) {
|
||||
if (res == 'no_internet') return 'تحقق من اتصالك بالإنترنت';
|
||||
if (res == 'token_expired') return 'انتهت الجلسة، حاول مجدداً';
|
||||
if (res is Map && res['message'] is String) return res['message'];
|
||||
return 'حدث خطأ، حاول مجدداً';
|
||||
}
|
||||
|
||||
static Future<TransitApiResult<List<TransitOrgSummary>>> listOrgs({
|
||||
String? country,
|
||||
String? type,
|
||||
String? contractStatus,
|
||||
String? search,
|
||||
}) async {
|
||||
final payload = <String, dynamic>{};
|
||||
if (country != null && country.isNotEmpty) payload['country'] = country;
|
||||
if (type != null && type.isNotEmpty) payload['type'] = type;
|
||||
if (contractStatus != null && contractStatus.isNotEmpty) {
|
||||
payload['contract_status'] = contractStatus;
|
||||
}
|
||||
if (search != null && search.isNotEmpty) payload['search'] = search;
|
||||
|
||||
final res = await CRUD().post(link: '$_base/org/list.php', payload: payload);
|
||||
|
||||
if (res is Map && res['status'] == 'success' && res['message'] is Map) {
|
||||
final msg = res['message'] as Map;
|
||||
final list = (msg['orgs'] is List)
|
||||
? (msg['orgs'] as List)
|
||||
.map((o) => TransitOrgSummary.fromJson(Map<String, dynamic>.from(o)))
|
||||
.toList()
|
||||
: <TransitOrgSummary>[];
|
||||
return TransitApiResult(true, list, 'ok');
|
||||
}
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
|
||||
static Future<TransitApiResult<TransitOrgDetails>> getOrgDetails(int orgId) async {
|
||||
final res = await CRUD().post(
|
||||
link: '$_base/org/details.php',
|
||||
payload: {'org_id': orgId.toString()},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success' && res['message'] is Map) {
|
||||
return TransitApiResult(
|
||||
true, TransitOrgDetails.fromJson(Map<String, dynamic>.from(res['message'])), 'ok');
|
||||
}
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
|
||||
static Future<TransitApiResult<Map<String, dynamic>>> createOrg({
|
||||
required String type,
|
||||
required String country,
|
||||
required String city,
|
||||
required String nameAr,
|
||||
required String nameEn,
|
||||
required String adminName,
|
||||
required String adminPhone,
|
||||
String? contactPhone,
|
||||
String? contactEmail,
|
||||
String? website,
|
||||
}) async {
|
||||
final res = await CRUD().post(link: '$_base/org/create.php', payload: {
|
||||
'type': type,
|
||||
'country': country,
|
||||
'city': city,
|
||||
'name_ar': nameAr,
|
||||
'name_en': nameEn,
|
||||
'admin_name': adminName,
|
||||
'admin_phone': adminPhone,
|
||||
if (contactPhone != null) 'contact_phone': contactPhone,
|
||||
if (contactEmail != null) 'contact_email': contactEmail,
|
||||
if (website != null) 'website': website,
|
||||
});
|
||||
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
return TransitApiResult(true, Map<String, dynamic>.from(res['message'] ?? {}), 'ok');
|
||||
}
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
|
||||
// ── مشرفو المؤسسة ────────────────────────────────────────────
|
||||
|
||||
static Future<TransitApiResult<List<Map<String, dynamic>>>> listOrgAdmins(
|
||||
int orgId) async {
|
||||
final res = await CRUD().post(
|
||||
link: '$_base/org/admins_list.php',
|
||||
payload: {'org_id': orgId.toString()},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success' && res['message'] is Map) {
|
||||
final msg = res['message'] as Map;
|
||||
final list = (msg['admins'] is List)
|
||||
? (msg['admins'] as List).map((a) => Map<String, dynamic>.from(a)).toList()
|
||||
: <Map<String, dynamic>>[];
|
||||
return TransitApiResult(true, list, 'ok');
|
||||
}
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
|
||||
static Future<TransitApiResult<void>> addOrgAdmin({
|
||||
required int orgId,
|
||||
required String name,
|
||||
required String phone,
|
||||
required String role,
|
||||
}) async {
|
||||
final res = await CRUD().post(link: '$_base/org/admin_add.php', payload: {
|
||||
'org_id': orgId.toString(),
|
||||
'name': name,
|
||||
'phone': phone,
|
||||
'role': role,
|
||||
});
|
||||
if (res is Map && res['status'] == 'success') return TransitApiResult(true, null, 'ok');
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
|
||||
static Future<TransitApiResult<void>> toggleOrgAdmin({
|
||||
required int adminId,
|
||||
required bool isActive,
|
||||
}) async {
|
||||
final res = await CRUD().post(link: '$_base/org/admin_toggle.php', payload: {
|
||||
'admin_id': adminId.toString(),
|
||||
'is_active': isActive ? '1' : '0',
|
||||
});
|
||||
if (res is Map && res['status'] == 'success') return TransitApiResult(true, null, 'ok');
|
||||
return TransitApiResult(false, null, _errMsg(res));
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import 'static/advanced_analytics_page.dart';
|
||||
import 'financial/financial_v2_page.dart';
|
||||
import 'security/audit_logs_page.dart';
|
||||
import 'analytics/live_analytics_page.dart';
|
||||
import '../transit/org_list_page.dart';
|
||||
|
||||
class AdminHomePage extends StatefulWidget {
|
||||
const AdminHomePage({super.key});
|
||||
@@ -747,6 +748,13 @@ class _AdminHomePageState extends State<AdminHomePage>
|
||||
() => Get.to(() => SiroTrackerScreen())),
|
||||
],
|
||||
),
|
||||
ActionCategory(
|
||||
title: 'مواصلاتي',
|
||||
items: [
|
||||
ActionItem('المؤسسات', Icons.directions_bus_filled_rounded, _accent,
|
||||
() => Get.to(() => const TransitOrgListPage())),
|
||||
],
|
||||
),
|
||||
ActionCategory(
|
||||
title: 'إدارة النظام الجديد',
|
||||
items: [
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
// org_admins_page.dart — متابعة إدارة المؤسسة وإضافة المشرفين (لوحة إدارة سيرو)
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../controller/transit/transit_admin_controller.dart';
|
||||
|
||||
class TransitOrgAdminsPage extends StatefulWidget {
|
||||
final int orgId;
|
||||
final String orgName;
|
||||
const TransitOrgAdminsPage({super.key, required this.orgId, required this.orgName});
|
||||
|
||||
@override
|
||||
State<TransitOrgAdminsPage> createState() => _TransitOrgAdminsPageState();
|
||||
}
|
||||
|
||||
class _TransitOrgAdminsPageState extends State<TransitOrgAdminsPage> {
|
||||
final _name = TextEditingController();
|
||||
final _phone = TextEditingController();
|
||||
String _role = 'transport_manager';
|
||||
|
||||
final _roles = const {
|
||||
'owner': 'مالك',
|
||||
'transport_manager': 'مدير نقل',
|
||||
'dispatcher': 'منسّق',
|
||||
};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Get.find<TransitAdminController>().fetchOrgAdmins(widget.orgId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<TransitAdminController>(
|
||||
builder: (c) => Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColor.bg,
|
||||
elevation: 0,
|
||||
title: Text('مشرفو ${widget.orgName}',
|
||||
style: const TextStyle(color: AppColor.textPrimary)),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: AppColor.accent,
|
||||
onPressed: () => _showAddAdminSheet(context, c),
|
||||
child: const Icon(Icons.person_add_alt_1, color: Colors.white),
|
||||
),
|
||||
body: c.isLoadingAdmins
|
||||
? const Center(child: CircularProgressIndicator(color: AppColor.accent))
|
||||
: c.orgAdmins.isEmpty
|
||||
? const Center(
|
||||
child: Text('لا يوجد مشرفون بعد', style: TextStyle(color: AppColor.textSecondary)))
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: c.orgAdmins.length,
|
||||
itemBuilder: (_, i) => _adminCard(c, c.orgAdmins[i]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _adminCard(TransitAdminController c, Map<String, dynamic> admin) {
|
||||
final isActive = admin['is_active'].toString() == '1';
|
||||
return Card(
|
||||
color: AppColor.surface,
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: AppColor.accentSoft,
|
||||
child: Icon(Icons.person, color: isActive ? AppColor.accent : AppColor.textMuted),
|
||||
),
|
||||
title: Text(admin['name']?.toString() ?? '',
|
||||
style: const TextStyle(color: AppColor.textPrimary, fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(
|
||||
'${admin['phone'] ?? ''} · ${_roles[admin['role']] ?? admin['role']}',
|
||||
style: const TextStyle(color: AppColor.textSecondary, fontSize: 12),
|
||||
),
|
||||
trailing: Switch(
|
||||
value: isActive,
|
||||
activeThumbColor: AppColor.success,
|
||||
onChanged: (v) => c.toggleOrgAdmin(widget.orgId, int.parse(admin['id'].toString()), v),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddAdminSheet(BuildContext context, TransitAdminController c) {
|
||||
_name.clear();
|
||||
_phone.clear();
|
||||
_role = 'transport_manager';
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: AppColor.surface,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (ctx) => StatefulBuilder(
|
||||
builder: (ctx, setSheetState) => GetBuilder<TransitAdminController>(
|
||||
builder: (c) => Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: 20,
|
||||
bottom: MediaQuery.of(ctx).viewInsets.bottom + 20,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('إضافة مشرف جديد',
|
||||
style: TextStyle(
|
||||
color: AppColor.textPrimary, fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _name,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
decoration: _inputDecoration('اسم المشرف'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _phone,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
decoration: _inputDecoration('رقم الهاتف'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: _role,
|
||||
dropdownColor: AppColor.surface,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
decoration: _inputDecoration('الصلاحية'),
|
||||
items: _roles.entries
|
||||
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
|
||||
.toList(),
|
||||
onChanged: (v) => setSheetState(() => _role = v!),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColor.accent,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
onPressed: c.isSavingAdmin
|
||||
? null
|
||||
: () async {
|
||||
if (_name.text.trim().isEmpty || _phone.text.trim().isEmpty) {
|
||||
Get.snackbar('مواصلاتي', 'الرجاء تعبئة كل الحقول');
|
||||
return;
|
||||
}
|
||||
final ok = await c.addOrgAdmin(
|
||||
orgId: widget.orgId,
|
||||
name: _name.text.trim(),
|
||||
phone: _phone.text.trim(),
|
||||
role: _role,
|
||||
);
|
||||
if (ok && ctx.mounted) Navigator.pop(ctx);
|
||||
},
|
||||
child: c.isSavingAdmin
|
||||
? const SizedBox(
|
||||
height: 20, width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text('إضافة', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _inputDecoration(String label) => InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: const TextStyle(color: AppColor.textSecondary),
|
||||
filled: true,
|
||||
fillColor: AppColor.surfaceElevated,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// org_create_page.dart — إضافة مؤسسة جديدة (لوحة إدارة سيرو)
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../controller/transit/transit_admin_controller.dart';
|
||||
|
||||
class TransitOrgCreatePage extends StatefulWidget {
|
||||
const TransitOrgCreatePage({super.key});
|
||||
|
||||
@override
|
||||
State<TransitOrgCreatePage> createState() => _TransitOrgCreatePageState();
|
||||
}
|
||||
|
||||
class _TransitOrgCreatePageState extends State<TransitOrgCreatePage> {
|
||||
final _nameAr = TextEditingController();
|
||||
final _nameEn = TextEditingController();
|
||||
final _city = TextEditingController();
|
||||
final _adminName = TextEditingController();
|
||||
final _adminPhone = TextEditingController();
|
||||
|
||||
String _type = 'university';
|
||||
String _country = 'JO';
|
||||
|
||||
final _types = const {
|
||||
'university': 'جامعة',
|
||||
'school': 'مدرسة',
|
||||
'hotel': 'فندق',
|
||||
'company': 'شركة',
|
||||
'transporter': 'ناقل',
|
||||
};
|
||||
final _countries = const {'JO': 'الأردن', 'SY': 'سوريا', 'EG': 'مصر'};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<TransitAdminController>(
|
||||
builder: (c) => Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColor.bg,
|
||||
elevation: 0,
|
||||
title: const Text('إضافة مؤسسة', style: TextStyle(color: AppColor.textPrimary)),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_dropdown('نوع المؤسسة', _type, _types, (v) => setState(() => _type = v!)),
|
||||
const SizedBox(height: 12),
|
||||
_dropdown('الدولة', _country, _countries, (v) => setState(() => _country = v!)),
|
||||
const SizedBox(height: 12),
|
||||
_field(_nameAr, 'اسم المؤسسة (عربي)'),
|
||||
const SizedBox(height: 12),
|
||||
_field(_nameEn, 'اسم المؤسسة (إنجليزي)'),
|
||||
const SizedBox(height: 12),
|
||||
_field(_city, 'المدينة'),
|
||||
const SizedBox(height: 20),
|
||||
const Divider(color: AppColor.surfaceElevated),
|
||||
const SizedBox(height: 8),
|
||||
const Text('أول مشرف (owner) لهذه المؤسسة',
|
||||
style: TextStyle(color: AppColor.textSecondary)),
|
||||
const SizedBox(height: 12),
|
||||
_field(_adminName, 'اسم المشرف'),
|
||||
const SizedBox(height: 12),
|
||||
_field(_adminPhone, 'هاتف المشرف', keyboardType: TextInputType.phone),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColor.accent,
|
||||
minimumSize: const Size.fromHeight(50),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
onPressed: c.isCreating ? null : _submit,
|
||||
child: c.isCreating
|
||||
? const SizedBox(
|
||||
height: 20, width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text('إنشاء', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _field(TextEditingController ctrl, String label, {TextInputType? keyboardType}) {
|
||||
return TextField(
|
||||
controller: ctrl,
|
||||
keyboardType: keyboardType,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: const TextStyle(color: AppColor.textSecondary),
|
||||
filled: true,
|
||||
fillColor: AppColor.surface,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _dropdown(String label, String value, Map<String, String> options,
|
||||
void Function(String?) onChanged) {
|
||||
return DropdownButtonFormField<String>(
|
||||
initialValue: value,
|
||||
dropdownColor: AppColor.surface,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: const TextStyle(color: AppColor.textSecondary),
|
||||
filled: true,
|
||||
fillColor: AppColor.surface,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
||||
),
|
||||
items: options.entries
|
||||
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
|
||||
.toList(),
|
||||
onChanged: onChanged,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (_nameAr.text.trim().isEmpty ||
|
||||
_nameEn.text.trim().isEmpty ||
|
||||
_city.text.trim().isEmpty ||
|
||||
_adminName.text.trim().isEmpty ||
|
||||
_adminPhone.text.trim().isEmpty) {
|
||||
Get.snackbar('مواصلاتي', 'الرجاء تعبئة كل الحقول');
|
||||
return;
|
||||
}
|
||||
|
||||
final c = Get.find<TransitAdminController>();
|
||||
final ok = await c.createOrg(
|
||||
type: _type,
|
||||
country: _country,
|
||||
city: _city.text.trim(),
|
||||
nameAr: _nameAr.text.trim(),
|
||||
nameEn: _nameEn.text.trim(),
|
||||
adminName: _adminName.text.trim(),
|
||||
adminPhone: _adminPhone.text.trim(),
|
||||
);
|
||||
|
||||
if (ok && mounted) Get.back(result: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// org_details_page.dart — تفاصيل وتحليلات مؤسسة (لوحة إدارة سيرو)
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../controller/transit/transit_admin_controller.dart';
|
||||
import 'org_admins_page.dart';
|
||||
|
||||
class TransitOrgDetailsPage extends StatefulWidget {
|
||||
final int orgId;
|
||||
final String orgName;
|
||||
const TransitOrgDetailsPage({super.key, required this.orgId, required this.orgName});
|
||||
|
||||
@override
|
||||
State<TransitOrgDetailsPage> createState() => _TransitOrgDetailsPageState();
|
||||
}
|
||||
|
||||
class _TransitOrgDetailsPageState extends State<TransitOrgDetailsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Get.find<TransitAdminController>().loadOrgDetails(widget.orgId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<TransitAdminController>(
|
||||
builder: (c) => Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColor.bg,
|
||||
elevation: 0,
|
||||
title: Text(widget.orgName, style: const TextStyle(color: AppColor.textPrimary)),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'إدارة المشرفين',
|
||||
icon: const Icon(Icons.admin_panel_settings_outlined, color: AppColor.accent),
|
||||
onPressed: () => Get.to(
|
||||
() => TransitOrgAdminsPage(orgId: widget.orgId, orgName: widget.orgName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: c.isLoadingDetails
|
||||
? const Center(child: CircularProgressIndicator(color: AppColor.accent))
|
||||
: c.selectedOrgDetails == null
|
||||
? const Center(
|
||||
child: Text('تعذّر تحميل البيانات', style: TextStyle(color: AppColor.textSecondary)))
|
||||
: _content(c),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(TransitAdminController c) {
|
||||
final d = c.selectedOrgDetails!;
|
||||
final counts = d.counts;
|
||||
final trips = d.trips;
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_sectionTitle('الأسطول'),
|
||||
Row(
|
||||
children: [
|
||||
_statCard('السائقون', '${counts['drivers_active'] ?? 0}/${counts['drivers_total'] ?? 0}',
|
||||
Icons.badge_outlined),
|
||||
const SizedBox(width: 10),
|
||||
_statCard('المركبات', '${counts['vehicles_active'] ?? 0}/${counts['vehicles_total'] ?? 0}',
|
||||
Icons.directions_bus_outlined),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
_statCard('الخطوط النشطة', '${counts['routes_active'] ?? 0}', Icons.route_outlined),
|
||||
const SizedBox(width: 10),
|
||||
_statCard('عضويات نشطة', '${counts['enrollments_active'] ?? 0}', Icons.people_outline),
|
||||
],
|
||||
),
|
||||
if ((int.tryParse(counts['enrollments_pending']?.toString() ?? '0') ?? 0) > 0) ...[
|
||||
const SizedBox(height: 10),
|
||||
_statCard('طلبات بانتظار الموافقة', '${counts['enrollments_pending']}',
|
||||
Icons.pending_actions_outlined, color: AppColor.warning),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
_sectionTitle('الرحلات'),
|
||||
Row(
|
||||
children: [
|
||||
_statCard('اليوم', '${trips['today'] ?? 0}', Icons.today_outlined),
|
||||
const SizedBox(width: 10),
|
||||
_statCard('هذا الأسبوع', '${trips['this_week'] ?? 0}', Icons.date_range_outlined),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
_statCard('هذا الشهر', '${trips['this_month'] ?? 0}', Icons.calendar_month_outlined),
|
||||
const SizedBox(width: 10),
|
||||
_statCard('ساعات القيادة', '${trips['total_hours_driven'] ?? 0}', Icons.timer_outlined),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
_statCard('مكتملة', '${trips['completed'] ?? 0}', Icons.check_circle_outline,
|
||||
color: AppColor.success),
|
||||
const SizedBox(width: 10),
|
||||
_statCard('متوسط التأخير', '${trips['avg_delay_minutes'] ?? 0} د', Icons.timelapse,
|
||||
color: AppColor.warning),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_sectionTitle('الخطوط'),
|
||||
...d.routes.map((r) => Card(
|
||||
color: AppColor.surface,
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: ListTile(
|
||||
title: Text(r['name_ar']?.toString() ?? '',
|
||||
style: const TextStyle(color: AppColor.textPrimary)),
|
||||
subtitle: Text(
|
||||
'${r['stops_count'] ?? 0} محطة · ${r['completed_trips'] ?? 0} رحلة مكتملة',
|
||||
style: const TextStyle(color: AppColor.textSecondary, fontSize: 12),
|
||||
),
|
||||
trailing: Text(
|
||||
r['status']?.toString() ?? '',
|
||||
style: TextStyle(
|
||||
color: r['status'] == 'active' ? AppColor.success : AppColor.textSecondary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sectionTitle(String text) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(text,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textPrimary, fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
);
|
||||
|
||||
Widget _statCard(String label, String value, IconData icon, {Color? color}) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, color: color ?? AppColor.accent, size: 20),
|
||||
const SizedBox(height: 8),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
color: color ?? AppColor.textPrimary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: const TextStyle(color: AppColor.textSecondary, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// org_list_page.dart — قائمة مؤسسات مواصلاتي (لوحة إدارة سيرو)
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../controller/transit/transit_admin_controller.dart';
|
||||
import '../../controller/transit/transit_admin_models.dart';
|
||||
import 'org_create_page.dart';
|
||||
import 'org_details_page.dart';
|
||||
|
||||
class TransitOrgListPage extends StatefulWidget {
|
||||
const TransitOrgListPage({super.key});
|
||||
|
||||
@override
|
||||
State<TransitOrgListPage> createState() => _TransitOrgListPageState();
|
||||
}
|
||||
|
||||
class _TransitOrgListPageState extends State<TransitOrgListPage> {
|
||||
final _searchCtrl = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Get.put(TransitAdminController());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<TransitAdminController>(
|
||||
builder: (c) => Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColor.bg,
|
||||
elevation: 0,
|
||||
title: const Text('مواصلاتي — المؤسسات', style: TextStyle(color: AppColor.textPrimary)),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, color: AppColor.accent),
|
||||
onPressed: () async {
|
||||
final created = await Get.to(() => const TransitOrgCreatePage());
|
||||
if (created == true) c.fetchOrgs();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: TextField(
|
||||
controller: _searchCtrl,
|
||||
style: const TextStyle(color: AppColor.textPrimary),
|
||||
onSubmitted: (v) {
|
||||
c.searchQuery = v;
|
||||
c.fetchOrgs();
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: 'ابحث عن مؤسسة...',
|
||||
hintStyle: const TextStyle(color: AppColor.textSecondary),
|
||||
prefixIcon: const Icon(Icons.search, color: AppColor.textSecondary),
|
||||
filled: true,
|
||||
fillColor: AppColor.surface,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: c.isLoadingList
|
||||
? const Center(child: CircularProgressIndicator(color: AppColor.accent))
|
||||
: c.orgs.isEmpty
|
||||
? const Center(
|
||||
child: Text('لا توجد مؤسسات', style: TextStyle(color: AppColor.textSecondary)),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: c.fetchOrgs,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
itemCount: c.orgs.length,
|
||||
itemBuilder: (_, i) => _orgCard(c.orgs[i]),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _orgCard(TransitOrgSummary org) {
|
||||
Color statusColor;
|
||||
switch (org.contractStatus) {
|
||||
case 'active':
|
||||
statusColor = AppColor.success;
|
||||
break;
|
||||
case 'trial':
|
||||
statusColor = AppColor.info;
|
||||
break;
|
||||
case 'suspended':
|
||||
statusColor = AppColor.warning;
|
||||
break;
|
||||
default:
|
||||
statusColor = AppColor.danger;
|
||||
}
|
||||
|
||||
return Card(
|
||||
color: AppColor.surface,
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
title: Text(org.nameAr,
|
||||
style: const TextStyle(color: AppColor.textPrimary, fontWeight: FontWeight.bold)),
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(org.contractStatus,
|
||||
style: TextStyle(color: statusColor, fontSize: 11)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('${org.city} · ${org.country}',
|
||||
style: const TextStyle(color: AppColor.textSecondary, fontSize: 12)),
|
||||
const Spacer(),
|
||||
Icon(Icons.directions_bus, size: 14, color: AppColor.textSecondary),
|
||||
const SizedBox(width: 2),
|
||||
Text('${org.vehiclesCount}',
|
||||
style: const TextStyle(color: AppColor.textSecondary, fontSize: 12)),
|
||||
const SizedBox(width: 10),
|
||||
Icon(Icons.people, size: 14, color: AppColor.textSecondary),
|
||||
const SizedBox(width: 2),
|
||||
Text('${org.activeEnrollments}',
|
||||
style: const TextStyle(color: AppColor.textSecondary, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_forward_ios, size: 14, color: AppColor.textSecondary),
|
||||
onTap: () => Get.to(() => TransitOrgDetailsPage(orgId: org.id, orgName: org.nameAr)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user