feat: order item
This commit is contained in:
parent
b82bb84152
commit
092e68615c
@ -15,6 +15,7 @@ import 'package:enaklo_pos/data/models/response/summary_response_model.dart';
|
|||||||
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
|
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
|
||||||
import 'package:enaklo_pos/presentation/home/models/order_request.dart';
|
import 'package:enaklo_pos/presentation/home/models/order_request.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class OrderRemoteDatasource {
|
class OrderRemoteDatasource {
|
||||||
final Dio dio = DioClient.instance;
|
final Dio dio = DioClient.instance;
|
||||||
@ -263,10 +264,13 @@ class OrderRemoteDatasource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<String, OrderResponseModel>> getOrder(
|
Future<Either<String, OrderResponseModel>> getOrder({
|
||||||
{int page = 1,
|
int page = 1,
|
||||||
int limit = Variables.defaultLimit,
|
int limit = Variables.defaultLimit,
|
||||||
String status = 'completed'}) async {
|
String status = 'completed',
|
||||||
|
required DateTime dateFrom,
|
||||||
|
required DateTime dateTo,
|
||||||
|
}) async {
|
||||||
try {
|
try {
|
||||||
final authData = await AuthLocalDataSource().getAuthData();
|
final authData = await AuthLocalDataSource().getAuthData();
|
||||||
final response = await dio.get(
|
final response = await dio.get(
|
||||||
@ -275,8 +279,8 @@ class OrderRemoteDatasource {
|
|||||||
'page': page,
|
'page': page,
|
||||||
'limit': limit,
|
'limit': limit,
|
||||||
'status': status,
|
'status': status,
|
||||||
'date_from': "05-08-2025",
|
'date_from': DateFormat('dd-MM-yyyy').format(dateFrom),
|
||||||
'date_to': "05-08-2025",
|
'date_to': DateFormat('dd-MM-yyyy').format(dateTo),
|
||||||
},
|
},
|
||||||
options: Options(
|
options: Options(
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -26,9 +26,13 @@ class _PaymentAddOrderDialogState extends State<PaymentAddOrderDialog> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
context
|
context.read<OrderLoaderBloc>().add(
|
||||||
.read<OrderLoaderBloc>()
|
OrderLoaderEvent.getByStatus(
|
||||||
.add(OrderLoaderEvent.getByStatus('pending'));
|
'pending',
|
||||||
|
dateFrom: DateTime.now(),
|
||||||
|
dateTo: DateTime.now(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -14,7 +14,11 @@ class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
|
|||||||
on<_GetByStatus>((event, emit) async {
|
on<_GetByStatus>((event, emit) async {
|
||||||
emit(const _Loading());
|
emit(const _Loading());
|
||||||
final result = await _orderRemoteDatasource.getOrder(
|
final result = await _orderRemoteDatasource.getOrder(
|
||||||
status: event.status, limit: 20);
|
status: event.status,
|
||||||
|
limit: 20,
|
||||||
|
dateFrom: event.dateFrom,
|
||||||
|
dateTo: event.dateTo,
|
||||||
|
);
|
||||||
result.fold(
|
result.fold(
|
||||||
(l) => emit(_Error(l)),
|
(l) => emit(_Error(l)),
|
||||||
(r) => emit(_Loaded(
|
(r) => emit(_Loaded(
|
||||||
|
|||||||
@ -18,19 +18,22 @@ final _privateConstructorUsedError = UnsupportedError(
|
|||||||
mixin _$OrderLoaderEvent {
|
mixin _$OrderLoaderEvent {
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>({
|
TResult when<TResult extends Object?>({
|
||||||
required TResult Function(String status) getByStatus,
|
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
|
||||||
|
getByStatus,
|
||||||
required TResult Function(String id) getById,
|
required TResult Function(String id) getById,
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
TResult? Function(String status)? getByStatus,
|
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult? Function(String id)? getById,
|
TResult? Function(String id)? getById,
|
||||||
}) =>
|
}) =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
TResult Function(String status)? getByStatus,
|
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult Function(String id)? getById,
|
TResult Function(String id)? getById,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) =>
|
}) =>
|
||||||
@ -83,7 +86,7 @@ abstract class _$$GetByStatusImplCopyWith<$Res> {
|
|||||||
_$GetByStatusImpl value, $Res Function(_$GetByStatusImpl) then) =
|
_$GetByStatusImpl value, $Res Function(_$GetByStatusImpl) then) =
|
||||||
__$$GetByStatusImplCopyWithImpl<$Res>;
|
__$$GetByStatusImplCopyWithImpl<$Res>;
|
||||||
@useResult
|
@useResult
|
||||||
$Res call({String status});
|
$Res call({String status, DateTime dateFrom, DateTime dateTo});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -100,12 +103,22 @@ class __$$GetByStatusImplCopyWithImpl<$Res>
|
|||||||
@override
|
@override
|
||||||
$Res call({
|
$Res call({
|
||||||
Object? status = null,
|
Object? status = null,
|
||||||
|
Object? dateFrom = null,
|
||||||
|
Object? dateTo = null,
|
||||||
}) {
|
}) {
|
||||||
return _then(_$GetByStatusImpl(
|
return _then(_$GetByStatusImpl(
|
||||||
null == status
|
null == status
|
||||||
? _value.status
|
? _value.status
|
||||||
: status // ignore: cast_nullable_to_non_nullable
|
: status // ignore: cast_nullable_to_non_nullable
|
||||||
as String,
|
as String,
|
||||||
|
dateFrom: null == dateFrom
|
||||||
|
? _value.dateFrom
|
||||||
|
: dateFrom // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime,
|
||||||
|
dateTo: null == dateTo
|
||||||
|
? _value.dateTo
|
||||||
|
: dateTo // ignore: cast_nullable_to_non_nullable
|
||||||
|
as DateTime,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,14 +126,19 @@ class __$$GetByStatusImplCopyWithImpl<$Res>
|
|||||||
/// @nodoc
|
/// @nodoc
|
||||||
|
|
||||||
class _$GetByStatusImpl implements _GetByStatus {
|
class _$GetByStatusImpl implements _GetByStatus {
|
||||||
const _$GetByStatusImpl(this.status);
|
const _$GetByStatusImpl(this.status,
|
||||||
|
{required this.dateFrom, required this.dateTo});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String status;
|
final String status;
|
||||||
|
@override
|
||||||
|
final DateTime dateFrom;
|
||||||
|
@override
|
||||||
|
final DateTime dateTo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'OrderLoaderEvent.getByStatus(status: $status)';
|
return 'OrderLoaderEvent.getByStatus(status: $status, dateFrom: $dateFrom, dateTo: $dateTo)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -128,11 +146,14 @@ class _$GetByStatusImpl implements _GetByStatus {
|
|||||||
return identical(this, other) ||
|
return identical(this, other) ||
|
||||||
(other.runtimeType == runtimeType &&
|
(other.runtimeType == runtimeType &&
|
||||||
other is _$GetByStatusImpl &&
|
other is _$GetByStatusImpl &&
|
||||||
(identical(other.status, status) || other.status == status));
|
(identical(other.status, status) || other.status == status) &&
|
||||||
|
(identical(other.dateFrom, dateFrom) ||
|
||||||
|
other.dateFrom == dateFrom) &&
|
||||||
|
(identical(other.dateTo, dateTo) || other.dateTo == dateTo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => Object.hash(runtimeType, status);
|
int get hashCode => Object.hash(runtimeType, status, dateFrom, dateTo);
|
||||||
|
|
||||||
/// Create a copy of OrderLoaderEvent
|
/// Create a copy of OrderLoaderEvent
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@ -145,30 +166,33 @@ class _$GetByStatusImpl implements _GetByStatus {
|
|||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>({
|
TResult when<TResult extends Object?>({
|
||||||
required TResult Function(String status) getByStatus,
|
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
|
||||||
|
getByStatus,
|
||||||
required TResult Function(String id) getById,
|
required TResult Function(String id) getById,
|
||||||
}) {
|
}) {
|
||||||
return getByStatus(status);
|
return getByStatus(status, dateFrom, dateTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
TResult? Function(String status)? getByStatus,
|
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult? Function(String id)? getById,
|
TResult? Function(String id)? getById,
|
||||||
}) {
|
}) {
|
||||||
return getByStatus?.call(status);
|
return getByStatus?.call(status, dateFrom, dateTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
TResult Function(String status)? getByStatus,
|
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult Function(String id)? getById,
|
TResult Function(String id)? getById,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) {
|
}) {
|
||||||
if (getByStatus != null) {
|
if (getByStatus != null) {
|
||||||
return getByStatus(status);
|
return getByStatus(status, dateFrom, dateTo);
|
||||||
}
|
}
|
||||||
return orElse();
|
return orElse();
|
||||||
}
|
}
|
||||||
@ -206,9 +230,13 @@ class _$GetByStatusImpl implements _GetByStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class _GetByStatus implements OrderLoaderEvent {
|
abstract class _GetByStatus implements OrderLoaderEvent {
|
||||||
const factory _GetByStatus(final String status) = _$GetByStatusImpl;
|
const factory _GetByStatus(final String status,
|
||||||
|
{required final DateTime dateFrom,
|
||||||
|
required final DateTime dateTo}) = _$GetByStatusImpl;
|
||||||
|
|
||||||
String get status;
|
String get status;
|
||||||
|
DateTime get dateFrom;
|
||||||
|
DateTime get dateTo;
|
||||||
|
|
||||||
/// Create a copy of OrderLoaderEvent
|
/// Create a copy of OrderLoaderEvent
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@ -285,7 +313,8 @@ class _$GetByIdImpl implements _GetById {
|
|||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult when<TResult extends Object?>({
|
TResult when<TResult extends Object?>({
|
||||||
required TResult Function(String status) getByStatus,
|
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
|
||||||
|
getByStatus,
|
||||||
required TResult Function(String id) getById,
|
required TResult Function(String id) getById,
|
||||||
}) {
|
}) {
|
||||||
return getById(id);
|
return getById(id);
|
||||||
@ -294,7 +323,8 @@ class _$GetByIdImpl implements _GetById {
|
|||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
TResult? whenOrNull<TResult extends Object?>({
|
||||||
TResult? Function(String status)? getByStatus,
|
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult? Function(String id)? getById,
|
TResult? Function(String id)? getById,
|
||||||
}) {
|
}) {
|
||||||
return getById?.call(id);
|
return getById?.call(id);
|
||||||
@ -303,7 +333,8 @@ class _$GetByIdImpl implements _GetById {
|
|||||||
@override
|
@override
|
||||||
@optionalTypeArgs
|
@optionalTypeArgs
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
TResult maybeWhen<TResult extends Object?>({
|
||||||
TResult Function(String status)? getByStatus,
|
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
|
||||||
|
getByStatus,
|
||||||
TResult Function(String id)? getById,
|
TResult Function(String id)? getById,
|
||||||
required TResult orElse(),
|
required TResult orElse(),
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@ -2,6 +2,10 @@ part of 'order_loader_bloc.dart';
|
|||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class OrderLoaderEvent with _$OrderLoaderEvent {
|
class OrderLoaderEvent with _$OrderLoaderEvent {
|
||||||
const factory OrderLoaderEvent.getByStatus(String status) = _GetByStatus;
|
const factory OrderLoaderEvent.getByStatus(
|
||||||
|
String status, {
|
||||||
|
required DateTime dateFrom,
|
||||||
|
required DateTime dateTo,
|
||||||
|
}) = _GetByStatus;
|
||||||
const factory OrderLoaderEvent.getById(String id) = _GetById;
|
const factory OrderLoaderEvent.getById(String id) = _GetById;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,9 +125,13 @@ class _RefundDialogState extends State<RefundDialog> {
|
|||||||
successMsg: () {
|
successMsg: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
AppFlushbar.showSuccess(context, 'Refund Berhasil!');
|
AppFlushbar.showSuccess(context, 'Refund Berhasil!');
|
||||||
context
|
context.read<OrderLoaderBloc>().add(
|
||||||
.read<OrderLoaderBloc>()
|
OrderLoaderEvent.getByStatus(
|
||||||
.add(OrderLoaderEvent.getByStatus('completed'));
|
'completed',
|
||||||
|
dateFrom: DateTime.now(),
|
||||||
|
dateTo: DateTime.now(),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
error: (msg) {
|
error: (msg) {
|
||||||
AppFlushbar.showError(context, msg);
|
AppFlushbar.showError(context, msg);
|
||||||
|
|||||||
@ -125,9 +125,13 @@ class _VoidDialogState extends State<VoidDialog> {
|
|||||||
successMsg: () {
|
successMsg: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
AppFlushbar.showSuccess(context, 'Void berhasil!');
|
AppFlushbar.showSuccess(context, 'Void berhasil!');
|
||||||
context
|
context.read<OrderLoaderBloc>().add(
|
||||||
.read<OrderLoaderBloc>()
|
OrderLoaderEvent.getByStatus(
|
||||||
.add(OrderLoaderEvent.getByStatus('pending'));
|
'pending',
|
||||||
|
dateFrom: DateTime.now(),
|
||||||
|
dateTo: DateTime.now(),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
error: (msg) {
|
error: (msg) {
|
||||||
AppFlushbar.showError(context, msg);
|
AppFlushbar.showError(context, msg);
|
||||||
|
|||||||
@ -37,9 +37,10 @@ class _SalesPageState extends State<SalesPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
context
|
context.read<OrderLoaderBloc>().add(OrderLoaderEvent.getByStatus(
|
||||||
.read<OrderLoaderBloc>()
|
widget.status,
|
||||||
.add(OrderLoaderEvent.getByStatus(widget.status));
|
dateFrom: startDate,
|
||||||
|
dateTo: endDate));
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +86,9 @@ class _SalesPageState extends State<SalesPage> {
|
|||||||
endDate = end;
|
endDate = end;
|
||||||
});
|
});
|
||||||
|
|
||||||
context.read<DaySalesBloc>().add(
|
context.read<OrderLoaderBloc>().add(
|
||||||
DaySalesEvent.getRangeDateSales(
|
OrderLoaderEvent.getByStatus(widget.status,
|
||||||
startDate, endDate));
|
dateFrom: startDate, dateTo: endDate));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user