Update: 2026-08-03 11:32:12
This commit is contained in:
@@ -60,6 +60,9 @@ class FinancialV2Page extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildMainFinancialStats(ctrl.stats, cs),
|
||||
const SizedBox(height: 32),
|
||||
_buildSectionTitle('محفظة سيرو', cs),
|
||||
_buildSiroWalletSection(ctrl.walletSummary, cs),
|
||||
const SizedBox(height: 24),
|
||||
_buildSectionTitle('طرق الدفع', cs),
|
||||
_buildPaymentMethodBreakdown(ctrl.stats, cs),
|
||||
@@ -78,6 +81,116 @@ class FinancialV2Page extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// تنسيق مبلغ بفواصل آلاف وخانتين عشريتين.
|
||||
/// بلا رمز عملة عمداً: هذا النشر أردني بينما بطاقات هذه الشاشة الأخرى
|
||||
/// ما زالت تكتب "ج.م" ثابتة — راجع صحّتها قبل توحيد الرمز.
|
||||
String _money(double v) {
|
||||
final neg = v < 0;
|
||||
final parts = v.abs().toStringAsFixed(2).split('.');
|
||||
final digits = parts[0];
|
||||
final buf = StringBuffer();
|
||||
for (int i = 0; i < digits.length; i++) {
|
||||
if (i > 0 && (digits.length - i) % 3 == 0) buf.write(',');
|
||||
buf.write(digits[i]);
|
||||
}
|
||||
return '${neg ? '-' : ''}$buf.${parts[1]}';
|
||||
}
|
||||
|
||||
/// محفظة سيرو من خادم المدفوعات: الشهر الجاري مقابل الشهر السابق،
|
||||
/// والإجمالي التراكمي، مع فصل الإيداع عن الصرف.
|
||||
Widget _buildSiroWalletSection(
|
||||
Map<String, dynamic> summary, ColorScheme cs) {
|
||||
if (summary.isEmpty) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.account_balance_wallet_outlined,
|
||||
color: cs.onSurfaceVariant, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'تعذّر جلب ملخّص المحفظة من خادم المدفوعات',
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 13),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final mtd = (summary['month_to_date'] as Map?) ?? {};
|
||||
final allTime = (summary['all_time'] as Map?) ?? {};
|
||||
final growth = summary['growth_percent'];
|
||||
|
||||
double n(dynamic v) => double.tryParse('${v ?? 0}') ?? 0;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'صافي هذا الشهر',
|
||||
_money(n(mtd['net'])),
|
||||
Icons.calendar_month_rounded,
|
||||
cs.primary,
|
||||
cs,
|
||||
// المؤشّر يظهر فقط عند وجود شهر سابق يُقارن به
|
||||
subtitle: growth == null
|
||||
? null
|
||||
: '${n(growth) >= 0 ? '▲' : '▼'} ${n(growth).abs().toStringAsFixed(1)}% عن الشهر السابق',
|
||||
subtitleColor: growth == null
|
||||
? null
|
||||
: (n(growth) >= 0 ? cs.success : cs.danger),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'الإجمالي التراكمي',
|
||||
_money(n(allTime['net'])),
|
||||
Icons.savings_rounded,
|
||||
cs.tertiary,
|
||||
cs,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'إيداع هذا الشهر',
|
||||
_money(n(mtd['credits'])),
|
||||
Icons.south_west_rounded,
|
||||
cs.success,
|
||||
cs,
|
||||
subtitle: '${mtd['tx_count'] ?? 0} حركة',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildFinancialCard(
|
||||
'صرف هذا الشهر',
|
||||
_money(n(mtd['debits'])),
|
||||
Icons.north_east_rounded,
|
||||
cs.warning,
|
||||
cs,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title, ColorScheme cs) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
@@ -134,7 +247,7 @@ class FinancialV2Page extends StatelessWidget {
|
||||
|
||||
Widget _buildFinancialCard(
|
||||
String title, String value, IconData icon, Color color, ColorScheme cs,
|
||||
{bool isSmall = false}) {
|
||||
{bool isSmall = false, String? subtitle, Color? subtitleColor}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(isSmall ? 16 : 24),
|
||||
decoration: BoxDecoration(
|
||||
@@ -170,6 +283,14 @@ class FinancialV2Page extends StatelessWidget {
|
||||
color: cs.onSurface,
|
||||
fontSize: isSmall ? 18 : 24,
|
||||
fontWeight: FontWeight.bold)),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(subtitle,
|
||||
style: TextStyle(
|
||||
color: subtitleColor ?? cs.onSurfaceVariant,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:siro_admin/constant/theme.dart';
|
||||
import 'package:siro_admin/controller/admin/withdrawal_controller.dart';
|
||||
|
||||
/// شاشة طلبات سحب أرصدة السائقين.
|
||||
/// تتبع لغة تصميم شاشة الرحلات: أسطح محايدة، واللون للمعنى وحده.
|
||||
class WithdrawalRequestsPage extends StatelessWidget {
|
||||
const WithdrawalRequestsPage({super.key});
|
||||
|
||||
static const _filters = <String, String>{
|
||||
'pending': 'معلّقة',
|
||||
'approved': 'معتمدة',
|
||||
'paid': 'مدفوعة',
|
||||
'rejected': 'مرفوضة',
|
||||
'all': 'الكل',
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: cs.surface,
|
||||
body: GetBuilder<WithdrawalController>(
|
||||
init: Get.isRegistered<WithdrawalController>()
|
||||
? Get.find<WithdrawalController>()
|
||||
: WithdrawalController(),
|
||||
builder: (ctrl) {
|
||||
return Column(
|
||||
children: [
|
||||
_buildHeader(context, ctrl, cs),
|
||||
_buildTotals(ctrl, cs),
|
||||
_buildFilterBar(ctrl, cs),
|
||||
Expanded(
|
||||
child: ctrl.isLoading
|
||||
? Center(child: CircularProgressIndicator(color: cs.primary))
|
||||
: _buildList(ctrl, cs),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(
|
||||
BuildContext context, WithdrawalController ctrl, ColorScheme cs) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 50, 16, 16),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
border: Border(bottom: BorderSide(color: cs.outline)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Get.back(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Icon(Icons.arrow_back_ios_new_rounded,
|
||||
color: cs.onSurfaceVariant, size: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text('طلبات السحب',
|
||||
style: TextStyle(
|
||||
color: cs.onSurface,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.refresh_rounded, color: cs.onSurfaceVariant),
|
||||
onPressed: () => ctrl.fetchRequests(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTotals(WithdrawalController ctrl, ColorScheme cs) {
|
||||
if (ctrl.totals.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
Widget tile(String label, String key, Color color) {
|
||||
final t = ctrl.totals[key] as Map? ?? {};
|
||||
return Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: color.withValues(alpha: 0.22)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text('${t['count'] ?? 0}',
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800)),
|
||||
const SizedBox(height: 2),
|
||||
Text(label,
|
||||
style:
|
||||
TextStyle(color: cs.onSurfaceVariant, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
tile('معلّقة', 'pending', cs.warning),
|
||||
tile('معتمدة', 'approved', cs.info),
|
||||
tile('مدفوعة', 'paid', cs.success),
|
||||
tile('مرفوضة', 'rejected', cs.danger),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterBar(WithdrawalController ctrl, ColorScheme cs) {
|
||||
return SizedBox(
|
||||
height: 52,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
children: _filters.entries.map((e) {
|
||||
final selected = ctrl.filter == e.key;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8),
|
||||
child: GestureDetector(
|
||||
onTap: () => ctrl.changeFilter(e.key),
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? cs.primary.withValues(alpha: 0.12)
|
||||
: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: selected ? cs.primary : cs.outline),
|
||||
),
|
||||
child: Text(
|
||||
e.value,
|
||||
style: TextStyle(
|
||||
color: selected ? cs.primary : cs.onSurfaceVariant,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(WithdrawalController ctrl, ColorScheme cs) {
|
||||
if (ctrl.requests.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.inbox_rounded, color: cs.onSurfaceVariant, size: 40),
|
||||
const SizedBox(height: 10),
|
||||
Text('لا توجد طلبات في هذه الحالة',
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 13)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(12, 4, 12, 24),
|
||||
itemCount: ctrl.requests.length,
|
||||
itemBuilder: (_, i) => _buildCard(ctrl, ctrl.requests[i], cs),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard(WithdrawalController ctrl, dynamic r, ColorScheme cs) {
|
||||
final status = '${r['status'] ?? 'pending'}';
|
||||
final color = switch (status) {
|
||||
'approved' => cs.info,
|
||||
'paid' => cs.success,
|
||||
'rejected' => cs.danger,
|
||||
_ => cs.warning,
|
||||
};
|
||||
final id = int.tryParse('${r['id']}') ?? 0;
|
||||
final busy = ctrl.busyId == id;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text('${r['driver_name'] ?? 'سائق غير معروف'}',
|
||||
style: TextStyle(
|
||||
color: cs.onSurface,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700)),
|
||||
),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Text(_filters[status] ?? status,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.payments_rounded, size: 14, color: color),
|
||||
const SizedBox(width: 6),
|
||||
Text('${r['amount'] ?? 0}',
|
||||
style: TextStyle(
|
||||
color: cs.onSurface,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w800)),
|
||||
const SizedBox(width: 12),
|
||||
Icon(Icons.account_balance_wallet_outlined,
|
||||
size: 14, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${r['wallet_type'] ?? ''} — ${r['wallet_number'] ?? ''}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
TextStyle(color: cs.onSurfaceVariant, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text('#$id · ${r['created_at'] ?? ''}',
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11)),
|
||||
|
||||
// الإجراءات تظهر بحسب ما يقبله الخادم: من pending إلى أي حالة،
|
||||
// ومن approved إلى paid فقط. أي انتقال آخر يرفضه الخادم بـ 409.
|
||||
if (status == 'pending' || status == 'approved') ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
if (status == 'pending') ...[
|
||||
_action(ctrl, id, 'approved', 'اعتماد', cs.info, cs, busy),
|
||||
const SizedBox(width: 8),
|
||||
_action(ctrl, id, 'rejected', 'رفض', cs.danger, cs, busy),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
_action(ctrl, id, 'paid', 'تم الدفع', cs.success, cs, busy),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _action(WithdrawalController ctrl, int id, String status, String label,
|
||||
Color color, ColorScheme cs, bool busy) {
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: busy ? null : () => ctrl.updateStatus(id, status),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: busy ? 0.05 : 0.12),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: color.withValues(alpha: busy ? 0.15 : 0.35)),
|
||||
),
|
||||
child: busy
|
||||
? SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: color),
|
||||
)
|
||||
: Text(label,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user