print bill
This commit is contained in:
parent
0886e8c912
commit
d78b6165c2
@ -39,12 +39,12 @@ class PrintStruckBloc extends Bloc<PrintStruckEvent, PrintStruckState> {
|
||||
),
|
||||
);
|
||||
},
|
||||
saveOrder: (e) async {
|
||||
receipt: (e) async {
|
||||
Either<PrinterFailure, Unit> failureOrSuccess;
|
||||
|
||||
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
|
||||
|
||||
failureOrSuccess = await _printerRepository.printStruckSaveOrder(
|
||||
failureOrSuccess = await _printerRepository.printStruckReceipt(
|
||||
order: e.order,
|
||||
);
|
||||
|
||||
|
||||
@ -21,33 +21,33 @@ mixin _$PrintStruckEvent {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(Order order) order,
|
||||
required TResult Function(Order order) saveOrder,
|
||||
required TResult Function(Order order) receipt,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(Order order)? order,
|
||||
TResult? Function(Order order)? saveOrder,
|
||||
TResult? Function(Order order)? receipt,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(Order order)? order,
|
||||
TResult Function(Order order)? saveOrder,
|
||||
TResult Function(Order order)? receipt,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Order value) order,
|
||||
required TResult Function(_SaveOrder value) saveOrder,
|
||||
required TResult Function(_Receipt value) receipt,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Order value)? order,
|
||||
TResult? Function(_SaveOrder value)? saveOrder,
|
||||
TResult? Function(_Receipt value)? receipt,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Order value)? order,
|
||||
TResult Function(_SaveOrder value)? saveOrder,
|
||||
TResult Function(_Receipt value)? receipt,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
|
||||
@ -183,7 +183,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(Order order) order,
|
||||
required TResult Function(Order order) saveOrder,
|
||||
required TResult Function(Order order) receipt,
|
||||
}) {
|
||||
return order(this.order);
|
||||
}
|
||||
@ -192,7 +192,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(Order order)? order,
|
||||
TResult? Function(Order order)? saveOrder,
|
||||
TResult? Function(Order order)? receipt,
|
||||
}) {
|
||||
return order?.call(this.order);
|
||||
}
|
||||
@ -201,7 +201,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(Order order)? order,
|
||||
TResult Function(Order order)? saveOrder,
|
||||
TResult Function(Order order)? receipt,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (order != null) {
|
||||
@ -214,7 +214,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Order value) order,
|
||||
required TResult Function(_SaveOrder value) saveOrder,
|
||||
required TResult Function(_Receipt value) receipt,
|
||||
}) {
|
||||
return order(this);
|
||||
}
|
||||
@ -223,7 +223,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Order value)? order,
|
||||
TResult? Function(_SaveOrder value)? saveOrder,
|
||||
TResult? Function(_Receipt value)? receipt,
|
||||
}) {
|
||||
return order?.call(this);
|
||||
}
|
||||
@ -232,7 +232,7 @@ class _$OrderImpl implements _Order {
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Order value)? order,
|
||||
TResult Function(_SaveOrder value)? saveOrder,
|
||||
TResult Function(_Receipt value)? receipt,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (order != null) {
|
||||
@ -257,12 +257,12 @@ abstract class _Order implements PrintStruckEvent {
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$SaveOrderImplCopyWith<$Res>
|
||||
abstract class _$$ReceiptImplCopyWith<$Res>
|
||||
implements $PrintStruckEventCopyWith<$Res> {
|
||||
factory _$$SaveOrderImplCopyWith(
|
||||
_$SaveOrderImpl value,
|
||||
$Res Function(_$SaveOrderImpl) then,
|
||||
) = __$$SaveOrderImplCopyWithImpl<$Res>;
|
||||
factory _$$ReceiptImplCopyWith(
|
||||
_$ReceiptImpl value,
|
||||
$Res Function(_$ReceiptImpl) then,
|
||||
) = __$$ReceiptImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({Order order});
|
||||
@ -272,12 +272,12 @@ abstract class _$$SaveOrderImplCopyWith<$Res>
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$SaveOrderImplCopyWithImpl<$Res>
|
||||
extends _$PrintStruckEventCopyWithImpl<$Res, _$SaveOrderImpl>
|
||||
implements _$$SaveOrderImplCopyWith<$Res> {
|
||||
__$$SaveOrderImplCopyWithImpl(
|
||||
_$SaveOrderImpl _value,
|
||||
$Res Function(_$SaveOrderImpl) _then,
|
||||
class __$$ReceiptImplCopyWithImpl<$Res>
|
||||
extends _$PrintStruckEventCopyWithImpl<$Res, _$ReceiptImpl>
|
||||
implements _$$ReceiptImplCopyWith<$Res> {
|
||||
__$$ReceiptImplCopyWithImpl(
|
||||
_$ReceiptImpl _value,
|
||||
$Res Function(_$ReceiptImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PrintStruckEvent
|
||||
@ -286,7 +286,7 @@ class __$$SaveOrderImplCopyWithImpl<$Res>
|
||||
@override
|
||||
$Res call({Object? order = null}) {
|
||||
return _then(
|
||||
_$SaveOrderImpl(
|
||||
_$ReceiptImpl(
|
||||
null == order
|
||||
? _value.order
|
||||
: order // ignore: cast_nullable_to_non_nullable
|
||||
@ -298,22 +298,22 @@ class __$$SaveOrderImplCopyWithImpl<$Res>
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$SaveOrderImpl implements _SaveOrder {
|
||||
const _$SaveOrderImpl(this.order);
|
||||
class _$ReceiptImpl implements _Receipt {
|
||||
const _$ReceiptImpl(this.order);
|
||||
|
||||
@override
|
||||
final Order order;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PrintStruckEvent.saveOrder(order: $order)';
|
||||
return 'PrintStruckEvent.receipt(order: $order)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$SaveOrderImpl &&
|
||||
other is _$ReceiptImpl &&
|
||||
(identical(other.order, order) || other.order == order));
|
||||
}
|
||||
|
||||
@ -325,36 +325,36 @@ class _$SaveOrderImpl implements _SaveOrder {
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$SaveOrderImplCopyWith<_$SaveOrderImpl> get copyWith =>
|
||||
__$$SaveOrderImplCopyWithImpl<_$SaveOrderImpl>(this, _$identity);
|
||||
_$$ReceiptImplCopyWith<_$ReceiptImpl> get copyWith =>
|
||||
__$$ReceiptImplCopyWithImpl<_$ReceiptImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(Order order) order,
|
||||
required TResult Function(Order order) saveOrder,
|
||||
required TResult Function(Order order) receipt,
|
||||
}) {
|
||||
return saveOrder(this.order);
|
||||
return receipt(this.order);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(Order order)? order,
|
||||
TResult? Function(Order order)? saveOrder,
|
||||
TResult? Function(Order order)? receipt,
|
||||
}) {
|
||||
return saveOrder?.call(this.order);
|
||||
return receipt?.call(this.order);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(Order order)? order,
|
||||
TResult Function(Order order)? saveOrder,
|
||||
TResult Function(Order order)? receipt,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (saveOrder != null) {
|
||||
return saveOrder(this.order);
|
||||
if (receipt != null) {
|
||||
return receipt(this.order);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
@ -363,36 +363,36 @@ class _$SaveOrderImpl implements _SaveOrder {
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Order value) order,
|
||||
required TResult Function(_SaveOrder value) saveOrder,
|
||||
required TResult Function(_Receipt value) receipt,
|
||||
}) {
|
||||
return saveOrder(this);
|
||||
return receipt(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Order value)? order,
|
||||
TResult? Function(_SaveOrder value)? saveOrder,
|
||||
TResult? Function(_Receipt value)? receipt,
|
||||
}) {
|
||||
return saveOrder?.call(this);
|
||||
return receipt?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Order value)? order,
|
||||
TResult Function(_SaveOrder value)? saveOrder,
|
||||
TResult Function(_Receipt value)? receipt,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (saveOrder != null) {
|
||||
return saveOrder(this);
|
||||
if (receipt != null) {
|
||||
return receipt(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _SaveOrder implements PrintStruckEvent {
|
||||
const factory _SaveOrder(final Order order) = _$SaveOrderImpl;
|
||||
abstract class _Receipt implements PrintStruckEvent {
|
||||
const factory _Receipt(final Order order) = _$ReceiptImpl;
|
||||
|
||||
@override
|
||||
Order get order;
|
||||
@ -401,7 +401,7 @@ abstract class _SaveOrder implements PrintStruckEvent {
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$SaveOrderImplCopyWith<_$SaveOrderImpl> get copyWith =>
|
||||
_$$ReceiptImplCopyWith<_$ReceiptImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
|
||||
@ -3,5 +3,5 @@ part of 'print_struck_bloc.dart';
|
||||
@freezed
|
||||
class PrintStruckEvent with _$PrintStruckEvent {
|
||||
const factory PrintStruckEvent.order(Order order) = _Order;
|
||||
const factory PrintStruckEvent.saveOrder(Order order) = _SaveOrder;
|
||||
const factory PrintStruckEvent.receipt(Order order) = _Receipt;
|
||||
}
|
||||
|
||||
@ -19,4 +19,7 @@ abstract class IPrinterRepository {
|
||||
Future<Either<PrinterFailure, Unit>> printStruckSaveOrder({
|
||||
required Order order,
|
||||
});
|
||||
Future<Either<PrinterFailure, Unit>> printStruckReceipt({
|
||||
required Order order,
|
||||
});
|
||||
}
|
||||
|
||||
@ -480,6 +480,15 @@ class PrinterRepository implements IPrinterRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<PrinterFailure, Unit>> printStruckReceipt({
|
||||
required Order order,
|
||||
}) async {
|
||||
final outlet = await _outletLocalDatasource.currentOutlet();
|
||||
final user = await _authLocalDataProvider.currentUser();
|
||||
return _printCashier(order: order, outlet: outlet, cashieName: user.name);
|
||||
}
|
||||
|
||||
Future<Either<PrinterFailure, Unit>> _printReceipt({
|
||||
required Order order,
|
||||
required Outlet outlet,
|
||||
|
||||
@ -4,8 +4,10 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/order/order_loader/order_loader_bloc.dart';
|
||||
import '../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/toast/flushbar.dart';
|
||||
import 'widgets/order_left_panel.dart';
|
||||
import 'widgets/order_right_panel.dart';
|
||||
|
||||
@ -36,6 +38,20 @@ class OrderPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
);
|
||||
},
|
||||
),
|
||||
BlocListener<PrintStruckBloc, PrintStruckState>(
|
||||
listenWhen: (previous, current) =>
|
||||
previous.failureOrPrintStruck != current.failureOrPrintStruck,
|
||||
listener: (context, state) {
|
||||
state.failureOrPrintStruck.fold(() {}, (either) {
|
||||
either.fold(
|
||||
(f) => AppFlushbar.showPrinterFailureToast(context, f),
|
||||
(success) {
|
||||
AppFlushbar.showSuccess(context, "Struck berhasil dicetak");
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../application/order/order_loader/order_loader_bloc.dart';
|
||||
import '../../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../components/button/button.dart';
|
||||
import '../../../components/spaces/space.dart';
|
||||
@ -59,26 +61,10 @@ class OrderRightPanel extends StatelessWidget {
|
||||
AppElevatedButton.outlined(
|
||||
onPressed: () {
|
||||
if (state.selectedOrder?.status == 'completed') {
|
||||
// onPrintRecipt(
|
||||
// context,
|
||||
// order: orderDetail!,
|
||||
// paymentMethod:
|
||||
// orderDetail!.payments
|
||||
// ?.map((p) => p.paymentMethodName)
|
||||
// .join(', ') ??
|
||||
// "",
|
||||
// nominalBayar: orderDetail?.totalPaid ?? 0,
|
||||
// kembalian: 0,
|
||||
// productQuantity: orderDetail!.orderItems!
|
||||
// .toProductQuantities(),
|
||||
// );
|
||||
} else {
|
||||
// onPrintBill(
|
||||
// context,
|
||||
// productQuantity: orderDetail!.orderItems!
|
||||
// .toProductQuantities(),
|
||||
// order: orderDetail!,
|
||||
// );
|
||||
context.read<PrintStruckBloc>().add(
|
||||
PrintStruckEvent.receipt(state.selectedOrder!),
|
||||
);
|
||||
}
|
||||
},
|
||||
label: 'Print Bill',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user