diff --git a/.env.example b/.env.example index 2d850b3..5847446 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -# owner account password (username: owner); changing it here resets the owner login -APP_PASSWORD=pick-a-long-password SECRET_KEY=generate-with-openssl-rand-hex-32 +# Default business time zone until you pick one in first-time setup APP_TZ=America/New_York diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca8d548..d578aca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,7 +175,8 @@ jobs: env: DATA_DIR: ${{ github.workspace }}/.ci-visual APP_URL: http://127.0.0.1:8000 - APP_PASSWORD: ci-smoke-only-not-a-real-password + DEMO_OWNER_PASSWORD: ci-smoke-only-not-a-real-password + OWNER_PASSWORD: ci-smoke-only-not-a-real-password SECRET_KEY: cismoke0000000000000000000000000000000000000000000000000000000000 PYTHONPATH: "." steps: @@ -226,7 +227,6 @@ jobs: - name: Boot to healthy run: | docker run -d --name "$SMOKE" \ - -e APP_PASSWORD=ci-smoke-only-not-a-real-password \ -e SECRET_KEY=cismoke0000000000000000000000000000000000000000000000000000000000 \ "$SMOKE" # HEALTHCHECK: 20s start-period, 30s interval — allow ~2 min total. diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..aec2fd4 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,33 @@ +# Publishes the project website (site/) to GitHub Pages. One-time setup in the +# repository: Settings → Pages → Build and deployment → Source: GitHub Actions. +name: Website + +on: + push: + branches: [main] + paths: ["site/**", ".github/workflows/pages.yml"] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: false + +jobs: + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v4 + - uses: actions/configure-pages@v5 + - uses: actions/upload-pages-artifact@v3 + with: + path: site + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/README.md b/README.md index 98852a3..458096d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@
Self-hosted pool-service management — routes, water chemistry, invoicing, and crew.
+Website · Docker Hub · Releases
+ --- Self-hosted pool-route app for small pool-service companies, built to run on @@ -24,27 +26,36 @@ one box (Docker + SQLite) and to be used from an iPhone in the field. ## Run - cp .env.example .env # set APP_PASSWORD and SECRET_KEY + cp .env.example .env # set SECRET_KEY (openssl rand -hex 32) docker compose up -d + # (builds from source; to run the published image instead use + # deploy/docker-compose.yml, which pulls dendlomm/openpoolpro:latest) # Put a TLS reverse proxy in front — the compose file binds the app to # 127.0.0.1:8000 ON PURPOSE (the app trusts X-Forwarded-* from the proxy), # so it is NOT reachable from other machines directly. Point the proxy at # 127.0.0.1:8000 and set FORWARDED_ALLOW_IPS to the proxy's address. - # First login is owner / your APP_PASSWORD - # manage crew under Settings → Manage crew - # change APP_PASSWORD in .env + restart to reset the owner login (recovery) + # Open the app: first-time setup asks for the setup code from + # docker compose logs app | grep "Setup code" + # then creates your owner account (your name, username and password). + # Forgot the owner password? Print a one-time reset link: + # docker compose exec app python -m app.manage reset-owner [--clear-2fa] # on iPhone: Share → Add to Home Screen All data lives in ./data (SQLite DB, photos, nightly backups). Back up that folder. +**Upgrading from a version that used `APP_PASSWORD`:** your `owner` account keeps +working with its current password. The first time you sign in after the upgrade, +you're asked to add your name, choose your own username and set a new password. +After that `APP_PASSWORD` is never read, so remove it from `.env`. + ### Deploy the published image (Unraid) CI publishes `:latest` on every merge to `main`, plus an immutable `:vX.Y.Z` per release, to both `ghcr.io/dlommm/openpoolpro` and Docker Hub (`dendlomm/openpoolpro`). `docker-compose.unraid.yml` is a ready-made stack for Unraid's Docker Compose Manager — read the SETUP notes at the top of the file -(cache-only appdata share, required `APP_PASSWORD`/`SECRET_KEY`), then: +(cache-only appdata share, required `SECRET_KEY`), then: docker compose -f docker-compose.unraid.yml pull docker compose -f docker-compose.unraid.yml up -d @@ -54,7 +65,8 @@ for Unraid's Docker Compose Manager — read the SETUP notes at the top of the f python3.12 -m venv .venv && source .venv/bin/activate pip install -r requirements-dev.txt python scripts/build_css.py - APP_PASSWORD=dev COOKIE_SECURE=0 uvicorn app.main:create_app --factory --reload + COOKIE_SECURE=0 uvicorn app.main:create_app --factory --reload + # the setup code is printed in the log on first start ruff check app/ tests/ scripts/ # same gate CI runs pytest -n auto @@ -505,7 +517,7 @@ is how a customer arrives. Every staff screen and the portal are rendered twice, once on a light device and once on a dark one, and each render is held to a 7:1 body-text contrast ratio: - APP_URL=http://localhost:8000 APP_PASSWORD=... python scripts/visual_check.py + APP_URL=http://localhost:8000 OWNER_USER=... OWNER_PASSWORD=... python scripts/visual_check.py Point it at a disposable instance: to reach those screens it creates a "Visual Tech" staff member and issues then revokes a portal link for customer 1, diff --git a/app/analytics_overview.py b/app/analytics_overview.py new file mode 100644 index 0000000..d284aa4 --- /dev/null +++ b/app/analytics_overview.py @@ -0,0 +1,516 @@ +"""The Analytics overview: one range (3, 6 or 12 months) scoping every panel. + +Pure query/aggregation layer, like app.analytics, whose money rules it reuses +to the cent: service is the frozen visit labor (`tax.effective_labor_cents`), +chemicals are billed through `qbo.billable_for_vc` at the current markup, and +"repairs and jobs" is the labor of finished jobs dated by their business-local +completion day. + +The current month is always partial. It is drawn and totalled, but the +like-for-like comparison uses full months only: the full months of the window +against the same number of months just before it. +""" +from collections import defaultdict +from dataclasses import dataclass, field +from datetime import date + +from sqlalchemy import func, select +from sqlalchemy.orm import Session, selectinload + +from app import analytics, models, qbo, receivables, tax +from app.qbo import _local_date +from app.rates import effective_rate_cents, largest_pool_gallons +from app.timefmt import business_today, local_date + +RANGES = (3, 6, 12) +DEFAULT_RANGE = 6 +REVIEW_SHARE = 0.15 # chemical cost at or above this share of the rate -> review + +# Visits a week each schedule frequency produces, for "recurring weekly service". +WEEKLY_FACTOR = {"weekly": 1.0, "biweekly": 0.5, "every4weeks": 0.25} + +SOURCES = ( + ("service", "Weekly service", "var(--c1)"), + ("chemicals", "Chemicals", "var(--c2)"), + ("jobs", "Repairs and jobs", "var(--c3)"), +) + +AGING_LABELS = { + "Current": "Not due yet", + "1-30": "1–30 days late", + "31-60": "31–60 days late", + "61-90": "61–90 days late", + "90+": "Over 90 days", +} + +MONTH_NAMES = ("January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December") + + +def ordinal(n: int) -> str: + suffix = "th" if 10 <= n % 100 <= 20 else {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th") + return f"{n}{suffix}" + + +def parse_range(raw) -> int: + try: + n = int(raw) + except (TypeError, ValueError): + return DEFAULT_RANGE + return n if n in RANGES else DEFAULT_RANGE + + +def month_keys(today: date, months: int) -> list[tuple[int, int]]: + """The `months` calendar months ending with today's, oldest first.""" + out = [] + y, m = today.year, today.month + for _ in range(max(1, months)): + out.append((y, m)) + y, m = (y - 1, 12) if m == 1 else (y, m - 1) + return out[::-1] + + +def _shift(key: tuple[int, int], back: int) -> tuple[int, int]: + idx = key[0] * 12 + (key[1] - 1) - back + return (idx // 12, idx % 12 + 1) + + +@dataclass +class MonthRow: + year: int + month: int + service_cents: int = 0 + chem_cents: int = 0 + jobs_cents: int = 0 + visits: int = 0 + partial_through: int | None = None # day of month the data runs to, when partial + + @property + def key(self) -> tuple[int, int]: + return (self.year, self.month) + + @property + def total_cents(self) -> int: + return self.service_cents + self.chem_cents + self.jobs_cents + + @property + def partial(self) -> bool: + return self.partial_through is not None + + @property + def short(self) -> str: + return MONTH_NAMES[self.month - 1][:3] + + @property + def axis_label(self) -> str: + if self.partial: + return f"{self.short} (to {ordinal(self.partial_through)})" + return self.short + + @property + def long(self) -> str: + name = MONTH_NAMES[self.month - 1] + if self.partial: + return f"{name} 1–{self.partial_through}, {self.year} (so far)" + return f"{name} {self.year}" + + def part(self, source: str) -> int: + return {"service": self.service_cents, "chemicals": self.chem_cents, + "jobs": self.jobs_cents}[source] + + +def monthly_revenue(session: Session, keys: list[tuple[int, int]], today: date, + data: "analytics.PeriodData | None" = None) -> list[MonthRow]: + """One row per month key (zeros included), split service/chemicals/jobs.""" + if not keys: + return [] + start = date(keys[0][0], keys[0][1], 1) + if data is None: + data = analytics.load_period(session, start, today) + markup = analytics._markup(session) + rows = {k: MonthRow(year=k[0], month=k[1]) for k in keys} + cur = (today.year, today.month) + if cur in rows: + rows[cur].partial_through = today.day + for v in data.done_visits: + r = rows.get((v.date.year, v.date.month)) + if r is None: + continue + r.visits += 1 + r.service_cents += tax.effective_labor_cents(v) + r.chem_cents += sum(qbo.billable_for_vc(vc, markup) for vc in v.chemicals) + for j in data.done_jobs: + d = _local_date(j.completed_at) + r = rows.get((d.year, d.month)) + if r is not None: + r.jobs_cents += tax.effective_labor_cents(j) + return [rows[k] for k in keys] + + +@dataclass +class Delta: + pct: float + current_cents: int + previous_cents: int + current_span: str + previous_span: str + + @property + def up(self) -> bool: + return self.pct >= 0 + + +def _span(rows: list[MonthRow]) -> str: + if not rows: + return "" + a, b = rows[0], rows[-1] + if a.key == b.key: + return f"{a.short} {a.year}" + if a.year == b.year: + return f"{a.short}–{b.short} {b.year}" + return f"{a.short} {a.year}–{b.short} {b.year}" + + +def like_for_like(window: list[MonthRow], before: list[MonthRow]) -> Delta | None: + """Full months of the window against the same count of months before it. + + None when there is nothing fair to compare: no full month in the window + (a one-month range is just the partial current month), or no revenue at + all in the earlier months (a new business, or history not entered). + """ + full = [m for m in window if not m.partial] + if not full: + return None + prev = before[-len(full):] if len(before) >= len(full) else [] + prev_total = sum(m.total_cents for m in prev) + if not prev or prev_total <= 0: + return None + cur_total = sum(m.total_cents for m in full) + return Delta(pct=(cur_total / prev_total - 1) * 100, current_cents=cur_total, + previous_cents=prev_total, current_span=_span(full), + previous_span=_span(prev)) + + +@dataclass +class MixRow: + key: str + label: str + colour: str + cents: int + share: float # 0..1 + + +def income_mix(months: list[MonthRow]) -> list[MixRow]: + total = sum(m.total_cents for m in months) + out = [] + for key, label, colour in SOURCES: + cents = sum(m.part(key) for m in months) + out.append(MixRow(key, label, colour, cents, cents / total if total else 0.0)) + return out + + +@dataclass +class RouteRow: + name: str + tech: "models.User | None" + customers: int = 0 + weekly_cents: int = 0 + + @property + def unassigned(self) -> bool: + return self.tech is None + + +def _service_props(session: Session) -> list["models.Property"]: + return session.scalars( + select(models.Property).join(models.Customer).where( + models.Property.active.is_(True), models.Customer.active.is_(True)) + .options(selectinload(models.Property.customer), + selectinload(models.Property.pools), + selectinload(models.Property.assigned_tech))).all() + + +def recurring_by_route(session: Session) -> list[RouteRow]: + """Recurring service a week on each technician's route, from today's customer list. + + Biweekly and four-weekly properties count at a half and a quarter of their + rate, so every route is in the same per-week unit. Unassigned recurring + properties are their own row, last, so nothing billable goes unseen. + """ + rows: dict[int | None, RouteRow] = {} + seen: dict[int | None, set[int]] = defaultdict(set) + for p in _service_props(session): + factor = WEEKLY_FACTOR.get(p.frequency) + if not factor: + continue + key = p.assigned_tech_id + row = rows.get(key) + if row is None: + row = rows[key] = RouteRow( + name=p.assigned_tech.name if p.assigned_tech else "Unassigned", tech=p.assigned_tech) + row.weekly_cents += round(effective_rate_cents(session, p) * factor) + seen[key].add(p.customer_id) + for key, row in rows.items(): + row.customers = len(seen[key]) + return sorted(rows.values(), key=lambda r: (r.unassigned, -r.weekly_cents, r.name)) + + +@dataclass +class AgingRow: + label: str + cents: int = 0 + count: int = 0 + level: str = "" # "" | "warn" | "neg" + + +def receivables_by_age(session: Session, today: date) -> list[AgingRow]: + """Open balances in the accountant's buckets, from the invoices themselves.""" + order = [label for label, _ in receivables.AGING_BUCKETS] + rows = {label: AgingRow(label=AGING_LABELS.get(label, label)) for label in order} + for inv in receivables.open_invoices(session): + r = rows[receivables.bucket_for(inv.days_overdue(today))] + r.cents += inv.balance_cents + r.count += 1 + out = [rows[label] for label in order] + for i, r in enumerate(out): + r.level = "" if i == 0 else ("warn" if i == 1 else "neg") + return out + + +@dataclass +class RatePoint: + name: str + property_id: int + customer_id: int + rate_cents: int + chem_per_visit_cents: int + visits: int + gallons: int + avg_minutes: int | None + + @property + def share(self) -> float: + return self.chem_per_visit_cents / self.rate_cents if self.rate_cents else 0.0 + + @property + def flag(self) -> bool: + return self.share >= REVIEW_SHARE + + +def rate_points(session: Session, data: "analytics.PeriodData", + start: date, end: date) -> list[RatePoint]: + """Chemical cost per visit as a share of the rate, per active property. + + Chemical COST (what the business spends), not the billed amount: the + question is whether the rate still covers the chemicals. The rate is the + property's current rate (the one a review would change), falling back to + what its visits in the range were billed when no rate resolves. + """ + per: dict[int, list] = defaultdict(list) + for v in data.done_visits: + if start <= v.date <= end: + per[v.property_id].append(v) + if not per: + return [] + props = session.scalars( + select(models.Property).where(models.Property.id.in_(per)) + .options(selectinload(models.Property.customer), + selectinload(models.Property.pools))).all() + multi = defaultdict(int) + for p in props: + multi[p.customer_id] += 1 + out = [] + for p in props: + if not p.active or not p.customer.active: + continue + visits = per[p.id] + n = len(visits) + chem = sum(vc.total_cost_cents for v in visits for vc in v.chemicals) + rate = effective_rate_cents(session, p) or round( + sum(tax.effective_labor_cents(v) for v in visits) / n) + if rate <= 0: + continue + mins = [v.duration_minutes for v in visits if v.duration_minutes is not None] + name = p.customer.name if multi[p.customer_id] == 1 else f"{p.customer.name} · {p.label}" + out.append(RatePoint( + name=name, property_id=p.id, customer_id=p.customer_id, rate_cents=rate, + chem_per_visit_cents=round(chem / n), visits=n, + gallons=largest_pool_gallons(p) or largest_pool_gallons(p, "spa"), + avg_minutes=round(sum(mins) / len(mins)) if mins else None)) + return sorted(out, key=lambda r: (-r.share, r.name)) + + +@dataclass +class Move: + name: str + customer_id: int + kind: str # "gained" | "lost" + on: date + + +@dataclass +class Movement: + gained: list[Move] = field(default_factory=list) + lost: list[Move] = field(default_factory=list) + by_month: dict[tuple[int, int], tuple[int, int]] = field(default_factory=dict) + + +def customer_movement(session: Session, keys: list[tuple[int, int]], today: date) -> Movement: + """Customers gained (by when they were added) and lost, per month of the window. + + A lost customer is one marked inactive, dated by when that happened. + Customers deactivated before that was recorded fall back to their last + completed visit, then to when they were added. + """ + mv = Movement(by_month={k: (0, 0) for k in keys}) + if not keys: + return mv + start = date(keys[0][0], keys[0][1], 1) + customers = session.scalars(select(models.Customer)).all() + last_visit = dict(session.execute( + select(models.Property.customer_id, func.max(models.Visit.date)) + .join(models.Visit, models.Visit.property_id == models.Property.id) + .join(models.Customer, models.Customer.id == models.Property.customer_id) + .where(models.Visit.status == "done", models.Customer.active.is_(False)) + .group_by(models.Property.customer_id)).all()) + + def add(move: Move, slot: int): + k = (move.on.year, move.on.month) + if k in mv.by_month and start <= move.on <= today: + g, lost = mv.by_month[k] + mv.by_month[k] = (g + (slot == 0), lost + (slot == 1)) + (mv.gained if slot == 0 else mv.lost).append(move) + + for c in customers: + added = local_date(c.created_at) if c.created_at else None + if added: + add(Move(c.name, c.id, "gained", added), 0) + if not c.active: + ended = (local_date(c.deactivated_at) if c.deactivated_at else None) \ + or last_visit.get(c.id) or added + if ended: + add(Move(c.name, c.id, "lost", ended), 1) + mv.gained.sort(key=lambda m: (m.on, m.name), reverse=True) + mv.lost.sort(key=lambda m: (m.on, m.name), reverse=True) + return mv + + +def nice_top(value: float, steps: int = 3) -> int: + """A round axis maximum at or above `value`, divisible into `steps` ticks.""" + if value <= 0: + return steps + raw = value / steps + mag = 10 ** (len(str(int(raw))) - 1) if raw >= 1 else 1 + for m in (1, 2, 2.5, 5, 10): + step = m * mag + if step >= raw: + return int(round(step * steps)) + return int(round(10 * mag * steps)) + + +def nice_range(lo: float, hi: float, steps: int = 4) -> tuple[int, int]: + """(start, step) of a round axis covering lo..hi in `steps` equal steps. + + The rate axis starts near the cheapest rate rather than at zero, so a + business whose rates all sit between $60 and $90 gets a readable spread. + """ + lo, hi = max(0, lo), max(0, hi) + if hi <= lo: + lo, hi = max(0, lo - steps), hi + steps + raw = (hi - lo) / steps + mag = 10 ** (len(str(int(raw))) - 1) if raw >= 1 else 1 + for m in (1, 2, 2.5, 5, 10, 20, 25, 50, 100): + step = int(m * mag) + start = int(lo // step * step) + if start + step * steps >= hi: + return start, step + return 0, int(hi // steps + 1) + + +@dataclass +class Overview: + months_n: int + today: date + months: list[MonthRow] + delta: Delta | None + mix: list[MixRow] + routes: list[RouteRow] + aging: list[AgingRow] + rates: list[RatePoint] + movement: Movement + active_customers: int + + @property + def start(self) -> date: + return date(self.months[0].year, self.months[0].month, 1) + + @property + def revenue_cents(self) -> int: + return sum(m.total_cents for m in self.months) + + @property + def visits(self) -> int: + return sum(m.visits for m in self.months) + + @property + def per_visit_cents(self) -> int: + return round(self.revenue_cents / self.visits) if self.visits else 0 + + @property + def full_months(self) -> list[MonthRow]: + return [m for m in self.months if not m.partial] + + @property + def visits_per_full_month(self) -> int | None: + full = self.full_months + return round(sum(m.visits for m in full) / len(full)) if full else None + + @property + def best_full_month(self) -> MonthRow | None: + full = [m for m in self.full_months if m.total_cents > 0] + return max(full, key=lambda m: m.total_cents) if full else None + + @property + def span(self) -> str: + return _span(self.months) + + @property + def flagged(self) -> list[RatePoint]: + return [p for p in self.rates if p.flag] + + @property + def weekly_recurring_cents(self) -> int: + return sum(r.weekly_cents for r in self.routes) + + @property + def ar_total_cents(self) -> int: + return sum(a.cents for a in self.aging) + + @property + def ar_over_30_cents(self) -> int: + return sum(a.cents for a in self.aging[2:]) + + @property + def has_revenue(self) -> bool: + return self.revenue_cents > 0 + + +def build(session: Session, months: int = DEFAULT_RANGE, today: date | None = None) -> Overview: + """Everything the overview shows, for the `months` months ending today.""" + today = today or business_today() + keys = month_keys(today, months) + full_count = len(keys) - 1 + before_keys = [_shift(keys[0], full_count - i) for i in range(full_count)] + load_from = before_keys[0] if before_keys else keys[0] + data = analytics.load_period(session, date(load_from[0], load_from[1], 1), today) + window = monthly_revenue(session, keys, today, data) + before = monthly_revenue(session, before_keys, today, data) if before_keys else [] + start = date(keys[0][0], keys[0][1], 1) + active = len(session.scalars(select(models.Customer.id).where( + models.Customer.active.is_(True))).all()) + return Overview( + months_n=len(keys), today=today, months=window, + delta=like_for_like(window, before), mix=income_mix(window), + routes=recurring_by_route(session), aging=receivables_by_age(session, today), + rates=rate_points(session, data, start, today), + movement=customer_movement(session, keys, today), active_customers=active) diff --git a/app/charts.py b/app/charts.py index 6ff971b..d089a2e 100644 --- a/app/charts.py +++ b/app/charts.py @@ -2,8 +2,8 @@ Self-contained SVG (no client JS, no external libs) so it satisfies the app CSP and renders inside the offline PWA. Marks are colored with the active theme's CSS -custom properties (var(--color-pool) etc.), so one chart reads correctly in every -theme and in light/dark without per-theme code. All axis/value text uses ink/mist +custom properties (var(--color-pool), the validated --c1..--c3 categorical slots, +--band for target bands), so one chart reads correctly in light and dark. All axis/value text uses ink/mist tokens — never the series color (dataviz rule). Any caller-supplied label is passed through html.escape before it reaches the SVG (customer/tech names are user data). @@ -17,8 +17,7 @@ # Distinct hue families (teal / gold / green / rose) so they separate for most # CVD types; every slice is also directly labelled, which is the secondary # encoding the dataviz guidance requires when relying on ≤4 hues. -_CAT = ["var(--color-pool)", "var(--color-brass)", "var(--cr-green, #10b981)", - "var(--color-safety)"] +_CAT = ["var(--c1)", "var(--c2)", "var(--c3)", "var(--m)"] def _esc(s) -> str: @@ -268,10 +267,10 @@ def y_of(v): parts.append( f'{{ eyebrow }}
-{{ eyebrow }}
{% endif %} +{{ lede }}
{% endif %} +{{ text }}
{%- endmacro %} + +{# Avatar initials disc. #} +{% macro av(name, cls="") -%}{%- endmacro %} + +{# One photo thumbnail with its tag; matches the upload response markup in + app/routers/photos.py. #} +{% macro photo(ph) -%} +{{ user.name }} · {{ "Owner · administrator" if user.role == "admin" else "Technician" }}
Saved on this phone or computer only.
{{ error }}
{% endif %} @@ -21,7 +64,7 @@ #sidebar, #topbar, .no-print { display: none !important; } } -Save these somewhere safe — each one works once, and this is the only time they'll be shown. Print this page or write them down now.
@@ -34,7 +77,7 @@Ends every other session signed in as you. This device stays signed in.
diff --git a/app/templates/analytics.html b/app/templates/analytics.html index 880c607..03a7237 100644 --- a/app/templates/analytics.html +++ b/app/templates/analytics.html @@ -2,68 +2,46 @@ {% block title %}Analytics{% endblock %} {% block content %} {% import "_ui.html" as ui %} -{{ ui.page_header("Business analytics", "Analytics") }} +Money
{% if ov.has_revenue %}{{ v.whole(ov.revenue_cents) }} from {{ '{:,}'.format(ov.visits) }} visit{{ 's' if ov.visits != 1 }}, {{ ov.span }}.{% else %}Nothing billed in {{ ov.span }} yet.{% endif %}{% if ov.flagged %} {{ ov.flagged | length }} {{ 'property costs' if ov.flagged | length == 1 else 'properties cost' }} 15% or more of the rate in chemicals.{% endif %}
+ {% else %} +{{ start | short_date }} – {{ end | short_date }}. Revenue is billed service, chemicals at your markup and finished jobs.
+ {% endif %}Revenue
-{{ summary.revenue_cents | dollars }}
-Profit
-{{ summary.profit_cents | dollars }}
-Visits done
-{{ summary.visits_done }}
-Avg / visit
-{{ summary.avg_per_visit_cents | dollars }}
-Customers
-{{ summary.customer_count }}
-Top customer
- {% if summary.top_customer %} -{{ summary.top_customer }}
-{{ summary.top_customer_cents | dollars }}
- {% else %} -—
- {% endif %} -+
{{ tab_labels[tab] }}{% if tab in ("income", "volume") %} by week{% elif tab in ("customers", "crew", "chemicals") %} ranked{% elif tab == "types" %} mix{% endif %}
{{ chart | safe }} @@ -343,4 +321,5 @@ {% endif %}- {{ totals.total_cents | dollars }} - - outstanding across {{ totals.customer_count }} customer{{ "s" if totals.customer_count != 1 }} -
- -{{ totals.total_cents | dollars }} outstanding across {{ totals.customer_count }} customer{{ "s" if totals.customer_count != 1 }}. Invoices are due {{ net_days }} days after their billing period.
No customer email address, or SMTP is not configured in Settings.
+No customer email address, or SMTP is not configured in Settings.
{% elif request.query_params.get("error") == "payment" %} -Enter a payment amount greater than zero.
+Enter a payment amount greater than zero.
{% endif %}- Invoices are due {{ net_days }} days after the end of their billing period. - Change that in Settings → Business. -
{% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index 0be5290..d0de8dc 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,131 +1,152 @@ -{% set active_theme = (request.state.active_theme if request else none) or 'warm-coastal' %} - +{#- The staff shell (Aqua Atelier). One layout for every screen: + desktop -- deep-water masthead with group tabs and the active group's + pages in a second row, the working sheet floating over it; or, + when the company chose it in Admin › Appearance, a sidebar. + tablet -- masthead with the page title, search and a menu sheet. + phone -- the same, plus a five-slot bottom bar. + A page that sets `bare = true` (sign-in, customer e-sign) gets the plain + centred shell with no staff chrome. -#} +{% set _ui_cfg = (request.state.ui if request is not none and request.state is defined and request.state.ui is defined else {}) %} +{% set _nav_layout = _ui_cfg.get("nav_layout", "top") %} +{% set _hdr = _ui_cfg.get("header_style", "lit") %} +{% set _org = _ui_cfg.get("company", "") %} + - {% set theme_colors = {'warm-coastal': '#16303B', 'control-room': '#0E141B', 'fresh-field': '#0F172A'} %} - + - - + {% include "_mode_head.html" %} + {% include "_palette.html" %}