update payment
This commit is contained in:
84
lib/features/orders/domain/entities/payment.dart
Normal file
84
lib/features/orders/domain/entities/payment.dart
Normal 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)';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/// Payment Repository Interface
|
||||
///
|
||||
/// Defines the contract for payment-related data operations.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/orders/domain/entities/payment.dart';
|
||||
|
||||
/// Payment Repository Interface
|
||||
abstract class PaymentRepository {
|
||||
/// Get list of payments
|
||||
Future<List<Payment>> getPaymentsList({
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 0,
|
||||
});
|
||||
|
||||
/// Get payment detail by ID
|
||||
Future<Payment> getPaymentDetail(String name);
|
||||
}
|
||||
Reference in New Issue
Block a user