2025-08-04 00:50:10 +07:00

89 lines
2.3 KiB
Dart

import 'dart:convert';
class OrderRequestModel {
final String? outletId;
final String? userId;
final String? tableNumber;
final String? tableId;
final String? orderType;
final String? notes;
final List<OrderItemRequest>? orderItems;
final String? customerName;
OrderRequestModel({
this.outletId,
this.userId,
this.tableNumber,
this.tableId,
this.orderType,
this.notes,
this.orderItems,
this.customerName,
});
factory OrderRequestModel.fromJson(String str) =>
OrderRequestModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory OrderRequestModel.fromMap(Map<String, dynamic> json) =>
OrderRequestModel(
outletId: json["outlet_id"],
userId: json["user_id"],
tableNumber: json["table_number"],
tableId: json["table_id"],
orderType: json["order_type"],
notes: json["notes"],
orderItems: json["order_items"] == null
? []
: List<OrderItemRequest>.from(
json["order_items"].map((x) => OrderItemRequest.fromMap(x))),
customerName: json["customer_name"],
);
Map<String, dynamic> toMap() => {
"outlet_id": outletId,
"user_id": userId,
"table_number": tableNumber,
"table_id": tableId,
"order_type": orderType,
"notes": notes,
"order_items": orderItems == null
? []
: List<dynamic>.from(orderItems!.map((x) => x.toMap())),
"customer_name": customerName,
};
}
class OrderItemRequest {
final String? productId;
final int? quantity;
final int? unitPrice;
final String? notes;
OrderItemRequest({
this.productId,
this.quantity,
this.unitPrice,
this.notes,
});
factory OrderItemRequest.fromJson(String str) =>
OrderItemRequest.fromMap(json.decode(str));
factory OrderItemRequest.fromMap(Map<String, dynamic> json) =>
OrderItemRequest(
productId: json["product_id"],
quantity: json["quantity"],
unitPrice: json["unit_price"]?.toDouble(),
notes: json["notes"],
);
Map<String, dynamic> toMap() => {
"product_id": productId,
"quantity": quantity,
"unit_price": unitPrice,
"notes": notes,
};
}