2024-08-01 17:01:50 +00:00
|
|
|
module account.model;
|
|
|
|
|
|
|
|
import std.datetime;
|
2024-09-19 19:12:23 +00:00
|
|
|
import std.traits : EnumMembers;
|
2024-08-01 17:01:50 +00:00
|
|
|
|
2024-09-19 19:12:23 +00:00
|
|
|
import util.money;
|
2024-08-01 17:01:50 +00:00
|
|
|
|
|
|
|
struct AccountType {
|
2024-09-27 15:35:08 +00:00
|
|
|
immutable string id;
|
|
|
|
immutable string name;
|
|
|
|
immutable bool debitsPositive;
|
2024-08-01 17:01:50 +00:00
|
|
|
|
|
|
|
static AccountType fromId(string id) {
|
2024-09-19 19:12:23 +00:00
|
|
|
static foreach (t; ALL_ACCOUNT_TYPES) {
|
|
|
|
if (t.id == id) return t;
|
2024-08-01 17:01:50 +00:00
|
|
|
}
|
|
|
|
throw new Exception("Invalid account type id " ~ id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AccountTypes : AccountType {
|
|
|
|
CHECKING = AccountType("CHECKING", "Checking", true),
|
|
|
|
SAVINGS = AccountType("SAVINGS", "Savings", true),
|
|
|
|
CREDIT_CARD = AccountType("CREDIT_CARD", "Credit Card", false),
|
|
|
|
BROKERAGE = AccountType("BROKERAGE", "Brokerage", true)
|
|
|
|
}
|
|
|
|
|
2024-09-19 19:12:23 +00:00
|
|
|
immutable(AccountType[]) ALL_ACCOUNT_TYPES = cast(AccountType[]) [ EnumMembers!AccountTypes ];
|
|
|
|
|
2024-08-01 17:01:50 +00:00
|
|
|
struct Account {
|
2024-09-27 15:35:08 +00:00
|
|
|
immutable ulong id;
|
|
|
|
immutable SysTime createdAt;
|
|
|
|
immutable bool archived;
|
|
|
|
immutable AccountType type;
|
|
|
|
immutable string numberSuffix;
|
|
|
|
immutable string name;
|
|
|
|
immutable Currency currency;
|
|
|
|
immutable string description;
|
2024-08-01 17:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AccountCreditCardProperties {
|
2024-09-27 15:35:08 +00:00
|
|
|
immutable ulong account_id;
|
|
|
|
immutable long creditLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AccountJournalEntryType : string {
|
|
|
|
CREDIT = "CREDIT",
|
|
|
|
DEBIT = "DEBIT"
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AccountJournalEntry {
|
|
|
|
immutable ulong id;
|
|
|
|
immutable SysTime timestamp;
|
|
|
|
immutable ulong accountId;
|
|
|
|
immutable ulong transactionId;
|
|
|
|
immutable ulong amount;
|
|
|
|
immutable AccountJournalEntryType type;
|
|
|
|
immutable Currency currency;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AccountValueRecordType : string {
|
|
|
|
BALANCE = "BALANCE"
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AccountValueRecord {
|
|
|
|
immutable ulong id;
|
|
|
|
immutable SysTime timestamp;
|
|
|
|
immutable ulong accountId;
|
|
|
|
immutable AccountValueRecordType type;
|
|
|
|
immutable long value;
|
|
|
|
immutable Currency currency;
|
2024-08-01 17:01:50 +00:00
|
|
|
}
|