Update: 2026-05-07 03:50:16

This commit is contained in:
Hamza-Ayed
2026-05-07 03:50:16 +03:00
parent 209f721cd6
commit bd7164ed23
9 changed files with 464 additions and 146 deletions

View File

@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:dio/dio.dart';
import '../../../core/storage/secure_storage.dart';
@@ -25,13 +26,11 @@ class DashboardController extends GetxController {
_loadDashboardData();
}
Future<void> _loadDashboardData() async {
try {
isLoading.value = true;
final token = await _storage.getToken();
if (token == null || token.isEmpty) {
Get.offAllNamed(AppRoutes.PHONE_INPUT);
return;
@@ -71,6 +70,133 @@ class DashboardController extends GetxController {
Get.offAllNamed(AppRoutes.PHONE_INPUT);
}
void startVoiceAssistant() {
final textController = TextEditingController();
Get.bottomSheet(
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Get.isDarkMode ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30), topRight: Radius.circular(30)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 4,
margin: const EdgeInsets.bottom(20),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.3),
borderRadius: BorderRadius.circular(2)),
),
Row(
children: [
const Icon(Icons.auto_awesome, color: Color(0xFF5EEAD4)),
const SizedBox(width: 12),
Text(
'المساعد الذكي (Grok-Beta)',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Get.isDarkMode
? Colors.white
: const Color(0xFF0F4C81)),
),
],
),
const SizedBox(height: 20),
TextField(
autofocus: true,
controller: textController,
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black),
decoration: InputDecoration(
hintText: 'اكتب أمرك هنا (مثلاً: أريد رؤية الفواتير)...',
hintStyle: const TextStyle(fontSize: 14, color: Colors.grey),
filled: true,
fillColor: Get.isDarkMode
? const Color(0xFF1A1A2E)
: const Color(0xFFF1F5F9),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide.none),
prefixIcon: const Icon(Icons.mic_none_rounded, color: Colors.grey),
suffixIcon: IconButton(
icon:
const Icon(Icons.send_rounded, color: Color(0xFF0F4C81)),
onPressed: () => _handleVoiceCommand(textController.text),
),
),
onSubmitted: (val) => _handleVoiceCommand(val),
),
const SizedBox(height: 12),
Text(
'ملاحظة: جاري تفعيل ميزة التعرف الصوتي المباشر...',
style:
TextStyle(fontSize: 11, color: Colors.grey.withOpacity(0.7)),
),
const SizedBox(height: 20),
],
),
),
isScrollControlled: true,
);
}
Future<void> _handleVoiceCommand(String text) async {
if (text.trim().isEmpty) return;
Get.back(); // Close bottom sheet
AppSnackbar.showWarning('جاري التحليل...', 'يتم تحليل طلبك بواسطة Grok AI');
try {
final token = await _storage.getToken();
final response = await _dio.post(
'/voice/parse-intent-grok',
data: {'text': text},
options: Options(headers: {'Authorization': 'Bearer $token'}),
);
if (response.data['success'] == true) {
final action = response.data['data']['action'];
final params = response.data['data']['params'];
final confirmation = response.data['data']['confirmation'] ?? 'تم!';
AppSnackbar.showSuccess('تم!', confirmation);
_executeAction(action, params);
} else {
AppSnackbar.showError(
'خطأ', response.data['message'] ?? 'فشل تحليل الطلب');
}
} catch (e) {
AppLogger.error('Voice Assistant Error', e);
AppSnackbar.showError(
'خطأ', 'حدث خطأ أثناء التواصل مع خادم الذكاء الاصطناعي');
}
}
void _executeAction(String action, dynamic params) {
switch (action) {
case 'list_invoices':
Get.toNamed(AppRoutes.INVOICES);
break;
case 'open_scanner':
Get.toNamed(AppRoutes.SCANNER);
break;
case 'navigate':
final screen = params['screen']?.toString().toLowerCase();
if (screen == 'settings') Get.toNamed(AppRoutes.SETTINGS);
if (screen == 'dashboard') Get.back();
break;
default:
AppSnackbar.showWarning(
'تنبيه', 'الأمر مفهوم ولكن لم يتم ربط الأكشن برمجياً بعد.');
}
}
void refreshData() {
_loadDashboardData();
}

View File

@@ -143,7 +143,7 @@ class DashboardView extends GetView<DashboardController> {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
onPressed: () {
Get.snackbar('المساعد الصوتي', 'يتم تجهيز خوادم AI (Grok & Gemini) للاستماع لأوامرك...');
controller.startVoiceAssistant();
},
),
),

View File

@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../core/network/dio_client.dart';
import '../../../core/utils/app_snackbar.dart';
@@ -22,8 +23,10 @@ class InvoiceDetailController extends GetxController {
Future<void> fetchInvoiceDetails() async {
try {
isLoading.value = true;
final res = await DioClient().client.get('invoices/view', queryParameters: {'id': invoiceId});
final res = await DioClient()
.client
.get('invoices/view', queryParameters: {'id': invoiceId});
if (res.data['success'] == true && res.data['data'] != null) {
invoice.value = res.data['data'];
} else {
@@ -41,7 +44,9 @@ class InvoiceDetailController extends GetxController {
Future<void> approveInvoice() async {
try {
final res = await DioClient().client.post('invoices/approve', data: {'invoice_id': invoiceId});
final res = await DioClient()
.client
.post('invoices/approve', data: {'invoice_id': invoiceId});
if (res.data['success'] == true) {
AppSnackbar.showSuccess('تم الاعتماد', 'تم اعتماد الفاتورة بنجاح');
// Refresh the detail view
@@ -56,10 +61,30 @@ class InvoiceDetailController extends GetxController {
}
void viewOriginalImage() {
final imagePath = invoice['file_path'];
if (imagePath != null && imagePath.isNotEmpty) {
// In a real app, you would download/show the image. For now, just a snackbar or open URL.
AppSnackbar.showInfo('قريباً', 'سيتم عرض الصورة قريباً');
final fileUrl = invoice['file_url'];
if (fileUrl != null && fileUrl.isNotEmpty) {
// Navigate to a dedicated image viewer or show in a dialog
final fullUrl = 'https://musadaq.intaleqapp.com/api$fileUrl';
Get.to(() => Scaffold(
appBar: AppBar(
title: const Text('صورة الفاتورة'),
backgroundColor: const Color(0xFF0F4C81)),
body: Center(
child: InteractiveViewer(
child: Image.network(
fullUrl,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return const CircularProgressIndicator();
},
errorBuilder: (context, error, stackTrace) {
return const Text(
'فشل تحميل الصورة. قد يكون الملف مفقوداً على الخادم.');
},
),
),
),
));
} else {
AppSnackbar.showWarning('عذراً', 'لا توجد صورة مرتبطة بهذه الفاتورة');
}

View File

@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import '../../../core/utils/app_snackbar.dart';
import '../controllers/payment_receipt_controller.dart';
class PaymentReceiptView extends StatelessWidget {
@@ -11,10 +13,13 @@ class PaymentReceiptView extends StatelessWidget {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? const Color(0xFF121212) : const Color(0xFFF5F7FA),
backgroundColor:
isDark ? const Color(0xFF121212) : const Color(0xFFF5F7FA),
appBar: AppBar(
title: const Text('إتمام الدفع', style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: isDark ? const Color(0xFF1E1E2E) : const Color(0xFF0F4C81),
title: const Text('إتمام الدفع',
style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor:
isDark ? const Color(0xFF1E1E2E) : const Color(0xFF0F4C81),
foregroundColor: Colors.white,
elevation: 0,
),
@@ -25,33 +30,51 @@ class PaymentReceiptView extends StatelessWidget {
children: [
// Payment Info Card
Obx(() => Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
children: [
const Text('تفاصيل التحويل المطلوب', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 16),
_buildInfoRow('الاسم المستعار (CliQ)', controller.payment['cliq_alias'] ?? '', isDark, isHighlight: true),
const Divider(height: 24),
_buildInfoRow('المبلغ المطلوب', '${controller.payment['amount_jod'] ?? 0} JOD', isDark),
],
),
)),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
children: [
const Text('تفاصيل التحويل المطلوب',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 16),
_buildInfoRow('الاسم المستعار (CliQ)',
controller.payment['cliq_alias'] ?? '', isDark,
isHighlight: true),
const Divider(height: 24),
_buildInfoRow(
'المبلغ المطلوب',
'${controller.payment['amount_jod'] ?? 0} JOD',
isDark),
],
),
)),
const SizedBox(height: 24),
Text('الخطوات التالية:', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: isDark ? Colors.white : Colors.black87)),
Text('الخطوات التالية:',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: isDark ? Colors.white : Colors.black87)),
const SizedBox(height: 12),
_buildStepRow('1', 'افتح تطبيق البنك أو المحفظة الإلكترونية الخاصة بك.', isDark),
_buildStepRow('1',
'افتح تطبيق البنك أو المحفظة الإلكترونية الخاصة بك.', isDark),
const SizedBox(height: 8),
_buildStepRow('2', 'اختر خدمة "كليك" (CliQ) للتحويل الفوري.', isDark),
_buildStepRow(
'2', 'اختر خدمة "كليك" (CliQ) للتحويل الفوري.', isDark),
const SizedBox(height: 8),
_buildStepRow('3', 'قم بالتحويل للاسم المستعار الموضح أعلاه.', isDark),
_buildStepRow(
'3', 'قم بالتحويل للاسم المستعار الموضح أعلاه.', isDark),
const SizedBox(height: 8),
_buildStepRow('4', 'بعد إتمام العملية، انسخ "رقم المرجع" من رسالة البنك أو الإشعار والصقه هنا.', isDark),
_buildStepRow(
'4',
'بعد إتمام العملية، انسخ "رقم المرجع" من رسالة البنك أو الإشعار والصقه هنا.',
isDark),
const SizedBox(height: 24),
// Reference Number Input Area
@@ -60,29 +83,40 @@ class PaymentReceiptView extends StatelessWidget {
decoration: BoxDecoration(
color: isDark ? const Color(0xFF1E1E2E) : Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: isDark ? Colors.white10 : Colors.grey.shade200),
border: Border.all(
color: isDark ? Colors.white10 : Colors.grey.shade200),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('رقم المرجع (Reference Number)', style: TextStyle(fontWeight: FontWeight.bold)),
const Text('رقم المرجع أو نص الرسالة كاملة',
style: TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
TextField(
controller: controller.referenceController,
maxLines: 3,
minLines: 1,
decoration: InputDecoration(
hintText: 'مثال: 1234567890',
hintStyle: TextStyle(color: isDark ? Colors.white38 : Colors.grey),
hintText:
'ألصق رقم المرجع أو نص الرسالة الواردة من البنك هنا...',
hintStyle: TextStyle(
color: isDark ? Colors.white38 : Colors.grey,
fontSize: 13),
filled: true,
fillColor: isDark ? const Color(0xFF1A1A2E) : const Color(0xFFF1F5F9),
fillColor: isDark
? const Color(0xFF1A1A2E)
: const Color(0xFFF1F5F9),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
),
keyboardType: TextInputType.text,
keyboardType: TextInputType.multiline,
style: TextStyle(
fontFamily: 'monospace',
fontSize: 14,
color: isDark ? Colors.white : Colors.black87,
),
),
@@ -96,23 +130,32 @@ class PaymentReceiptView extends StatelessWidget {
SizedBox(
height: 52,
child: Obx(() => ElevatedButton.icon(
onPressed: controller.isUploading.value
? null
: () => controller.submitReference(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0F4C81),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
disabledBackgroundColor: isDark ? Colors.white10 : Colors.grey.shade300,
),
icon: controller.isUploading.value
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
: const Icon(Icons.check_circle_outline),
label: Text(
controller.isUploading.value ? 'جاري التحقق...' : 'تأكيد الدفع',
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
)),
onPressed: controller.isUploading.value
? null
: () => controller.submitReference(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0F4C81),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
disabledBackgroundColor:
isDark ? Colors.white10 : Colors.grey.shade300,
),
icon: controller.isUploading.value
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2, color: Colors.white))
: const Icon(Icons.check_circle_outline),
label: Text(
controller.isUploading.value
? 'جاري التحقق...'
: 'تأكيد الدفع',
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
),
)),
),
],
),
@@ -134,7 +177,10 @@ class PaymentReceiptView extends StatelessWidget {
child: Center(
child: Text(
number,
style: const TextStyle(color: Color(0xFF0F4C81), fontWeight: FontWeight.bold, fontSize: 12),
style: const TextStyle(
color: Color(0xFF0F4C81),
fontWeight: FontWeight.bold,
fontSize: 12),
),
),
),
@@ -142,31 +188,62 @@ class PaymentReceiptView extends StatelessWidget {
Expanded(
child: Text(
text,
style: TextStyle(fontSize: 13, color: isDark ? Colors.white70 : Colors.grey.shade700, height: 1.4),
style: TextStyle(
fontSize: 13,
color: isDark ? Colors.white70 : Colors.grey.shade700,
height: 1.4),
),
),
],
);
}
Widget _buildInfoRow(String label, String value, bool isDark, {bool isHighlight = false}) {
Widget _buildInfoRow(String label, String value, bool isDark,
{bool isHighlight = false}) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: TextStyle(fontSize: 13, color: isDark ? Colors.white70 : Colors.grey.shade600)),
Container(
padding: EdgeInsets.symmetric(horizontal: isHighlight ? 12 : 0, vertical: isHighlight ? 6 : 0),
decoration: isHighlight ? BoxDecoration(
color: const Color(0xFF0F4C81).withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
) : null,
child: Text(
value,
Text(label,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: isHighlight ? const Color(0xFF0F4C81) : (isDark ? Colors.white : Colors.black87),
fontFamily: 'monospace',
fontSize: 13,
color: isDark ? Colors.white70 : Colors.grey.shade600)),
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: value));
AppSnackbar.showSuccess('تم النسخ', 'تم نسخ $label إلى الحافظة');
},
child: Container(
padding: EdgeInsets.symmetric(
horizontal: isHighlight ? 12 : 0,
vertical: isHighlight ? 6 : 0),
decoration: isHighlight
? BoxDecoration(
color: const Color(0xFF0F4C81).withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: const Color(0xFF0F4C81).withOpacity(0.3)),
)
: null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
value,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: isHighlight
? const Color(0xFF0F4C81)
: (isDark ? Colors.white : Colors.black87),
fontFamily: 'monospace',
),
),
if (isHighlight) ...[
const SizedBox(width: 8),
const Icon(Icons.copy_rounded,
size: 14, color: Color(0xFF0F4C81)),
],
],
),
),
),