part of '../analytic_dtos.dart'; @freezed class ProfitLossAnalyticDto with _$ProfitLossAnalyticDto { const ProfitLossAnalyticDto._(); const factory ProfitLossAnalyticDto({ @JsonKey(name: 'organization_id') String? organizationId, @JsonKey(name: 'date_from') String? dateFrom, @JsonKey(name: 'date_to') String? dateTo, @JsonKey(name: 'group_by') String? groupBy, @JsonKey(name: 'summary') ProfitLossSummaryDto? summary, @JsonKey(name: 'data') List? data, @JsonKey(name: 'product_data') List? productData, }) = _ProfitLossAnalyticDto; factory ProfitLossAnalyticDto.fromJson(Map json) => _$ProfitLossAnalyticDtoFromJson(json); ProfitLossAnalytic toDomain() => ProfitLossAnalytic( organizationId: organizationId ?? '', dateFrom: dateFrom ?? '', dateTo: dateTo ?? '', groupBy: groupBy ?? '', summary: summary?.toDomain() ?? ProfitLossSummary.empty(), data: (data ?? []).map((e) => e.toDomain()).toList(), productData: (productData ?? []).map((e) => e.toDomain()).toList(), ); } @freezed class ProfitLossSummaryDto with _$ProfitLossSummaryDto { const ProfitLossSummaryDto._(); const factory ProfitLossSummaryDto({ @JsonKey(name: 'total_revenue') int? totalRevenue, @JsonKey(name: 'total_cost') int? totalCost, @JsonKey(name: 'gross_profit') int? grossProfit, @JsonKey(name: 'gross_profit_margin') double? grossProfitMargin, @JsonKey(name: 'total_tax') int? totalTax, @JsonKey(name: 'total_discount') int? totalDiscount, @JsonKey(name: 'net_profit') int? netProfit, @JsonKey(name: 'net_profit_margin') double? netProfitMargin, @JsonKey(name: 'total_orders') int? totalOrders, @JsonKey(name: 'average_profit') double? averageProfit, @JsonKey(name: 'profitability_ratio') double? profitabilityRatio, }) = _ProfitLossSummaryDto; factory ProfitLossSummaryDto.fromJson(Map json) => _$ProfitLossSummaryDtoFromJson(json); ProfitLossSummary toDomain() => ProfitLossSummary( totalRevenue: totalRevenue ?? 0, totalCost: totalCost ?? 0, grossProfit: grossProfit ?? 0, grossProfitMargin: grossProfitMargin ?? 0.0, totalTax: totalTax ?? 0, totalDiscount: totalDiscount ?? 0, netProfit: netProfit ?? 0, netProfitMargin: netProfitMargin ?? 0.0, totalOrders: totalOrders ?? 0, averageProfit: averageProfit ?? 0.0, profitabilityRatio: profitabilityRatio ?? 0.0, ); } @freezed class ProfitLossDailyDataDto with _$ProfitLossDailyDataDto { const ProfitLossDailyDataDto._(); const factory ProfitLossDailyDataDto({ @JsonKey(name: 'date') String? date, @JsonKey(name: 'revenue') int? revenue, @JsonKey(name: 'cost') int? cost, @JsonKey(name: 'gross_profit') int? grossProfit, @JsonKey(name: 'gross_profit_margin') double? grossProfitMargin, @JsonKey(name: 'tax') int? tax, @JsonKey(name: 'discount') int? discount, @JsonKey(name: 'net_profit') int? netProfit, @JsonKey(name: 'net_profit_margin') double? netProfitMargin, @JsonKey(name: 'orders') int? orders, }) = _ProfitLossDailyDataDto; factory ProfitLossDailyDataDto.fromJson(Map json) => _$ProfitLossDailyDataDtoFromJson(json); ProfitLossDailyData toDomain() => ProfitLossDailyData( date: date ?? '', revenue: revenue ?? 0, cost: cost ?? 0, grossProfit: grossProfit ?? 0, grossProfitMargin: grossProfitMargin ?? 0.0, tax: tax ?? 0, discount: discount ?? 0, netProfit: netProfit ?? 0, netProfitMargin: netProfitMargin ?? 0.0, orders: orders ?? 0, ); } @freezed class ProfitLossProductDataDto with _$ProfitLossProductDataDto { const ProfitLossProductDataDto._(); const factory ProfitLossProductDataDto({ @JsonKey(name: 'product_id') String? productId, @JsonKey(name: 'product_name') String? productName, @JsonKey(name: 'category_id') String? categoryId, @JsonKey(name: 'category_name') String? categoryName, @JsonKey(name: 'quantity_sold') int? quantitySold, @JsonKey(name: 'revenue') int? revenue, @JsonKey(name: 'cost') int? cost, @JsonKey(name: 'gross_profit') int? grossProfit, @JsonKey(name: 'gross_profit_margin') double? grossProfitMargin, @JsonKey(name: 'average_price') int? averagePrice, @JsonKey(name: 'average_cost') int? averageCost, @JsonKey(name: 'profit_per_unit') int? profitPerUnit, }) = _ProfitLossProductDataDto; factory ProfitLossProductDataDto.fromJson(Map json) => _$ProfitLossProductDataDtoFromJson(json); ProfitLossProductData toDomain() => ProfitLossProductData( productId: productId ?? '', productName: productName ?? '', categoryId: categoryId ?? '', categoryName: categoryName ?? '', quantitySold: quantitySold ?? 0, revenue: revenue ?? 0, cost: cost ?? 0, grossProfit: grossProfit ?? 0, grossProfitMargin: grossProfitMargin ?? 0.0, averagePrice: averagePrice ?? 0, averageCost: averageCost ?? 0, profitPerUnit: profitPerUnit ?? 0, ); }