Skip to content

Commit

Permalink
0 for newXxx to represent not set
Browse files Browse the repository at this point in the history
  • Loading branch information
guanlisheng committed Sep 17, 2024
1 parent 2cb5050 commit 91e4f6d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MMEX/Models/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Account {
static let notes = Expression<String?>("NOTES")

static var empty: Account {
Account(id: 0, name: "", type: "", status: AccountStatus.open, favoriteAcct: "TRUE", currencyId: 1, balance: 0.0, notes: "")
Account(id: 0, name: "", type: "", status: AccountStatus.open, favoriteAcct: "TRUE", currencyId: 0, balance: 0.0, notes: "")
}
}
extension Account {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Category {

extension Category {
//
static var empty : Category {Category(id: 1, name: "cateogry name", active: true, parentId: nil)}
static var empty : Category {Category(id: 1, name: "cateogry name", active: true, parentId: 0)}

//
static let table = Table("CATEGORY_V1")
Expand Down
2 changes: 1 addition & 1 deletion MMEX/Models/Payee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Payee {
}

extension Payee {
static var empty: Payee { Payee(id: 0, name: "") }
static var empty: Payee { Payee(id: 0, name: "", categoryId: 0) }

static let table = Table("PAYEE_V1")

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Models/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extension Transaction {
}

extension Transaction {
static var empty: Transaction {Transaction(id: 0, accountID: 1, payeeID: 1, categID:1, transCode: Transcode.withdrawal, status: TransactionStatus.none, transAmount: 0.0, transDate: Date().ISO8601Format())}
static var empty: Transaction {Transaction(id: 0, accountID: 0, payeeID: 0, categID:0, transCode: Transcode.withdrawal, status: TransactionStatus.none, transAmount: 0.0, transDate: Date().ISO8601Format())}
static let sampleData : [Transaction] =
[
Transaction(id: 1, accountID: 1, payeeID: 1, categID:1, transCode: Transcode.withdrawal, status: TransactionStatus.none, transAmount: 10.01, transDate: Date().ISO8601Format()),
Expand Down
1 change: 1 addition & 0 deletions MMEX/Views/AccountEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct AccountEditView: View {
}
Section(header: Text("Currency")) {
Picker("Currency", selection: $account.currencyId) {
Text("Currency").tag(0 as Int64) // not set
ForEach(currencies) { currency in
Text(currency.name).tag(currency.id) // Use currency.name to display and tag by id
}
Expand Down
1 change: 1 addition & 0 deletions MMEX/Views/PayeeEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct PayeeEditView: View {
get: { payee.categoryId ?? 0 }, // Safely unwrap the optional notes field
set: { payee.categoryId = $0 } // Set
)) {
Text("Category").tag(0 as Int64) // not set
ForEach(categories) { category in
Text(category.name).tag(category.id) // Use currency.name to display and tag by id
}
Expand Down
3 changes: 3 additions & 0 deletions MMEX/Views/TransactionEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct TransactionEditView: View {
Spacer()

Picker("Select account", selection: $txn.accountID) {
Text("Account").tag(0 as Int64) // not set
ForEach(accounts) { account in
Text(account.name).tag(account.id)
}
Expand Down Expand Up @@ -100,6 +101,7 @@ struct TransactionEditView: View {
HStack {
// Payee picker
Picker("Select Payee", selection: $txn.payeeID) {
Text("Payee").tag(0 as Int64) // not set
ForEach(payees) { payee in
Text(payee.name).tag(payee.id)
}
Expand All @@ -113,6 +115,7 @@ struct TransactionEditView: View {
get: { txn.categID ?? 0 }, // Safely unwrap the optional notes field
set: { txn.categID = $0 } // Set
)) {
Text("Category").tag(0 as Int64) // not set
ForEach(categories) { category in
Text(category.name).tag(category.id)
}
Expand Down

0 comments on commit 91e4f6d

Please sign in to comment.