Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 81b36878b3 | |||
| 97f568f49f | |||
| cf0f176d3f | |||
| 5a41cdae83 | |||
| dfdf2aacb8 | |||
| ced238385e | |||
| 77743019b0 | |||
| f712198319 | |||
| 1ac5df7be5 | |||
| 109ef983f0 | |||
| 083a51023c | |||
| 54762cd421 | |||
| b2aaca5df9 | |||
| 883bc4489e | |||
| 3ad4a21f5b | |||
| 3c1604c7af | |||
| 8b3223f865 | |||
| 276e18a9c8 |
16
.claude/settings.json
Normal file
16
.claude/settings.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(git add:*)",
|
||||
"Bash(go version *)",
|
||||
"Bash(go mod *)",
|
||||
"Bash(golangci-lint run *)",
|
||||
"Bash(golangci-lint --version)",
|
||||
"Bash(gofumpt *)",
|
||||
"Bash(./bin/fuj help *)",
|
||||
"Bash(./bin/fuj version *)",
|
||||
"Bash(make go-test *)",
|
||||
"Bash(make go-lint *)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -31,5 +31,35 @@ jobs:
|
||||
TAG=${{ inputs.tag }}
|
||||
fi
|
||||
IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG
|
||||
docker build -f build/Dockerfile -t $IMAGE .
|
||||
docker build -f build/Dockerfile \
|
||||
--build-arg GIT_TAG=$TAG \
|
||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-t $IMAGE .
|
||||
docker push $IMAGE
|
||||
|
||||
build-go:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Gitea registry
|
||||
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login -u ${{ github.actor }} --password-stdin gitea.home.hrajfrisbee.cz
|
||||
|
||||
- name: Build and push Go image
|
||||
run: |
|
||||
TAG=${{ github.ref_name }}
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
TAG=${{ inputs.tag }}
|
||||
fi
|
||||
IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG-go
|
||||
docker build -f go/build/Dockerfile \
|
||||
--build-arg GIT_TAG=$TAG \
|
||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-t $IMAGE go/
|
||||
docker push $IMAGE
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,3 +4,6 @@
|
||||
|
||||
# local tmp folder
|
||||
tmp/
|
||||
|
||||
# go build output
|
||||
bin/
|
||||
|
||||
38
CHANGELOG.md
Normal file
38
CHANGELOG.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-05-04 23:08 CEST — fix: payment inference exact-match short-circuit
|
||||
|
||||
- `match_members()` now short-circuits on whole-word full-name hits; nickname/partial checks only run when no full name is present.
|
||||
- Replaced bare `in` substring checks with `_word_in()` word-boundary regex throughout, closing the class of bugs where a short nickname (e.g. `tov`) matches inside another member's surname (`ottova`).
|
||||
- Added `tests/test_match_members.py` (6 cases). Affects `scripts/match_payments.py`.
|
||||
|
||||
## 2026-05-04 23:08 CEST — feat: lower adult monthly fee to 700 CZK from April 2026
|
||||
|
||||
- `ADULT_FEE_DEFAULT` reduced from 750 → 700 CZK.
|
||||
- `ADULT_FEE_MONTHLY_RATE` now pins Sep 2025 – Feb 2026 at 750 to preserve historical billing; Mar 2026 stays 350; Apr–May 2026 at 700. Affects `scripts/attendance.py`.
|
||||
|
||||
## 2026-05-04 12:02 CEST — Go rewrite M1: skeleton + tooling
|
||||
|
||||
- Created `go/` tree with module `fuj-management/go` (Go 1.26).
|
||||
- `cmd/fuj`: stdlib-flag subcommand dispatcher; `server` and `version` implemented, stubs for M2/M4 commands.
|
||||
- `internal/config`: env loader mirroring `scripts/config.py` (same env var names and defaults).
|
||||
- `internal/logging`: slog setup accepting log level from config.
|
||||
- `internal/web`: `net/http` ServeMux on `:8080`; `middleware/timer.go` logs method/path/status/ms.
|
||||
- `go/build/Dockerfile`: multi-stage (`golang:1.26` → `alpine:3`) producing a static binary image.
|
||||
- Makefile: `web` → `web-py` alias; added `web-go`, `go-build`, `go-test`, `go-run`, `go-lint`.
|
||||
- `.gitea/workflows/build.yaml`: parallel `build-go` job pushing `<tag>-go` image.
|
||||
- Gate: `make go-build`, `make go-lint`, `make go-test`, `curl :8080` all pass.
|
||||
|
||||
## 2026-05-03 20:37 CEST — Fix Balance column to correctly reflect past-month debt
|
||||
|
||||
- Balance (and Pay-All) are now computed as `sum(paid − expected)` over past months only, iterating directly over the ledger entries from `reconcile()`.
|
||||
- Previously the balance used `total_balance` (which includes current/future-month activity and out-of-window credits) plus a one-sided current-month debt adjustment. Current-month *surplus* leaked through, making the balance appear less negative than the actual past-month debt.
|
||||
- Pay-All is now `max(0, −balance)` so the two values are derived from a single source and can never disagree.
|
||||
- Affected: `adults_view()` and `juniors_view()` in `app.py`.
|
||||
|
||||
## 2026-05-03 19:26 CEST — Fee-aware allocation for multi-month payments
|
||||
|
||||
- `reconcile()` no longer splits a multi-month payment evenly. Allocation is now per-member with two phases: greedy (if amount ≥ total expected, each month gets exactly its expected fee and overflow → credit) and proportional (otherwise distribute by each month's expected). Fixes the case where e.g. 1250 CZK covering 3 months with mixed fees (750/350/150) marked two months red.
|
||||
- Out-of-window months keep the previous even-split-to-credit behavior. Fallback to even split when all matched months have `expected = 0` (prepayment before attendance is recorded).
|
||||
- Display layer only — no changes to how payments are stored in Google Sheets; `Inferred Amount` still holds the full bank amount.
|
||||
- Files: [scripts/match_payments.py](scripts/match_payments.py), [tests/test_reconcile_exceptions.py](tests/test_reconcile_exceptions.py) (6 new test cases).
|
||||
105
CLAUDE.md
105
CLAUDE.md
@@ -16,22 +16,105 @@ Flask-based financial management system for FUJ (Frisbee Ultimate Jablonec). Han
|
||||
This project uses `uv` for dependency management.
|
||||
|
||||
```bash
|
||||
uv venv # Create virtual environment
|
||||
uv sync # Install dependencies from pyproject.toml
|
||||
uv venv && uv sync
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
Alternatively, use the Makefile:
|
||||
- `make sync` - Sync bank transactions to Google Sheets
|
||||
- `make infer` - Automatically infer Person/Purpose/Amount in the sheet
|
||||
- `make reconcile` - Generate balance report from Google Sheets data
|
||||
- `make fees` - Calculate expected fees from attendance
|
||||
- `make match` - (Legacy) Match bank data directly
|
||||
- `make web` - Start dashboard
|
||||
- `make image` - Build Docker image
|
||||
Set `PYTHONPATH=scripts:.` when running scripts directly (the Makefile does this automatically).
|
||||
|
||||
Requires `.secret/fuj-management-bot-credentials.json` for Google Sheets API access (configurable via `CREDENTIALS_PATH` env var).
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
make web # Start dashboard at http://localhost:5001
|
||||
make web-debug # Same with FLASK_DEBUG=1
|
||||
make test # Run all tests (unittest discover)
|
||||
make test-v # Tests with verbose output
|
||||
make fees # Print fee report from attendance sheet
|
||||
make sync-2026 # Sync Fio bank transactions for 2026 to Google Sheets
|
||||
make infer # Auto-fill Person/Purpose/Amount columns in payments sheet
|
||||
make reconcile # Print balance report from Google Sheets data
|
||||
make image # Build Docker image
|
||||
```
|
||||
|
||||
Run a single test:
|
||||
```bash
|
||||
PYTHONPATH=scripts:. python -m unittest tests.test_app.TestWebApp.test_adults_route
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Data flow
|
||||
|
||||
```
|
||||
Google Sheets (attendance) ──► attendance.py ──► reconcile() ──► Flask routes ──► templates/
|
||||
Google Sheets (payments) ──► match_payments.py ──┘
|
||||
Fio Bank API ──► sync_fio_to_sheets.py ──► Google Sheets (payments)
|
||||
```
|
||||
|
||||
### Key modules
|
||||
|
||||
- `app.py` — Flask app; routes for `/adults`, `/juniors`, `/payments`, `/sync-bank`, `/qr`, `/flush-cache`
|
||||
- `scripts/attendance.py` — Fetches attendance CSV from Google Sheets, computes per-member per-month fees. Contains fee rate constants (`ADULT_FEE_DEFAULT`, `JUNIOR_FEE_DEFAULT`) and `ADULT_MERGED_MONTHS` / `JUNIOR_MERGED_MONTHS` dicts.
|
||||
- `scripts/match_payments.py` — `reconcile()` matches transactions to members/months. `fetch_sheet_data()` reads the payments sheet. `fetch_exceptions()` reads the `exceptions` tab.
|
||||
- `scripts/cache_utils.py` — Invalidation via Google Drive API `modifiedTime`; falls back to 5-minute TTL buckets when Drive API is unavailable. Cache files live in `tmp/`.
|
||||
- `scripts/sync_fio_to_sheets.py` — Pulls Fio bank transactions and appends them to the payments Google Sheet.
|
||||
- `scripts/infer_payments.py` — Fills in Person/Purpose/Inferred Amount columns using name-matching heuristics.
|
||||
- `scripts/config.py` — All external IDs, paths, and tunable TTLs. Override via env vars (`CREDENTIALS_PATH`, `BANK_ACCOUNT`, `CACHE_TTL_SECONDS`).
|
||||
|
||||
### Member tiers
|
||||
|
||||
Tiers are set in column B of the attendance sheet:
|
||||
- `A` — Adult, pays fees (750 CZK/month for 2+ sessions, 200 CZK for exactly 1)
|
||||
- `J` — Junior attending adult practices; their attendance is merged with the junior sheet
|
||||
- `X` — Excluded from junior fee calculation (coaches, etc.)
|
||||
|
||||
### Fee calculation
|
||||
|
||||
- Adults: 0 sessions → 0, 1 session → 200 CZK, 2+ sessions → monthly rate (default 750 CZK)
|
||||
- Juniors: 0 → 0, 1 → `"?"` (manual review required), 2+ → monthly rate (default 500 CZK)
|
||||
- Per-member per-month overrides live in the `exceptions` tab of the payments sheet (columns: Name, Period YYYY-MM, Amount, Note). Exceptions are keyed by `(normalize(name), normalize(period))`.
|
||||
|
||||
### Merged months
|
||||
|
||||
`ADULT_MERGED_MONTHS` / `JUNIOR_MERGED_MONTHS` in `attendance.py` map a source month to a target month (e.g., `"2025-12": "2026-01"` merges December into January billing). The target month accumulates attendance from both months.
|
||||
|
||||
### Caching
|
||||
|
||||
`get_cached_data()` in `app.py` checks the Drive API `modifiedTime` before each request and serves a JSON file from `tmp/` when the sheet hasn't changed. Cache is warmed up at startup (`warmup_cache()`). Flush via `/flush-cache` (POST) or `flush_cache()`.
|
||||
|
||||
### Payments sheet columns
|
||||
|
||||
`Date | Amount | manual fix | Person | Purpose | Inferred Amount | Sender | VS | Message | Bank ID | Sync ID`
|
||||
|
||||
`Person` and `Purpose` are written by `infer_payments.py` and can be manually corrected. `manual fix` column presence disables re-inference for that row. Multiple people or months are comma-separated in Person/Purpose.
|
||||
|
||||
### QR codes
|
||||
|
||||
`/qr?account=…&amount=…&message=…` generates a Czech QR Platba PNG (SPD format).
|
||||
|
||||
## Git Commits
|
||||
|
||||
When making git commits, always append yourself as co-author trailer to the end of the commit message to indicate AI assistance
|
||||
|
||||
## Changelog
|
||||
|
||||
Maintain a running changelog in `CHANGELOG.md` at the repo root. After every significant change, fix, or update — once the user confirms it works — append a new entry **at the top** of the file in this format:
|
||||
|
||||
```markdown
|
||||
## YYYY-MM-DD HH:MM TZ — short title
|
||||
|
||||
- One-line summary of what changed and why.
|
||||
- Key files touched (optional, only if useful for traceability).
|
||||
```
|
||||
|
||||
Get the timestamp with `date "+%Y-%m-%d %H:%M %Z"`. Skip trivial edits (typos, formatting, comment tweaks); only log changes a future reader would care about.
|
||||
|
||||
## Plans
|
||||
|
||||
When Claude Code's plan mode is used, save the plan file inside the repo at
|
||||
`docs/plans/YYYY-MM-DD-HHMM-<slug>.md` instead of the default `~/.claude/plans/`
|
||||
location. Get the timestamp with `date "+%Y-%m-%d-%H%M"` (matches the changelog
|
||||
convention). The `<slug>` should be a short kebab-case summary of the plan's topic.
|
||||
|
||||
Create the `docs/plans/` directory on first use. Plan files are committed to the
|
||||
repo so other contributors can review historical decisions.
|
||||
|
||||
51
Makefile
51
Makefile
@@ -1,10 +1,13 @@
|
||||
.PHONY: help fees match web web-debug image run sync sync-2026 test test-v docs
|
||||
.PHONY: help fees match web web-py web-debug web-go go-build go-test go-run go-lint image run sync sync-2026 test test-v docs
|
||||
|
||||
export PYTHONPATH := scripts:$(PYTHONPATH)
|
||||
VENV := .venv
|
||||
PYTHON := $(VENV)/bin/python3
|
||||
CREDENTIALS := .secret/fuj-management-bot-credentials.json
|
||||
|
||||
GO_SRC := go
|
||||
GO_BIN := bin/fuj
|
||||
|
||||
$(PYTHON): .venv/.last_sync
|
||||
|
||||
.venv/.last_sync: pyproject.toml
|
||||
@@ -15,18 +18,23 @@ help:
|
||||
@echo "Available targets:"
|
||||
@echo " make fees - Calculate monthly fees from the attendance sheet"
|
||||
@echo " make match - Match Fio bank payments against expected attendance fees"
|
||||
@echo " make web - Start a dynamic web dashboard locally"
|
||||
@echo " make web-debug - Start a dynamic web dashboard locally in debug mode"
|
||||
@echo " make image - Build an OCI container image"
|
||||
@echo " make run - Run the built Docker image locally"
|
||||
@echo " make web - Start Python dashboard (alias for web-py, until M8)"
|
||||
@echo " make web-py - Start Python dashboard on :5001"
|
||||
@echo " make web-go - Build and start Go dashboard on :8080"
|
||||
@echo " make web-debug - Start Python dashboard in debug mode"
|
||||
@echo " make go-build - Build Go binary to bin/fuj"
|
||||
@echo " make go-test - Run Go tests"
|
||||
@echo " make go-lint - Run golangci-lint on Go code"
|
||||
@echo " make image - Build Python OCI container image"
|
||||
@echo " make run - Run the built Python Docker image locally"
|
||||
@echo " make sync - Sync Fio transactions to Google Sheets"
|
||||
@echo " make sync-2025 - Sync Fio transactions for Q4 2025 (Oct-Dec)"
|
||||
@echo " make sync-2026 - Sync Fio transactions for the whole year of 2026"
|
||||
@echo " make infer - Infer payment details (Person, Purpose, Amount) in the sheet"
|
||||
@echo " make reconcile - Show balance report using Google Sheets data"
|
||||
@echo " make venv - Sync virtual environment with pyproject.toml"
|
||||
@echo " make test - Run web application infrastructure tests"
|
||||
@echo " make test-v - Run tests with verbose output"
|
||||
@echo " make test - Run Python web application infrastructure tests"
|
||||
@echo " make test-v - Run Python tests with verbose output"
|
||||
@echo " make docs - Serve documentation in a browser"
|
||||
|
||||
venv:
|
||||
@@ -38,14 +46,39 @@ fees: $(PYTHON)
|
||||
match: $(PYTHON)
|
||||
$(PYTHON) scripts/match_payments.py
|
||||
|
||||
web: $(PYTHON)
|
||||
web: web-py
|
||||
|
||||
web-py: $(PYTHON)
|
||||
$(PYTHON) app.py
|
||||
|
||||
web-debug: $(PYTHON)
|
||||
FLASK_DEBUG=1 $(PYTHON) app.py
|
||||
|
||||
go-build:
|
||||
cd $(GO_SRC) && go build -trimpath \
|
||||
-ldflags "-X main.version=$$(git describe --tags --always 2>/dev/null || echo dev) \
|
||||
-X main.commit=$$(git rev-parse --short HEAD) \
|
||||
-X main.buildDate=$$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
-o ../$(GO_BIN) ./cmd/fuj
|
||||
|
||||
go-test:
|
||||
cd $(GO_SRC) && go test -race ./...
|
||||
|
||||
go-run: go-build
|
||||
./$(GO_BIN) $(ARGS)
|
||||
|
||||
go-lint:
|
||||
cd $(GO_SRC) && golangci-lint run ./...
|
||||
|
||||
web-go: go-build
|
||||
./$(GO_BIN) server
|
||||
|
||||
image:
|
||||
docker build -t fuj-management:latest -f build/Dockerfile .
|
||||
docker build -t fuj-management:latest \
|
||||
--build-arg GIT_TAG=$$(git describe --tags --always 2>/dev/null || echo "untagged") \
|
||||
--build-arg GIT_COMMIT=$$(git rev-parse --short HEAD) \
|
||||
--build-arg BUILD_DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-f build/Dockerfile .
|
||||
|
||||
run:
|
||||
docker run -it --rm -p 5001:5001 -v $(CURDIR)/.secret:/app/.secret:ro fuj-management:latest
|
||||
|
||||
492
app.py
492
app.py
@@ -23,7 +23,9 @@ from config import (
|
||||
)
|
||||
from attendance import get_members_with_fees, get_junior_members_with_fees, ADULT_MERGED_MONTHS, JUNIOR_MERGED_MONTHS
|
||||
from match_payments import reconcile, fetch_sheet_data, fetch_exceptions, normalize
|
||||
from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED
|
||||
from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED, flush_cache
|
||||
from sync_fio_to_sheets import sync_to_sheets
|
||||
from infer_payments import infer_payments
|
||||
|
||||
def get_cached_data(cache_key, sheet_id, fetch_func, *args, serialize=None, deserialize=None, **kwargs):
|
||||
mod_time = get_sheet_modified_time(cache_key)
|
||||
@@ -72,6 +74,13 @@ def warmup_cache():
|
||||
logger.info("Cache warmup complete.")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import json as _json
|
||||
_meta_path = Path(__file__).parent / "build_meta.json"
|
||||
BUILD_META = _json.loads(_meta_path.read_text()) if _meta_path.exists() else {
|
||||
"tag": "dev", "commit": "local", "build_date": ""
|
||||
}
|
||||
|
||||
warmup_cache()
|
||||
|
||||
@app.before_request
|
||||
@@ -101,157 +110,52 @@ def inject_render_time():
|
||||
"total": f"{total:.3f}",
|
||||
"breakdown": " | ".join(breakdown)
|
||||
}
|
||||
return dict(get_render_time=get_render_time)
|
||||
return dict(get_render_time=get_render_time, build_meta=BUILD_META)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
# Redirect root to /adults for convenience while there are no other apps
|
||||
return '<meta http-equiv="refresh" content="0; url=/adults" />'
|
||||
|
||||
@app.route("/fees")
|
||||
def fees():
|
||||
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit"
|
||||
payments_url = f"https://docs.google.com/spreadsheets/d/{PAYMENTS_SHEET_ID}/edit"
|
||||
@app.route("/flush-cache", methods=["GET", "POST"])
|
||||
def flush_cache_endpoint():
|
||||
if request.method == "GET":
|
||||
return render_template("flush-cache.html")
|
||||
deleted = flush_cache()
|
||||
return render_template("flush-cache.html", flushed=True, deleted=deleted)
|
||||
|
||||
members_data = get_cached_data("attendance_regular", ATTENDANCE_SHEET_ID, get_members_with_fees)
|
||||
record_step("fetch_members")
|
||||
if not members_data:
|
||||
return "No data."
|
||||
members, sorted_months = members_data
|
||||
|
||||
# Filter to adults only for display
|
||||
results = [(name, fees) for name, tier, fees in members if tier == "A"]
|
||||
|
||||
# Format month labels
|
||||
month_labels = get_month_labels(sorted_months, ADULT_MERGED_MONTHS)
|
||||
|
||||
monthly_totals = {m: 0 for m in sorted_months}
|
||||
|
||||
# Get exceptions for formatting
|
||||
credentials_path = CREDENTIALS_PATH
|
||||
exceptions = get_cached_data(
|
||||
"exceptions_dict", PAYMENTS_SHEET_ID, fetch_exceptions,
|
||||
PAYMENTS_SHEET_ID, credentials_path,
|
||||
serialize=lambda d: [[list(k), v] for k, v in d.items()],
|
||||
deserialize=lambda c: {tuple(k): v for k, v in c},
|
||||
@app.route("/sync-bank")
|
||||
def sync_bank():
|
||||
import contextlib
|
||||
output = io.StringIO()
|
||||
success = True
|
||||
try:
|
||||
with contextlib.redirect_stdout(output), contextlib.redirect_stderr(output):
|
||||
# sync_to_sheets: equivalent of make sync-2026
|
||||
output.write("=== Syncing Fio transactions (2026) ===\n")
|
||||
sync_to_sheets(
|
||||
spreadsheet_id=PAYMENTS_SHEET_ID,
|
||||
credentials_path=CREDENTIALS_PATH,
|
||||
date_from_str="2026-01-01",
|
||||
date_to_str="2026-12-31",
|
||||
sort_by_date=True,
|
||||
)
|
||||
record_step("fetch_exceptions")
|
||||
output.write("\n=== Inferring payment details ===\n")
|
||||
infer_payments(PAYMENTS_SHEET_ID, CREDENTIALS_PATH)
|
||||
output.write("\n=== Flushing cache ===\n")
|
||||
deleted = flush_cache()
|
||||
output.write(f"Deleted {deleted} cache files.\n")
|
||||
output.write("\n=== Done ===\n")
|
||||
except Exception as e:
|
||||
import traceback
|
||||
output.write(f"\n!!! Error: {e}\n")
|
||||
output.write(traceback.format_exc())
|
||||
success = False
|
||||
return render_template("sync.html", output=output.getvalue(), success=success)
|
||||
|
||||
formatted_results = []
|
||||
for name, month_fees in results:
|
||||
row = {"name": name, "months": []}
|
||||
norm_name = normalize(name)
|
||||
for m in sorted_months:
|
||||
fee, count = month_fees.get(m, (0, 0))
|
||||
|
||||
# Check for exception
|
||||
norm_period = normalize(m)
|
||||
ex_data = exceptions.get((norm_name, norm_period))
|
||||
override_amount = ex_data["amount"] if ex_data else None
|
||||
|
||||
if override_amount is not None and override_amount != fee:
|
||||
cell = f"{override_amount} ({fee}) CZK ({count})" if count > 0 else f"{override_amount} ({fee}) CZK"
|
||||
is_overridden = True
|
||||
else:
|
||||
if isinstance(fee, int):
|
||||
monthly_totals[m] += fee
|
||||
cell = f"{fee} CZK ({count})" if count > 0 else "-"
|
||||
is_overridden = False
|
||||
row["months"].append({"cell": cell, "overridden": is_overridden})
|
||||
formatted_results.append(row)
|
||||
|
||||
record_step("process_data")
|
||||
|
||||
return render_template(
|
||||
"fees.html",
|
||||
months=[month_labels[m] for m in sorted_months],
|
||||
results=formatted_results,
|
||||
totals=[f"{monthly_totals[m]} CZK" for m in sorted_months],
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url
|
||||
)
|
||||
|
||||
@app.route("/fees-juniors")
|
||||
def fees_juniors():
|
||||
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit#gid={JUNIOR_SHEET_GID}"
|
||||
payments_url = f"https://docs.google.com/spreadsheets/d/{PAYMENTS_SHEET_ID}/edit"
|
||||
|
||||
members_data = get_cached_data("attendance_juniors", ATTENDANCE_SHEET_ID, get_junior_members_with_fees)
|
||||
record_step("fetch_junior_members")
|
||||
if not members_data:
|
||||
return "No data."
|
||||
members, sorted_months = members_data
|
||||
|
||||
# Sort members by name
|
||||
results = sorted([(name, fees) for name, tier, fees in members], key=lambda x: x[0])
|
||||
|
||||
# Format month labels
|
||||
month_labels = get_month_labels(sorted_months, JUNIOR_MERGED_MONTHS)
|
||||
|
||||
monthly_totals = {m: 0 for m in sorted_months}
|
||||
|
||||
# Get exceptions for formatting (reusing payments sheet)
|
||||
credentials_path = CREDENTIALS_PATH
|
||||
exceptions = get_cached_data(
|
||||
"exceptions_dict", PAYMENTS_SHEET_ID, fetch_exceptions,
|
||||
PAYMENTS_SHEET_ID, credentials_path,
|
||||
serialize=lambda d: [[list(k), v] for k, v in d.items()],
|
||||
deserialize=lambda c: {tuple(k): v for k, v in c},
|
||||
)
|
||||
record_step("fetch_exceptions")
|
||||
|
||||
formatted_results = []
|
||||
for name, month_fees in results:
|
||||
row = {"name": name, "months": []}
|
||||
norm_name = normalize(name)
|
||||
for m in sorted_months:
|
||||
fee_data = month_fees.get(m, (0, 0, 0, 0))
|
||||
if len(fee_data) == 4:
|
||||
fee, total_count, adult_count, junior_count = fee_data
|
||||
else:
|
||||
fee, total_count = fee_data
|
||||
adult_count, junior_count = 0, 0
|
||||
|
||||
# Check for exception
|
||||
norm_period = normalize(m)
|
||||
ex_data = exceptions.get((norm_name, norm_period))
|
||||
override_amount = ex_data["amount"] if ex_data else None
|
||||
|
||||
if ex_data is None and isinstance(fee, int):
|
||||
monthly_totals[m] += fee
|
||||
|
||||
# Formulate the count string display
|
||||
if adult_count > 0 and junior_count > 0:
|
||||
count_str = f"{total_count} ({adult_count}A+{junior_count}J)"
|
||||
elif adult_count > 0:
|
||||
count_str = f"{total_count} (A)"
|
||||
elif junior_count > 0:
|
||||
count_str = f"{total_count} (J)"
|
||||
else:
|
||||
count_str = f"{total_count}"
|
||||
|
||||
if override_amount is not None and override_amount != fee:
|
||||
cell = f"{override_amount} ({fee}) CZK / {count_str}" if total_count > 0 else f"{override_amount} ({fee}) CZK"
|
||||
is_overridden = True
|
||||
else:
|
||||
if fee == "?":
|
||||
cell = f"? / {count_str}" if total_count > 0 else "-"
|
||||
else:
|
||||
cell = f"{fee} CZK / {count_str}" if total_count > 0 else "-"
|
||||
is_overridden = False
|
||||
row["months"].append({"cell": cell, "overridden": is_overridden})
|
||||
formatted_results.append(row)
|
||||
|
||||
record_step("process_data")
|
||||
|
||||
return render_template(
|
||||
"fees-juniors.html",
|
||||
months=[month_labels[m] for m in sorted_months],
|
||||
results=formatted_results,
|
||||
totals=[f"{t} CZK" if isinstance(t, int) else t for t in monthly_totals.values()],
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url
|
||||
)
|
||||
@app.route("/version")
|
||||
def version():
|
||||
return BUILD_META
|
||||
|
||||
@app.route("/adults")
|
||||
def adults_view():
|
||||
@@ -279,13 +183,15 @@ def adults_view():
|
||||
|
||||
month_labels = get_month_labels(sorted_months, ADULT_MERGED_MONTHS)
|
||||
adult_names = sorted([name for name, tier, _ in members if tier == "A"])
|
||||
current_month = datetime.now().strftime("%Y-%m")
|
||||
|
||||
monthly_totals = {m: {"expected": 0, "paid": 0} for m in sorted_months}
|
||||
formatted_results = []
|
||||
for name in adult_names:
|
||||
data = result["members"][name]
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""}
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
|
||||
unpaid_months = []
|
||||
raw_unpaid_months = []
|
||||
for m in sorted_months:
|
||||
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None})
|
||||
expected = mdata.get("expected", 0)
|
||||
@@ -318,11 +224,15 @@ def adults_view():
|
||||
elif paid > 0:
|
||||
status = "partial"
|
||||
cell_text = f"{paid}/{fee_display}"
|
||||
if m < current_month:
|
||||
unpaid_months.append(month_labels[m])
|
||||
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
|
||||
else:
|
||||
status = "unpaid"
|
||||
cell_text = f"0/{fee_display}"
|
||||
if m < current_month:
|
||||
unpaid_months.append(month_labels[m])
|
||||
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
|
||||
elif paid > 0:
|
||||
status = "surplus"
|
||||
cell_text = f"PAID {paid}"
|
||||
@@ -341,11 +251,24 @@ def adults_view():
|
||||
"status": status,
|
||||
"amount": amount_to_pay,
|
||||
"month": month_labels[m],
|
||||
"raw_month": m,
|
||||
"tooltip": tooltip
|
||||
})
|
||||
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
|
||||
row["balance"] = data["total_balance"]
|
||||
# Balance = sum of (paid - expected) for past months only; current/future months ignored.
|
||||
settled_balance = 0
|
||||
for m, mdata in data["months"].items():
|
||||
if m >= current_month:
|
||||
continue
|
||||
exp = mdata.get("expected", 0)
|
||||
if isinstance(exp, int):
|
||||
settled_balance += int(mdata.get("paid", 0)) - exp
|
||||
|
||||
payable_amount = max(0, -settled_balance)
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months)
|
||||
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
|
||||
row["balance"] = settled_balance
|
||||
row["payable_amount"] = payable_amount
|
||||
formatted_results.append(row)
|
||||
|
||||
formatted_totals = []
|
||||
@@ -365,8 +288,19 @@ def adults_view():
|
||||
"status": status
|
||||
})
|
||||
|
||||
credits = sorted([{"name": n, "amount": a["total_balance"]} for n, a in result["members"].items() if a["total_balance"] > 0 and n in adult_names], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(a["total_balance"])} for n, a in result["members"].items() if a["total_balance"] < 0 and n in adult_names], key=lambda x: x["name"])
|
||||
def settled_balance(name):
|
||||
data = result["members"][name]
|
||||
total = 0
|
||||
for m, mdata in data["months"].items():
|
||||
if m >= current_month:
|
||||
continue
|
||||
exp = mdata.get("expected", 0)
|
||||
if isinstance(exp, int):
|
||||
total += int(mdata.get("paid", 0)) - exp
|
||||
return total
|
||||
|
||||
credits = sorted([{"name": n, "amount": settled_balance(n)} for n in adult_names if settled_balance(n) > 0], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(settled_balance(n))} for n in adult_names if settled_balance(n) < 0], key=lambda x: x["name"])
|
||||
unmatched = result["unmatched"]
|
||||
import json
|
||||
|
||||
@@ -385,106 +319,8 @@ def adults_view():
|
||||
unmatched=unmatched,
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url,
|
||||
bank_account=BANK_ACCOUNT
|
||||
)
|
||||
|
||||
@app.route("/reconcile")
|
||||
def reconcile_view():
|
||||
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit"
|
||||
payments_url = f"https://docs.google.com/spreadsheets/d/{PAYMENTS_SHEET_ID}/edit"
|
||||
|
||||
# Use hardcoded credentials path for now, consistent with other scripts
|
||||
credentials_path = CREDENTIALS_PATH
|
||||
|
||||
members_data = get_cached_data("attendance_regular", ATTENDANCE_SHEET_ID, get_members_with_fees)
|
||||
record_step("fetch_members")
|
||||
if not members_data:
|
||||
return "No data."
|
||||
members, sorted_months = members_data
|
||||
|
||||
transactions = get_cached_data("payments_transactions", PAYMENTS_SHEET_ID, fetch_sheet_data, PAYMENTS_SHEET_ID, credentials_path)
|
||||
record_step("fetch_payments")
|
||||
exceptions = get_cached_data(
|
||||
"exceptions_dict", PAYMENTS_SHEET_ID, fetch_exceptions,
|
||||
PAYMENTS_SHEET_ID, credentials_path,
|
||||
serialize=lambda d: [[list(k), v] for k, v in d.items()],
|
||||
deserialize=lambda c: {tuple(k): v for k, v in c},
|
||||
)
|
||||
record_step("fetch_exceptions")
|
||||
result = reconcile(members, sorted_months, transactions, exceptions)
|
||||
record_step("reconcile")
|
||||
|
||||
# Format month labels
|
||||
month_labels = get_month_labels(sorted_months, ADULT_MERGED_MONTHS)
|
||||
|
||||
# Filter to adults for the main table
|
||||
adult_names = sorted([name for name, tier, _ in members if tier == "A"])
|
||||
|
||||
formatted_results = []
|
||||
for name in adult_names:
|
||||
data = result["members"][name]
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""}
|
||||
unpaid_months = []
|
||||
for m in sorted_months:
|
||||
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0})
|
||||
expected = mdata["expected"]
|
||||
paid = int(mdata["paid"])
|
||||
|
||||
status = "empty"
|
||||
cell_text = "-"
|
||||
amount_to_pay = 0
|
||||
|
||||
if expected > 0:
|
||||
if paid >= expected:
|
||||
status = "ok"
|
||||
cell_text = "OK"
|
||||
elif paid > 0:
|
||||
status = "partial"
|
||||
cell_text = f"{paid}/{expected}"
|
||||
amount_to_pay = expected - paid
|
||||
unpaid_months.append(month_labels[m])
|
||||
else:
|
||||
status = "unpaid"
|
||||
cell_text = f"UNPAID {expected}"
|
||||
amount_to_pay = expected
|
||||
unpaid_months.append(month_labels[m])
|
||||
elif paid > 0:
|
||||
status = "surplus"
|
||||
cell_text = f"PAID {paid}"
|
||||
|
||||
row["months"].append({
|
||||
"text": cell_text,
|
||||
"status": status,
|
||||
"amount": amount_to_pay,
|
||||
"month": month_labels[m]
|
||||
})
|
||||
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
|
||||
row["balance"] = data["total_balance"] # Updated to use total_balance
|
||||
formatted_results.append(row)
|
||||
|
||||
# Format credits and debts
|
||||
credits = sorted([{"name": n, "amount": a["total_balance"]} for n, a in result["members"].items() if a["total_balance"] > 0 and n in adult_names], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(a["total_balance"])} for n, a in result["members"].items() if a["total_balance"] < 0 and n in adult_names], key=lambda x: x["name"])
|
||||
# Format unmatched
|
||||
unmatched = result["unmatched"]
|
||||
import json
|
||||
|
||||
record_step("process_data")
|
||||
|
||||
return render_template(
|
||||
"reconcile.html",
|
||||
months=[month_labels[m] for m in sorted_months],
|
||||
raw_months=sorted_months,
|
||||
results=formatted_results,
|
||||
member_data=json.dumps(result["members"]),
|
||||
month_labels_json=json.dumps(month_labels),
|
||||
credits=credits,
|
||||
debts=debts,
|
||||
unmatched=unmatched,
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url,
|
||||
bank_account=BANK_ACCOUNT
|
||||
bank_account=BANK_ACCOUNT,
|
||||
current_month=current_month
|
||||
)
|
||||
|
||||
@app.route("/juniors")
|
||||
@@ -531,13 +367,15 @@ def juniors_view():
|
||||
month_labels = get_month_labels(sorted_months, JUNIOR_MERGED_MONTHS)
|
||||
junior_names = sorted([name for name, tier, _ in adapted_members])
|
||||
junior_members_dict = {name: fees_dict for name, _, fees_dict in junior_members}
|
||||
current_month = datetime.now().strftime("%Y-%m")
|
||||
|
||||
monthly_totals = {m: {"expected": 0, "paid": 0} for m in sorted_months}
|
||||
formatted_results = []
|
||||
for name in junior_names:
|
||||
data = result["members"][name]
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""}
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": "", "raw_unpaid_periods": ""}
|
||||
unpaid_months = []
|
||||
raw_unpaid_months = []
|
||||
for m in sorted_months:
|
||||
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "attendance_count": 0, "paid": 0, "exception": None})
|
||||
expected = mdata.get("expected", 0)
|
||||
@@ -582,7 +420,7 @@ def juniors_view():
|
||||
if expected == "?" or (isinstance(expected, int) and expected > 0):
|
||||
if expected == "?":
|
||||
status = "empty"
|
||||
cell_text = "?"
|
||||
cell_text = f"?{count_str}"
|
||||
elif paid >= expected:
|
||||
status = "ok"
|
||||
cell_text = f"{paid}/{fee_display}"
|
||||
@@ -590,12 +428,16 @@ def juniors_view():
|
||||
status = "partial"
|
||||
cell_text = f"{paid}/{fee_display}"
|
||||
amount_to_pay = expected - paid
|
||||
if m < current_month:
|
||||
unpaid_months.append(month_labels[m])
|
||||
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
|
||||
else:
|
||||
status = "unpaid"
|
||||
cell_text = f"0/{fee_display}"
|
||||
amount_to_pay = expected
|
||||
if m < current_month:
|
||||
unpaid_months.append(month_labels[m])
|
||||
raw_unpaid_months.append(datetime.strptime(m, "%Y-%m").strftime("%m/%Y"))
|
||||
elif paid > 0:
|
||||
status = "surplus"
|
||||
cell_text = f"PAID {paid}"
|
||||
@@ -611,11 +453,24 @@ def juniors_view():
|
||||
"status": status,
|
||||
"amount": amount_to_pay,
|
||||
"month": month_labels[m],
|
||||
"raw_month": m,
|
||||
"tooltip": tooltip
|
||||
})
|
||||
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
|
||||
row["balance"] = data["total_balance"]
|
||||
# Balance = sum of (paid - expected) for past months only; current/future months ignored.
|
||||
settled_balance = 0
|
||||
for m, mdata in data["months"].items():
|
||||
if m >= current_month:
|
||||
continue
|
||||
exp = mdata.get("expected", 0)
|
||||
if isinstance(exp, int):
|
||||
settled_balance += int(mdata.get("paid", 0)) - exp
|
||||
|
||||
payable_amount = max(0, -settled_balance)
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months)
|
||||
row["raw_unpaid_periods"] = "+".join(raw_unpaid_months)
|
||||
row["balance"] = settled_balance
|
||||
row["payable_amount"] = payable_amount
|
||||
formatted_results.append(row)
|
||||
|
||||
formatted_totals = []
|
||||
@@ -636,8 +491,20 @@ def juniors_view():
|
||||
})
|
||||
|
||||
# Format credits and debts
|
||||
credits = sorted([{"name": n, "amount": a["total_balance"]} for n, a in result["members"].items() if a["total_balance"] > 0], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(a["total_balance"])} for n, a in result["members"].items() if a["total_balance"] < 0], key=lambda x: x["name"])
|
||||
def junior_settled_balance(name):
|
||||
data = result["members"][name]
|
||||
total = 0
|
||||
for m, mdata in data["months"].items():
|
||||
if m >= current_month:
|
||||
continue
|
||||
exp = mdata.get("expected", 0)
|
||||
if isinstance(exp, int):
|
||||
total += int(mdata.get("paid", 0)) - exp
|
||||
return total
|
||||
|
||||
junior_all_names = [name for name, _, _ in adapted_members]
|
||||
credits = sorted([{"name": n, "amount": junior_settled_balance(n)} for n in junior_all_names if junior_settled_balance(n) > 0], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(junior_settled_balance(n))} for n in junior_all_names if junior_settled_balance(n) < 0], key=lambda x: x["name"])
|
||||
unmatched = result["unmatched"]
|
||||
import json
|
||||
|
||||
@@ -656,121 +523,8 @@ def juniors_view():
|
||||
unmatched=unmatched,
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url,
|
||||
bank_account=BANK_ACCOUNT
|
||||
)
|
||||
|
||||
@app.route("/reconcile-juniors")
|
||||
def reconcile_juniors_view():
|
||||
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit#gid={JUNIOR_SHEET_GID}"
|
||||
payments_url = f"https://docs.google.com/spreadsheets/d/{PAYMENTS_SHEET_ID}/edit"
|
||||
|
||||
credentials_path = CREDENTIALS_PATH
|
||||
|
||||
junior_members_data = get_cached_data("attendance_juniors", ATTENDANCE_SHEET_ID, get_junior_members_with_fees)
|
||||
record_step("fetch_junior_members")
|
||||
if not junior_members_data:
|
||||
return "No data."
|
||||
junior_members, sorted_months = junior_members_data
|
||||
|
||||
transactions = get_cached_data("payments_transactions", PAYMENTS_SHEET_ID, fetch_sheet_data, PAYMENTS_SHEET_ID, credentials_path)
|
||||
record_step("fetch_payments")
|
||||
exceptions = get_cached_data(
|
||||
"exceptions_dict", PAYMENTS_SHEET_ID, fetch_exceptions,
|
||||
PAYMENTS_SHEET_ID, credentials_path,
|
||||
serialize=lambda d: [[list(k), v] for k, v in d.items()],
|
||||
deserialize=lambda c: {tuple(k): v for k, v in c},
|
||||
)
|
||||
record_step("fetch_exceptions")
|
||||
|
||||
# Adapt junior tuple format (name, tier, {month: (fee, total_count, adult_count, junior_count)})
|
||||
# to what match_payments expects: (name, tier, {month: (expected_fee, attendance_count)})
|
||||
adapted_members = []
|
||||
for name, tier, fees_dict in junior_members:
|
||||
adapted_fees = {}
|
||||
for m, fee_data in fees_dict.items():
|
||||
if len(fee_data) == 4:
|
||||
fee, total_count, _, _ = fee_data
|
||||
adapted_fees[m] = (fee, total_count)
|
||||
else:
|
||||
fee, count = fee_data
|
||||
adapted_fees[m] = (fee, count)
|
||||
adapted_members.append((name, tier, adapted_fees))
|
||||
|
||||
result = reconcile(adapted_members, sorted_months, transactions, exceptions)
|
||||
record_step("reconcile")
|
||||
|
||||
# Format month labels
|
||||
month_labels = get_month_labels(sorted_months, JUNIOR_MERGED_MONTHS)
|
||||
|
||||
# Filter to juniors for the main table
|
||||
junior_names = sorted([name for name, tier, _ in adapted_members])
|
||||
|
||||
formatted_results = []
|
||||
for name in junior_names:
|
||||
data = result["members"][name]
|
||||
row = {"name": name, "months": [], "balance": data["total_balance"], "unpaid_periods": ""}
|
||||
unpaid_months = []
|
||||
for m in sorted_months:
|
||||
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0})
|
||||
expected = mdata["expected"]
|
||||
paid = int(mdata["paid"])
|
||||
|
||||
status = "empty"
|
||||
cell_text = "-"
|
||||
amount_to_pay = 0
|
||||
|
||||
if expected == "?" or (isinstance(expected, int) and expected > 0):
|
||||
if expected == "?":
|
||||
status = "empty"
|
||||
cell_text = "?"
|
||||
elif paid >= expected:
|
||||
status = "ok"
|
||||
cell_text = "OK"
|
||||
elif paid > 0:
|
||||
status = "partial"
|
||||
cell_text = f"{paid}/{expected}"
|
||||
amount_to_pay = expected - paid
|
||||
unpaid_months.append(month_labels[m])
|
||||
else:
|
||||
status = "unpaid"
|
||||
cell_text = f"UNPAID {expected}"
|
||||
amount_to_pay = expected
|
||||
unpaid_months.append(month_labels[m])
|
||||
elif paid > 0:
|
||||
status = "surplus"
|
||||
cell_text = f"PAID {paid}"
|
||||
|
||||
row["months"].append({
|
||||
"text": cell_text,
|
||||
"status": status,
|
||||
"amount": amount_to_pay,
|
||||
"month": month_labels[m]
|
||||
})
|
||||
|
||||
row["unpaid_periods"] = ", ".join(unpaid_months) if unpaid_months else ("Older debt" if data["total_balance"] < 0 else "")
|
||||
row["balance"] = data["total_balance"]
|
||||
formatted_results.append(row)
|
||||
|
||||
# Format credits and debts
|
||||
credits = sorted([{"name": n, "amount": a["total_balance"]} for n, a in result["members"].items() if a["total_balance"] > 0], key=lambda x: x["name"])
|
||||
debts = sorted([{"name": n, "amount": abs(a["total_balance"])} for n, a in result["members"].items() if a["total_balance"] < 0], key=lambda x: x["name"])
|
||||
import json
|
||||
|
||||
record_step("process_data")
|
||||
|
||||
return render_template(
|
||||
"reconcile-juniors.html",
|
||||
months=[month_labels[m] for m in sorted_months],
|
||||
raw_months=sorted_months,
|
||||
results=formatted_results,
|
||||
member_data=json.dumps(result["members"]),
|
||||
month_labels_json=json.dumps(month_labels),
|
||||
credits=credits,
|
||||
debts=debts,
|
||||
unmatched=[],
|
||||
attendance_url=attendance_url,
|
||||
payments_url=payments_url,
|
||||
bank_account=BANK_ACCOUNT
|
||||
bank_account=BANK_ACCOUNT,
|
||||
current_month=current_month
|
||||
)
|
||||
|
||||
@app.route("/payments")
|
||||
|
||||
@@ -24,6 +24,17 @@ COPY templates/ ./templates/
|
||||
COPY build/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ARG GIT_TAG=unknown
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_DATE=unknown
|
||||
|
||||
LABEL org.opencontainers.image.version="${GIT_TAG}" \
|
||||
org.opencontainers.image.revision="${GIT_COMMIT}" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}" \
|
||||
org.opencontainers.image.title="fuj-management"
|
||||
|
||||
RUN echo "{\"tag\": \"${GIT_TAG}\", \"commit\": \"${GIT_COMMIT}\", \"build_date\": \"${BUILD_DATE}\"}" > /app/build_meta.json
|
||||
|
||||
EXPOSE 5001
|
||||
|
||||
HEALTHCHECK --interval=60s --timeout=5s --start-period=5s \
|
||||
|
||||
52
docs/operation-manual.md
Normal file
52
docs/operation-manual.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Operation Manual
|
||||
|
||||
## Adding a Monthly Fee Override
|
||||
|
||||
Use this when the club decides to charge a different flat fee for a specific month — for example, a reduced fee during a short or holiday month.
|
||||
|
||||
There are two independent dictionaries in [scripts/attendance.py](../scripts/attendance.py), one for adults and one for juniors. Edit whichever tiers need an override.
|
||||
|
||||
### Adults
|
||||
|
||||
Add an entry to `ADULT_FEE_MONTHLY_RATE` (line ~15):
|
||||
|
||||
```python
|
||||
ADULT_FEE_MONTHLY_RATE = {
|
||||
"2026-03": 350 # reduced fee for March 2026
|
||||
}
|
||||
```
|
||||
|
||||
The key is `YYYY-MM`, the value is the fee in CZK. This replaces `ADULT_FEE_DEFAULT` (750 CZK) for members who attended 2+ practices that month. The single-practice fee (`ADULT_FEE_SINGLE`, 200 CZK) is unaffected.
|
||||
|
||||
### Juniors
|
||||
|
||||
Add an entry to `JUNIOR_MONTHLY_RATE` (line ~20):
|
||||
|
||||
```python
|
||||
JUNIOR_MONTHLY_RATE = {
|
||||
"2025-09": 250, # reduced fee for September 2025
|
||||
"2026-03": 250 # reduced fee for March 2026
|
||||
}
|
||||
```
|
||||
|
||||
The key is `YYYY-MM`, the value is the fee in CZK. This replaces `JUNIOR_FEE_DEFAULT` (500 CZK) for members who attended 2+ practices that month.
|
||||
|
||||
### Example: March 2026
|
||||
|
||||
Both tiers reduced to 350 CZK (adults) and 250 CZK (juniors):
|
||||
|
||||
```python
|
||||
ADULT_FEE_MONTHLY_RATE = {
|
||||
"2026-03": 350
|
||||
}
|
||||
|
||||
JUNIOR_MONTHLY_RATE = {
|
||||
"2026-03": 250
|
||||
}
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Overrides apply to all members of the given tier — use the **exceptions sheet** in Google Sheets for per-member overrides instead.
|
||||
- After changing these values, restart the web dashboard (`make web`) for the change to take effect.
|
||||
- The override only affects the calculated/expected fee. It does not modify any already-recorded payments in the bank sheet.
|
||||
@@ -0,0 +1,52 @@
|
||||
# Plan: Document plan-file location convention in `CLAUDE.md`
|
||||
|
||||
## Context
|
||||
|
||||
The user wants all plan files (created during Claude Code's plan mode) to live
|
||||
inside the project at `docs/plans/`, with a creation timestamp in the filename.
|
||||
This keeps planning artifacts version-controlled alongside the code, makes it
|
||||
easy to see when each plan was drafted, and — critically — needs to be
|
||||
discoverable by other contributors who use Claude Code on this repo. So the
|
||||
convention belongs in `CLAUDE.md`, not in private agent memory.
|
||||
|
||||
## Approach
|
||||
|
||||
1. **Add a new section to `CLAUDE.md`** (placed near the existing "Changelog"
|
||||
section, since both are about persisted artifacts that Claude maintains):
|
||||
|
||||
```markdown
|
||||
## Plans
|
||||
|
||||
When Claude Code's plan mode is used, save the plan file inside the repo at
|
||||
`docs/plans/YYYY-MM-DD-HHMM-<slug>.md` instead of the default
|
||||
`~/.claude/plans/` location. Get the timestamp with
|
||||
`date "+%Y-%m-%d-%H%M"` (matches the changelog convention). The `<slug>`
|
||||
should be a short kebab-case summary of the plan's topic.
|
||||
|
||||
Create the `docs/plans/` directory on first use. Plan files are committed
|
||||
to the repo so other contributors can review historical decisions.
|
||||
```
|
||||
|
||||
2. **Create the `docs/plans/` directory** with a `.gitkeep` (or just let it
|
||||
appear when the first plan is moved in) so the path exists.
|
||||
|
||||
3. **Move this current plan** into the new location once plan mode exits:
|
||||
`docs/plans/2026-05-03-1200-document-plan-location-convention.md`
|
||||
(timestamp will be re-generated with the actual `date` output).
|
||||
|
||||
4. **No memory entry needed** — the rule lives in `CLAUDE.md` and is loaded
|
||||
automatically into every Claude Code session in this repo.
|
||||
|
||||
## Files touched
|
||||
|
||||
- [CLAUDE.md](CLAUDE.md) — add the new "## Plans" section.
|
||||
- New directory: [docs/plans/](docs/plans/) — created on first use.
|
||||
- Move this plan file from `~/.claude/plans/...` into `docs/plans/` with the
|
||||
proper timestamped filename.
|
||||
|
||||
## Verification
|
||||
|
||||
- `grep -A 5 "## Plans" CLAUDE.md` shows the new section.
|
||||
- `ls docs/plans/` lists this plan file with a `YYYY-MM-DD-HHMM-` prefix.
|
||||
- Next time plan mode is entered in this repo, the new plan is written to
|
||||
`docs/plans/` with a fresh timestamp (verify by re-entering plan mode).
|
||||
158
docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md
Normal file
158
docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md
Normal file
@@ -0,0 +1,158 @@
|
||||
# Go Rewrite — Progress Tracker
|
||||
|
||||
Companion to [2026-05-03-2349-go-backend-rewrite.md](2026-05-03-2349-go-backend-rewrite.md).
|
||||
|
||||
**Current milestone:** M2 — Pure-domain helpers
|
||||
**Started:** 2026-05-04
|
||||
**Last updated:** 2026-05-04
|
||||
|
||||
## How to use
|
||||
|
||||
- Tick a checkbox when the task's PR/commit lands. Append the SHA in the same
|
||||
line: `[x] **M1.1** ... — `abc1234``.
|
||||
- One task = one focused commit or PR. If a task balloons, split it and add
|
||||
sub-tasks below the parent.
|
||||
- Note decisions, surprises, or blockers under "Notes & decisions" at the
|
||||
bottom — that's where future-you (or a contributor) will look first.
|
||||
- Don't reorder milestones. Within a milestone, tasks can be done in any
|
||||
order unless explicitly noted.
|
||||
|
||||
---
|
||||
|
||||
## M1 — Skeleton + tooling
|
||||
|
||||
Goal: `make web-go` serves a hello page on :8080 in parallel with `make web-py` on :5001. Lint clean.
|
||||
|
||||
- [x] **M1.1** Create `go/` tree skeleton + `go.mod` initialized to latest stable Go
|
||||
- [x] **M1.2** Add `cmd/fuj/main.go` with subcommand dispatcher — stdlib `flag` + `os.Args[1]` switch
|
||||
- [x] **M1.3** Wire `fuj server` subcommand: `net/http` ServeMux on `:8080`, plaintext hello page
|
||||
- [x] **M1.4** Add Makefile targets: `go-build`, `go-test`, `go-run`, `go-lint`
|
||||
- [x] **M1.5** Rename existing `make web` → `make web-py`; added `make web-go`; kept `make web` as alias
|
||||
- [x] **M1.6** Add `go/.golangci.yml` (govet, staticcheck, errcheck, gofumpt, unused) + `make go-lint` clean
|
||||
- [x] **M1.7** Write `go/build/Dockerfile` (multi-stage `golang:1.26` → `alpine:3`); parallel `build-go` job in Gitea CI
|
||||
- [x] **M1.8** Add `internal/config` package mirroring `scripts/config.py` (same env var names + defaults)
|
||||
- [x] **M1.9** Add `internal/logging` (slog, level from config) + `middleware/timer.go` (method/path/status/ms)
|
||||
- [x] **M1.10** Gate passed: `make go-build`, `make go-lint`, `make go-test`, `curl :8080` all green; CHANGELOG entry added
|
||||
|
||||
**Gate:** ✅ `make go-build` succeeds, `curl localhost:8080` returns hello page, `make go-lint` clean.
|
||||
|
||||
---
|
||||
|
||||
## M2 — Pure-domain helpers (port leaf-first)
|
||||
|
||||
Goal: every pure function from the Python backend exists in Go with a parity test against captured fixtures (M3 produces fixtures in parallel — order is M2.1 → M3.1/M3.2 → M3.3+ alongside M2.2+).
|
||||
|
||||
Each task: port the function, write Go unit tests for fresh cases, hook into the Tier-1 parity runner.
|
||||
|
||||
- [ ] **M2.1** `domain/czech.Normalize` — port [czech_utils.py](scripts/czech_utils.py) `normalize` (NFKD + combining-mark strip + lowercase)
|
||||
- [ ] **M2.2** `domain/czech.ParseMonthReferences` — port `parse_month_references` (45 month declensions, range wrap, year inference)
|
||||
- [ ] **M2.3** `domain/fees.CalculateFee` — port [attendance.py](scripts/attendance.py) `calculate_fee` (constants table)
|
||||
- [ ] **M2.4** `domain/fees.CalculateJuniorFee` — port `calculate_junior_fee` with `Expected{Value int; Unknown bool}` for the `"?"` sentinel
|
||||
- [ ] **M2.5** `domain/money.ParseCZK` — port [infer_payments.py](scripts/infer_payments.py) `parse_czk_amount` (Czech locale: comma decimal, dot/space thousand separators)
|
||||
- [ ] **M2.6** `domain/synch.GenerateSyncID` — port [sync_fio_to_sheets.py](scripts/sync_fio_to_sheets.py) `generate_sync_id` (SHA-256, byte-stable hash; verify float string format against real sheet rows)
|
||||
- [ ] **M2.7** `domain/matching.BuildNameVariants` + `MatchMembers` — port `_build_name_variants` and `match_members` from [match_payments.py](scripts/match_payments.py) (auto vs review confidence, common-surname filter)
|
||||
- [ ] **M2.8** `domain/matching.InferTransactionDetails` — port `infer_transaction_details` (composes name + month parsing)
|
||||
- [ ] **M2.9** `domain/matching.FormatDate` — port `format_date` (handles Google Sheets serial-day numbers since 1899-12-30)
|
||||
- [ ] **M2.10** `domain/reconcile.Reconcile` — port `reconcile` (three-phase allocation: greedy / proportional with float-remainder absorption / even-split fallback). The single most load-bearing function; budget extra time.
|
||||
- [ ] **M2.11** `fuj fees` subcommand wired up via `domain/fees` + (M4-stub) attendance loader — fail gracefully on missing IO until M4 lands
|
||||
- [ ] **M2.12** `fuj reconcile` subcommand similarly stubbed
|
||||
|
||||
**Gate:** `cd go && go test -tags=parity ./tests/parity/pure/...` green for every fixture in `tests/fixtures/pure/`.
|
||||
|
||||
---
|
||||
|
||||
## M3 — Fixture capture + characterization framework
|
||||
|
||||
Goal: deterministic, PII-free fixture corpus that drives parity tests. Runs in parallel with M2 (M3.1/M3.2 unblocks M2.1).
|
||||
|
||||
- [ ] **M3.1** `scripts/capture_fixtures.py` — pure-function output dumper. Reads inputs from stdin / argv, prints `{"input":..., "output":...}` JSON
|
||||
- [ ] **M3.2** `scripts/scrub_fixtures.py` — replaces names with `Member_<8hex>` (deterministic per name); scrambles sender/account/VS/bank_id with stable bijection; preserves dates, amounts, exception keys
|
||||
- [ ] **M3.3** Capture pure-fn fixtures for M2.1–M2.9 (run helper + scrubber, commit to `tests/fixtures/pure/<func>/<case>.json`)
|
||||
- [ ] **M3.4** Capture ~10 reconcile fixtures spanning every code path: greedy, proportional (float remainder), even-split, out-of-window credit, exception override, `other:` purpose, junior `"?"`, multi-person comma-split, multi-month range, unmatched. Commit to `tests/fixtures/reconcile/`
|
||||
- [ ] **M3.5** Hook fixtures into Tier-1 test runner with `-tags=parity` build constraint
|
||||
- [ ] **M3.6** Document fixture-refresh workflow in `tests/fixtures/README.md` (what to do when sheet schema changes)
|
||||
|
||||
**Gate:** `tests/fixtures/` populated; M2 parity tests green; raw `tmp/*.json` confirmed gitignored.
|
||||
|
||||
---
|
||||
|
||||
## M4 — IO layer behind interfaces
|
||||
|
||||
Goal: every external IO (Sheets, Drive, Fio, file cache) accessed through a narrow Go interface with both a real and a fake implementation.
|
||||
|
||||
- [ ] **M4.1** Design IO interfaces (`SheetsClient`, `DriveClient`, `FioClient`, `FileCache`) + in-memory fakes seeded from M3 fixtures
|
||||
- [ ] **M4.2** `internal/io/sheets` — Google client (read + append + batchUpdate); integration test against a separate test sheet (NOT prod)
|
||||
- [ ] **M4.3** `internal/io/drive` — Drive `modifiedTime` client + integration test
|
||||
- [ ] **M4.4** `internal/io/fio` — API JSON impl (token-based); parses by hardcoded `column0..column22` indices matching [fio_utils.py](scripts/fio_utils.py)
|
||||
- [ ] **M4.5** `internal/io/fio` — transparent-page HTML scraper using `golang.org/x/net/html` token visitor; targets the **second** `<table class="table">`
|
||||
- [ ] **M4.6** `internal/io/cache` — FileCache with `modifiedTime` gating + two TTL knobs + atomic writes (`os.Rename`)
|
||||
- [ ] **M4.7** `services/banksync.SyncToSheets` + `fuj sync` subcommand
|
||||
- [ ] **M4.8** `services/banksync.InferPayments` + `fuj infer [--dry-run]` subcommand
|
||||
|
||||
**Gate:** `go test -tags=integration ./internal/io/...` round-trips against test sheet; default-tag tests run on fakes.
|
||||
|
||||
---
|
||||
|
||||
## M5 — JSON-only `/api/...` routes
|
||||
|
||||
Goal: byte-equal JSON between Python and Go for every route. This is the parity contract.
|
||||
|
||||
- [ ] **M5.1** Hand-author Go structs for `/api/adults`, `/api/juniors`, `/api/payments`, `/api/version` with explicit `json:` tags matching Python keys; emit JSON Schemas via `github.com/invopop/jsonschema` to `tests/fixtures/api-schema/`
|
||||
- [ ] **M5.2** Implement Go handlers for `/api/*` routes composing `services/*` results into the JSON structs
|
||||
- [ ] **M5.3** Add Python `/api/X` shadow endpoints in [app.py](app.py): `jsonify(view_model_dict)` — no transformation
|
||||
- [ ] **M5.4** Build `cmd/parity/main.go`: hits both backends' `/api/X`, normalizes allowlist (`render_time.total`, `build_meta`), prints `cmp.Diff`. Add `make parity` target
|
||||
|
||||
**Gate:** For each route, `make parity` reports zero non-allowlisted diffs across the M3 fixture corpus.
|
||||
|
||||
---
|
||||
|
||||
## M6 — Go-native HTML frontend
|
||||
|
||||
Goal: feature-equivalent UX on the Go side, designed cleanly. Not a Jinja port.
|
||||
|
||||
- [ ] **M6.1** Template skeleton: base layout, nav (Adults/Juniors/Payments/Sync/Flush), terminal-green-on-black theme; `embed.FS` for `templates/` + `static/`
|
||||
- [ ] **M6.2** `/adults` page: table, name filter input, month range filter, totals row, credits/debts/unmatched sections, Pay buttons that link to `/qr`
|
||||
- [ ] **M6.3** `/juniors` page: same structure + per-month J/A attendance breakdown + `"?"` sentinel rendering
|
||||
- [ ] **M6.4** `/payments` page: grouped-by-person ledger view
|
||||
- [ ] **M6.5** Modal JS module (`static/js/member-detail.js`): fetches `/api/adults` (or juniors), renders status/exceptions/transactions on row click; keyboard nav (Esc, ↑/↓)
|
||||
- [ ] **M6.6** `/qr`, `/sync-bank`, `/flush-cache`, `/version` pages
|
||||
- [ ] **M6.7** Wire `embed.FS` into handlers; verify single-binary deployment includes all assets
|
||||
|
||||
**Gate:** Browser smoke on :8080: all pages render, name+month filters work, modal opens with correct data, QR loads, sync/flush work end-to-end.
|
||||
|
||||
---
|
||||
|
||||
## M7 — Parallel-running watch period
|
||||
|
||||
Goal: prove parity over real time before flipping the default.
|
||||
|
||||
- [ ] **M7.1** Add Go service to `docker-compose.yml` on different port (alongside Python container)
|
||||
- [ ] **M7.2** Set up `parity-nightly.yml` Gitea workflow: boot both, replay fixed transaction script, fail on diff
|
||||
- [ ] **M7.3** Run `make parity` daily for 7–14 days, log any diffs; investigate and fix root cause (don't just allowlist)
|
||||
- [ ] **M7.4** Manual feature parity check: walk through every UI feature on both sides, sign off in Notes section
|
||||
|
||||
**Gate:** Zero non-allowlisted JSON diffs over 7 consecutive days, including a sync-bank execution + flush + attendance update; user sign-off on UI feature parity.
|
||||
|
||||
---
|
||||
|
||||
## M8 — Cutover + Python retirement
|
||||
|
||||
Goal: Go is the one true backend.
|
||||
|
||||
- [ ] **M8.1** Update bookmarks, README, CLAUDE.md to point at Go (`make web` aliases to `make web-go`)
|
||||
- [ ] **M8.2** Run Go-only for 2 weeks including a month-end settlement; keep Python container available but unrouted
|
||||
- [ ] **M8.3** Manual reconciliation review: produce a balance report on `python-final` and on Go for the same period; sign off they match
|
||||
- [ ] **M8.4** Tag final Python image as `python-final` in registry; remove Python service from `docker-compose.yml`
|
||||
- [ ] **M8.5** Delete [app.py](app.py), [scripts/](scripts/), Python `Dockerfile`, [tests/](tests/), `pyproject.toml`, `uv.lock`
|
||||
- [ ] **M8.6** Update [CLAUDE.md](CLAUDE.md) to reflect Go-only state (commands, architecture, key modules); CHANGELOG entry
|
||||
|
||||
**Gate:** Two consecutive months of Go-only operation with end-of-month settlement complete; zero rollbacks.
|
||||
|
||||
---
|
||||
|
||||
## Notes & decisions
|
||||
|
||||
(Add entries as you go. Format: `YYYY-MM-DD — short note`.)
|
||||
|
||||
- 2026-05-04 — Plan approved. Versioning policy: latest stable for Go and all libs at the time M1 starts. Frontends explicitly allowed to diverge between Python and Go; only the JSON API contract is parity-locked. No reverse proxy — both backends run on different ports via `make web-py` / `make web-go`.
|
||||
- 2026-05-04 — M1 complete. Dockerfile base changed from `distroless/static:nonroot` → `alpine:3` for debuggability (can tighten later). CLI dispatcher uses stdlib `flag`; module path `fuj-management/go`. golangci-lint v1 embedded gofumpt merges all imports into one group (no stdlib/local split) — accepted as the project style.
|
||||
424
docs/plans/2026-05-03-2349-go-backend-rewrite.md
Normal file
424
docs/plans/2026-05-03-2349-go-backend-rewrite.md
Normal file
@@ -0,0 +1,424 @@
|
||||
# Plan: Full Go rewrite of the Python/Flask backend
|
||||
|
||||
## Context
|
||||
|
||||
The current Flask app ([app.py](app.py) + [scripts/](scripts/), ~2400 LOC of
|
||||
Python) handles attendance-based fee calculation, Fio bank sync, payment
|
||||
reconciliation, and a server-rendered dashboard. The user wants a full
|
||||
rewrite in Go with two goals:
|
||||
|
||||
1. **Quality Go code** as the primary outcome — idiomatic stdlib-first
|
||||
design, strong typing, proper layering. The Python codebase grew
|
||||
organically and mixes domain logic, IO, and HTTP concerns.
|
||||
2. **Feature-parity certainty** — no behavioural drift between the Python
|
||||
and Go versions on anything that touches money. Reconciliation is real
|
||||
money; silent divergence is unacceptable.
|
||||
|
||||
**Switchable runtime**: both backends run on different TCP ports, started
|
||||
independently via Makefile targets (`make web-py` on :5001, `make web-go` on
|
||||
:8080). The user opens whichever they want in a browser. No reverse proxy,
|
||||
no traffic-splitting, no shared frontend constraint — just two services
|
||||
that read the same Google Sheets and the same `tmp/` cache.
|
||||
|
||||
**Frontends are allowed to diverge.** The Go web layer is designed cleanly
|
||||
in its own right rather than as a byte-compatible Jinja port. Both backends
|
||||
expose a JSON API (`/api/...`) with an identical contract — that's what
|
||||
parity testing locks down. Rendered HTML and inline JS can be different.
|
||||
|
||||
## Versioning policy
|
||||
|
||||
- **Go**: latest stable release at project start. Pin in `go.mod` via the
|
||||
`go` directive (e.g. `go 1.X`) and use the matching `golang:1.X` builder
|
||||
image. Bump on each new minor as it lands stable.
|
||||
- **Go libraries**: latest stable for every dependency in `go.mod`; run
|
||||
`go get -u ./... && go mod tidy` at the start and quarterly thereafter.
|
||||
- **Python deps** (during the parallel-run period): keep
|
||||
[pyproject.toml](pyproject.toml) on its current versions to avoid
|
||||
destabilizing the parity baseline; bump only after Python retires.
|
||||
- **Base images**: `golang:latest-stable` builder → `gcr.io/distroless/static:latest`
|
||||
runtime, both pinned by digest in CI for reproducibility.
|
||||
- **CI runners**: latest stable Linux image on Gitea Actions.
|
||||
|
||||
The plan does not hardcode specific version numbers below — implementation
|
||||
picks current-stable at the time M1 starts.
|
||||
|
||||
## Approach summary
|
||||
|
||||
- **Three-layer Go architecture**: pure domain (no IO) → IO clients (behind
|
||||
interfaces, easily faked) → HTTP/services (composition).
|
||||
- **Capture-then-port**: dump current Python outputs as JSON fixtures, port
|
||||
Go function-by-function, assert byte-equality with `cmp.Diff`.
|
||||
- **JSON contract is the spec, not the templates.** Each Python route gets
|
||||
an `/api/X` shadow that returns the dict already passed to the template.
|
||||
Go defines typed structs matching that shape; both sides validate against
|
||||
generated JSON Schema.
|
||||
- **Money is integer CZK**: existing fees are integer CZK (750/200/500);
|
||||
keep it that way to avoid float drift in reconcile allocation. Where
|
||||
Sheets returns floats, parse and round at the boundary.
|
||||
- **Frontend rewrite, not port**: Go uses `html/template` with cleanly
|
||||
organized templates and JS extracted into static files served via
|
||||
`embed.FS`. Same UX (filterable table, member-detail modal, QR launcher)
|
||||
but designed natively, no Jinja-port baggage.
|
||||
|
||||
## Go project layout
|
||||
|
||||
`go/` lives at the repo root alongside `scripts/` and `templates/` so both
|
||||
backends share the same git history during migration.
|
||||
|
||||
```
|
||||
go/
|
||||
cmd/
|
||||
fuj/main.go # single binary, subcommands: server | fees | sync | infer | reconcile
|
||||
parity/main.go # diff tool: hits both backends' /api/X, prints JSON diff
|
||||
internal/
|
||||
domain/ # pure, no IO, no net/*
|
||||
czech/ # normalize, parse_month_references
|
||||
fees/ # calculate_fee, calculate_junior_fee, "?" sentinel type
|
||||
money/ # parse_czk_amount, format helpers
|
||||
reconcile/ # reconcile() + Ledger, MemberResult types
|
||||
matching/ # _build_name_variants, match_members, infer_transaction_details
|
||||
synch/ # generate_sync_id (pure hash)
|
||||
io/ # IO behind interfaces, all impls have an in-memory fake
|
||||
sheets/ # SheetsClient + Google impl + fake
|
||||
drive/ # DriveClient for modifiedTime
|
||||
fio/ # FioClient: API JSON impl + transparent-page HTML scraper
|
||||
cache/ # FileCache with modifiedTime gating + two TTL knobs
|
||||
services/ # composition layer; pure + IO, no HTTP
|
||||
attendance/ # GetMembersWithFees, GetJuniorMembersWithFees
|
||||
payments/ # FetchTransactions, FetchExceptions, BuildView
|
||||
banksync/ # SyncToSheets, InferPayments (write ops)
|
||||
web/
|
||||
handlers/ # one file per route family
|
||||
view/ # HTML view-model structs (per route)
|
||||
api/ # JSON view-model structs (the parity-locked contract)
|
||||
templates/ # *.tmpl, embed.FS — designed natively, not a Jinja port
|
||||
static/ # js/*.js, css/*.css served via embed.FS
|
||||
middleware/ # request timer, recovery, slog
|
||||
config/ # mirrors scripts/config.py (env loading)
|
||||
qr/ # SPD string builder + PNG via go-qrcode
|
||||
tests/
|
||||
fixtures/ # JSON fixtures captured from Python (PII-scrubbed)
|
||||
parity/ # Go-side characterization tests (replay fixtures)
|
||||
build/Dockerfile # multi-stage: latest-stable golang builder → distroless static
|
||||
go.mod
|
||||
```
|
||||
|
||||
## Library choices
|
||||
|
||||
All on latest stable as per the versioning policy above.
|
||||
|
||||
| Concern | Pick | Rationale |
|
||||
|---|---|---|
|
||||
| HTTP routing | `net/http` ServeMux | 8 static routes; no need for chi/gin given modern stdlib pattern matching |
|
||||
| Templates | `html/template` | Auto-escaping; native Go feel |
|
||||
| Static assets | `embed.FS` | Single binary, no loose files |
|
||||
| Sheets/Drive | `google.golang.org/api/{sheets/v4,drive/v3}` + `option` | Official client; service-account auth via `option.WithCredentialsFile` |
|
||||
| OAuth | `golang.org/x/oauth2/google` (token only; drop installed-app flow + pickle) | Production already uses service accounts |
|
||||
| QR PNG | `github.com/skip2/go-qrcode` | Mature, byte-stable PNG output |
|
||||
| NFKD | `golang.org/x/text/unicode/norm` + `unicode.IsMark` | Direct equivalent of `unicodedata.normalize("NFKD", ...)` |
|
||||
| HTML scrape | `golang.org/x/net/html` token visitor | Counts `<table class="table">` to target the second one |
|
||||
| CSV | `encoding/csv` (stdlib) | Match for Python `csv.reader` |
|
||||
| Logging | `log/slog` (stdlib) | Honors `LOG_LEVEL` env |
|
||||
| Diff/testing | `testing` + `github.com/google/go-cmp/cmp` | Readable `cmp.Diff` for parity assertions |
|
||||
| Lint | `golangci-lint` (govet, staticcheck, errcheck, gofumpt, unused) | Standard quality gate |
|
||||
|
||||
## Migration sequencing — eight milestones with hard gates
|
||||
|
||||
**M1 — Skeleton + tooling.** Create `go/` tree, `go.mod` (latest stable
|
||||
Go), Makefile targets (`go-build`, `go-test`, `go-run`, `web-go`),
|
||||
`golangci-lint` config. `cmd/fuj server` prints a hello + version and
|
||||
listens on :8080.
|
||||
*Gate:* `make go-build` succeeds; `make web-go` serves a "hello" page on
|
||||
:8080 in parallel with `make web` on :5001; lint clean.
|
||||
|
||||
**M2 — Pure-domain helpers, port leaf-first.** Order:
|
||||
[czech_utils.py](scripts/czech_utils.py) `normalize` → `parse_month_references` →
|
||||
[attendance.py](scripts/attendance.py) `calculate_fee`/`calculate_junior_fee` →
|
||||
[infer_payments.py](scripts/infer_payments.py) `parse_czk_amount` →
|
||||
[sync_fio_to_sheets.py](scripts/sync_fio_to_sheets.py) `generate_sync_id` →
|
||||
[match_payments.py](scripts/match_payments.py) helpers (`_build_name_variants`,
|
||||
`match_members`, `infer_transaction_details`, `format_date`) → `reconcile`.
|
||||
Each gets a Go unit test plus a parity test driven by JSON fixtures from M3.
|
||||
Also: `fuj fees` and `fuj reconcile` subcommands wired up (pure-domain CLIs).
|
||||
*Gate:* All ported helpers pass parity tests.
|
||||
|
||||
**M3 — Fixture capture + characterization framework.** Build
|
||||
`scripts/capture_fixtures.py` (Python helper that prints function results as
|
||||
JSON to stdout — user pipes to disk) and `scripts/scrub_fixtures.py`
|
||||
(replaces member names with deterministic pseudonyms `Member_<8hex>`,
|
||||
scrambles sender/account/VS/bank_id while preserving structural
|
||||
relationships, dates, amounts, exception keys). Capture ~10 reconcile
|
||||
fixtures spanning every code path: greedy, proportional with float
|
||||
remainder, even-split fallback, out-of-window credit, exception override,
|
||||
`other:` purpose, junior `"?"`, comma-separated multi-person, multi-month
|
||||
range, unmatched.
|
||||
*Gate:* `tests/fixtures/` populated and committed; M2 parity tests green.
|
||||
|
||||
**M4 — IO layer behind interfaces.** Implement Sheets/Drive/Fio clients
|
||||
matching Python return shapes. Drop the OAuth+pickle path entirely (service
|
||||
account only). All clients have in-memory fakes for tests. Wire `fuj sync`
|
||||
and `fuj infer` subcommands.
|
||||
*Gate:* `go test -tags=integration ./internal/io/...` round-trips against a
|
||||
test sheet (separate from prod); default-tag tests use fakes.
|
||||
|
||||
**M5 — JSON-only `/api/...` routes.** Add 8 Go route handlers that return
|
||||
JSON. Add symmetric `/api/X` shadow endpoints in [app.py](app.py) that
|
||||
`jsonify` the existing view-model dict (no transformation).
|
||||
*Gate:* For each route, `cmd/parity` asserts
|
||||
`cmp.Diff(python.json, go.json) == ""` modulo allowlist
|
||||
(`render_time.total`, `build_meta`).
|
||||
|
||||
**M6 — Go-native HTML frontend.** Design Go templates cleanly (not a Jinja
|
||||
port). Extract JS from inline into `internal/web/static/js/*.js` served via
|
||||
`embed.FS`. Vanilla JS, no framework — same UX as Python (sortable table,
|
||||
member-detail modal, name filter, month range filter, QR launcher) but
|
||||
organized as proper modules. Templates render the JSON API response into
|
||||
HTML; frontend JS fetches additional data from `/api/X` for the modal
|
||||
rather than embedding `member_data` in `<script>`.
|
||||
*Gate:* Browser smoke test of all routes on :8080 covers: name filter,
|
||||
month filter, modal opens with correct months/transactions/exceptions, QR
|
||||
modal renders, navigation between adults/juniors/payments works.
|
||||
|
||||
**M7 — Parallel-running watch period.** Both `make web-py` and `make web-go`
|
||||
running locally (and in production via two containers on different ports).
|
||||
Daily/manual `cmd/parity` runs catch any JSON drift. The user verifies the
|
||||
Go UI matches what they expect feature-by-feature against the Python UI.
|
||||
Run 1–2 weeks.
|
||||
*Gate:* Zero non-allowlisted JSON diffs over 7 consecutive days, including
|
||||
a sync-bank execution, a flush, and an attendance update. User sign-off
|
||||
that the Go UI is feature-complete.
|
||||
|
||||
**M8 — Cutover + Python retirement.** Switch the bookmarked URL / docs to
|
||||
the Go port. Keep Python container running but unrouted (or stopped) for
|
||||
1 week as rollback. Then delete [app.py](app.py), [scripts/](scripts/),
|
||||
the Python `Dockerfile`, and the Python tests. Update
|
||||
[CLAUDE.md](CLAUDE.md) to reflect the Go-only state.
|
||||
*Gate:* Two consecutive months of Go-only operation including end-of-month
|
||||
settlement.
|
||||
|
||||
## CLI port (decided: port as Go subcommands)
|
||||
|
||||
Single Go binary `fuj` with subcommands replacing the existing Makefile
|
||||
targets. Each reuses the domain layer directly:
|
||||
|
||||
| Old | New | Backed by | Milestone |
|
||||
|---|---|---|---|
|
||||
| `make fees` | `fuj fees` | `domain/fees` + `services/attendance` | M2 |
|
||||
| `make reconcile` | `fuj reconcile` | `domain/reconcile` | M2 |
|
||||
| `make sync-2026` | `fuj sync --year=2026` | `services/banksync.SyncToSheets` | M4 |
|
||||
| `make infer` | `fuj infer [--dry-run]` | `services/banksync.InferPayments` | M4 |
|
||||
| `make web` (py) | stays as Python `make web-py` until M8 | — | — |
|
||||
| `make web-go` | `fuj server` | `web/handlers` | M1 |
|
||||
|
||||
Makefile targets get rewritten to invoke `./bin/fuj <subcommand>` once each
|
||||
is ported. The Python `make` targets for already-ported commands stay as
|
||||
`make X-py` aliases until M8, so you can run either side for cross-checks.
|
||||
|
||||
## JSON API contract strategy
|
||||
|
||||
**Go-defines, Python-conforms** with a 1-step bootstrap:
|
||||
|
||||
1. Run Python locally and dump `result["members"]`, `formatted_results`,
|
||||
`monthly_totals`, etc., to JSON. This is the spec.
|
||||
2. Hand-author Go structs with explicit `json:` tags matching exact Python
|
||||
keys (`total_balance`, `original_expected`, `attendance_count` — no
|
||||
reliance on default lowercasing).
|
||||
3. Generate `tests/fixtures/api-schema/*.schema.json` from the Go structs
|
||||
using `github.com/invopop/jsonschema`. Commit them.
|
||||
4. Add a Python-side schema validator running in CI against the new
|
||||
`/api/X` responses.
|
||||
|
||||
**Two known-tricky shapes:**
|
||||
|
||||
- Junior `expected: int | "?"` →
|
||||
```go
|
||||
type Expected struct{ Value int; Unknown bool }
|
||||
// MarshalJSON emits 42 or "?"
|
||||
```
|
||||
Same for `original_expected`.
|
||||
- Tuple dict keys `(normalize(name), normalize(period))` for exceptions —
|
||||
internal only, never crosses JSON. Use
|
||||
`map[ExceptionKey]Exception` with `ExceptionKey struct{ Name, Period string }`.
|
||||
|
||||
## Characterization test harness — two tiers
|
||||
|
||||
(HTML rendering parity dropped: frontends are intentionally different.)
|
||||
|
||||
**Tier 1 — Pure-function parity** (fast, every commit). Fixtures at
|
||||
`tests/fixtures/pure/<func>/<case>.json` containing `{input, output}`,
|
||||
captured once via `scripts/capture_fixtures.py`. Go test reads each, calls
|
||||
the ported function, asserts deep equality with `cmp.Diff`. Functions in
|
||||
scope: `normalize`, `parse_month_references`, `parse_czk_amount`,
|
||||
`parse_czech_amount`, `parse_czech_date`, `format_date`,
|
||||
`_build_name_variants`, `match_members`, `infer_transaction_details`,
|
||||
`generate_sync_id`, `calculate_fee`, `calculate_junior_fee`, `reconcile`.
|
||||
|
||||
**Tier 2 — JSON API parity** (medium, on PR + nightly). `cmd/parity/main.go`
|
||||
hits both `:5001/api/X` and `:8080/api/X` with a fixture-seeded `tmp/`
|
||||
cache, normalizes volatile fields (`render_time`, build metadata), asserts
|
||||
byte-equality. Cache freezing: pre-populate `tmp/*_cache.json` from
|
||||
scrubbed snapshots so both backends read identical data.
|
||||
|
||||
**PII scrubbing** is mandatory ([CLAUDE.md](CLAUDE.md): "Member data must
|
||||
never be committed"). `scripts/scrub_fixtures.py` produces deterministic
|
||||
pseudonyms preserving uniqueness and structural relationships. Only
|
||||
scrubbed fixtures land in `tests/fixtures/`; raw `tmp/*.json` stays
|
||||
gitignored.
|
||||
|
||||
## Side-by-side runtime
|
||||
|
||||
Two services on different ports, started independently. No reverse proxy.
|
||||
|
||||
```
|
||||
make web-py # Python on :5001 (existing target, perhaps renamed from `make web`)
|
||||
make web-go # Go on :8080
|
||||
```
|
||||
|
||||
Both read the same Google Sheets and write to the same `tmp/` cache
|
||||
directory. The user opens `localhost:5001` or `localhost:8080` directly to
|
||||
A/B compare.
|
||||
|
||||
**Cache directory coordination**: both backends use `tmp/`. Go writes via
|
||||
`os.WriteFile` to `tmp/<key>_cache.json.tmp` then `os.Rename` (atomic on
|
||||
Linux). Python's writes are pre-existing-non-atomic; accept until Python
|
||||
retires.
|
||||
|
||||
**Sync coordination**: `/sync-bank` is non-idempotent under concurrency.
|
||||
Both backends `flock` on `tmp/sync.lock`; Go uses `syscall.Flock`. (In
|
||||
practice the user is unlikely to trigger sync from both UIs at once, but
|
||||
the lock is cheap insurance.)
|
||||
|
||||
**Production deployment**: keep the existing Python container; add a Go
|
||||
container in `docker-compose.yml` exposed on a different port. After M8,
|
||||
remove the Python service.
|
||||
|
||||
## CI/CD
|
||||
|
||||
Currently zero test CI ([.gitea/workflows/build.yaml](.gitea/workflows/build.yaml)
|
||||
only does `docker build`/`push`). Add `/.gitea/workflows/test.yml`:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
python-tests: # fix M3 broken-test references first
|
||||
- uv sync && pytest tests/
|
||||
go-tests:
|
||||
- cd go && go test -race ./...
|
||||
- cd go && golangci-lint run
|
||||
parity-pure: # Tier 1
|
||||
- cd go && go test -tags=parity ./tests/parity/...
|
||||
```
|
||||
|
||||
Branch protection: `python-tests`, `go-tests`, `parity-pure` block merge.
|
||||
Tier-2 parity runs nightly via `parity-nightly.yml` (boots both servers
|
||||
via docker-compose with seeded caches, replays a fixed transaction script,
|
||||
fails on any non-allowlisted diff).
|
||||
|
||||
A new Go `build/Dockerfile` (multi-stage: latest-stable `golang` builder →
|
||||
`gcr.io/distroless/static:latest`, both pinned by digest) mirrors the
|
||||
existing Python build job and produces a single static binary image.
|
||||
|
||||
## Risk register (top 4)
|
||||
|
||||
(Template auto-escape divergence dropped: irrelevant when frontends differ.)
|
||||
|
||||
1. **Sync ID hash drift** — HIGH/HIGH. Python builds the SHA-256 input by
|
||||
`str()`-ing each field then `.lower()`-ing the joined string;
|
||||
`str(750.0) == "750.0"`, `str(750) == "750"`. If Sheets API returns
|
||||
floats in Python but Go unmarshals as int, `750` vs `750.0` → different
|
||||
hash → duplicate rows. *Mitigation:* dedicated parity test with ~50
|
||||
real-row fixtures; if Go can't reproduce Python's float string format,
|
||||
normalize at the boundary (round to 2 decimals, format with explicit
|
||||
precision).
|
||||
2. **Float allocation in `reconcile()` proportional phase** — HIGH/MEDIUM.
|
||||
Python's "last month absorbs remainder" depends on dict iteration order;
|
||||
Go map iteration is randomized. *Mitigation:* always iterate
|
||||
`sorted_months` explicitly in Go, never the map. Lock the distribution
|
||||
with a parity test on (300, 300, 150) months × 751-CZK payment.
|
||||
3. **NFKD edge cases** — MEDIUM/MEDIUM. Python `unicodedata` and Go
|
||||
`golang.org/x/text` use the same algorithm but can differ on niche
|
||||
compatibility decompositions if `x/text` is older than CPython's tables.
|
||||
*Mitigation:* parity test with every distinct character ever observed in
|
||||
member names; pin `x/text` version explicitly.
|
||||
4. **Czech month parser semantics** — MEDIUM/MEDIUM. Wrap-around year
|
||||
inference (`if start_m > end_m and m >= start_m: year = default_year - 1`)
|
||||
plus the "month >= 10 → previous year" heuristic are easy to mis-port.
|
||||
*Mitigation:* port table and algorithm verbatim line-for-line; parity
|
||||
test with ~30 real `message`-field fixture strings.
|
||||
|
||||
## Cutover plan
|
||||
|
||||
Simpler without a proxy in the middle:
|
||||
|
||||
1. After M7's 7-day clean window + user sign-off, treat Go as primary.
|
||||
Update bookmarks, docs, `make web` to point at Go.
|
||||
2. Keep `make web-py` available for 1-week rollback. Run both containers
|
||||
in production but only point users at the Go one.
|
||||
3. Watch 2 weeks including a month-end settlement on Go-only.
|
||||
4. Decommission Python: remove from `docker-compose.yml`, delete
|
||||
[app.py](app.py) and [scripts/](scripts/), update
|
||||
[CLAUDE.md](CLAUDE.md). Keep image tagged `python-final` in registry as
|
||||
a 6-month rollback option.
|
||||
|
||||
**Retirement criteria:** zero parity-diff incidents in last 30 days, zero
|
||||
rollbacks, two month-end settlements completed Go-only, manual
|
||||
reconciliation review against `python-final` signed off.
|
||||
|
||||
## Critical files
|
||||
|
||||
- [scripts/match_payments.py](scripts/match_payments.py) — `reconcile()` is
|
||||
the single most load-bearing function (~200 lines of allocation logic)
|
||||
that must port byte-equivalently.
|
||||
- [scripts/czech_utils.py](scripts/czech_utils.py) — `normalize` and
|
||||
`parse_month_references` underpin every member/month match across the
|
||||
system. 45 Czech month declensions, range wrap-around, year inference.
|
||||
- [app.py](app.py) — defines the 8-route HTTP surface and view-model
|
||||
shapes. The spec for the Go web layer's JSON API.
|
||||
- [scripts/sync_fio_to_sheets.py](scripts/sync_fio_to_sheets.py) —
|
||||
`generate_sync_id` defines the dedup contract against existing rows in
|
||||
the live sheet. Any drift creates duplicates.
|
||||
- [scripts/attendance.py](scripts/attendance.py) — fee math + merged-month
|
||||
logic + junior `"?"` sentinel.
|
||||
- [scripts/cache_utils.py](scripts/cache_utils.py) — Drive `modifiedTime`
|
||||
gating + two-TTL fallback that must be reproduced for shared-cache
|
||||
safety.
|
||||
- [templates/adults.html](templates/adults.html) — read for the JSON shape
|
||||
the existing inline JS consumes (`member_data`); the Go frontend doesn't
|
||||
have to mirror the template, but the JSON contract derived from this
|
||||
page's data injection is the parity spec.
|
||||
|
||||
## Verification
|
||||
|
||||
End-to-end checks per milestone:
|
||||
|
||||
- **M1**: `make go-build && ./bin/fuj server --help` prints subcommand
|
||||
list. `make web-go` serves :8080 in parallel with `make web-py` on :5001.
|
||||
- **M2-M3**: `cd go && go test -tags=parity ./tests/parity/pure/...` green.
|
||||
Spot-check: feed a known Czech-message string through both
|
||||
`parse_month_references` implementations, diff outputs.
|
||||
- **M4**: `go test -tags=integration ./internal/io/sheets/...` round-trips
|
||||
against a test sheet (separate from prod).
|
||||
- **M5**: `curl localhost:5001/api/adults | jq -S . > py.json && curl
|
||||
localhost:8080/api/adults | jq -S . > go.json && diff py.json go.json` —
|
||||
empty diff modulo allowlist.
|
||||
- **M6**: Browser open `localhost:8080/adults`, click a member row, modal
|
||||
opens with all months / transactions / exceptions correctly populated.
|
||||
Same on `/juniors`. Click a Pay button → QR loads. Name filter and month
|
||||
range filter work.
|
||||
- **M7**: Run `cd go && ./bin/parity --base http://localhost:5001
|
||||
--candidate http://localhost:8080 --routes adults,juniors,payments`
|
||||
daily for 7 days, zero non-allowlisted diffs. User confirms Go UI is
|
||||
feature-complete vs Python UI side-by-side.
|
||||
- **M8**: `make web-py` removed from Makefile; `make web` points at Go;
|
||||
manual end-of-month settlement on Go matches the prior month's
|
||||
Python-produced report.
|
||||
|
||||
## Open questions / forks the user can override at review
|
||||
|
||||
- **Frontend JS organization in M6**: default is vanilla JS in separate
|
||||
files via `embed.FS`. If the user wants HTMX, Alpine.js, or a small
|
||||
framework, raise it before M6.
|
||||
- **CI host**: Gitea Actions assumed (matches existing
|
||||
[.gitea/workflows/build.yaml](.gitea/workflows/build.yaml)).
|
||||
- **Test sheet for M4 integration tests**: would need provisioning.
|
||||
Confirm whether to use a copy of the production sheet (PII!) or a
|
||||
synthetic one seeded by the fixture-capture process.
|
||||
233
docs/plans/2026-05-04-1115-go-rewrite-m1-kickoff.md
Normal file
233
docs/plans/2026-05-04-1115-go-rewrite-m1-kickoff.md
Normal file
@@ -0,0 +1,233 @@
|
||||
# Plan: Go rewrite — M1 kickoff (skeleton + tooling)
|
||||
|
||||
Companion to [2026-05-03-2349-go-backend-rewrite.md](2026-05-03-2349-go-backend-rewrite.md)
|
||||
and the progress tracker
|
||||
[2026-05-03-2349-go-backend-rewrite-progress.md](2026-05-03-2349-go-backend-rewrite-progress.md).
|
||||
|
||||
## Context
|
||||
|
||||
The master plan for a full Go rewrite of the Flask backend is approved
|
||||
(2026-05-04). No Go code exists yet — this plan executes **M1** end-to-end:
|
||||
a working `go/` skeleton, a `fuj` binary with a `server` subcommand serving
|
||||
a hello page on `:8080`, lint config, Makefile + CI integration, and an
|
||||
`internal/config` package mirroring [scripts/config.py](scripts/config.py).
|
||||
|
||||
After M1, both backends run side-by-side locally (`make web-py` on `:5001`,
|
||||
`make web-go` on `:8080`) — that side-by-side capability is what unblocks
|
||||
M2's parity testing and every later milestone.
|
||||
|
||||
## Locked-in decisions
|
||||
|
||||
| # | Decision | Choice |
|
||||
|---|---|---|
|
||||
| 1 | CLI dispatcher | stdlib `flag` + `os.Args[1]` switch (no cobra) |
|
||||
| 2 | Go module path | `fuj-management/go` |
|
||||
| 3 | Go version | `1.26` (latest stable; user toolchain is `go1.26.1`) |
|
||||
| 4 | M1 scope | all 10 progress-tracker sub-tasks in one session |
|
||||
| 5 | Lint | `golangci-lint` with govet, staticcheck, errcheck, gofumpt, unused |
|
||||
| 6 | Logging | `log/slog` text handler, level from `LOG_LEVEL` env |
|
||||
| 7 | HTTP | `net/http.ServeMux` (Go 1.22+ pattern matching) |
|
||||
| 8 | Container base | `golang:1.26` builder → `gcr.io/distroless/static:nonroot` runtime |
|
||||
| 9 | CI | extend [.gitea/workflows/build.yaml](.gitea/workflows/build.yaml) with a `go-build` job parallel to existing Python `build` job; tag suffix `-go` |
|
||||
|
||||
## Files to create
|
||||
|
||||
```
|
||||
go/
|
||||
go.mod # module fuj-management/go, go 1.26
|
||||
go.sum # empty / generated
|
||||
.golangci.yml # govet, staticcheck, errcheck, gofumpt, unused
|
||||
cmd/fuj/main.go # subcommand dispatcher + version vars
|
||||
internal/
|
||||
config/config.go # env loader mirroring scripts/config.py
|
||||
logging/logger.go # slog setup honoring LOG_LEVEL
|
||||
web/
|
||||
server.go # `fuj server` handler: ServeMux on :8080, hello page
|
||||
middleware/timer.go # request-timer middleware (parity with Python `get_render_time`)
|
||||
build/
|
||||
Dockerfile # multi-stage golang:1.26 → distroless/static
|
||||
```
|
||||
|
||||
No `embed.FS`, no templates, no static assets in M1 — the hello page is
|
||||
inline HTML in `server.go`. Templates land in M6.
|
||||
|
||||
## Files to edit
|
||||
|
||||
- [Makefile](Makefile) — add Go targets, rename `web` → `web-py`, keep
|
||||
`web` as transitional alias to `web-py` until M8.
|
||||
- [.gitignore](.gitignore) — add `bin/` and `go/.cache/` (if any).
|
||||
- [.gitea/workflows/build.yaml](.gitea/workflows/build.yaml) — add
|
||||
`go-build` job that builds and pushes `<tag>-go` image.
|
||||
- [CHANGELOG.md](CHANGELOG.md) — top-of-file entry per CLAUDE.md convention.
|
||||
- [docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md](docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md)
|
||||
— tick M1.1–M1.10 with commit SHAs as they land.
|
||||
|
||||
## Execution sequence
|
||||
|
||||
Order is tight: each step keeps the tree compilable and lint-clean.
|
||||
|
||||
1. **Skeleton (M1.1)** — `mkdir -p go/{cmd/fuj,internal/{config,logging,web/middleware},build}` and `cd go && go mod init fuj-management/go`. Pin `go 1.26` in `go.mod`.
|
||||
|
||||
2. **Config + logger (M1.8, M1.9)** — write `internal/config/config.go` mirroring [scripts/config.py](scripts/config.py): exported constants for `AttendanceSheetID`, `PaymentsSheetID`, `JuniorSheetGID`, env-driven `CredentialsPath`, `BankAccount`, `CacheTTL`, `CacheAPICheckTTL`, `LogLevel`, `FioAPIToken`. Write `internal/logging/logger.go` with a `New() *slog.Logger` honoring `LOG_LEVEL` (`DEBUG|INFO|WARN|ERROR`).
|
||||
|
||||
3. **Web middleware + handler (M1.3)** — `internal/web/middleware/timer.go` logs `method path status ms` for every request. `internal/web/server.go` exposes `Run(ctx, addr) error`: `http.ServeMux` with `GET /` returning a minimal HTML hello page that includes `version`, `commit`, and `buildDate` (linker-injected via `-X main.version=…`).
|
||||
|
||||
4. **Subcommand dispatcher (M1.2)** — `cmd/fuj/main.go`:
|
||||
- Package-level `var version, commit, buildDate string` for `-ldflags -X` injection.
|
||||
- `os.Args[1]` switch over `server | version | fees | reconcile | sync | infer | help`. M1 implements `server` and `version`; the rest print `<cmd>: not implemented yet (lands in M2/M4)` and exit 2.
|
||||
- Each subcommand parses its own `flag.NewFlagSet`. `server` flags: `--addr` (default `:8080`).
|
||||
|
||||
5. **Lint config (M1.6)** — `go/.golangci.yml` enabling `govet`, `staticcheck`, `errcheck`, `gofumpt`, `unused`. Run `golangci-lint run ./...` to confirm clean.
|
||||
|
||||
6. **Makefile (M1.4, M1.5)** — add:
|
||||
```make
|
||||
GO_BIN := bin/fuj
|
||||
GO_SRC := go
|
||||
|
||||
go-build:
|
||||
cd $(GO_SRC) && go build -trimpath \
|
||||
-ldflags "-X main.version=$$(git describe --tags --always 2>/dev/null || echo dev) \
|
||||
-X main.commit=$$(git rev-parse --short HEAD) \
|
||||
-X main.buildDate=$$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
-o ../$(GO_BIN) ./cmd/fuj
|
||||
|
||||
go-test:
|
||||
cd $(GO_SRC) && go test -race ./...
|
||||
|
||||
go-run: go-build
|
||||
./$(GO_BIN) $(ARGS)
|
||||
|
||||
go-lint:
|
||||
cd $(GO_SRC) && golangci-lint run ./...
|
||||
|
||||
web-go: go-build
|
||||
./$(GO_BIN) server --addr :8080
|
||||
```
|
||||
Rename existing `web:` target to `web-py:` and add `web: web-py` as alias.
|
||||
|
||||
7. **Dockerfile + CI (M1.7)** — `go/build/Dockerfile`:
|
||||
```dockerfile
|
||||
FROM golang:1.26 AS build
|
||||
WORKDIR /src
|
||||
COPY go/go.mod go/go.sum ./
|
||||
RUN go mod download
|
||||
COPY go/ ./
|
||||
ARG GIT_TAG=unknown
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_DATE=unknown
|
||||
RUN CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags "-s -w -X main.version=${GIT_TAG} -X main.commit=${GIT_COMMIT} -X main.buildDate=${BUILD_DATE}" \
|
||||
-o /out/fuj ./cmd/fuj
|
||||
|
||||
FROM gcr.io/distroless/static:nonroot
|
||||
COPY --from=build /out/fuj /usr/local/bin/fuj
|
||||
EXPOSE 8080
|
||||
USER nonroot:nonroot
|
||||
ENTRYPOINT ["/usr/local/bin/fuj","server"]
|
||||
```
|
||||
In [.gitea/workflows/build.yaml](.gitea/workflows/build.yaml), add a parallel job:
|
||||
```yaml
|
||||
build-go:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: docker login ...
|
||||
- run: |
|
||||
docker build -f go/build/Dockerfile \
|
||||
--build-arg GIT_TAG=$TAG \
|
||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
|
||||
-t gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG-go .
|
||||
docker push gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG-go
|
||||
```
|
||||
|
||||
8. **Smoke verify (M1.10)** — see Verification section below; then append a CHANGELOG entry and tick M1 boxes in the progress tracker with commit SHAs.
|
||||
|
||||
## Reuse / parity with Python side
|
||||
|
||||
- `internal/config` mirrors [scripts/config.py](scripts/config.py) **exactly** — same env var names, same defaults. No new env knobs in M1.
|
||||
- Request-timer middleware records elapsed milliseconds; this is the Go-side
|
||||
equivalent of the Python `get_render_time` helper that supplies
|
||||
`render_time.total` to templates. Allowlisted as volatile in the future
|
||||
parity diff (M5).
|
||||
- Constants `AttendanceSheetID`, `PaymentsSheetID`, `JuniorSheetGID` are
|
||||
copied verbatim from [scripts/config.py](scripts/config.py); they don't
|
||||
get used until M4 but live in `internal/config` from day one.
|
||||
|
||||
## Verification
|
||||
|
||||
Run from repo root after all changes are in place:
|
||||
|
||||
```bash
|
||||
# 1. Builds clean
|
||||
make go-build && test -x bin/fuj
|
||||
|
||||
# 2. Lint clean
|
||||
make go-lint
|
||||
|
||||
# 3. Subcommand dispatcher works
|
||||
./bin/fuj help
|
||||
./bin/fuj version # prints version/commit/buildDate
|
||||
./bin/fuj fees # prints "not implemented yet" and exits 2
|
||||
|
||||
# 4. Server runs and hello page is served
|
||||
make web-go &
|
||||
GO_PID=$!
|
||||
sleep 1
|
||||
curl -sf http://localhost:8080/ | grep -q "fuj"
|
||||
kill $GO_PID
|
||||
|
||||
# 5. Side-by-side: both backends up
|
||||
make web-py & # :5001
|
||||
PY_PID=$!
|
||||
make web-go & # :8080
|
||||
GO_PID=$!
|
||||
sleep 2
|
||||
curl -sf http://localhost:5001/ >/dev/null && echo "py OK"
|
||||
curl -sf http://localhost:8080/ >/dev/null && echo "go OK"
|
||||
kill $PY_PID $GO_PID
|
||||
|
||||
# 6. Race-free unit tests pass (none yet beyond a smoke test, but harness works)
|
||||
make go-test
|
||||
|
||||
# 7. Docker image builds locally
|
||||
docker build -f go/build/Dockerfile -t fuj-go:dev .
|
||||
docker run --rm -p 8080:8080 fuj-go:dev &
|
||||
sleep 1
|
||||
curl -sf http://localhost:8080/ >/dev/null && echo "container OK"
|
||||
docker stop $(docker ps -lq)
|
||||
```
|
||||
|
||||
All seven steps must succeed. Then update the progress tracker and
|
||||
CHANGELOG.
|
||||
|
||||
## Out of scope for M1 (deferred to later milestones)
|
||||
|
||||
- Domain logic — `czech.Normalize`, fees, reconcile, etc. → **M2**.
|
||||
- Fixture capture and parity tests → **M3**.
|
||||
- Sheets/Drive/Fio clients and `internal/io/*` → **M4**.
|
||||
- `/api/*` JSON routes and `cmd/parity` → **M5**.
|
||||
- HTML templates, static assets, `embed.FS` → **M6**.
|
||||
- Removing the Python backend → **M8**.
|
||||
|
||||
## Open items / forks the user can override at review
|
||||
|
||||
- **CI tag suffix**: `<tag>-go` proposed. Alternative: separate image
|
||||
repository (`fuj-management-go:<tag>`). The suffix keeps things in one
|
||||
registry path; speak up if separate repos are preferred.
|
||||
- **Distroless variant**: `nonroot` chosen for least privilege. If the
|
||||
existing Python container runs as root and the user expects parity,
|
||||
switch to `gcr.io/distroless/static` (root). Doesn't affect M1
|
||||
functionality.
|
||||
- **Hello page content**: minimal HTML mentioning `fuj`, version, commit,
|
||||
build date, link list to future routes. Speak up if you want a different
|
||||
shape — it gets thrown away in M6 anyway.
|
||||
|
||||
## Critical files
|
||||
|
||||
- [docs/plans/2026-05-03-2349-go-backend-rewrite.md](docs/plans/2026-05-03-2349-go-backend-rewrite.md) — master plan (approved 2026-05-04)
|
||||
- [docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md](docs/plans/2026-05-03-2349-go-backend-rewrite-progress.md) — task tracker; tick M1.1–M1.10 here
|
||||
- [Makefile](Makefile) — current target structure (renaming `web` → `web-py`)
|
||||
- [scripts/config.py](scripts/config.py) — source of truth for env vars / IDs that `internal/config` mirrors
|
||||
- [build/Dockerfile](build/Dockerfile) — Python container (unchanged); the new Go Dockerfile lives at `go/build/Dockerfile`
|
||||
- [.gitea/workflows/build.yaml](.gitea/workflows/build.yaml) — extended with parallel `build-go` job
|
||||
81
docs/plans/2026-05-04-2249-payment-name-match-exact.md
Normal file
81
docs/plans/2026-05-04-2249-payment-name-match-exact.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Exact full-name match for payment inference
|
||||
|
||||
## Context
|
||||
|
||||
A bank payment with the message `Henrietta Ottová (Heny): 04/2026` is being inferred to **two** members: the correct `Henrietta Ottová` *and* the unrelated `Tomáš Němeček (Tov)`. As a result, `reconcile()` splits the amount 50/50 between them, producing wrong balances.
|
||||
|
||||
**Root cause** (`scripts/match_payments.py:51-115`): `match_members` runs four substring checks via raw Python `in`, with no word boundaries. Tomáš's nickname `Tov` normalizes to `tov`, which is literally a substring of `ottova`. Check #3 (`match_payments.py:79-85`) treats bare nickname presence as an `auto`-confidence match, so Tomáš is appended even though no part of his name is actually in the message. There is also no short-circuit when a member's full canonical name appears verbatim — every other member is still scored against the same haystack.
|
||||
|
||||
**Goal:** when a member's full canonical name (diacritics-insensitive) appears in the message as whole words, return only the full-name hit(s) and skip nickname/partial scoring entirely. Additionally, harden the remaining checks with word boundaries so future substring collisions (any nickname or short name part that happens to live inside another member's surname) can't reproduce this class of bug.
|
||||
|
||||
## Approach
|
||||
|
||||
Single-file change in [scripts/match_payments.py](scripts/match_payments.py). Two coordinated edits to `match_members` (`match_payments.py:51-115`):
|
||||
|
||||
### 1. Add an exact-canonical-name short-circuit (new, before the existing loop)
|
||||
|
||||
After computing `normalized_text`, do a first pass that collects every member whose `normalized_base` (the full name minus the parenthesized nickname, normalized) appears in the haystack as **whole words**. If at least one is found, return *only* those as `auto` matches and skip the rest of the function.
|
||||
|
||||
Implementation sketch (inserted between [match_payments.py:58](scripts/match_payments.py#L58) and [match_payments.py:61](scripts/match_payments.py#L61)):
|
||||
|
||||
```python
|
||||
exact_matches = []
|
||||
for name in member_names:
|
||||
variants = _build_name_variants(name)
|
||||
full_name = variants[0] if variants else ""
|
||||
if full_name and re.search(rf"\b{re.escape(full_name)}\b", normalized_text):
|
||||
exact_matches.append((name, "auto"))
|
||||
if exact_matches:
|
||||
return exact_matches
|
||||
```
|
||||
|
||||
This satisfies the user's primary ask: when the message literally contains the canonical name, that wins outright. Multi-member messages still work — every full-name occurrence is collected.
|
||||
|
||||
### 2. Replace remaining `in normalized_text` checks with `\b…\b` regex
|
||||
|
||||
For the three checks that survive the short-circuit (and the `review`-tier partials), swap raw `in` for whole-word regex so `tov` cannot match inside `ottova`, `dan` cannot match inside `bohdan`, etc. Affected lines:
|
||||
|
||||
- [match_payments.py:73](scripts/match_payments.py#L73) — first+last name both present
|
||||
- [match_payments.py:82](scripts/match_payments.py#L82) — nickname presence
|
||||
- [match_payments.py:94](scripts/match_payments.py#L94) — last-name partial (`review`)
|
||||
- [match_payments.py:99](scripts/match_payments.py#L99) — first-name partial (`review`)
|
||||
- [match_payments.py:104](scripts/match_payments.py#L104) — single-name member partial
|
||||
|
||||
Helper to keep the call sites tidy:
|
||||
|
||||
```python
|
||||
def _word_in(needle: str, haystack: str) -> bool:
|
||||
return bool(re.search(rf"\b{re.escape(needle)}\b", haystack))
|
||||
```
|
||||
|
||||
Check #1 (line 67) becomes redundant once the short-circuit is in place, but leave it untouched as a defensive fallback in case `_build_name_variants` ever returns a `full_name` shorter than the 3-char filter would allow. (No code change there.)
|
||||
|
||||
### 3. Why this is sufficient
|
||||
|
||||
- The reported message `Henrietta Ottová (Heny): 04/2026` hits the new short-circuit on `henrietta ottova`, returns `[("Henrietta Ottová", "auto")]`, and never even evaluates Tomáš.
|
||||
- Bare-nickname messages (e.g. `Heny 04/2026`) skip the short-circuit (no full name present) and fall into the existing nickname check — now word-bounded, so `tov` no longer collides with `ottova` even there.
|
||||
- Combined-payment messages listing two full names continue to work: both are collected by the short-circuit.
|
||||
|
||||
### Files to modify
|
||||
|
||||
- [scripts/match_payments.py](scripts/match_payments.py) — only `match_members` (lines 51-115). Add `_word_in` helper just above it.
|
||||
|
||||
### Files to read for confidence (no edits)
|
||||
|
||||
- [scripts/czech_utils.py](scripts/czech_utils.py) — confirm `normalize()` semantics (NFKD strip + lowercase). Already understood; relevant because `re.escape` on already-normalized lowercase ASCII is safe.
|
||||
- [scripts/infer_payments.py](scripts/infer_payments.py) — confirm it just consumes the `match_members` output verbatim and writes comma-joined names. No change needed; the upstream fix propagates.
|
||||
- [scripts/match_payments.py:336-362](scripts/match_payments.py#L336-L362) — `reconcile()` only re-runs inference when `Person` is empty, so existing wrong rows in the sheet must be cleared by hand or via the `manual fix`/blank-cell workflow before re-running `make infer`.
|
||||
|
||||
## Verification
|
||||
|
||||
1. **Unit test** — add `tests/test_match_members.py` (new file, mirroring `tests/test_reconcile_exceptions.py` style). Cases:
|
||||
- `match_members("Henrietta Ottová (Heny): 04/2026", ["Henrietta Ottová", "Tomáš Němeček (Tov)"])` → `[("Henrietta Ottová", "auto")]` only.
|
||||
- `match_members("Heny 04/2026", ["Tomáš Němeček (Tov)", "Henrietta Ottová"])` → no match for Tomáš (the substring trap is closed); whatever the legitimate behavior for "Heny" is, document it.
|
||||
- Combined payment: `match_members("Henrietta Ottová a Tomáš Němeček 04/2026", ["Henrietta Ottová", "Tomáš Němeček (Tov)"])` → both as `auto`.
|
||||
- Sanity: `match_members("VS 1234 Tomáš Němeček", [...])` still returns Tomáš.
|
||||
|
||||
2. **Run the suite**: `make test`.
|
||||
|
||||
3. **End-to-end**: clear the buggy row's `Person`/`Purpose` cells in the payments sheet, then `make infer`, then `make reconcile`. Confirm the payment now allocates fully to Henrietta and balance reflects it.
|
||||
|
||||
4. **Changelog**: per [CLAUDE.md](CLAUDE.md), append an entry to [CHANGELOG.md](CHANGELOG.md) once the user confirms the fix works in production. Format: `## 2026-05-04 HH:MM TZ — fix: payment inference exact-match short-circuit`.
|
||||
11
go/.golangci.yml
Normal file
11
go/.golangci.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
linters:
|
||||
enable:
|
||||
- govet
|
||||
- staticcheck
|
||||
- errcheck
|
||||
- gofumpt
|
||||
- unused
|
||||
|
||||
linters-settings:
|
||||
gofumpt:
|
||||
extra-rules: true
|
||||
30
go/build/Dockerfile
Normal file
30
go/build/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
FROM golang:1.26 AS build
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
ARG GIT_TAG=unknown
|
||||
ARG GIT_COMMIT=unknown
|
||||
ARG BUILD_DATE=unknown
|
||||
|
||||
RUN CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags "-s -w \
|
||||
-X main.version=${GIT_TAG} \
|
||||
-X main.commit=${GIT_COMMIT} \
|
||||
-X main.buildDate=${BUILD_DATE}" \
|
||||
-o /out/fuj ./cmd/fuj
|
||||
|
||||
FROM alpine:3
|
||||
|
||||
RUN addgroup -S fuj && adduser -S fuj -G fuj
|
||||
|
||||
COPY --from=build /out/fuj /usr/local/bin/fuj
|
||||
|
||||
EXPOSE 8080
|
||||
USER fuj
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/fuj", "server"]
|
||||
84
go/cmd/fuj/main.go
Normal file
84
go/cmd/fuj/main.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"fuj-management/go/internal/config"
|
||||
"fuj-management/go/internal/logging"
|
||||
"fuj-management/go/internal/web"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Injected at build time via -ldflags "-X main.version=... -X main.commit=... -X main.buildDate=..."
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "unknown"
|
||||
buildDate = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
cmd, args := os.Args[1], os.Args[2:]
|
||||
|
||||
switch cmd {
|
||||
case "server":
|
||||
serverCmd(args)
|
||||
case "version":
|
||||
versionCmd()
|
||||
case "fees", "reconcile", "sync", "infer":
|
||||
fmt.Fprintf(os.Stderr, "fuj %s: not implemented yet (lands in M2/M4)\n", cmd)
|
||||
os.Exit(2)
|
||||
case "-h", "--help", "help":
|
||||
usage()
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "fuj: unknown command %q\n\n", cmd)
|
||||
usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
func serverCmd(args []string) {
|
||||
fs := flag.NewFlagSet("server", flag.ExitOnError)
|
||||
addr := fs.String("addr", "", "listen address (default from SERVER_ADDR env or :8080)")
|
||||
fs.Usage = func() {
|
||||
fmt.Fprintln(os.Stderr, "usage: fuj server [--addr :8080]")
|
||||
fs.PrintDefaults()
|
||||
}
|
||||
if err := fs.Parse(args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
cfg := config.Load()
|
||||
if *addr != "" {
|
||||
cfg.ServerAddr = *addr
|
||||
}
|
||||
|
||||
logger := logging.New(cfg.LogLevel)
|
||||
build := web.BuildInfo{Version: version, Commit: commit, BuildDate: buildDate}
|
||||
|
||||
if err := web.Run(logger, cfg.ServerAddr, build); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func versionCmd() {
|
||||
fmt.Printf("fuj %s (%s) built %s\n", version, commit, buildDate)
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintln(os.Stderr, `usage: fuj <command> [flags]
|
||||
|
||||
Commands:
|
||||
server Start HTTP server (default :8080)
|
||||
version Print version information
|
||||
fees Calculate monthly fees [M2]
|
||||
reconcile Show balance report [M2]
|
||||
sync Sync Fio transactions [M4]
|
||||
infer Infer payment details [M4]`)
|
||||
}
|
||||
56
go/internal/config/config.go
Normal file
56
go/internal/config/config.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Google Sheets IDs — change in code if sheets change (not from env).
|
||||
const (
|
||||
AttendanceSheetID = "1E2e_gT_K5AwSRCDLDTa2UetZTkHmBOcz0kFbBUNUNBA"
|
||||
PaymentsSheetID = "1Om0YPoDVCH5cV8BrNz5LG5eR5MMU05ypQC7UMN1xn_Y"
|
||||
JuniorSheetGID = "1213318614"
|
||||
)
|
||||
|
||||
// Config holds all runtime configuration loaded from environment variables.
|
||||
// Mirrors scripts/config.py.
|
||||
type Config struct {
|
||||
CredentialsPath string
|
||||
BankAccount string
|
||||
CacheTTL time.Duration
|
||||
CacheAPICheckTTL time.Duration
|
||||
LogLevel string
|
||||
FioAPIToken string
|
||||
ServerAddr string
|
||||
}
|
||||
|
||||
// Load reads configuration from the environment, applying defaults that
|
||||
// match the Python side.
|
||||
func Load() Config {
|
||||
return Config{
|
||||
CredentialsPath: env("CREDENTIALS_PATH", ".secret/fuj-management-bot-credentials.json"),
|
||||
BankAccount: env("BANK_ACCOUNT", "CZ8520100000002800359168"),
|
||||
CacheTTL: envDuration("CACHE_TTL_SECONDS", 300),
|
||||
CacheAPICheckTTL: envDuration("CACHE_API_CHECK_TTL_SECONDS", 300),
|
||||
LogLevel: env("LOG_LEVEL", "INFO"),
|
||||
FioAPIToken: env("FIO_API_TOKEN", ""),
|
||||
ServerAddr: env("SERVER_ADDR", ":8080"),
|
||||
}
|
||||
}
|
||||
|
||||
func env(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func envDuration(key string, defaultSeconds int) time.Duration {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
return time.Duration(n) * time.Second
|
||||
}
|
||||
}
|
||||
return time.Duration(defaultSeconds) * time.Second
|
||||
}
|
||||
24
go/internal/logging/logger.go
Normal file
24
go/internal/logging/logger.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// New returns a slog.Logger at the given level (DEBUG|INFO|WARN|ERROR).
|
||||
// Pass config.Config.LogLevel as the argument. Defaults to INFO on unrecognised input.
|
||||
func New(level string) *slog.Logger {
|
||||
var l slog.Level
|
||||
switch strings.ToUpper(level) {
|
||||
case "DEBUG":
|
||||
l = slog.LevelDebug
|
||||
case "WARN", "WARNING":
|
||||
l = slog.LevelWarn
|
||||
case "ERROR":
|
||||
l = slog.LevelError
|
||||
default:
|
||||
l = slog.LevelInfo
|
||||
}
|
||||
return slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: l}))
|
||||
}
|
||||
34
go/internal/web/middleware/timer.go
Normal file
34
go/internal/web/middleware/timer.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type statusWriter struct {
|
||||
http.ResponseWriter
|
||||
status int
|
||||
}
|
||||
|
||||
func (sw *statusWriter) WriteHeader(code int) {
|
||||
sw.status = code
|
||||
sw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
// RequestTimer logs method, path, status, and elapsed milliseconds for every
|
||||
// request. Parity with Python's get_render_time — the elapsed value maps to
|
||||
// render_time.total in the M5 JSON allowlist.
|
||||
func RequestTimer(logger *slog.Logger, next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
sw := &statusWriter{ResponseWriter: w, status: http.StatusOK}
|
||||
next.ServeHTTP(sw, r)
|
||||
logger.Info("req",
|
||||
"method", r.Method,
|
||||
"path", r.URL.Path,
|
||||
"status", sw.status,
|
||||
"ms", time.Since(start).Milliseconds(),
|
||||
)
|
||||
})
|
||||
}
|
||||
32
go/internal/web/server.go
Normal file
32
go/internal/web/server.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fuj-management/go/internal/web/middleware"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// BuildInfo carries the linker-injected build metadata.
|
||||
type BuildInfo struct {
|
||||
Version string
|
||||
Commit string
|
||||
BuildDate string
|
||||
}
|
||||
|
||||
// Run registers routes and starts the HTTP server on addr.
|
||||
func Run(logger *slog.Logger, addr string, build BuildInfo) error {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /{$}", helloHandler(build))
|
||||
|
||||
logger.Info("starting server", "addr", addr)
|
||||
return http.ListenAndServe(addr, middleware.RequestTimer(logger, mux))
|
||||
}
|
||||
|
||||
func helloHandler(build BuildInfo) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
fmt.Fprintf(w, "fuj-go ok\nversion: %s\ncommit: %s\nbuilt: %s\n",
|
||||
build.Version, build.Commit, build.BuildDate)
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,24 @@ from config import ATTENDANCE_SHEET_ID as SHEET_ID, JUNIOR_SHEET_GID
|
||||
EXPORT_URL = f"https://docs.google.com/spreadsheets/d/{SHEET_ID}/export?format=csv&gid=0"
|
||||
JUNIOR_EXPORT_URL = f"https://docs.google.com/spreadsheets/d/{SHEET_ID}/export?format=csv&gid={JUNIOR_SHEET_GID}"
|
||||
|
||||
FEE_FULL = 750 # CZK, for 2+ practices in a month
|
||||
FEE_SINGLE = 200 # CZK, for exactly 1 practice in a month
|
||||
ADULT_FEE_DEFAULT = 700 # CZK, for 2+ practices in a month
|
||||
ADULT_FEE_SINGLE = 200 # CZK, for exactly 1 practice in a month
|
||||
ADULT_FEE_MONTHLY_RATE = {
|
||||
"2025-09": 750,
|
||||
"2025-10": 750,
|
||||
"2025-11": 750,
|
||||
"2025-12": 750,
|
||||
"2026-01": 750,
|
||||
"2026-02": 750,
|
||||
"2026-03": 350,
|
||||
"2026-04": 700,
|
||||
"2026-05": 700,
|
||||
}
|
||||
|
||||
JUNIOR_FEE_DEFAULT = 500 # CZK for 2+ practices
|
||||
JUNIOR_MONTHLY_RATE = {
|
||||
"2025-09": 250
|
||||
"2025-09": 250,
|
||||
"2026-03": 250 # reduced fee for March 2026
|
||||
}
|
||||
ADULT_MERGED_MONTHS = {
|
||||
#"2025-12": "2026-01", # keys are merged into values
|
||||
@@ -76,13 +88,13 @@ def group_by_month(dates: list[tuple[int, datetime]], merged_months: dict[str, s
|
||||
return months
|
||||
|
||||
|
||||
def calculate_fee(attendance_count: int) -> int:
|
||||
"""Apply fee rules: 0 → 0, 1 → 200, 2+ → 750."""
|
||||
def calculate_fee(attendance_count: int, month_key: str) -> int:
|
||||
"""Apply fee rules: 0 → 0, 1 → 200, 2+ → configured rate (default 750)."""
|
||||
if attendance_count == 0:
|
||||
return 0
|
||||
if attendance_count == 1:
|
||||
return FEE_SINGLE
|
||||
return FEE_FULL
|
||||
return ADULT_FEE_SINGLE
|
||||
return ADULT_FEE_MONTHLY_RATE.get(month_key, ADULT_FEE_DEFAULT)
|
||||
|
||||
|
||||
def calculate_junior_fee(attendance_count: int, month_key: str) -> str | int:
|
||||
@@ -186,7 +198,7 @@ def get_members_with_fees() -> tuple[list[tuple[str, str, dict[str, int]]], list
|
||||
for c in cols
|
||||
if c < len(row) and row[c].strip().upper() == "TRUE"
|
||||
)
|
||||
fee = calculate_fee(count) if tier == "A" else 0
|
||||
fee = calculate_fee(count, month_key) if tier == "A" else 0
|
||||
month_fees[month_key] = (fee, count)
|
||||
members.append((name, tier, month_fees))
|
||||
|
||||
|
||||
@@ -155,3 +155,19 @@ def write_cache(sheet_id: str, modified_time: str, data: list | dict) -> None:
|
||||
logger.info(f"Wrote cache for {sheet_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to write cache {sheet_id}: {e}")
|
||||
|
||||
def flush_cache():
|
||||
"""Delete all cache files and reset in-memory state. Returns count of deleted files."""
|
||||
global _DRIVE_SERVICE
|
||||
_LAST_CHECKED.clear()
|
||||
_DRIVE_SERVICE = None
|
||||
|
||||
deleted = 0
|
||||
if CACHE_DIR.exists():
|
||||
for f in CACHE_DIR.glob("*_cache.json"):
|
||||
f.unlink()
|
||||
deleted += 1
|
||||
logger.info(f"Deleted cache file: {f.name}")
|
||||
|
||||
logger.info(f"Cache flushed: {deleted} files deleted, timers reset")
|
||||
return deleted
|
||||
|
||||
@@ -48,6 +48,11 @@ def _build_name_variants(name: str) -> list[str]:
|
||||
return [v for v in variants if len(v) >= 3]
|
||||
|
||||
|
||||
def _word_in(needle: str, haystack: str) -> bool:
|
||||
"""Return True if needle appears as a whole word in haystack."""
|
||||
return bool(re.search(rf"\b{re.escape(needle)}\b", haystack))
|
||||
|
||||
|
||||
def match_members(
|
||||
text: str, member_names: list[str]
|
||||
) -> list[tuple[str, str]]:
|
||||
@@ -56,6 +61,19 @@ def match_members(
|
||||
Returns list of (member_name, confidence) where confidence is 'auto' or 'review'.
|
||||
"""
|
||||
normalized_text = normalize(text)
|
||||
|
||||
# Short-circuit: if any member's full canonical name appears verbatim (whole words),
|
||||
# return only those matches and skip all fuzzy/nickname checks. This prevents a
|
||||
# nickname that is a substring of another member's surname from producing false hits.
|
||||
exact_matches = []
|
||||
for name in member_names:
|
||||
variants = _build_name_variants(name)
|
||||
full_name = variants[0] if variants else ""
|
||||
if full_name and _word_in(full_name, normalized_text):
|
||||
exact_matches.append((name, "auto"))
|
||||
if exact_matches:
|
||||
return exact_matches
|
||||
|
||||
matches = []
|
||||
|
||||
for name in member_names:
|
||||
@@ -70,17 +88,16 @@ def match_members(
|
||||
|
||||
# 2. Both first and last name present (any order) = high confidence
|
||||
if len(parts) >= 2:
|
||||
if parts[0] in normalized_text and parts[-1] in normalized_text:
|
||||
if _word_in(parts[0], normalized_text) and _word_in(parts[-1], normalized_text):
|
||||
matches.append((name, "auto"))
|
||||
continue
|
||||
|
||||
# 3. Nickname + one part of the name = high confidence
|
||||
# 3. Nickname present = high confidence
|
||||
nickname = ""
|
||||
nickname_match = re.search(r"\(([^)]+)\)", name)
|
||||
if nickname_match:
|
||||
nickname = normalize(nickname_match.group(1))
|
||||
if nickname and nickname in normalized_text:
|
||||
# Nickname alone is often enough, but let's check if it's combined with a name part
|
||||
if nickname and _word_in(nickname, normalized_text):
|
||||
matches.append((name, "auto"))
|
||||
continue
|
||||
|
||||
@@ -90,18 +107,15 @@ def match_members(
|
||||
last_name = parts[-1]
|
||||
_COMMON_SURNAMES = {"novak", "novakova", "prach"}
|
||||
|
||||
# Match last name
|
||||
if len(last_name) >= 4 and last_name not in _COMMON_SURNAMES and last_name in normalized_text:
|
||||
if len(last_name) >= 4 and last_name not in _COMMON_SURNAMES and _word_in(last_name, normalized_text):
|
||||
matches.append((name, "review"))
|
||||
continue
|
||||
|
||||
# Match first name (if not too short)
|
||||
if len(first_name) >= 3 and first_name in normalized_text:
|
||||
if len(first_name) >= 3 and _word_in(first_name, normalized_text):
|
||||
matches.append((name, "review"))
|
||||
continue
|
||||
elif len(parts) == 1:
|
||||
# Single name member
|
||||
if len(parts[0]) >= 4 and parts[0] in normalized_text:
|
||||
if len(parts[0]) >= 4 and _word_in(parts[0], normalized_text):
|
||||
matches.append((name, "review"))
|
||||
continue
|
||||
|
||||
@@ -109,7 +123,6 @@ def match_members(
|
||||
# If we have any "auto" matches, discard all "review" matches
|
||||
auto_matches = [m for m in matches if m[1] == "auto"]
|
||||
if auto_matches:
|
||||
# If multiple auto matches, keep them (ambiguous but high priority)
|
||||
return auto_matches
|
||||
|
||||
return matches
|
||||
@@ -385,8 +398,7 @@ def reconcile(
|
||||
})
|
||||
continue
|
||||
|
||||
num_allocations = len(matched_members) * len(matched_months)
|
||||
per_allocation = amount / num_allocations if num_allocations > 0 else 0
|
||||
member_share = amount / len(matched_members) if matched_members else 0
|
||||
|
||||
for member_name, confidence in matched_members:
|
||||
if member_name not in ledger:
|
||||
@@ -397,20 +409,64 @@ def reconcile(
|
||||
unmatched.append(tx)
|
||||
continue
|
||||
|
||||
for month_key in matched_months:
|
||||
entry = {
|
||||
"amount": per_allocation,
|
||||
in_window = [(m, ledger[member_name][m]["expected"]) for m in matched_months if m in ledger[member_name]]
|
||||
out_of_window = [m for m in matched_months if m not in ledger[member_name]]
|
||||
|
||||
# Out-of-window months (outside display range): even split → credit, same as before.
|
||||
n_total = len(matched_months)
|
||||
if out_of_window and n_total > 0:
|
||||
out_credit = member_share / n_total * len(out_of_window)
|
||||
credits[member_name] = credits.get(member_name, 0) + int(out_credit)
|
||||
else:
|
||||
out_credit = 0.0
|
||||
|
||||
in_window_share = member_share - out_credit
|
||||
|
||||
if not in_window:
|
||||
continue
|
||||
|
||||
total_expected = sum(e for _, e in in_window)
|
||||
|
||||
if total_expected > 0 and in_window_share >= total_expected:
|
||||
# Greedy phase: payment covers all in-window fees; overflow → credit.
|
||||
credits[member_name] = credits.get(member_name, 0) + int(in_window_share - total_expected)
|
||||
for m, exp in in_window:
|
||||
alloc = float(exp)
|
||||
ledger[member_name][m]["paid"] += alloc
|
||||
ledger[member_name][m]["transactions"].append({
|
||||
"amount": alloc,
|
||||
"date": tx["date"],
|
||||
"sender": tx["sender"],
|
||||
"message": tx["message"],
|
||||
"confidence": confidence,
|
||||
}
|
||||
if month_key in ledger[member_name]:
|
||||
ledger[member_name][month_key]["paid"] += per_allocation
|
||||
ledger[member_name][month_key]["transactions"].append(entry)
|
||||
})
|
||||
elif total_expected > 0:
|
||||
# Proportional phase: distribute in_window_share by each month's expected fee.
|
||||
# Last month absorbs any float remainder so the sum equals in_window_share exactly.
|
||||
remaining = in_window_share
|
||||
for i, (m, exp) in enumerate(in_window):
|
||||
alloc = remaining if i == len(in_window) - 1 else in_window_share * exp / total_expected
|
||||
remaining -= alloc
|
||||
ledger[member_name][m]["paid"] += alloc
|
||||
ledger[member_name][m]["transactions"].append({
|
||||
"amount": alloc,
|
||||
"date": tx["date"],
|
||||
"sender": tx["sender"],
|
||||
"message": tx["message"],
|
||||
"confidence": confidence,
|
||||
})
|
||||
else:
|
||||
# Future month — track as credit
|
||||
credits[member_name] = credits.get(member_name, 0) + int(per_allocation)
|
||||
# Fallback: no expected fees (prepayment before attendance recorded); even split.
|
||||
per_month = in_window_share / len(in_window)
|
||||
for m, _ in in_window:
|
||||
ledger[member_name][m]["paid"] += per_month
|
||||
ledger[member_name][m]["transactions"].append({
|
||||
"amount": per_month,
|
||||
"date": tx["date"],
|
||||
"sender": tx["sender"],
|
||||
"message": tx["message"],
|
||||
"confidence": confidence,
|
||||
})
|
||||
|
||||
# Calculate final total balances (window + off-window credits)
|
||||
final_balances: dict[str, int] = {}
|
||||
|
||||
@@ -167,6 +167,12 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cell-unpaid-current {
|
||||
color: #994444;
|
||||
background-color: rgba(153, 68, 68, 0.05);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cell-overridden {
|
||||
color: #ffa500 !important;
|
||||
}
|
||||
@@ -259,6 +265,24 @@
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #333;
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.filter-select:focus {
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.month-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
color: #888;
|
||||
text-transform: lowercase;
|
||||
@@ -458,12 +482,13 @@
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Tools:</span>
|
||||
<a href="/sync-bank">[Sync Bank Data]</a>
|
||||
<a href="/flush-cache">[Flush Cache]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Adults Dashboard</h1>
|
||||
@@ -477,6 +502,20 @@
|
||||
<div class="filter-container">
|
||||
<span class="filter-label">search member:</span>
|
||||
<input type="text" id="nameFilter" class="filter-input" placeholder="..." autocomplete="off">
|
||||
<span class="filter-label" style="margin-left: 16px;">from:</span>
|
||||
<select id="fromMonth" class="filter-select">
|
||||
{% for m in months %}
|
||||
<option value="{{ loop.index0 }}">{{ m }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span class="filter-label" style="margin-left: 8px;">to:</span>
|
||||
<select id="toMonth" class="filter-select">
|
||||
{% for m in months %}
|
||||
<option value="{{ loop.index0 }}">{{ m }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="button" onclick="applyMonthFilter()" class="filter-select" style="cursor: pointer;">Apply</button>
|
||||
<button type="button" onclick="resetMonthFilter()" class="filter-select" style="cursor: pointer;">All</button>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
@@ -485,7 +524,7 @@
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
<th data-month-idx="{{ loop.index0 }}">{{ m }}</th>
|
||||
{% endfor %}
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
@@ -498,20 +537,20 @@
|
||||
<span class="info-icon" onclick="showMemberDetails('{{ row.name|e }}')">[i]</span>
|
||||
</td>
|
||||
{% for cell in row.months %}
|
||||
<td title="{{ cell.tooltip }}"
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}{% if cell.overridden %} cell-overridden{% endif %}">
|
||||
<td data-month-idx="{{ loop.index0 }}" title="{{ cell.tooltip }}"
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif (cell.status == 'unpaid' or cell.status == 'partial') and cell.raw_month >= current_month %}cell-unpaid-current{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}{% if cell.overridden %} cell-overridden{% endif %}">
|
||||
{{ cell.text }}
|
||||
{% if cell.status == 'unpaid' or cell.status == 'partial' %}
|
||||
{% if (cell.status == 'unpaid' or cell.status == 'partial') and cell.raw_month < current_month %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button>
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{% if row.balance > 0 %}balance-pos{% elif row.balance < 0 %}balance-neg{% endif %}" style="position: relative;">
|
||||
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
|
||||
{% if row.balance < 0 %}
|
||||
{% if row.payable_amount > 0 %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button>
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ row.payable_amount }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -521,7 +560,7 @@
|
||||
TOTAL
|
||||
</td>
|
||||
{% for t in totals %}
|
||||
<td class="{% if t.status == 'ok' %}cell-ok{% elif t.status == 'unpaid' %}cell-unpaid{% elif t.status == 'surplus' %}cell-overridden{% endif %}" style="padding-top: 4px; padding-bottom: 4px;">
|
||||
<td data-month-idx="{{ loop.index0 }}" class="{% if t.status == 'ok' %}cell-ok{% elif t.status == 'unpaid' %}cell-unpaid{% elif t.status == 'surplus' %}cell-overridden{% endif %}" style="padding-top: 4px; padding-bottom: 4px;">
|
||||
<span style="font-size: 0.6em; font-weight: normal; color: #666; text-transform: lowercase; display: block; margin-bottom: 2px;">received / expected</span>
|
||||
{{ t.text }}
|
||||
</td>
|
||||
@@ -647,7 +686,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
@@ -857,9 +896,13 @@
|
||||
showMemberDetails(nextName);
|
||||
}
|
||||
}
|
||||
function showPayQR(name, amount, month) {
|
||||
function showPayQR(name, amount, month, rawMonth) {
|
||||
const account = "{{ bank_account }}";
|
||||
const message = `${name} / ${month}`;
|
||||
// Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
|
||||
const numericMonth = rawMonth.includes('+')
|
||||
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
|
||||
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
|
||||
const message = `${name}: ${numericMonth}`;
|
||||
const qrTitle = document.getElementById('qrTitle');
|
||||
const qrImg = document.getElementById('qrImg');
|
||||
const qrAccount = document.getElementById('qrAccount');
|
||||
@@ -884,6 +927,64 @@
|
||||
event.target.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Month range filter
|
||||
var maxMonthIdx;
|
||||
|
||||
function applyMonthFilter() {
|
||||
var fromIdx = parseInt(document.getElementById('fromMonth').value);
|
||||
var toIdx = parseInt(document.getElementById('toMonth').value);
|
||||
document.querySelectorAll('[data-month-idx]').forEach(function(el) {
|
||||
var idx = parseInt(el.getAttribute('data-month-idx'));
|
||||
if (idx >= fromIdx && idx <= toIdx) {
|
||||
el.classList.remove('month-hidden');
|
||||
} else {
|
||||
el.classList.add('month-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetMonthFilter() {
|
||||
var fromSelect = document.getElementById('fromMonth');
|
||||
var toSelect = document.getElementById('toMonth');
|
||||
fromSelect.value = 0;
|
||||
toSelect.value = maxMonthIdx;
|
||||
applyMonthFilter();
|
||||
}
|
||||
|
||||
// Remove future months from selects, set defaults, apply on load
|
||||
(function() {
|
||||
var now = new Date();
|
||||
var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
|
||||
maxMonthIdx = sortedMonths.length - 1;
|
||||
for (var i = 0; i < sortedMonths.length; i++) {
|
||||
if (sortedMonths[i] > currentMonth) {
|
||||
maxMonthIdx = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var fromSelect = document.getElementById('fromMonth');
|
||||
var toSelect = document.getElementById('toMonth');
|
||||
|
||||
// Remove future month options
|
||||
for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) {
|
||||
fromSelect.remove(i);
|
||||
toSelect.remove(i);
|
||||
}
|
||||
|
||||
// Hide future month columns permanently
|
||||
document.querySelectorAll('[data-month-idx]').forEach(function(el) {
|
||||
if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) {
|
||||
el.classList.add('month-hidden');
|
||||
}
|
||||
});
|
||||
|
||||
var defaultFrom = Math.max(0, maxMonthIdx - 4);
|
||||
fromSelect.value = defaultFrom;
|
||||
toSelect.value = maxMonthIdx;
|
||||
applyMonthFilter();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ Junior Fees Dashboard</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
color: #cccccc;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
background-color: transparent;
|
||||
border: 1px solid #333;
|
||||
box-shadow: none;
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
table-layout: auto;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 2px 8px;
|
||||
text-align: right;
|
||||
border-bottom: 1px dashed #222;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th:first-child,
|
||||
td:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: transparent;
|
||||
color: #888888;
|
||||
font-weight: normal;
|
||||
border-bottom: 1px solid #555;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
.total {
|
||||
font-weight: bold;
|
||||
background-color: transparent;
|
||||
color: #00ff00;
|
||||
border-top: 1px solid #555;
|
||||
}
|
||||
|
||||
.total:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.cell-empty {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
.cell-paid {
|
||||
color: #aaaaaa;
|
||||
}
|
||||
|
||||
.cell-overridden {
|
||||
color: #ffa500 !important;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
color: #888;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.description a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-size: 9px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.perf-breakdown {
|
||||
display: none;
|
||||
margin-top: 5px;
|
||||
color: #222;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors" class="active">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>FUJ Junior Fees Dashboard</h1>
|
||||
|
||||
<div class="description">
|
||||
Calculated monthly fees based on attendance markers.<br>
|
||||
Source: <a href="{{ attendance_url }}" target="_blank">Junior Attendance Sheet</a> |
|
||||
<a href="{{ payments_url }}" target="_blank">Payments Ledger</a>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in results %}
|
||||
<tr>
|
||||
<td>{{ row.name }}</td>
|
||||
{% for mdata in row.months %}
|
||||
<td
|
||||
class="{% if mdata.cell == '-' %}cell-empty{% elif mdata.overridden %}cell-overridden{% else %}cell-paid{% endif %}">
|
||||
{{ mdata.cell }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class="total">
|
||||
<td>TOTAL</td>
|
||||
{% for t in totals %}
|
||||
<td>{{ t }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,263 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ Fees Dashboard</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
/* Deeper black */
|
||||
color: #cccccc;
|
||||
/* Base gray terminal text */
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
/* Even smaller font */
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
/* Terminal green */
|
||||
font-family: inherit;
|
||||
/* Use monospace for header too */
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
background-color: transparent;
|
||||
/* Remove the card background */
|
||||
border: 1px solid #333;
|
||||
/* Just a thin outline if needed, or none */
|
||||
box-shadow: none;
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
table-layout: auto;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 2px 8px;
|
||||
/* Extremely tight padding */
|
||||
text-align: right;
|
||||
border-bottom: 1px dashed #222;
|
||||
/* Dashed lines for terminal feel */
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th:first-child,
|
||||
td:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: transparent;
|
||||
color: #888888;
|
||||
font-weight: normal;
|
||||
border-bottom: 1px solid #555;
|
||||
/* Stronger border for header */
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #1a1a1a;
|
||||
/* Very subtle hover */
|
||||
}
|
||||
|
||||
.total {
|
||||
font-weight: bold;
|
||||
background-color: transparent;
|
||||
color: #00ff00;
|
||||
/* Highlight total row */
|
||||
border-top: 1px solid #555;
|
||||
}
|
||||
|
||||
.total:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.cell-empty {
|
||||
color: #444444;
|
||||
/* Darker gray for empty cells */
|
||||
}
|
||||
|
||||
.cell-paid {
|
||||
color: #aaaaaa;
|
||||
/* Light gray for normal cells */
|
||||
}
|
||||
|
||||
.cell-overridden {
|
||||
color: #ffa500 !important;
|
||||
/* Orange for overrides */
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
color: #888;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.description a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-size: 9px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.perf-breakdown {
|
||||
display: none;
|
||||
margin-top: 5px;
|
||||
color: #222;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees" class="active">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>FUJ Fees Dashboard</h1>
|
||||
|
||||
<div class="description">
|
||||
Calculated monthly fees based on attendance markers.<br>
|
||||
Source: <a href="{{ attendance_url }}" target="_blank">Attendance Sheet</a> |
|
||||
<a href="{{ payments_url }}" target="_blank">Payments Ledger</a>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in results %}
|
||||
<tr>
|
||||
<td>{{ row.name }}</td>
|
||||
{% for mdata in row.months %}
|
||||
<td
|
||||
class="{% if mdata.cell == '-' %}cell-empty{% elif mdata.overridden %}cell-overridden{% else %}cell-paid{% endif %}">
|
||||
{{ mdata.cell }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class="total">
|
||||
<td>TOTAL</td>
|
||||
{% for t in totals %}
|
||||
<td>{{ t }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
163
templates/flush-cache.html
Normal file
163
templates/flush-cache.html
Normal file
@@ -0,0 +1,163 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ - Flush Cache</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
color: #cccccc;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.flush-container {
|
||||
background-color: #111;
|
||||
border: 1px solid #333;
|
||||
padding: 30px;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.flush-btn {
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
color: #00ff00;
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #00ff00;
|
||||
padding: 8px 24px;
|
||||
cursor: pointer;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.flush-btn:hover {
|
||||
background-color: #00ff00;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-bottom: 15px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-ok { color: #00ff00; }
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
margin-top: 20px;
|
||||
font-size: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Tools:</span>
|
||||
<a href="/sync-bank">[Sync Bank Data]</a>
|
||||
<a href="/flush-cache" class="active">[Flush Cache]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Flush Cache</h1>
|
||||
|
||||
{% if flushed %}
|
||||
<div class="status">
|
||||
<span class="status-ok">Cache flushed successfully. {{ deleted }} file(s) deleted.</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="flush-container">
|
||||
<p style="margin-bottom: 20px; color: #888;">Clears all cached Google Sheets data and resets refresh timers.</p>
|
||||
<form method="POST" action="/flush-cache">
|
||||
<button type="submit" class="flush-btn">[Flush Cache]</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
{{ build_meta.tag }} | {{ build_meta.commit }} | {{ build_meta.build_date }}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -167,6 +167,12 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cell-unpaid-current {
|
||||
color: #994444;
|
||||
background-color: rgba(153, 68, 68, 0.05);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cell-overridden {
|
||||
color: #ffa500 !important;
|
||||
}
|
||||
@@ -259,6 +265,24 @@
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #333;
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.filter-select:focus {
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.month-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
color: #888;
|
||||
text-transform: lowercase;
|
||||
@@ -458,12 +482,13 @@
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Tools:</span>
|
||||
<a href="/sync-bank">[Sync Bank Data]</a>
|
||||
<a href="/flush-cache">[Flush Cache]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Juniors Dashboard</h1>
|
||||
@@ -477,6 +502,20 @@
|
||||
<div class="filter-container">
|
||||
<span class="filter-label">search member:</span>
|
||||
<input type="text" id="nameFilter" class="filter-input" placeholder="..." autocomplete="off">
|
||||
<span class="filter-label" style="margin-left: 16px;">from:</span>
|
||||
<select id="fromMonth" class="filter-select">
|
||||
{% for m in months %}
|
||||
<option value="{{ loop.index0 }}">{{ m }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span class="filter-label" style="margin-left: 8px;">to:</span>
|
||||
<select id="toMonth" class="filter-select">
|
||||
{% for m in months %}
|
||||
<option value="{{ loop.index0 }}">{{ m }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="button" onclick="applyMonthFilter()" class="filter-select" style="cursor: pointer;">Apply</button>
|
||||
<button type="button" onclick="resetMonthFilter()" class="filter-select" style="cursor: pointer;">All</button>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
@@ -485,7 +524,7 @@
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
<th data-month-idx="{{ loop.index0 }}">{{ m }}</th>
|
||||
{% endfor %}
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
@@ -498,20 +537,20 @@
|
||||
<span class="info-icon" onclick="showMemberDetails('{{ row.name|e }}')">[i]</span>
|
||||
</td>
|
||||
{% for cell in row.months %}
|
||||
<td title="{{ cell.tooltip }}"
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}{% if cell.overridden %} cell-overridden{% endif %}">
|
||||
<td data-month-idx="{{ loop.index0 }}" title="{{ cell.tooltip }}"
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif (cell.status == 'unpaid' or cell.status == 'partial') and cell.raw_month >= current_month %}cell-unpaid-current{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}{% if cell.overridden %} cell-overridden{% endif %}">
|
||||
{{ cell.text }}
|
||||
{% if cell.status == 'unpaid' or cell.status == 'partial' %}
|
||||
{% if (cell.status == 'unpaid' or cell.status == 'partial') and cell.raw_month < current_month %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button>
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}', '{{ cell.raw_month }}')">Pay</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{% if row.balance > 0 %}balance-pos{% elif row.balance < 0 %}balance-neg{% endif %}" style="position: relative;">
|
||||
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
|
||||
{% if row.balance < 0 %}
|
||||
{% if row.payable_amount > 0 %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button>
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ row.payable_amount }}, '{{ row.unpaid_periods|e }}', '{{ row.raw_unpaid_periods|e }}')">Pay All</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -521,7 +560,7 @@
|
||||
TOTAL
|
||||
</td>
|
||||
{% for t in totals %}
|
||||
<td class="{% if t.status == 'ok' %}cell-ok{% elif t.status == 'unpaid' %}cell-unpaid{% elif t.status == 'surplus' %}cell-overridden{% endif %}" style="padding-top: 4px; padding-bottom: 4px;">
|
||||
<td data-month-idx="{{ loop.index0 }}" class="{% if t.status == 'ok' %}cell-ok{% elif t.status == 'unpaid' %}cell-unpaid{% elif t.status == 'surplus' %}cell-overridden{% endif %}" style="padding-top: 4px; padding-bottom: 4px;">
|
||||
<span style="font-size: 0.6em; font-weight: normal; color: #666; text-transform: lowercase; display: block; margin-bottom: 2px;">received / expected</span>
|
||||
{{ t.text }}
|
||||
</td>
|
||||
@@ -628,7 +667,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
@@ -838,9 +877,13 @@
|
||||
showMemberDetails(nextName);
|
||||
}
|
||||
}
|
||||
function showPayQR(name, amount, month) {
|
||||
function showPayQR(name, amount, month, rawMonth) {
|
||||
const account = "{{ bank_account }}";
|
||||
const message = `${name} / ${month}`;
|
||||
// Convert YYYY-MM to MM/YYYY for infer_payments.py compatibility
|
||||
const numericMonth = rawMonth.includes('+')
|
||||
? rawMonth.split('+').map(p => p.replace(/(\d{4})-(\d{2})/, '$2/$1')).join('+')
|
||||
: rawMonth.replace(/(\d{4})-(\d{2})/, '$2/$1');
|
||||
const message = `${name}: ${numericMonth}`;
|
||||
const qrTitle = document.getElementById('qrTitle');
|
||||
const qrImg = document.getElementById('qrImg');
|
||||
const qrAccount = document.getElementById('qrAccount');
|
||||
@@ -865,6 +908,64 @@
|
||||
event.target.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Month range filter
|
||||
var maxMonthIdx;
|
||||
|
||||
function applyMonthFilter() {
|
||||
var fromIdx = parseInt(document.getElementById('fromMonth').value);
|
||||
var toIdx = parseInt(document.getElementById('toMonth').value);
|
||||
document.querySelectorAll('[data-month-idx]').forEach(function(el) {
|
||||
var idx = parseInt(el.getAttribute('data-month-idx'));
|
||||
if (idx >= fromIdx && idx <= toIdx) {
|
||||
el.classList.remove('month-hidden');
|
||||
} else {
|
||||
el.classList.add('month-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetMonthFilter() {
|
||||
var fromSelect = document.getElementById('fromMonth');
|
||||
var toSelect = document.getElementById('toMonth');
|
||||
fromSelect.value = 0;
|
||||
toSelect.value = maxMonthIdx;
|
||||
applyMonthFilter();
|
||||
}
|
||||
|
||||
// Remove future months from selects, set defaults, apply on load
|
||||
(function() {
|
||||
var now = new Date();
|
||||
var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
|
||||
maxMonthIdx = sortedMonths.length - 1;
|
||||
for (var i = 0; i < sortedMonths.length; i++) {
|
||||
if (sortedMonths[i] > currentMonth) {
|
||||
maxMonthIdx = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var fromSelect = document.getElementById('fromMonth');
|
||||
var toSelect = document.getElementById('toMonth');
|
||||
|
||||
// Remove future month options
|
||||
for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) {
|
||||
fromSelect.remove(i);
|
||||
toSelect.remove(i);
|
||||
}
|
||||
|
||||
// Hide future month columns permanently
|
||||
document.querySelectorAll('[data-month-idx]').forEach(function(el) {
|
||||
if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) {
|
||||
el.classList.add('month-hidden');
|
||||
}
|
||||
});
|
||||
|
||||
var defaultFrom = Math.max(0, maxMonthIdx - 4);
|
||||
fromSelect.value = defaultFrom;
|
||||
toSelect.value = maxMonthIdx;
|
||||
applyMonthFilter();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -190,12 +190,13 @@
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments" class="active">[Payments Ledger]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Tools:</span>
|
||||
<a href="/sync-bank">[Sync Bank Data]</a>
|
||||
<a href="/flush-cache">[Flush Cache]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Payments Ledger</h1>
|
||||
@@ -237,7 +238,7 @@
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
{{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
|
||||
@@ -1,875 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ Junior Payment Reconciliation</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
color: #cccccc;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #00ff00;
|
||||
font-size: 12px;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 10px;
|
||||
text-transform: uppercase;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
border-bottom: 1px solid #333;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
color: #888;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.description a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
background-color: transparent;
|
||||
border: 1px solid #333;
|
||||
box-shadow: none;
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
table-layout: auto;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 2px 8px;
|
||||
text-align: right;
|
||||
border-bottom: 1px dashed #222;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th:first-child,
|
||||
td:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: transparent;
|
||||
color: #888888;
|
||||
font-weight: normal;
|
||||
border-bottom: 1px solid #555;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
.balance-pos {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.balance-neg {
|
||||
color: #ff3333;
|
||||
}
|
||||
|
||||
.cell-ok {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.cell-unpaid {
|
||||
color: #ff3333;
|
||||
background-color: rgba(255, 51, 51, 0.05);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pay-btn {
|
||||
display: none;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: #ff3333;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
padding: 2px 6px;
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.member-row:hover .pay-btn {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.cell-empty {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
.list-container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
color: #888;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
gap: 20px;
|
||||
padding: 1px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.list-item-name {
|
||||
color: #ccc;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.list-item-val {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.unmatched-row {
|
||||
font-family: inherit;
|
||||
display: grid;
|
||||
grid-template-columns: 100px 100px 200px 1fr;
|
||||
gap: 15px;
|
||||
color: #888;
|
||||
padding: 2px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.unmatched-header {
|
||||
color: #555;
|
||||
border-bottom: 1px solid #333;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin-bottom: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #333;
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
width: 250px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.filter-input:focus {
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
color: #888;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
color: #00ff00;
|
||||
cursor: pointer;
|
||||
margin-left: 5px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.info-icon:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Modal Styles */
|
||||
#memberModal {
|
||||
display: none !important;
|
||||
/* Force hide by default */
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
z-index: 9999;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#memberModal.active {
|
||||
display: flex !important;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: #0c0c0c;
|
||||
border: 1px solid #00ff00;
|
||||
width: 90%;
|
||||
max-width: 800px;
|
||||
max-height: 85vh;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 20px rgba(0, 255, 0, 0.2);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
border-bottom: 1px solid #333;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
color: #00ff00;
|
||||
font-size: 14px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
color: #ff3333;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.modal-section {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.modal-section-title {
|
||||
color: #555;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
margin-bottom: 8px;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.modal-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.modal-table th,
|
||||
.modal-table td {
|
||||
text-align: left;
|
||||
padding: 4px 0;
|
||||
border-bottom: 1px dashed #1a1a1a;
|
||||
}
|
||||
|
||||
.modal-table th {
|
||||
color: #666;
|
||||
font-weight: normal;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.tx-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tx-item {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.tx-meta {
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.tx-main {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.tx-amount {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.tx-sender {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.tx-msg {
|
||||
color: #888;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-size: 9px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.perf-breakdown {
|
||||
display: none;
|
||||
margin-top: 5px;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
/* QR Modal styles */
|
||||
#qrModal .modal-content {
|
||||
max-width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.qr-image {
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin: 20px 0;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.qr-image img {
|
||||
display: block;
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
.qr-details {
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
font-size: 14px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.qr-details div {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.qr-details span {
|
||||
color: #00ff00;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors" class="active">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Junior Payment Reconciliation</h1>
|
||||
|
||||
<div class="description">
|
||||
Balances calculated by matching Google Sheet payments against junior attendance fees.<br>
|
||||
Source: <a href="{{ attendance_url }}" target="_blank">Attendance Sheet</a> |
|
||||
<a href="{{ payments_url }}" target="_blank">Payments Ledger</a>
|
||||
</div>
|
||||
|
||||
<div class="filter-container">
|
||||
<span class="filter-label">search member:</span>
|
||||
<input type="text" id="nameFilter" class="filter-input" placeholder="..." autocomplete="off">
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
{% endfor %}
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="reconcileBody">
|
||||
{% for row in results %}
|
||||
<tr class="member-row">
|
||||
<td class="member-name">
|
||||
{{ row.name }}
|
||||
<span class="info-icon" onclick="showMemberDetails('{{ row.name|e }}')">[i]</span>
|
||||
</td>
|
||||
{% for cell in row.months %}
|
||||
<td
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}">
|
||||
{{ cell.text }}
|
||||
{% if cell.status == 'unpaid' or cell.status == 'partial' %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{% if row.balance > 0 %}balance-pos{% elif row.balance < 0 %}balance-neg{% endif %}" style="position: relative;">
|
||||
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
|
||||
{% if row.balance < 0 %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if credits %}
|
||||
<h2>Credits (Advance Payments / Surplus)</h2>
|
||||
<div class="list-container">
|
||||
{% for item in credits %}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{ item.name }}</span>
|
||||
<span class="list-item-val">{{ item.amount }} CZK</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if debts %}
|
||||
<h2>Debts (Missing Payments)</h2>
|
||||
<div class="list-container">
|
||||
{% for item in debts %}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{ item.name }}</span>
|
||||
<span class="list-item-val" style="color: #ff3333;">{{ item.amount }} CZK</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if unmatched %}
|
||||
<h2>Unmatched Transactions</h2>
|
||||
<div class="list-container">
|
||||
<div class="unmatched-row unmatched-header">
|
||||
<span>Date</span>
|
||||
<span>Amount</span>
|
||||
<span>Sender</span>
|
||||
<span>Message</span>
|
||||
</div>
|
||||
{% for tx in unmatched %}
|
||||
<div class="unmatched-row">
|
||||
<span>{{ tx.date }}</span>
|
||||
<span>{{ tx.amount }}</span>
|
||||
<span>{{ tx.sender }}</span>
|
||||
<span>{{ tx.message }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- QR Code Modal -->
|
||||
<div id="qrModal" class="modal"
|
||||
style="display:none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.9); z-index: 9999; justify-content: center; align-items: center;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="qrTitle">Payment for ...</div>
|
||||
<div class="close-btn" onclick="closeModal('qrModal')">[close]</div>
|
||||
</div>
|
||||
<div class="qr-image">
|
||||
<img id="qrImg" src="" alt="Payment QR Code">
|
||||
</div>
|
||||
<div class="qr-details">
|
||||
<div>Account: <span id="qrAccount"></span></div>
|
||||
<div>Amount: <span id="qrAmount"></span> CZK</div>
|
||||
<div>Message: <span id="qrMessage"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="memberModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="modalMemberName">Member Name</div>
|
||||
<div class="close-btn" onclick="closeModal()">[close]</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section">
|
||||
<div class="modal-section-title">Status Summary</div>
|
||||
<div id="modalTier" style="margin-bottom: 10px; color: #888;">Tier: -</div>
|
||||
<table class="modal-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Month</th>
|
||||
<th style="text-align: center;">Att.</th>
|
||||
<th style="text-align: center;">Expected</th>
|
||||
<th style="text-align: center;">Paid</th>
|
||||
<th style="text-align: right;">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="modalStatusBody">
|
||||
<!-- Filled by JS -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="modal-section" id="modalExceptionSection" style="display: none;">
|
||||
<div class="modal-section-title">Fee Exceptions</div>
|
||||
<div id="modalExceptionList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section" id="modalOtherSection" style="display: none;">
|
||||
<div class="modal-section-title">Other Transactions</div>
|
||||
<div id="modalOtherList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section">
|
||||
<div class="modal-section-title">Payment History</div>
|
||||
<div id="modalTxList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const memberData = {{ member_data| safe }};
|
||||
const sortedMonths = {{ raw_months| tojson }};
|
||||
const monthLabels = {{ month_labels_json| safe }};
|
||||
let currentMemberName = null;
|
||||
|
||||
function showMemberDetails(name) {
|
||||
currentMemberName = name;
|
||||
const data = memberData[name];
|
||||
if (!data) return;
|
||||
|
||||
document.getElementById('modalMemberName').textContent = name;
|
||||
document.getElementById('modalTier').textContent = 'Tier: ' + data.tier;
|
||||
|
||||
const statusBody = document.getElementById('modalStatusBody');
|
||||
statusBody.innerHTML = '';
|
||||
|
||||
// Collect all transactions for listing
|
||||
const allTransactions = [];
|
||||
|
||||
// We need to iterate over months in reverse to show newest first
|
||||
const monthKeys = Object.keys(data.months).sort().reverse();
|
||||
|
||||
monthKeys.forEach(m => {
|
||||
const mdata = data.months[m];
|
||||
const expected = mdata.expected || 0;
|
||||
const paid = mdata.paid || 0;
|
||||
const attendance = mdata.attendance_count || 0;
|
||||
const originalExpected = mdata.original_expected;
|
||||
|
||||
let status = '-';
|
||||
let statusClass = '';
|
||||
if (expected > 0 || paid > 0) {
|
||||
if (paid >= expected && expected > 0) { status = 'OK'; statusClass = 'cell-ok'; }
|
||||
else if (paid > 0) { status = paid + '/' + expected; }
|
||||
else { status = 'UNPAID ' + expected; statusClass = 'cell-unpaid'; }
|
||||
}
|
||||
|
||||
const expectedCell = mdata.exception
|
||||
? `<span style="color: #ffaa00;" title="Overridden from ${originalExpected}">${expected}*</span>`
|
||||
: expected;
|
||||
|
||||
const displayMonth = monthLabels[m] || m;
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td style="color: #888;">${displayMonth}</td>
|
||||
<td style="text-align: center; color: #ccc;">${attendance}</td>
|
||||
<td style="text-align: center; color: #ccc;">${expectedCell}</td>
|
||||
<td style="text-align: center; color: #ccc;">${paid}</td>
|
||||
<td style="text-align: right;" class="${statusClass}">${status}</td>
|
||||
`;
|
||||
statusBody.appendChild(row);
|
||||
|
||||
if (mdata.transactions) {
|
||||
mdata.transactions.forEach(tx => {
|
||||
allTransactions.push({ month: m, ...tx });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const exList = document.getElementById('modalExceptionList');
|
||||
const exSection = document.getElementById('modalExceptionSection');
|
||||
exList.innerHTML = '';
|
||||
|
||||
const exceptions = [];
|
||||
monthKeys.forEach(m => {
|
||||
if (data.months[m].exception) {
|
||||
exceptions.push({ month: m, ...data.months[m].exception });
|
||||
}
|
||||
});
|
||||
|
||||
if (exceptions.length > 0) {
|
||||
exSection.style.display = 'block';
|
||||
exceptions.forEach(ex => {
|
||||
const displayMonth = monthLabels[ex.month] || ex.month;
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item'; // Reuse style
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${displayMonth}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount" style="color: #ffaa00;">${ex.amount} CZK</span>
|
||||
</div>
|
||||
<div class="tx-msg">${ex.note || 'No details provided.'}</div>
|
||||
`;
|
||||
exList.appendChild(item);
|
||||
});
|
||||
} else {
|
||||
exSection.style.display = 'none';
|
||||
}
|
||||
|
||||
const otherList = document.getElementById('modalOtherList');
|
||||
const otherSection = document.getElementById('modalOtherSection');
|
||||
otherList.innerHTML = '';
|
||||
|
||||
if (data.other_transactions && data.other_transactions.length > 0) {
|
||||
otherSection.style.display = 'block';
|
||||
data.other_transactions.forEach(tx => {
|
||||
const displayPurpose = tx.purpose || 'Other';
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item';
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${tx.date} | ${displayPurpose}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount" style="color: #66ccff;">${tx.amount} CZK</span>
|
||||
<span class="tx-sender">${tx.sender}</span>
|
||||
</div>
|
||||
<div class="tx-msg">${tx.message || ''}</div>
|
||||
`;
|
||||
otherList.appendChild(item);
|
||||
});
|
||||
} else {
|
||||
otherSection.style.display = 'none';
|
||||
}
|
||||
|
||||
const txList = document.getElementById('modalTxList');
|
||||
txList.innerHTML = '';
|
||||
|
||||
if (allTransactions.length === 0) {
|
||||
txList.innerHTML = '<div style="color: #444; font-style: italic; padding: 10px 0;">No transactions matched to this member.</div>';
|
||||
} else {
|
||||
allTransactions.sort((a, b) => b.date.localeCompare(a.date)).forEach(tx => {
|
||||
const displayMonth = monthLabels[tx.month] || tx.month;
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item';
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${tx.date} | matched to ${displayMonth}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount">${tx.amount} CZK</span>
|
||||
<span class="tx-sender">${tx.sender}</span>
|
||||
</div>
|
||||
<div class="tx-msg">${tx.message || ''}</div>
|
||||
`;
|
||||
txList.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('memberModal').classList.add('active');
|
||||
}
|
||||
|
||||
function closeModal(id) {
|
||||
if (id) {
|
||||
document.getElementById(id).style.display = 'none';
|
||||
if (id === 'qrModal') {
|
||||
document.getElementById(id).style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
document.getElementById('memberModal').classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Existing filter script
|
||||
document.getElementById('nameFilter').addEventListener('input', function (e) {
|
||||
const filterValue = e.target.value.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
const rows = document.querySelectorAll('.member-row');
|
||||
|
||||
rows.forEach(row => {
|
||||
const nameNode = row.querySelector('.member-name');
|
||||
const name = nameNode.childNodes[0].textContent.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
if (name.includes(filterValue)) {
|
||||
row.style.display = '';
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close on Esc and Navigate with Arrows
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeModal();
|
||||
closeModal('qrModal');
|
||||
}
|
||||
|
||||
const modal = document.getElementById('memberModal');
|
||||
if (modal.classList.contains('active')) {
|
||||
if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
navigateMember(-1);
|
||||
} else if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
navigateMember(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function navigateMember(direction) {
|
||||
const rows = Array.from(document.querySelectorAll('.member-row'));
|
||||
const visibleRows = rows.filter(row => row.style.display !== 'none');
|
||||
|
||||
let currentIndex = visibleRows.findIndex(row => {
|
||||
const nameNode = row.querySelector('.member-name');
|
||||
const name = nameNode.childNodes[0].textContent.trim();
|
||||
return name === currentMemberName;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
let nextIndex = currentIndex + direction;
|
||||
if (nextIndex >= 0 && nextIndex < visibleRows.length) {
|
||||
const nextRow = visibleRows[nextIndex];
|
||||
const nextName = nextRow.querySelector('.member-name').childNodes[0].textContent.trim();
|
||||
showMemberDetails(nextName);
|
||||
}
|
||||
}
|
||||
function showPayQR(name, amount, month) {
|
||||
const account = "{{ bank_account }}";
|
||||
const message = `${name} / ${month}`;
|
||||
const qrTitle = document.getElementById('qrTitle');
|
||||
const qrImg = document.getElementById('qrImg');
|
||||
const qrAccount = document.getElementById('qrAccount');
|
||||
const qrAmount = document.getElementById('qrAmount');
|
||||
const qrMessage = document.getElementById('qrMessage');
|
||||
|
||||
qrTitle.innerText = `Payment for ${month}`;
|
||||
qrAccount.innerText = account;
|
||||
qrAmount.innerText = amount;
|
||||
qrMessage.innerText = message;
|
||||
|
||||
const encodedMessage = encodeURIComponent(message);
|
||||
const qrUrl = `/qr?account=${encodeURIComponent(account)}&amount=${amount}&message=${encodedMessage}`;
|
||||
|
||||
qrImg.src = qrUrl;
|
||||
document.getElementById('qrModal').style.display = 'block';
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
window.onclick = function (event) {
|
||||
if (event.target.className === 'modal') {
|
||||
event.target.style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
```
|
||||
@@ -1,875 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ Payment Reconciliation</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
color: #cccccc;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #00ff00;
|
||||
font-size: 12px;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 10px;
|
||||
text-transform: uppercase;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
border-bottom: 1px solid #333;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
color: #888;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.description a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.description a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
background-color: transparent;
|
||||
border: 1px solid #333;
|
||||
box-shadow: none;
|
||||
overflow-x: auto;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
table-layout: auto;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 2px 8px;
|
||||
text-align: right;
|
||||
border-bottom: 1px dashed #222;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th:first-child,
|
||||
td:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: transparent;
|
||||
color: #888888;
|
||||
font-weight: normal;
|
||||
border-bottom: 1px solid #555;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
.balance-pos {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.balance-neg {
|
||||
color: #ff3333;
|
||||
}
|
||||
|
||||
.cell-ok {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.cell-unpaid {
|
||||
color: #ff3333;
|
||||
background-color: rgba(255, 51, 51, 0.05);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pay-btn {
|
||||
display: none;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: #ff3333;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
padding: 2px 6px;
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.member-row:hover .pay-btn {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.cell-empty {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
.list-container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
color: #888;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
gap: 20px;
|
||||
padding: 1px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.list-item-name {
|
||||
color: #ccc;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.list-item-val {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.unmatched-row {
|
||||
font-family: inherit;
|
||||
display: grid;
|
||||
grid-template-columns: 100px 100px 200px 1fr;
|
||||
gap: 15px;
|
||||
color: #888;
|
||||
padding: 2px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.unmatched-header {
|
||||
color: #555;
|
||||
border-bottom: 1px solid #333;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin-bottom: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #333;
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
width: 250px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.filter-input:focus {
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
color: #888;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
color: #00ff00;
|
||||
cursor: pointer;
|
||||
margin-left: 5px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.info-icon:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Modal Styles */
|
||||
#memberModal {
|
||||
display: none !important;
|
||||
/* Force hide by default */
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
z-index: 9999;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#memberModal.active {
|
||||
display: flex !important;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: #0c0c0c;
|
||||
border: 1px solid #00ff00;
|
||||
width: 90%;
|
||||
max-width: 800px;
|
||||
max-height: 85vh;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 20px rgba(0, 255, 0, 0.2);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
border-bottom: 1px solid #333;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
color: #00ff00;
|
||||
font-size: 14px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
color: #ff3333;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.modal-section {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.modal-section-title {
|
||||
color: #555;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
margin-bottom: 8px;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.modal-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.modal-table th,
|
||||
.modal-table td {
|
||||
text-align: left;
|
||||
padding: 4px 0;
|
||||
border-bottom: 1px dashed #1a1a1a;
|
||||
}
|
||||
|
||||
.modal-table th {
|
||||
color: #666;
|
||||
font-weight: normal;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.tx-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tx-item {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px dashed #222;
|
||||
}
|
||||
|
||||
.tx-meta {
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.tx-main {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.tx-amount {
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.tx-sender {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.tx-msg {
|
||||
color: #888;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-size: 9px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.perf-breakdown {
|
||||
display: none;
|
||||
margin-top: 5px;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
/* QR Modal styles */
|
||||
#qrModal .modal-content {
|
||||
max-width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.qr-image {
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin: 20px 0;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.qr-image img {
|
||||
display: block;
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
.qr-details {
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
font-size: 14px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.qr-details div {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.qr-details span {
|
||||
color: #00ff00;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/fees">[Adult - Attendance/Fees]</a>
|
||||
<a href="/fees-juniors">[Junior Attendance/Fees]</a>
|
||||
<a href="/reconcile" class="active">[Adult Payment Reconciliation]</a>
|
||||
<a href="/reconcile-juniors">[Junior Payment Reconciliation]</a>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Payment Reconciliation</h1>
|
||||
|
||||
<div class="description">
|
||||
Balances calculated by matching Google Sheet payments against attendance fees.<br>
|
||||
Source: <a href="{{ attendance_url }}" target="_blank">Attendance Sheet</a> |
|
||||
<a href="{{ payments_url }}" target="_blank">Payments Ledger</a>
|
||||
</div>
|
||||
|
||||
<div class="filter-container">
|
||||
<span class="filter-label">search member:</span>
|
||||
<input type="text" id="nameFilter" class="filter-input" placeholder="..." autocomplete="off">
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{% for m in months %}
|
||||
<th>{{ m }}</th>
|
||||
{% endfor %}
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="reconcileBody">
|
||||
{% for row in results %}
|
||||
<tr class="member-row">
|
||||
<td class="member-name">
|
||||
{{ row.name }}
|
||||
<span class="info-icon" onclick="showMemberDetails('{{ row.name|e }}')">[i]</span>
|
||||
</td>
|
||||
{% for cell in row.months %}
|
||||
<td
|
||||
class="{% if cell.status == 'empty' %}cell-empty{% elif cell.status == 'unpaid' or cell.status == 'partial' %}cell-unpaid{% elif cell.status == 'ok' %}cell-ok{% endif %}">
|
||||
{{ cell.text }}
|
||||
{% if cell.status == 'unpaid' or cell.status == 'partial' %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ cell.amount }}, '{{ cell.month|e }}')">Pay</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="{% if row.balance > 0 %}balance-pos{% elif row.balance < 0 %}balance-neg{% endif %}" style="position: relative;">
|
||||
{{ "%+d"|format(row.balance) if row.balance != 0 else "0" }}
|
||||
{% if row.balance < 0 %}
|
||||
<button class="pay-btn"
|
||||
onclick="showPayQR('{{ row.name|e }}', {{ -row.balance }}, '{{ row.unpaid_periods|e }}')">Pay All</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if credits %}
|
||||
<h2>Credits (Advance Payments / Surplus)</h2>
|
||||
<div class="list-container">
|
||||
{% for item in credits %}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{ item.name }}</span>
|
||||
<span class="list-item-val">{{ item.amount }} CZK</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if debts %}
|
||||
<h2>Debts (Missing Payments)</h2>
|
||||
<div class="list-container">
|
||||
{% for item in debts %}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{ item.name }}</span>
|
||||
<span class="list-item-val" style="color: #ff3333;">{{ item.amount }} CZK</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if unmatched %}
|
||||
<h2>Unmatched Transactions</h2>
|
||||
<div class="list-container">
|
||||
<div class="unmatched-row unmatched-header">
|
||||
<span>Date</span>
|
||||
<span>Amount</span>
|
||||
<span>Sender</span>
|
||||
<span>Message</span>
|
||||
</div>
|
||||
{% for tx in unmatched %}
|
||||
<div class="unmatched-row">
|
||||
<span>{{ tx.date }}</span>
|
||||
<span>{{ tx.amount }}</span>
|
||||
<span>{{ tx.sender }}</span>
|
||||
<span>{{ tx.message }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- QR Code Modal -->
|
||||
<div id="qrModal" class="modal"
|
||||
style="display:none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.9); z-index: 9999; justify-content: center; align-items: center;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="qrTitle">Payment for ...</div>
|
||||
<div class="close-btn" onclick="closeModal('qrModal')">[close]</div>
|
||||
</div>
|
||||
<div class="qr-image">
|
||||
<img id="qrImg" src="" alt="Payment QR Code">
|
||||
</div>
|
||||
<div class="qr-details">
|
||||
<div>Account: <span id="qrAccount"></span></div>
|
||||
<div>Amount: <span id="qrAmount"></span> CZK</div>
|
||||
<div>Message: <span id="qrMessage"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="memberModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="modalMemberName">Member Name</div>
|
||||
<div class="close-btn" onclick="closeModal()">[close]</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section">
|
||||
<div class="modal-section-title">Status Summary</div>
|
||||
<div id="modalTier" style="margin-bottom: 10px; color: #888;">Tier: -</div>
|
||||
<table class="modal-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Month</th>
|
||||
<th style="text-align: center;">Att.</th>
|
||||
<th style="text-align: center;">Expected</th>
|
||||
<th style="text-align: center;">Paid</th>
|
||||
<th style="text-align: right;">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="modalStatusBody">
|
||||
<!-- Filled by JS -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="modal-section" id="modalExceptionSection" style="display: none;">
|
||||
<div class="modal-section-title">Fee Exceptions</div>
|
||||
<div id="modalExceptionList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section" id="modalOtherSection" style="display: none;">
|
||||
<div class="modal-section-title">Other Transactions</div>
|
||||
<div id="modalOtherList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section">
|
||||
<div class="modal-section-title">Payment History</div>
|
||||
<div id="modalTxList" class="tx-list">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% set rt = get_render_time() %}
|
||||
<div class="footer"
|
||||
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
|
||||
render time: {{ rt.total }}s
|
||||
<div id="perf-details" class="perf-breakdown">
|
||||
{{ rt.breakdown }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const memberData = {{ member_data| safe }};
|
||||
const sortedMonths = {{ raw_months| tojson }};
|
||||
const monthLabels = {{ month_labels_json| safe }};
|
||||
let currentMemberName = null;
|
||||
|
||||
function showMemberDetails(name) {
|
||||
currentMemberName = name;
|
||||
const data = memberData[name];
|
||||
if (!data) return;
|
||||
|
||||
document.getElementById('modalMemberName').textContent = name;
|
||||
document.getElementById('modalTier').textContent = 'Tier: ' + data.tier;
|
||||
|
||||
const statusBody = document.getElementById('modalStatusBody');
|
||||
statusBody.innerHTML = '';
|
||||
|
||||
// Collect all transactions for listing
|
||||
const allTransactions = [];
|
||||
|
||||
// We need to iterate over months in reverse to show newest first
|
||||
const monthKeys = Object.keys(data.months).sort().reverse();
|
||||
|
||||
monthKeys.forEach(m => {
|
||||
const mdata = data.months[m];
|
||||
const expected = mdata.expected || 0;
|
||||
const paid = mdata.paid || 0;
|
||||
const attendance = mdata.attendance_count || 0;
|
||||
const originalExpected = mdata.original_expected;
|
||||
|
||||
let status = '-';
|
||||
let statusClass = '';
|
||||
if (expected > 0 || paid > 0) {
|
||||
if (paid >= expected && expected > 0) { status = 'OK'; statusClass = 'cell-ok'; }
|
||||
else if (paid > 0) { status = paid + '/' + expected; }
|
||||
else { status = 'UNPAID ' + expected; statusClass = 'cell-unpaid'; }
|
||||
}
|
||||
|
||||
const expectedCell = mdata.exception
|
||||
? `<span style="color: #ffaa00;" title="Overridden from ${originalExpected}">${expected}*</span>`
|
||||
: expected;
|
||||
|
||||
const displayMonth = monthLabels[m] || m;
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td style="color: #888;">${displayMonth}</td>
|
||||
<td style="text-align: center; color: #ccc;">${attendance}</td>
|
||||
<td style="text-align: center; color: #ccc;">${expectedCell}</td>
|
||||
<td style="text-align: center; color: #ccc;">${paid}</td>
|
||||
<td style="text-align: right;" class="${statusClass}">${status}</td>
|
||||
`;
|
||||
statusBody.appendChild(row);
|
||||
|
||||
if (mdata.transactions) {
|
||||
mdata.transactions.forEach(tx => {
|
||||
allTransactions.push({ month: m, ...tx });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const exList = document.getElementById('modalExceptionList');
|
||||
const exSection = document.getElementById('modalExceptionSection');
|
||||
exList.innerHTML = '';
|
||||
|
||||
const exceptions = [];
|
||||
monthKeys.forEach(m => {
|
||||
if (data.months[m].exception) {
|
||||
exceptions.push({ month: m, ...data.months[m].exception });
|
||||
}
|
||||
});
|
||||
|
||||
if (exceptions.length > 0) {
|
||||
exSection.style.display = 'block';
|
||||
exceptions.forEach(ex => {
|
||||
const displayMonth = monthLabels[ex.month] || ex.month;
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item'; // Reuse style
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${displayMonth}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount" style="color: #ffaa00;">${ex.amount} CZK</span>
|
||||
</div>
|
||||
<div class="tx-msg">${ex.note || 'No details provided.'}</div>
|
||||
`;
|
||||
exList.appendChild(item);
|
||||
});
|
||||
} else {
|
||||
exSection.style.display = 'none';
|
||||
}
|
||||
|
||||
const otherList = document.getElementById('modalOtherList');
|
||||
const otherSection = document.getElementById('modalOtherSection');
|
||||
otherList.innerHTML = '';
|
||||
|
||||
if (data.other_transactions && data.other_transactions.length > 0) {
|
||||
otherSection.style.display = 'block';
|
||||
data.other_transactions.forEach(tx => {
|
||||
const displayPurpose = tx.purpose || 'Other';
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item';
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${tx.date} | ${displayPurpose}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount" style="color: #66ccff;">${tx.amount} CZK</span>
|
||||
<span class="tx-sender">${tx.sender}</span>
|
||||
</div>
|
||||
<div class="tx-msg">${tx.message || ''}</div>
|
||||
`;
|
||||
otherList.appendChild(item);
|
||||
});
|
||||
} else {
|
||||
otherSection.style.display = 'none';
|
||||
}
|
||||
|
||||
const txList = document.getElementById('modalTxList');
|
||||
txList.innerHTML = '';
|
||||
|
||||
if (allTransactions.length === 0) {
|
||||
txList.innerHTML = '<div style="color: #444; font-style: italic; padding: 10px 0;">No transactions matched to this member.</div>';
|
||||
} else {
|
||||
allTransactions.sort((a, b) => b.date.localeCompare(a.date)).forEach(tx => {
|
||||
const displayMonth = monthLabels[tx.month] || tx.month;
|
||||
const item = document.createElement('div');
|
||||
item.className = 'tx-item';
|
||||
item.innerHTML = `
|
||||
<div class="tx-meta">${tx.date} | matched to ${displayMonth}</div>
|
||||
<div class="tx-main">
|
||||
<span class="tx-amount">${tx.amount} CZK</span>
|
||||
<span class="tx-sender">${tx.sender}</span>
|
||||
</div>
|
||||
<div class="tx-msg">${tx.message || ''}</div>
|
||||
`;
|
||||
txList.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('memberModal').classList.add('active');
|
||||
}
|
||||
|
||||
function closeModal(id) {
|
||||
if (id) {
|
||||
document.getElementById(id).style.display = 'none';
|
||||
if (id === 'qrModal') {
|
||||
document.getElementById(id).style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
document.getElementById('memberModal').classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Existing filter script
|
||||
document.getElementById('nameFilter').addEventListener('input', function (e) {
|
||||
const filterValue = e.target.value.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
const rows = document.querySelectorAll('.member-row');
|
||||
|
||||
rows.forEach(row => {
|
||||
const nameNode = row.querySelector('.member-name');
|
||||
const name = nameNode.childNodes[0].textContent.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
if (name.includes(filterValue)) {
|
||||
row.style.display = '';
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close on Esc and Navigate with Arrows
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeModal();
|
||||
closeModal('qrModal');
|
||||
}
|
||||
|
||||
const modal = document.getElementById('memberModal');
|
||||
if (modal.classList.contains('active')) {
|
||||
if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
navigateMember(-1);
|
||||
} else if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
navigateMember(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function navigateMember(direction) {
|
||||
const rows = Array.from(document.querySelectorAll('.member-row'));
|
||||
const visibleRows = rows.filter(row => row.style.display !== 'none');
|
||||
|
||||
let currentIndex = visibleRows.findIndex(row => {
|
||||
const nameNode = row.querySelector('.member-name');
|
||||
const name = nameNode.childNodes[0].textContent.trim();
|
||||
return name === currentMemberName;
|
||||
});
|
||||
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
let nextIndex = currentIndex + direction;
|
||||
if (nextIndex >= 0 && nextIndex < visibleRows.length) {
|
||||
const nextRow = visibleRows[nextIndex];
|
||||
const nextName = nextRow.querySelector('.member-name').childNodes[0].textContent.trim();
|
||||
showMemberDetails(nextName);
|
||||
}
|
||||
}
|
||||
function showPayQR(name, amount, month) {
|
||||
const account = "{{ bank_account }}";
|
||||
const message = `${name} / ${month}`;
|
||||
const qrTitle = document.getElementById('qrTitle');
|
||||
const qrImg = document.getElementById('qrImg');
|
||||
const qrAccount = document.getElementById('qrAccount');
|
||||
const qrAmount = document.getElementById('qrAmount');
|
||||
const qrMessage = document.getElementById('qrMessage');
|
||||
|
||||
qrTitle.innerText = `Payment for ${month}`;
|
||||
qrAccount.innerText = account;
|
||||
qrAmount.innerText = amount;
|
||||
qrMessage.innerText = message;
|
||||
|
||||
const encodedMessage = encodeURIComponent(message);
|
||||
const qrUrl = `/qr?account=${encodeURIComponent(account)}&amount=${amount}&message=${encodedMessage}`;
|
||||
|
||||
qrImg.src = qrUrl;
|
||||
document.getElementById('qrModal').style.display = 'block';
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
window.onclick = function (event) {
|
||||
if (event.target.className === 'modal') {
|
||||
event.target.style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
```
|
||||
153
templates/sync.html
Normal file
153
templates/sync.html
Normal file
@@ -0,0 +1,153 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>FUJ - Sync Bank Data</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
background-color: #0c0c0c;
|
||||
color: #cccccc;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #00ff00;
|
||||
font-family: inherit;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 20px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-bottom: 20px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav > div {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
|
||||
.nav a.active {
|
||||
color: #000;
|
||||
background-color: #00ff00;
|
||||
border-color: #00ff00;
|
||||
}
|
||||
|
||||
.nav a:hover {
|
||||
color: #fff;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a {
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
border-color: #222;
|
||||
}
|
||||
|
||||
.nav-archived a.active {
|
||||
color: #ccc;
|
||||
background-color: #333;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.nav-archived a:hover {
|
||||
color: #999;
|
||||
border-color: #444;
|
||||
}
|
||||
|
||||
.output-container {
|
||||
background-color: #111;
|
||||
border: 1px solid #333;
|
||||
padding: 15px;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
margin-bottom: 30px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.output-container pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
color: {% if success %}#cccccc{% else %}#ff6666{% endif %};
|
||||
}
|
||||
|
||||
.status {
|
||||
margin-bottom: 15px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-ok { color: #00ff00; }
|
||||
.status-error { color: #ff6666; }
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
margin-top: 20px;
|
||||
font-size: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav">
|
||||
<div>
|
||||
<a href="/adults">[Adults]</a>
|
||||
<a href="/juniors">[Juniors]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Archived:</span>
|
||||
<a href="/payments">[Payments Ledger]</a>
|
||||
</div>
|
||||
<div class="nav-archived">
|
||||
<span style="color: #666; margin-right: 5px;">Tools:</span>
|
||||
<a href="/sync-bank" class="active">[Sync Bank Data]</a>
|
||||
<a href="/flush-cache">[Flush Cache]</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Sync Bank Data</h1>
|
||||
|
||||
<div class="status">
|
||||
{% if success %}
|
||||
<span class="status-ok">Sync completed successfully.</span>
|
||||
{% else %}
|
||||
<span class="status-error">Sync failed - see output below.</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="output-container">
|
||||
<pre>{{ output }}</pre>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
{{ build_meta.tag }} | {{ build_meta.commit }} | {{ build_meta.build_date }}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
53
tests/test_match_members.py
Normal file
53
tests/test_match_members.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import unittest
|
||||
from scripts.match_payments import match_members
|
||||
|
||||
|
||||
MEMBERS = [
|
||||
"Henrietta Ottová",
|
||||
"Tomáš Němeček (Tov)",
|
||||
"František Vrbík (Štrúdl)",
|
||||
"Jana Nováková",
|
||||
]
|
||||
|
||||
|
||||
class TestMatchMembersExact(unittest.TestCase):
|
||||
def test_full_name_in_message_returns_only_that_member(self):
|
||||
# "tov" is a substring of "ottova" — the old code returned both members
|
||||
result = match_members("Henrietta Ottová (Heny): 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertEqual(names, ["Henrietta Ottová"])
|
||||
self.assertTrue(all(conf == "auto" for _, conf in result))
|
||||
|
||||
def test_nickname_tov_not_matched_inside_ottova(self):
|
||||
# Bare nickname message should NOT match Tomáš via "tov" inside "ottova"
|
||||
result = match_members("platba ottova 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertNotIn("Tomáš Němeček (Tov)", names)
|
||||
|
||||
def test_combined_payment_two_full_names(self):
|
||||
result = match_members("Henrietta Ottová a Tomáš Němeček 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertIn("Henrietta Ottová", names)
|
||||
self.assertIn("Tomáš Němeček (Tov)", names)
|
||||
self.assertTrue(all(conf == "auto" for _, conf in result))
|
||||
|
||||
def test_nickname_alone_still_matches_correctly(self):
|
||||
# "Tov" alone should still match Tomáš (as long as "ottova" is not in the text)
|
||||
result = match_members("Tov platba 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertIn("Tomáš Němeček (Tov)", names)
|
||||
|
||||
def test_full_name_no_diacritics_still_matches(self):
|
||||
result = match_members("Henrietta Ottova 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertIn("Henrietta Ottová", names)
|
||||
self.assertNotIn("Tomáš Němeček (Tov)", names)
|
||||
|
||||
def test_first_last_name_present_any_order(self):
|
||||
result = match_members("Platba od Nemeček Tomas 04/2026", MEMBERS)
|
||||
names = [r[0] for r in result]
|
||||
self.assertIn("Tomáš Němeček (Tov)", names)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -52,5 +52,108 @@ class TestReconcileWithExceptions(unittest.TestCase):
|
||||
alice_data = result['members']['Alice']
|
||||
self.assertEqual(alice_data['months']['2026-01']['expected'], 750, "Should fallback to attendance fee")
|
||||
|
||||
def _tx(person, purpose, amount):
|
||||
return {
|
||||
'date': '2026-01-01',
|
||||
'amount': amount,
|
||||
'person': person,
|
||||
'purpose': purpose,
|
||||
'inferred_amount': amount,
|
||||
'sender': 'Sender',
|
||||
'message': 'fee',
|
||||
}
|
||||
|
||||
|
||||
class TestMultiMonthAllocation(unittest.TestCase):
|
||||
"""Fee-aware allocation across multiple months in a single payment."""
|
||||
|
||||
def test_greedy_exact_match(self):
|
||||
"""Payment equals total expected → every month fully covered (green)."""
|
||||
members = [('Alice', 'A', {'2026-02': (750, 3), '2026-03': (350, 3), '2026-04': (150, 2)})]
|
||||
sorted_months = ['2026-02', '2026-03', '2026-04']
|
||||
tx = _tx('Alice', '2026-02, 2026-03, 2026-04', 1250)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
months = result['members']['Alice']['months']
|
||||
|
||||
self.assertEqual(int(months['2026-02']['paid']), 750)
|
||||
self.assertEqual(int(months['2026-03']['paid']), 350)
|
||||
self.assertEqual(int(months['2026-04']['paid']), 150)
|
||||
|
||||
def test_greedy_overpayment_goes_to_credit(self):
|
||||
"""Payment exceeds total expected → each month fully covered, surplus → credit."""
|
||||
members = [('Alice', 'A', {'2026-01': (750, 3), '2026-02': (750, 3)})]
|
||||
sorted_months = ['2026-01', '2026-02']
|
||||
tx = _tx('Alice', '2026-01, 2026-02', 2000)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
months = result['members']['Alice']['months']
|
||||
|
||||
self.assertEqual(int(months['2026-01']['paid']), 750)
|
||||
self.assertEqual(int(months['2026-02']['paid']), 750)
|
||||
self.assertEqual(result['credits'].get('Alice', 0), 500)
|
||||
|
||||
def test_proportional_underpayment(self):
|
||||
"""Payment < total expected → proportional split; sum of paid == payment amount."""
|
||||
members = [('Alice', 'A', {'2026-02': (750, 3), '2026-03': (350, 3), '2026-04': (750, 3)})]
|
||||
sorted_months = ['2026-02', '2026-03', '2026-04']
|
||||
amount = 1250
|
||||
tx = _tx('Alice', '2026-02, 2026-03, 2026-04', amount)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
months = result['members']['Alice']['months']
|
||||
|
||||
paid_02 = months['2026-02']['paid']
|
||||
paid_03 = months['2026-03']['paid']
|
||||
paid_04 = months['2026-04']['paid']
|
||||
|
||||
# All months should be partial (underpaid)
|
||||
self.assertLess(paid_02, 750)
|
||||
self.assertLess(paid_03, 350)
|
||||
self.assertLess(paid_04, 750)
|
||||
# Sum must equal the original payment (no CZK lost)
|
||||
self.assertAlmostEqual(paid_02 + paid_03 + paid_04, amount, places=2)
|
||||
# 02 and 04 have equal expected → equal allocation
|
||||
self.assertAlmostEqual(paid_02, paid_04, places=2)
|
||||
|
||||
def test_single_month_unchanged(self):
|
||||
"""Single-month payment: full amount goes to that month (regression guard)."""
|
||||
members = [('Alice', 'A', {'2026-01': (750, 3)})]
|
||||
sorted_months = ['2026-01']
|
||||
tx = _tx('Alice', '2026-01', 750)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
self.assertAlmostEqual(result['members']['Alice']['months']['2026-01']['paid'], 750, places=2)
|
||||
|
||||
def test_two_members_multi_month(self):
|
||||
"""Two members, 2 months: each member gets member_share, then fee-aware per month."""
|
||||
members = [
|
||||
('Alice', 'A', {'2026-01': (750, 3), '2026-02': (350, 3)}),
|
||||
('Bob', 'A', {'2026-01': (750, 3), '2026-02': (350, 3)}),
|
||||
]
|
||||
sorted_months = ['2026-01', '2026-02']
|
||||
# Both members pay together; total expected per member = 1100
|
||||
tx = _tx('Alice, Bob', '2026-01, 2026-02', 2200)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
|
||||
for name in ('Alice', 'Bob'):
|
||||
months = result['members'][name]['months']
|
||||
self.assertAlmostEqual(months['2026-01']['paid'], 750, places=2)
|
||||
self.assertAlmostEqual(months['2026-02']['paid'], 350, places=2)
|
||||
|
||||
def test_fallback_even_split_when_no_expected(self):
|
||||
"""All matched months have expected=0 → falls back to even split."""
|
||||
members = [('Alice', 'A', {'2026-01': (0, 0), '2026-02': (0, 0)})]
|
||||
sorted_months = ['2026-01', '2026-02']
|
||||
tx = _tx('Alice', '2026-01, 2026-02', 300)
|
||||
|
||||
result = reconcile(members, sorted_months, [tx])
|
||||
months = result['members']['Alice']['months']
|
||||
|
||||
self.assertAlmostEqual(months['2026-01']['paid'], 150, places=2)
|
||||
self.assertAlmostEqual(months['2026-02']['paid'], 150, places=2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user