WIP: integration with ledger
This commit is contained in:
31
frontend/pshared/lib/models/payment/source.dart
Normal file
31
frontend/pshared/lib/models/payment/source.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
|
||||
|
||||
enum PaymentSourceType { wallet, ledger }
|
||||
|
||||
class PaymentSource {
|
||||
final PaymentSourceType type;
|
||||
final Wallet? wallet;
|
||||
final LedgerAccount? ledgerAccount;
|
||||
|
||||
const PaymentSource._({required this.type, this.wallet, this.ledgerAccount});
|
||||
|
||||
const PaymentSource.wallet(Wallet wallet)
|
||||
: this._(type: PaymentSourceType.wallet, wallet: wallet);
|
||||
|
||||
const PaymentSource.ledger(LedgerAccount account)
|
||||
: this._(type: PaymentSourceType.ledger, ledgerAccount: account);
|
||||
|
||||
String get id => switch (type) {
|
||||
PaymentSourceType.wallet => wallet!.id,
|
||||
PaymentSourceType.ledger => ledgerAccount!.ledgerAccountRef,
|
||||
};
|
||||
|
||||
String get key => '${type.name}:$id';
|
||||
|
||||
String get name => switch (type) {
|
||||
PaymentSourceType.wallet => wallet!.name,
|
||||
PaymentSourceType.ledger => ledgerAccount!.name,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user