print order add item
This commit is contained in:
parent
93560b85cb
commit
0886e8c912
@ -161,6 +161,17 @@ class Order with _$Order {
|
|||||||
paymentCount: 1,
|
paymentCount: 1,
|
||||||
splitType: 'Single',
|
splitType: 'Single',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// For Add Item Order
|
||||||
|
factory Order.fromLastOrder(Order order, List<ProductQuantity> products) =>
|
||||||
|
order.copyWith(
|
||||||
|
orderItems: products
|
||||||
|
.map((e) => OrderItem.fromProductQuantity(e))
|
||||||
|
.toList(),
|
||||||
|
totalAmount: products
|
||||||
|
.map((e) => e.product.price.toInt() * e.quantity)
|
||||||
|
.reduce((value, element) => value + element),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -202,4 +213,25 @@ class OrderItem with _$OrderItem {
|
|||||||
printerType: '',
|
printerType: '',
|
||||||
paidQuantity: 0,
|
paidQuantity: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
factory OrderItem.fromProductQuantity(ProductQuantity productQuantity) =>
|
||||||
|
OrderItem(
|
||||||
|
id: '',
|
||||||
|
orderId: '',
|
||||||
|
productId: productQuantity.product.id,
|
||||||
|
productName: productQuantity.product.name,
|
||||||
|
productVariantId: productQuantity.variant?.id ?? '',
|
||||||
|
productVariantName: productQuantity.variant?.name ?? '',
|
||||||
|
quantity: productQuantity.quantity,
|
||||||
|
unitPrice: productQuantity.product.price.toInt(),
|
||||||
|
totalPrice: (productQuantity.product.price * productQuantity.quantity)
|
||||||
|
.toInt(),
|
||||||
|
modifiers: [],
|
||||||
|
notes: productQuantity.notes,
|
||||||
|
status: 'pending',
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
updatedAt: DateTime.now(),
|
||||||
|
printerType: productQuantity.product.printerType,
|
||||||
|
paidQuantity: 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
|||||||
|
|
||||||
import '../../common/api/api_failure.dart';
|
import '../../common/api/api_failure.dart';
|
||||||
import '../../common/types/split_type.dart';
|
import '../../common/types/split_type.dart';
|
||||||
|
import '../product/product.dart';
|
||||||
|
|
||||||
part 'order.freezed.dart';
|
part 'order.freezed.dart';
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
import '../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
import '../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||||
|
import '../../../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||||
import '../../../../../common/theme/theme.dart';
|
import '../../../../../common/theme/theme.dart';
|
||||||
import '../../../../components/spaces/space.dart';
|
import '../../../../components/spaces/space.dart';
|
||||||
|
import '../../../../components/toast/flushbar.dart';
|
||||||
import 'widgets/success_add_item_order_left_panel.dart';
|
import 'widgets/success_add_item_order_left_panel.dart';
|
||||||
import 'widgets/success_add_item_order_right_panel.dart';
|
import 'widgets/success_add_item_order_right_panel.dart';
|
||||||
|
|
||||||
@ -14,32 +16,46 @@ class SuccessAddItemOrderPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return BlocListener<PrintStruckBloc, PrintStruckState>(
|
||||||
backgroundColor: AppColor.background,
|
listenWhen: (p, c) => p.failureOrPrintStruck != c.failureOrPrintStruck,
|
||||||
body: SafeArea(
|
listener: (context, state) {
|
||||||
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
state.failureOrPrintStruck.fold(
|
||||||
builder: (context, checkoutState) {
|
() {},
|
||||||
return Padding(
|
(either) => either.fold(
|
||||||
padding: const EdgeInsets.all(24.0),
|
(f) => AppFlushbar.showPrinterFailureToast(context, f),
|
||||||
child: Row(
|
(success) {
|
||||||
children: [
|
AppFlushbar.showSuccess(context, "Struck berhasil dicetak");
|
||||||
Expanded(
|
},
|
||||||
flex: 35,
|
),
|
||||||
child: SuccessAddItemOrderLeftPanel(
|
);
|
||||||
checkoutState: checkoutState,
|
},
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: AppColor.background,
|
||||||
|
body: SafeArea(
|
||||||
|
child: BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||||
|
builder: (context, checkoutState) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(24.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 35,
|
||||||
|
child: SuccessAddItemOrderLeftPanel(
|
||||||
|
checkoutState: checkoutState,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
SpaceWidth(16),
|
||||||
SpaceWidth(16),
|
Expanded(
|
||||||
Expanded(
|
flex: 65,
|
||||||
flex: 65,
|
child: SuccessAddItemOrderRightPanel(
|
||||||
child: SuccessAddItemOrderRightPanel(
|
checkoutState: checkoutState,
|
||||||
checkoutState: checkoutState,
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||||
|
import '../../../../../../application/printer/print_struck/print_struck_bloc.dart';
|
||||||
import '../../../../../../common/extension/extension.dart';
|
import '../../../../../../common/extension/extension.dart';
|
||||||
import '../../../../../../common/theme/theme.dart';
|
import '../../../../../../common/theme/theme.dart';
|
||||||
|
import '../../../../../../domain/order/order.dart';
|
||||||
import '../../../../../components/button/button.dart';
|
import '../../../../../components/button/button.dart';
|
||||||
import '../../../../../components/spaces/space.dart';
|
import '../../../../../components/spaces/space.dart';
|
||||||
import '../../../../../router/app_router.gr.dart';
|
import '../../../../../router/app_router.gr.dart';
|
||||||
@ -186,22 +188,14 @@ class SuccessAddItemOrderLeftPanel extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: AppElevatedButton.filled(
|
child: AppElevatedButton.filled(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// onPrintRecipt(
|
context.read<PrintStruckBloc>().add(
|
||||||
// context,
|
PrintStruckEvent.order(
|
||||||
// order: widget.order,
|
Order.fromLastOrder(
|
||||||
// paymentMethod: widget.paymentMethod,
|
checkoutState.orderAdded!,
|
||||||
// nominalBayar: widget.paymentMethod == "Cash"
|
checkoutState.items,
|
||||||
// ? widget.nominalBayar
|
),
|
||||||
// : widget.order.totalAmount ?? 0,
|
),
|
||||||
// kembalian: widget.nominalBayar -
|
);
|
||||||
// (widget.order.totalAmount ?? 0),
|
|
||||||
// productQuantity: widget.productQuantity,
|
|
||||||
// );
|
|
||||||
// onPrint(
|
|
||||||
// context,
|
|
||||||
// productQuantity: widget.productQuantity,
|
|
||||||
// order: widget.order,
|
|
||||||
// );
|
|
||||||
},
|
},
|
||||||
label: 'Cetak Struk',
|
label: 'Cetak Struk',
|
||||||
icon: Icon(Icons.print_rounded, color: AppColor.white),
|
icon: Icon(Icons.print_rounded, color: AppColor.white),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user