report sales

This commit is contained in:
efrilm
2025-11-03 17:18:29 +07:00
parent b4a9cf31fc
commit 3bb6bd653e
20 changed files with 3003 additions and 7 deletions
@@ -6,3 +6,4 @@ part 'analytic_dtos.freezed.dart';
part 'analytic_dtos.g.dart';
part 'dtos/dashboard_dto.dart';
part 'dtos/sales_dto.dart';
@@ -1745,3 +1745,997 @@ abstract class _DashboardRecentSaleDto extends DashboardRecentSaleDto {
_$$DashboardRecentSaleDtoImplCopyWith<_$DashboardRecentSaleDtoImpl>
get copyWith => throw _privateConstructorUsedError;
}
SalesAnalyticDto _$SalesAnalyticDtoFromJson(Map<String, dynamic> json) {
return _SalesAnalyticDto.fromJson(json);
}
/// @nodoc
mixin _$SalesAnalyticDto {
@JsonKey(name: "organization_id")
String? get organizationId => throw _privateConstructorUsedError;
@JsonKey(name: "outlet_id")
String? get outletId => throw _privateConstructorUsedError;
@JsonKey(name: "date_from")
DateTime? get dateFrom => throw _privateConstructorUsedError;
@JsonKey(name: "date_to")
DateTime? get dateTo => throw _privateConstructorUsedError;
@JsonKey(name: "group_by")
String? get groupBy => throw _privateConstructorUsedError;
@JsonKey(name: "summary")
SalesSummaryDto? get summary => throw _privateConstructorUsedError;
@JsonKey(name: "data")
List<SalesAnalyticItemDto>? get data => throw _privateConstructorUsedError;
/// Serializes this SalesAnalyticDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$SalesAnalyticDtoCopyWith<SalesAnalyticDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SalesAnalyticDtoCopyWith<$Res> {
factory $SalesAnalyticDtoCopyWith(
SalesAnalyticDto value,
$Res Function(SalesAnalyticDto) then,
) = _$SalesAnalyticDtoCopyWithImpl<$Res, SalesAnalyticDto>;
@useResult
$Res call({
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "date_from") DateTime? dateFrom,
@JsonKey(name: "date_to") DateTime? dateTo,
@JsonKey(name: "group_by") String? groupBy,
@JsonKey(name: "summary") SalesSummaryDto? summary,
@JsonKey(name: "data") List<SalesAnalyticItemDto>? data,
});
$SalesSummaryDtoCopyWith<$Res>? get summary;
}
/// @nodoc
class _$SalesAnalyticDtoCopyWithImpl<$Res, $Val extends SalesAnalyticDto>
implements $SalesAnalyticDtoCopyWith<$Res> {
_$SalesAnalyticDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? organizationId = freezed,
Object? outletId = freezed,
Object? dateFrom = freezed,
Object? dateTo = freezed,
Object? groupBy = freezed,
Object? summary = freezed,
Object? data = freezed,
}) {
return _then(
_value.copyWith(
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
outletId: freezed == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String?,
dateFrom: freezed == dateFrom
? _value.dateFrom
: dateFrom // ignore: cast_nullable_to_non_nullable
as DateTime?,
dateTo: freezed == dateTo
? _value.dateTo
: dateTo // ignore: cast_nullable_to_non_nullable
as DateTime?,
groupBy: freezed == groupBy
? _value.groupBy
: groupBy // ignore: cast_nullable_to_non_nullable
as String?,
summary: freezed == summary
? _value.summary
: summary // ignore: cast_nullable_to_non_nullable
as SalesSummaryDto?,
data: freezed == data
? _value.data
: data // ignore: cast_nullable_to_non_nullable
as List<SalesAnalyticItemDto>?,
)
as $Val,
);
}
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$SalesSummaryDtoCopyWith<$Res>? get summary {
if (_value.summary == null) {
return null;
}
return $SalesSummaryDtoCopyWith<$Res>(_value.summary!, (value) {
return _then(_value.copyWith(summary: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$SalesAnalyticDtoImplCopyWith<$Res>
implements $SalesAnalyticDtoCopyWith<$Res> {
factory _$$SalesAnalyticDtoImplCopyWith(
_$SalesAnalyticDtoImpl value,
$Res Function(_$SalesAnalyticDtoImpl) then,
) = __$$SalesAnalyticDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "date_from") DateTime? dateFrom,
@JsonKey(name: "date_to") DateTime? dateTo,
@JsonKey(name: "group_by") String? groupBy,
@JsonKey(name: "summary") SalesSummaryDto? summary,
@JsonKey(name: "data") List<SalesAnalyticItemDto>? data,
});
@override
$SalesSummaryDtoCopyWith<$Res>? get summary;
}
/// @nodoc
class __$$SalesAnalyticDtoImplCopyWithImpl<$Res>
extends _$SalesAnalyticDtoCopyWithImpl<$Res, _$SalesAnalyticDtoImpl>
implements _$$SalesAnalyticDtoImplCopyWith<$Res> {
__$$SalesAnalyticDtoImplCopyWithImpl(
_$SalesAnalyticDtoImpl _value,
$Res Function(_$SalesAnalyticDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? organizationId = freezed,
Object? outletId = freezed,
Object? dateFrom = freezed,
Object? dateTo = freezed,
Object? groupBy = freezed,
Object? summary = freezed,
Object? data = freezed,
}) {
return _then(
_$SalesAnalyticDtoImpl(
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
outletId: freezed == outletId
? _value.outletId
: outletId // ignore: cast_nullable_to_non_nullable
as String?,
dateFrom: freezed == dateFrom
? _value.dateFrom
: dateFrom // ignore: cast_nullable_to_non_nullable
as DateTime?,
dateTo: freezed == dateTo
? _value.dateTo
: dateTo // ignore: cast_nullable_to_non_nullable
as DateTime?,
groupBy: freezed == groupBy
? _value.groupBy
: groupBy // ignore: cast_nullable_to_non_nullable
as String?,
summary: freezed == summary
? _value.summary
: summary // ignore: cast_nullable_to_non_nullable
as SalesSummaryDto?,
data: freezed == data
? _value._data
: data // ignore: cast_nullable_to_non_nullable
as List<SalesAnalyticItemDto>?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$SalesAnalyticDtoImpl extends _SalesAnalyticDto {
const _$SalesAnalyticDtoImpl({
@JsonKey(name: "organization_id") this.organizationId,
@JsonKey(name: "outlet_id") this.outletId,
@JsonKey(name: "date_from") this.dateFrom,
@JsonKey(name: "date_to") this.dateTo,
@JsonKey(name: "group_by") this.groupBy,
@JsonKey(name: "summary") this.summary,
@JsonKey(name: "data") final List<SalesAnalyticItemDto>? data,
}) : _data = data,
super._();
factory _$SalesAnalyticDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$SalesAnalyticDtoImplFromJson(json);
@override
@JsonKey(name: "organization_id")
final String? organizationId;
@override
@JsonKey(name: "outlet_id")
final String? outletId;
@override
@JsonKey(name: "date_from")
final DateTime? dateFrom;
@override
@JsonKey(name: "date_to")
final DateTime? dateTo;
@override
@JsonKey(name: "group_by")
final String? groupBy;
@override
@JsonKey(name: "summary")
final SalesSummaryDto? summary;
final List<SalesAnalyticItemDto>? _data;
@override
@JsonKey(name: "data")
List<SalesAnalyticItemDto>? get data {
final value = _data;
if (value == null) return null;
if (_data is EqualUnmodifiableListView) return _data;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
String toString() {
return 'SalesAnalyticDto(organizationId: $organizationId, outletId: $outletId, dateFrom: $dateFrom, dateTo: $dateTo, groupBy: $groupBy, summary: $summary, data: $data)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SalesAnalyticDtoImpl &&
(identical(other.organizationId, organizationId) ||
other.organizationId == organizationId) &&
(identical(other.outletId, outletId) ||
other.outletId == outletId) &&
(identical(other.dateFrom, dateFrom) ||
other.dateFrom == dateFrom) &&
(identical(other.dateTo, dateTo) || other.dateTo == dateTo) &&
(identical(other.groupBy, groupBy) || other.groupBy == groupBy) &&
(identical(other.summary, summary) || other.summary == summary) &&
const DeepCollectionEquality().equals(other._data, _data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
organizationId,
outletId,
dateFrom,
dateTo,
groupBy,
summary,
const DeepCollectionEquality().hash(_data),
);
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SalesAnalyticDtoImplCopyWith<_$SalesAnalyticDtoImpl> get copyWith =>
__$$SalesAnalyticDtoImplCopyWithImpl<_$SalesAnalyticDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$SalesAnalyticDtoImplToJson(this);
}
}
abstract class _SalesAnalyticDto extends SalesAnalyticDto {
const factory _SalesAnalyticDto({
@JsonKey(name: "organization_id") final String? organizationId,
@JsonKey(name: "outlet_id") final String? outletId,
@JsonKey(name: "date_from") final DateTime? dateFrom,
@JsonKey(name: "date_to") final DateTime? dateTo,
@JsonKey(name: "group_by") final String? groupBy,
@JsonKey(name: "summary") final SalesSummaryDto? summary,
@JsonKey(name: "data") final List<SalesAnalyticItemDto>? data,
}) = _$SalesAnalyticDtoImpl;
const _SalesAnalyticDto._() : super._();
factory _SalesAnalyticDto.fromJson(Map<String, dynamic> json) =
_$SalesAnalyticDtoImpl.fromJson;
@override
@JsonKey(name: "organization_id")
String? get organizationId;
@override
@JsonKey(name: "outlet_id")
String? get outletId;
@override
@JsonKey(name: "date_from")
DateTime? get dateFrom;
@override
@JsonKey(name: "date_to")
DateTime? get dateTo;
@override
@JsonKey(name: "group_by")
String? get groupBy;
@override
@JsonKey(name: "summary")
SalesSummaryDto? get summary;
@override
@JsonKey(name: "data")
List<SalesAnalyticItemDto>? get data;
/// Create a copy of SalesAnalyticDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SalesAnalyticDtoImplCopyWith<_$SalesAnalyticDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
SalesSummaryDto _$SalesSummaryDtoFromJson(Map<String, dynamic> json) {
return _SalesSummaryDto.fromJson(json);
}
/// @nodoc
mixin _$SalesSummaryDto {
@JsonKey(name: "total_sales")
int? get totalSales => throw _privateConstructorUsedError;
@JsonKey(name: "total_orders")
int? get totalOrders => throw _privateConstructorUsedError;
@JsonKey(name: "total_items")
int? get totalItems => throw _privateConstructorUsedError;
@JsonKey(name: "average_order_value")
double? get averageOrderValue => throw _privateConstructorUsedError;
@JsonKey(name: "total_tax")
int? get totalTax => throw _privateConstructorUsedError;
@JsonKey(name: "total_discount")
int? get totalDiscount => throw _privateConstructorUsedError;
@JsonKey(name: "net_sales")
int? get netSales => throw _privateConstructorUsedError;
/// Serializes this SalesSummaryDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of SalesSummaryDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$SalesSummaryDtoCopyWith<SalesSummaryDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SalesSummaryDtoCopyWith<$Res> {
factory $SalesSummaryDtoCopyWith(
SalesSummaryDto value,
$Res Function(SalesSummaryDto) then,
) = _$SalesSummaryDtoCopyWithImpl<$Res, SalesSummaryDto>;
@useResult
$Res call({
@JsonKey(name: "total_sales") int? totalSales,
@JsonKey(name: "total_orders") int? totalOrders,
@JsonKey(name: "total_items") int? totalItems,
@JsonKey(name: "average_order_value") double? averageOrderValue,
@JsonKey(name: "total_tax") int? totalTax,
@JsonKey(name: "total_discount") int? totalDiscount,
@JsonKey(name: "net_sales") int? netSales,
});
}
/// @nodoc
class _$SalesSummaryDtoCopyWithImpl<$Res, $Val extends SalesSummaryDto>
implements $SalesSummaryDtoCopyWith<$Res> {
_$SalesSummaryDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SalesSummaryDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? totalSales = freezed,
Object? totalOrders = freezed,
Object? totalItems = freezed,
Object? averageOrderValue = freezed,
Object? totalTax = freezed,
Object? totalDiscount = freezed,
Object? netSales = freezed,
}) {
return _then(
_value.copyWith(
totalSales: freezed == totalSales
? _value.totalSales
: totalSales // ignore: cast_nullable_to_non_nullable
as int?,
totalOrders: freezed == totalOrders
? _value.totalOrders
: totalOrders // ignore: cast_nullable_to_non_nullable
as int?,
totalItems: freezed == totalItems
? _value.totalItems
: totalItems // ignore: cast_nullable_to_non_nullable
as int?,
averageOrderValue: freezed == averageOrderValue
? _value.averageOrderValue
: averageOrderValue // ignore: cast_nullable_to_non_nullable
as double?,
totalTax: freezed == totalTax
? _value.totalTax
: totalTax // ignore: cast_nullable_to_non_nullable
as int?,
totalDiscount: freezed == totalDiscount
? _value.totalDiscount
: totalDiscount // ignore: cast_nullable_to_non_nullable
as int?,
netSales: freezed == netSales
? _value.netSales
: netSales // ignore: cast_nullable_to_non_nullable
as int?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$SalesSummaryDtoImplCopyWith<$Res>
implements $SalesSummaryDtoCopyWith<$Res> {
factory _$$SalesSummaryDtoImplCopyWith(
_$SalesSummaryDtoImpl value,
$Res Function(_$SalesSummaryDtoImpl) then,
) = __$$SalesSummaryDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "total_sales") int? totalSales,
@JsonKey(name: "total_orders") int? totalOrders,
@JsonKey(name: "total_items") int? totalItems,
@JsonKey(name: "average_order_value") double? averageOrderValue,
@JsonKey(name: "total_tax") int? totalTax,
@JsonKey(name: "total_discount") int? totalDiscount,
@JsonKey(name: "net_sales") int? netSales,
});
}
/// @nodoc
class __$$SalesSummaryDtoImplCopyWithImpl<$Res>
extends _$SalesSummaryDtoCopyWithImpl<$Res, _$SalesSummaryDtoImpl>
implements _$$SalesSummaryDtoImplCopyWith<$Res> {
__$$SalesSummaryDtoImplCopyWithImpl(
_$SalesSummaryDtoImpl _value,
$Res Function(_$SalesSummaryDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of SalesSummaryDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? totalSales = freezed,
Object? totalOrders = freezed,
Object? totalItems = freezed,
Object? averageOrderValue = freezed,
Object? totalTax = freezed,
Object? totalDiscount = freezed,
Object? netSales = freezed,
}) {
return _then(
_$SalesSummaryDtoImpl(
totalSales: freezed == totalSales
? _value.totalSales
: totalSales // ignore: cast_nullable_to_non_nullable
as int?,
totalOrders: freezed == totalOrders
? _value.totalOrders
: totalOrders // ignore: cast_nullable_to_non_nullable
as int?,
totalItems: freezed == totalItems
? _value.totalItems
: totalItems // ignore: cast_nullable_to_non_nullable
as int?,
averageOrderValue: freezed == averageOrderValue
? _value.averageOrderValue
: averageOrderValue // ignore: cast_nullable_to_non_nullable
as double?,
totalTax: freezed == totalTax
? _value.totalTax
: totalTax // ignore: cast_nullable_to_non_nullable
as int?,
totalDiscount: freezed == totalDiscount
? _value.totalDiscount
: totalDiscount // ignore: cast_nullable_to_non_nullable
as int?,
netSales: freezed == netSales
? _value.netSales
: netSales // ignore: cast_nullable_to_non_nullable
as int?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$SalesSummaryDtoImpl extends _SalesSummaryDto {
const _$SalesSummaryDtoImpl({
@JsonKey(name: "total_sales") this.totalSales,
@JsonKey(name: "total_orders") this.totalOrders,
@JsonKey(name: "total_items") this.totalItems,
@JsonKey(name: "average_order_value") this.averageOrderValue,
@JsonKey(name: "total_tax") this.totalTax,
@JsonKey(name: "total_discount") this.totalDiscount,
@JsonKey(name: "net_sales") this.netSales,
}) : super._();
factory _$SalesSummaryDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$SalesSummaryDtoImplFromJson(json);
@override
@JsonKey(name: "total_sales")
final int? totalSales;
@override
@JsonKey(name: "total_orders")
final int? totalOrders;
@override
@JsonKey(name: "total_items")
final int? totalItems;
@override
@JsonKey(name: "average_order_value")
final double? averageOrderValue;
@override
@JsonKey(name: "total_tax")
final int? totalTax;
@override
@JsonKey(name: "total_discount")
final int? totalDiscount;
@override
@JsonKey(name: "net_sales")
final int? netSales;
@override
String toString() {
return 'SalesSummaryDto(totalSales: $totalSales, totalOrders: $totalOrders, totalItems: $totalItems, averageOrderValue: $averageOrderValue, totalTax: $totalTax, totalDiscount: $totalDiscount, netSales: $netSales)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SalesSummaryDtoImpl &&
(identical(other.totalSales, totalSales) ||
other.totalSales == totalSales) &&
(identical(other.totalOrders, totalOrders) ||
other.totalOrders == totalOrders) &&
(identical(other.totalItems, totalItems) ||
other.totalItems == totalItems) &&
(identical(other.averageOrderValue, averageOrderValue) ||
other.averageOrderValue == averageOrderValue) &&
(identical(other.totalTax, totalTax) ||
other.totalTax == totalTax) &&
(identical(other.totalDiscount, totalDiscount) ||
other.totalDiscount == totalDiscount) &&
(identical(other.netSales, netSales) ||
other.netSales == netSales));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
totalSales,
totalOrders,
totalItems,
averageOrderValue,
totalTax,
totalDiscount,
netSales,
);
/// Create a copy of SalesSummaryDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SalesSummaryDtoImplCopyWith<_$SalesSummaryDtoImpl> get copyWith =>
__$$SalesSummaryDtoImplCopyWithImpl<_$SalesSummaryDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$SalesSummaryDtoImplToJson(this);
}
}
abstract class _SalesSummaryDto extends SalesSummaryDto {
const factory _SalesSummaryDto({
@JsonKey(name: "total_sales") final int? totalSales,
@JsonKey(name: "total_orders") final int? totalOrders,
@JsonKey(name: "total_items") final int? totalItems,
@JsonKey(name: "average_order_value") final double? averageOrderValue,
@JsonKey(name: "total_tax") final int? totalTax,
@JsonKey(name: "total_discount") final int? totalDiscount,
@JsonKey(name: "net_sales") final int? netSales,
}) = _$SalesSummaryDtoImpl;
const _SalesSummaryDto._() : super._();
factory _SalesSummaryDto.fromJson(Map<String, dynamic> json) =
_$SalesSummaryDtoImpl.fromJson;
@override
@JsonKey(name: "total_sales")
int? get totalSales;
@override
@JsonKey(name: "total_orders")
int? get totalOrders;
@override
@JsonKey(name: "total_items")
int? get totalItems;
@override
@JsonKey(name: "average_order_value")
double? get averageOrderValue;
@override
@JsonKey(name: "total_tax")
int? get totalTax;
@override
@JsonKey(name: "total_discount")
int? get totalDiscount;
@override
@JsonKey(name: "net_sales")
int? get netSales;
/// Create a copy of SalesSummaryDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SalesSummaryDtoImplCopyWith<_$SalesSummaryDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
SalesAnalyticItemDto _$SalesAnalyticItemDtoFromJson(Map<String, dynamic> json) {
return _SalesAnalyticItemDto.fromJson(json);
}
/// @nodoc
mixin _$SalesAnalyticItemDto {
@JsonKey(name: "date")
DateTime? get date => throw _privateConstructorUsedError;
@JsonKey(name: "sales")
int? get sales => throw _privateConstructorUsedError;
@JsonKey(name: "orders")
int? get orders => throw _privateConstructorUsedError;
@JsonKey(name: "items")
int? get items => throw _privateConstructorUsedError;
@JsonKey(name: "tax")
int? get tax => throw _privateConstructorUsedError;
@JsonKey(name: "discount")
int? get discount => throw _privateConstructorUsedError;
@JsonKey(name: "net_sales")
int? get netSales => throw _privateConstructorUsedError;
/// Serializes this SalesAnalyticItemDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of SalesAnalyticItemDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$SalesAnalyticItemDtoCopyWith<SalesAnalyticItemDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SalesAnalyticItemDtoCopyWith<$Res> {
factory $SalesAnalyticItemDtoCopyWith(
SalesAnalyticItemDto value,
$Res Function(SalesAnalyticItemDto) then,
) = _$SalesAnalyticItemDtoCopyWithImpl<$Res, SalesAnalyticItemDto>;
@useResult
$Res call({
@JsonKey(name: "date") DateTime? date,
@JsonKey(name: "sales") int? sales,
@JsonKey(name: "orders") int? orders,
@JsonKey(name: "items") int? items,
@JsonKey(name: "tax") int? tax,
@JsonKey(name: "discount") int? discount,
@JsonKey(name: "net_sales") int? netSales,
});
}
/// @nodoc
class _$SalesAnalyticItemDtoCopyWithImpl<
$Res,
$Val extends SalesAnalyticItemDto
>
implements $SalesAnalyticItemDtoCopyWith<$Res> {
_$SalesAnalyticItemDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SalesAnalyticItemDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? date = freezed,
Object? sales = freezed,
Object? orders = freezed,
Object? items = freezed,
Object? tax = freezed,
Object? discount = freezed,
Object? netSales = freezed,
}) {
return _then(
_value.copyWith(
date: freezed == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as DateTime?,
sales: freezed == sales
? _value.sales
: sales // ignore: cast_nullable_to_non_nullable
as int?,
orders: freezed == orders
? _value.orders
: orders // ignore: cast_nullable_to_non_nullable
as int?,
items: freezed == items
? _value.items
: items // ignore: cast_nullable_to_non_nullable
as int?,
tax: freezed == tax
? _value.tax
: tax // ignore: cast_nullable_to_non_nullable
as int?,
discount: freezed == discount
? _value.discount
: discount // ignore: cast_nullable_to_non_nullable
as int?,
netSales: freezed == netSales
? _value.netSales
: netSales // ignore: cast_nullable_to_non_nullable
as int?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$SalesAnalyticItemDtoImplCopyWith<$Res>
implements $SalesAnalyticItemDtoCopyWith<$Res> {
factory _$$SalesAnalyticItemDtoImplCopyWith(
_$SalesAnalyticItemDtoImpl value,
$Res Function(_$SalesAnalyticItemDtoImpl) then,
) = __$$SalesAnalyticItemDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: "date") DateTime? date,
@JsonKey(name: "sales") int? sales,
@JsonKey(name: "orders") int? orders,
@JsonKey(name: "items") int? items,
@JsonKey(name: "tax") int? tax,
@JsonKey(name: "discount") int? discount,
@JsonKey(name: "net_sales") int? netSales,
});
}
/// @nodoc
class __$$SalesAnalyticItemDtoImplCopyWithImpl<$Res>
extends _$SalesAnalyticItemDtoCopyWithImpl<$Res, _$SalesAnalyticItemDtoImpl>
implements _$$SalesAnalyticItemDtoImplCopyWith<$Res> {
__$$SalesAnalyticItemDtoImplCopyWithImpl(
_$SalesAnalyticItemDtoImpl _value,
$Res Function(_$SalesAnalyticItemDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of SalesAnalyticItemDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? date = freezed,
Object? sales = freezed,
Object? orders = freezed,
Object? items = freezed,
Object? tax = freezed,
Object? discount = freezed,
Object? netSales = freezed,
}) {
return _then(
_$SalesAnalyticItemDtoImpl(
date: freezed == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as DateTime?,
sales: freezed == sales
? _value.sales
: sales // ignore: cast_nullable_to_non_nullable
as int?,
orders: freezed == orders
? _value.orders
: orders // ignore: cast_nullable_to_non_nullable
as int?,
items: freezed == items
? _value.items
: items // ignore: cast_nullable_to_non_nullable
as int?,
tax: freezed == tax
? _value.tax
: tax // ignore: cast_nullable_to_non_nullable
as int?,
discount: freezed == discount
? _value.discount
: discount // ignore: cast_nullable_to_non_nullable
as int?,
netSales: freezed == netSales
? _value.netSales
: netSales // ignore: cast_nullable_to_non_nullable
as int?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$SalesAnalyticItemDtoImpl extends _SalesAnalyticItemDto {
const _$SalesAnalyticItemDtoImpl({
@JsonKey(name: "date") this.date,
@JsonKey(name: "sales") this.sales,
@JsonKey(name: "orders") this.orders,
@JsonKey(name: "items") this.items,
@JsonKey(name: "tax") this.tax,
@JsonKey(name: "discount") this.discount,
@JsonKey(name: "net_sales") this.netSales,
}) : super._();
factory _$SalesAnalyticItemDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$SalesAnalyticItemDtoImplFromJson(json);
@override
@JsonKey(name: "date")
final DateTime? date;
@override
@JsonKey(name: "sales")
final int? sales;
@override
@JsonKey(name: "orders")
final int? orders;
@override
@JsonKey(name: "items")
final int? items;
@override
@JsonKey(name: "tax")
final int? tax;
@override
@JsonKey(name: "discount")
final int? discount;
@override
@JsonKey(name: "net_sales")
final int? netSales;
@override
String toString() {
return 'SalesAnalyticItemDto(date: $date, sales: $sales, orders: $orders, items: $items, tax: $tax, discount: $discount, netSales: $netSales)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SalesAnalyticItemDtoImpl &&
(identical(other.date, date) || other.date == date) &&
(identical(other.sales, sales) || other.sales == sales) &&
(identical(other.orders, orders) || other.orders == orders) &&
(identical(other.items, items) || other.items == items) &&
(identical(other.tax, tax) || other.tax == tax) &&
(identical(other.discount, discount) ||
other.discount == discount) &&
(identical(other.netSales, netSales) ||
other.netSales == netSales));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
date,
sales,
orders,
items,
tax,
discount,
netSales,
);
/// Create a copy of SalesAnalyticItemDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SalesAnalyticItemDtoImplCopyWith<_$SalesAnalyticItemDtoImpl>
get copyWith =>
__$$SalesAnalyticItemDtoImplCopyWithImpl<_$SalesAnalyticItemDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$SalesAnalyticItemDtoImplToJson(this);
}
}
abstract class _SalesAnalyticItemDto extends SalesAnalyticItemDto {
const factory _SalesAnalyticItemDto({
@JsonKey(name: "date") final DateTime? date,
@JsonKey(name: "sales") final int? sales,
@JsonKey(name: "orders") final int? orders,
@JsonKey(name: "items") final int? items,
@JsonKey(name: "tax") final int? tax,
@JsonKey(name: "discount") final int? discount,
@JsonKey(name: "net_sales") final int? netSales,
}) = _$SalesAnalyticItemDtoImpl;
const _SalesAnalyticItemDto._() : super._();
factory _SalesAnalyticItemDto.fromJson(Map<String, dynamic> json) =
_$SalesAnalyticItemDtoImpl.fromJson;
@override
@JsonKey(name: "date")
DateTime? get date;
@override
@JsonKey(name: "sales")
int? get sales;
@override
@JsonKey(name: "orders")
int? get orders;
@override
@JsonKey(name: "items")
int? get items;
@override
@JsonKey(name: "tax")
int? get tax;
@override
@JsonKey(name: "discount")
int? get discount;
@override
@JsonKey(name: "net_sales")
int? get netSales;
/// Create a copy of SalesAnalyticItemDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SalesAnalyticItemDtoImplCopyWith<_$SalesAnalyticItemDtoImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -137,3 +137,83 @@ Map<String, dynamic> _$$DashboardRecentSaleDtoImplToJson(
'discount': instance.discount,
'net_sales': instance.netSales,
};
_$SalesAnalyticDtoImpl _$$SalesAnalyticDtoImplFromJson(
Map<String, dynamic> json,
) => _$SalesAnalyticDtoImpl(
organizationId: json['organization_id'] as String?,
outletId: json['outlet_id'] as String?,
dateFrom: json['date_from'] == null
? null
: DateTime.parse(json['date_from'] as String),
dateTo: json['date_to'] == null
? null
: DateTime.parse(json['date_to'] as String),
groupBy: json['group_by'] as String?,
summary: json['summary'] == null
? null
: SalesSummaryDto.fromJson(json['summary'] as Map<String, dynamic>),
data: (json['data'] as List<dynamic>?)
?.map((e) => SalesAnalyticItemDto.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$$SalesAnalyticDtoImplToJson(
_$SalesAnalyticDtoImpl instance,
) => <String, dynamic>{
'organization_id': instance.organizationId,
'outlet_id': instance.outletId,
'date_from': instance.dateFrom?.toIso8601String(),
'date_to': instance.dateTo?.toIso8601String(),
'group_by': instance.groupBy,
'summary': instance.summary,
'data': instance.data,
};
_$SalesSummaryDtoImpl _$$SalesSummaryDtoImplFromJson(
Map<String, dynamic> json,
) => _$SalesSummaryDtoImpl(
totalSales: (json['total_sales'] as num?)?.toInt(),
totalOrders: (json['total_orders'] as num?)?.toInt(),
totalItems: (json['total_items'] as num?)?.toInt(),
averageOrderValue: (json['average_order_value'] as num?)?.toDouble(),
totalTax: (json['total_tax'] as num?)?.toInt(),
totalDiscount: (json['total_discount'] as num?)?.toInt(),
netSales: (json['net_sales'] as num?)?.toInt(),
);
Map<String, dynamic> _$$SalesSummaryDtoImplToJson(
_$SalesSummaryDtoImpl instance,
) => <String, dynamic>{
'total_sales': instance.totalSales,
'total_orders': instance.totalOrders,
'total_items': instance.totalItems,
'average_order_value': instance.averageOrderValue,
'total_tax': instance.totalTax,
'total_discount': instance.totalDiscount,
'net_sales': instance.netSales,
};
_$SalesAnalyticItemDtoImpl _$$SalesAnalyticItemDtoImplFromJson(
Map<String, dynamic> json,
) => _$SalesAnalyticItemDtoImpl(
date: json['date'] == null ? null : DateTime.parse(json['date'] as String),
sales: (json['sales'] as num?)?.toInt(),
orders: (json['orders'] as num?)?.toInt(),
items: (json['items'] as num?)?.toInt(),
tax: (json['tax'] as num?)?.toInt(),
discount: (json['discount'] as num?)?.toInt(),
netSales: (json['net_sales'] as num?)?.toInt(),
);
Map<String, dynamic> _$$SalesAnalyticItemDtoImplToJson(
_$SalesAnalyticItemDtoImpl instance,
) => <String, dynamic>{
'date': instance.date?.toIso8601String(),
'sales': instance.sales,
'orders': instance.orders,
'items': instance.items,
'tax': instance.tax,
'discount': instance.discount,
'net_sales': instance.netSales,
};
@@ -47,4 +47,33 @@ class AnalyticRemoteDataProvider {
return DC.error(AnalyticFailure.serverError(e));
}
}
Future<DC<AnalyticFailure, SalesAnalyticDto>> fetchSales({
required DateTime dateFrom,
required DateTime dateTo,
}) async {
try {
final response = await _apiClient.get(
ApiPath.analyticSales,
params: {
'date_from': dateFrom.toServerDate(),
'date_to': dateTo.toServerDate(),
},
headers: getAuthorizationHeader(),
);
if (response.data['success'] == false) {
return DC.error(AnalyticFailure.unexpectedError());
}
final sales = SalesAnalyticDto.fromJson(
response.data['data'] as Map<String, dynamic>,
);
return DC.data(sales);
} on ApiFailure catch (e, s) {
log('fetchSales', name: _logName, error: e, stackTrace: s);
return DC.error(AnalyticFailure.serverError(e));
}
}
}
@@ -0,0 +1,88 @@
part of '../analytic_dtos.dart';
@freezed
class SalesAnalyticDto with _$SalesAnalyticDto {
const SalesAnalyticDto._();
const factory SalesAnalyticDto({
@JsonKey(name: "organization_id") String? organizationId,
@JsonKey(name: "outlet_id") String? outletId,
@JsonKey(name: "date_from") DateTime? dateFrom,
@JsonKey(name: "date_to") DateTime? dateTo,
@JsonKey(name: "group_by") String? groupBy,
@JsonKey(name: "summary") SalesSummaryDto? summary,
@JsonKey(name: "data") List<SalesAnalyticItemDto>? data,
}) = _SalesAnalyticDto;
factory SalesAnalyticDto.fromJson(Map<String, dynamic> json) =>
_$SalesAnalyticDtoFromJson(json);
// Optional mapping ke domain
SalesAnalytic toDomain() => SalesAnalytic(
organizationId: organizationId ?? '',
outletId: outletId ?? '',
dateFrom: dateFrom ?? DateTime.now(),
dateTo: dateTo ?? DateTime.now(),
groupBy: groupBy ?? '',
summary: summary?.toDomain() ?? SalesSummary.empty(),
data: data?.map((e) => e.toDomain()).toList() ?? [],
);
}
@freezed
class SalesSummaryDto with _$SalesSummaryDto {
const SalesSummaryDto._();
const factory SalesSummaryDto({
@JsonKey(name: "total_sales") int? totalSales,
@JsonKey(name: "total_orders") int? totalOrders,
@JsonKey(name: "total_items") int? totalItems,
@JsonKey(name: "average_order_value") double? averageOrderValue,
@JsonKey(name: "total_tax") int? totalTax,
@JsonKey(name: "total_discount") int? totalDiscount,
@JsonKey(name: "net_sales") int? netSales,
}) = _SalesSummaryDto;
factory SalesSummaryDto.fromJson(Map<String, dynamic> json) =>
_$SalesSummaryDtoFromJson(json);
// Optional mapping ke domain
SalesSummary toDomain() => SalesSummary(
totalSales: totalSales ?? 0,
totalOrders: totalOrders ?? 0,
totalItems: totalItems ?? 0,
averageOrderValue: averageOrderValue ?? 0.0,
totalTax: totalTax ?? 0,
totalDiscount: totalDiscount ?? 0,
netSales: netSales ?? 0,
);
}
@freezed
class SalesAnalyticItemDto with _$SalesAnalyticItemDto {
const SalesAnalyticItemDto._();
const factory SalesAnalyticItemDto({
@JsonKey(name: "date") DateTime? date,
@JsonKey(name: "sales") int? sales,
@JsonKey(name: "orders") int? orders,
@JsonKey(name: "items") int? items,
@JsonKey(name: "tax") int? tax,
@JsonKey(name: "discount") int? discount,
@JsonKey(name: "net_sales") int? netSales,
}) = _SalesAnalyticItemDto;
factory SalesAnalyticItemDto.fromJson(Map<String, dynamic> json) =>
_$SalesAnalyticItemDtoFromJson(json);
// Optional mapping ke domain
SalesAnalyticItem toDomain() => SalesAnalyticItem(
date: date ?? DateTime.now(),
sales: sales ?? 0,
orders: orders ?? 0,
items: items ?? 0,
tax: tax ?? 0,
discount: discount ?? 0,
netSales: netSales ?? 0,
);
}
@@ -37,4 +37,28 @@ class AnalyticRepository implements IAnalyticRepository {
return left(const AnalyticFailure.unexpectedError());
}
}
@override
Future<Either<AnalyticFailure, SalesAnalytic>> getSales({
required DateTime dateFrom,
required DateTime dateTo,
}) async {
try {
final result = await _dataProvider.fetchSales(
dateFrom: dateFrom,
dateTo: dateTo,
);
if (result.hasError) {
return left(result.error!);
}
final sales = result.data!.toDomain();
return right(sales);
} catch (e) {
log('getSalesError', name: _logName, error: e);
return left(const AnalyticFailure.unexpectedError());
}
}
}