Update: 2026-08-08 14:09:20
This commit is contained in:
@@ -28,14 +28,17 @@ try {
|
|||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
d.id as driver_id,
|
d.id as driver_id,
|
||||||
COALESCE(d.name, d.nameArabic, d.firstName, 'Driver') as name,
|
-- الأعمدة الفعلية في جدول driver. الاستعلام السابق كان
|
||||||
d.personal_photo as photoUrl,
|
-- يطلب name / nameArabic / firstName / personal_photo وأيٌّ
|
||||||
|
-- منها غير موجود، فكان كل طلب يسقط بخطأ قاعدة بيانات.
|
||||||
|
d.first_name as first_name,
|
||||||
|
d.last_name as last_name,
|
||||||
COALESCE(SUM(r.price_for_driver), 0) as value
|
COALESCE(SUM(r.price_for_driver), 0) as value
|
||||||
FROM `driver` d
|
FROM `driver` d
|
||||||
JOIN `ride` r ON d.id = r.driver_id
|
JOIN `ride` r ON d.id = r.driver_id
|
||||||
WHERE r.status = 'Finished'
|
WHERE r.status = 'Finished'
|
||||||
AND r.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
|
AND r.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
|
||||||
GROUP BY d.id
|
GROUP BY d.id, d.first_name, d.last_name
|
||||||
ORDER BY value DESC
|
ORDER BY value DESC
|
||||||
LIMIT 10
|
LIMIT 10
|
||||||
";
|
";
|
||||||
@@ -44,14 +47,17 @@ try {
|
|||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
d.id as driver_id,
|
d.id as driver_id,
|
||||||
COALESCE(d.name, d.nameArabic, d.firstName, 'Driver') as name,
|
-- الأعمدة الفعلية في جدول driver. الاستعلام السابق كان
|
||||||
d.personal_photo as photoUrl,
|
-- يطلب name / nameArabic / firstName / personal_photo وأيٌّ
|
||||||
|
-- منها غير موجود، فكان كل طلب يسقط بخطأ قاعدة بيانات.
|
||||||
|
d.first_name as first_name,
|
||||||
|
d.last_name as last_name,
|
||||||
COUNT(r.id) as value
|
COUNT(r.id) as value
|
||||||
FROM `driver` d
|
FROM `driver` d
|
||||||
JOIN `ride` r ON d.id = r.driver_id
|
JOIN `ride` r ON d.id = r.driver_id
|
||||||
WHERE r.status = 'Finished'
|
WHERE r.status = 'Finished'
|
||||||
AND r.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
|
AND r.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
|
||||||
GROUP BY d.id
|
GROUP BY d.id, d.first_name, d.last_name
|
||||||
ORDER BY value DESC
|
ORDER BY value DESC
|
||||||
LIMIT 10
|
LIMIT 10
|
||||||
";
|
";
|
||||||
@@ -71,8 +77,20 @@ if ($stmt->rowCount() > 0) {
|
|||||||
$rank = 1;
|
$rank = 1;
|
||||||
foreach ($rows as &$row) {
|
foreach ($rows as &$row) {
|
||||||
$row['rank'] = $rank++;
|
$row['rank'] = $rank++;
|
||||||
|
|
||||||
|
// الأسماء مخزّنة مشفّرة في driver — بلا فكّ تشفير تظهر اللوحة
|
||||||
|
// صفوفاً من النص المشفّر. نعرض الاسم الأول فقط: لوحة صدارة
|
||||||
|
// عامة لا داعي لأن تكشف الاسم الكامل لكل سائق.
|
||||||
|
$first = !empty($row['first_name'])
|
||||||
|
? (string) $encryptionHelper->decryptData($row['first_name'])
|
||||||
|
: '';
|
||||||
|
unset($row['first_name'], $row['last_name']);
|
||||||
|
|
||||||
|
$row['name'] = $first !== '' ? $first : 'Driver';
|
||||||
|
$row['photoUrl'] = null;
|
||||||
}
|
}
|
||||||
|
unset($row);
|
||||||
|
|
||||||
$responseData = $rows;
|
$responseData = $rows;
|
||||||
} else {
|
} else {
|
||||||
$responseData = [];
|
$responseData = [];
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../../connect.php';
|
require_once __DIR__ . '/../../connect.php';
|
||||||
|
require_once __DIR__ . '/referral_code_helper.php';
|
||||||
|
|
||||||
// Use JWT token variables provided by connect.php
|
// Use JWT token variables provided by connect.php
|
||||||
if (!$user_id || $role != 'driver') {
|
if (!$user_id || $role != 'driver') {
|
||||||
jsonError("Invalid parameters or unauthorized token");
|
jsonError("Invalid parameters or unauthorized token");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Get the driver's referral code
|
// 1. Get the driver's referral code — ونُنشئه إن غاب.
|
||||||
$stmtCode = $con->prepare("SELECT referral_code FROM user_referral_codes WHERE user_id = ? AND user_type = 'driver'");
|
// الردّ بـ null كان يترك شاشة الدعوة تدور بلا كود إلى الأبد، لأن لا
|
||||||
$stmtCode->execute([$user_id]);
|
// شيء في التطبيق ينادي get_unified_code.php الذي يولّده.
|
||||||
|
$referralCode = ensureReferralCode($con, (string) $user_id, 'driver');
|
||||||
|
|
||||||
if ($stmtCode->rowCount() == 0) {
|
if ($referralCode === null) {
|
||||||
// If no code exists, return empty stats
|
|
||||||
printSuccess([
|
printSuccess([
|
||||||
"referral_code" => null,
|
"referral_code" => null,
|
||||||
"total_invited_drivers" => 0,
|
"total_invited_drivers" => 0,
|
||||||
@@ -21,8 +22,6 @@ if ($stmtCode->rowCount() == 0) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$referralCode = $stmtCode->fetchColumn();
|
|
||||||
|
|
||||||
// 2. Fetch all referrals made by this code
|
// 2. Fetch all referrals made by this code
|
||||||
$stmtRefs = $con->prepare("
|
$stmtRefs = $con->prepare("
|
||||||
SELECT id, invited_user_id, invited_user_type, status, trip_count, is_reward_claimed, created_at
|
SELECT id, invited_user_id, invited_user_type, status, trip_count, is_reward_claimed, created_at
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../../connect.php';
|
require_once __DIR__ . '/../../connect.php';
|
||||||
|
require_once __DIR__ . '/referral_code_helper.php';
|
||||||
|
|
||||||
// Use JWT token variables provided by connect.php
|
// Use JWT token variables provided by connect.php
|
||||||
if (!$user_id || $role != 'passenger') {
|
if (!$user_id || $role != 'passenger') {
|
||||||
@@ -8,12 +9,10 @@ if (!$user_id || $role != 'passenger') {
|
|||||||
|
|
||||||
$country_code = $_POST['country_code'] ?? 'Jordan';
|
$country_code = $_POST['country_code'] ?? 'Jordan';
|
||||||
|
|
||||||
// 1. Get the passenger's referral code
|
// 1. Get the passenger's referral code — ونُنشئه إن غاب (نفس علّة السائق).
|
||||||
$stmtCode = $con->prepare("SELECT referral_code FROM user_referral_codes WHERE user_id = ? AND user_type = 'passenger'");
|
$referralCode = ensureReferralCode($con, (string) $user_id, 'passenger');
|
||||||
$stmtCode->execute([$user_id]);
|
|
||||||
|
|
||||||
if ($stmtCode->rowCount() == 0) {
|
if ($referralCode === null) {
|
||||||
// If no code exists, return empty stats
|
|
||||||
printSuccess([
|
printSuccess([
|
||||||
"referral_code" => null,
|
"referral_code" => null,
|
||||||
"total_invited_drivers" => 0,
|
"total_invited_drivers" => 0,
|
||||||
@@ -23,8 +22,6 @@ if ($stmtCode->rowCount() == 0) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$referralCode = $stmtCode->fetchColumn();
|
|
||||||
|
|
||||||
// 2. Fetch all referrals made by this code
|
// 2. Fetch all referrals made by this code
|
||||||
$stmtRefs = $con->prepare("
|
$stmtRefs = $con->prepare("
|
||||||
SELECT id, invited_user_id, invited_user_type, status, trip_count, is_reward_claimed, created_at
|
SELECT id, invited_user_id, invited_user_type, status, trip_count, is_reward_claimed, created_at
|
||||||
|
|||||||
@@ -1,42 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../../connect.php';
|
require_once __DIR__ . '/../../connect.php';
|
||||||
|
// منطق التوليد انتقل إلى helper مشترك حتى تولّده نقاط القراءة أيضاً —
|
||||||
function generateUnifiedCode($con) {
|
// هذه النقطة لم تكن مُستدعاة من أي شاشة، فبقي الكود بلا توليد.
|
||||||
while (true) {
|
require_once __DIR__ . '/referral_code_helper.php';
|
||||||
$letters = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ"), 0, 2);
|
|
||||||
$numbers = substr(str_shuffle("23456789"), 0, 4);
|
|
||||||
$code = $letters . $numbers;
|
|
||||||
|
|
||||||
$stmt = $con->prepare("SELECT COUNT(*) FROM user_referral_codes WHERE referral_code = ?");
|
|
||||||
$stmt->execute([$code]);
|
|
||||||
|
|
||||||
if ($stmt->fetchColumn() == 0) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the JWT values exist
|
// Ensure the JWT values exist
|
||||||
if (!$user_id || !in_array($role, ['driver', 'passenger'])) {
|
if (!$user_id || !in_array($role, ['driver', 'passenger'])) {
|
||||||
jsonError("Invalid or missing user information in token");
|
jsonError("Invalid or missing user information in token");
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $con->prepare("SELECT referral_code FROM user_referral_codes WHERE user_id = ? AND user_type = ?");
|
$code = ensureReferralCode($con, (string) $user_id, (string) $role);
|
||||||
$stmt->execute([$user_id, $role]);
|
|
||||||
|
|
||||||
if ($stmt->rowCount() > 0) {
|
if ($code === null) {
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
jsonError("An internal error occurred. Please try again later.");
|
||||||
printSuccess(["referral_code" => $row['referral_code']]);
|
|
||||||
} else {
|
|
||||||
$newCode = generateUnifiedCode($con);
|
|
||||||
$insertStmt = $con->prepare("INSERT INTO user_referral_codes (user_id, user_type, referral_code) VALUES (?, ?, ?)");
|
|
||||||
|
|
||||||
try {
|
|
||||||
$insertStmt->execute([$user_id, $role, $newCode]);
|
|
||||||
printSuccess(["referral_code" => $newCode]);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
error_log("[get_unified_code.php] " . $e->getMessage());
|
|
||||||
jsonError("An internal error occurred. Please try again later.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
printSuccess(["referral_code" => $code]);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* referral_code_helper.php — توليد كود الدعوة عند أول قراءة
|
||||||
|
* ─────────────────────────────────────────────────────────────
|
||||||
|
* سبب وجود هذا الملف عطل قائم: `get_unified_code.php` وحده يولّد الكود،
|
||||||
|
* وهو غير مُستدعى من أي شاشة في التطبيقين — الرابط معرّف في links.dart
|
||||||
|
* ولا أحد يناديه. بينما `get_driver_referrals.php` و
|
||||||
|
* `get_passenger_referrals.php` تقرآن فقط وتردّان null.
|
||||||
|
*
|
||||||
|
* النتيجة: صفّ لم يُكتب قط في `user_referral_codes`، فكود الدعوة null
|
||||||
|
* دائماً وشاشة الدعوة تدور بلا نهاية عند السائق والراكب معاً.
|
||||||
|
*
|
||||||
|
* الإصلاح هنا لا في التطبيق: القراءة نفسها تُنشئ الكود إن غاب. هذا
|
||||||
|
* يعالج التطبيقات المنشورة أصلاً بلا انتظار إصدار جديد.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!function_exists('generateUnifiedCode')) {
|
||||||
|
function generateUnifiedCode(PDO $con): string
|
||||||
|
{
|
||||||
|
// حروف بلا I/O وأرقام بلا 0/1: الكود يُملى صوتياً بين السائقين.
|
||||||
|
for ($attempt = 0; $attempt < 20; $attempt++) {
|
||||||
|
$letters = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ"), 0, 2);
|
||||||
|
$numbers = substr(str_shuffle("23456789"), 0, 4);
|
||||||
|
$code = $letters . $numbers;
|
||||||
|
|
||||||
|
$stmt = $con->prepare("SELECT COUNT(*) FROM user_referral_codes WHERE referral_code = ?");
|
||||||
|
$stmt->execute([$code]);
|
||||||
|
if ((int) $stmt->fetchColumn() === 0) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// احتياط: حلقة while اللانهائية الأصلية كانت تُعلّق العامل كاملاً
|
||||||
|
// لو امتلأت مساحة الأكواد. نسقط لكود أطول بدل التعليق.
|
||||||
|
return substr(strtoupper(bin2hex(random_bytes(4))), 0, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('ensureReferralCode')) {
|
||||||
|
/**
|
||||||
|
* يعيد كود الدعوة للمستخدم، ويُنشئه إن لم يكن موجوداً.
|
||||||
|
* يعيد null فقط إذا تعذّرت الكتابة (لا يُسقط الطلب).
|
||||||
|
*/
|
||||||
|
function ensureReferralCode(PDO $con, string $userId, string $userType): ?string
|
||||||
|
{
|
||||||
|
$stmt = $con->prepare("SELECT referral_code FROM user_referral_codes WHERE user_id = ? AND user_type = ?");
|
||||||
|
$stmt->execute([$userId, $userType]);
|
||||||
|
$existing = $stmt->fetchColumn();
|
||||||
|
if ($existing !== false && $existing !== null && $existing !== '') {
|
||||||
|
return (string) $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$newCode = generateUnifiedCode($con);
|
||||||
|
$con->prepare("INSERT INTO user_referral_codes (user_id, user_type, referral_code) VALUES (?, ?, ?)")
|
||||||
|
->execute([$userId, $userType, $newCode]);
|
||||||
|
return $newCode;
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// سباق بين طلبين متزامنين: الآخر كتب الصفّ أولاً — نقرأه.
|
||||||
|
$stmt->execute([$userId, $userType]);
|
||||||
|
$raced = $stmt->fetchColumn();
|
||||||
|
if ($raced !== false && $raced !== null && $raced !== '') {
|
||||||
|
return (string) $raced;
|
||||||
|
}
|
||||||
|
error_log("[referral_code_helper] " . $e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,7 +45,10 @@ class DestinationController extends GetxController {
|
|||||||
|
|
||||||
if (response != null && response is Map && response['status'] == 'success') {
|
if (response != null && response is Map && response['status'] == 'success') {
|
||||||
final data = response['message'];
|
final data = response['message'];
|
||||||
if (data != null) {
|
// عند غياب وجهة نشطة يردّ السيرفر نصاً ("No active destination set.")
|
||||||
|
// لا خريطة، وفهرسته كخريطة كان يرمي
|
||||||
|
// type 'String' is not a subtype of type 'int'.
|
||||||
|
if (data is Map) {
|
||||||
final lat = double.tryParse(data['target_latitude']?.toString() ?? '0') ?? 0.0;
|
final lat = double.tryParse(data['target_latitude']?.toString() ?? '0') ?? 0.0;
|
||||||
final lng = double.tryParse(data['target_longitude']?.toString() ?? '0') ?? 0.0;
|
final lng = double.tryParse(data['target_longitude']?.toString() ?? '0') ?? 0.0;
|
||||||
activeLatLng = LatLng(lat, lng);
|
activeLatLng = LatLng(lat, lng);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import 'package:siro_driver/constant/box_name.dart';
|
|||||||
import 'package:siro_driver/constant/links.dart';
|
import 'package:siro_driver/constant/links.dart';
|
||||||
import 'package:siro_driver/controller/functions/crud.dart';
|
import 'package:siro_driver/controller/functions/crud.dart';
|
||||||
import 'package:siro_driver/main.dart';
|
import 'package:siro_driver/main.dart';
|
||||||
|
import 'package:siro_driver/print.dart';
|
||||||
import 'package:siro_driver/views/widgets/mycircular.dart';
|
import 'package:siro_driver/views/widgets/mycircular.dart';
|
||||||
|
|
||||||
import '../../../views/home/my_wallet/payment_screen_mtn.dart';
|
import '../../../views/home/my_wallet/payment_screen_mtn.dart';
|
||||||
@@ -88,9 +89,36 @@ class CaptainWalletController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future refreshCaptainWallet() async {
|
Future refreshCaptainWallet() async {
|
||||||
await getCaptainWalletFromRide();
|
// ═══════════════════════════════════════════════════════════════
|
||||||
await getCaptainWalletFromBuyPoints();
|
// isLoading كان يُطفأ في نهاية الدالة الثانية فقط. أي استثناء قبلها
|
||||||
// await checkAccountCaptainBank();
|
// — وأشهره سائق بلا أي دفعات، إذ يعود message = [] فيرمي فهرسه
|
||||||
|
// [0] خطأ نطاق — كان يترك الشاشة تدور بلا نهاية بلا رسالة.
|
||||||
|
// finally يضمن إطفاءه مهما حدث.
|
||||||
|
// ═══════════════════════════════════════════════════════════════
|
||||||
|
isLoading = true;
|
||||||
|
update();
|
||||||
|
try {
|
||||||
|
await getCaptainWalletFromRide();
|
||||||
|
await getCaptainWalletFromBuyPoints();
|
||||||
|
// await checkAccountCaptainBank();
|
||||||
|
} catch (e) {
|
||||||
|
Log.print('❌ refreshCaptainWallet: $e');
|
||||||
|
mySnackbarError('Connection problem, please try again'.tr);
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// يقرأ رقماً من ردّ المحفظة بأمان: الردّ قد يكون خريطة بلا `message`،
|
||||||
|
/// أو قائمة فارغة (سائق جديد بلا دفعات) — وكلاهما كان يُسقط الشاشة.
|
||||||
|
static String _readWalletNumber(dynamic decoded, String key) {
|
||||||
|
if (decoded is! Map) return '0';
|
||||||
|
final message = decoded['message'];
|
||||||
|
if (message is! List || message.isEmpty) return '0';
|
||||||
|
final first = message.first;
|
||||||
|
if (first is! Map) return '0';
|
||||||
|
return first[key]?.toString() ?? '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
List amountToNewDriverMap = [];
|
List amountToNewDriverMap = [];
|
||||||
@@ -122,23 +150,27 @@ class CaptainWalletController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future getCaptainWalletFromRide() async {
|
Future getCaptainWalletFromRide() async {
|
||||||
isLoading = true;
|
|
||||||
update();
|
|
||||||
var res = await CRUD().getWallet(
|
var res = await CRUD().getWallet(
|
||||||
link: AppLink.getAllPaymentFromRide,
|
link: AppLink.getAllPaymentFromRide,
|
||||||
payload: {'driverID': box.read(BoxName.driverID).toString()},
|
payload: {'driverID': box.read(BoxName.driverID).toString()},
|
||||||
);
|
);
|
||||||
// isLoading = false;
|
|
||||||
if (res != 'failure') {
|
if (res != 'failure') {
|
||||||
walletDate = jsonDecode(res);
|
final decoded = jsonDecode(res);
|
||||||
totalAmount = walletDate['message'][0]['total_amount'] ?? '0';
|
walletDate = decoded is Map ? decoded : {};
|
||||||
|
totalAmount = _readWalletNumber(decoded, 'total_amount');
|
||||||
update();
|
update();
|
||||||
|
|
||||||
var res1 = await CRUD().getWallet(
|
var res1 = await CRUD().getWallet(
|
||||||
link: AppLink.getAllPaymentVisa,
|
link: AppLink.getAllPaymentVisa,
|
||||||
payload: {'driverID': box.read(BoxName.driverID).toString()});
|
payload: {'driverID': box.read(BoxName.driverID).toString()});
|
||||||
walletDateVisa = jsonDecode(res1);
|
if (res1 != 'failure') {
|
||||||
totalAmountVisa = walletDateVisa['message'][0]['diff'].toString();
|
final decodedVisa = jsonDecode(res1);
|
||||||
|
walletDateVisa = decodedVisa is Map ? decodedVisa : {};
|
||||||
|
totalAmountVisa = _readWalletNumber(decodedVisa, 'diff');
|
||||||
|
} else {
|
||||||
|
totalAmountVisa = '0';
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
totalAmount = "0";
|
totalAmount = "0";
|
||||||
@@ -147,21 +179,16 @@ class CaptainWalletController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future getCaptainWalletFromBuyPoints() async {
|
Future getCaptainWalletFromBuyPoints() async {
|
||||||
// isLoading = true;
|
|
||||||
update();
|
|
||||||
|
|
||||||
var res = await CRUD().getWallet(
|
var res = await CRUD().getWallet(
|
||||||
link: AppLink.getDriverPaymentPoints,
|
link: AppLink.getDriverPaymentPoints,
|
||||||
payload: {'driverID': box.read(BoxName.driverID).toString()},
|
payload: {'driverID': box.read(BoxName.driverID).toString()},
|
||||||
);
|
);
|
||||||
isLoading = false;
|
|
||||||
// update();
|
|
||||||
|
|
||||||
if (res != 'failure') {
|
if (res != 'failure') {
|
||||||
walletDriverPointsDate = jsonDecode(res);
|
final decoded = jsonDecode(res);
|
||||||
double totalPointsDouble = double.parse(
|
walletDriverPointsDate = decoded is Map ? decoded : {};
|
||||||
walletDriverPointsDate['message'][0]['total_amount'].toString());
|
final raw = _readWalletNumber(decoded, 'total_amount');
|
||||||
totalPoints = totalPointsDouble.toStringAsFixed(0);
|
totalPoints = (double.tryParse(raw) ?? 0).toStringAsFixed(0);
|
||||||
} else {
|
} else {
|
||||||
totalPoints = '0';
|
totalPoints = '0';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ class DriverScheduledRidesController extends GetxController {
|
|||||||
final bookings = <Map<String, dynamic>>[].obs;
|
final bookings = <Map<String, dynamic>>[].obs;
|
||||||
final isLoading = false.obs;
|
final isLoading = false.obs;
|
||||||
|
|
||||||
|
/// فشل الجلب ≠ لا توجد حجوزات. بدون هذا العلم كانت الشاشة تعرض
|
||||||
|
/// "لا حجوزات قادمة" حتى حين يردّ السيرفر 500، فيطمئن الكابتن
|
||||||
|
/// لعدم وجود عمل بينما الحقيقة أننا لا نعرف.
|
||||||
|
final hasError = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@@ -21,13 +26,19 @@ class DriverScheduledRidesController extends GetxController {
|
|||||||
try {
|
try {
|
||||||
final res = await _crud.post(
|
final res = await _crud.post(
|
||||||
link: AppLink.scheduledList,
|
link: AppLink.scheduledList,
|
||||||
payload: {'scope': 'upcoming_driver'},
|
payload: {'scope': 'upcoming_driver'},
|
||||||
);
|
);
|
||||||
final data = _extract(res);
|
final data = _extract(res);
|
||||||
final list = (data?['bookings'] as List?) ?? [];
|
if (data == null) {
|
||||||
|
hasError.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final list = (data['bookings'] as List?) ?? [];
|
||||||
bookings.assignAll(
|
bookings.assignAll(
|
||||||
list.map((e) => Map<String, dynamic>.from(e as Map)).toList());
|
list.map((e) => Map<String, dynamic>.from(e as Map)).toList());
|
||||||
|
hasError.value = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
hasError.value = true;
|
||||||
mySnackbarError('Failed to fetch scheduled rides'.tr);
|
mySnackbarError('Failed to fetch scheduled rides'.tr);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
|||||||
@@ -945,6 +945,10 @@
|
|||||||
"Sun": "أحد",
|
"Sun": "أحد",
|
||||||
"Upcoming Scheduled Rides": "الرحلات المجدولة القادمة",
|
"Upcoming Scheduled Rides": "الرحلات المجدولة القادمة",
|
||||||
"You have no upcoming scheduled rides": "ليس لديك رحلات مجدولة قادمة",
|
"You have no upcoming scheduled rides": "ليس لديك رحلات مجدولة قادمة",
|
||||||
|
"Could not load scheduled rides": "تعذّر تحميل الرحلات المجدولة",
|
||||||
|
"Please check your connection and try again.": "تحقّق من اتصالك ثم أعد المحاولة.",
|
||||||
|
"Retry": "إعادة المحاولة",
|
||||||
|
"Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.": "لم تُطلق خطط التأمين في منطقتك بعد. ستظهر هنا تلقائياً فور توفّر خطة من أحد الشركاء.",
|
||||||
"Starting Point": "نقطة الانطلاق",
|
"Starting Point": "نقطة الانطلاق",
|
||||||
"Destination": "وجهة الوصول",
|
"Destination": "وجهة الوصول",
|
||||||
"Failed to fetch scheduled rides": "تعذّر جلب الرحلات المجدولة",
|
"Failed to fetch scheduled rides": "تعذّر جلب الرحلات المجدولة",
|
||||||
|
|||||||
@@ -903,6 +903,10 @@
|
|||||||
"Sun": "Sun",
|
"Sun": "Sun",
|
||||||
"Upcoming Scheduled Rides": "Upcoming Scheduled Rides",
|
"Upcoming Scheduled Rides": "Upcoming Scheduled Rides",
|
||||||
"You have no upcoming scheduled rides": "You have no upcoming scheduled rides",
|
"You have no upcoming scheduled rides": "You have no upcoming scheduled rides",
|
||||||
|
"Could not load scheduled rides": "Could not load scheduled rides",
|
||||||
|
"Please check your connection and try again.": "Please check your connection and try again.",
|
||||||
|
"Retry": "Retry",
|
||||||
|
"Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.": "Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.",
|
||||||
"Starting Point": "Starting Point",
|
"Starting Point": "Starting Point",
|
||||||
"Destination": "Destination",
|
"Destination": "Destination",
|
||||||
"Failed to fetch scheduled rides": "Failed to fetch scheduled rides",
|
"Failed to fetch scheduled rides": "Failed to fetch scheduled rides",
|
||||||
|
|||||||
@@ -222,24 +222,34 @@ class _HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
// ── Logo + App Name ──────────────────────
|
// ── Logo + App Name ──────────────────────
|
||||||
title: Padding(
|
title: Padding(
|
||||||
padding: const EdgeInsets.only(left: 4),
|
padding: const EdgeInsets.only(left: 4),
|
||||||
child: Row(
|
// شارات الـ actions تلتهم عرض الـ AppBar فلا يبقى للعنوان أحياناً
|
||||||
mainAxisSize: MainAxisSize.min,
|
// سوى ~26px، بينما الشعار وحده 36px — ومن هنا كان الفيض.
|
||||||
children: [
|
// نُسقط الاسم عند ضيق المساحة ونُبقي الشعار: هو الهوية الأهم.
|
||||||
_LogoBadge(),
|
child: LayoutBuilder(
|
||||||
const SizedBox(width: 6),
|
builder: (context, constraints) {
|
||||||
Flexible(
|
final showName = constraints.maxWidth >= 96;
|
||||||
child: Text(
|
return Row(
|
||||||
AppInformation.appName.split(' ')[0].tr,
|
mainAxisSize: MainAxisSize.min,
|
||||||
style: const TextStyle(
|
children: [
|
||||||
color: _Token.accent,
|
_LogoBadge(),
|
||||||
fontSize: 18,
|
if (showName) ...[
|
||||||
fontWeight: FontWeight.w800,
|
const SizedBox(width: 6),
|
||||||
letterSpacing: 0.5,
|
Flexible(
|
||||||
),
|
child: Text(
|
||||||
overflow: TextOverflow.ellipsis,
|
AppInformation.appName.split(' ')[0].tr,
|
||||||
),
|
style: const TextStyle(
|
||||||
),
|
color: _Token.accent,
|
||||||
],
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
|
letterSpacing: 0.5,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
|||||||
@@ -140,14 +140,39 @@ class DriverInsurancePage extends StatelessWidget {
|
|||||||
// ── الخطط المتاحة ──────────────────────────────────────────
|
// ── الخطط المتاحة ──────────────────────────────────────────
|
||||||
List<Widget> _plansView(BuildContext context, DriverInsuranceController c) {
|
List<Widget> _plansView(BuildContext context, DriverInsuranceController c) {
|
||||||
if (c.plans.isEmpty) {
|
if (c.plans.isEmpty) {
|
||||||
|
// الصفحة كانت تبدو "معطّلة" لأنها تعرض عنواناً واحداً بلا سبب.
|
||||||
|
// الحالة الحقيقية: لا خطط مُفعّلة بعد لدى الشركاء — لا خطأ ولا
|
||||||
|
// نقص أهلية — ونقولها صراحة حتى لا يظن الكابتن أن التطبيق خربان.
|
||||||
return [
|
return [
|
||||||
const SizedBox(height: 80),
|
const SizedBox(height: 72),
|
||||||
Icon(Icons.health_and_safety_outlined,
|
Icon(Icons.health_and_safety_outlined,
|
||||||
size: 80, color: Colors.grey.shade400),
|
size: 80, color: Colors.grey.shade400),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text('No insurance plans available yet'.tr,
|
Text('No insurance plans available yet'.tr,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(fontSize: 18, color: Colors.grey)),
|
style: const TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: Colors.grey)),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
child: Text(
|
||||||
|
'Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.'
|
||||||
|
.tr,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14, height: 1.5, color: Colors.grey.shade600),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Center(
|
||||||
|
child: TextButton.icon(
|
||||||
|
onPressed: c.isLoading.value ? null : () => c.refreshAll(),
|
||||||
|
icon: const Icon(Icons.refresh_rounded, size: 18),
|
||||||
|
label: Text('Refresh'.tr),
|
||||||
|
),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,44 @@ class DriverScheduledRidesPage extends StatelessWidget {
|
|||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// تعذّر الجلب: نقولها بدل ادّعاء "لا حجوزات" — الفرق بينهما
|
||||||
|
// هو الفرق بين كابتن يطمئن وكابتن يفوته عمل مؤكد.
|
||||||
|
if (controller.hasError.value) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.cloud_off_rounded,
|
||||||
|
size: 80, color: Colors.grey.shade400),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Could not load scheduled rides'.tr,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: Colors.grey),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
|
child: Text(
|
||||||
|
'Please check your connection and try again.'.tr,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14, color: Colors.grey.shade600, height: 1.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
ElevatedButton.icon(
|
||||||
|
onPressed: controller.fetch,
|
||||||
|
icon: const Icon(Icons.refresh_rounded, size: 18),
|
||||||
|
label: Text('Retry'.tr),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (controller.bookings.isEmpty) {
|
if (controller.bookings.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ class StatSummaryCard extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(16),
|
// رأسي 12 لا 16: البطاقة داخل شبكة بارتفاع ثابت، و16 كانت تتجاوزه
|
||||||
|
// بنحو 10px مع خط الرقم مقاس 22.
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: FinanceDesignSystem.cardColor,
|
color: FinanceDesignSystem.cardColor,
|
||||||
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
borderRadius: BorderRadius.circular(FinanceDesignSystem.cardRadius),
|
||||||
@@ -54,14 +56,22 @@ class StatSummaryCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// الرقم يتقلّص بدل أن يفيض: مبالغ الأرباح تطول بلا سقف
|
||||||
value,
|
// (٤ خانات + كسور + عملة) والبطاقة عرضها ثابت.
|
||||||
style: TextStyle(
|
FittedBox(
|
||||||
fontSize: 22,
|
fit: BoxFit.scaleDown,
|
||||||
fontWeight: FontWeight.w900,
|
alignment: AlignmentDirectional.centerStart,
|
||||||
color: FinanceDesignSystem.primaryDark,
|
child: Text(
|
||||||
fontFamily: 'digit',
|
value,
|
||||||
|
maxLines: 1,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
color: FinanceDesignSystem.primaryDark,
|
||||||
|
fontFamily: 'digit',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
Reference in New Issue
Block a user