Export the operations for the tax return

Every execution, dividend and correction of a world, with its value in euro
at the ECB rate of its own Italian day or the last one before it, and for
sales the cost of what was sold. Costs come from the executions of the whole
account, so the method (LIFO by default, or FIFO) can be changed at any
time. A missing rate leaves the cell empty and says so.

The ECB download no longer leaves holes after a pause, and each execution
keeps the reference rate in force when it happened (SPEC 6.8).

refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 19:33:10 +01:00
1 parent 3cd214ae78
commit 9d1a4f2f69
11 files changed
+890 -13

No files matched your search

+27
View File
@@ -191,6 +191,33 @@ internal static partial class Endpoints
"text/csv; charset=utf-8", $"anubis-operazioni-{day}.csv");
});
// The operations for the tax return (SPEC 4.6, 13.5): one world and one Italian year, or all of them.
api.MapGet("/dichiarazione.csv", async (AnubisHost host, IClock clock, string? anno, string? mondo, string? dettaglio, CancellationToken ct) =>
{
int? year = null;
if (!string.IsNullOrEmpty(anno) && anno != "tutti")
{
if (!int.TryParse(anno, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out var parsed) || parsed is < 1999 or > 9999)
{
return Error(StatusCodes.Status400BadRequest, "valore_non_valido", "L'anno non è valido.");
}
year = parsed;
}
if (mondo is not (null or "" or "reale" or "simulazione") || dettaglio is not (null or "" or "lotti"))
{
return Error(StatusCodes.Status400BadRequest, "valore_non_valido", "La scelta non è valida.");
}
var world = mondo == "reale" ? Anubis.Trading.Worlds.Real : Anubis.Trading.Worlds.Simulated;
var services = host.Services!;
var method = Anubis.Trading.TaxExport.Method((await services.Settings.GetAsync(Anubis.Trading.TaxExport.MethodSetting.Key, ct).ConfigureAwait(false)).Value);
var report = await Anubis.Trading.TaxExport.LoadAsync(services.Db, world, year, method, ct).ConfigureAwait(false);
var name = $"anubis-dichiarazione-{year?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? "tutti"}{(dettaglio == "lotti" ? "-lotti" : "")}{(world == Anubis.Trading.Worlds.Real ? "" : "-simulazione")}.csv";
return Results.File(dettaglio == "lotti" ? report.LotsCsv() : report.Csv(), "text/csv; charset=utf-8", name);
});
// The technical logs of the data folder as one zip (SPEC 13.6, "Diario e sistema"). They are redacted when
// written (JsonLog); only the files the log writer names, read while it keeps writing the newest one.
api.MapGet("/registri.zip", (AnubisHost host, ShellData shell, IClock clock) =>