-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from moneymanagerex/new_models-4
Add BudgetYear, BudgetTable, Report
- Loading branch information
Showing
8 changed files
with
398 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] = [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] = [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] = [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
Oops, something went wrong.