print order add item

This commit is contained in:
efrilm
2025-11-07 16:45:36 +07:00
parent 93560b85cb
commit 0886e8c912
4 changed files with 83 additions and 40 deletions
@@ -161,6 +161,17 @@ class Order with _$Order {
paymentCount: 1,
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
@@ -202,4 +213,25 @@ class OrderItem with _$OrderItem {
printerType: '',
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,
);
}
+1
View File
@@ -3,6 +3,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import '../../common/api/api_failure.dart';
import '../../common/types/split_type.dart';
import '../product/product.dart';
part 'order.freezed.dart';