Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock: refine Stock.accountID(heldat), add linked asset and shares account #366

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions MMEX/Data/AccountData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum AccountType: String, ChoiceProtocol {
case .asset:
return "house.fill"
case .shares:
return "person.3.fill"
return "chart.line.uptrend.xyaxis"
}
}
}
Expand Down Expand Up @@ -145,11 +145,29 @@ extension AccountData {
initialBal: 200.0, favoriteAcct: .boolTrue, currencyId: 2
),
AccountData(
id: 3, name: "Investment Account", type: AccountType.investment,
id: 3, name: "Inv Account", type: AccountType.investment,
status: AccountStatus.open, notes: "",
initialDate: DateString(Date()),
initialBal: 0.0, favoriteAcct: .boolTrue, currencyId: 1
),
AccountData(
id: 4, name: "House", type: AccountType.asset,
status: AccountStatus.open, notes: "",
initialDate: DateString(Date()),
initialBal: 0.0, favoriteAcct: .boolTrue, currencyId: 1
),
AccountData(
id: 5, name: "Car", type: AccountType.asset,
status: AccountStatus.open, notes: "",
initialDate: DateString(Date()),
initialBal: 0.0, favoriteAcct: .boolFalse, currencyId: 1
),
AccountData(
id: 6, name: "Apple", type: AccountType.shares,
status: AccountStatus.open, notes: "links of Stock: Apple",
initialDate: DateString(Date()),
initialBal: 0.0, favoriteAcct: .boolTrue, currencyId: 1
),
]

static var sampleDataIds : [DataId] {
Expand Down
6 changes: 5 additions & 1 deletion MMEX/Repository/AccountRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ struct AccountRepository: RepositoryProtocol {
static func filterUsed(_ table: SQLite.Table) -> SQLite.Table {
typealias I = InfotableRepository
typealias S = StockRepository
typealias A = AssetRepository
typealias T = TransactionRepository
typealias Q = ScheduledRepository
let cond = "EXISTS (" + (I.table.select(1).where(
I.table[I.col_name] == InfoKey.defaultAccountID.rawValue &&
I.table[I.col_value] == cast(Self.table[Self.col_id]) as SQLite.Expression<String>
) ).union(S.table.select(1).where(
S.table[S.col_accountId] == Self.table[Self.col_id]
S.table[S.col_accountId] == Self.table[Self.col_id] ||
S.table[S.col_name] == Self.table[Self.col_name]
) ).union(A.table.select(1).where(
A.table[A.col_name] == Self.table[Self.col_name]
) ).union(T.table.select(1).where(
T.table[T.col_accountId] == Self.table[Self.col_id]
) ).union(T.table.select(1).where(
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Manage/Repository/RepositoryListView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// RpositoryListView.swift
// RepositoryListView.swift
// MMEX
//
// 2024-10-11: Created by George Ef ([email protected])
Expand Down
4 changes: 3 additions & 1 deletion MMEX/View/Manage/Stock/StockFormView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ struct StockFormView: View {
Text("(none)").tag(DataId.void)
}
ForEach(accountOrder, id: \.self) { id in
Text(accountData[id]?.name ?? "").tag(id)
if let account = accountData[id], account.type == AccountType.investment {
Text(accountData[id]?.name ?? "").tag(id)
}
}
}
}, showView: {
Expand Down