85 lines
2.2 KiB
Dart
85 lines
2.2 KiB
Dart
/// Domain Entity: Payment
|
|
///
|
|
/// Represents a payment transaction from the API.
|
|
library;
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
/// Payment Entity
|
|
///
|
|
/// Contains payment information from API:
|
|
/// - name: Payment ID (e.g., "ACC-PAY-2025-00020")
|
|
/// - posting_date: Payment date
|
|
/// - paid_amount: Amount paid
|
|
/// - mode_of_payment: Payment method (e.g., "Chuyển khoản")
|
|
/// - invoice_id: Related invoice ID (nullable)
|
|
/// - order_id: Related order ID (nullable)
|
|
class Payment extends Equatable {
|
|
/// Payment ID (e.g., "ACC-PAY-2025-00020")
|
|
final String name;
|
|
|
|
/// Payment posting date
|
|
final DateTime postingDate;
|
|
|
|
/// Amount paid
|
|
final double paidAmount;
|
|
|
|
/// Payment method (e.g., "Chuyển khoản", null if not specified)
|
|
final String? modeOfPayment;
|
|
|
|
/// Related invoice ID (nullable)
|
|
final String? invoiceId;
|
|
|
|
/// Related order ID (nullable)
|
|
final String? orderId;
|
|
|
|
const Payment({
|
|
required this.name,
|
|
required this.postingDate,
|
|
required this.paidAmount,
|
|
this.modeOfPayment,
|
|
this.invoiceId,
|
|
this.orderId,
|
|
});
|
|
|
|
/// Get display payment method
|
|
String get displayPaymentMethod => modeOfPayment ?? 'Chuyển khoản';
|
|
|
|
/// Get description based on order/invoice
|
|
String get description {
|
|
if (orderId != null) {
|
|
return 'Thanh toán cho Đơn hàng #$orderId';
|
|
} else if (invoiceId != null) {
|
|
return 'Thanh toán hóa đơn #$invoiceId';
|
|
}
|
|
return 'Thanh toán #$name';
|
|
}
|
|
|
|
/// Copy with method for immutability
|
|
Payment copyWith({
|
|
String? name,
|
|
DateTime? postingDate,
|
|
double? paidAmount,
|
|
String? modeOfPayment,
|
|
String? invoiceId,
|
|
String? orderId,
|
|
}) {
|
|
return Payment(
|
|
name: name ?? this.name,
|
|
postingDate: postingDate ?? this.postingDate,
|
|
paidAmount: paidAmount ?? this.paidAmount,
|
|
modeOfPayment: modeOfPayment ?? this.modeOfPayment,
|
|
invoiceId: invoiceId ?? this.invoiceId,
|
|
orderId: orderId ?? this.orderId,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [name, postingDate, paidAmount, modeOfPayment, invoiceId, orderId];
|
|
|
|
@override
|
|
String toString() {
|
|
return 'Payment(name: $name, paidAmount: $paidAmount, orderId: $orderId)';
|
|
}
|
|
}
|