feat: syn product

This commit is contained in:
efrilm
2025-08-03 00:35:00 +07:00
parent 576f687d21
commit 7678b4791d
28 changed files with 1922 additions and 948 deletions
@@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:enaklo_pos/core/extensions/string_ext.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'add_order_items_event.dart';
@@ -12,24 +11,26 @@ part 'add_order_items_bloc.freezed.dart';
class AddOrderItemsBloc extends Bloc<AddOrderItemsEvent, AddOrderItemsState> {
final OrderRemoteDatasource orderRemoteDatasource;
AddOrderItemsBloc(
this.orderRemoteDatasource,
) : super(const _Initial()) {
on<_AddOrderItems>((event, emit) async {
emit(const _Loading());
try {
// Convert ProductQuantity list to the format expected by the API
final orderItems = event.items.map((item) => {
'id_product': item.product.productId,
'quantity': item.quantity,
'price': item.product.price!.toIntegerFromText,
'notes': item.notes,
}).toList();
final orderItems = event.items
.map((item) => {
'id_product': item.product.id,
'quantity': item.quantity,
'price': item.product.price,
'notes': item.notes,
})
.toList();
log("Adding order items: ${orderItems.toString()}");
final result = await orderRemoteDatasource.addOrderItems(
event.orderId,
orderItems,
@@ -45,4 +46,4 @@ class AddOrderItemsBloc extends Bloc<AddOrderItemsEvent, AddOrderItemsState> {
}
});
}
}
}