## Summary
A new page **Stammdaten → Texte bereinigen** (`/text-cleanup?acc=<number>`) to view and clean the booking texts of one account, e.g. "Ferien", in the year selected in the header.
Scope, as agreed: one account, the selected year, **only the `Text` field**, only existing bookings. Booking rules and the booking-text list are not touched.
### Page
- **Account dropdown**, filter, and a table of all bookings of the account (both sides, so refunds are negative): date, amount, counter account, the **editable text**, and the bank text as a read-only hint.
- **Group panel:** the texts grouped by first word, exactly as the Analyse page groups them, with count and total. It updates live while editing, and clicking a group filters the table.
- **Tools, acting on the rows currently shown** (the filter limits their reach):
- **Search and replace:** plain text, or regex with `$1` groups. For example `^(.+) Luzern$` → `Luzern $1` turns "Migros Luzern" into "Luzern Migros".
- **Leerzeichen bereinigen:** trims and collapses repeated spaces.
- **Several rows at once:** checkboxes plus "Text setzen" give selected rows one text.
- **Changes:** changed rows are highlighted, with the old text crossed out underneath. Nothing is written until **Speichern (n)**; **Verwerfen** discards.
- **Unsaved changes:** leaving the page asks first (same `unsaved-guard.js` as the JSON editor).
- **Entry points:** the menu, a new button per account on **Konten**, and a "Texte <Jahr> bereinigen" link on the **Analyse** page at account level.
### Saving
`RawDataRepository.SaveTransactionTextsAsync` changes only the `Text` of the given bookings (by ID):
- refused if the file changed since loading (SHA-256), if a text is empty, or if a booking no longer exists;
- the previous version is backed up to `backup/{mandator}/{year}/json-{timestamp}/`, then saved atomically through `BaseRepository`, so cached data is refreshed;
- the file is read once, so the backup is exactly the version that was checked.
`TextReplacement` (Services) holds the search and replace logic:
- plain search is literal, including a `$` in the replacement;
- regex has a 500 ms timeout against runaway patterns;
- invalid patterns give a German error message.
### Layout fix (app-wide)
The content area (`.body-content`) scrolls its own content and was only as tall as the page, so on short pages open dropdowns were cut off after a line or two. It now fills at least the window between header and footer (`app.css`). On short pages the footer therefore sits at the bottom of the window. The account list is also limited to 360 px and scrolls.
## Test plan
- [x] `dotnet build`: no warnings
- [x] `dotnet test`: 111/111 pass, including 13 new tests:
- 5 `RawDataRepositoryTestShould`: load with hash, only Text changes plus backup, empty text refused, unknown booking refused, changed file refused
- 8 `TextReplacementTestShould`: case handling, literal special characters, regex groups, no match, invalid regex, empty search, tidy
- [x] Headless Chrome on a copy of the real data, Ferien account (21 bookings in 2026):
- "Mailand" → "Milano" via replace, 1 direct edit, and 3 rows set via "Text setzen"; the group panel showed "Milano" before saving
- after saving, exactly those 7 texts changed on disk, no other field of any booking, and a backup was written
- [x] Opening the page without an account: hint shown, no render error. An early `return` inside an element first caused "A frame of type 'Element' was left unclosed"; fixed and checked.
- [x] Account dropdown on the empty page opens fully (360 px, scrollable) within the content area
- [x] Links from Konten and Analyse open the page with the account preselected
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed-on: #8
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
105 lines
5.2 KiB
Markdown
105 lines
5.2 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Commands
|
|
|
|
```bash
|
|
# Build
|
|
dotnet build
|
|
|
|
# Run (dev server at http://localhost:5225)
|
|
cd Schaad.Accounting.UI && dotnet run
|
|
|
|
# Test
|
|
dotnet test
|
|
|
|
# Publish
|
|
dotnet publish -c Release
|
|
```
|
|
|
|
Tests live in `Schaad.Accounting.Tests` (xUnit + NSubstitute + Shouldly). There is no lint command.
|
|
|
|
## Architecture
|
|
|
|
**AccountingNext** is a Swiss personal accounting app built with ASP.NET Core 9 + Blazor (interactive server-side rendering) and Microsoft Fluent UI. Data is stored as human-readable JSON files on disk (`System.Text.Json`, settings in `JsonStorage`) — no database.
|
|
|
|
### Projects
|
|
|
|
| Project | Role |
|
|
|---|---|
|
|
| `Schaad.Accounting.UI` | Blazor web app — pages, dialogs, layout |
|
|
| `Schaad.Accounting.Services` | Business logic — balances, FX conversion, file import, charts |
|
|
| `Schaad.Accounting.Db` | Repository layer — JSON serialization/deserialization |
|
|
| `Schaad.Accounting.Common` | Shared models, DTOs, interfaces |
|
|
|
|
### Data flow
|
|
|
|
```
|
|
Blazor Pages/Dialogs (UI)
|
|
→ Services (ViewService, FileService, ChartService)
|
|
→ Repositories (AccountRepository, TransactionRepository, …)
|
|
→ JSON files: {DataPath}/{mandator}/{year}/*.json
|
|
```
|
|
|
|
Data is multi-mandator and multi-year. The layout below `DataPath` (configured in `appsettings.Development.json`) is defined in `DataFolders`:
|
|
|
|
```
|
|
{DataPath}/{mandator}/{year}/*.json data files
|
|
{DataPath}/uploads/{mandator}/{year}/ imported bank statements (+ creditCard/)
|
|
{DataPath}/backup/{mandator}/{year}/ backup zips
|
|
```
|
|
|
|
When a new year is opened, the previous year's data is copied as the starting point.
|
|
|
|
### Key services
|
|
|
|
- **ViewService** — aggregates account balances, applies FX rates, builds datasets for the UI
|
|
- **FileService** — imports bank statements (MT940, CAMT053 via external `Schaad.Finance.dll`), parses PDFs, manages backups
|
|
- **ChartService** — produces data for the Plotly booking-text charts on the transactions page
|
|
- **SettingsService** — manages the active year, mandator, and file paths
|
|
- **RawDataRepository** — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to `backup/{mandator}/{year}/json-{timestamp}/`
|
|
- **Texte bereinigen** page (`TextCleanup`) — edits only the `Text` of one account's bookings in the selected year (inline, search/replace via `TextReplacement`, bulk set); saves through `RawDataRepository.SaveTransactionTextsAsync`
|
|
- **AnalyticsService** — loads all years of the current mandator (via `MultiYearRepository`) into an `AccountingAnalysis` (expenses, income, net, assets) for the Analyse page; queries run in memory
|
|
|
|
### UI structure
|
|
|
|
Pages live in `Schaad.Accounting.UI/Components/Pages/`. Each page typically has a companion `Dialogs/` subfolder with Fluent UI dialog components for CRUD operations. The app is hardcoded to the `de-CH` culture.
|
|
|
|
### Key external dependencies
|
|
|
|
- `Microsoft.FluentUI.AspNetCore.Components` — UI components (FluentDataGrid, FluentDialog, etc.)
|
|
- `Plotly.Blazor` — charts on the older chart pages
|
|
- `BlazorMonaco` — Monaco editor for the JSON editor page; loaded on demand by `wwwroot/js/monaco.js` instead of script tags in `App.razor`
|
|
- Chart.js 4 + `chartjs-chart-treemap` — charts on the Analyse page; vendored in `wwwroot/lib/` (no CDN), wrapped by `wwwroot/js/charts.js` and `ChartJsChart.razor`
|
|
- `FreeSpire.PDF` — PDF parsing for bank statement imports
|
|
- `Schaad.Finance.dll` / `Schaad.Finance.Api.dll` — proprietary DLLs for MT940/CAMT053 parsing and FX rate lookups (FixerIo API key in `appsettings.Development.json`)
|
|
|
|
### Domain constants
|
|
|
|
`ClassIds` in `Schaad.Accounting.Common` defines the Swiss accounting chart-of-accounts classes: Activa=1, Passiva=2, Income=3, Expenses=4. These are the leading digit of an account number (accounts are 4-digit; `Account.Class = Number / 1000`).
|
|
|
|
## Testing conventions
|
|
|
|
Tests live in `Schaad.Accounting.Tests` and use **xUnit** + **NSubstitute** (mocks) + **Shouldly** (assertions).
|
|
|
|
- **File and class name**: `<Subject>TestShould` — one file per subject under test. Examples: `ViewServiceTestShould.cs`, `TransactionRepositoryTestShould.cs`, `FormattingTestShould.cs`.
|
|
- **Test method name**: `DoThisWhenThat` — describes the behavior first, then the condition. Read together the class + method form a sentence:
|
|
- `ViewServiceTestShould.SumActivaAndPassivaTotalsSeparatelyWhenGettingBalanceView`
|
|
- `TransactionRepositoryTestShould.ReturnNullWhenGettingUnknownTransactionId`
|
|
- **Assertions**: use Shouldly (`value.ShouldBe(expected)`, `list.ShouldBeEmpty()`, `x.ShouldBeNull()`, `list.ShouldContain(...)`, `first.ShouldBeSameAs(second)`, etc.). Do **not** use xUnit `Assert.*`.
|
|
|
|
Example:
|
|
|
|
```csharp
|
|
public class FormattingTestShould
|
|
{
|
|
[Fact]
|
|
public void RoundToTwoDecimalsWhenValueHasMorePrecision()
|
|
{
|
|
1.234m.ToFormattedString().ShouldBe("1.23");
|
|
}
|
|
}
|
|
```
|
|
|
|
Repository tests that hit real file I/O use a temp directory via `Path.GetTempPath()` and clean up in `IDisposable.Dispose`. Pure service tests use NSubstitute mocks for every dependency and don't touch the filesystem.
|