Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. struct BudgetPlan: Codable {
  2. let savingsGoal: Double
  3. var budget: Double
  4. private(set) var transactions: [Transaction]
  5. private var netToDate: Double {
  6. return transactions.reduce(0) { $0 + $1.amount }
  7. }
  8.  
  9. mutating func addTransaction(_ newTransaction: Transaction, newMonth: Bool) {
  10. if (newMonth) {
  11. transactions = [newTransaction]
  12. }
  13. else {
  14. transactions.append(newTransaction)
  15. }
  16. }
  17.  
  18. func estimateMonthlyIncome() -> Double {
  19. let monthlyCredit = transactions.reduce(0) { (amount, transaction) -> Double in
  20. return transaction.amount > 0 ? amount + transaction.amount : amount
  21. }
  22. let daysInMonth = 30.0
  23. let currentDay = Utilities.getDayOfMonth()
  24. transactions.last?.dollarAmount()
  25. return (monthlyCredit / currentDay) * daysInMonth
  26. }
  27.  
  28. func post() {
  29. DatabaseManager.shared.post(self)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement