Gives the company tables of the previous commit their screens, so a company can be configured from the browser, and makes the base data runnable outside the web server. - one generic editor for the 26 coded tables (/tabelle/<slug>), described in TableScreens: grid with active/disabled filter, detail with errors and warnings, disable instead of delete, CSV export and all-or-nothing import, "update from base tables"; index page and menu entries - company profile in tabs with the fiscal pack checks, fiscal years with month lock/unlock, exchange rates with manual rates - PaymentTermService: installments saved together, percentages must sum to 100 - a new profile proposes the registered company name instead of its code - seed verb in Khaemhat.Web and scripts/seed.sh --base [--company CODE], shipped in the image under /app/scripts - ADR 0026 (base data only adds missing codes; ISTAT and ABI/CAB lists come as separate datasets), wiki, CHANGELOG, STATUS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
218 lines
9.3 KiB
Plaintext
218 lines
9.3 KiB
Plaintext
@page "/tabelle/esercizi"
|
|
@attribute [Authorize]
|
|
@using Khaemhat.Application.Security
|
|
@using Khaemhat.Application.Tables
|
|
@using Khaemhat.Core.Tables
|
|
@using Khaemhat.Web.Tables
|
|
@inject ShellSession Session
|
|
@inject FiscalYearService Years
|
|
@inject ToastService Toasts
|
|
@inject DialogService Dialogs
|
|
@inject TimeProvider Clock
|
|
|
|
@* Fiscal years and periods (SPEC §11.1, mockup 052): the years with their state, the months of the chosen year with
|
|
the lock that stops new entries and documents on those dates. The VAT settlement (M7) marks a month as settled. *@
|
|
<KhPageTitle Text="@T["CompanyTables.FiscalYears.Title"]" Icon="calendar" />
|
|
|
|
<TablesGuard>
|
|
<div class="phead">
|
|
<div>
|
|
<div class="crumbs"><a href="@TableScreens.BasePath">@T["Shell.Menu.CompanyTables"]</a> / @T["CompanyTables.FiscalYears.Title"]</div>
|
|
<h1>@T["CompanyTables.FiscalYears.Heading"]</h1>
|
|
<div class="sub">@T["CompanyTables.FiscalYears.Hint"]</div>
|
|
</div>
|
|
<div class="grow"></div>
|
|
<div class="toolbar">
|
|
<button type="button" class="btn primary" disabled="@(!CanWrite || _busy)" @onclick="CreateAsync"><KhIcon Name="plus" /> @T["CompanyTables.FiscalYears.New"]</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="kh-tables">
|
|
<KhPanel Title="@T["CompanyTables.FiscalYears.Years"]" Icon="calendar" Tight="true">
|
|
@if (_years.Count == 0)
|
|
{
|
|
<p class="muted kh-pad">@T["CompanyTables.FiscalYears.None"]</p>
|
|
}
|
|
else
|
|
{
|
|
<table class="grid" aria-label="@T["CompanyTables.FiscalYears.Years"]">
|
|
<thead>
|
|
<tr>
|
|
<th>@T["CompanyTables.FiscalYears.Year"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.Start"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.End"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.State"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.LockedMonths"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.LastSettled"]</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var view in _years)
|
|
{
|
|
var year = view.Year;
|
|
<tr class="@(year.Id == _selected?.Year.Id ? "sel" : null)" @onclick="() => _selected = view" style="cursor:pointer">
|
|
<td><b class="mono">@year.Code</b></td>
|
|
<td>@T.Date(year.StartDate)</td>
|
|
<td>@T.Date(year.EndDate)</td>
|
|
<td><KhBadge Tone="ToneOf(year.Status)">@T[TableScreens.EnumKey(year.Status)]</KhBadge></td>
|
|
<td>@view.Periods.Count(p => p.Status != FiscalPeriodStatus.Open) / @view.Periods.Count</td>
|
|
<td>@(view.Periods.LastOrDefault(p => p.Status == FiscalPeriodStatus.Settled) is { } last ? MonthName(last) : "-")</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}
|
|
</KhPanel>
|
|
|
|
@if (_selected is { } selected)
|
|
{
|
|
<KhPanel Title="@T.Format("CompanyTables.FiscalYears.Periods", selected.Year.Code, T[TableScreens.EnumKey(_periodicity)])" Icon="lock" Tight="true">
|
|
<table class="grid" aria-label="@T["CompanyTables.FiscalYears.PeriodsLabel"]">
|
|
<thead>
|
|
<tr>
|
|
<th>@T["CompanyTables.FiscalYears.Period"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.From"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.To"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.State"]</th>
|
|
<th>@T["CompanyTables.FiscalYears.Lock"]</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var period in selected.Periods)
|
|
{
|
|
<tr>
|
|
<td>@MonthName(period)</td>
|
|
<td>@T.Date(period.StartDate)</td>
|
|
<td>@T.Date(period.EndDate)</td>
|
|
<td><KhBadge Tone="ToneOf(period.Status)">@T[TableScreens.EnumKey(period.Status)]</KhBadge></td>
|
|
<td>
|
|
@if (period.Status == FiscalPeriodStatus.Settled)
|
|
{
|
|
<span class="muted">@T["CompanyTables.FiscalYears.SettledLock"]</span>
|
|
}
|
|
else
|
|
{
|
|
var locked = period.Status == FiscalPeriodStatus.Locked;
|
|
<button type="button" class="btn sm" disabled="@(!CanWrite || _busy || selected.Year.Status != FiscalYearStatus.Open)"
|
|
@onclick="() => LockAsync(period, !locked)">
|
|
<KhIcon Name="@(locked ? "key" : "lock")" /> @T[locked ? "CompanyTables.FiscalYears.Unlock" : "CompanyTables.FiscalYears.LockMonth"]
|
|
</button>
|
|
}
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</KhPanel>
|
|
}
|
|
</div>
|
|
</TablesGuard>
|
|
|
|
@code {
|
|
private IReadOnlyList<FiscalYearView> _years = [];
|
|
private FiscalYearView? _selected;
|
|
private Khaemhat.Core.Tax.VatPeriodicity _periodicity;
|
|
private bool _busy;
|
|
|
|
/// <summary>The service of the company profile, for the VAT periodicity shown on the months.</summary>
|
|
[Inject]
|
|
private CompanyProfileService Profiles { get; set; } = default!;
|
|
|
|
private bool CanWrite => Session.Permissions.Allows(TableService.WritePermission);
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Session.EnsureLoadedAsync();
|
|
if (Session.Actor is { } actor && Session.Company?.Code is { } company && Session.Permissions.Allows(TableService.ReadPermission))
|
|
{
|
|
_periodicity = (await Profiles.GetAsync(actor, company)).VatPeriodicity;
|
|
await LoadAsync(actor, company);
|
|
}
|
|
}
|
|
|
|
private async Task LoadAsync(Actor actor, string company)
|
|
{
|
|
var selected = _selected?.Year.Id;
|
|
_years = await Years.ListAsync(actor, company);
|
|
var today = DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
|
_selected = _years.FirstOrDefault(y => y.Year.Id == selected)
|
|
?? _years.FirstOrDefault(y => y.Year.StartDate <= today && today <= y.Year.EndDate)
|
|
?? _years.FirstOrDefault();
|
|
}
|
|
|
|
private async Task CreateAsync()
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_busy = true;
|
|
try
|
|
{
|
|
var created = await Years.CreateNextAsync(actor, company, DateOnly.FromDateTime(Clock.GetLocalNow().DateTime));
|
|
_selected = created;
|
|
await LoadAsync(actor, company);
|
|
Toasts.Show(ToastKind.Success, T["CompanyTables.FiscalYears.Created"], created.Year.Code);
|
|
}
|
|
catch (ValidationFailedException ex)
|
|
{
|
|
Toasts.Show(ToastKind.Error, T["CompanyTables.NotSaved"], string.Join(" ", ex.Errors.Select(e => T[TableValues.SplitError(e).Code])));
|
|
}
|
|
finally
|
|
{
|
|
_busy = false;
|
|
}
|
|
}
|
|
|
|
private async Task LockAsync(FiscalPeriod period, bool locked)
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!locked && !await Dialogs.ConfirmAsync(new ConfirmRequest(T["CompanyTables.FiscalYears.Unlock"], T.Format("CompanyTables.FiscalYears.UnlockText", MonthName(period)),
|
|
T["CompanyTables.FiscalYears.Unlock"], T["Common.Cancel"])))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_busy = true;
|
|
try
|
|
{
|
|
await Years.SetLockedAsync(actor, company, period.Id, locked);
|
|
await LoadAsync(actor, company);
|
|
}
|
|
catch (ValidationFailedException ex)
|
|
{
|
|
Toasts.Show(ToastKind.Error, T["CompanyTables.NotSaved"], string.Join(" ", ex.Errors.Select(e => T[TableValues.SplitError(e).Code])));
|
|
}
|
|
finally
|
|
{
|
|
_busy = false;
|
|
}
|
|
}
|
|
|
|
private string MonthName(FiscalPeriod period)
|
|
{
|
|
var text = period.StartDate.ToString("MMMM yyyy", T.Culture);
|
|
return char.ToUpper(text[0], T.Culture) + text[1..];
|
|
}
|
|
|
|
private static KhTone ToneOf(FiscalYearStatus status) => status switch
|
|
{
|
|
FiscalYearStatus.Open => KhTone.Ok,
|
|
FiscalYearStatus.Closing => KhTone.Warning,
|
|
_ => KhTone.Neutral,
|
|
};
|
|
|
|
private static KhTone ToneOf(FiscalPeriodStatus status) => status switch
|
|
{
|
|
FiscalPeriodStatus.Open => KhTone.Ok,
|
|
FiscalPeriodStatus.Settled => KhTone.Info,
|
|
_ => KhTone.Warning,
|
|
};
|
|
}
|