update payment

This commit is contained in:
Phuoc Nguyen
2025-12-01 16:07:49 +07:00
parent e62c466155
commit 12bd70479c
10 changed files with 796 additions and 136 deletions

View File

@@ -0,0 +1,84 @@
/// 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)';
}
}