305 lines
10 KiB
Dart
305 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:siro_admin/controller/admin/financial_v2_controller.dart';
|
|
|
|
class FinancialV2Page extends StatelessWidget {
|
|
const FinancialV2Page({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
final controller = Get.put(FinancialV2Controller());
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
body: Column(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.fromLTRB(16, 50, 16, 16),
|
|
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: () => controller.fetchAllFinancials(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: GetBuilder<FinancialV2Controller>(
|
|
builder: (ctrl) {
|
|
if (ctrl.isLoading) {
|
|
return Center(
|
|
child: CircularProgressIndicator(color: cs.primary));
|
|
}
|
|
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildMainFinancialStats(ctrl.stats, cs),
|
|
const SizedBox(height: 24),
|
|
_buildSectionTitle('طرق الدفع', cs),
|
|
_buildPaymentMethodBreakdown(ctrl.stats, cs),
|
|
const SizedBox(height: 32),
|
|
_buildSectionTitle('تسويات الكباتن (مستحقات معلقة)', cs),
|
|
_buildSettlementsList(ctrl.settlements, cs),
|
|
const SizedBox(height: 40),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSectionTitle(String title, ColorScheme cs) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMainFinancialStats(Map<String, dynamic> stats, ColorScheme cs) {
|
|
return Column(
|
|
children: [
|
|
_buildFinancialCard(
|
|
'إجمالي عمولة المنصة',
|
|
'${stats['total_platform_commission'] ?? 0} ج.م',
|
|
Icons.account_balance_rounded,
|
|
cs.primary,
|
|
cs,
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: _buildFinancialCard(
|
|
'إجمالي دخل الكباتن',
|
|
'${stats['total_driver_pay'] ?? 0}',
|
|
Icons.person_pin_rounded,
|
|
cs.tertiary,
|
|
cs,
|
|
isSmall: true,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: _buildFinancialCard(
|
|
'إجمالي الإيرادات',
|
|
'${stats['total_revenue'] ?? 0}',
|
|
Icons.payments_rounded,
|
|
const Color(0xFF10B981),
|
|
cs,
|
|
isSmall: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildFinancialCard(
|
|
String title, String value, IconData icon, Color color, ColorScheme cs,
|
|
{bool isSmall = false}) {
|
|
return Container(
|
|
padding: EdgeInsets.all(isSmall ? 16 : 24),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: color.withValues(alpha: 0.2)),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [cs.surfaceContainerHighest, color.withValues(alpha: 0.05)],
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Icon(icon, color: color, size: isSmall ? 20 : 28),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title,
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 12)),
|
|
const SizedBox(height: 4),
|
|
Text(value,
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: isSmall ? 18 : 24,
|
|
fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildPaymentMethodBreakdown(
|
|
Map<String, dynamic> stats, ColorScheme cs) {
|
|
double cash = double.tryParse(stats['cash_payments'].toString()) ?? 0;
|
|
double digital = double.tryParse(stats['digital_payments'].toString()) ?? 0;
|
|
double total = cash + digital;
|
|
if (total == 0) total = 1;
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildPaymentBar('نقدي (Cash)', cash, total, cs.tertiary, cs),
|
|
const SizedBox(height: 16),
|
|
_buildPaymentBar('إلكتروني / محفظة', digital, total, cs.tertiary, cs),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildPaymentBar(
|
|
String label, double value, double total, Color color, ColorScheme cs) {
|
|
double percent = value / total;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(label, style: TextStyle(color: cs.onSurface, fontSize: 13)),
|
|
Text('${value.toStringAsFixed(0)} ج.م',
|
|
style: TextStyle(color: color, fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: LinearProgressIndicator(
|
|
value: percent,
|
|
backgroundColor: cs.outline,
|
|
color: color,
|
|
minHeight: 8,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildSettlementsList(List<dynamic> settlements, ColorScheme cs) {
|
|
if (settlements.isEmpty) {
|
|
return Center(
|
|
child: Text('لا توجد تسويات معلقة',
|
|
style: TextStyle(color: cs.onSurfaceVariant)));
|
|
}
|
|
|
|
return ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: settlements.length,
|
|
itemBuilder: (ctx, i) {
|
|
final s = settlements[i];
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('${s['first_name']} ${s['last_name']}',
|
|
style: TextStyle(
|
|
color: cs.onSurface, fontWeight: FontWeight.bold)),
|
|
Text(s['phone'] ?? '',
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 12)),
|
|
const SizedBox(height: 4),
|
|
Text('${s['total_rides']} رحلة مكتملة',
|
|
style: TextStyle(color: cs.tertiary, fontSize: 11)),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text('المستحقات',
|
|
style:
|
|
TextStyle(color: cs.onSurfaceVariant, fontSize: 10)),
|
|
Text('${s['total_earned']} ج.م',
|
|
style: TextStyle(
|
|
color: cs.primary,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 4),
|
|
ElevatedButton(
|
|
onPressed: () {},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: cs.primary.withValues(alpha: 0.1),
|
|
foregroundColor: cs.primary,
|
|
elevation: 0,
|
|
minimumSize: const Size(80, 32),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8)),
|
|
),
|
|
child: const Text('تسوية',
|
|
style: TextStyle(
|
|
fontSize: 11, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|