19
This commit is contained in:
@@ -25,10 +25,16 @@ class DashboardController extends GetxController {
|
||||
var res = await CRUD().get(link: AppLink.getdashbord, payload: {});
|
||||
print('📡 Main dashboard response: $res');
|
||||
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res);
|
||||
print('✅ Decoded main dashboard: ${jsonEncode(d)}');
|
||||
dashbord = d['message'];
|
||||
if (res != 'failure' && res != null) {
|
||||
try {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
print('✅ Decoded main dashboard: ${jsonEncode(d)}');
|
||||
if (d['status'] == 'success' && d['message'] != null) {
|
||||
dashbord = d['message'] is List ? d['message'] : [d['message']];
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ Error parsing main dashboard: $e');
|
||||
}
|
||||
} else {
|
||||
print('❌ Failed to load main dashboard');
|
||||
}
|
||||
@@ -40,7 +46,7 @@ class DashboardController extends GetxController {
|
||||
);
|
||||
print('💳 Wallet dashboard response: $resPayments');
|
||||
|
||||
if (resPayments != 'failure') {
|
||||
if (resPayments is Map && resPayments['status'] == 'success') {
|
||||
var p = resPayments;
|
||||
print('✅ Decoded wallet dashboard: ${jsonEncode(p)}');
|
||||
|
||||
@@ -48,9 +54,11 @@ class DashboardController extends GetxController {
|
||||
p['message'] is List &&
|
||||
p['message'].isNotEmpty) {
|
||||
dashbord[0].addAll(p['message'][0]);
|
||||
} else if (dashbord.isNotEmpty && p['message'] is Map) {
|
||||
dashbord[0].addAll(p['message']);
|
||||
}
|
||||
} else {
|
||||
print('❌ Failed to load wallet dashboard');
|
||||
print('❌ Failed to load wallet dashboard (or verification required)');
|
||||
}
|
||||
|
||||
// 🔹 Check SMS credit
|
||||
|
||||
81
lib/controller/admin/staff_controller.dart
Normal file
81
lib/controller/admin/staff_controller.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../functions/crud.dart';
|
||||
import '../functions/device_info.dart';
|
||||
import '../../views/widgets/snackbar.dart';
|
||||
|
||||
class StaffController extends GetxController {
|
||||
final CRUD _crud = CRUD();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
// التكست كنترولرز
|
||||
final nameController = TextEditingController();
|
||||
final phoneController = TextEditingController();
|
||||
final emailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final birthdateController = TextEditingController();
|
||||
|
||||
String selectedGender = 'Male';
|
||||
String selectedRole = 'service'; // 'admin' or 'service'
|
||||
|
||||
bool isLoading = false;
|
||||
|
||||
Future<void> registerStaff() async {
|
||||
if (!formKey.currentState!.validate()) return;
|
||||
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
// ملاحظة: لا نأخذ بصمة جهاز الأدمن هنا، بل نتركها فارغة ليقوم الموظف بربطها عند أول دخول له
|
||||
String fingerprint = "";
|
||||
|
||||
var response = await _crud.post(
|
||||
link: AppLink.addStaff,
|
||||
payload: {
|
||||
"name": nameController.text.trim(),
|
||||
"phone": phoneController.text.trim(),
|
||||
"email": emailController.text.trim(),
|
||||
"password": passwordController.text.trim(),
|
||||
"role": selectedRole,
|
||||
"gender": selectedGender,
|
||||
"birthdate": birthdateController.text.trim(),
|
||||
"fingerprint": fingerprint,
|
||||
"site": "main", // القيمة الافتراضية للفرع
|
||||
},
|
||||
);
|
||||
|
||||
if (response != "failure") {
|
||||
mySnackbarSuccess('تمت إضافة الموظف بنجاح');
|
||||
_clearFields();
|
||||
Get.back();
|
||||
} else {
|
||||
mySnackeBarError('فشل في إضافة الموظف. يرجى المحاولة لاحقاً');
|
||||
}
|
||||
} catch (e) {
|
||||
mySnackeBarError('حدث خطأ: $e');
|
||||
} finally {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void _clearFields() {
|
||||
nameController.clear();
|
||||
phoneController.clear();
|
||||
emailController.clear();
|
||||
passwordController.clear();
|
||||
birthdateController.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
nameController.dispose();
|
||||
phoneController.dispose();
|
||||
emailController.dispose();
|
||||
passwordController.dispose();
|
||||
birthdateController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user