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 String orderId,
required List<OrderItemRequest> orderItems, required List<OrderItemRequest> orderItems,
}) async { }) async {
@ -429,8 +429,7 @@ class OrderRemoteDatasource {
); );
if (response.statusCode == 200) { if (response.statusCode == 200) {
final data = OrderDetailResponseModel.fromMap(response.data); return Right(true);
return Right(data);
} else { } else {
return const Left('Gagal menambahkan pesanan pesanan'); return const Left('Gagal menambahkan pesanan pesanan');
} }
@ -442,7 +441,7 @@ class OrderRemoteDatasource {
return Left(errorMessage); return Left(errorMessage);
} catch (e) { } catch (e) {
log("💥 Unexpected error: $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 orders: map["orders"] == null
? [] ? []
: List<Order>.from(map['orders']?.map((x) => Order.fromMap(x))), : 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))), : List<Payment>.from(map['payments']?.map((x) => Payment.fromMap(x))),
totalCount: map['total_count'], totalCount: map['total_count'],

View File

@ -131,11 +131,11 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
result.fold( result.fold(
(error) => emit(_Error(error)), (error) => emit(_Error(error)),
(success) => emit(_Success(success.data!)), (success) => emit(_SuccessMsg()),
); );
} catch (e) { } catch (e) {
log("Error in AddOrderItemsBloc: $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) { listener: (context, state) {
state.maybeWhen( state.maybeWhen(
orElse: () {}, orElse: () {},
success: (data) { successMsg: () {
context.pop(); context.pop();
context.pushReplacement( context.pushReplacement(
SuccessSaveOrderPage( SuccessSaveOrderPage(

View File

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

View File

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

View File

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

View File

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

View File

@ -380,7 +380,8 @@ class _SuccessSaveOrderPageState extends State<SuccessSaveOrderPage> {
Widget _buildProductCard(int index) { Widget _buildProductCard(int index) {
final item = widget.productQuantity[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( return Container(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),