Subscriptions: «Оплачено?» → paid status → «repeat?»; edit and create everything

- ops: paying marks the current charge paid (paid_for, persisted) instead of jumping to
  the next date; repeat_sub moves to the next period or closes the subscription.
  Paid-and-undecided subscriptions leave reminders and show in agenda['paid'].
  update_sub can set paid; tasks reopen when their status goes back; delete for subs and
  routines (BroV only, /api/delete); /api/tasks?all=1 and /api/subs?all=1.
- Bot: «₽ Оплачено?» on reminders, then «🔁 Да, <date> / Нет, закрыть»; after paying by
  text it asks the same with buttons.
- BroV: «Оплачено?» everywhere; «Оплачено — повторить?» section under the notch;
  «Весь план»: forms to edit or create tasks (title, description, status, due, company),
  subscriptions (amount, currency, period, date, reminder, company, paid, active) and
  routines, delete with confirmation, «+» per list, done tasks on demand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maksarsanjeev
2026-10-10 03:57:18 +03:00
parent 011c709acf
commit 882632b7ce
9 changed files with 628 additions and 65 deletions
+74 -10
View File
@@ -15,6 +15,8 @@ struct OpsItem: Identifiable, Equatable {
var client: String
var amount: Double?
var currency: String?
var paid = false
var nextIfRepeat: String?
var id: String { "\(kind)-\(ref)" }
}
@@ -22,11 +24,13 @@ struct OpsAgenda: Equatable {
var overdue: [OpsItem] = []
var today: [OpsItem] = []
var soon: [OpsItem] = []
/// Subscriptions paid and waiting for «repeat?».
var paid: [OpsItem] = []
var running: (id: Int, title: String, minutes: Int)?
var monthly: [String: Double] = [:]
static func == (a: OpsAgenda, b: OpsAgenda) -> Bool {
a.overdue == b.overdue && a.today == b.today && a.soon == b.soon
a.overdue == b.overdue && a.today == b.today && a.soon == b.soon && a.paid == b.paid
&& a.running?.id == b.running?.id && a.running?.minutes == b.running?.minutes && a.monthly == b.monthly
}
}
@@ -41,6 +45,7 @@ struct OpsTask: Identifiable, Equatable {
var minutes: Int
var running: Bool
var children: [OpsTask]
var notes: String = ""
}
struct OpsSub: Identifiable, Equatable {
@@ -53,6 +58,10 @@ struct OpsSub: Identifiable, Equatable {
var next: String
var remindDays: Int
var client: String
var paid = false
var nextIfRepeat = ""
var active = true
var notes = ""
}
struct OpsRoutine: Identifiable, Equatable {
@@ -61,6 +70,7 @@ struct OpsRoutine: Identifiable, Equatable {
var everyDays: Int
var next: String
var last: String?
var notes = ""
}
@MainActor
@@ -80,6 +90,10 @@ final class OpsClient: ObservableObject {
/// Subscriptions per month by company ("" = none), then by currency.
@Published var byClient: [String: [String: Double]] = [:]
var fullLoaded = false
/// «Весь план» → Задачи: also the finished ones.
@Published var showDone = false {
didSet { Task { await refreshAll() } }
}
var baseURL: String {
(UserDefaults.standard.string(forKey: Self.urlKey) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
@@ -129,11 +143,12 @@ final class OpsClient: ObservableObject {
(j[key] as? [[String: Any]] ?? []).compactMap { d in
guard let kind = d["kind"] as? String, let ref = d["id"] as? Int else { return nil }
return OpsItem(kind: kind, ref: ref, title: d["title"] as? String ?? "", date: d["date"] as? String ?? "",
client: d["client"] as? String ?? "", amount: d["amount"] as? Double,
currency: d["currency"] as? String)
client: d["client"] as? String ?? "", amount: (d["amount"] as? NSNumber)?.doubleValue,
currency: d["currency"] as? String, paid: d["paid"] as? Bool ?? false,
nextIfRepeat: d["next_if_repeat"] as? String)
}
}
var a = OpsAgenda(overdue: items("overdue"), today: items("due_today"), soon: items("soon"))
var a = OpsAgenda(overdue: items("overdue"), today: items("due_today"), soon: items("soon"), paid: items("paid"))
if let r = j["running"] as? [String: Any], let id = r["id"] as? Int {
a.running = (id, r["title"] as? String ?? "", r["minutes"] as? Int ?? 0)
}
@@ -143,12 +158,12 @@ final class OpsClient: ObservableObject {
func refreshAll() async {
await refresh()
if let arr = await request("/api/tasks") as? [[String: Any]] {
if let arr = await request(showDone ? "/api/tasks?all=1" : "/api/tasks") as? [[String: Any]] {
func task(_ d: [String: Any]) -> OpsTask {
OpsTask(id: d["id"] as? Int ?? 0, parentId: d["parent_id"] as? Int, title: d["title"] as? String ?? "",
client: d["client"] as? String ?? "", status: d["status"] as? String ?? "todo",
due: d["due"] as? String, minutes: d["minutes"] as? Int ?? 0, running: d["running"] as? Bool ?? false,
children: (d["children"] as? [[String: Any]] ?? []).map(task))
children: (d["children"] as? [[String: Any]] ?? []).map(task), notes: d["notes"] as? String ?? "")
}
tasks = arr.map(task)
}
@@ -157,7 +172,9 @@ final class OpsClient: ObservableObject {
OpsSub(id: d["id"] as? Int ?? 0, name: d["name"] as? String ?? "", amount: (d["amount"] as? NSNumber)?.doubleValue ?? 0,
currency: d["currency"] as? String ?? "RUB", period: d["period"] as? String ?? "month",
every: d["every"] as? Int ?? 1, next: d["next_date"] as? String ?? "", remindDays: d["remind_days"] as? Int ?? 3,
client: d["client"] as? String ?? "")
client: d["client"] as? String ?? "", paid: d["paid"] as? Bool ?? false,
nextIfRepeat: d["next_if_repeat"] as? String ?? "", active: (d["active"] as? Int ?? 1) == 1,
notes: d["notes"] as? String ?? "")
}
byClient = (j["by_client"] as? [String: [String: Any]] ?? [:]).mapValues { m in
m.compactMapValues { ($0 as? NSNumber)?.doubleValue }
@@ -166,7 +183,7 @@ final class OpsClient: ObservableObject {
if let arr = await request("/api/routines") as? [[String: Any]] {
routines = arr.map { d in
OpsRoutine(id: d["id"] as? Int ?? 0, title: d["title"] as? String ?? "", everyDays: d["every_days"] as? Int ?? 1,
next: d["next_date"] as? String ?? "", last: d["last_done"] as? String)
next: d["next_date"] as? String ?? "", last: d["last_done"] as? String, notes: d["notes"] as? String ?? "")
}
}
fullLoaded = true
@@ -189,6 +206,17 @@ final class OpsClient: ObservableObject {
if fullLoaded { await refreshAll() } else { await refresh() }
}
func delete(_ kind: String, _ id: Int) async {
let r = await request("/api/delete", body: ["kind": kind, "id": id]) as? [String: Any]
if let lines = r?["result"] as? [String] { lastAnswer = lines.joined(separator: "\n") }
SoundEngine.shared.play("close")
await refreshAll()
}
func repeatSub(_ id: Int, _ again: Bool) async {
await act(["op": "repeat_sub", "id": id, "repeat": again])
}
func done(_ it: OpsItem) async {
switch it.kind {
case "task": await act(["op": "complete_task", "id": it.ref])
@@ -310,6 +338,10 @@ struct OpsPanel: View {
header("СЕГОДНЯ", "#F5A524")
ForEach(ops.agenda.today) { OpsRow(item: $0) }
}
if !ops.agenda.paid.isEmpty {
header("ОПЛАЧЕНО — ПОВТОРИТЬ?", "#60A5FA")
ForEach(ops.agenda.paid) { PaidRow(item: $0) }
}
if !ops.agenda.soon.isEmpty {
Button { withAnimation(.easeOut(duration: 0.15)) { showWeek.toggle() } } label: {
HStack(spacing: 4) {
@@ -323,7 +355,7 @@ struct OpsPanel: View {
.buttonStyle(.plain)
if showWeek { ForEach(ops.agenda.soon) { OpsRow(item: $0) } }
}
if ops.configured && ops.reachable == true && ops.agenda.running == nil
if ops.configured && ops.reachable == true && ops.agenda.running == nil && ops.agenda.paid.isEmpty
&& ops.agenda.overdue.isEmpty && ops.agenda.today.isEmpty && ops.agenda.soon.isEmpty {
Text("На неделю ничего не горит 👌").font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
.padding(.vertical, 8).padding(.leading, 6)
@@ -404,6 +436,38 @@ struct OpsInput: View {
}
}
/// A paid subscription: «✓ Оплачено» and the question «repeat on <date>?».
struct PaidRow: View {
let item: OpsItem
@ObservedObject private var ops = OpsClient.shared
var body: some View {
HStack(spacing: 8) {
Image(systemName: "checkmark.circle.fill").font(.system(size: 13)).foregroundColor(Color(hex: "#34D399")).frame(width: 16)
VStack(alignment: .leading, spacing: 1) {
Text(item.title).font(.system(size: 12, weight: .medium)).lineLimit(1)
Text("Оплачено · повторить \(OpsClient.ruDay(item.nextIfRepeat))?")
.font(.system(size: 10.5)).foregroundColor(Color(hex: "#34D399")).lineLimit(1)
}
Spacer(minLength: 4)
Button { Task { await ops.repeatSub(item.ref, true) } } label: {
Text("Повторить").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
.padding(.horizontal, 7).frame(height: 18)
.background(Capsule().fill(Color(hex: "#60A5FA").opacity(0.14)))
}
.buttonStyle(.plain)
Button { Task { await ops.repeatSub(item.ref, false) } } label: {
Text("Нет").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#8E939C"))
.padding(.horizontal, 7).frame(height: 18)
.background(Capsule().fill(Color.white.opacity(0.06)))
}
.buttonStyle(.plain)
.help("Больше не повторять — подписка закроется")
}
.padding(.horizontal, 6).padding(.vertical, 5)
}
}
/// One agenda line: ○ done on the left (₽ «Оплачено» for subscriptions), ⏱ / ⏰ on hover.
struct OpsRow: View {
let item: OpsItem
@@ -445,7 +509,7 @@ struct OpsRow: View {
}
if item.kind == "sub" {
Button { Task { await ops.done(item) } } label: {
Text("Оплачено").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
Text("Оплачено?").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
.padding(.horizontal, 7).frame(height: 18)
.background(Capsule().fill(Color(hex: "#60A5FA").opacity(0.14)))
}