feat: product variant

This commit is contained in:
efrilm
2025-08-04 17:42:39 +07:00
parent 04e1edbe79
commit 835c834ce1
18 changed files with 718 additions and 1024 deletions
@@ -2,7 +2,7 @@ import 'dart:convert';
class OrderRequestModel {
final String? outletId;
final String? userId;
final String? customerId;
final String? tableNumber;
final String? tableId;
final String? orderType;
@@ -12,7 +12,7 @@ class OrderRequestModel {
OrderRequestModel({
this.outletId,
this.userId,
this.customerId,
this.tableNumber,
this.tableId,
this.orderType,
@@ -29,7 +29,7 @@ class OrderRequestModel {
factory OrderRequestModel.fromMap(Map<String, dynamic> json) =>
OrderRequestModel(
outletId: json["outlet_id"],
userId: json["user_id"],
customerId: json["customer_id"],
tableNumber: json["table_number"],
tableId: json["table_id"],
orderType: json["order_type"],
@@ -43,7 +43,7 @@ class OrderRequestModel {
Map<String, dynamic> toMap() => {
"outlet_id": outletId,
"user_id": userId,
"customer_id": customerId,
"table_number": tableNumber,
"table_id": tableId,
"order_type": orderType,
@@ -57,12 +57,14 @@ class OrderRequestModel {
class OrderItemRequest {
final String? productId;
final String? productVariantId;
final int? quantity;
final int? unitPrice;
final String? notes;
OrderItemRequest({
this.productId,
this.productVariantId,
this.quantity,
this.unitPrice,
this.notes,
@@ -74,6 +76,7 @@ class OrderItemRequest {
factory OrderItemRequest.fromMap(Map<String, dynamic> json) =>
OrderItemRequest(
productId: json["product_id"],
productVariantId: json["product_variant_id"],
quantity: json["quantity"],
unitPrice: json["unit_price"]?.toDouble(),
notes: json["notes"],
@@ -81,6 +84,7 @@ class OrderItemRequest {
Map<String, dynamic> toMap() => {
"product_id": productId,
"product_variant_id": productVariantId,
"quantity": quantity,
"unit_price": unitPrice,
"notes": notes,
@@ -5,12 +5,14 @@ import 'package:enaklo_pos/data/models/response/product_response_model.dart';
class ProductQuantity {
final Product product;
ProductVariant? variant;
int quantity;
String notes;
ProductQuantity({
required this.product,
required this.quantity,
this.notes = '',
this.variant,
});
@override
@@ -20,17 +22,20 @@ class ProductQuantity {
return other is ProductQuantity &&
other.product == product &&
other.quantity == quantity &&
other.variant == variant &&
other.notes == notes;
}
@override
int get hashCode => product.hashCode ^ quantity.hashCode ^ notes.hashCode;
int get hashCode =>
product.hashCode ^ quantity.hashCode ^ variant.hashCode ^ notes.hashCode;
Map<String, dynamic> toMap() {
return {
'product': product.toMap(),
'quantity': quantity,
'notes': notes,
'variant': variant?.toMap(),
};
}
@@ -43,6 +48,7 @@ class ProductQuantity {
'quantity': quantity,
'price': product.price,
'notes': notes,
'variant': variant?.toMap(),
};
}
@@ -55,6 +61,7 @@ class ProductQuantity {
'quantity': quantity,
'price': product.price,
'notes': notes,
'variant': variant?.toMap(),
};
}
@@ -63,6 +70,9 @@ class ProductQuantity {
product: Product.fromMap(map['product']),
quantity: map['quantity']?.toInt() ?? 0,
notes: map['notes'] ?? '',
variant: map['variant'] != null
? ProductVariant.fromMap(map['variant'])
: null,
);
}
@@ -72,6 +82,9 @@ class ProductQuantity {
product: Product.fromOrderMap(map),
quantity: map['quantity']?.toInt() ?? 0,
notes: map['notes'] ?? '',
variant: map['variant'] != null
? ProductVariant.fromMap(map['variant'])
: null,
);
}
@@ -89,6 +102,7 @@ class ProductQuantity {
product: product ?? this.product,
quantity: quantity ?? this.quantity,
notes: notes ?? this.notes,
variant: variant,
);
}
}