apskel-pos-flutter/lib/data/models/response/order_response_model.dart

383 lines
9.8 KiB
Dart
Raw Normal View History

2025-08-03 14:39:15 +07:00
import 'dart:convert';
2025-08-07 23:59:01 +07:00
class OrderDetailResponseModel {
2025-08-03 14:39:15 +07:00
final bool? success;
2025-08-07 23:59:01 +07:00
final Order? data;
2025-08-03 14:39:15 +07:00
final dynamic errors;
2025-08-07 23:59:01 +07:00
OrderDetailResponseModel({
2025-08-03 14:39:15 +07:00
this.success,
this.data,
this.errors,
});
2025-08-07 23:59:01 +07:00
factory OrderDetailResponseModel.fromJson(String str) =>
OrderDetailResponseModel.fromMap(json.decode(str));
2025-08-03 14:39:15 +07:00
String toJson() => json.encode(toMap());
2025-08-07 23:59:01 +07:00
factory OrderDetailResponseModel.fromMap(Map<String, dynamic> json) =>
OrderDetailResponseModel(
2025-08-03 14:39:15 +07:00
success: json["success"],
2025-08-07 23:59:01 +07:00
data: json["data"] == null ? null : Order.fromMap(json["data"]),
2025-08-03 14:39:15 +07:00
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
2025-08-07 23:59:01 +07:00
class OrderResponseModel {
final bool? success;
2025-08-07 23:59:01 +07:00
final OrderData? data;
2025-08-07 23:59:01 +07:00
OrderResponseModel({
this.success,
this.data,
});
2025-08-07 23:59:01 +07:00
factory OrderResponseModel.fromJson(String str) =>
OrderResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
2025-08-07 23:59:01 +07:00
factory OrderResponseModel.fromMap(Map<String, dynamic> map) {
return OrderResponseModel(
success: map['success'] ?? false,
data: OrderData.fromMap(map['data']),
);
}
2025-08-07 23:59:01 +07:00
Map<String, dynamic> toMap() {
return {
'success': success,
'data': data?.toMap(),
};
}
}
2025-08-03 14:39:15 +07:00
class OrderData {
final List<Order>? orders;
2025-08-07 23:59:01 +07:00
final List<Payment>? payments;
2025-08-03 14:39:15 +07:00
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
OrderData({
2025-08-07 23:59:01 +07:00
required this.orders,
required this.payments,
required this.totalCount,
required this.page,
required this.limit,
required this.totalPages,
2025-08-03 14:39:15 +07:00
});
2025-08-07 23:59:01 +07:00
factory OrderData.fromMap(Map<String, dynamic> map) {
return OrderData(
orders: map["orders"] == null
? []
: List<Order>.from(map['orders']?.map((x) => Order.fromMap(x))),
payments: map["orders"] == null
? []
: List<Payment>.from(map['payments']?.map((x) => Payment.fromMap(x))),
totalCount: map['total_count'],
page: map['page'],
limit: map['limit'],
totalPages: map['total_pages'],
);
}
2025-08-03 14:39:15 +07:00
2025-08-07 23:59:01 +07:00
Map<String, dynamic> toMap() {
return {
'orders': orders?.map((x) => x.toMap()).toList(),
'payments': payments?.map((x) => x.toMap()).toList(),
'total_count': totalCount,
'page': page,
'limit': limit,
'total_pages': totalPages,
};
}
2025-08-03 14:39:15 +07:00
}
class Order {
final String? id;
final String? orderNumber;
final String? outletId;
final String? userId;
final String? tableNumber;
final String? orderType;
final String? status;
final int? subtotal;
final int? taxAmount;
final int? discountAmount;
final int? totalAmount;
2025-08-07 23:59:01 +07:00
final int? totalCost;
final int? remainingAmount;
final String? paymentStatus;
final int? refundAmount;
final bool? isVoid;
final bool? isRefund;
2025-08-03 14:39:15 +07:00
final String? notes;
final Map<String, dynamic>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
final List<OrderItem>? orderItems;
2025-08-07 23:59:01 +07:00
final List<Payment>? payments;
final int? totalPaid;
final int? paymentCount;
2025-08-08 10:29:17 +07:00
final String? splitType;
2025-08-03 14:39:15 +07:00
Order({
this.id,
this.orderNumber,
this.outletId,
this.userId,
this.tableNumber,
this.orderType,
this.status,
this.subtotal,
this.taxAmount,
this.discountAmount,
this.totalAmount,
2025-08-07 23:59:01 +07:00
this.totalCost,
this.remainingAmount,
this.paymentStatus,
this.refundAmount,
this.isVoid,
this.isRefund,
2025-08-03 14:39:15 +07:00
this.notes,
this.metadata,
this.createdAt,
this.updatedAt,
this.orderItems,
2025-08-07 23:59:01 +07:00
this.payments,
this.totalPaid,
this.paymentCount,
2025-08-08 10:29:17 +07:00
this.splitType,
2025-08-03 14:39:15 +07:00
});
2025-08-07 23:59:01 +07:00
factory Order.fromMap(Map<String, dynamic> map) {
return Order(
id: map['id'],
orderNumber: map['order_number'],
outletId: map['outlet_id'],
userId: map['user_id'],
tableNumber: map['table_number'],
orderType: map['order_type'],
status: map['status'],
subtotal: map['subtotal'],
taxAmount: map['tax_amount'],
discountAmount: map['discount_amount'],
totalAmount: map['total_amount'],
totalCost: map['total_cost'],
remainingAmount: map['remaining_amount'],
paymentStatus: map['payment_status'],
refundAmount: map['refund_amount'],
isVoid: map['is_void'],
isRefund: map['is_refund'],
notes: map['notes'],
metadata: map['metadata'] ?? {},
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
orderItems: map["order_items"] == null
? []
: List<OrderItem>.from(
map['order_items'].map((x) => OrderItem.fromMap(x))),
payments: map["payments"] == null
? []
: List<Payment>.from(map['payments'].map((x) => Payment.fromMap(x))),
totalPaid: map['total_paid'],
paymentCount: map['payment_count'],
2025-08-08 10:29:17 +07:00
splitType: map['split_type'] ?? "",
2025-08-07 23:59:01 +07:00
);
}
2025-08-03 14:39:15 +07:00
2025-08-07 23:59:01 +07:00
Map<String, dynamic> toMap() {
return {
'id': id,
'order_number': orderNumber,
'outlet_id': outletId,
'user_id': userId,
'table_number': tableNumber,
'order_type': orderType,
'status': status,
'subtotal': subtotal,
'tax_amount': taxAmount,
'discount_amount': discountAmount,
'total_amount': totalAmount,
'total_cost': totalCost,
'remaining_amount': remainingAmount,
'payment_status': paymentStatus,
'refund_amount': refundAmount,
'is_void': isVoid,
'is_refund': isRefund,
'notes': notes,
'metadata': metadata,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
'order_items': orderItems?.map((x) => x.toMap()).toList(),
'payments': payments?.map((x) => x.toMap()).toList(),
'total_paid': totalPaid,
'payment_count': paymentCount,
2025-08-08 10:29:17 +07:00
'split_type': splitType,
2025-08-07 23:59:01 +07:00
};
}
2025-08-03 14:39:15 +07:00
}
class OrderItem {
2025-08-07 23:59:01 +07:00
String? id;
String? orderId;
String? productId;
String? productName;
String? productVariantId;
String? productVariantName;
int? quantity;
int? unitPrice;
int? totalPrice;
List<dynamic>? modifiers;
String? notes;
String? status;
DateTime? createdAt;
DateTime? updatedAt;
String? printerType;
2025-08-08 23:04:35 +07:00
int? paidQuantity;
2025-08-03 14:39:15 +07:00
OrderItem({
this.id,
this.orderId,
this.productId,
this.productName,
this.productVariantId,
2025-08-04 17:42:39 +07:00
this.productVariantName,
2025-08-03 14:39:15 +07:00
this.quantity,
this.unitPrice,
this.totalPrice,
this.modifiers,
this.notes,
this.status,
this.createdAt,
this.updatedAt,
2025-08-07 23:59:01 +07:00
this.printerType,
2025-08-08 23:04:35 +07:00
this.paidQuantity,
2025-08-03 14:39:15 +07:00
});
2025-08-07 23:59:01 +07:00
factory OrderItem.fromMap(Map<String, dynamic> map) {
return OrderItem(
id: map['id'],
orderId: map['order_id'],
productId: map['product_id'],
productName: map['product_name'],
productVariantId: map['product_variant_id'],
productVariantName: map['product_variant_name'],
quantity: map['quantity'],
unitPrice: map['unit_price'],
totalPrice: map['total_price'],
modifiers:
map['modifiers'] == null ? [] : List<dynamic>.from(map['modifiers']),
notes: map['notes'],
status: map['status'],
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
printerType: map['printer_type'],
2025-08-08 23:04:35 +07:00
paidQuantity: map['paid_quantity'],
2025-08-07 23:59:01 +07:00
);
}
2025-08-03 14:39:15 +07:00
2025-08-07 23:59:01 +07:00
Map<String, dynamic> toMap() {
return {
'id': id,
'order_id': orderId,
'product_id': productId,
'product_name': productName,
'product_variant_id': productVariantId,
'product_variant_name': productVariantName,
'quantity': quantity,
'unit_price': unitPrice,
'total_price': totalPrice,
'modifiers': modifiers,
'notes': notes,
'status': status,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
'printer_type': printerType,
2025-08-08 23:04:35 +07:00
'paid_quantity': paidQuantity,
2025-08-07 23:59:01 +07:00
};
}
}
class Payment {
final String? id;
final String? orderId;
final String? paymentMethodId;
final String? paymentMethodName;
final String? paymentMethodType;
final int? amount;
final String? status;
final int? splitNumber;
final int? splitTotal;
final String? splitDescription;
final int? refundAmount;
final Map<String, dynamic>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
Payment({
this.id,
this.orderId,
this.paymentMethodId,
this.paymentMethodName,
this.paymentMethodType,
this.amount,
this.status,
this.splitNumber,
this.splitTotal,
this.splitDescription,
this.refundAmount,
this.metadata,
this.createdAt,
this.updatedAt,
});
factory Payment.fromMap(Map<String, dynamic> map) {
return Payment(
id: map['id'],
orderId: map['order_id'],
paymentMethodId: map['payment_method_id'],
paymentMethodName: map['payment_method_name'],
paymentMethodType: map['payment_method_type'],
amount: map['amount'],
status: map['status'],
splitNumber: map['split_number'],
splitTotal: map['split_total'],
splitDescription: map['split_description'],
refundAmount: map['refund_amount'],
metadata: map['metadata'] ?? {},
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'order_id': orderId,
'payment_method_id': paymentMethodId,
'payment_method_name': paymentMethodName,
'payment_method_type': paymentMethodType,
'amount': amount,
'status': status,
'split_number': splitNumber,
'split_total': splitTotal,
'split_description': splitDescription,
'refund_amount': refundAmount,
'metadata': metadata,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
2025-08-03 14:39:15 +07:00
}