Update: 2026-06-14 22:10:07

This commit is contained in:
Hamza-Ayed
2026-06-14 22:10:08 +03:00
parent 8e3b9eca4d
commit f021ba5a35
21 changed files with 3669 additions and 636 deletions

View File

@@ -16,15 +16,15 @@ class RideLookupController extends GetxController {
String currentStatusFilter = '';
// Whitelist of allowed statuses for the Update Dropdown
// UPDATED: Matches the exact types you requested
// مطابقة لحالات الرحلة الفعلية في قاعدة البيانات
final List<String> statusOptions = const [
'Pending',
'Accepted',
'EnRoute',
'Arrived',
'Started',
'Completed',
'Canceled',
'New', // جديد - بانتظار سائق
'waiting', // في انتظار سائق
'Apply', // سائق قبل الرحلة
'Arrived', // السائق وصل
'Begin', // الرحلة بدأت
'Finished', // مكتملة
'Cancel', // إلغاء
];
String? selectedStatus;
@@ -105,8 +105,12 @@ class RideLookupController extends GetxController {
final d = res;
if (d['status'] == 'success') {
passenger = (d['message'] ?? d)['passenger'];
ride = (d['message'] ?? d)['ride'];
// يستجيب API الجديد بـ user_type, user, rides
final message = d['message'] ?? d;
passenger = message['user']; // user يمكن أن يكون سائقاً أو راكباً
ride = (message['rides'] is List && message['rides'].isNotEmpty)
? message['rides'][0]
: null;
// Hydrate the dropdown for the update section based on the fetched ride
hydrateSelectedFromRide();

View File

@@ -41,6 +41,33 @@ class DriverLocation {
/// 2. GETX CONTROLLER
/// --------------------------------------------------------------------------
/// تطبيع رقم الهاتف تلقائياً حسب الدولة
/// مثال: 0992952235 ← 963992952235 (سوريا)
/// مثال: 079XXXXXXX ← 96279XXXXXXX (أردن)
/// مثال: 010XXXXXXXX ← 2010XXXXXXXX (مصر)
String normalizePhone(String input) {
final clean = input.replaceAll(RegExp(r'\D+'), '');
// Syria: 099XXXXXXX or 9639XXXXXXX
if (clean.length == 10 && clean.startsWith('09'))
return '963${clean.substring(1)}';
if (clean.length == 12 && clean.startsWith('963')) return clean;
if (clean.length == 9 && clean.startsWith('9')) return '963$clean';
// Jordan: 079XXXXXXX or 9627XXXXXXX
if (clean.length == 10 && clean.startsWith('07'))
return '962${clean.substring(1)}';
if (clean.length == 12 && clean.startsWith('962')) return clean;
if (clean.length == 9 && clean.startsWith('7')) return '962$clean';
// Egypt: 010XXXXXXXX or 2010XXXXXXXX
if (clean.length == 11 && clean.startsWith('01'))
return '20${clean.substring(1)}';
if (clean.length == 13 && clean.startsWith('20')) return clean;
return clean;
}
class RideMonitorController extends GetxController {
// CONFIGURATION
final String apiUrl = "${AppLink.server}/Admin/rides/monitorRide.php";
@@ -129,9 +156,11 @@ class RideMonitorController extends GetxController {
if (phone.isEmpty) return;
try {
// تطبيع رقم الهاتف تلقائياً حسب الدولة
String normalizedPhone = normalizePhone(phone);
final response = await CRUD().post(
link: apiUrl,
payload: {"phone": "963$phone"},
payload: {"phone": normalizedPhone},
);
if (response != 'failure') {

View File

@@ -24,14 +24,24 @@ class KazanEditorPage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionHeader('النسب العامة'),
_buildKazanCard(),
// ⚙️ الإعدادات العامة
_buildSectionHeader('⚙️ الإعدادات العامة'),
_buildGeneralSettings(),
const SizedBox(height: 24),
_buildSectionHeader('أسعار الفئات الإضافية'),
_buildPricesGrid(),
// 🚗 أسعار الكيلومتر لكل نوع سيارة
_buildSectionHeader('🚗 أسعار الكيلومتر لكل نوع سيارة'),
_buildKmPricesGrid(),
const SizedBox(height: 24),
// ⏱️ أسعار الدقيقة
_buildSectionHeader('⏱️ أسعار الدقيقة (حسب وقت اليوم)'),
_buildMinutePrices(),
const SizedBox(height: 32),
// 💾 زر الحفظ
MyElevatedButton(
title: 'حفظ جميع التعديلات',
title: '💾 حفظ جميع التعديلات',
icon: Icons.save_rounded,
onPressed: () => _handleSave(),
),
@@ -43,25 +53,18 @@ class KazanEditorPage extends StatelessWidget {
);
}
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.only(bottom: 12, left: 4),
child: Text(
title,
style: AppStyle.title.copyWith(color: AppColor.accent),
),
);
}
Widget _buildKazanCard() {
// ====================================================================
// 1. الإعدادات العامة
// ====================================================================
Widget _buildGeneralSettings() {
return Container(
padding: const EdgeInsets.all(20),
decoration: AppStyle.cardDecoration,
child: Column(
children: [
_buildSliderItem(
'نسبة كازان العامة',
'kazan',
'نسبة كازان العامة (عمولة المنصة)',
'kazanPercent',
'النسبة المئوية التي تقتطعها المنصة من كل رحلة',
Icons.percent_rounded,
),
@@ -72,69 +75,69 @@ class KazanEditorPage extends StatelessWidget {
'السعر المستخدم في حسابات تعويض الوقود',
Icons.local_gas_station_rounded,
),
const Divider(height: 32, color: AppColor.divider),
_buildPriceInputRow(
'رمز العملة',
'currency',
'مثال: SYP, EGP, JOD, IQD',
Icons.currency_exchange_rounded,
),
],
),
);
}
Widget _buildPriceInputRow(String title, String key, String desc, IconData icon) {
final TextEditingController textController = TextEditingController(
text: controller.kazanData[key]?.toString() ?? '0'
);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(icon, size: 20, color: AppColor.accent),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: AppStyle.body.copyWith(fontWeight: FontWeight.bold)),
Text(desc, style: AppStyle.caption.copyWith(fontSize: 10)),
],
),
),
Container(
width: 100,
height: 40,
decoration: BoxDecoration(
color: AppColor.surfaceElevated,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.divider),
),
child: TextField(
controller: textController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
style: AppStyle.number.copyWith(fontSize: 16, color: AppColor.accent),
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 10),
),
onChanged: (val) => controller.kazanData[key] = val,
),
),
const SizedBox(width: 8),
Text('ل.س', style: AppStyle.caption),
],
),
);
}
Widget _buildPricesGrid() {
final Map<String, dynamic> priceFields = {
'comfortPrice': {'label': 'Comfort', 'icon': Icons.chair_rounded},
'speedPrice': {'label': 'Speed', 'icon': Icons.flash_on_rounded},
'familyPrice': {'label': 'Family', 'icon': Icons.groups_rounded},
'deliveryPrice': {'label': 'Delivery', 'icon': Icons.delivery_dining_rounded},
'freePrice': {'label': 'Free', 'icon': Icons.money_off_rounded},
'latePrice': {'label': 'Late Night', 'icon': Icons.nightlight_round},
'heavyPrice': {'label': 'Heavy Load', 'icon': Icons.inventory_2_rounded},
'naturePrice': {'label': 'Nature', 'icon': Icons.forest_rounded},
// ====================================================================
// 2. أسعار الكيلومتر - كل نوع سيارة له حقل خاص به
// ====================================================================
Widget _buildKmPricesGrid() {
// 🆕 9 أنواع سيارات - كل واحد له عمود سعر مستقل
final Map<String, Map<String, dynamic>> priceFields = {
'speedPrice': {
'label': 'Speed ⚡',
'icon': Icons.flash_on_rounded,
'color': Colors.amber.shade700
},
'comfortPrice': {
'label': 'Comfort ❄️',
'icon': Icons.chair_rounded,
'color': Colors.blue.shade700
},
'ladyPrice': {
'label': 'Lady 👩',
'icon': Icons.female_rounded,
'color': Colors.pink.shade400
},
'electricPrice': {
'label': 'Electric 🔋',
'icon': Icons.electric_car_rounded,
'color': Colors.green.shade700
},
'vanPrice': {
'label': 'Van 🚐',
'icon': Icons.airport_shuttle_rounded,
'color': Colors.deepPurple.shade700
},
'deliveryPrice': {
'label': 'Delivery 📦',
'icon': Icons.delivery_dining_rounded,
'color': Colors.orange.shade700
},
'mishwarVipPrice': {
'label': 'Mishwar Vip ⭐',
'icon': Icons.star_rounded,
'color': Colors.amber.shade900
},
'fixedPrice': {
'label': 'Fixed Price 💰',
'icon': Icons.money_rounded,
'color': Colors.teal.shade700
},
'awfarPrice': {
'label': 'Awfar Car 🚗',
'icon': Icons.directions_car_rounded,
'color': Colors.brown.shade600
},
};
return Container(
@@ -144,63 +147,190 @@ class KazanEditorPage extends StatelessWidget {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 2.5,
crossAxisCount: 3, // 3 أعمدة بدلاً من 2
childAspectRatio: 1.8,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
),
itemCount: priceFields.length,
itemBuilder: (context, index) {
String key = priceFields.keys.elementAt(index);
var field = priceFields[key];
return _buildCompactPriceInputCard(key, field['label'], field['icon']);
var field = priceFields[key]!;
return _buildKmPriceCard(
key, field['label'], field['icon'], field['color']);
},
),
);
}
Widget _buildCompactPriceInputCard(String key, String label, IconData icon) {
final TextEditingController textController = TextEditingController(
text: controller.kazanData[key]?.toString() ?? '0'
);
Widget _buildKmPriceCard(
String key, String label, IconData icon, Color color) {
final TextEditingController textController =
TextEditingController(text: _getValue(key));
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
decoration: BoxDecoration(
color: AppColor.surfaceElevated,
color: color.withAlpha(25),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.divider.withAlpha(100)),
border: Border.all(color: color.withAlpha(80)),
),
child: Row(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 16, color: AppColor.textSecondary),
const SizedBox(width: 6),
Expanded(
child: Text(label, style: AppStyle.caption.copyWith(fontSize: 11), overflow: TextOverflow.ellipsis),
),
SizedBox(
width: 50,
child: TextField(
controller: textController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
style: AppStyle.number.copyWith(fontSize: 14),
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.zero,
Row(
children: [
Icon(icon, size: 14, color: color),
const SizedBox(width: 4),
Expanded(
child: Text(
label,
style: AppStyle.caption
.copyWith(fontSize: 10, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
),
onChanged: (val) => controller.kazanData[key] = val,
),
],
),
const SizedBox(height: 4),
Row(
children: [
Expanded(
child: TextField(
controller: textController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
style: AppStyle.number.copyWith(fontSize: 13, color: color),
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 2),
),
onChanged: (val) => _setValue(key, val),
),
),
],
),
],
),
);
}
Widget _buildSliderItem(String title, String key, String desc, IconData icon) {
double value = double.tryParse(controller.kazanData[key]?.toString() ?? '0') ?? 0;
// ====================================================================
// 3. أسعار الدقيقة (حسب وقت اليوم)
// ====================================================================
Widget _buildMinutePrices() {
final Map<String, Map<String, dynamic>> minuteFields = {
'normalMinPrice': {
'label': 'Normal (سعر الدقيقة العادي)',
'desc': '9 ص - 2 م / 6 م - 9 م',
'icon': Icons.wb_sunny_rounded,
'color': Colors.orange
},
'peakMinPrice': {
'label': 'Peak (سعر الدقيقة ذروة)',
'desc': '2 م - 5 م',
'icon': Icons.whatshot_rounded,
'color': Colors.red
},
'lateMinPrice': {
'label': 'Late (سعر الدقيقة ليلي)',
'desc': '9 م - 1 ص',
'icon': Icons.nightlight_round,
'color': Colors.indigo
},
};
return Container(
decoration: AppStyle.cardDecoration,
padding: const EdgeInsets.all(16),
child: Column(
children: minuteFields.entries.map((entry) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: _buildPriceInputRow(
entry.value['label'],
entry.key,
entry.value['desc'],
entry.value['icon'],
),
);
}).toList(),
),
);
}
// ====================================================================
// دوال مساعدة للـ UI
// ====================================================================
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.only(bottom: 12, left: 4),
child: Text(
title,
style: AppStyle.title.copyWith(color: AppColor.accent),
),
);
}
String _getValue(String key) {
return controller.kazanData[key]?.toString() ?? '0';
}
void _setValue(String key, String val) {
controller.kazanData[key] = val;
}
Widget _buildPriceInputRow(
String title, String key, String desc, IconData icon) {
final TextEditingController textController =
TextEditingController(text: _getValue(key));
return Row(
children: [
Icon(icon, size: 20, color: AppColor.accent),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style: AppStyle.body.copyWith(fontWeight: FontWeight.bold)),
Text(desc, style: AppStyle.caption.copyWith(fontSize: 10)),
],
),
),
Container(
width: 100,
height: 40,
decoration: BoxDecoration(
color: AppColor.surfaceElevated,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.divider),
),
child: TextField(
controller: textController,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
style:
AppStyle.number.copyWith(fontSize: 16, color: AppColor.accent),
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 10),
),
onChanged: (val) => _setValue(key, val),
),
),
],
);
}
Widget _buildSliderItem(
String title, String key, String desc, IconData icon) {
double value = double.tryParse(_getValue(key)) ?? 0;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -229,26 +359,40 @@ class KazanEditorPage extends StatelessWidget {
activeColor: AppColor.accent,
inactiveColor: AppColor.divider,
onChanged: (val) {
controller.kazanData[key] = val.toInt().toString();
_setValue(key, val.toInt().toString());
},
),
],
);
}
// ====================================================================
// حفظ البيانات
// ====================================================================
void _handleSave() async {
final data = Map<String, dynamic>.from(controller.kazanData);
data['adminId'] = 'admin'; // Should be dynamic from auth service
data['country'] = 'syria';
data['adminId'] = 'admin1';
// التأكد من وجود country (إذا لم يكن موجوداً، استخدم 'syria')
if (!data.containsKey('country') ||
data['country'] == null ||
data['country'].toString().isEmpty) {
data['country'] = 'Syria';
}
bool success = await controller.updateKazan(data);
if (success) {
Get.snackbar("نجاح", "تم تحديث الأسعار بنجاح",
backgroundColor: AppColor.successSoft,
colorText: AppColor.textPrimary,
snackPosition: SnackPosition.BOTTOM,
margin: const EdgeInsets.all(16)
);
Get.snackbar("نجاح", "تم تحديث الأسعار بنجاح",
backgroundColor: AppColor.successSoft,
colorText: AppColor.textPrimary,
snackPosition: SnackPosition.BOTTOM,
margin: const EdgeInsets.all(16));
} else {
Get.snackbar("خطأ", "فشل تحديث الأسعار",
backgroundColor: Colors.red.shade100,
colorText: AppColor.textPrimary,
snackPosition: SnackPosition.BOTTOM,
margin: const EdgeInsets.all(16));
}
}
}