Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct BudgetPlan: Codable {
- let savingsGoal: Double
- var budget: Double
- private(set) var transactions: [Transaction]
- private var netToDate: Double {
- return transactions.reduce(0) { $0 + $1.amount }
- }
- mutating func addTransaction(_ newTransaction: Transaction, newMonth: Bool) {
- if (newMonth) {
- transactions = [newTransaction]
- }
- else {
- transactions.append(newTransaction)
- }
- }
- func estimateMonthlyIncome() -> Double {
- let monthlyCredit = transactions.reduce(0) { (amount, transaction) -> Double in
- return transaction.amount > 0 ? amount + transaction.amount : amount
- }
- let daysInMonth = 30.0
- let currentDay = Utilities.getDayOfMonth()
- transactions.last?.dollarAmount()
- return (monthlyCredit / currentDay) * daysInMonth
- }
- func post() {
- DatabaseManager.shared.post(self)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement