diff --git a/lib/data/datasources/order_remote_datasource.dart b/lib/data/datasources/order_remote_datasource.dart index a0f35d8..fdb3675 100644 --- a/lib/data/datasources/order_remote_datasource.dart +++ b/lib/data/datasources/order_remote_datasource.dart @@ -405,7 +405,7 @@ class OrderRemoteDatasource { } } - Future> addToOrder({ + Future> addToOrder({ required String orderId, required List 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.'); } } diff --git a/lib/data/models/response/order_response_model.dart b/lib/data/models/response/order_response_model.dart index 075f12c..178d5e0 100644 --- a/lib/data/models/response/order_response_model.dart +++ b/lib/data/models/response/order_response_model.dart @@ -81,7 +81,7 @@ class OrderData { orders: map["orders"] == null ? [] : List.from(map['orders']?.map((x) => Order.fromMap(x))), - payments: map["orders"] == null + payments: map["payments"] == null ? [] : List.from(map['payments']?.map((x) => Payment.fromMap(x))), totalCount: map['total_count'], diff --git a/lib/presentation/home/bloc/order_form/order_form_bloc.dart b/lib/presentation/home/bloc/order_form/order_form_bloc.dart index cc86adc..85236c5 100644 --- a/lib/presentation/home/bloc/order_form/order_form_bloc.dart +++ b/lib/presentation/home/bloc/order_form/order_form_bloc.dart @@ -131,11 +131,11 @@ class OrderFormBloc extends Bloc { 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")); } }, ); diff --git a/lib/presentation/home/dialog/payment_add_order_dialog.dart b/lib/presentation/home/dialog/payment_add_order_dialog.dart index b051cf7..f2a0906 100644 --- a/lib/presentation/home/dialog/payment_add_order_dialog.dart +++ b/lib/presentation/home/dialog/payment_add_order_dialog.dart @@ -289,7 +289,7 @@ class _PaymentAddOrderDialogState extends State { listener: (context, state) { state.maybeWhen( orElse: () {}, - success: (data) { + successMsg: () { context.pop(); context.pushReplacement( SuccessSaveOrderPage( diff --git a/lib/presentation/home/models/order_request.dart b/lib/presentation/home/models/order_request.dart index 2101f48..7eabb86 100644 --- a/lib/presentation/home/models/order_request.dart +++ b/lib/presentation/home/models/order_request.dart @@ -45,7 +45,6 @@ class OrderRequestModel { Map 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; } } diff --git a/lib/presentation/home/pages/confirm_payment_page.dart b/lib/presentation/home/pages/confirm_payment_page.dart index ba12f76..b03e1f8 100644 --- a/lib/presentation/home/pages/confirm_payment_page.dart +++ b/lib/presentation/home/pages/confirm_payment_page.dart @@ -355,7 +355,10 @@ class _ConfirmPaymentPageState extends State { (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 { (previousValue, element) => previousValue + (element.product.price! * - element.quantity), + element.quantity) + + (element.variant?.priceModifier ?? + 0), ), ); @@ -1074,7 +1079,7 @@ class _ConfirmPaymentPageState extends State { orderType: orderType, paymentMethod: selectedPaymentMethod!, - table: widget.table!, + table: widget.table, customer: selectedCustomer, ), diff --git a/lib/presentation/home/pages/home_page.dart b/lib/presentation/home/pages/home_page.dart index d92e18c..f3e3bd6 100644 --- a/lib/presentation/home/pages/home_page.dart +++ b/lib/presentation/home/pages/home_page.dart @@ -429,8 +429,10 @@ class _HomePageState extends State { } return products .map((e) => - e.product.price! * - e.quantity) + (e.product.price! * + e.quantity) + + (e.variant?.priceModifier ?? + 0)) .reduce((value, element) => value + element); }); diff --git a/lib/presentation/success/pages/success_order_page.dart b/lib/presentation/success/pages/success_order_page.dart index 9ad041a..b13d54d 100644 --- a/lib/presentation/success/pages/success_order_page.dart +++ b/lib/presentation/success/pages/success_order_page.dart @@ -538,7 +538,8 @@ class _SuccessOrderPageState extends State 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( tween: Tween(begin: 0.0, end: 1.0), @@ -634,7 +635,8 @@ class _SuccessOrderPageState extends State borderRadius: BorderRadius.circular(8), ), child: Text( - (item.product.price ?? 0) + ((item.product.price ?? 0) + + (item.variant?.priceModifier ?? 0)) .toString() .currencyFormatRpV2, style: TextStyle( diff --git a/lib/presentation/success/pages/success_save_order_page.dart b/lib/presentation/success/pages/success_save_order_page.dart index d3a6887..96b5776 100644 --- a/lib/presentation/success/pages/success_save_order_page.dart +++ b/lib/presentation/success/pages/success_save_order_page.dart @@ -380,7 +380,8 @@ class _SuccessSaveOrderPageState extends State { 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),