admin 26-5-2

This commit is contained in:
Hamza-Ayed
2026-05-02 15:16:30 +03:00
parent 5fc160e374
commit 0d9fab31bd
21 changed files with 1636 additions and 260 deletions

View File

@@ -0,0 +1,56 @@
import 'dart:convert';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../functions/crud.dart';
class ComplaintController extends GetxController {
var complaintList = [].obs;
var isLoading = false.obs;
final CRUD _crud = CRUD();
@override
void onInit() {
super.onInit();
getComplaints();
}
Future<void> getComplaints() async {
isLoading.value = true;
try {
var response = await _crud.get(link: AppLink.getComplaintAllData);
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
complaintList.assignAll(decoded['message']);
}
} else {
complaintList.clear();
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب الشكاوى: $e");
} finally {
isLoading.value = false;
}
}
Future<bool> updateComplaintStatus(String id, String status, String resolution) async {
isLoading.value = true;
try {
var response = await _crud.post(link: "${AppLink.server}/serviceapp/update_complaint.php", payload: {
"id": id,
"statusComplaint": status,
"resolution": resolution,
});
if (response != null && response is Map && response['status'] == "success") {
await getComplaints();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل تحديث الشكوى: $e");
return false;
} finally {
isLoading.value = false;
}
}
}

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_admin1/constant/links.dart';
import 'package:sefer_admin1/controller/functions/crud.dart';
import 'package:sefer_admin1/controller/auth/otp_helper.dart';
import '../../constant/api_key.dart';
import '../../constant/box_name.dart';
@@ -25,6 +26,19 @@ class DashboardController extends GetxController {
var res = await CRUD().get(link: AppLink.getdashbord, payload: {});
print('📡 Main dashboard response: $res');
if (res == 'token_expired') {
print('❌ Admin token expired. Attempting seamless auto-login.');
box.remove(BoxName.jwt);
try {
final otpHelper = Get.put(OtpHelper());
await otpHelper.checkAdminLogin();
} catch (e) {
Get.offAllNamed('/login');
}
return;
}
if (res != 'failure' && res != null) {
try {
var d = res is String ? jsonDecode(res) : res;

View File

@@ -0,0 +1,97 @@
import 'dart:convert';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../functions/crud.dart';
class DriverDocsController extends GetxController {
var pendingDrivers = [].obs;
var isLoading = false.obs;
var isMoreLoading = false.obs;
var hasMore = true.obs;
int _offset = 0;
final int _limit = 10;
final CRUD _crud = CRUD();
@override
void onInit() {
super.onInit();
getPendingDrivers();
}
Future<void> getPendingDrivers({bool refresh = true}) async {
if (refresh) {
isLoading.value = true;
_offset = 0;
hasMore.value = true;
} else {
if (isMoreLoading.value || !hasMore.value) return;
isMoreLoading.value = true;
}
try {
var response = await _crud.post(
link: AppLink.getDriversPending,
payload: {"limit": _limit.toString(), "offset": _offset.toString()},
);
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
List newItems = decoded['message'] ?? [];
if (refresh) {
pendingDrivers.assignAll(newItems);
} else {
pendingDrivers.addAll(newItems);
}
_offset += newItems.length;
if (newItems.length < _limit) {
hasMore.value = false;
}
}
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب السائقين: $e");
} finally {
isLoading.value = false;
isMoreLoading.value = false;
}
}
Future<void> loadMore() async {
await getPendingDrivers(refresh: false);
}
Future<Map<String, dynamic>?> getDriverFullDetails(String id) async {
try {
var response = await _crud.get(link: "${AppLink.getDriverDetails}?id=$id");
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
return decoded['data'];
}
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب تفاصيل السائق: $e");
}
return null;
}
Future<bool> approveDriver(String id) async {
isLoading.value = true;
try {
var response = await _crud.post(link: AppLink.updateDriverFromAdmin, payload: {
"id": id,
"status": "active",
});
if (response != null && response is Map && response['status'] == "success") {
await getPendingDrivers();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل اعتماد السائق: $e");
return false;
} finally {
isLoading.value = false;
}
}
}

View File

@@ -0,0 +1,60 @@
import 'dart:convert';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../functions/crud.dart';
class KazanController extends GetxController {
var kazanData = {}.obs;
var isLoading = false.obs;
final CRUD _crud = CRUD();
@override
void onInit() {
super.onInit();
getKazan();
}
Future<void> getKazan() async {
isLoading.value = true;
try {
var response = await _crud.get(link: "${AppLink.getKazanPercent}?country=syria");
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
var message = decoded['message'];
if (message is List && message.isNotEmpty) {
kazanData.value = message[0];
}
}
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب بيانات التسعير: $e");
} finally {
isLoading.value = false;
}
}
Future<bool> updateKazan(Map<String, dynamic> data) async {
isLoading.value = true;
try {
final String link = data.containsKey('id') ? AppLink.updateKazanPercent : AppLink.addKazanPercent;
Map<String, String> payload = {};
data.forEach((key, value) {
payload[key] = value.toString();
});
var response = await _crud.post(link: link, payload: payload);
if (response != null && response is Map && response['status'] == "success") {
await getKazan();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل تحديث التسعير: $e");
return false;
} finally {
isLoading.value = false;
}
}
}

View File

@@ -0,0 +1,83 @@
import 'dart:convert';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../functions/crud.dart';
class PromoController extends GetxController {
var promoList = [].obs;
var isLoading = false.obs;
final CRUD _crud = CRUD();
@override
void onInit() {
super.onInit();
getPromos();
}
Future<void> getPromos() async {
isLoading.value = true;
try {
var response = await _crud.get(link: AppLink.getPassengersPromo);
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
promoList.assignAll(decoded['message']);
}
} else {
promoList.clear();
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب أكواد الخصم: $e");
} finally {
isLoading.value = false;
}
}
Future<bool> addPromo(Map<String, dynamic> data) async {
isLoading.value = true;
try {
var response = await _crud.post(link: AppLink.addPassengersPromo, payload: data);
if (response != null && response is Map && response['status'] == "success") {
await getPromos();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل إضافة كود الخصم: $e");
return false;
} finally {
isLoading.value = false;
}
}
Future<bool> deletePromo(String id) async {
try {
var response = await _crud.post(link: AppLink.deletePassengersPromo, payload: {"id": id});
if (response != null && response is Map && response['status'] == "success") {
await getPromos();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل حذف كود الخصم: $e");
return false;
}
}
Future<bool> updatePromo(Map<String, dynamic> data) async {
isLoading.value = true;
try {
var response = await _crud.post(link: AppLink.updatePassengersPromo, payload: data);
if (response != null && response is Map && response['status'] == "success") {
await getPromos();
return true;
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل تحديث كود الخصم: $e");
return false;
} finally {
isLoading.value = false;
}
}
}