report category
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
part of '../analytic.dart';
|
||||
|
||||
@freezed
|
||||
class CategoryAnalytic with _$CategoryAnalytic {
|
||||
const CategoryAnalytic._();
|
||||
|
||||
const factory CategoryAnalytic({
|
||||
required String organizationId,
|
||||
required String outletId,
|
||||
required DateTime dateFrom,
|
||||
required DateTime dateTo,
|
||||
required List<CategoryAnalyticItem> data,
|
||||
}) = _CategoryAnalytic;
|
||||
|
||||
factory CategoryAnalytic.empty() => CategoryAnalytic(
|
||||
organizationId: '',
|
||||
outletId: '',
|
||||
dateFrom: DateTime.now(),
|
||||
dateTo: DateTime.now(),
|
||||
data: const [],
|
||||
);
|
||||
|
||||
int get totalRevenue => data.fold(0, (sum, item) => sum + item.totalRevenue);
|
||||
|
||||
int get totalQuantity =>
|
||||
data.fold(0, (sum, item) => sum + item.totalQuantity);
|
||||
|
||||
int get totalOrders => data.fold(0, (sum, item) => sum + item.orderCount);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class CategoryAnalyticItem with _$CategoryAnalyticItem {
|
||||
const factory CategoryAnalyticItem({
|
||||
required String categoryId,
|
||||
required String categoryName,
|
||||
required int totalRevenue,
|
||||
required int totalQuantity,
|
||||
required int productCount,
|
||||
required int orderCount,
|
||||
}) = _CategoryAnalyticItem;
|
||||
|
||||
factory CategoryAnalyticItem.empty() => const CategoryAnalyticItem(
|
||||
categoryId: '',
|
||||
categoryName: '',
|
||||
totalRevenue: 0,
|
||||
totalQuantity: 0,
|
||||
productCount: 0,
|
||||
orderCount: 0,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user