Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Income and Expenses report #61

Merged
merged 1 commit into from
Sep 28, 2024
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
21 changes: 21 additions & 0 deletions MMEX/Models/TransactionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ extension TransactionData {
}
return transDate // If parsing fails, return original string
}
var income: Double {
// TODO: in base currency
if transCode == .deposit {
return transAmount
}
return 0.0
}
var expenses: Double {
// TODO: in base currency
if transCode == .withdrawal {
return transAmount
}
return 0.0
}
var transfer: Double {
// TODO: in base currency
if transCode == .transfer {
return transAmount// or toTransAmount
}
return 0.0
}
}

extension TransactionData {
Expand Down
10 changes: 5 additions & 5 deletions MMEX/Repositories/TransactionRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@ extension TransactionRepository {
func loadRecent(
accountId: Int64? = nil,
startDate: Date? = Calendar.current.date(byAdding: .month, value: -3, to: Date()),
endDate: Date? = Date()
endDate: Date? = Calendar.current.date(byAdding: .day, value: 1, to: Date())
) -> [TransactionData] {
var table = Self.table

if let accountId {
table = table.filter(Self.col_accountId == accountId || Self.col_toAccountId == accountId)
}
if let startDate {
table = table.filter(Self.col_transDate >= startDate.ISO8601Format())
table = table.filter(Self.col_transDate >= String(startDate.ISO8601Format().dropLast()))
}
if let endDate {
table = table.filter(Self.col_transDate <= String(endDate.ISO8601Format().dropLast()))
}
//if let endDate {
// table = table.filter(Self.col_transDate <= endDate.ISO8601Format())
//}

return select(from: table)
}
Expand Down
26 changes: 23 additions & 3 deletions MMEX/Views/InsightsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ struct InsightsView: View {
.shadow(radius: 2)
}

// Transactions Over Time Chart Section
// Transactions Income Over Time Chart Section
Section {
Chart(viewModel.stats) {
BarMark(
x: .value("Day", $0.day),
y: .value("Amount", $0.transAmount)
y: .value("Amount", $0.income)
)
.foregroundStyle(by: .value("Status", $0.status.fullName))
}
Expand All @@ -50,11 +50,31 @@ struct InsightsView: View {
.cornerRadius(10)
.shadow(radius: 2)
} header: {
Text("Transactions Over Time")
Text("Income Over Time")
.font(.headline)
.padding(.horizontal)
}

// Transactions expenses Over Time Chart Section
Section {
Chart(viewModel.stats) {
BarMark(
x: .value("Day", $0.day),
y: .value("Amount", $0.expenses)
)
.foregroundStyle(by: .value("Status", $0.status.fullName))
}
.frame(height: 200)
.padding()
.background(Color(.systemGray6))
.cornerRadius(10)
.shadow(radius: 2)
} header: {
Text("Expenses Over Time")
.font(.headline)
.padding(.horizontal)
}

// Placeholder for Future Sections
Section {
VStack {
Expand Down