Skip to content
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
14 changes: 11 additions & 3 deletions iOSApp/Features/Transactions/TransactionEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct TransactionEditor: View {
@State private var amountString: String
@State private var isNegative: Bool
@State private var selectedPayeeId: String
@State private var selectedTransferId: String?
Comment thread
BearTS marked this conversation as resolved.
@State private var customPayee: String
@State private var payeeMode: PayeeInputMode
@State private var notes: String
Expand Down Expand Up @@ -53,6 +54,7 @@ struct TransactionEditor: View {
_notes = State(initialValue: t.notes ?? "")
_categoryId = State(initialValue: t.category)
_selectedAccountId = State(initialValue: t.account)
_selectedTransferId = State(initialValue: t.transfer_id)
} else {
// Creating a new transaction: Initialize with default values
_date = State(initialValue: Date())
Expand All @@ -64,6 +66,7 @@ struct TransactionEditor: View {
_notes = State(initialValue: "")
_categoryId = State(initialValue: nil)
_selectedAccountId = State(initialValue: initialAccountId ?? "")
_selectedTransferId = State(initialValue: nil)
}
}

Expand Down Expand Up @@ -131,6 +134,9 @@ struct TransactionEditor: View {
Text(payee.name).tag(payee.id)
}
}
.onChange(of: selectedPayeeId) { oldValue, newValue in
selectedTransferId = payees.first(where: { $0.id == newValue })?.transfer_acct
}
Comment thread
anuj-rajput marked this conversation as resolved.
} else {
TextField("Payee Name", text: $customPayee)
}
Expand Down Expand Up @@ -166,7 +172,9 @@ struct TransactionEditor: View {
imported_payee: nil,
category: categoryId,
notes: notes.isEmpty ? nil : notes,
imported_id: nil, transfer_id: nil, cleared: false, subtransactions: nil
imported_id: nil,
transfer_id: selectedTransferId,
cleared: false, subtransactions: nil
)
}

Expand All @@ -177,7 +185,7 @@ struct TransactionEditor: View {
if let id = built.id {
try await client().updateTransaction(transactionId: id, transaction: built)
} else {
try await client().createTransaction(accountId: built.account, transaction: built)
try await client().createTransaction(accountId: built.account, transaction: built, runTransfers: (built.transfer_id != nil))
Comment thread
BearTS marked this conversation as resolved.
}
onSave(built)
dismiss()
Expand Down Expand Up @@ -229,4 +237,4 @@ struct TransactionEditor: View {
private func parseAmountFromDisplay(_ display: String) -> Int {
Int((Double(display.replacingOccurrences(of: ",", with: ".")) ?? 0.0) * 100)
}
}
}
2 changes: 1 addition & 1 deletion iOSApp/Features/Transactions/TransactionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct TransactionsView: View {

private func payeeText(_ tx: Transaction) -> String {
if let account = transferDestinationAccount(tx) {
return "Transfer to: \(account.name)"
return "Transfer \((tx.amount ?? 0) < 0 ? "to" : "from"): \(account.name)"
Comment thread
BearTS marked this conversation as resolved.
}
if let payeeId = tx.payee, let p = payeesById[payeeId] { return p.name }
if let n = tx.payee_name, !n.isEmpty { return n }
Expand Down
2 changes: 1 addition & 1 deletion iOSApp/UI/TransactionRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct TransactionRow: View {

private func primaryText() -> String {
if let account = transferDestinationAccount(transaction) {
return "Transfer to: \(account.name)"
return "Transfer \((transaction.amount ?? 0) < 0 ? "to" : "from"): \(account.name)"
Comment thread
BearTS marked this conversation as resolved.
}
if let payeeId = transaction.payee, let p = payeesById[payeeId] { return p.name }
if let n = transaction.payee_name, !n.isEmpty { return n }
Expand Down