Update: 2026-05-08 14:05:50

This commit is contained in:
Hamza-Ayed
2026-05-08 14:05:50 +03:00
parent cfc330e291
commit 155c2d0fc0
13 changed files with 709 additions and 22 deletions

View File

@@ -57,4 +57,27 @@ class CompaniesManagementController extends GetxController {
AppSnackbar.showError('خطأ', 'تعذر حذف الشركة');
}
}
Future<void> connectJoFotara(String id, String clientId, String secretKey, String sequence) async {
try {
isLoading.value = true;
final response = await _dio.post('companies/connect_jofotara', data: {
'id': id,
'client_id': clientId,
'secret_key': secretKey,
'income_source_sequence': sequence,
});
if (response.data['success'] == true) {
await fetchCompanies();
AppSnackbar.showSuccess('نجاح', 'تم ربط الشركة بجوفوترا بنجاح');
} else {
AppSnackbar.showError('خطأ', response.data['message'] ?? 'فشل الربط');
}
} catch (e) {
AppLogger.error('Failed to connect jofotara', e);
AppSnackbar.showError('خطأ', 'تعذر ربط جوفوترا');
} finally {
isLoading.value = false;
}
}
}

View File

@@ -137,6 +137,9 @@ class CompaniesManagementView extends StatelessWidget {
'company_name': company['name'],
});
break;
case 'link_jofotara':
_showLinkJoFotaraDialog(context, company, controller);
break;
case 'delete':
_confirmDelete(context, controller, company['id'], company['name'] ?? '');
break;
@@ -145,6 +148,7 @@ class CompaniesManagementView extends StatelessWidget {
itemBuilder: (context) => [
const PopupMenuItem(value: 'edit', child: Row(children: [Icon(Icons.edit, size: 18), SizedBox(width: 8), Text('تعديل البيانات')])),
const PopupMenuItem(value: 'stats', child: Row(children: [Icon(Icons.bar_chart, size: 18), SizedBox(width: 8), Text('الإحصائيات')])),
const PopupMenuItem(value: 'link_jofotara', child: Row(children: [Icon(Icons.link, size: 18, color: Color(0xFF6366F1)), SizedBox(width: 8), Text('ربط جوفوترا', style: TextStyle(color: Color(0xFF6366F1)))])),
const PopupMenuItem(value: 'delete', child: Row(children: [Icon(Icons.delete, size: 18, color: Colors.red), SizedBox(width: 8), Text('حذف', style: TextStyle(color: Colors.red))])),
],
),
@@ -162,7 +166,7 @@ class CompaniesManagementView extends StatelessWidget {
if (company['address'] != null && company['address'].toString().isNotEmpty)
_chip(Icons.location_on, company['address'], Colors.orange),
if (company['is_jofotara_linked'] == 1)
_chip(Icons.verified, 'جوفتورة', const Color(0xFF6366F1)),
_chip(Icons.verified, 'جوفوترا', const Color(0xFF6366F1)),
],
),
@@ -298,4 +302,43 @@ class CompaniesManagementView extends StatelessWidget {
},
);
}
void _showLinkJoFotaraDialog(BuildContext context, Map<String, dynamic> company, CompaniesManagementController controller) {
final clientIdC = TextEditingController();
final secretKeyC = TextEditingController();
final sequenceC = TextEditingController();
Get.dialog(
AlertDialog(
title: const Text('ربط منصة جوفوترا', textAlign: TextAlign.center, style: TextStyle(color: Color(0xFF6366F1))),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('أدخل بيانات الربط الخاصة بالشركة:', style: TextStyle(fontSize: 13, color: Colors.grey), textAlign: TextAlign.center),
const SizedBox(height: 16),
_editField('Client ID', clientIdC, Icons.vpn_key),
_editField('Secret Key', secretKeyC, Icons.lock),
_editField('Income Source Sequence (اختياري)', sequenceC, Icons.format_list_numbered),
],
),
),
actions: [
TextButton(onPressed: () => Get.back(), child: const Text('إلغاء')),
ElevatedButton(
onPressed: () {
if (clientIdC.text.isEmpty || secretKeyC.text.isEmpty) {
Get.snackbar('تنبيه', 'يجب إدخال الـ Client ID و Secret Key');
return;
}
Get.back();
controller.connectJoFotara(company['id'], clientIdC.text, secretKeyC.text, sequenceC.text);
},
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF6366F1)),
child: const Text('ربط الآن', style: TextStyle(color: Colors.white)),
),
],
),
);
}
}