Skip to content

Commit

Permalink
Merge pull request #45 from moneymanagerex/new_models-4
Browse files Browse the repository at this point in the history
Add BudgetYear, BudgetTable, Report
  • Loading branch information
georgeef authored Sep 25, 2024
2 parents 8971366 + 6a92629 commit 8362139
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 0 deletions.
24 changes: 24 additions & 0 deletions MMEX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
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 */; };
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 */; };
920824162CA4C95F00388AB2 /* ReportRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920824152CA4C95F00388AB2 /* ReportRepository.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 */; };
Expand Down Expand Up @@ -102,6 +108,12 @@
920824032CA4ADC100388AB2 /* ScheduledSplitData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledSplitData.swift; sourceTree = "<group>"; };
920824052CA4AE0A00388AB2 /* TransactionSplitRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionSplitRepository.swift; sourceTree = "<group>"; };
920824072CA4B05700388AB2 /* ScheduledSplitRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledSplitRepository.swift; sourceTree = "<group>"; };
920824092CA4C2AD00388AB2 /* BudgetYearData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetYearData.swift; sourceTree = "<group>"; };
9208240B2CA4C31B00388AB2 /* BudgetTableData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetTableData.swift; sourceTree = "<group>"; };
9208240D2CA4C4FA00388AB2 /* ReportData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportData.swift; sourceTree = "<group>"; };
9208240F2CA4C5CD00388AB2 /* BudgetYearRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetYearRepository.swift; sourceTree = "<group>"; };
920824112CA4C6A400388AB2 /* BudgetTableRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BudgetTableRepository.swift; sourceTree = "<group>"; };
920824152CA4C95F00388AB2 /* ReportRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportRepository.swift; sourceTree = "<group>"; };
929EF65E2C9FF2DE0051A3E6 /* AssetData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetData.swift; sourceTree = "<group>"; };
929EF6602C9FF2FD0051A3E6 /* StockData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StockData.swift; sourceTree = "<group>"; };
929EF6622C9FF3ED0051A3E6 /* AssetRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssetRepository.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,6 +333,9 @@
920824052CA4AE0A00388AB2 /* TransactionSplitRepository.swift */,
929EF66E2CA0BC2D0051A3E6 /* ScheduledRepository.swift */,
920824072CA4B05700388AB2 /* ScheduledSplitRepository.swift */,
9208240F2CA4C5CD00388AB2 /* BudgetYearRepository.swift */,
920824112CA4C6A400388AB2 /* BudgetTableRepository.swift */,
920824152CA4C95F00388AB2 /* ReportRepository.swift */,
);
path = Repositories;
sourceTree = "<group>";
Expand Down Expand Up @@ -388,6 +403,9 @@
920824012CA4AD0C00388AB2 /* TransactionSplitData.swift */,
929EF66C2CA0BA5E0051A3E6 /* ScheduledData.swift */,
920824032CA4ADC100388AB2 /* ScheduledSplitData.swift */,
920824092CA4C2AD00388AB2 /* BudgetYearData.swift */,
9208240B2CA4C31B00388AB2 /* BudgetTableData.swift */,
9208240D2CA4C4FA00388AB2 /* ReportData.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -506,6 +524,7 @@
929EF6612C9FF2FD0051A3E6 /* StockData.swift in Sources */,
A39B1B322C99A084003E5562 /* CurrencyAddView.swift in Sources */,
A37E7D922C9AC60000B4ECFC /* ContactSupportView.swift in Sources */,
9208240E2CA4C4FA00388AB2 /* ReportData.swift in Sources */,
929EF6652C9FF3FB0051A3E6 /* StockRepository.swift in Sources */,
A3C142502C8B366400D3CEC0 /* PayeeListView.swift in Sources */,
A379C1A72CA3B79E00CC8E2C /* AssetAddView.swift in Sources */,
Expand Down Expand Up @@ -538,31 +557,36 @@
A3C142442C89C8FA00D3CEC0 /* AccountData.swift in Sources */,
A3C142AE2C9134DD00D3CEC0 /* InsightsView.swift in Sources */,
A3C142A82C906E0A00D3CEC0 /* CustomNumberPadView.swift in Sources */,
9208240A2CA4C2AD00388AB2 /* BudgetYearData.swift in Sources */,
A3363EEB2C93BF62004696C7 /* CurrencyRepository.swift in Sources */,
A37E7D942C9B217500B4ECFC /* InfotableData.swift in Sources */,
A37E7D882C9AC2E600B4ECFC /* VersionInfoView.swift in Sources */,
920823F62CA498A200388AB2 /* CurrencyHistoryData.swift in Sources */,
A3462F662C94854800F79145 /* ExportableEntity.swift in Sources */,
A3462F6A2C948CDB00F79145 /* ExportableEntityDocument.swift in Sources */,
920824122CA4C6A400388AB2 /* BudgetTableRepository.swift in Sources */,
A3C142982C8FE62200D3CEC0 /* TransactionListView.swift in Sources */,
A3C142542C8B381400D3CEC0 /* PayeeEditView.swift in Sources */,
920823F82CA498B500388AB2 /* CurrencyHistoryRepository.swift in Sources */,
A37E7D8A2C9AC30700B4ECFC /* HelpFAQView.swift in Sources */,
929EF66D2CA0BA5E0051A3E6 /* ScheduledData.swift in Sources */,
920824022CA4AD0C00388AB2 /* TransactionSplitData.swift in Sources */,
A3363EE32C9323A5004696C7 /* CategoryEditView.swift in Sources */,
920824102CA4C5CD00388AB2 /* BudgetYearRepository.swift in Sources */,
A3C142652C8ED8EA00D3CEC0 /* AccountEditView.swift in Sources */,
A3C142632C8ED8C000D3CEC0 /* AccountAddView.swift in Sources */,
929EF6712CA3676B0051A3E6 /* MMEXDocument.swift in Sources */,
929EF6692CA034770051A3E6 /* Repository.swift in Sources */,
A3C142A22C90267F00D3CEC0 /* CategoryRepository.swift in Sources */,
A37E7D862C9AC2D000B4ECFC /* AboutView.swift in Sources */,
9208240C2CA4C31B00388AB2 /* BudgetTableData.swift in Sources */,
A3363EE92C9326A1004696C7 /* CategoryListView.swift in Sources */,
A3C142A02C9025D600D3CEC0 /* CategoryData.swift in Sources */,
A3C142A42C9033E300D3CEC0 /* SettingsView.swift in Sources */,
A3363EE52C9323D2004696C7 /* CategoryDetailView.swift in Sources */,
929EF66F2CA0BC2D0051A3E6 /* ScheduledRepository.swift in Sources */,
A37E7D842C9AC14800B4ECFC /* ManagementView.swift in Sources */,
920824162CA4C95F00388AB2 /* ReportRepository.swift in Sources */,
A37E7D902C9AC4F300B4ECFC /* TermsOfServiceView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
45 changes: 45 additions & 0 deletions MMEX/Models/BudgetTableData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// BudgetTable.swift
// MMEX
//
// Created 2024-09-26 by George Ef ([email protected])
//

import Foundation
import SQLite

enum Period: String, EnumCollateNoCase {
case none = "None"
case weekly = "Weekly"
case biweekly = "Fortnightly"
case monthly = "Monthly"
case bimonthly = "Every 2 Months"
case quarterly = "Quarterly"
case halfyearly = "Half-Yearly"
case yearly = "Yearly"
case daily = "Daily"
static let defaultValue = Self.none
}

struct BudgetTableData: ExportableEntity {
var id : Int64 = 0
var yearId : Int64 = 0
var categId : Int64 = 0
var period : Period = Period.defaultValue
var amount : Double = 0.0
var notes : String = ""
var active : Bool = false
}

extension BudgetTableData: DataProtocol {
static let dataName = "BudgetTable"

func shortDesc() -> String {
"\(self.id)"
}
}

extension BudgetTableData {
static let sampleData: [BudgetTableData] = [
]
}
27 changes: 27 additions & 0 deletions MMEX/Models/BudgetYearData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// BudgetYear.swift
// MMEX
//
// Created 2024-09-26 by George Ef ([email protected])
//

import Foundation
import SQLite

struct BudgetYearData: ExportableEntity {
var id : Int64 = 0
var name : String = ""
}

extension BudgetYearData: DataProtocol {
static let dataName = "BudgetYear"

func shortDesc() -> String {
"\(self.name)"
}
}

extension BudgetYearData {
static let sampleData: [BudgetYearData] = [
]
}
33 changes: 33 additions & 0 deletions MMEX/Models/ReportData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Report.swift
// MMEX
//
// Created 2024-09-26 by George Ef ([email protected])
//

import Foundation
import SQLite

struct ReportData: ExportableEntity {
var id : Int64 = 0
var name : String = ""
var groupName : String = ""
var active : Bool = false
var sqlContent : String = ""
var luaContent : String = ""
var templateContent : String = ""
var description : String = ""
}

extension ReportData: DataProtocol {
static let dataName = "Report"

func shortDesc() -> String {
"\(self.name)"
}
}

extension ReportData {
static let sampleData: [ReportData] = [
]
}
87 changes: 87 additions & 0 deletions MMEX/Repositories/BudgetTableRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// BudgetTableRepository.swift
// MMEX
//
// Created 2024-09-26 by George Ef ([email protected])
//

import Foundation
import SQLite

class BudgetTableRepository: RepositoryProtocol {
typealias RepositoryData = BudgetTableData

let db: Connection?
init(db: Connection?) {
self.db = db
}

static let repositoryName = "BUDGETTABLE_V1"
static let table = SQLite.Table(repositoryName)

// column | type | other
// --------------+---------+------
// BUDGETENTRYID | INTEGER | PRIMARY KEY
// BUDGETYEARID | INTEGER |
// CATEGID | INTEGER |
// PERIOD | TEXT | NOT NULL (None, Weekly, Bi-Weekly, Monthly, ...)
// AMOUNT | NUMERIC | NOT NULL
// NOTES | TEXT |
// ACTIVE | INTEGER |

// column expressions
static let col_id = SQLite.Expression<Int64>("BUDGETENTRYID")
static let col_yearId = SQLite.Expression<Int64?>("BUDGETYEARID")
static let col_categId = SQLite.Expression<Int64?>("CATEGID")
static let col_period = SQLite.Expression<String>("PERIOD")
static let col_amount = SQLite.Expression<Double>("AMOUNT")
static let col_notes = SQLite.Expression<String?>("NOTES")
static let col_active = SQLite.Expression<Int?>("ACTIVE")

// cast NUMERIC to REAL
static let cast_amount = cast(col_amount) as SQLite.Expression<Double>

static func selectQuery(from table: SQLite.Table) -> SQLite.Table {
return table.select(
col_id,
col_yearId,
col_categId,
col_period,
cast_amount,
col_notes,
col_active
)
}

static func selectData(_ row: SQLite.Row) -> BudgetTableData {
return BudgetTableData(
id : row[col_id],
yearId : row[col_yearId] ?? -1,
categId : row[col_categId] ?? -1,
period : Period(collateNoCase: row[col_period]),
amount : row[cast_amount],
notes : row[col_notes] ?? "",
active : row[col_active] ?? 0 != 0
)
}

static func itemSetters(_ budget: BudgetTableData) -> [SQLite.Setter] {
return [
col_yearId <- budget.yearId,
col_categId <- budget.categId,
col_period <- budget.period.rawValue,
col_amount <- budget.amount,
col_notes <- budget.notes,
col_active <- budget.active ? 1 : 0
]
}
}

extension BudgetTableRepository {
// load all budget tables
func load() -> [BudgetTableData] {
return select(from: Self.table
.order(Self.col_id)
)
}
}
59 changes: 59 additions & 0 deletions MMEX/Repositories/BudgetYearRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// BudgetYearRepository.swift
// MMEX
//
// Created 2024-09-26 by George Ef ([email protected])
//

import Foundation
import SQLite

class BudgetYearRepository: RepositoryProtocol {
typealias RepositoryData = BudgetYearData

let db: Connection?
init(db: Connection?) {
self.db = db
}

static let repositoryName = "BUDGETYEAR_V1"
static let table = SQLite.Table(repositoryName)

// column | type | other
// ---------------+---------+------
// BUDGETYEARID | INTEGER | PRIMARY KEY
// BUDGETYEARNAME | TEXT | NOT NULL UNIQUE

// column expressions
static let col_id = SQLite.Expression<Int64>("BUDGETYEARID")
static let col_name = SQLite.Expression<String>("BUDGETYEARNAME")

static func selectQuery(from table: SQLite.Table) -> SQLite.Table {
return table.select(
col_id,
col_name
)
}

static func selectData(_ row: SQLite.Row) -> BudgetYearData {
return BudgetYearData(
id : row[col_id],
name : row[col_name]
)
}

static func itemSetters(_ year: BudgetYearData) -> [SQLite.Setter] {
return [
col_name <- year.name
]
}
}

extension BudgetYearRepository {
// load all budget years
func load() -> [BudgetYearData] {
return select(from: Self.table
.order(Self.col_name)
)
}
}
Loading

0 comments on commit 8362139

Please sign in to comment.