The pages of the Scadenzario area follow mockups 053-057: open items with aging, the collection and payment dialog, collections and payments of a period, remittances (new, file, presentation, credit, unpaid), SDD mandates, reminders with levels and history, bank reconciliation with rules, and the cash flow forecast. The dashboard shows the items due among the deadlines and the overdue receivables among the things to do. Texts are in Treasury.json; the menu lists the new pages and no longer marks the area as coming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4014373797
commit
aef0a0d233
20 files changed
+3437
-12
No files matched your search
@@ -0,0 +1,397 @@
|
||||
@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="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="num">
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user