2025-08-03 12:26:47 +07:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
class OrderRequestModel {
|
|
|
|
|
final String? outletId;
|
2025-08-04 17:42:39 +07:00
|
|
|
final String? customerId;
|
2025-08-03 12:26:47 +07:00
|
|
|
final String? tableNumber;
|
2025-08-04 00:50:10 +07:00
|
|
|
final String? tableId;
|
2025-08-03 12:26:47 +07:00
|
|
|
final String? orderType;
|
|
|
|
|
final String? notes;
|
|
|
|
|
final List<OrderItemRequest>? orderItems;
|
|
|
|
|
final String? customerName;
|
|
|
|
|
|
|
|
|
|
OrderRequestModel({
|
|
|
|
|
this.outletId,
|
2025-08-04 17:42:39 +07:00
|
|
|
this.customerId,
|
2025-08-03 12:26:47 +07:00
|
|
|
this.tableNumber,
|
2025-08-04 00:50:10 +07:00
|
|
|
this.tableId,
|
2025-08-03 12:26:47 +07:00
|
|
|
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"],
|
2025-08-04 17:42:39 +07:00
|
|
|
customerId: json["customer_id"],
|
2025-08-03 12:26:47 +07:00
|
|
|
tableNumber: json["table_number"],
|
2025-08-04 00:50:10 +07:00
|
|
|
tableId: json["table_id"],
|
2025-08-03 12:26:47 +07:00
|
|
|
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"],
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-05 22:39:43 +07:00
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
|
Map<String, dynamic> data = {
|
|
|
|
|
"outlet_id": outletId,
|
|
|
|
|
"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,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (customerId != null || customerId != "") {
|
|
|
|
|
data["customer_id"] = customerId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2025-08-03 12:26:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OrderItemRequest {
|
|
|
|
|
final String? productId;
|
2025-08-04 17:42:39 +07:00
|
|
|
final String? productVariantId;
|
2025-08-03 12:26:47 +07:00
|
|
|
final int? quantity;
|
|
|
|
|
final int? unitPrice;
|
|
|
|
|
final String? notes;
|
|
|
|
|
|
|
|
|
|
OrderItemRequest({
|
|
|
|
|
this.productId,
|
2025-08-04 17:42:39 +07:00
|
|
|
this.productVariantId,
|
2025-08-03 12:26:47 +07:00
|
|
|
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"],
|
2025-08-04 17:42:39 +07:00
|
|
|
productVariantId: json["product_variant_id"],
|
2025-08-03 12:26:47 +07:00
|
|
|
quantity: json["quantity"],
|
|
|
|
|
unitPrice: json["unit_price"]?.toDouble(),
|
|
|
|
|
notes: json["notes"],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
|
"product_id": productId,
|
2025-08-04 17:42:39 +07:00
|
|
|
"product_variant_id": productVariantId,
|
2025-08-03 12:26:47 +07:00
|
|
|
"quantity": quantity,
|
|
|
|
|
"unit_price": unitPrice,
|
|
|
|
|
"notes": notes,
|
|
|
|
|
};
|
|
|
|
|
}
|