83 lines
2.2 KiB
Dart
83 lines
2.2 KiB
Dart
import 'dart:convert';
|
|
import 'package:get/get.dart';
|
|
import 'package:siro_admin/constant/links.dart';
|
|
import 'package:siro_admin/controller/functions/crud.dart';
|
|
import '../../print.dart';
|
|
|
|
class FinancialV2Controller extends GetxController {
|
|
bool isLoading = true;
|
|
|
|
Map<String, dynamic> stats = {};
|
|
List<dynamic> settlements = [];
|
|
|
|
/// ملخّص محفظة سيرو القادم من خادم المدفوعات.
|
|
/// المفاتيح: month_to_date / previous_month / all_time / growth_percent
|
|
/// / by_payment_method — ولكل نافذة: credits و debits و net و tx_count.
|
|
Map<String, dynamic> walletSummary = {};
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchAllFinancials();
|
|
}
|
|
|
|
Future<void> fetchAllFinancials() async {
|
|
isLoading = true;
|
|
update();
|
|
|
|
await Future.wait([
|
|
fetchStats(),
|
|
fetchSettlements(),
|
|
fetchWalletSummary(),
|
|
]);
|
|
|
|
isLoading = false;
|
|
update();
|
|
}
|
|
|
|
Future<void> fetchWalletSummary() async {
|
|
try {
|
|
var res =
|
|
await CRUD().getWallet(link: AppLink.siroWalletSummary, payload: {});
|
|
if (res != 'failure' && res != null) {
|
|
var d = res is String ? jsonDecode(res) : res;
|
|
if (d['status'] == 'success' && d['data'] is Map) {
|
|
walletSummary = Map<String, dynamic>.from(d['data']);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
Log.print('Error fetching Siro wallet summary: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> fetchStats() async {
|
|
try {
|
|
var res =
|
|
await CRUD().getWallet(link: AppLink.financialStatsV2, payload: {});
|
|
if (res != 'failure' && res != null) {
|
|
var d = res is String ? jsonDecode(res) : res;
|
|
if (d['status'] == 'success') {
|
|
stats = d['data'];
|
|
}
|
|
}
|
|
} catch (e) {
|
|
Log.print('Error fetching financial stats: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> fetchSettlements() async {
|
|
try {
|
|
var res =
|
|
await CRUD().getWallet(link: AppLink.settlementsV2, payload: {});
|
|
if (res != 'failure' && res != null) {
|
|
var d = res is String ? jsonDecode(res) : res;
|
|
if (d['status'] == 'success') {
|
|
settlements = d['data'];
|
|
}
|
|
}
|
|
} catch (e) {
|
|
Log.print('Error fetching settlements: $e');
|
|
}
|
|
}
|
|
}
|