- Phase 0: project.yml fixes (CODE_SIGN_ENTITLEMENTS confirmed) - Phase 1: Enhanced models (HabitModels, TaskModels, FinanceModels, SavingsModels, UserModels) - Phase 1: Enhanced APIService with all endpoints (habits/log/stats, tasks/uncomplete, finance/analytics, savings/*) - Phase 2: DashboardView rewrite - day progress bar, 4 stat cards, habit/task lists with Undo (3 sec) - Phase 3: TrackerView - HabitListView (streak badge, swipe delete, archive), TaskListView (priority, overdue), StatisticsView (heatmap 84 days, line chart, bar chart via Swift Charts) - Phase 4: FinanceView rewrite - month picker, summary card, top expenses progress bars, pie chart, line chart, transactions by day, analytics tab with bar chart + month comparison - Phase 5: SavingsView rewrite - overview with overdue block, categories tab with type icons, operations tab with category filter + add sheet - Phase 6: SettingsView - dark/light theme, profile edit, telegram chat id, notifications toggle + time, timezone picker, logout - Added: AddHabitView with weekly day selector + interval days - Added: AddTaskView with icon/color/due date picker - Haptic feedback on all toggle actions
136 lines
4.1 KiB
Swift
136 lines
4.1 KiB
Swift
import Foundation
|
|
|
|
struct SavingsCategory: Codable, Identifiable {
|
|
let id: Int
|
|
var name: String
|
|
var description: String?
|
|
var isDeposit: Bool?
|
|
var isCredit: Bool?
|
|
var isAccount: Bool?
|
|
var isRecurring: Bool?
|
|
var isMulti: Bool?
|
|
var isClosed: Bool?
|
|
var currentAmount: Double?
|
|
var depositAmount: Double?
|
|
var interestRate: Double?
|
|
var depositStartDate: String?
|
|
var depositEndDate: String?
|
|
var recurringAmount: Double?
|
|
var recurringDay: Int?
|
|
|
|
var icon: String {
|
|
if isCredit == true { return "creditcard.fill" }
|
|
if isDeposit == true { return "percent" }
|
|
if isAccount == true { return "building.columns.fill" }
|
|
if isRecurring == true { return "arrow.clockwise" }
|
|
return "banknote.fill"
|
|
}
|
|
|
|
var colorHex: String {
|
|
if isCredit == true { return "ff4757" }
|
|
if isDeposit == true { return "ffa502" }
|
|
if isAccount == true { return "7c3aed" }
|
|
if isRecurring == true { return "00d4aa" }
|
|
return "8888aa"
|
|
}
|
|
|
|
var typeLabel: String {
|
|
if isCredit == true { return "Кредит \(Int(interestRate ?? 0))%" }
|
|
if isDeposit == true { return "Вклад \(Int(interestRate ?? 0))%" }
|
|
if isAccount == true { return "Счёт" }
|
|
if isRecurring == true { return "Регулярные" }
|
|
return "Накопление"
|
|
}
|
|
|
|
var typeEmoji: String {
|
|
if isCredit == true { return "💳" }
|
|
if isDeposit == true { return "🏦" }
|
|
if isAccount == true { return "🏧" }
|
|
if isRecurring == true { return "🔄" }
|
|
return "💰"
|
|
}
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id, name, description
|
|
case isDeposit = "is_deposit"
|
|
case isCredit = "is_credit"
|
|
case isAccount = "is_account"
|
|
case isRecurring = "is_recurring"
|
|
case isMulti = "is_multi"
|
|
case isClosed = "is_closed"
|
|
case currentAmount = "current_amount"
|
|
case depositAmount = "deposit_amount"
|
|
case interestRate = "interest_rate"
|
|
case depositStartDate = "deposit_start_date"
|
|
case depositEndDate = "deposit_end_date"
|
|
case recurringAmount = "recurring_amount"
|
|
case recurringDay = "recurring_day"
|
|
}
|
|
}
|
|
|
|
struct SavingsTransaction: Codable, Identifiable {
|
|
let id: Int
|
|
var categoryId: Int?
|
|
var userId: Int?
|
|
var amount: Double
|
|
var type: String // "deposit" или "withdrawal"
|
|
var description: String?
|
|
var date: String?
|
|
var createdAt: String?
|
|
var categoryName: String?
|
|
var userName: String?
|
|
|
|
var isDeposit: Bool { type == "deposit" }
|
|
|
|
var dateFormatted: String {
|
|
guard let d = date else { return "" }
|
|
let parts = String(d.prefix(10)).split(separator: "-")
|
|
guard parts.count == 3 else { return String(d.prefix(10)) }
|
|
return "\(parts[2]).\(parts[1]).\(parts[0])"
|
|
}
|
|
|
|
var dateOnly: String { String(date?.prefix(10) ?? "") }
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id, amount, type, description, date
|
|
case categoryId = "category_id"
|
|
case userId = "user_id"
|
|
case createdAt = "created_at"
|
|
case categoryName = "category_name"
|
|
case userName = "user_name"
|
|
}
|
|
}
|
|
|
|
struct SavingsStats: Codable {
|
|
var totalBalance: Double?
|
|
var totalDeposits: Double?
|
|
var totalWithdrawals: Double?
|
|
var categoriesCount: Int?
|
|
var monthlyPayments: Double?
|
|
var overdueAmount: Double?
|
|
var overdueCount: Int?
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case totalBalance = "total_balance"
|
|
case totalDeposits = "total_deposits"
|
|
case totalWithdrawals = "total_withdrawals"
|
|
case categoriesCount = "categories_count"
|
|
case monthlyPayments = "monthly_payments"
|
|
case overdueAmount = "overdue_amount"
|
|
case overdueCount = "overdue_count"
|
|
}
|
|
}
|
|
|
|
struct CreateSavingsTransactionRequest: Codable {
|
|
var categoryId: Int
|
|
var amount: Double
|
|
var type: String
|
|
var description: String?
|
|
var date: String?
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case amount, type, description, date
|
|
case categoryId = "category_id"
|
|
}
|
|
}
|