report category
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
part of '../analytic_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class CategoryAnalyticDto with _$CategoryAnalyticDto {
|
||||
const CategoryAnalyticDto._();
|
||||
|
||||
const factory CategoryAnalyticDto({
|
||||
@JsonKey(name: "organization_id") String? organizationId,
|
||||
@JsonKey(name: "outlet_id") String? outletId,
|
||||
@JsonKey(name: "date_from") DateTime? dateFrom,
|
||||
@JsonKey(name: "date_to") DateTime? dateTo,
|
||||
List<CategoryAnalyticItemDto>? data,
|
||||
}) = _CategoryAnalyticDto;
|
||||
|
||||
factory CategoryAnalyticDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CategoryAnalyticDtoFromJson(json);
|
||||
|
||||
// Optional mapper ke entity
|
||||
CategoryAnalytic toDomain() => CategoryAnalytic(
|
||||
organizationId: organizationId ?? '',
|
||||
outletId: outletId ?? '',
|
||||
dateFrom: dateFrom ?? DateTime.now(),
|
||||
dateTo: dateTo ?? DateTime.now(),
|
||||
data: data?.map((e) => e.toDomain()).toList() ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class CategoryAnalyticItemDto with _$CategoryAnalyticItemDto {
|
||||
const CategoryAnalyticItemDto._();
|
||||
|
||||
const factory CategoryAnalyticItemDto({
|
||||
@JsonKey(name: "category_id") String? categoryId,
|
||||
@JsonKey(name: "category_name") String? categoryName,
|
||||
@JsonKey(name: "total_revenue") int? totalRevenue,
|
||||
@JsonKey(name: "total_quantity") int? totalQuantity,
|
||||
@JsonKey(name: "product_count") int? productCount,
|
||||
@JsonKey(name: "order_count") int? orderCount,
|
||||
}) = _CategoryAnalyticItemDto;
|
||||
|
||||
factory CategoryAnalyticItemDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CategoryAnalyticItemDtoFromJson(json);
|
||||
|
||||
// Optional mapper ke entity
|
||||
CategoryAnalyticItem toDomain() => CategoryAnalyticItem(
|
||||
categoryId: categoryId ?? '',
|
||||
categoryName: categoryName ?? '',
|
||||
totalRevenue: totalRevenue ?? 0,
|
||||
totalQuantity: totalQuantity ?? 0,
|
||||
productCount: productCount ?? 0,
|
||||
orderCount: orderCount ?? 0,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user