The SDI dashboard (mockup 058) with its six counters, the documents to
generate, generate+send, manual receipts import, history, courtesy copy
and mark-as-sent; the channels page (mockup 059) with settings, test,
pause and routing rules; the received invoices, the notifications and
the conservation packages. The SdICoop web service receives pushes at
/sdicoop/{company}, authenticated by the key of the channel, through a
new IEInvoicePushReader feature so the web layer stays country-neutral.
The menu gives each e-invoice page its own permission and keeps the
intent declarations under M10.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
5.6 KiB
Plaintext
131 lines
5.6 KiB
Plaintext
@page "/fatturazione-elettronica/conservazione"
|
||
@attribute [Authorize]
|
||
@using Khaemhat.Application.EInvoicing
|
||
@using Khaemhat.Application.Security
|
||
@using Khaemhat.Core.EInvoicing
|
||
@using Khaemhat.Web.EInvoicing
|
||
@inject ShellSession Session
|
||
@inject ConservationExportService Conservation
|
||
@inject ToastService Toasts
|
||
@inject IJSRuntime JS
|
||
@inject TimeProvider Clock
|
||
|
||
@* The packages for substitute conservation (SPEC §11.9, issue #79): the files issued and received in a period, their
|
||
notifications, an index with the fingerprint of each file, to hand to the conservation provider. Khaemhat is not a
|
||
conservation system: it prepares what goes to one, and remembers what went out. *@
|
||
<KhPageTitle Text="@T["EInvoicing.Conservation.Title"]" Icon="folder" />
|
||
|
||
<EInvoiceGuard Permission="@EInvoicePermissions.Read">
|
||
<div class="phead">
|
||
<div>
|
||
<div class="crumbs"><a href="@EInvoicingScreens.BasePath">@T["Shell.Menu.EInvoicing"]</a> / @T["EInvoicing.Conservation.Title"]</div>
|
||
<h1>@T["EInvoicing.Conservation.Heading"]</h1>
|
||
<div class="sub">@T["EInvoicing.Conservation.Hint"]</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="kh-remit">
|
||
<KhPanel Title="@T["EInvoicing.Conservation.New"]" Icon="folder">
|
||
<div class="form plain">
|
||
<KhDateBox Label="@T["EInvoicing.Fields.From"]" Name="cfrom" @bind-Value="_from" Required="true" Span="6" />
|
||
<KhDateBox Label="@T["EInvoicing.Fields.To"]" Name="cto" @bind-Value="_to" Required="true" Span="6" />
|
||
</div>
|
||
<p class="muted sm">@T["EInvoicing.Conservation.Contents"]</p>
|
||
<button type="button" class="btn primary" disabled="@(_busy || _from is null || _to is null)" @onclick="ExportAsync"><KhIcon Name="download" /> @T["EInvoicing.Conservation.Export"]</button>
|
||
</KhPanel>
|
||
<KhPanel Title="@T["EInvoicing.Conservation.History"]" Icon="history" Tight="true">
|
||
@if (_exports.Count == 0)
|
||
{
|
||
<p class="kh-wempty">@T["EInvoicing.Conservation.None"]</p>
|
||
}
|
||
else
|
||
{
|
||
<div class="gridwrap kh-scrollx">
|
||
<table class="grid" aria-label="@T["EInvoicing.Conservation.History"]">
|
||
<thead>
|
||
<tr>
|
||
<th scope="col">@T["EInvoicing.Conservation.Period"]</th>
|
||
<th scope="col">@T["EInvoicing.Conservation.File"]</th>
|
||
<th scope="col" class="num">@T["EInvoicing.Conservation.Files"]</th>
|
||
<th scope="col" class="num">@T["EInvoicing.Conservation.Size"]</th>
|
||
<th scope="col">@T["EInvoicing.Conservation.Hash"]</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
@foreach (var x in _exports)
|
||
{
|
||
<tr>
|
||
<td class="kh-nowrap">@T.Date(x.FromDate) – @T.Date(x.ToDate)</td>
|
||
<td class="code">@x.FileName</td>
|
||
<td class="num">@x.FileCount</td>
|
||
<td class="num">@Size(x.Size)</td>
|
||
<td class="code kh-w260" title="@x.Hash">@x.Hash[..16]…</td>
|
||
</tr>
|
||
}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
}
|
||
<div class="filters"><span class="muted sm">@T["EInvoicing.Conservation.Footer"]</span></div>
|
||
</KhPanel>
|
||
</div>
|
||
</EInvoiceGuard>
|
||
|
||
@code {
|
||
private IReadOnlyList<ConservationExport> _exports = [];
|
||
private DateOnly? _from;
|
||
private DateOnly? _to;
|
||
private bool _busy;
|
||
|
||
private string Size(long bytes) => bytes >= 1024 * 1024
|
||
? T.Format("EInvoicing.Conservation.MegaBytes", bytes / 1048576m)
|
||
: T.Format("EInvoicing.Conservation.KiloBytes", Math.Max(1, bytes / 1024));
|
||
|
||
/// <inheritdoc />
|
||
protected override async Task OnInitializedAsync()
|
||
{
|
||
await Session.EnsureLoadedAsync();
|
||
var today = DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||
var previous = new DateOnly(today.Year, today.Month, 1).AddMonths(-1);
|
||
_from = previous;
|
||
_to = previous.AddMonths(1).AddDays(-1);
|
||
if (EInvoiceGuard.Allowed(Session, EInvoicePermissions.Read))
|
||
{
|
||
await LoadAsync();
|
||
}
|
||
}
|
||
|
||
private async Task LoadAsync()
|
||
{
|
||
if (Session.Actor is { } actor && Session.Company?.Code is { } company)
|
||
{
|
||
_exports = await Conservation.ListAsync(actor, company);
|
||
}
|
||
}
|
||
|
||
private async Task ExportAsync()
|
||
{
|
||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _from is not { } from || _to is not { } to)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_busy = true;
|
||
try
|
||
{
|
||
var package = await Conservation.ExportAsync(actor, company, from, to);
|
||
await EInvoicingScreens.DownloadAsync(JS, package.Export.FileName, "application/zip", package.Content);
|
||
Toasts.Show(ToastKind.Success, T["EInvoicing.Conservation.Done"], T.Format("EInvoicing.Conservation.DoneText", package.Export.FileCount));
|
||
await LoadAsync();
|
||
}
|
||
catch (ValidationFailedException ex)
|
||
{
|
||
Toasts.Show(ToastKind.Error, T["EInvoicing.NotDone"], EInvoicingScreens.Errors(T, ex));
|
||
}
|
||
finally
|
||
{
|
||
_busy = false;
|
||
}
|
||
}
|
||
}
|