7cb5f92cf4
Deleted files: - AddTransactionView.swift - TransactionRepository.swift - Transaction+CoreDataClass.swift Cleaned files: - SourceDetailViewModel: removed transactions published property, showingAddTransaction flag, transactionRepository dependency, addTransaction() and deleteTransaction() methods - SourceDetailView: removed transactionsSection, TransactionRow struct, Add Transaction button from quickActions, sheet presentation - InvestmentSource+CoreDataClass: removed transactions NSManaged property, transactionsArray, totalInvested, totalDividends, totalFees computed properties, and all transaction Core Data accessors - SettingsViewModel: removed "Transaction" from resetAllData entity list - SampleDataService: removed transactionRepository and sample transaction Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
2.3 KiB
Swift
80 lines
2.3 KiB
Swift
import Foundation
|
|
|
|
struct MonthlySummary {
|
|
let periodLabel: String
|
|
let startDate: Date
|
|
let endDate: Date
|
|
let startingValue: Decimal
|
|
let endingValue: Decimal
|
|
let contributions: Decimal
|
|
let netPerformance: Decimal
|
|
|
|
var netPerformancePercentage: Double {
|
|
let base = startingValue + contributions
|
|
guard base > 0 else { return 0 }
|
|
return NSDecimalNumber(decimal: netPerformance / base).doubleValue * 100
|
|
}
|
|
|
|
var formattedMonthYear: String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "MMMM yyyy"
|
|
return formatter.string(from: startDate)
|
|
}
|
|
|
|
var formattedStartingValue: String {
|
|
CurrencyFormatter.format(startingValue, style: .currency, maximumFractionDigits: 0)
|
|
}
|
|
|
|
var formattedEndingValue: String {
|
|
CurrencyFormatter.format(endingValue, style: .currency, maximumFractionDigits: 0)
|
|
}
|
|
|
|
var formattedContributions: String {
|
|
CurrencyFormatter.format(contributions, style: .currency, maximumFractionDigits: 0)
|
|
}
|
|
|
|
var formattedNetPerformance: String {
|
|
let prefix = netPerformance >= 0 ? "+" : ""
|
|
let value = CurrencyFormatter.format(netPerformance, style: .currency, maximumFractionDigits: 0)
|
|
return prefix + value
|
|
}
|
|
|
|
var formattedNetPerformancePercentage: String {
|
|
let prefix = netPerformance >= 0 ? "+" : ""
|
|
return String(format: "\(prefix)%.2f%%", netPerformancePercentage)
|
|
}
|
|
|
|
static var empty: MonthlySummary {
|
|
MonthlySummary(
|
|
periodLabel: "This Month",
|
|
startDate: Date(),
|
|
endDate: Date(),
|
|
startingValue: 0,
|
|
endingValue: 0,
|
|
contributions: 0,
|
|
netPerformance: 0
|
|
)
|
|
}
|
|
}
|
|
|
|
struct PortfolioChange {
|
|
let absolute: Decimal
|
|
let percentage: Double
|
|
let label: String
|
|
|
|
var formattedAbsolute: String {
|
|
let prefix = absolute >= 0 ? "+" : ""
|
|
let value = CurrencyFormatter.format(absolute, style: .currency, maximumFractionDigits: 0)
|
|
return prefix + value
|
|
}
|
|
|
|
var formattedPercentage: String {
|
|
let prefix = absolute >= 0 ? "+" : ""
|
|
return String(format: "\(prefix)%.2f%%", percentage)
|
|
}
|
|
|
|
static var empty: PortfolioChange {
|
|
PortfolioChange(absolute: 0, percentage: 0, label: "since last update")
|
|
}
|
|
}
|