diff --git a/MMEX.xcodeproj/project.pbxproj b/MMEX.xcodeproj/project.pbxproj index f0490ee..52cc92c 100644 --- a/MMEX.xcodeproj/project.pbxproj +++ b/MMEX.xcodeproj/project.pbxproj @@ -18,11 +18,11 @@ 920824042CA4ADC100388AB2 /* ScheduledSplitData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824032CA4ADC100388AB2 /* ScheduledSplitData.swift */; }; 920824062CA4AE0A00388AB2 /* TransactionSplitRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824052CA4AE0A00388AB2 /* TransactionSplitRepository.swift */; }; 920824082CA4B05700388AB2 /* ScheduledSplitRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824072CA4B05700388AB2 /* ScheduledSplitRepository.swift */; }; - 9208240A2CA4C2AD00388AB2 /* BudgetYearData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824092CA4C2AD00388AB2 /* BudgetYearData.swift */; }; - 9208240C2CA4C31B00388AB2 /* BudgetTableData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9208240B2CA4C31B00388AB2 /* BudgetTableData.swift */; }; + 9208240A2CA4C2AD00388AB2 /* YearData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824092CA4C2AD00388AB2 /* YearData.swift */; }; + 9208240C2CA4C31B00388AB2 /* BudgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9208240B2CA4C31B00388AB2 /* BudgetData.swift */; }; 9208240E2CA4C4FA00388AB2 /* ReportData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9208240D2CA4C4FA00388AB2 /* ReportData.swift */; }; - 920824102CA4C5CD00388AB2 /* BudgetYearRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9208240F2CA4C5CD00388AB2 /* BudgetYearRepository.swift */; }; - 920824122CA4C6A400388AB2 /* BudgetTableRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824112CA4C6A400388AB2 /* BudgetTableRepository.swift */; }; + 920824102CA4C5CD00388AB2 /* YearRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9208240F2CA4C5CD00388AB2 /* YearRepository.swift */; }; + 920824122CA4C6A400388AB2 /* BudgetRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824112CA4C6A400388AB2 /* BudgetRepository.swift */; }; 920824162CA4C95F00388AB2 /* ReportRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824152CA4C95F00388AB2 /* ReportRepository.swift */; }; 920824182CA4CF4300388AB2 /* AttachmentData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824172CA4CF4300388AB2 /* AttachmentData.swift */; }; 9208241A2CA4D35700388AB2 /* AttachmentRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824192CA4D35700388AB2 /* AttachmentRepository.swift */; }; @@ -95,6 +95,7 @@ 925EABB62CD6E6EF003CEAB3 /* InfotableList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB52CD6E6EF003CEAB3 /* InfotableList.swift */; }; 925EABB82CD6FAC7003CEAB3 /* TransactionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB72CD6FAC7003CEAB3 /* TransactionList.swift */; }; 925EABBA2CD6FBF7003CEAB3 /* ScheduledList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABB92CD6FBF7003CEAB3 /* ScheduledList.swift */; }; + 925EABBC2CD78A65003CEAB3 /* JournalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925EABBB2CD78A65003CEAB3 /* JournalData.swift */; }; 929EF65F2C9FF2DE0051A3E6 /* AssetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF65E2C9FF2DE0051A3E6 /* AssetData.swift */; }; 929EF6612C9FF2FD0051A3E6 /* StockData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF6602C9FF2FD0051A3E6 /* StockData.swift */; }; 929EF6632C9FF3ED0051A3E6 /* AssetRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 929EF6622C9FF3ED0051A3E6 /* AssetRepository.swift */; }; @@ -174,11 +175,11 @@ 920824032CA4ADC100388AB2 /* ScheduledSplitData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledSplitData.swift; sourceTree = ""; }; 920824052CA4AE0A00388AB2 /* TransactionSplitRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionSplitRepository.swift; sourceTree = ""; }; 920824072CA4B05700388AB2 /* ScheduledSplitRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledSplitRepository.swift; sourceTree = ""; }; - 920824092CA4C2AD00388AB2 /* BudgetYearData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetYearData.swift; sourceTree = ""; }; - 9208240B2CA4C31B00388AB2 /* BudgetTableData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetTableData.swift; sourceTree = ""; }; + 920824092CA4C2AD00388AB2 /* YearData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YearData.swift; sourceTree = ""; }; + 9208240B2CA4C31B00388AB2 /* BudgetData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetData.swift; sourceTree = ""; }; 9208240D2CA4C4FA00388AB2 /* ReportData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportData.swift; sourceTree = ""; }; - 9208240F2CA4C5CD00388AB2 /* BudgetYearRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetYearRepository.swift; sourceTree = ""; }; - 920824112CA4C6A400388AB2 /* BudgetTableRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetTableRepository.swift; sourceTree = ""; }; + 9208240F2CA4C5CD00388AB2 /* YearRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YearRepository.swift; sourceTree = ""; }; + 920824112CA4C6A400388AB2 /* BudgetRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetRepository.swift; sourceTree = ""; }; 920824152CA4C95F00388AB2 /* ReportRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportRepository.swift; sourceTree = ""; }; 920824172CA4CF4300388AB2 /* AttachmentData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentData.swift; sourceTree = ""; }; 920824192CA4D35700388AB2 /* AttachmentRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentRepository.swift; sourceTree = ""; }; @@ -251,6 +252,7 @@ 925EABB52CD6E6EF003CEAB3 /* InfotableList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfotableList.swift; sourceTree = ""; }; 925EABB72CD6FAC7003CEAB3 /* TransactionList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionList.swift; sourceTree = ""; }; 925EABB92CD6FBF7003CEAB3 /* ScheduledList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledList.swift; sourceTree = ""; }; + 925EABBB2CD78A65003CEAB3 /* JournalData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JournalData.swift; sourceTree = ""; }; 929EF65E2C9FF2DE0051A3E6 /* AssetData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetData.swift; sourceTree = ""; }; 929EF6602C9FF2FD0051A3E6 /* StockData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StockData.swift; sourceTree = ""; }; 929EF6622C9FF3ED0051A3E6 /* AssetRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetRepository.swift; sourceTree = ""; }; @@ -617,8 +619,8 @@ 9208242B2CA615B400388AB2 /* FieldRepository.swift */, 9208242D2CA617FB00388AB2 /* FieldContentRepository.swift */, 920824192CA4D35700388AB2 /* AttachmentRepository.swift */, - 9208240F2CA4C5CD00388AB2 /* BudgetYearRepository.swift */, - 920824112CA4C6A400388AB2 /* BudgetTableRepository.swift */, + 9208240F2CA4C5CD00388AB2 /* YearRepository.swift */, + 920824112CA4C6A400388AB2 /* BudgetRepository.swift */, 920824152CA4C95F00388AB2 /* ReportRepository.swift */, ); path = Repository; @@ -701,9 +703,10 @@ 920824272CA60E8400388AB2 /* FieldData.swift */, 920824292CA60FD900388AB2 /* FieldContentData.swift */, 920824172CA4CF4300388AB2 /* AttachmentData.swift */, - 920824092CA4C2AD00388AB2 /* BudgetYearData.swift */, - 9208240B2CA4C31B00388AB2 /* BudgetTableData.swift */, + 920824092CA4C2AD00388AB2 /* YearData.swift */, + 9208240B2CA4C31B00388AB2 /* BudgetData.swift */, 9208240D2CA4C4FA00388AB2 /* ReportData.swift */, + 925EABBB2CD78A65003CEAB3 /* JournalData.swift */, ); path = Data; sourceTree = ""; @@ -892,7 +895,7 @@ 924353492CCD36890052E4BC /* CurrencyList.swift in Sources */, 924352FA2CB355CF0052E4BC /* SettingsThemeView.swift in Sources */, 925EABAC2CCF826F003CEAB3 /* CategoryValidation.swift in Sources */, - 9208240A2CA4C2AD00388AB2 /* BudgetYearData.swift in Sources */, + 9208240A2CA4C2AD00388AB2 /* YearData.swift in Sources */, 924353392CCD2F310052E4BC /* CurrencySearch.swift in Sources */, 9243533B2CCD2F610052E4BC /* AccountSearch.swift in Sources */, A3363EEB2C93BF62004696C7 /* CurrencyRepository.swift in Sources */, @@ -904,6 +907,7 @@ 9208242E2CA617FB00388AB2 /* FieldContentRepository.swift in Sources */, 9208241E2CA4E1C500388AB2 /* TransactionLinkRepository.swift in Sources */, 9208241A2CA4D35700388AB2 /* AttachmentRepository.swift in Sources */, + 925EABBC2CD78A65003CEAB3 /* JournalData.swift in Sources */, 925EABA82CCF81FF003CEAB3 /* AssetValidation.swift in Sources */, 925EAB932CCD7386003CEAB3 /* RepositoryCreateView.swift in Sources */, A37E7D882C9AC2E600B4ECFC /* VersionInfoView.swift in Sources */, @@ -911,7 +915,7 @@ 9208242A2CA60FD900388AB2 /* FieldContentData.swift in Sources */, A3462F662C94854800F79145 /* ExportableEntity.swift in Sources */, A3462F6A2C948CDB00F79145 /* ExportableEntityDocument.swift in Sources */, - 920824122CA4C6A400388AB2 /* BudgetTableRepository.swift in Sources */, + 920824122CA4C6A400388AB2 /* BudgetRepository.swift in Sources */, A3C142982C8FE62200D3CEC0 /* TransactionListView.swift in Sources */, 9243533D2CCD2F990052E4BC /* AssetSearch.swift in Sources */, A33742882CA8E55400698466 /* IncomeExpenseView.swift in Sources */, @@ -930,7 +934,7 @@ 920824022CA4AD0C00388AB2 /* TransactionSplitData.swift in Sources */, 924353172CC51F8E0052E4BC /* StockReload.swift in Sources */, A3363EE32C9323A5004696C7 /* CategoryEditView.swift in Sources */, - 920824102CA4C5CD00388AB2 /* BudgetYearRepository.swift in Sources */, + 920824102CA4C5CD00388AB2 /* YearRepository.swift in Sources */, 925EABB62CD6E6EF003CEAB3 /* InfotableList.swift in Sources */, 920824202CA4E5C200388AB2 /* TagLinkData.swift in Sources */, A3C142652C8ED8EA00D3CEC0 /* AccountEditView.swift in Sources */, @@ -942,7 +946,7 @@ 9243531D2CC5201C0052E4BC /* ManageList.swift in Sources */, A3C142A22C90267F00D3CEC0 /* CategoryRepository.swift in Sources */, A37E7D862C9AC2D000B4ECFC /* AboutView.swift in Sources */, - 9208240C2CA4C31B00388AB2 /* BudgetTableData.swift in Sources */, + 9208240C2CA4C31B00388AB2 /* BudgetData.swift in Sources */, 924353472CCD353A0052E4BC /* ListProtocol.swift in Sources */, A3363EE92C9326A1004696C7 /* CategoryListView.swift in Sources */, A3C142A02C9025D600D3CEC0 /* CategoryData.swift in Sources */, diff --git a/MMEX/Data/AccountData.swift b/MMEX/Data/AccountData.swift index a5e974a..cccfe84 100644 --- a/MMEX/Data/AccountData.swift +++ b/MMEX/Data/AccountData.swift @@ -1,5 +1,5 @@ // -// Account.swift +// AccountData.swift // MMEX // // Created by Lisheng Guan on 2024/9/5. diff --git a/MMEX/Data/AssetData.swift b/MMEX/Data/AssetData.swift index 6bd9a59..289b974 100644 --- a/MMEX/Data/AssetData.swift +++ b/MMEX/Data/AssetData.swift @@ -1,5 +1,5 @@ // -// Asset.swift +// AssetData.swift // MMEX // // Created 2024-09-22 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/AttachmentData.swift b/MMEX/Data/AttachmentData.swift index b86eb34..83c3ab8 100644 --- a/MMEX/Data/AttachmentData.swift +++ b/MMEX/Data/AttachmentData.swift @@ -1,5 +1,5 @@ // -// Attachment.swift +// AttachmentData.swift // MMEX // // Created 2024-09-26 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/BudgetTableData.swift b/MMEX/Data/BudgetData.swift similarity index 72% rename from MMEX/Data/BudgetTableData.swift rename to MMEX/Data/BudgetData.swift index 152541b..8e181c9 100644 --- a/MMEX/Data/BudgetTableData.swift +++ b/MMEX/Data/BudgetData.swift @@ -1,8 +1,8 @@ // -// BudgetTable.swift +// BudgetData.swift // MMEX // -// Created 2024-09-26 by George Ef (george.a.ef@gmail.com) +// 2024-09-26: Created by George Ef (george.a.ef@gmail.com) // import Foundation @@ -21,7 +21,7 @@ enum BudgetPeriod: String, EnumCollateNoCase { static let defaultValue = Self.none } -struct BudgetTableData: ExportableEntity { +struct BudgetData: ExportableEntity { var id : DataId = .void var yearId : DataId = .void var categId : DataId = .void @@ -31,15 +31,15 @@ struct BudgetTableData: ExportableEntity { var active : Bool = false } -extension BudgetTableData: DataProtocol { - static let dataName = ("Budget Table", "Budget Tables") +extension BudgetData: DataProtocol { + static let dataName = ("Budget", "Budget") func shortDesc() -> String { "#\(self.id.value)" } } -extension BudgetTableData { - static let sampleData: [BudgetTableData] = [ +extension BudgetData { + static let sampleData: [BudgetData] = [ ] } diff --git a/MMEX/Data/CategoryData.swift b/MMEX/Data/CategoryData.swift index c70a2bd..0b17b6d 100644 --- a/MMEX/Data/CategoryData.swift +++ b/MMEX/Data/CategoryData.swift @@ -1,5 +1,5 @@ // -// Category.swift +// CategoryData.swift // MMEX // // Created by Lisheng Guan on 2024/9/10. diff --git a/MMEX/Data/CurrencyData.swift b/MMEX/Data/CurrencyData.swift index 939d27e..737decc 100644 --- a/MMEX/Data/CurrencyData.swift +++ b/MMEX/Data/CurrencyData.swift @@ -1,5 +1,5 @@ // -// Currency.swift +// CurrencyData.swift // MMEX // // Created by Lisheng Guan on 2024/9/6. diff --git a/MMEX/Data/CurrencyHistoryData.swift b/MMEX/Data/CurrencyHistoryData.swift index 4f4650a..94f5c1d 100644 --- a/MMEX/Data/CurrencyHistoryData.swift +++ b/MMEX/Data/CurrencyHistoryData.swift @@ -1,5 +1,5 @@ // -// CurrencyHistory.swift +// CurrencyHistoryData.swift // MMEX // // Created 2024-09-25 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/FieldData.swift b/MMEX/Data/FieldData.swift index bd9d57c..99fa071 100644 --- a/MMEX/Data/FieldData.swift +++ b/MMEX/Data/FieldData.swift @@ -1,5 +1,5 @@ // -// Field.swift +// FieldData.swift // MMEX // // Created 2024-09-26 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/InfotableData.swift b/MMEX/Data/InfotableData.swift index 837757d..1118d6e 100644 --- a/MMEX/Data/InfotableData.swift +++ b/MMEX/Data/InfotableData.swift @@ -1,5 +1,5 @@ // -// Infotable.swift +// InfotableData.swift // MMEX // // Created by Lisheng Guan on 2024/9/18. diff --git a/MMEX/Data/JournalData.swift b/MMEX/Data/JournalData.swift new file mode 100644 index 0000000..4bc3113 --- /dev/null +++ b/MMEX/Data/JournalData.swift @@ -0,0 +1,184 @@ +// +// JournalData.swift +// MMEX +// +// 2024-11-03: Created by George Ef (george.a.ef@gmail.com) +// + +import Foundation + +// JournalData represents one of the following: +// * an already executed transaction (similar to TransactionData) +// * a future execution of a scheduled transaction (similar to TransactionData) +// * a scheduled transaction (similar to ScheduledData) +// +// For easier access to fields, the data structure is flattened, i.e., +// there are no associated enum values. + +enum JournalType: Int, CaseIterable, Identifiable, Codable { + case transaction = 0 + case future + case scheduled + static let defaultValue = Self.transaction + + static let names = [ + "Transaction", + "Future", + "Scheduled" + ] + var id: Int { self.rawValue } + var name: String { Self.names[self.rawValue] } +} + +struct JournalData { + // type == .transaction: + // transactionId : same as TransactionData.id + // scheduledId = .void + // sequence = 0 + // type == .future + // transactionId = .void + // scheduledId : same as ScheduledData.id of the original scheduled transaction + // sequence > 0 (1 represents the first future execution) + // type == .scheduled + // transactionId = .void + // scheduledId : same as ScheduledData.id + // sequence = 0 + var type : JournalType = .defaultValue + var transactionId : DataId = .void + var scheduledId : DataId = .void + var sequence : Int = 0 + + // common fields for all types + var accountId : DataId = .void + var toAccountId : DataId = .void + var payeeId : DataId = .void + var transCode : TransactionType = TransactionType.defaultValue + var transAmount : Double = 0.0 + var status : TransactionStatus = TransactionStatus.defaultValue + var transactionNumber : String = "" + var notes : String = "" + var categId : DataId = .void + var transDate : DateTimeString = DateTimeString("") + var followUpId : Int64 = 0 + var toTransAmount : Double = 0.0 + var color : Int64 = 0 + + // applicable for type == .transaction + var lastUpdatedTime : DateTimeString = DateTimeString("") + var deletedTime : DateTimeString = DateTimeString("") + + // applicable for type == .scheduled + var dueDate : DateString = DateString("") + var repeatAuto : RepeatAuto = RepeatAuto.defaultValue + var repeatType : RepeatType = RepeatType.defaultValue + var repeatNum : Int = 0 +} + +extension JournalData { + init(_ data: TransactionData) { + self.type = .transaction + self.transactionId = data.id + self.accountId = data.accountId + self.toAccountId = data.toAccountId + self.payeeId = data.payeeId + self.transCode = data.transCode + self.transAmount = data.transAmount + self.status = data.status + self.transactionNumber = data.transactionNumber + self.notes = data.notes + self.categId = data.categId + self.transDate = data.transDate + self.followUpId = data.followUpId + self.toTransAmount = data.toTransAmount + self.color = data.color + self.lastUpdatedTime = data.lastUpdatedTime + self.deletedTime = data.deletedTime + } + + init(_ data: ScheduledData, sequence: Int, at transDate: DateTimeString) { + self.type = .future + self.scheduledId = data.id + self.sequence = sequence + self.accountId = data.accountId + self.toAccountId = data.toAccountId + self.payeeId = data.payeeId + self.transCode = data.transCode + self.transAmount = data.transAmount + self.status = data.status + self.transactionNumber = data.transactionNumber + self.notes = data.notes + self.categId = data.categId + self.transDate = transDate + self.followUpId = data.followUpId + self.toTransAmount = data.toTransAmount + self.color = data.color + } + + init(_ data: ScheduledData) { + self.type = .scheduled + self.scheduledId = data.id + self.accountId = data.accountId + self.toAccountId = data.toAccountId + self.payeeId = data.payeeId + self.transCode = data.transCode + self.transAmount = data.transAmount + self.status = data.status + self.transactionNumber = data.transactionNumber + self.notes = data.notes + self.categId = data.categId + self.transDate = data.transDate + self.followUpId = data.followUpId + self.toTransAmount = data.toTransAmount + self.color = data.color + self.dueDate = data.dueDate + self.repeatAuto = data.repeatAuto + self.repeatType = data.repeatType + self.repeatNum = data.repeatNum + } +} + +extension JournalData { + var toTransaction: TransactionData? { + type == .transaction || type == .future ? TransactionData( + id : transactionId, + accountId : accountId, + toAccountId : toAccountId, + payeeId : payeeId, + transCode : transCode, + transAmount : transAmount, + status : status, + transactionNumber : transactionNumber, + notes : notes, + categId : categId, + transDate : transDate, + lastUpdatedTime : lastUpdatedTime, + deletedTime : deletedTime, + followUpId : followUpId, + toTransAmount : toTransAmount, + color : color + ) : nil + } + + var toScheduled: ScheduledData? { + type == .scheduled ? ScheduledData( + id : scheduledId, + accountId : accountId, + toAccountId : toAccountId, + payeeId : payeeId, + transCode : transCode, + transAmount : transAmount, + status : status, + transactionNumber : transactionNumber, + notes : notes, + categId : categId, + transDate : transDate, + followUpId : followUpId, + toTransAmount : toTransAmount, + dueDate : dueDate, + repeatAuto : repeatAuto, + repeatType : repeatType, + repeatNum : repeatNum, + color : color + ) : nil + } +} diff --git a/MMEX/Data/PayeeData.swift b/MMEX/Data/PayeeData.swift index 77dd652..0ee489e 100644 --- a/MMEX/Data/PayeeData.swift +++ b/MMEX/Data/PayeeData.swift @@ -1,5 +1,5 @@ // -// Payee.swift +// PayeeData.swift // MMEX // // Created by Lisheng Guan on 2024/9/6. diff --git a/MMEX/Data/ReportData.swift b/MMEX/Data/ReportData.swift index 7bc6a85..0e1c137 100644 --- a/MMEX/Data/ReportData.swift +++ b/MMEX/Data/ReportData.swift @@ -1,5 +1,5 @@ // -// Report.swift +// ReportData.swift // MMEX // // Created 2024-09-26 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/ScheduledData.swift b/MMEX/Data/ScheduledData.swift index 75b69a7..4191eac 100644 --- a/MMEX/Data/ScheduledData.swift +++ b/MMEX/Data/ScheduledData.swift @@ -1,12 +1,12 @@ // -// Scheduled.swift +// ScheduledData.swift // MMEX // // Created 2024-09-22 by George Ef (george.a.ef@gmail.com) // -import SQLite import Foundation +import SQLite enum RepeatAuto: Int, CaseIterable, Identifiable, Codable { case none = 0 diff --git a/MMEX/Data/ScheduledSplitData.swift b/MMEX/Data/ScheduledSplitData.swift index 6cfd8d9..fdb4208 100644 --- a/MMEX/Data/ScheduledSplitData.swift +++ b/MMEX/Data/ScheduledSplitData.swift @@ -1,5 +1,5 @@ // -// ScheduledSplit.swift +// ScheduledSplitData.swift // MMEX // // Created 2024-09-25 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/StockData.swift b/MMEX/Data/StockData.swift index fa6cee7..c06a365 100644 --- a/MMEX/Data/StockData.swift +++ b/MMEX/Data/StockData.swift @@ -1,5 +1,5 @@ // -// Stock.swift +// StockData.swift // MMEX // // Created 2024-09-22 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/StockHistoryData.swift b/MMEX/Data/StockHistoryData.swift index 79081ab..dd2fb3f 100644 --- a/MMEX/Data/StockHistoryData.swift +++ b/MMEX/Data/StockHistoryData.swift @@ -1,5 +1,5 @@ // -// StockHistory.swift +// StockHistoryData.swift // MMEX // // Created 2024-09-25 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/TagData.swift b/MMEX/Data/TagData.swift index 108f5f8..51bf15f 100644 --- a/MMEX/Data/TagData.swift +++ b/MMEX/Data/TagData.swift @@ -1,5 +1,5 @@ // -// Tag.swift +// TagData.swift // MMEX // // Created 2024-09-25 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/TransactionData.swift b/MMEX/Data/TransactionData.swift index bc135bd..a9db664 100644 --- a/MMEX/Data/TransactionData.swift +++ b/MMEX/Data/TransactionData.swift @@ -1,12 +1,12 @@ // -// Transaction.swift +// TransactionData.swift // MMEX // // Created by Lisheng Guan on 2024/9/9. // -import SQLite import Foundation +import SQLite enum TransactionType: String, EnumCollateNoCase { case withdrawal = "Withdrawal" diff --git a/MMEX/Data/TransactionShareData.swift b/MMEX/Data/TransactionShareData.swift index f6759fa..898c683 100644 --- a/MMEX/Data/TransactionShareData.swift +++ b/MMEX/Data/TransactionShareData.swift @@ -1,5 +1,5 @@ // -// TransactionShare.swift +// TransactionShareData.swift // MMEX // // Created 2024-09-26 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/TransactionSplitData.swift b/MMEX/Data/TransactionSplitData.swift index ab0b0ca..d2ca921 100644 --- a/MMEX/Data/TransactionSplitData.swift +++ b/MMEX/Data/TransactionSplitData.swift @@ -1,5 +1,5 @@ // -// TransactionSplit.swift +// TransactionSplitData.swift // MMEX // // Created 2024-09-25 by George Ef (george.a.ef@gmail.com) diff --git a/MMEX/Data/BudgetYearData.swift b/MMEX/Data/YearData.swift similarity index 50% rename from MMEX/Data/BudgetYearData.swift rename to MMEX/Data/YearData.swift index b3b2986..0ca2874 100644 --- a/MMEX/Data/BudgetYearData.swift +++ b/MMEX/Data/YearData.swift @@ -1,19 +1,19 @@ // -// BudgetYear.swift +// YearData.swift // MMEX // -// Created 2024-09-26 by George Ef (george.a.ef@gmail.com) +// 2024-09-26: Created by George Ef (george.a.ef@gmail.com) // import Foundation import SQLite -struct BudgetYearData: ExportableEntity { +struct YearData: ExportableEntity { var id : DataId = .void var name : String = "" } -extension BudgetYearData: DataProtocol { +extension YearData: DataProtocol { static let dataName = ("Budget Year", "Budget Years") func shortDesc() -> String { @@ -21,7 +21,7 @@ extension BudgetYearData: DataProtocol { } } -extension BudgetYearData { - static let sampleData: [BudgetYearData] = [ +extension YearData { + static let sampleData: [YearData] = [ ] } diff --git a/MMEX/Repository/BudgetTableRepository.swift b/MMEX/Repository/BudgetRepository.swift similarity index 83% rename from MMEX/Repository/BudgetTableRepository.swift rename to MMEX/Repository/BudgetRepository.swift index 43e3bdb..0670d8b 100644 --- a/MMEX/Repository/BudgetTableRepository.swift +++ b/MMEX/Repository/BudgetRepository.swift @@ -1,15 +1,15 @@ // -// BudgetTableRepository.swift +// BudgetRepository.swift // MMEX // -// Created 2024-09-26 by George Ef (george.a.ef@gmail.com) +// 2024-09-26: Created by George Ef (george.a.ef@gmail.com) // import Foundation import SQLite -struct BudgetTableRepository: RepositoryProtocol { - typealias RepositoryData = BudgetTableData +struct BudgetRepository: RepositoryProtocol { + typealias RepositoryData = BudgetData let db: Connection @@ -50,8 +50,8 @@ struct BudgetTableRepository: RepositoryProtocol { ) } - static func fetchData(_ row: SQLite.Row) -> BudgetTableData { - return BudgetTableData( + static func fetchData(_ row: SQLite.Row) -> BudgetData { + return BudgetData( id : DataId(row[col_id]), yearId : DataId(row[col_yearId] ?? -1), categId : DataId(row[col_categId] ?? -1), @@ -62,7 +62,7 @@ struct BudgetTableRepository: RepositoryProtocol { ) } - static func itemSetters(_ data: BudgetTableData) -> [SQLite.Setter] { + static func itemSetters(_ data: BudgetData) -> [SQLite.Setter] { return [ col_yearId <- Int64(data.yearId), col_categId <- Int64(data.categId), @@ -74,9 +74,9 @@ struct BudgetTableRepository: RepositoryProtocol { } } -extension BudgetTableRepository { +extension BudgetRepository { // load all budget tables - func load() -> [BudgetTableData]? { + func load() -> [BudgetData]? { return select(from: Self.table .order(Self.col_id) ) diff --git a/MMEX/Repository/CategoryRepository.swift b/MMEX/Repository/CategoryRepository.swift index 2fdd502..9e1023e 100644 --- a/MMEX/Repository/CategoryRepository.swift +++ b/MMEX/Repository/CategoryRepository.swift @@ -62,7 +62,7 @@ struct CategoryRepository: RepositoryProtocol { typealias TP = TransactionSplitRepository typealias R = ScheduledRepository typealias RP = ScheduledSplitRepository - typealias B = BudgetTableRepository + typealias B = BudgetRepository let CP_table: SQLite.Table = C.table.alias("Parent") // problem: compiler cannot determine the type with too many union terms diff --git a/MMEX/Repository/Repository.swift b/MMEX/Repository/Repository.swift index 7aa2ab2..c7c8c07 100644 --- a/MMEX/Repository/Repository.swift +++ b/MMEX/Repository/Repository.swift @@ -392,9 +392,9 @@ extension Repository { var budgetYearMap: [DataId: DataId] = [:] do { - let repo = BudgetYearRepository(db) + let repo = YearRepository(db) guard repo.deleteAll() else { return false } - for var data in BudgetYearData.sampleData { + for var data in YearData.sampleData { let id = data.id guard repo.insert(&data) else { return false } budgetYearMap[id] = data.id @@ -403,9 +403,9 @@ extension Repository { var budgetTableMap: [DataId: DataId] = [:] do { - let repo = BudgetTableRepository(db) + let repo = BudgetRepository(db) guard repo.deleteAll() else { return false } - for var data in BudgetTableData.sampleData { + for var data in BudgetData.sampleData { let id = data.id data.yearId = budgetYearMap[data.yearId] ?? data.yearId data.categId = categoryMap[data.categId] ?? data.categId diff --git a/MMEX/Repository/BudgetYearRepository.swift b/MMEX/Repository/YearRepository.swift similarity index 76% rename from MMEX/Repository/BudgetYearRepository.swift rename to MMEX/Repository/YearRepository.swift index 1260e5d..a02f6c5 100644 --- a/MMEX/Repository/BudgetYearRepository.swift +++ b/MMEX/Repository/YearRepository.swift @@ -1,5 +1,5 @@ // -// BudgetYearRepository.swift +// YearRepository.swift // MMEX // // Created 2024-09-26 by George Ef (george.a.ef@gmail.com) @@ -8,8 +8,8 @@ import Foundation import SQLite -struct BudgetYearRepository: RepositoryProtocol { - typealias RepositoryData = BudgetYearData +struct YearRepository: RepositoryProtocol { + typealias RepositoryData = YearData let db: Connection @@ -32,21 +32,21 @@ struct BudgetYearRepository: RepositoryProtocol { ) } - static func fetchData(_ row: SQLite.Row) -> BudgetYearData { - return BudgetYearData( + static func fetchData(_ row: SQLite.Row) -> YearData { + return YearData( id : DataId(row[col_id]), name : row[col_name] ) } - static func itemSetters(_ data: BudgetYearData) -> [SQLite.Setter] { + static func itemSetters(_ data: YearData) -> [SQLite.Setter] { return [ col_name <- data.name ] } static func filterUsed(_ table: SQLite.Table) -> SQLite.Table { - typealias B = BudgetTableRepository + typealias B = BudgetRepository let cond = "EXISTS (" + (B.table.select(1).where( B.table[B.col_yearId] == Self.table[Self.col_id] ) ).expression.description + ")" @@ -54,9 +54,9 @@ struct BudgetYearRepository: RepositoryProtocol { } } -extension BudgetYearRepository { +extension YearRepository { // load all budget years - func load() -> [BudgetYearData]? { + func load() -> [YearData]? { return select(from: Self.table .order(Self.col_name) ) diff --git a/MMEX/View/Journal/JournalView.swift b/MMEX/View/Journal/JournalView.swift index 788ecbc..5affa41 100644 --- a/MMEX/View/Journal/JournalView.swift +++ b/MMEX/View/Journal/JournalView.swift @@ -68,11 +68,10 @@ struct JournalView: View { viewModel.filterTransactions(by: query) } } - .onAppear { - Task { - await vm.loadTransactionList() - accountId = (vm.infotableList.defaultAccountId.readyValue ?? nil) ?? DataId.void - } + .task { + log.debug("DEBUG: JournalView.onAppear(main=\(Thread.isMainThread))") + await vm.loadTransactionList() + accountId = (vm.infotableList.defaultAccountId.readyValue ?? nil) ?? DataId.void viewModel.loadTransactions(for: accountId) viewModel.loadAccounts() viewModel.loadCategories() diff --git a/MMEX/ViewModel/ViewModel.swift b/MMEX/ViewModel/ViewModel.swift index 28b1349..2c0dc1f 100644 --- a/MMEX/ViewModel/ViewModel.swift +++ b/MMEX/ViewModel/ViewModel.swift @@ -61,8 +61,8 @@ class ViewModel: ObservableObject { typealias F = FieldRepository typealias FD = FieldContentRepository typealias AX = AttachmentRepository - typealias Y = BudgetYearRepository - typealias B = BudgetTableRepository + typealias Y = YearRepository + typealias B = BudgetRepository typealias O = ReportRepository @Published var manageList: LoadState = .init()