feat: change total to amount
Build Android APK (split per ABI) / build-apk (push) Waiting to run
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run

This commit is contained in:
efrilm
2026-10-20 18:22:02 +07:00
parent 7c8b36b65d
commit 24f94fa747
11 changed files with 326 additions and 87 deletions
@@ -69,17 +69,19 @@ class OrderRemoteDataProvider {
}
/// Backend belum punya endpoint ringkasan order, jadi jumlahnya diambil
/// dari `total_count` list order (limit 1 supaya payload kecil).
Future<DC<OrderFailure, int>> fetchTotalCount({
/// dari `total_count` list order, dan nominalnya dijumlahkan dari
/// `total_amount` tiap order (diambil per halaman sampai habis).
Future<DC<OrderFailure, OrderTotal>> fetchTotal({
String? status,
String? outletId,
required DateTime dateFrom,
required DateTime dateTo,
}) async {
const limit = 100;
try {
Map<String, dynamic> params = {
'page': 1,
'limit': 1,
'limit': limit,
'date_from': dateFrom.toServerDate,
'date_to': dateTo.toServerDate,
};
@@ -92,21 +94,42 @@ class OrderRemoteDataProvider {
params['outlet_id'] = outletId;
}
final response = await _apiClient.get(
ApiPath.order,
params: params,
headers: getAuthorizationHeader(),
);
int page = 1;
int count = 0;
int fetched = 0;
int amount = 0;
if (response.data['data'] == null) {
return DC.error(OrderFailure.empty());
while (true) {
final response = await _apiClient.get(
ApiPath.order,
params: {...params, 'page': page},
headers: getAuthorizationHeader(),
);
if (response.data['data'] == null) {
if (page == 1) return DC.error(OrderFailure.empty());
break;
}
final data = response.data['data'];
count = (data['total_count'] as num? ?? 0).toInt();
final orders = (data['orders'] as List? ?? [])
.map((item) => OrderDto.fromJson(item))
.toList();
for (final order in orders) {
amount += order.totalAmount ?? 0;
}
fetched += orders.length;
if (orders.isEmpty || fetched >= count) break;
page++;
}
final total = response.data['data']['total_count'] as num? ?? 0;
return DC.data(total.toInt());
return DC.data(OrderTotal(count: count, amount: amount));
} on ApiFailure catch (e, s) {
log('fetchOrderTotalCountError', name: _logName, error: e, stackTrace: s);
log('fetchOrderTotalError', name: _logName, error: e, stackTrace: s);
return DC.error(OrderFailure.serverError(e));
}
}