report profit loss

This commit is contained in:
efrilm
2025-11-03 21:28:36 +07:00
parent 5a7892aa99
commit 07932d688f
23 changed files with 5188 additions and 1 deletions
@@ -0,0 +1,52 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'profit_loss_analytic_loader_event.dart';
part 'profit_loss_analytic_loader_state.dart';
part 'profit_loss_analytic_loader_bloc.freezed.dart';
@injectable
class ProfitLossAnalyticLoaderBloc
extends Bloc<ProfitLossAnalyticLoaderEvent, ProfitLossAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
ProfitLossAnalyticLoaderBloc(this._analyticRepository)
: super(ProfitLossAnalyticLoaderState.initial()) {
on<ProfitLossAnalyticLoaderEvent>(_onProfitLossAnalyticLoaderEvent);
}
Future<void> _onProfitLossAnalyticLoaderEvent(
ProfitLossAnalyticLoaderEvent event,
Emitter<ProfitLossAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getProfitLoss(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(profitLoss) async {
emit(
state.copyWith(isFetching: false, profitLossAnalytic: profitLoss),
);
},
);
},
);
}
}
@@ -0,0 +1,483 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'profit_loss_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$ProfitLossAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProfitLossAnalyticLoaderEventCopyWith<ProfitLossAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
factory $ProfitLossAnalyticLoaderEventCopyWith(
ProfitLossAnalyticLoaderEvent value,
$Res Function(ProfitLossAnalyticLoaderEvent) then,
) =
_$ProfitLossAnalyticLoaderEventCopyWithImpl<
$Res,
ProfitLossAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$ProfitLossAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends ProfitLossAnalyticLoaderEvent
>
implements $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
_$ProfitLossAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$ProfitLossAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'ProfitLossAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements ProfitLossAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProfitLossAnalyticLoaderState {
ProfitLossAnalytic get profitLossAnalytic =>
throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProfitLossAnalyticLoaderStateCopyWith<ProfitLossAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
factory $ProfitLossAnalyticLoaderStateCopyWith(
ProfitLossAnalyticLoaderState value,
$Res Function(ProfitLossAnalyticLoaderState) then,
) =
_$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
ProfitLossAnalyticLoaderState
>;
@useResult
$Res call({
ProfitLossAnalytic profitLossAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic;
}
/// @nodoc
class _$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends ProfitLossAnalyticLoaderState
>
implements $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
_$ProfitLossAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? profitLossAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
profitLossAnalytic: null == profitLossAnalytic
? _value.profitLossAnalytic
: profitLossAnalytic // ignore: cast_nullable_to_non_nullable
as ProfitLossAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic {
return $ProfitLossAnalyticCopyWith<$Res>(_value.profitLossAnalytic, (
value,
) {
return _then(_value.copyWith(profitLossAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ProfitLossAnalyticLoaderStateImplCopyWith<$Res>
implements $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
factory _$$ProfitLossAnalyticLoaderStateImplCopyWith(
_$ProfitLossAnalyticLoaderStateImpl value,
$Res Function(_$ProfitLossAnalyticLoaderStateImpl) then,
) = __$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
ProfitLossAnalytic profitLossAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic;
}
/// @nodoc
class __$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
_$ProfitLossAnalyticLoaderStateImpl
>
implements _$$ProfitLossAnalyticLoaderStateImplCopyWith<$Res> {
__$$ProfitLossAnalyticLoaderStateImplCopyWithImpl(
_$ProfitLossAnalyticLoaderStateImpl _value,
$Res Function(_$ProfitLossAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? profitLossAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$ProfitLossAnalyticLoaderStateImpl(
profitLossAnalytic: null == profitLossAnalytic
? _value.profitLossAnalytic
: profitLossAnalytic // ignore: cast_nullable_to_non_nullable
as ProfitLossAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$ProfitLossAnalyticLoaderStateImpl
implements _ProfitLossAnalyticLoaderState {
_$ProfitLossAnalyticLoaderStateImpl({
required this.profitLossAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final ProfitLossAnalytic profitLossAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'ProfitLossAnalyticLoaderState(profitLossAnalytic: $profitLossAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProfitLossAnalyticLoaderStateImpl &&
(identical(other.profitLossAnalytic, profitLossAnalytic) ||
other.profitLossAnalytic == profitLossAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, profitLossAnalytic, failureOption, isFetching);
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProfitLossAnalyticLoaderStateImplCopyWith<
_$ProfitLossAnalyticLoaderStateImpl
>
get copyWith =>
__$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<
_$ProfitLossAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _ProfitLossAnalyticLoaderState
implements ProfitLossAnalyticLoaderState {
factory _ProfitLossAnalyticLoaderState({
required final ProfitLossAnalytic profitLossAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$ProfitLossAnalyticLoaderStateImpl;
@override
ProfitLossAnalytic get profitLossAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProfitLossAnalyticLoaderStateImplCopyWith<
_$ProfitLossAnalyticLoaderStateImpl
>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'profit_loss_analytic_loader_bloc.dart';
@freezed
class ProfitLossAnalyticLoaderEvent with _$ProfitLossAnalyticLoaderEvent {
const factory ProfitLossAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,16 @@
part of 'profit_loss_analytic_loader_bloc.dart';
@freezed
class ProfitLossAnalyticLoaderState with _$ProfitLossAnalyticLoaderState {
factory ProfitLossAnalyticLoaderState({
required ProfitLossAnalytic profitLossAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _ProfitLossAnalyticLoaderState;
factory ProfitLossAnalyticLoaderState.initial() =>
ProfitLossAnalyticLoaderState(
profitLossAnalytic: ProfitLossAnalytic.empty(),
failureOption: none(),
);
}