CI / Build and test (SQLite) (pull_request) Successful in 3m51s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 5s
CI / Docker image (pull_request) Successful in 1m22s
Rewrite the Scadenzario wiki page from the real screens and services, add ADR 0038, the 0.8.0 changelog, STATUS, MODULES and the regenerated data model, and update the pages that still pointed to M8. The browser check found a few screen defects, fixed here: reminder channels are flags, so they show as "e-mail + PEC" and are edited with check boxes; icon buttons in grids stay on one row; the summary strip no longer collapses on long pages; the customers/suppliers switch uses the right style; the cash flow bars scale between the lowest and highest balance. The late payment rate of the second half of 2026 is 2.40 (MEF, GU 163 of 16 July 2026), now covered by tests, and the mapping test knows the ten treasury tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
398 lines
19 KiB
Plaintext
398 lines
19 KiB
Plaintext
@page "/scadenzario"
|
|
@page "/scadenzario/scadenze"
|
|
@attribute [Authorize]
|
|
@using Khaemhat.Application.Security
|
|
@using Khaemhat.Application.Treasury
|
|
@using Khaemhat.Core.Accounting
|
|
@using Khaemhat.Core.Treasury
|
|
@using Khaemhat.Web.Ledger
|
|
@using Khaemhat.Web.Treasury
|
|
@inject ShellSession Session
|
|
@inject ScheduleService Schedule
|
|
@inject ToastService Toasts
|
|
@inject IJSRuntime JS
|
|
@inject TimeProvider Clock
|
|
|
|
@* The schedule (SPEC §11.8, mockups 053 and 054): the open items of customers and suppliers with the aging of what is
|
|
past due, the filters by state and party, the collection or payment of the items chosen, the change of due date,
|
|
method or dispute of one item, the statement of a party and the export of the grid. *@
|
|
<KhPageTitle Text="@T["Treasury.Schedule.Title"]" Icon="coins" />
|
|
|
|
<FinanceGuard Permission="@TreasuryPermissions.ScheduleRead">
|
|
<div class="phead">
|
|
<div>
|
|
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.Schedule.Title"]</div>
|
|
<h1>@T["Treasury.Schedule.Heading"]</h1>
|
|
<div class="sub">@T["Treasury.Schedule.Hint"]</div>
|
|
</div>
|
|
<div class="grow"></div>
|
|
@if (_result is { } r)
|
|
{
|
|
<KhBadge Tone="KhTone.Info">@T.Format("Treasury.Schedule.OpenTotal", T.Money(r.Residual))</KhBadge>
|
|
<KhBadge Tone="KhTone.Error">@T.Format("Treasury.Schedule.OverdueTotal", T.Money(r.Overdue))</KhBadge>
|
|
}
|
|
</div>
|
|
|
|
@if (_result is { } result)
|
|
{
|
|
<div class="kh-aging">
|
|
<KhTile Title="@T["Treasury.Aging.NotDue"]" Value="@T.Money(result.Aging.NotDue)" Tone="KhTone.Ok"><Detail>@T.Format("Treasury.Aging.Count", result.Aging.CountNotDue)</Detail></KhTile>
|
|
<KhTile Title="@T["Treasury.Aging.Days1To30"]" Value="@T.Money(result.Aging.Days1To30)" Tone="KhTone.Warning"><Detail>@T.Format("Treasury.Aging.Count", result.Aging.Count1To30)</Detail></KhTile>
|
|
<KhTile Title="@T["Treasury.Aging.Days31To60"]" Value="@T.Money(result.Aging.Days31To60)" Tone="KhTone.Warning"><Detail>@T.Format("Treasury.Aging.Count", result.Aging.Count31To60)</Detail></KhTile>
|
|
<KhTile Title="@T["Treasury.Aging.Days61To90"]" Value="@T.Money(result.Aging.Days61To90)" Tone="KhTone.Error"><Detail>@T.Format("Treasury.Aging.Count", result.Aging.Count61To90)</Detail></KhTile>
|
|
<KhTile Title="@T["Treasury.Aging.Over90"]" Value="@T.Money(result.Aging.Over90)" Tone="KhTone.Error"><Detail>@T.Format("Treasury.Aging.Count", result.Aging.CountOver90)</Detail></KhTile>
|
|
</div>
|
|
}
|
|
|
|
<KhPanel Tight="true">
|
|
<div class="filters kh-ledger-filters">
|
|
<input type="search" class="in kh-searchbox" placeholder="@T["Treasury.Schedule.Search"]" aria-label="@T["Treasury.Schedule.Search"]" value="@_search"
|
|
@onchange="SearchAsync" />
|
|
<KhSelect TValue="ScheduleView" Label="@T["Treasury.Schedule.View"]" Name="view" Options="Views" Value="_view" ValueChanged="SetViewAsync" />
|
|
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Method"]" Name="method" Options="Methods" Empty="@T["Treasury.All"]" Value="_methodId" ValueChanged="SetMethodAsync" />
|
|
<span class="grow"></span>
|
|
<div class="kh-seg" role="group" aria-label="@T["Treasury.Schedule.Direction"]">
|
|
<button type="button" class="@(_direction == OpenItemDirection.Receivable ? "on" : null)" @onclick="() => SetDirectionAsync(OpenItemDirection.Receivable)">@T["Treasury.Schedule.Customers"]</button>
|
|
<button type="button" class="@(_direction == OpenItemDirection.Payable ? "on" : null)" @onclick="() => SetDirectionAsync(OpenItemDirection.Payable)">@T["Treasury.Schedule.Suppliers"]</button>
|
|
</div>
|
|
<button type="button" class="btn" disabled="@_busy" @onclick="ExportAsync"><KhIcon Name="download" /> @T["Treasury.Export"]</button>
|
|
</div>
|
|
<div class="filters">
|
|
@if (CanPay)
|
|
{
|
|
<button type="button" class="btn primary" disabled="@(!OnePartySelected)" @onclick="OpenPayment">
|
|
<KhIcon Name="euro" /> @T[_direction == OpenItemDirection.Receivable ? "Treasury.Payment.NewReceipt" : "Treasury.Payment.NewPayment"]
|
|
</button>
|
|
}
|
|
<button type="button" class="btn" disabled="@(!OnePartySelected)" @onclick="StatementAsync"><KhIcon Name="file" /> @T["Treasury.Statement.Open"]</button>
|
|
<span class="muted sm">@T["Treasury.Schedule.SelectHint"]</span>
|
|
</div>
|
|
@if (_result is not { Rows.Count: > 0 } rows)
|
|
{
|
|
<p class="kh-wempty">@T["Treasury.Schedule.None"]</p>
|
|
}
|
|
else
|
|
{
|
|
<div class="gridwrap kh-scrollx">
|
|
<table class="grid" aria-label="@T["Treasury.Schedule.Title"]">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="chkcol"><span class="sr-only">@T["Treasury.Select"]</span></th>
|
|
<th scope="col">@T[_direction == OpenItemDirection.Receivable ? "Treasury.Fields.Customer" : "Treasury.Fields.Supplier"]</th>
|
|
<th scope="col">@T["Treasury.Fields.Document"]</th>
|
|
<th scope="col">@T["Treasury.Fields.Installment"]</th>
|
|
<th scope="col">@T["Treasury.Fields.DueDate"]</th>
|
|
<th scope="col" class="num">@T["Treasury.Fields.Days"]</th>
|
|
<th scope="col">@T["Treasury.Fields.Method"]</th>
|
|
<th scope="col" class="num">@T["Treasury.Fields.Amount"]</th>
|
|
<th scope="col" class="num">@T[_direction == OpenItemDirection.Receivable ? "Treasury.Payment.Collected" : "Treasury.Payment.Paid"]</th>
|
|
<th scope="col" class="num">@T["Treasury.Fields.Residual"]</th>
|
|
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
|
<th scope="col"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var row in rows.Rows)
|
|
{
|
|
var item = row.Item;
|
|
var selectable = !item.Closed && item.Status != OpenItemStatus.InRemittance;
|
|
<tr class="@(_selected.Contains(item.Id) ? "sel" : null)">
|
|
<td class="chkcol">
|
|
@if (selectable)
|
|
{
|
|
<input type="checkbox" aria-label="@(T["Treasury.Select"] + " " + item.DocumentNumber)" checked="@_selected.Contains(item.Id)" @onchange="e => Toggle(item.Id, e.Value is true)" />
|
|
}
|
|
</td>
|
|
<td><b>@row.PartyName</b></td>
|
|
<td class="code">
|
|
@if (item.EntryId > 0)
|
|
{
|
|
<a href="@LedgerScreens.EntryUrl(item.EntryId)">@item.DocumentNumber</a>
|
|
}
|
|
else
|
|
{
|
|
@item.DocumentNumber
|
|
}
|
|
</td>
|
|
<td>@item.Installment</td>
|
|
<td>@T.Date(item.DueDate)</td>
|
|
<td class="num @(row.DaysOverdue > 0 && !item.Closed ? "neg" : null)">@(item.Closed ? null : row.DaysOverdue.ToString(T.Culture))</td>
|
|
<td>@(row.MethodDescription ?? row.Method)</td>
|
|
<td class="num">@T.Money(item.Amount)</td>
|
|
<td class="num">@T.Money(item.PaidAmount)</td>
|
|
<td class="num"><b>@T.Money(item.Residual)</b></td>
|
|
<td>
|
|
<KhBadge Tone="TreasuryScreens.ToneOf(item, Today)">@TreasuryScreens.StatusText(T, item, Today)</KhBadge>
|
|
@if (row.Remittance is { } remittance)
|
|
{
|
|
<span class="muted sm"> @remittance</span>
|
|
}
|
|
</td>
|
|
<td class="kh-acts">
|
|
@if (CanWrite && !item.Closed)
|
|
{
|
|
<KhIconButton Icon="edit" Text="@T["Treasury.Schedule.Edit"]" OnClick="() => OpenEdit(row)" />
|
|
}
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="filters">
|
|
<span class="muted sm">@T.Format("Treasury.Schedule.Footer", rows.Rows.Count, _selected.Count, T.Money(SelectedRows.Sum(r => r.Item.Residual)))</span>
|
|
</div>
|
|
}
|
|
</KhPanel>
|
|
|
|
<PaymentDialog Open="_paymentOpen" Rows="_paymentRows" Choices="_choices" OnClose="() => _paymentOpen = false" OnSaved="PaidAsync" />
|
|
|
|
<KhDialog Open="_edit is not null" Title="@T["Treasury.Schedule.Edit"]" Icon="edit" OnClose="() => _edit = null">
|
|
<ChildContent>
|
|
@if (_edit is { } edit)
|
|
{
|
|
<p>@T.Format("Treasury.Schedule.EditText", edit.Item.DocumentNumber ?? string.Empty, edit.Item.Installment, edit.PartyName)</p>
|
|
<div class="form plain">
|
|
<KhDateBox Label="@T["Treasury.Fields.DueDate"]" Name="editdue" @bind-Value="_editDue" Required="true" Span="6" />
|
|
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Method"]" Name="editmethod" Options="Methods" Empty="—" @bind-Value="_editMethod" Span="6" />
|
|
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Bank"]" Name="editbank" Options="Banks" Empty="—" @bind-Value="_editBank" Span="6" />
|
|
<KhCheck Label="@T["Treasury.Schedule.Disputed"]" Name="editdisputed" @bind-Value="_editDisputed" Span="6" />
|
|
<KhTextArea Label="@T["Treasury.Fields.Notes"]" Name="editnotes" @bind-Value="_editNotes" MaxLength="200" Rows="2" Span="12" />
|
|
</div>
|
|
}
|
|
</ChildContent>
|
|
<Footer>
|
|
<button type="button" class="btn" @onclick="() => _edit = null">@T["Common.Cancel"]</button>
|
|
<button type="button" class="btn primary" disabled="@(_busy || _editDue is null)" @onclick="SaveEditAsync"><KhIcon Name="check" /> @T["Common.Save"]</button>
|
|
</Footer>
|
|
</KhDialog>
|
|
|
|
<KhDialog Open="_statement is not null" Title="@T["Treasury.Statement.Title"]" Icon="file" Size="lg" OnClose="() => _statement = null">
|
|
<ChildContent>
|
|
@if (_statement is { } st)
|
|
{
|
|
<p><b>@st.Party.Name</b> · @T.Format("Treasury.Statement.At", T.Date(st.Day))</p>
|
|
<div class="kh-aging">
|
|
<KhTile Title="@T["Treasury.Fields.Residual"]" Value="@T.Money(st.Residual)" />
|
|
<KhTile Title="@T["Treasury.Schedule.Overdue"]" Value="@T.Money(st.Overdue)" Tone="KhTone.Error" />
|
|
<KhTile Title="@T["Treasury.Statement.Interest"]" Value="@T.Money(st.Interest)" Tone="KhTone.Warning" />
|
|
</div>
|
|
<table class="grid" aria-label="@T["Treasury.Statement.Title"]">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">@T["Treasury.Fields.Document"]</th>
|
|
<th scope="col">@T["Treasury.Fields.DueDate"]</th>
|
|
<th scope="col" class="num">@T["Treasury.Fields.Amount"]</th>
|
|
<th scope="col" class="num">@T["Treasury.Fields.Residual"]</th>
|
|
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var row in st.Items)
|
|
{
|
|
<tr>
|
|
<td class="code">@row.Item.DocumentNumber @(row.Item.Installment > 1 ? "· " + row.Item.Installment : null)</td>
|
|
<td>@T.Date(row.Item.DueDate)</td>
|
|
<td class="num">@T.Money(row.Item.Amount)</td>
|
|
<td class="num">@T.Money(row.Item.Residual)</td>
|
|
<td><KhBadge Tone="TreasuryScreens.ToneOf(row.Item, st.Day)">@TreasuryScreens.StatusText(T, row.Item, st.Day)</KhBadge></td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
@if (st.Payments.Count > 0)
|
|
{
|
|
<h3 class="kh-subhead">@T["Treasury.Statement.Payments"]</h3>
|
|
<table class="grid" aria-label="@T["Treasury.Statement.Payments"]">
|
|
<tbody>
|
|
@foreach (var p in st.Payments)
|
|
{
|
|
<tr>
|
|
<td>@T.Date(p.PaymentDate)</td>
|
|
<td>@p.Reference</td>
|
|
<td class="num">@T.Money(p.Amount)</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}
|
|
}
|
|
</ChildContent>
|
|
<Footer>
|
|
<button type="button" class="btn" @onclick="() => _statement = null">@T["Common.Close"]</button>
|
|
</Footer>
|
|
</KhDialog>
|
|
</FinanceGuard>
|
|
|
|
@code {
|
|
private OpenItemDirection _direction = OpenItemDirection.Receivable;
|
|
private ScheduleView _view = ScheduleView.Open;
|
|
private long? _methodId;
|
|
private string? _search;
|
|
private ScheduleResult? _result;
|
|
private TreasuryChoices? _choices;
|
|
private readonly HashSet<long> _selected = [];
|
|
private bool _busy;
|
|
private bool _paymentOpen;
|
|
private IReadOnlyList<ScheduleRow> _paymentRows = [];
|
|
private ScheduleRow? _edit;
|
|
private DateOnly? _editDue;
|
|
private long? _editMethod;
|
|
private long? _editBank;
|
|
private bool _editDisputed;
|
|
private string? _editNotes;
|
|
private PartyStatement? _statement;
|
|
|
|
/// <summary>The direction asked by the address (?fornitori).</summary>
|
|
[SupplyParameterFromQuery(Name = "vista")]
|
|
public string? Side { get; set; }
|
|
|
|
private DateOnly Today => DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
|
|
|
private bool CanWrite => Session.Permissions.Allows(TreasuryPermissions.ScheduleWrite);
|
|
|
|
private bool CanPay => Session.Permissions.Allows(TreasuryPermissions.PaymentWrite);
|
|
|
|
private IEnumerable<ScheduleRow> SelectedRows => _result?.Rows.Where(r => _selected.Contains(r.Item.Id)) ?? [];
|
|
|
|
private bool OnePartySelected => _selected.Count > 0 && SelectedRows.Select(r => r.Item.PartyId).Distinct().Count() == 1;
|
|
|
|
private IReadOnlyList<KhOption<ScheduleView>> Views => TreasuryScreens.Choices<ScheduleView>(T);
|
|
|
|
private IReadOnlyList<KhOption<long?>> Methods => TreasuryScreens.MethodChoices(_choices?.Methods ?? []);
|
|
|
|
private IReadOnlyList<KhOption<long?>> Banks => TreasuryScreens.BankChoices(_choices?.Banks ?? []);
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Session.EnsureLoadedAsync();
|
|
if (string.Equals(Side, "fornitori", StringComparison.Ordinal))
|
|
{
|
|
_direction = OpenItemDirection.Payable;
|
|
}
|
|
|
|
if (FinanceGuard.Allowed(Session, TreasuryPermissions.ScheduleRead))
|
|
{
|
|
_choices = await Schedule.ChoicesAsync(Session.Actor!, Session.Company!.Code);
|
|
await LoadAsync();
|
|
}
|
|
}
|
|
|
|
private ScheduleFilter Filter => new(_direction, _view, null, null, null, _methodId, string.IsNullOrWhiteSpace(_search) ? null : _search.Trim());
|
|
|
|
private async Task LoadAsync()
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_result = await Schedule.ItemsAsync(actor, company, Filter);
|
|
_selected.IntersectWith(_result.Rows.Select(r => r.Item.Id));
|
|
}
|
|
|
|
private async Task SetDirectionAsync(OpenItemDirection direction)
|
|
{
|
|
_direction = direction;
|
|
_selected.Clear();
|
|
await LoadAsync();
|
|
}
|
|
|
|
private async Task SetViewAsync(ScheduleView view)
|
|
{
|
|
_view = view;
|
|
await LoadAsync();
|
|
}
|
|
|
|
private async Task SetMethodAsync(long? method)
|
|
{
|
|
_methodId = method;
|
|
await LoadAsync();
|
|
}
|
|
|
|
private async Task SearchAsync(ChangeEventArgs e)
|
|
{
|
|
_search = e.Value?.ToString();
|
|
await LoadAsync();
|
|
}
|
|
|
|
private void Toggle(long id, bool on)
|
|
{
|
|
if (on)
|
|
{
|
|
_selected.Add(id);
|
|
}
|
|
else
|
|
{
|
|
_selected.Remove(id);
|
|
}
|
|
}
|
|
|
|
private void OpenPayment()
|
|
{
|
|
_paymentRows = [.. SelectedRows.OrderBy(r => r.Item.DueDate)];
|
|
_paymentOpen = true;
|
|
}
|
|
|
|
private async Task PaidAsync(Payment payment)
|
|
{
|
|
_paymentOpen = false;
|
|
_selected.Clear();
|
|
await LoadAsync();
|
|
}
|
|
|
|
private void OpenEdit(ScheduleRow row)
|
|
{
|
|
_edit = row;
|
|
_editDue = row.Item.DueDate;
|
|
_editMethod = row.Item.PaymentMethodId;
|
|
_editBank = row.Item.BankAccountId;
|
|
_editDisputed = row.Item.Disputed;
|
|
_editNotes = row.Item.Notes;
|
|
}
|
|
|
|
private async Task SaveEditAsync() => await RunAsync(async (actor, company) =>
|
|
{
|
|
if (_edit is { } edit && _editDue is { } due)
|
|
{
|
|
await Schedule.UpdateAsync(actor, company, edit.Item.Id, new OpenItemChange(due, _editMethod, _editBank, _editDisputed, _editNotes));
|
|
_edit = null;
|
|
Toasts.Show(ToastKind.Success, T["Treasury.Saved"], null);
|
|
await LoadAsync();
|
|
}
|
|
});
|
|
|
|
private async Task StatementAsync() => await RunAsync(async (actor, company) =>
|
|
{
|
|
if (SelectedRows.FirstOrDefault() is { } row)
|
|
{
|
|
_statement = await Schedule.StatementAsync(actor, company, row.Item.PartyId, _direction);
|
|
}
|
|
});
|
|
|
|
private async Task ExportAsync() => await RunAsync(async (actor, company) => await LedgerScreens.DownloadAsync(JS, await Schedule.ExportAsync(actor, company, Filter)));
|
|
|
|
private async Task RunAsync(Func<Actor, string, Task> action)
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_busy = true;
|
|
try
|
|
{
|
|
await action(actor, company);
|
|
}
|
|
catch (ValidationFailedException ex)
|
|
{
|
|
Toasts.Show(ToastKind.Error, T["Treasury.NotDone"], TreasuryScreens.Errors(T, ex));
|
|
}
|
|
finally
|
|
{
|
|
_busy = false;
|
|
}
|
|
}
|
|
}
|