- GeminiService (integrations/gemini, @Global): extractDocument (OCR fields) + faceMatch; graceful if no GEMINI_API_KEY - documents: face-match now real via Gemini; POST /admin/documents/:id/ocr extracts fields for CS auto-fill - roles: PATCH /admin/users/:id/role (admin) + POST /platform/users/role (bootstrap via x-platform-secret) - config: gemini + platform.secret; .env.example entries Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
177 lines
4.8 KiB
Dart
Executable File
177 lines
4.8 KiB
Dart
Executable File
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../../constant/box_name.dart';
|
|
import '../../../constant/colors.dart';
|
|
import '../../../constant/links.dart';
|
|
import '../../../controller/functions/crud.dart';
|
|
import '../../../main.dart';
|
|
import '../../widgets/error_snakbar.dart';
|
|
|
|
class DriverCarController extends GetxController {
|
|
bool isLoading = false;
|
|
List cars = [];
|
|
// int? carId;
|
|
fetchCatrsForDrivers() async {
|
|
isLoading = true;
|
|
update();
|
|
var res = await CRUD().get(link: AppLink.getNewCarsDrivers, payload: {
|
|
"driverID": box.read(BoxName.driverID).toString(),
|
|
});
|
|
if (res != 'failure') {
|
|
var d = jsonDecode(res)['message'];
|
|
cars = d;
|
|
// carId = cars.isEmpty ? 1 : cars.length + 1;
|
|
}
|
|
isLoading = false;
|
|
update();
|
|
}
|
|
|
|
Future<void> addNewCarToAccount({
|
|
required String vin,
|
|
required String plate,
|
|
required String make,
|
|
required String model,
|
|
required String year,
|
|
required String expiryDate,
|
|
required String color,
|
|
required String colorHex,
|
|
required String owner,
|
|
required String address,
|
|
required String inspectionDate,
|
|
required String displacement,
|
|
required String fuel,
|
|
}) async {
|
|
// إظهار Loading
|
|
Get.dialog(const Center(child: CircularProgressIndicator()),
|
|
barrierDismissible: false);
|
|
|
|
try {
|
|
var payload = {
|
|
'driver_id': box.read(BoxName.driverID), // معرف السائق الحالي
|
|
'vin': vin,
|
|
'car_plate': plate,
|
|
'make': make,
|
|
'model': model,
|
|
'year': year,
|
|
'expiration_date': expiryDate,
|
|
'color': color,
|
|
'color_hex': colorHex,
|
|
'owner': owner,
|
|
'address': address,
|
|
'displacement': displacement,
|
|
'fuel': fuel,
|
|
'registration_date': inspectionDate,
|
|
};
|
|
|
|
// الاتصال بسكريبت PHP الجديد
|
|
var res = await CRUD().post(
|
|
link: AppLink.addNewCarsDrivers,
|
|
payload: payload); // تأكد من إضافة الرابط في links.dart
|
|
|
|
Get.back(); // إغلاق الـ Loading
|
|
|
|
var json = jsonDecode(res);
|
|
if (json['status'] == 'success') {
|
|
Get.snackbar("Success".tr, "New car added successfully".tr,
|
|
backgroundColor: AppColor.greenColor, colorText: Colors.white);
|
|
|
|
// تحديث قائمة السيارات (إذا كان لديك دالة تجلب السيارات)
|
|
// getDriverCars();
|
|
|
|
Get.back(); // العودة للصفحة السابقة
|
|
} else {
|
|
Get.snackbar("Error".tr, json['message'].toString().tr,
|
|
backgroundColor: AppColor.redColor, colorText: Colors.white);
|
|
}
|
|
} catch (e) {
|
|
Get.back();
|
|
print("Add Car Error: $e");
|
|
Get.snackbar("Error".tr, "Connection failed".tr);
|
|
}
|
|
}
|
|
|
|
addCarsForDrivers(
|
|
String vin,
|
|
String carPlate,
|
|
String make,
|
|
String model,
|
|
String year,
|
|
String expirationDate,
|
|
String color,
|
|
String colorHex,
|
|
String address,
|
|
String owner,
|
|
String registrationDate,
|
|
String displacement,
|
|
String fuel) async {
|
|
var res = await CRUD().post(
|
|
link: AppLink.addRegisrationCar,
|
|
payload: {
|
|
"driverID": box.read(BoxName.driverID).toString(),
|
|
"vin": vin ?? 'unknown',
|
|
"car_plate": carPlate.toString(),
|
|
"make": make ?? 'unknown',
|
|
"model": model ?? 'unknown',
|
|
"year": year ?? 'unknown',
|
|
"expiration_date": expirationDate ?? 'unknown',
|
|
"color": color ?? 'unknown',
|
|
"owner": owner ?? 'unknown',
|
|
"color_hex": colorHex ?? '#000000',
|
|
"address": address ?? 'unknown',
|
|
"displacement": displacement ?? 'unknown',
|
|
"fuel": fuel ?? 'unknown',
|
|
"registration_date": registrationDate ?? 'unknown',
|
|
},
|
|
);
|
|
if (res != 'failure') {
|
|
mySnackbarSuccess('');
|
|
|
|
fetchCatrsForDrivers();
|
|
} else {
|
|
mySnackeBarError('');
|
|
}
|
|
}
|
|
|
|
// update carRegistration only and insert on it without tow column
|
|
Future<void> updateCarRegistration(String id, String driverID) async {
|
|
final body = {
|
|
'id': id,
|
|
'driverID': driverID,
|
|
};
|
|
// remove default before update
|
|
var response = await CRUD().post(
|
|
link: AppLink.makeDefaultCar,
|
|
payload: body,
|
|
);
|
|
|
|
if (response != 'failure') {
|
|
mySnackbarSuccess('Updated'.tr);
|
|
} else {
|
|
mySnackeBarError('Not updated'.tr);
|
|
}
|
|
}
|
|
|
|
//todo need review
|
|
removeCar(String carId) async {
|
|
isLoading = true;
|
|
update();
|
|
var res = await CRUD().post(link: AppLink.deleteNewCarsDrivers, payload: {
|
|
"id": carId.toString(),
|
|
});
|
|
if (res != 'failure') {
|
|
mySnackbarSuccess('deleted'.tr);
|
|
}
|
|
isLoading = false;
|
|
update();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
fetchCatrsForDrivers();
|
|
super.onInit();
|
|
}
|
|
}
|