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:
1 parent
3cd214ae78
commit
9d1a4f2f69
11 files changed
+890
-13
No files matched your search
@@ -319,6 +319,57 @@
|
||||
}
|
||||
<p class="hint"><a href="/api/data/quality?format=md&days=30">Rapporto sulla qualità dei dati degli ultimi 30 giorni</a></p>
|
||||
|
||||
<h3 id="dichiarazione">Esportazione per la dichiarazione</h3>
|
||||
<p class="hint">Tutte le operazioni con il controvalore in euro al cambio della BCE del giorno di ciascuna, o l'ultimo precedente. È un elenco per te o per il tuo commercialista, non un calcolo delle tasse.</p>
|
||||
@if (Shell.IsDemo)
|
||||
{
|
||||
<p class="note">Nella modalità dimostrativa non ci sono operazioni da esportare.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post" action="/azioni/impostazioni/@_taxMethod.Key" class="form-inline">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="ritorno" value="/impostazioni#dichiarazione" />
|
||||
<label for="metodo-lotti">@Anubis.Trading.TaxExport.MethodSetting.Label</label>
|
||||
<select id="metodo-lotti" name="valore" data-autosubmit>
|
||||
<option value="lifo" selected="@(_taxMethod.Value == "lifo")">@Label("lifo")</option>
|
||||
<option value="fifo" selected="@(_taxMethod.Value == "fifo")">@Label("fifo")</option>
|
||||
</select>
|
||||
<button class="btn btn-small" type="submit">Salva</button>
|
||||
</form>
|
||||
@if (_taxChoices.Count == 0)
|
||||
{
|
||||
<p class="note">Nessuna operazione da esportare finora.</p>
|
||||
}
|
||||
@foreach (var (world, years) in _taxChoices)
|
||||
{
|
||||
var real = world == Anubis.Trading.Worlds.Real;
|
||||
<form method="get" action="/api/dichiarazione.csv" class="form-inline">
|
||||
<input type="hidden" name="mondo" value="@(real ? "reale" : "simulazione")" />
|
||||
<label for="anno-@world">@(real ? "Soldi veri" : "Simulazione: solo per prova, non va dichiarata")</label>
|
||||
<select id="anno-@world" name="anno">
|
||||
@foreach (var year in years)
|
||||
{
|
||||
<option value="@year">@year</option>
|
||||
}
|
||||
<option value="tutti">Tutti gli anni</option>
|
||||
</select>
|
||||
<button class="btn btn-small" type="submit">Esporta le operazioni</button>
|
||||
<button class="btn btn-small" type="submit" name="dettaglio" value="lotti">Esporta il dettaglio degli acquisti venduti</button>
|
||||
</form>
|
||||
}
|
||||
<details>
|
||||
<summary>Cosa c'è e cosa non c'è</summary>
|
||||
<ul class="hint">
|
||||
<li>Il costo di ciò che vendi segue gli acquisti del solo bot su quel conto. Se sullo stesso conto compri o vendi anche a mano, il conto va rifatto insieme.</li>
|
||||
<li>Il risultato può essere diverso da quello della pagina Operazioni, che usa il prezzo medio e non gli acquisti uno per uno.</li>
|
||||
<li>I dividendi sono lordi e alla data di stacco. Ritenute e piccole commissioni di legge di Alpaca non sono nel registro: prendile dai documenti del broker.</li>
|
||||
<li>Una riga senza cambio resta vuota e lo dice nella nota; un cambio provvisorio diventa definitivo appena la BCE pubblica quello del giorno.</li>
|
||||
<li>Il capitale affidato e gli spostamenti fra strategie non sono operazioni e non ci sono.</li>
|
||||
</ul>
|
||||
</details>
|
||||
}
|
||||
|
||||
</section>
|
||||
|
||||
<section class="panel" id="notizie">
|
||||
@@ -590,6 +641,8 @@
|
||||
IReadOnlyList<StrategyCapital> Strategies);
|
||||
private sealed record LimitField(string Key, string Label, string Value, bool ReadOnly);
|
||||
private readonly List<LimitField> _limits = [];
|
||||
private SettingValue _taxMethod = new(Anubis.Trading.TaxExport.MethodSetting.Key, "lifo", false, null);
|
||||
private IReadOnlyList<(string World, IReadOnlyList<int> Years)> _taxChoices = [];
|
||||
private bool _anyLive;
|
||||
private string _pdt = "off";
|
||||
private string _scenarios = "";
|
||||
@@ -631,6 +684,8 @@
|
||||
_history = await services.Settings.HistoryAsync(null, 50, ct);
|
||||
_meetings = await services.Settings.GetAsync(SettingsStore.CentralBankMeetings.Key, ct);
|
||||
_sources = await new Anubis.Data.SourceStateStore(services.Db, Clock).ListAsync(ct);
|
||||
_taxMethod = await services.Settings.GetAsync(Anubis.Trading.TaxExport.MethodSetting.Key, ct);
|
||||
_taxChoices = await Anubis.Trading.TaxExport.ChoicesAsync(services.Db, ct);
|
||||
foreach (var rule in Anubis.News.NewsRuleSettings.All)
|
||||
{
|
||||
_newsRules.Add(await services.Settings.GetAsync(rule.Key, ct));
|
||||
@@ -864,6 +919,8 @@
|
||||
"auto" => "Come il sistema",
|
||||
"light" => "Chiaro",
|
||||
"dark" => "Scuro",
|
||||
"lifo" => "Ultimo comprato, primo venduto (LIFO)",
|
||||
"fifo" => "Primo comprato, primo venduto (FIFO)",
|
||||
"EUR" => "Euro (EUR)",
|
||||
"USD" => "Dollaro (USD)",
|
||||
"active" => "Attivo",
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -273,7 +273,7 @@ internal static partial class Forms
|
||||
var back = Back(form, "/impostazioni");
|
||||
var news = Anubis.News.NewsRuleSettings.All.Any(d => d.Key == key);
|
||||
var model = Anubis.News.NewsModelSettings.All.Any(d => d.Key == key);
|
||||
if (key != SettingsStore.Theme.Key && key != SettingsStore.Currency.Key && key != SettingsStore.CentralBankMeetings.Key && key != SettingsStore.TelegramStatus.Key &&
|
||||
if (key != SettingsStore.Theme.Key && key != SettingsStore.Currency.Key && key != SettingsStore.CentralBankMeetings.Key && key != SettingsStore.TelegramStatus.Key && key != Anubis.Trading.TaxExport.MethodSetting.Key &&
|
||||
!news && !model)
|
||||
{
|
||||
return Results.Redirect(With(back, "errore", "impostazione"));
|
||||
|
||||
Reference in new issue
Block a user