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