fix: order and add to order

This commit is contained in:
efrilm 2025-08-13 22:52:37 +07:00
parent b34428965e
commit b0006ee6bc
9 changed files with 29 additions and 17 deletions

View File

@ -405,7 +405,7 @@ class OrderRemoteDatasource {
}
}
Future<Either<String, OrderDetailResponseModel>> addToOrder({
Future<Either<String, bool>> addToOrder({
required String orderId,
required List<OrderItemRequest> orderItems,
}) async {
@ -429,8 +429,7 @@ class OrderRemoteDatasource {
);
if (response.statusCode == 200) {
final data = OrderDetailResponseModel.fromMap(response.data);
return Right(data);
return Right(true);
} else {
return const Left('Gagal menambahkan pesanan pesanan');
}
@ -442,7 +441,7 @@ class OrderRemoteDatasource {
return Left(errorMessage);
} catch (e) {
log("💥 Unexpected error: $e");
return const Left('Terjadi kesalahan tak terduga');
return const Left('Terjadi kesalahan, coba lagi nanti.');
}
}

View File

@ -81,7 +81,7 @@ class OrderData {
orders: map["orders"] == null
? []
: List<Order>.from(map['orders']?.map((x) => Order.fromMap(x))),
payments: map["orders"] == null
payments: map["payments"] == null
? []
: List<Payment>.from(map['payments']?.map((x) => Payment.fromMap(x))),
totalCount: map['total_count'],

View File

@ -131,11 +131,11 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
result.fold(
(error) => emit(_Error(error)),
(success) => emit(_Success(success.data!)),
(success) => emit(_SuccessMsg()),
);
} catch (e) {
log("Error in AddOrderItemsBloc: $e");
emit(_Error("Failed to add order items: $e"));
emit(_Error("Ada kesalahan. Coba lagi nanti"));
}
},
);

View File

@ -289,7 +289,7 @@ class _PaymentAddOrderDialogState extends State<PaymentAddOrderDialog> {
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: (data) {
successMsg: () {
context.pop();
context.pushReplacement(
SuccessSaveOrderPage(

View File

@ -45,7 +45,6 @@ class OrderRequestModel {
Map<String, dynamic> data = {
"outlet_id": outletId,
"table_number": tableNumber,
"table_id": tableId,
"order_type": orderType,
"notes": notes,
"order_items": orderItems == null
@ -58,6 +57,10 @@ class OrderRequestModel {
data["customer_id"] = customerId;
}
if (tableId != null && tableId != "") {
data["table_id"] = tableId;
}
return data;
}
}

View File

@ -355,7 +355,10 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
(previousValue, element) =>
previousValue +
(element.product.price! *
element.quantity),
element.quantity) +
(element.variant
?.priceModifier ??
0),
));
return Text(
price.currencyFormatRp,
@ -500,7 +503,9 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
(previousValue, element) =>
previousValue +
(element.product.price! *
element.quantity),
element.quantity) +
(element.variant?.priceModifier ??
0),
),
);
@ -1074,7 +1079,7 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
orderType: orderType,
paymentMethod:
selectedPaymentMethod!,
table: widget.table!,
table: widget.table,
customer:
selectedCustomer,
),

View File

@ -429,8 +429,10 @@ class _HomePageState extends State<HomePage> {
}
return products
.map((e) =>
e.product.price! *
e.quantity)
(e.product.price! *
e.quantity) +
(e.variant?.priceModifier ??
0))
.reduce((value, element) =>
value + element);
});

View File

@ -538,7 +538,8 @@ class _SuccessOrderPageState extends State<SuccessOrderPage>
Widget _buildProductCard(int index) {
final item = widget.productQuantity[index];
final totalPrice = (item.product.price ?? 0) * item.quantity;
final totalPrice = (item.product.price ?? 0) * item.quantity +
(item.variant?.priceModifier ?? 0);
return TweenAnimationBuilder<double>(
tween: Tween<double>(begin: 0.0, end: 1.0),
@ -634,7 +635,8 @@ class _SuccessOrderPageState extends State<SuccessOrderPage>
borderRadius: BorderRadius.circular(8),
),
child: Text(
(item.product.price ?? 0)
((item.product.price ?? 0) +
(item.variant?.priceModifier ?? 0))
.toString()
.currencyFormatRpV2,
style: TextStyle(

View File

@ -380,7 +380,8 @@ class _SuccessSaveOrderPageState extends State<SuccessSaveOrderPage> {
Widget _buildProductCard(int index) {
final item = widget.productQuantity[index];
final totalPrice = (item.product.price ?? 0) * item.quantity;
final totalPrice = (item.product.price ?? 0) * item.quantity +
(item.variant?.priceModifier ?? 0);
return Container(
padding: const EdgeInsets.all(16.0),