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
@@ -13,6 +13,11 @@ using Khaemhat.Infrastructure.Files;
|
||||
|
||||
namespace Khaemhat.Application.Treasury;
|
||||
|
||||
/// <summary>The payment methods and the bank accounts of the company.</summary>
|
||||
/// <param name="Methods">The payment methods in use.</param>
|
||||
/// <param name="Banks">The bank accounts in use.</param>
|
||||
public sealed record TreasuryChoices(IReadOnlyList<PaymentMethod> Methods, IReadOnlyList<BankAccount> Banks);
|
||||
|
||||
/// <summary>Which items the schedule shows.</summary>
|
||||
public enum ScheduleView
|
||||
{
|
||||
@@ -258,6 +263,20 @@ public sealed class ScheduleService
|
||||
return await RowsAsync(uow, items, today, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>The payment methods and the bank accounts in use, for the choices of the treasury screens.</summary>
|
||||
/// <param name="actor">Who reads.</param>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>The choices, by code.</returns>
|
||||
public async Task<TreasuryChoices> ChoicesAsync(Actor actor, string companyCode, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var company = await CompanyGuard.DemandAsync(_permissions, actor, companyCode, TreasuryPermissions.ScheduleRead, cancellationToken).ConfigureAwait(false);
|
||||
await using var uow = await _factory.CreateAsync(DatabaseScope.Company(company), cancellationToken).ConfigureAwait(false);
|
||||
var methods = (await uow.Repository<PaymentMethod, long>().ListAsync(Query.For<PaymentMethod>().Where(m => !m.Disabled).OrderBy(m => m.Code), cancellationToken).ConfigureAwait(false)).Items;
|
||||
var banks = (await uow.Repository<BankAccount, long>().ListAsync(Query.For<BankAccount>().Where(b => !b.Disabled).OrderBy(b => b.Code), cancellationToken).ConfigureAwait(false)).Items;
|
||||
return new TreasuryChoices(methods, banks);
|
||||
}
|
||||
|
||||
internal static async Task<ScheduleResult> LoadAsync(IUnitOfWork uow, ScheduleFilter filter, DateOnly today, CancellationToken cancellationToken)
|
||||
{
|
||||
var direction = filter.Direction;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Globalization;
|
||||
using Khaemhat.Application.Dashboard;
|
||||
using Khaemhat.Application.Localization;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Core.Accounting;
|
||||
using Khaemhat.Core.Treasury;
|
||||
|
||||
namespace Khaemhat.Application.Treasury;
|
||||
|
||||
/// <summary>
|
||||
/// The schedule on the dashboard (SPEC §10.3): the collections and payments due in the next days among the deadlines,
|
||||
/// and the customers' items past due among the things to do. Only for who may see the schedule of the company.
|
||||
/// </summary>
|
||||
/// <param name="schedule">The schedule.</param>
|
||||
/// <param name="permissions">The permissions, licence included.</param>
|
||||
/// <param name="texts">The texts.</param>
|
||||
public sealed class TreasuryFeedSource(ScheduleService schedule, PermissionService permissions, ITexts texts) : IDeadlineSource, ITodoSource
|
||||
{
|
||||
/// <summary>The text key of the area.</summary>
|
||||
public const string Area = "Dashboard.Areas.Treasury";
|
||||
|
||||
/// <summary>The most deadlines of the schedule on the dashboard.</summary>
|
||||
public const int MaxDeadlines = 12;
|
||||
|
||||
private const string Href = "/scadenzario/scadenze";
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<FeedItem>> GetAsync(FeedContext context, DateOnly until, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
if (!await AllowedAsync(context, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var days = Math.Max(0, until.DayNumber - context.Today.DayNumber);
|
||||
var rows = await schedule.DueSoonAsync(context.Actor, context.Actor.CompanyCode!, days, MaxDeadlines * 2, cancellationToken).ConfigureAwait(false);
|
||||
return [.. rows.Where(r => r.Item.DueDate >= context.Today && r.Item.Status != OpenItemStatus.InRemittance).Take(MaxDeadlines).Select(r =>
|
||||
{
|
||||
var receivable = r.Item.Direction == OpenItemDirection.Receivable;
|
||||
return new FeedItem(
|
||||
"openitem-" + r.Item.Id.ToString(CultureInfo.InvariantCulture),
|
||||
texts.Format(receivable ? "Dashboard.Feed.DueReceivable" : "Dashboard.Feed.DuePayable", r.PartyName, texts.Money(r.Item.Residual)),
|
||||
Area,
|
||||
receivable ? FeedTone.Info : FeedTone.Warning)
|
||||
{
|
||||
Detail = r.Item.DocumentNumber,
|
||||
When = new DateTimeOffset(r.Item.DueDate.ToDateTime(TimeOnly.MinValue), context.Now.Offset),
|
||||
Href = Href + (receivable ? string.Empty : "?vista=fornitori"),
|
||||
};
|
||||
})];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<FeedItem>> GetAsync(FeedContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
if (!await AllowedAsync(context, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var overdue = await schedule.ItemsAsync(context.Actor, context.Actor.CompanyCode!, new ScheduleFilter(OpenItemDirection.Receivable, ScheduleView.Overdue), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return overdue.Rows.Count == 0
|
||||
? []
|
||||
:
|
||||
[
|
||||
new FeedItem("openitems-overdue", texts.Format("Dashboard.Feed.Overdue", overdue.Rows.Count, texts.Money(overdue.Overdue)), Area, FeedTone.Error)
|
||||
{
|
||||
Priority = 40,
|
||||
Href = "/scadenzario/solleciti",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
private async Task<bool> AllowedAsync(FeedContext context, CancellationToken cancellationToken) =>
|
||||
context.Actor.CompanyCode is not null && (await permissions.CheckAsync(context.Actor, TreasuryPermissions.ScheduleRead, cancellationToken).ConfigureAwait(false)).Allowed;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
@page "/scadenzario/flusso-di-cassa"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Treasury
|
||||
@using Khaemhat.Core.Treasury
|
||||
@using Khaemhat.Web.Treasury
|
||||
@inject ShellSession Session
|
||||
@inject CashFlowService CashFlow
|
||||
|
||||
@* The cash flow forecast (SPEC §11.8, report "flusso di cassa 90 gg"): the money of the banks and the cash today and,
|
||||
week by week or month by month, what comes in and goes out from the open items, the remittances presented, the
|
||||
orders not yet invoiced, the recurring entries and the taxes still to pay. Overdue items fall in the first period. *@
|
||||
<KhPageTitle Text="@T["Treasury.CashFlow.Title"]" Icon="chart" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.ScheduleRead">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.CashFlow.Title"]</div>
|
||||
<h1>@T["Treasury.CashFlow.Heading"]</h1>
|
||||
<div class="sub">@T["Treasury.CashFlow.Hint"]</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KhPanel Tight="true">
|
||||
<div class="filters kh-ledger-filters">
|
||||
<KhSelect TValue="int" Label="@T["Treasury.CashFlow.Days"]" Name="cfdays" Options="DayChoices" Value="_days" ValueChanged="SetDaysAsync" />
|
||||
<KhSelect TValue="int" Label="@T["Treasury.CashFlow.Period"]" Name="cfperiod" Options="PeriodChoices" Value="_period" ValueChanged="SetPeriodAsync" />
|
||||
@foreach (var source in Enum.GetValues<CashFlowSource>())
|
||||
{
|
||||
<label class="chk">
|
||||
<input type="checkbox" checked="@_sources.Contains(source)" @onchange="e => ToggleAsync(source, e.Value is true)" />
|
||||
@T[TreasuryScreens.EnumKey(source)]
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
</KhPanel>
|
||||
|
||||
@if (_forecast is { } f)
|
||||
{
|
||||
var lowest = f.Periods.Count == 0 ? f.Opening : Math.Min(f.Opening, f.Periods.Min(p => p.Balance));
|
||||
<KhStrip Items="Stats(f, lowest)" Label="@T["Treasury.CashFlow.Title"]" />
|
||||
|
||||
<div class="kh-ledger-two">
|
||||
<KhPanel Title="@T["Treasury.CashFlow.Periods"]" Icon="chart" Tight="true">
|
||||
<table class="grid" aria-label="@T["Treasury.CashFlow.Periods"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.CashFlow.Period"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.In"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.Out"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.CashFlow.Balance"]</th>
|
||||
<th scope="col" class="kh-cfbarcol"><span class="sr-only">@T["Treasury.CashFlow.Chart"]</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@{ var scale = Math.Max(1m, f.Periods.Select(p => Math.Abs(p.Balance)).DefaultIfEmpty(0m).Max()); }
|
||||
@foreach (var p in f.Periods)
|
||||
{
|
||||
var width = (int)Math.Round(Math.Abs(p.Balance) / scale * 100m);
|
||||
<tr>
|
||||
<td>@T.Date(p.From) – @T.Date(p.To)</td>
|
||||
<td class="num pos">@(p.In != 0m ? T.Money(p.In) : null)</td>
|
||||
<td class="num neg">@(p.Out != 0m ? T.Money(p.Out) : null)</td>
|
||||
<td class="num @(p.Balance < 0m ? "neg" : null)"><b>@T.Money(p.Balance)</b></td>
|
||||
<td class="kh-cfbarcol"><span class="kh-cfbar @(p.Balance < 0m ? "neg" : null)" style="width:@(width)%"></span></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</KhPanel>
|
||||
<KhPanel Title="@T["Treasury.CashFlow.Accounts"]" Icon="building" Tight="true">
|
||||
<table class="grid" aria-label="@T["Treasury.CashFlow.Accounts"]">
|
||||
<tbody>
|
||||
@foreach (var a in f.Accounts)
|
||||
{
|
||||
<tr>
|
||||
<td>@a.Name</td>
|
||||
<td class="num">@T.Money(a.Balance)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td><b>@T["Treasury.Fields.Total"]</b></td>
|
||||
<td class="num"><b>@T.Money(f.Opening)</b></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</KhPanel>
|
||||
</div>
|
||||
|
||||
<KhPanel Title="@T["Treasury.CashFlow.Movements"]" Icon="list" Tight="true">
|
||||
@if (f.Movements.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.CashFlow.NoMovements"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.CashFlow.Movements"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Date"]</th>
|
||||
<th scope="col">@T["Treasury.CashFlow.Source"]</th>
|
||||
<th scope="col">@T["Treasury.Reconciliation.Description"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Amount"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var m in f.Movements)
|
||||
{
|
||||
<tr>
|
||||
<td>@T.Date(m.Date)</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(m.Source)]</td>
|
||||
<td>@m.Label</td>
|
||||
<td class="num @(m.Amount < 0m ? "neg" : "pos")">@T.Money(m.Amount)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</KhPanel>
|
||||
}
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private int _days = 90;
|
||||
private int _period = 7;
|
||||
private readonly HashSet<CashFlowSource> _sources = [.. Enum.GetValues<CashFlowSource>()];
|
||||
private CashFlowForecast? _forecast;
|
||||
|
||||
private IReadOnlyList<KhOption<int>> DayChoices =>
|
||||
[.. new[] { 30, 60, 90, 180, 365 }.Select(d => new KhOption<int>(d, T.Format("Treasury.CashFlow.DaysText", d)))];
|
||||
|
||||
private IReadOnlyList<KhOption<int>> PeriodChoices =>
|
||||
[
|
||||
new(7, T["Treasury.CashFlow.Weeks"]),
|
||||
new(30, T["Treasury.CashFlow.Months"]),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
if (FinanceGuard.Allowed(Session, TreasuryPermissions.ScheduleRead))
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private IReadOnlyList<KhStat> Stats(CashFlowForecast f, decimal lowest) =>
|
||||
[
|
||||
new(T["Treasury.CashFlow.Today"], T.Money(f.Opening)),
|
||||
new(T["Treasury.CashFlow.TotalIn"], T.Money(f.Periods.Sum(p => p.In)), KhTone.Ok),
|
||||
new(T["Treasury.CashFlow.TotalOut"], T.Money(f.Periods.Sum(p => p.Out)), KhTone.Warning),
|
||||
new(T["Treasury.CashFlow.End"], T.Money(f.Periods.Count == 0 ? f.Opening : f.Periods[^1].Balance)),
|
||||
new(T["Treasury.CashFlow.Lowest"], T.Money(lowest), lowest < 0m ? KhTone.Error : KhTone.Neutral),
|
||||
];
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
if (Session.Actor is { } actor && Session.Company?.Code is { } company)
|
||||
{
|
||||
_forecast = await CashFlow.ForecastAsync(actor, company, _days, _sources, _period);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetDaysAsync(int days)
|
||||
{
|
||||
_days = days;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task SetPeriodAsync(int period)
|
||||
{
|
||||
_period = period;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task ToggleAsync(CashFlowSource source, bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_sources.Add(source);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sources.Remove(source);
|
||||
}
|
||||
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
@page "/scadenzario/solleciti"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Application.Treasury
|
||||
@using Khaemhat.Core.Treasury
|
||||
@using Khaemhat.Web.Ledger
|
||||
@using Khaemhat.Web.Treasury
|
||||
@inject ShellSession Session
|
||||
@inject DunningService Dunning
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject IJSRuntime JS
|
||||
|
||||
@* The reminders (SPEC §11.8, mockup 056): the customers with items past due by more days than the next level asks,
|
||||
public administrations and disputed items left out; the level, the channel and the late interest of D.Lgs.
|
||||
231/2002; the letters sent by e-mail or PEC with the PDF attached, the third level that blocks the customer, the
|
||||
history of what was sent. The scheduled task "Solleciti automatici" sends the levels marked automatic. *@
|
||||
<KhPageTitle Text="@T["Treasury.Dunning.Title"]" Icon="mail" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.ScheduleRead">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.Dunning.Title"]</div>
|
||||
<h1>@T["Treasury.Dunning.Heading"]</h1>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
@if (CanWrite)
|
||||
{
|
||||
<div class="toolbar">
|
||||
<button type="button" class="btn" disabled="@(_busy || _included.Count == 0)" @onclick="PreviewAsync"><KhIcon Name="eye" /> @T["Treasury.Dunning.Preview"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _included.Count == 0)" @onclick="SendAsync"><KhIcon Name="send" /> @T.Format("Treasury.Dunning.Send", _included.Count)</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<KhStrip Items="Stats" Label="@T["Treasury.Dunning.Title"]" />
|
||||
|
||||
<KhTabs Items="Tabs" Active="@_tab" ActiveChanged="SetTabAsync" Label="@T["Treasury.Dunning.Title"]" />
|
||||
|
||||
@if (_tab == "proposal")
|
||||
{
|
||||
<KhPanel Title="@T["Treasury.Dunning.Proposal"]" Tight="true">
|
||||
<Actions><span class="muted sm">@T["Treasury.Dunning.Rule"]</span></Actions>
|
||||
<ChildContent>
|
||||
@if (_proposal.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Dunning.Nothing"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.Dunning.Proposal"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Customer"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Dunning.Items"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Schedule.Overdue"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Dunning.MaxDays"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.LastSent"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.NextLevel"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Channel"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Statement.Interest"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Include"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var p in _proposal)
|
||||
{
|
||||
<tr>
|
||||
<td><b>@p.PartyName</b> @(p.Blocked ? T["Treasury.Dunning.Blocked"] : null)</td>
|
||||
<td class="num">@p.Items.Count</td>
|
||||
<td class="num">@T.Money(p.Overdue)</td>
|
||||
<td class="num">@p.MaxDays</td>
|
||||
<td>@(p.LastSent is { } last ? p.CurrentLevel + " · " + T.Date(last) : "—")</td>
|
||||
<td>
|
||||
@if (p.Level is { } level)
|
||||
{
|
||||
<KhBadge Tone="@(level.Level >= 2 ? KhTone.Warning : KhTone.Info)">@T.Format("Treasury.Dunning.Level", level.Level)</KhBadge>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhBadge Tone="KhTone.Neutral">@T["Treasury.Dunning.Waiting"]</KhBadge>
|
||||
}
|
||||
</td>
|
||||
<td>@(p.Level is { } l ? T[TreasuryScreens.EnumKey(l.Channel)] : "—") <span class="muted sm">@(p.Pec ?? p.Email)</span></td>
|
||||
<td class="num">@T.Money(p.Interest)</td>
|
||||
<td>
|
||||
@if (p.Level is not null)
|
||||
{
|
||||
var on = _included.Contains(p.PartyId);
|
||||
<button type="button" role="switch" class="kh-switch" aria-checked="@(on ? "true" : "false")" aria-label="@(T["Treasury.Dunning.Include"] + " " + p.PartyName)"
|
||||
@onclick="() => Toggle(p.PartyId, !on)">
|
||||
<span class="switch @(on ? "on" : null)" aria-hidden="true"></span>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</ChildContent>
|
||||
</KhPanel>
|
||||
|
||||
<KhPanel Title="@T["Treasury.Dunning.Levels"]" Tight="true">
|
||||
<table class="grid" aria-label="@T["Treasury.Dunning.Levels"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Dunning.LevelColumn"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Dunning.After"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Template"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Channel"]</th>
|
||||
<th scope="col">@T["Treasury.Statement.Interest"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Action"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Automatic"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var level in _levels)
|
||||
{
|
||||
<tr>
|
||||
<td>@level.Level</td>
|
||||
<td class="num">@level.DaysAfterDue</td>
|
||||
<td>@level.Name</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(level.Channel)]</td>
|
||||
<td>@T[level.ChargeInterest ? "Treasury.Dunning.InterestYes" : "Treasury.Dunning.InterestNo"]</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(level.Action)]</td>
|
||||
<td>@T[level.Automatic ? "Common.Yes" : "Common.No"]</td>
|
||||
<td class="num">
|
||||
@if (CanWrite)
|
||||
{
|
||||
<KhIconButton Icon="edit" Text="@T["Treasury.Dunning.EditLevel"]" OnClick="() => OpenLevel(level)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="filters"><span class="muted sm">@T["Treasury.Dunning.Placeholders"]</span></div>
|
||||
</KhPanel>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhPanel Tight="true">
|
||||
@if (_history.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Dunning.NoHistory"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="grid" aria-label="@T["Treasury.Dunning.History"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Date"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Customer"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.LevelColumn"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Channel"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.Recipients"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Dunning.Items"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Schedule.Overdue"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Statement.Interest"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
||||
<th scope="col">@T["Treasury.Dunning.SentBy"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _history)
|
||||
{
|
||||
var l = row.Letter;
|
||||
<tr>
|
||||
<td>@T.Date(l.SentOn)</td>
|
||||
<td>@row.PartyName</td>
|
||||
<td>@l.Level</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(l.Channel)]</td>
|
||||
<td class="sm">@l.Recipients</td>
|
||||
<td class="num">@l.ItemCount</td>
|
||||
<td class="num">@T.Money(l.OverdueAmount)</td>
|
||||
<td class="num">@LedgerScreens.AmountText(T, l.Interest)</td>
|
||||
<td><KhBadge Tone="@(l.Status == DunningLetterStatus.Failed ? KhTone.Error : l.Status == DunningLetterStatus.Sent ? KhTone.Ok : KhTone.Info)">@T[TreasuryScreens.EnumKey(l.Status)]</KhBadge></td>
|
||||
<td>@l.SentBy</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</KhPanel>
|
||||
}
|
||||
|
||||
<KhDialog Open="_level is not null" Title="@T["Treasury.Dunning.EditLevel"]" Icon="edit" Size="lg" OnClose="() => _level = null">
|
||||
<ChildContent>
|
||||
@if (_level is { } level)
|
||||
{
|
||||
<div class="form plain">
|
||||
<KhTextBox Label="@T["Treasury.Dunning.Template"]" Name="lname" @bind-Value="level.Name" MaxLength="60" Span="6" Required="true" />
|
||||
<KhNumberBox Label="@T["Treasury.Dunning.After"]" Name="ldays" Value="level.DaysAfterDue" ValueChanged="v => level.DaysAfterDue = (int)(v ?? 0)" Decimals="0" Min="1" Span="3" />
|
||||
<KhSelect TValue="DunningChannel" Label="@T["Treasury.Dunning.Channel"]" Name="lchannel" Options="Channels" @bind-Value="level.Channel" Span="3" />
|
||||
<KhSelect TValue="DunningAction" Label="@T["Treasury.Dunning.Action"]" Name="laction" Options="Actions" @bind-Value="level.Action" Span="6" />
|
||||
<KhCheck Label="@T["Treasury.Dunning.ChargeInterest"]" Name="linterest" @bind-Value="level.ChargeInterest" Span="3" />
|
||||
<KhCheck Label="@T["Treasury.Dunning.Automatic"]" Name="lauto" @bind-Value="level.Automatic" Span="3" />
|
||||
<KhTextBox Label="@T["Treasury.Dunning.Subject"]" Name="lsubject" @bind-Value="level.Subject" MaxLength="200" Span="12" Required="true" />
|
||||
<KhTextArea Label="@T["Treasury.Dunning.Body"]" Name="lbody" @bind-Value="level.Body" Rows="10" Span="12" />
|
||||
</div>
|
||||
<p class="muted sm">@T["Treasury.Dunning.Placeholders"]</p>
|
||||
}
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _level = null">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@_busy" @onclick="SaveLevelAsync"><KhIcon Name="check" /> @T["Common.Save"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private string _tab = "proposal";
|
||||
private IReadOnlyList<DunningProposal> _proposal = [];
|
||||
private IReadOnlyList<DunningLevel> _levels = [];
|
||||
private IReadOnlyList<DunningLetterRow> _history = [];
|
||||
private readonly HashSet<long> _included = [];
|
||||
private DunningLevel? _level;
|
||||
private bool _busy;
|
||||
|
||||
private bool CanWrite => Session.Permissions.Allows(TreasuryPermissions.ScheduleWrite);
|
||||
|
||||
private IReadOnlyList<KhTabItem> Tabs =>
|
||||
[
|
||||
new("proposal", "send", T["Treasury.Dunning.Proposal"], _proposal.Count(p => p.Level is not null)),
|
||||
new("history", "clock", T["Treasury.Dunning.History"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhOption<DunningChannel>> Channels => TreasuryScreens.Choices<DunningChannel>(T);
|
||||
|
||||
private IReadOnlyList<KhOption<DunningAction>> Actions => TreasuryScreens.Choices<DunningAction>(T);
|
||||
|
||||
private IReadOnlyList<KhStat> Stats
|
||||
{
|
||||
get
|
||||
{
|
||||
var last = _history.Count == 0 ? null : _history[0].Letter;
|
||||
return
|
||||
[
|
||||
new(T["Treasury.Dunning.Customers"], _proposal.Count.ToString(T.Culture)),
|
||||
new(T["Treasury.Dunning.OverdueTotal"], T.Money(_proposal.Sum(p => p.Overdue)), KhTone.Error),
|
||||
new(T["Treasury.Dunning.Today"], _proposal.Count(p => p.Level is not null).ToString(T.Culture), KhTone.Warning),
|
||||
new(T["Treasury.Dunning.LastRun"], last is null ? "—" : T.Date(last.SentOn) + " · " + _history.Count(h => h.Letter.SentOn == last.SentOn)),
|
||||
new(T["Treasury.Dunning.Schedule"], T["Treasury.Dunning.ScheduleText"]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
if (FinanceGuard.Allowed(Session, TreasuryPermissions.ScheduleRead))
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_levels = await Dunning.LevelsAsync(actor, company);
|
||||
_proposal = await Dunning.ProposalAsync(actor, company);
|
||||
_history = await Dunning.HistoryAsync(actor, company);
|
||||
_included.Clear();
|
||||
_included.UnionWith(_proposal.Where(p => p.Level is not null).Select(p => p.PartyId));
|
||||
}
|
||||
|
||||
private async Task SetTabAsync(string tab)
|
||||
{
|
||||
_tab = tab;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private void Toggle(long partyId, bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_included.Add(partyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_included.Remove(partyId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PreviewAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_proposal.FirstOrDefault(p => _included.Contains(p.PartyId)) is { } first)
|
||||
{
|
||||
await LedgerScreens.DownloadAsync(JS, await Dunning.PreviewAsync(actor, company, first.PartyId));
|
||||
}
|
||||
});
|
||||
|
||||
private async Task SendAsync()
|
||||
{
|
||||
if (!await Dialogs.ConfirmAsync(new ConfirmRequest(T["Treasury.Dunning.SendTitle"], T.Format("Treasury.Dunning.SendText", _included.Count), T["Treasury.Dunning.SendTitle"], T["Common.Cancel"])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunAsync(async (actor, company) =>
|
||||
{
|
||||
var run = await Dunning.SendAsync(actor, company, [.. _included]);
|
||||
Toasts.Show(run.Skipped.Count == 0 ? ToastKind.Success : ToastKind.Warning, T.Format("Treasury.Dunning.Sent", run.Sent, run.Letters),
|
||||
run.Skipped.Count == 0 ? null : string.Join("; ", run.Skipped.Select(s => s.Party + ": " + (T.Contains(s.Reason) ? T[s.Reason] : s.Reason))));
|
||||
if (run.Pdf is { } pdf)
|
||||
{
|
||||
await LedgerScreens.DownloadAsync(JS, pdf);
|
||||
}
|
||||
|
||||
await LoadAsync();
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenLevel(DunningLevel level) => _level = new DunningLevel
|
||||
{
|
||||
Id = level.Id,
|
||||
Level = level.Level,
|
||||
DaysAfterDue = level.DaysAfterDue,
|
||||
Name = level.Name,
|
||||
Subject = level.Subject,
|
||||
Body = level.Body,
|
||||
Channel = level.Channel,
|
||||
ChargeInterest = level.ChargeInterest,
|
||||
Action = level.Action,
|
||||
Automatic = level.Automatic,
|
||||
};
|
||||
|
||||
private async Task SaveLevelAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_level is { } level)
|
||||
{
|
||||
await Dunning.SaveLevelAsync(actor, company, level);
|
||||
_level = null;
|
||||
Toasts.Show(ToastKind.Success, T["Treasury.Saved"], null);
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
@using Khaemhat.Application.Modules
|
||||
@inject ShellSession Session
|
||||
|
||||
@* What every page of the schedule checks first: an open company, the module FIN in the licence and the permission. *@
|
||||
@if (!_loaded)
|
||||
{
|
||||
<p class="muted kh-pad">@T["Common.Loading"]</p>
|
||||
}
|
||||
else if (Session.Company is null)
|
||||
{
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="building" Class="lg" />
|
||||
<h1>@T["Treasury.NoCompany"]</h1>
|
||||
</div>
|
||||
}
|
||||
else if (!Session.Licenses.IsModuleActive(ModuleCodes.Finance))
|
||||
{
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="key" Class="lg" />
|
||||
<h1>@T["Treasury.NoModule.Title"]</h1>
|
||||
<p class="lead">@T["Treasury.NoModule.Lead"]</p>
|
||||
</div>
|
||||
}
|
||||
else if (!Session.Permissions.Allows(Permission))
|
||||
{
|
||||
<div class="kh-message">
|
||||
<KhIcon Name="lock" Class="lg" />
|
||||
<h1>@T["Pages.AccessDenied.Title"]</h1>
|
||||
<p class="lead">@T["Pages.AccessDenied.Lead"]</p>
|
||||
<a class="btn" href="./">@T["Common.BackHome"]</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@ChildContent
|
||||
}
|
||||
|
||||
@code {
|
||||
private bool _loaded;
|
||||
|
||||
/// <summary>The permission the page needs.</summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Permission { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>The page.</summary>
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
/// <summary>Whether the page may load its data: company, licence and permission.</summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="permission">The permission.</param>
|
||||
/// <returns>True when it may.</returns>
|
||||
public static bool Allowed(ShellSession session, string permission) =>
|
||||
session is { Actor: not null, Company: not null } && session.Licenses.IsModuleActive(ModuleCodes.Finance) && session.Permissions.Allows(permission);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
_loaded = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
@page "/scadenzario/mandati"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Parties
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Application.Treasury
|
||||
@using Khaemhat.Core.Parties
|
||||
@using Khaemhat.Core.Treasury
|
||||
@using Khaemhat.Web.Treasury
|
||||
@inject ShellSession Session
|
||||
@inject MandateService Mandates
|
||||
@inject PartyService Parties
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* The SEPA direct debit mandates of the customers (SPEC §11.8, mockup 055): the unique reference, the signature, the
|
||||
scheme Core or B2B, the account of the debtor; a direct debit remittance takes only the items of customers with a
|
||||
valid mandate, and the first collection of each mandate goes out as FRST, the next ones as RCUR. *@
|
||||
<KhPageTitle Text="@T["Treasury.Mandates.Title"]" Icon="file-check" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.ScheduleRead">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.Mandates.Title"]</div>
|
||||
<h1>@T["Treasury.Mandates.Heading"]</h1>
|
||||
<div class="sub">@T["Treasury.Mandates.Hint"]</div>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
@if (CanWrite)
|
||||
{
|
||||
<div class="toolbar">
|
||||
<button type="button" class="btn primary" @onclick="() => OpenEdit(null)"><KhIcon Name="plus" /> @T["Treasury.Mandates.New"]</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<KhPanel Tight="true">
|
||||
@if (_rows.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Mandates.None"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.Mandates.Title"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Customer"]</th>
|
||||
<th scope="col">@T["Treasury.Mandates.Reference"]</th>
|
||||
<th scope="col">@T["Treasury.Mandates.Signed"]</th>
|
||||
<th scope="col">@T["Treasury.Mandates.Scheme"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Iban"]</th>
|
||||
<th scope="col">@T["Treasury.Mandates.LastCollection"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _rows)
|
||||
{
|
||||
var m = row.Mandate;
|
||||
<tr>
|
||||
<td><b>@row.PartyName</b> <span class="muted sm">@row.PartyCode</span></td>
|
||||
<td class="code">@m.Reference</td>
|
||||
<td>@T.Date(m.SignatureDate)</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(m.Scheme)] @(m.OneOff ? "· " + T["Treasury.Mandates.OneOff"] : null)</td>
|
||||
<td class="code">@m.Iban</td>
|
||||
<td>@(m.LastCollectionDate is { } last ? T.Date(last) : T["Treasury.Mandates.First"])</td>
|
||||
<td><KhBadge Tone="@(m.Revoked ? KhTone.Error : KhTone.Ok)">@T[m.Revoked ? "Treasury.Mandates.Revoked" : "Treasury.Mandates.Active"]</KhBadge></td>
|
||||
<td class="num">
|
||||
@if (CanWrite)
|
||||
{
|
||||
<KhIconButton Icon="edit" Text="@T["Treasury.Mandates.Edit"]" OnClick="() => OpenEdit(row)" />
|
||||
<KhIconButton Icon="@(m.Revoked ? "undo" : "slash")" Text="@T[m.Revoked ? "Treasury.Mandates.Restore" : "Treasury.Mandates.Revoke"]" Disabled="_busy" OnClick="() => RevokeAsync(row)" />
|
||||
<KhIconButton Icon="trash" Text="@T["Treasury.Mandates.Delete"]" Danger="true" Disabled="_busy" OnClick="() => DeleteAsync(row)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</KhPanel>
|
||||
|
||||
<KhDialog Open="_editOpen" Title="@T[_editId is null ? "Treasury.Mandates.New" : "Treasury.Mandates.Edit"]" Icon="file-check" OnClose="() => _editOpen = false">
|
||||
<ChildContent>
|
||||
<div class="form plain">
|
||||
<KhHotlink TItem="PartyRow" Label="@T["Treasury.Fields.Customer"]" Name="mparty" @bind-Value="_party" Span="12" Required="true"
|
||||
Search="SearchPartiesAsync" CodeOf="r => r.Code" DescriptionOf="r => r.Name" />
|
||||
<KhTextBox Label="@T["Treasury.Mandates.Reference"]" Name="mref" @bind-Value="_reference" MaxLength="35" Mono="true" Span="6" Required="true" />
|
||||
<KhDateBox Label="@T["Treasury.Mandates.Signed"]" Name="msigned" @bind-Value="_signed" Span="6" Required="true" />
|
||||
<KhSelect TValue="SddScheme" Label="@T["Treasury.Mandates.Scheme"]" Name="mscheme" Options="Schemes" @bind-Value="_scheme" Span="6" />
|
||||
<KhCheck Label="@T["Treasury.Mandates.OneOff"]" Name="moneoff" @bind-Value="_oneOff" Span="6" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Iban"]" Name="miban" @bind-Value="_iban" MaxLength="34" Mono="true" Span="8" Required="true" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Bic"]" Name="mbic" @bind-Value="_bic" MaxLength="11" Mono="true" Span="4" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Notes"]" Name="mnotes" @bind-Value="_notes" MaxLength="200" Span="12" />
|
||||
</div>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _editOpen = false">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _party is null || _signed is null)" @onclick="SaveAsync"><KhIcon Name="check" /> @T["Common.Save"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<MandateRow> _rows = [];
|
||||
private bool _busy;
|
||||
private bool _editOpen;
|
||||
private long? _editId;
|
||||
private PartyRow? _party;
|
||||
private string? _reference;
|
||||
private DateOnly? _signed;
|
||||
private SddScheme _scheme;
|
||||
private bool _oneOff;
|
||||
private string? _iban;
|
||||
private string? _bic;
|
||||
private string? _notes;
|
||||
|
||||
private bool CanWrite => Session.Permissions.Allows(TreasuryPermissions.ScheduleWrite);
|
||||
|
||||
private IReadOnlyList<KhOption<SddScheme>> Schemes => TreasuryScreens.Choices<SddScheme>(T);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
if (FinanceGuard.Allowed(Session, TreasuryPermissions.ScheduleRead))
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
if (Session.Actor is { } actor && Session.Company?.Code is { } company)
|
||||
{
|
||||
_rows = await Mandates.ListAsync(actor, company);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IReadOnlyList<PartyRow>> SearchPartiesAsync(string text, CancellationToken cancellationToken) =>
|
||||
Session.Actor is { } actor && Session.Company?.Code is { } company && Session.Permissions.Allows(PartyService.ReadPermission)
|
||||
? await Parties.SearchAsync(actor, company, PartyArchive.Customers, text, cancellationToken)
|
||||
: [];
|
||||
|
||||
private async Task OpenEdit(MandateRow? row)
|
||||
{
|
||||
var m = row?.Mandate;
|
||||
_editId = m?.Id;
|
||||
_party = m is not null && Session.Actor is { } actor && Session.Company?.Code is { } company && Session.Permissions.Allows(PartyService.ReadPermission)
|
||||
? (await Parties.RowsAsync(actor, company, [m.PartyId])).FirstOrDefault()
|
||||
: null;
|
||||
_reference = m?.Reference;
|
||||
_signed = m?.SignatureDate ?? DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||||
_scheme = m?.Scheme ?? SddScheme.Core;
|
||||
_oneOff = m?.OneOff ?? false;
|
||||
_iban = m?.Iban;
|
||||
_bic = m?.Bic;
|
||||
_notes = m?.Notes;
|
||||
_editOpen = true;
|
||||
}
|
||||
|
||||
private async Task SaveAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_party is { } party && _signed is { } signed)
|
||||
{
|
||||
await Mandates.SaveAsync(actor, company, new MandateInput(_editId, party.Id, _reference ?? string.Empty, signed, _scheme, _iban ?? string.Empty, _bic, _oneOff, _notes));
|
||||
_editOpen = false;
|
||||
Toasts.Show(ToastKind.Success, T["Treasury.Saved"], null);
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private async Task RevokeAsync(MandateRow row) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Mandates.RevokeAsync(actor, company, row.Mandate.Id, !row.Mandate.Revoked);
|
||||
await LoadAsync();
|
||||
});
|
||||
|
||||
private async Task DeleteAsync(MandateRow row)
|
||||
{
|
||||
if (!await Dialogs.ConfirmAsync(new ConfirmRequest(T["Treasury.Mandates.Delete"], T.Format("Treasury.Mandates.DeleteText", row.Mandate.Reference), T["Treasury.Mandates.Delete"], T["Common.Cancel"], Danger: true)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Mandates.DeleteAsync(actor, company, row.Mandate.Id);
|
||||
await LoadAsync();
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
@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 PaymentService Payments
|
||||
@inject ToastService Toasts
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* Record a collection or a payment on the items chosen in the schedule (SPEC §11.8, mockup 054): the amount of each
|
||||
item, an allowance that closes it for less, the fees of the bank; the entry is written by the treasury with the
|
||||
template of collections or payments and the items are settled. *@
|
||||
<KhDialog Open="Open" Title="@T[Receipt ? "Treasury.Payment.NewReceipt" : "Treasury.Payment.NewPayment"]" Icon="euro" Size="lg" OnClose="CloseAsync">
|
||||
<ChildContent>
|
||||
<div class="form plain">
|
||||
<KhTextBox Label="@T[Receipt ? "Treasury.Fields.Customer" : "Treasury.Fields.Supplier"]" Name="payparty" Value="@PartyName" ReadOnly="true" Span="6" />
|
||||
<KhDateBox Label="@T["Treasury.Fields.Date"]" Name="paydate" @bind-Value="_date" Required="true" Span="3" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Amount"]" Name="payamount" Value="@T.Money(Total)" ReadOnly="true" Span="3" />
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Method"]" Name="paymethod" Options="Methods" Empty="—" @bind-Value="_methodId" Span="4" />
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Bank"]" Name="paybank" Options="Banks" Empty="@T["Treasury.Payment.Cash"]" @bind-Value="_bankId" Span="4" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Reference"]" Name="payref" @bind-Value="_reference" MaxLength="60" Span="4" />
|
||||
<KhNumberBox Label="@T["Treasury.Fields.Fees"]" Name="payfees" @bind-Value="_fees" Decimals="2" Min="0" Span="4" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Notes"]" Name="paynotes" @bind-Value="_notes" MaxLength="200" Span="8" />
|
||||
</div>
|
||||
<h3 class="kh-subhead">@T["Treasury.Payment.Items"]</h3>
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.Payment.Items"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<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.Residual"]</th>
|
||||
<th scope="col" class="num">@T[Receipt ? "Treasury.Payment.Collected" : "Treasury.Payment.Paid"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Allowance"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Payment.ResidualAfter"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var line in _lines)
|
||||
{
|
||||
var item = line.Row.Item;
|
||||
<tr>
|
||||
<td class="code">@item.DocumentNumber</td>
|
||||
<td>@item.Installment</td>
|
||||
<td>@T.Date(item.DueDate)</td>
|
||||
<td class="num">@T.Money(item.Residual)</td>
|
||||
<td class="num"><input class="in num" aria-label="@(T["Treasury.Payment.Collected"] + " " + item.DocumentNumber)" value="@LedgerScreens.AmountText(T, line.Amount)" @onchange="e => line.Amount = LedgerScreens.ParseAmount(T, e.Value?.ToString())" style="width:120px" /></td>
|
||||
<td class="num"><input class="in num" aria-label="@(T["Treasury.Fields.Allowance"] + " " + item.DocumentNumber)" value="@LedgerScreens.AmountText(T, line.Allowance)" @onchange="e => line.Allowance = LedgerScreens.ParseAmount(T, e.Value?.ToString())" style="width:100px" /></td>
|
||||
<td class="num">@T.Money(item.Residual - line.Amount - line.Allowance)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3"><b>@T["Treasury.Fields.Total"]</b></td>
|
||||
<td class="num"><b>@T.Money(_lines.Sum(l => l.Row.Item.Residual))</b></td>
|
||||
<td class="num"><b>@T.Money(Total)</b></td>
|
||||
<td class="num"><b>@T.Money(_lines.Sum(l => l.Allowance))</b></td>
|
||||
<td class="num"><b>@T.Money(_lines.Sum(l => l.Row.Item.Residual - l.Amount - l.Allowance))</b></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<div class="callout info">
|
||||
<KhIcon Name="info" />
|
||||
<span>@T.Format(Receipt ? "Treasury.Payment.EntryReceipt" : "Treasury.Payment.EntryPayment", T.Money(Total), T.Money(_lines.Sum(l => l.Allowance)))</span>
|
||||
</div>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="CloseAsync"><KhIcon Name="x" /> @T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _date is null || Total == 0m && _lines.Sum(l => l.Allowance) == 0m)" @onclick="SaveAsync"><KhIcon Name="check" /> @T["Treasury.Payment.Save"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
|
||||
@code {
|
||||
private List<Line> _lines = [];
|
||||
private DateOnly? _date;
|
||||
private long? _methodId;
|
||||
private long? _bankId;
|
||||
private string? _reference;
|
||||
private decimal? _fees;
|
||||
private string? _notes;
|
||||
private bool _busy;
|
||||
private IReadOnlyList<ScheduleRow>? _shown;
|
||||
|
||||
/// <summary>Whether the dialog is open.</summary>
|
||||
[Parameter]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>The items to settle, all of one party and one direction.</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<ScheduleRow> Rows { get; set; } = [];
|
||||
|
||||
/// <summary>The payment methods and the banks.</summary>
|
||||
[Parameter]
|
||||
public TreasuryChoices? Choices { get; set; }
|
||||
|
||||
/// <summary>Closed without saving.</summary>
|
||||
[Parameter]
|
||||
public EventCallback OnClose { get; set; }
|
||||
|
||||
/// <summary>Saved.</summary>
|
||||
[Parameter]
|
||||
public EventCallback<Payment> OnSaved { get; set; }
|
||||
|
||||
private bool Receipt => Rows.Count == 0 || Rows[0].Item.Direction == OpenItemDirection.Receivable;
|
||||
|
||||
private string PartyName => Rows.Count == 0 ? string.Empty : (Rows[0].PartyCode is { } code ? code + " · " : string.Empty) + Rows[0].PartyName;
|
||||
|
||||
private decimal Total => _lines.Sum(l => l.Amount);
|
||||
|
||||
private IReadOnlyList<KhOption<long?>> Methods => TreasuryScreens.MethodChoices(Choices?.Methods ?? []);
|
||||
|
||||
private IReadOnlyList<KhOption<long?>> Banks => TreasuryScreens.BankChoices(Choices?.Banks ?? []);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (!Open || ReferenceEquals(_shown, Rows))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// A new set of items: the whole residual of each, the method of the first and the bank it names or the default.
|
||||
_shown = Rows;
|
||||
_lines = [.. Rows.Select(r => new Line(r) { Amount = r.Item.Residual })];
|
||||
_date = DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||||
_methodId = Rows.Select(r => r.Item.PaymentMethodId).FirstOrDefault(m => m is not null);
|
||||
_bankId = Rows.Select(r => r.Item.BankAccountId).FirstOrDefault(b => b is not null)
|
||||
?? Choices?.Banks.FirstOrDefault(b => b.IsDefault)?.Id ?? Choices?.Banks.FirstOrDefault()?.Id;
|
||||
_reference = null;
|
||||
_fees = null;
|
||||
_notes = null;
|
||||
}
|
||||
|
||||
private async Task CloseAsync()
|
||||
{
|
||||
_shown = null;
|
||||
await OnClose.InvokeAsync();
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _date is not { } date || Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
try
|
||||
{
|
||||
var payment = await Payments.RegisterAsync(actor, company, new PaymentInput(
|
||||
Receipt ? PaymentDirection.Receipt : PaymentDirection.Disbursement, Rows[0].Item.PartyId, date, _methodId, _bankId, _fees ?? 0m, _reference, _notes,
|
||||
[.. _lines.Where(l => l.Amount != 0m || l.Allowance != 0m).Select(l => new PaymentLineInput(l.Row.Item.Id, l.Amount, l.Allowance))]));
|
||||
Toasts.Show(ToastKind.Success, T[Receipt ? "Treasury.Payment.ReceiptSaved" : "Treasury.Payment.PaymentSaved"], T.Money(payment.Amount));
|
||||
_shown = null;
|
||||
await OnSaved.InvokeAsync(payment);
|
||||
}
|
||||
catch (ValidationFailedException ex)
|
||||
{
|
||||
Toasts.Show(ToastKind.Error, T["Treasury.NotDone"], TreasuryScreens.Errors(T, ex));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Line(ScheduleRow row)
|
||||
{
|
||||
public ScheduleRow Row { get; } = row;
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public decimal Allowance { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
@page "/scadenzario/incassi"
|
||||
@page "/scadenzario/pagamenti"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Application.Treasury
|
||||
@using Khaemhat.Core.Treasury
|
||||
@using Khaemhat.Web.Ledger
|
||||
@using Khaemhat.Web.Treasury
|
||||
@inject ShellSession Session
|
||||
@inject PaymentService Payments
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject NavigationManager Navigation
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* The collections or the payments of a period (SPEC §11.8): who, when, how much, on which bank, the documents they
|
||||
settled and their entry; cancelling one gives the items back and takes the entry away. Those born from a
|
||||
remittance are cancelled from the remittance. *@
|
||||
<KhPageTitle Text="@T[Title]" Icon="euro" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.PaymentRead">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T[Title]</div>
|
||||
<h1>@T[Title]</h1>
|
||||
<div class="sub">@T[Receipts ? "Treasury.Payments.ReceiptsHint" : "Treasury.Payments.PaymentsHint"]</div>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
<div class="toolbar">
|
||||
<a class="btn primary" href="@(TreasuryScreens.BasePath + "/scadenze" + (Receipts ? string.Empty : "?vista=fornitori"))">
|
||||
<KhIcon Name="plus" /> @T[Receipts ? "Treasury.Payment.NewReceipt" : "Treasury.Payment.NewPayment"]
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KhPanel Tight="true">
|
||||
<div class="filters kh-ledger-filters">
|
||||
<KhDateBox Label="@T["Treasury.Fields.From"]" Name="from" Value="_from" ValueChanged="SetFromAsync" />
|
||||
<KhDateBox Label="@T["Treasury.Fields.To"]" Name="to" Value="_to" ValueChanged="SetToAsync" />
|
||||
<span class="grow"></span>
|
||||
<span class="muted sm">@T.Format("Treasury.Payments.Total", _rows.Count, T.Money(_rows.Sum(r => r.Payment.Amount)))</span>
|
||||
</div>
|
||||
@if (_rows.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Payments.None"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T[Title]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Date"]</th>
|
||||
<th scope="col">@T[Receipts ? "Treasury.Fields.Customer" : "Treasury.Fields.Supplier"]</th>
|
||||
<th scope="col">@T["Treasury.Payments.Documents"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Reference"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Bank"]</th>
|
||||
<th scope="col">@T["Treasury.Payments.Origin"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Amount"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Allowance"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Fees"]</th>
|
||||
<th scope="col">@T["Treasury.Payments.Entry"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _rows)
|
||||
{
|
||||
var p = row.Payment;
|
||||
<tr>
|
||||
<td>@T.Date(p.PaymentDate)</td>
|
||||
<td><b>@row.PartyName</b></td>
|
||||
<td class="code">@row.Documents</td>
|
||||
<td>@p.Reference</td>
|
||||
<td>@(row.Bank ?? T["Treasury.Payment.Cash"])</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(p.Origin)]</td>
|
||||
<td class="num"><b>@T.Money(p.Amount)</b></td>
|
||||
<td class="num">@LedgerScreens.AmountText(T, p.AllowanceAmount)</td>
|
||||
<td class="num">@LedgerScreens.AmountText(T, p.Fees)</td>
|
||||
<td class="code">
|
||||
@if (p.GlEntryId is { } entry)
|
||||
{
|
||||
<a href="@LedgerScreens.EntryUrl(entry)">@row.EntryNumber</a>
|
||||
}
|
||||
</td>
|
||||
<td class="num">
|
||||
@if (CanWrite && p.Origin != PaymentOrigin.Remittance)
|
||||
{
|
||||
<KhIconButton Icon="undo" Text="@T["Treasury.Payments.Cancel"]" Disabled="_busy" OnClick="() => CancelAsync(row)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</KhPanel>
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<PaymentRow> _rows = [];
|
||||
private DateOnly? _from;
|
||||
private DateOnly? _to;
|
||||
private bool _busy;
|
||||
|
||||
private bool Receipts => !Navigation.Uri.Contains("/pagamenti", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private string Title => Receipts ? "Treasury.Payments.Receipts" : "Treasury.Payments.Payments";
|
||||
|
||||
private bool CanWrite => Session.Permissions.Allows(TreasuryPermissions.PaymentWrite);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
var today = DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||||
_from ??= new DateOnly(today.Year, 1, 1);
|
||||
_to ??= today.AddDays(30);
|
||||
if (FinanceGuard.Allowed(Session, TreasuryPermissions.PaymentRead))
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _from is not { } from || _to is not { } to)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_rows = await Payments.ListAsync(actor, company, Receipts ? PaymentDirection.Receipt : PaymentDirection.Disbursement, from, to);
|
||||
}
|
||||
|
||||
private async Task SetFromAsync(DateOnly? date)
|
||||
{
|
||||
_from = date;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task SetToAsync(DateOnly? date)
|
||||
{
|
||||
_to = date;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task CancelAsync(PaymentRow row)
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company
|
||||
|| !await Dialogs.ConfirmAsync(new ConfirmRequest(T["Treasury.Payments.Cancel"], T.Format("Treasury.Payments.CancelText", T.Money(row.Payment.Amount), row.PartyName), T["Treasury.Payments.Cancel"], T["Common.Cancel"])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
try
|
||||
{
|
||||
await Payments.CancelAsync(actor, company, row.Payment.Id);
|
||||
Toasts.Show(ToastKind.Success, T["Treasury.Payments.Cancelled"], null);
|
||||
await LoadAsync();
|
||||
}
|
||||
catch (ValidationFailedException ex)
|
||||
{
|
||||
Toasts.Show(ToastKind.Error, T["Treasury.NotDone"], TreasuryScreens.Errors(T, ex));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,604 @@
|
||||
@page "/scadenzario/riconciliazione"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Ledger
|
||||
@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 BankReconciliationService Reconciliation
|
||||
@inject ScheduleService Schedule
|
||||
@inject PaymentService Payments
|
||||
@inject LedgerService Ledger
|
||||
@inject ToastService Toasts
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* Bank reconciliation (SPEC §11.8, mockup 057): the statement imported from CAMT.053, CBI or CSV, the movements
|
||||
matched by amount, date, reference and name with open items, recorded payments, F24, remittance credits and unpaid
|
||||
effects, or by the saved rules for the recurring ones; the proposals confirmed one by one or all those above 90%,
|
||||
the rest matched by hand, posted to an account or ignored. The difference between the bank and the books is what is
|
||||
still to reconcile. *@
|
||||
<KhPageTitle Text="@T["Treasury.Reconciliation.Title"]" Icon="link" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.BankReconcile">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.Reconciliation.Title"]</div>
|
||||
<h1>@T["Treasury.Reconciliation.Title"]</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KhStrip Items="Stats" Label="@T["Treasury.Reconciliation.Title"]" />
|
||||
|
||||
<div class="filters kh-ledger-filters">
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Fields.Bank"]" Name="rbank" Options="Banks" Value="_bankId" ValueChanged="SetBankAsync" />
|
||||
<label class="btn primary kh-filebtn">
|
||||
<KhIcon Name="upload" /> @T["Treasury.Reconciliation.Import"]
|
||||
<InputFile OnChange="ImportAsync" accept=".xml,.txt,.csv,.cbi,.sta" disabled="@(_busy || _bankId is null)" />
|
||||
</label>
|
||||
<button type="button" class="btn" disabled="@(_busy || _bankId is null)" @onclick="RefreshAsync"><KhIcon Name="zap" /> @T["Treasury.Reconciliation.Auto"]</button>
|
||||
<button type="button" class="btn ok" disabled="@(_busy || _bankId is null)" @onclick="ConfirmAllAsync"><KhIcon Name="check" /> @T["Treasury.Reconciliation.ConfirmAll"]</button>
|
||||
<span class="grow"></span>
|
||||
<KhSelect TValue="string" Label="@T["Treasury.Fields.Status"]" Name="rshow" Options="Shows" Value="_show" ValueChanged="SetShowAsync" />
|
||||
</div>
|
||||
|
||||
<KhTabs Items="Tabs" Active="@_tab" ActiveChanged="t => _tab = t" Label="@T["Treasury.Reconciliation.Title"]" />
|
||||
|
||||
@if (_tab == "lines")
|
||||
{
|
||||
<KhPanel Tight="true">
|
||||
@if (_lines.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Reconciliation.None"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.Reconciliation.Lines"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Date"]</th>
|
||||
<th scope="col">@T["Treasury.Reconciliation.Description"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.In"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.Out"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
||||
<th scope="col">@T["Treasury.Reconciliation.Proposal"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.Confidence"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _lines)
|
||||
{
|
||||
var l = row.Line;
|
||||
<tr>
|
||||
<td>@T.Date(l.BookingDate)</td>
|
||||
<td>@l.Description <span class="muted sm">@row.PartyName</span></td>
|
||||
<td class="num">@(l.Amount > 0m ? T.Money(l.Amount) : null)</td>
|
||||
<td class="num">@(l.Amount < 0m ? T.Money(-l.Amount) : null)</td>
|
||||
<td><KhBadge Tone="TreasuryScreens.ToneOf(l.Status)">@T[TreasuryScreens.EnumKey(l.Status)]</KhBadge></td>
|
||||
<td>
|
||||
@if (l.MatchKind != StatementMatchKind.None)
|
||||
{
|
||||
<span class="muted sm">@T[TreasuryScreens.EnumKey(l.MatchKind)] · </span>
|
||||
}
|
||||
@l.Proposal
|
||||
@if (l.GlEntryId is { } entry)
|
||||
{
|
||||
<a class="sm" href="@LedgerScreens.EntryUrl(entry)"> @T["Treasury.Payments.Entry"]</a>
|
||||
}
|
||||
</td>
|
||||
<td class="num">@(l.Confidence > 0 ? l.Confidence + "%" : "—")</td>
|
||||
<td class="num kh-nowrap">
|
||||
@if (l.Status == StatementLineStatus.Suggested)
|
||||
{
|
||||
<KhIconButton Icon="check" Text="@T["Treasury.Reconciliation.Confirm"]" Primary="true" Disabled="_busy" OnClick="() => ConfirmAsync(l)" />
|
||||
}
|
||||
@if (l.Status is StatementLineStatus.ToMatch or StatementLineStatus.Suggested)
|
||||
{
|
||||
<KhIconButton Icon="list" Text="@T["Treasury.Reconciliation.MatchItems"]" Disabled="_busy" OnClick="() => OpenItemsAsync(row)" />
|
||||
<KhIconButton Icon="euro" Text="@T["Treasury.Reconciliation.MatchPayment"]" Disabled="_busy" OnClick="() => OpenPaymentsAsync(row)" />
|
||||
<KhIconButton Icon="book" Text="@T["Treasury.Reconciliation.Post"]" Disabled="_busy" OnClick="() => OpenPostAsync(row)" />
|
||||
<KhIconButton Icon="slash" Text="@T["Treasury.Reconciliation.Ignore"]" Disabled="_busy" OnClick="() => IgnoreAsync(l)" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhIconButton Icon="undo" Text="@T["Treasury.Reconciliation.Reset"]" Disabled="_busy" OnClick="() => ResetAsync(l)" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
<div class="filters"><span class="muted sm">@T["Treasury.Reconciliation.Footer"]</span></div>
|
||||
</KhPanel>
|
||||
}
|
||||
else if (_tab == "rules")
|
||||
{
|
||||
<KhPanel Tight="true">
|
||||
<Actions>
|
||||
<button type="button" class="btn sm" @onclick="() => OpenRuleAsync(null)"><KhIcon Name="plus" /> @T["Treasury.Rules.New"]</button>
|
||||
</Actions>
|
||||
<ChildContent>
|
||||
@if (_rules.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Rules.None"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="grid" aria-label="@T["Treasury.Rules.Title"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Rules.Name"]</th>
|
||||
<th scope="col">@T["Treasury.Rules.Pattern"]</th>
|
||||
<th scope="col">@T["Treasury.Rules.Direction"]</th>
|
||||
<th scope="col">@T["Treasury.Rules.Account"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Rules.Uses"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var rule in _rules)
|
||||
{
|
||||
<tr class="@(rule.Disabled ? "muted" : null)">
|
||||
<td>@rule.Name</td>
|
||||
<td class="code">@rule.Pattern</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(rule.Direction)]</td>
|
||||
<td>@AccountText(rule.AccountId)</td>
|
||||
<td class="num">@rule.Uses</td>
|
||||
<td class="num">
|
||||
<KhIconButton Icon="edit" Text="@T["Treasury.Rules.Edit"]" OnClick="() => OpenRuleAsync(rule)" />
|
||||
<KhIconButton Icon="trash" Text="@T["Treasury.Rules.Delete"]" Danger="true" Disabled="_busy" OnClick="() => DeleteRuleAsync(rule)" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</ChildContent>
|
||||
</KhPanel>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhPanel Tight="true">
|
||||
@if (_statements.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Reconciliation.NoStatements"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="grid" aria-label="@T["Treasury.Reconciliation.Statements"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Reconciliation.File"]</th>
|
||||
<th scope="col">@T["Treasury.Reconciliation.Format"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.From"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.To"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.Movements"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Reconciliation.Closing"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var st in _statements)
|
||||
{
|
||||
<tr>
|
||||
<td>@st.FileName</td>
|
||||
<td>@T[TreasuryScreens.EnumKey(st.Format)]</td>
|
||||
<td>@T.Date(st.FromDate)</td>
|
||||
<td>@T.Date(st.ToDate)</td>
|
||||
<td class="num">@st.MovementCount</td>
|
||||
<td class="num">@(st.ClosingBalance is { } c ? T.Money(c) : "—")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</KhPanel>
|
||||
}
|
||||
|
||||
<KhDialog Open="_itemsFor is not null" Title="@T["Treasury.Reconciliation.MatchItems"]" Icon="list" Size="lg" OnClose="() => _itemsFor = null">
|
||||
<ChildContent>
|
||||
@if (_itemsFor is { } target)
|
||||
{
|
||||
<p>@target.Line.Description · <b>@T.Money(target.Line.Amount)</b></p>
|
||||
<input type="search" class="in kh-searchbox" placeholder="@T["Treasury.Schedule.Search"]" aria-label="@T["Treasury.Schedule.Search"]" @onchange="SearchItemsAsync" />
|
||||
<table class="grid" aria-label="@T["Treasury.Payment.Items"]">
|
||||
<tbody>
|
||||
@foreach (var row in _items)
|
||||
{
|
||||
<tr class="@(_chosen.Contains(row.Item.Id) ? "sel" : null)">
|
||||
<td class="chkcol"><input type="checkbox" aria-label="@(T["Treasury.Select"] + " " + row.Item.DocumentNumber)" checked="@_chosen.Contains(row.Item.Id)" @onchange="e => ToggleItem(row.Item.Id, e.Value is true)" /></td>
|
||||
<td>@row.PartyName</td>
|
||||
<td class="code">@row.Item.DocumentNumber</td>
|
||||
<td>@T.Date(row.Item.DueDate)</td>
|
||||
<td class="num">@T.Money(row.Item.Residual)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="muted sm">@T.Format("Treasury.Reconciliation.Chosen", T.Money(_items.Where(r => _chosen.Contains(r.Item.Id)).Sum(r => r.Item.Residual)))</p>
|
||||
}
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _itemsFor = null">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _chosen.Count == 0)" @onclick="MatchItemsAsync"><KhIcon Name="check" /> @T["Treasury.Reconciliation.Match"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
|
||||
<KhDialog Open="_paymentsFor is not null" Title="@T["Treasury.Reconciliation.MatchPayment"]" Icon="euro" OnClose="() => _paymentsFor = null">
|
||||
<ChildContent>
|
||||
@if (_paymentsFor is { } target)
|
||||
{
|
||||
<p>@target.Line.Description · <b>@T.Money(target.Line.Amount)</b></p>
|
||||
@if (_payments.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Payments.None"]</p>
|
||||
}
|
||||
<table class="grid" aria-label="@T["Treasury.Reconciliation.MatchPayment"]">
|
||||
<tbody>
|
||||
@foreach (var p in _payments)
|
||||
{
|
||||
<tr>
|
||||
<td>@T.Date(p.Payment.PaymentDate)</td>
|
||||
<td>@p.PartyName</td>
|
||||
<td>@p.Payment.Reference</td>
|
||||
<td class="num">@T.Money(p.Payment.Amount + p.Payment.Fees)</td>
|
||||
<td class="num"><button type="button" class="btn sm" disabled="@_busy" @onclick="() => MatchPaymentAsync(p.Payment.Id)">@T["Treasury.Reconciliation.Match"]</button></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _paymentsFor = null">@T["Common.Close"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
|
||||
<KhDialog Open="_postFor is not null" Title="@T["Treasury.Reconciliation.Post"]" Icon="book" OnClose="() => _postFor = null">
|
||||
<ChildContent>
|
||||
@if (_postFor is { } target)
|
||||
{
|
||||
<p>@target.Line.Description · <b>@T.Money(target.Line.Amount)</b></p>
|
||||
<div class="form plain">
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Rules.Account"]" Name="paccount" Options="Accounts" Empty="—" @bind-Value="_postAccount" Span="12" Required="true" />
|
||||
<KhTextBox Label="@T["Treasury.Reconciliation.EntryDescription"]" Name="pdesc" @bind-Value="_postDescription" MaxLength="200" Span="12" />
|
||||
<KhTextBox Label="@T["Treasury.Reconciliation.SaveRule"]" Name="prule" @bind-Value="_postRule" MaxLength="60" Hint="@T["Treasury.Reconciliation.SaveRuleHint"]" Span="12" />
|
||||
</div>
|
||||
}
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _postFor = null">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _postAccount is null)" @onclick="PostAsync"><KhIcon Name="check" /> @T["Treasury.Reconciliation.Post"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
|
||||
<KhDialog Open="_ruleOpen" Title="@T["Treasury.Rules.Edit"]" Icon="zap" OnClose="() => _ruleOpen = false">
|
||||
<ChildContent>
|
||||
<div class="form plain">
|
||||
<KhTextBox Label="@T["Treasury.Rules.Name"]" Name="rname" @bind-Value="_ruleName" MaxLength="60" Span="12" Required="true" />
|
||||
<KhTextBox Label="@T["Treasury.Rules.Pattern"]" Name="rpattern" @bind-Value="_rulePattern" MaxLength="100" Mono="true" Hint="@T["Treasury.Rules.PatternHint"]" Span="8" Required="true" />
|
||||
<KhSelect TValue="BankRuleDirection" Label="@T["Treasury.Rules.Direction"]" Name="rdir" Options="Directions" @bind-Value="_ruleDirection" Span="4" />
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Rules.Account"]" Name="racc" Options="Accounts" Empty="—" @bind-Value="_ruleAccount" Span="12" Required="true" />
|
||||
<KhTextBox Label="@T["Treasury.Reconciliation.EntryDescription"]" Name="rdesc" @bind-Value="_ruleDescription" MaxLength="200" Span="12" />
|
||||
<KhCheck Label="@T["Treasury.Rules.Disabled"]" Name="rdis" @bind-Value="_ruleDisabled" Span="12" />
|
||||
</div>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _ruleOpen = false">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _ruleAccount is null)" @onclick="SaveRuleAsync"><KhIcon Name="check" /> @T["Common.Save"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private string _tab = "lines";
|
||||
private string _show = "open";
|
||||
private long? _bankId;
|
||||
private TreasuryChoices? _choices;
|
||||
private BankPosition? _position;
|
||||
private IReadOnlyList<StatementLineRow> _lines = [];
|
||||
private IReadOnlyList<BankStatement> _statements = [];
|
||||
private IReadOnlyList<BankMatchRule> _rules = [];
|
||||
private IReadOnlyList<GlAccount> _accounts = [];
|
||||
private bool _busy;
|
||||
|
||||
private StatementLineRow? _itemsFor;
|
||||
private IReadOnlyList<ScheduleRow> _items = [];
|
||||
private readonly HashSet<long> _chosen = [];
|
||||
private StatementLineRow? _paymentsFor;
|
||||
private IReadOnlyList<PaymentRow> _payments = [];
|
||||
private StatementLineRow? _postFor;
|
||||
private long? _postAccount;
|
||||
private string? _postDescription;
|
||||
private string? _postRule;
|
||||
|
||||
private bool _ruleOpen;
|
||||
private long? _ruleId;
|
||||
private string? _ruleName;
|
||||
private string? _rulePattern;
|
||||
private BankRuleDirection _ruleDirection;
|
||||
private long? _ruleAccount;
|
||||
private string? _ruleDescription;
|
||||
private bool _ruleDisabled;
|
||||
|
||||
private IReadOnlyList<KhOption<long?>> Banks => TreasuryScreens.BankChoices(_choices?.Banks ?? []);
|
||||
|
||||
private IReadOnlyList<KhOption<string>> Shows =>
|
||||
[
|
||||
new("open", T["Treasury.Reconciliation.ShowOpen"]),
|
||||
new("all", T["Treasury.All"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhOption<BankRuleDirection>> Directions => TreasuryScreens.Choices<BankRuleDirection>(T);
|
||||
|
||||
private IReadOnlyList<KhOption<long?>> Accounts => [.. _accounts.Where(a => a.Postable && !a.Disabled).Select(a => new KhOption<long?>(a.Id, a.Code + " " + a.Description))];
|
||||
|
||||
private IReadOnlyList<KhTabItem> Tabs =>
|
||||
[
|
||||
new("lines", "list", T["Treasury.Reconciliation.Lines"], _position?.ToMatch),
|
||||
new("rules", "zap", T["Treasury.Rules.Title"], _rules.Count),
|
||||
new("statements", "file", T["Treasury.Reconciliation.Statements"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhStat> Stats
|
||||
{
|
||||
get
|
||||
{
|
||||
var bank = _choices?.Banks.FirstOrDefault(b => b.Id == _bankId);
|
||||
var p = _position;
|
||||
var difference = p?.BankBalance is { } balance ? balance - p.BookBalance : (decimal?)null;
|
||||
return
|
||||
[
|
||||
new(T["Treasury.Reconciliation.Account"], bank is null ? "—" : bank.BankName ?? bank.Description),
|
||||
new(T["Treasury.Reconciliation.BankBalance"], p?.BankBalance is { } b ? T.Money(b) + (p.BankBalanceDate is { } d ? " · " + T.Date(d) : null) : "—"),
|
||||
new(T["Treasury.Reconciliation.BookBalance"], p is null ? "—" : T.Money(p.BookBalance)),
|
||||
new(T["Treasury.Reconciliation.Difference"], difference is { } diff ? T.Money(diff) : "—", difference is { } x && x != 0m ? KhTone.Warning : KhTone.Ok),
|
||||
new(T["Treasury.Reconciliation.ToMatch"], p is null ? "—" : T.Format("Treasury.Reconciliation.ToMatchText", p.ToMatch, T.Money(p.ToMatchAmount))),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
if (!FinanceGuard.Allowed(Session, TreasuryPermissions.BankReconcile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_choices = await Schedule.ChoicesAsync(Session.Actor!, Session.Company!.Code);
|
||||
_bankId = _choices.Banks.FirstOrDefault(b => b.IsDefault)?.Id ?? _choices.Banks.FirstOrDefault()?.Id;
|
||||
if (Session.Permissions.Allows(LedgerPermissions.EntryRead))
|
||||
{
|
||||
_accounts = await Ledger.AccountsAsync(Session.Actor!, Session.Company.Code);
|
||||
}
|
||||
|
||||
_rules = await Reconciliation.RulesAsync(Session.Actor!, Session.Company.Code);
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _bankId is not { } bank)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lines = await Reconciliation.LinesAsync(actor, company, bank, _show == "open");
|
||||
_position = await Reconciliation.PositionAsync(actor, company, bank);
|
||||
_statements = await Reconciliation.StatementsAsync(actor, company, bank);
|
||||
}
|
||||
|
||||
private string AccountText(long id) => _accounts.FirstOrDefault(a => a.Id == id) is { } a ? a.Code + " " + a.Description : id.ToString(T.Culture);
|
||||
|
||||
private async Task SetBankAsync(long? bank)
|
||||
{
|
||||
_bankId = bank;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task SetShowAsync(string show)
|
||||
{
|
||||
_show = show;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task ImportAsync(InputFileChangeEventArgs e) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_bankId is not { } bank)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var buffer = new MemoryStream();
|
||||
await using (var stream = e.File.OpenReadStream(10 * 1024 * 1024))
|
||||
{
|
||||
await stream.CopyToAsync(buffer);
|
||||
}
|
||||
|
||||
var result = await Reconciliation.ImportAsync(actor, company, bank, e.File.Name, buffer.ToArray());
|
||||
Toasts.Show(ToastKind.Success, T.Format("Treasury.Reconciliation.Imported", result.Added, result.Duplicates, result.Suggested), null);
|
||||
await LoadAsync();
|
||||
});
|
||||
|
||||
private async Task RefreshAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_bankId is { } bank)
|
||||
{
|
||||
var found = await Reconciliation.RefreshAsync(actor, company, bank);
|
||||
Toasts.Show(ToastKind.Info, T.Format("Treasury.Reconciliation.Refreshed", found), null);
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private async Task ConfirmAllAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_bankId is { } bank)
|
||||
{
|
||||
var done = await Reconciliation.ConfirmAllAsync(actor, company, bank);
|
||||
Toasts.Show(ToastKind.Success, T.Format("Treasury.Reconciliation.Confirmed", done), null);
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private async Task ConfirmAsync(BankStatementLine line) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Reconciliation.ConfirmAsync(actor, company, line.Id);
|
||||
await LoadAsync();
|
||||
});
|
||||
|
||||
private async Task IgnoreAsync(BankStatementLine line) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Reconciliation.IgnoreAsync(actor, company, line.Id);
|
||||
await LoadAsync();
|
||||
});
|
||||
|
||||
private async Task ResetAsync(BankStatementLine line) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Reconciliation.ResetAsync(actor, company, line.Id);
|
||||
await LoadAsync();
|
||||
});
|
||||
|
||||
private async Task OpenItemsAsync(StatementLineRow row)
|
||||
{
|
||||
_itemsFor = row;
|
||||
_chosen.Clear();
|
||||
await LoadItemsAsync(row.PartyName);
|
||||
}
|
||||
|
||||
private async Task LoadItemsAsync(string? search)
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _itemsFor is not { } target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var direction = target.Line.Amount > 0m ? OpenItemDirection.Receivable : OpenItemDirection.Payable;
|
||||
_items = [.. (await Schedule.ItemsAsync(actor, company, new ScheduleFilter(direction, ScheduleView.Open, Search: string.IsNullOrWhiteSpace(search) ? null : search))).Rows
|
||||
.Where(r => r.Item.Status != OpenItemStatus.InRemittance).Take(50)];
|
||||
}
|
||||
|
||||
private async Task SearchItemsAsync(ChangeEventArgs e) => await LoadItemsAsync(e.Value?.ToString());
|
||||
|
||||
private void ToggleItem(long id, bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_chosen.Add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_chosen.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MatchItemsAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_itemsFor is { } target)
|
||||
{
|
||||
await Reconciliation.MatchItemsAsync(actor, company, target.Line.Id, [.. _items.Where(r => _chosen.Contains(r.Item.Id)).OrderBy(r => r.Item.DueDate).Select(r => r.Item.Id)]);
|
||||
_itemsFor = null;
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private async Task OpenPaymentsAsync(StatementLineRow row)
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_paymentsFor = row;
|
||||
var day = row.Line.BookingDate;
|
||||
var direction = row.Line.Amount > 0m ? PaymentDirection.Receipt : PaymentDirection.Disbursement;
|
||||
_payments = [.. (await Payments.ListAsync(actor, company, direction, day.AddDays(-45), day.AddDays(15))).Where(p => p.Payment.StatementLineId is null)];
|
||||
}
|
||||
|
||||
private async Task MatchPaymentAsync(long paymentId) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_paymentsFor is { } target)
|
||||
{
|
||||
await Reconciliation.MatchPaymentAsync(actor, company, target.Line.Id, paymentId);
|
||||
_paymentsFor = null;
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private Task OpenPostAsync(StatementLineRow row)
|
||||
{
|
||||
_postFor = row;
|
||||
_postAccount = null;
|
||||
_postDescription = row.Line.Description;
|
||||
_postRule = null;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task PostAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_postFor is { } target && _postAccount is { } account)
|
||||
{
|
||||
await Reconciliation.PostAsync(actor, company, target.Line.Id, account, _postDescription, string.IsNullOrWhiteSpace(_postRule) ? null : _postRule.Trim());
|
||||
_postFor = null;
|
||||
_rules = await Reconciliation.RulesAsync(actor, company);
|
||||
await LoadAsync();
|
||||
}
|
||||
});
|
||||
|
||||
private Task OpenRuleAsync(BankMatchRule? rule)
|
||||
{
|
||||
_ruleId = rule?.Id;
|
||||
_ruleName = rule?.Name;
|
||||
_rulePattern = rule?.Pattern;
|
||||
_ruleDirection = rule?.Direction ?? BankRuleDirection.Out;
|
||||
_ruleAccount = rule?.AccountId;
|
||||
_ruleDescription = rule?.EntryDescription;
|
||||
_ruleDisabled = rule?.Disabled ?? false;
|
||||
_ruleOpen = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task SaveRuleAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_ruleAccount is { } account)
|
||||
{
|
||||
await Reconciliation.SaveRuleAsync(actor, company, new BankRuleInput(_ruleId, _ruleName ?? string.Empty, _rulePattern ?? string.Empty, _ruleDirection, account, _ruleDescription, _ruleDisabled));
|
||||
_ruleOpen = false;
|
||||
_rules = await Reconciliation.RulesAsync(actor, company);
|
||||
}
|
||||
});
|
||||
|
||||
private async Task DeleteRuleAsync(BankMatchRule rule) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Reconciliation.DeleteRuleAsync(actor, company, rule.Id);
|
||||
_rules = await Reconciliation.RulesAsync(actor, company);
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
@page "/scadenzario/distinte"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Application.Treasury
|
||||
@using Khaemhat.Core.Treasury
|
||||
@using Khaemhat.Web.Ledger
|
||||
@using Khaemhat.Web.Treasury
|
||||
@inject ShellSession Session
|
||||
@inject RemittanceService Remittances
|
||||
@inject ScheduleService Schedule
|
||||
@inject ToastService Toasts
|
||||
@inject DialogService Dialogs
|
||||
@inject IJSRuntime JS
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* The remittances (SPEC §11.8, mockup 055): RiBa in the CBI file, SEPA direct debits (pain.008) and SEPA credit
|
||||
transfers to the suppliers (pain.001). A new remittance gathers the items due by a date with the method of its kind,
|
||||
checks the bank coordinates and the mandates; then the file, the presentation with its entry, the credit of the
|
||||
bank and the effects that come back unpaid, which reopen the item with the fees. *@
|
||||
<KhPageTitle Text="@T["Treasury.Remittances.Title"]" Icon="layers" />
|
||||
|
||||
<FinanceGuard Permission="@TreasuryPermissions.ScheduleRead">
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TreasuryScreens.BasePath">@T["Shell.Menu.Finance"]</a> / @T["Treasury.Remittances.Title"]</div>
|
||||
<h1>@T["Treasury.Remittances.Heading"]</h1>
|
||||
<div class="sub">@T["Treasury.Remittances.Hint"]</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KhTabs Items="Tabs" Active="@_tab" ActiveChanged="SetTabAsync" Label="@T["Treasury.Remittances.Title"]" />
|
||||
|
||||
@if (_tab == "new")
|
||||
{
|
||||
<div class="kh-remit">
|
||||
<KhPanel Title="@T["Treasury.Remittances.New"]" Icon="plus">
|
||||
<div class="form plain">
|
||||
<KhSelect TValue="RemittanceKind" Label="@T["Treasury.Remittances.Kind"]" Name="kind" Options="Kinds" Value="_kind" ValueChanged="SetKindAsync" Span="12" />
|
||||
<KhSelect TValue="long?" Label="@T["Treasury.Remittances.Bank"]" Name="bank" Options="Banks" @bind-Value="_bankId" Span="12" />
|
||||
<KhDateBox Label="@T["Treasury.Remittances.PresentationDate"]" Name="presented" @bind-Value="_presentation" Span="6" Required="true" />
|
||||
<KhDateBox Label="@T["Treasury.Remittances.DueUntil"]" Name="dueuntil" Value="_dueUntil" ValueChanged="SetDueUntilAsync" Span="6" Required="true" />
|
||||
<KhTextBox Label="@T["Treasury.Fields.Total"]" Name="rtotal" Value="@T.Money(SelectedTotal)" ReadOnly="true" Span="6" />
|
||||
<KhTextBox Label="@T["Treasury.Remittances.Effects"]" Name="rcount" Value="@_chosen.Count.ToString(T.Culture)" ReadOnly="true" Span="6" />
|
||||
@if (_kind != RemittanceKind.SepaCreditTransfer)
|
||||
{
|
||||
<KhCheck Label="@T["Treasury.Remittances.Advance"]" Name="advance" @bind-Value="_advance" Span="12" />
|
||||
}
|
||||
<KhTextBox Label="@T["Treasury.Fields.Notes"]" Name="rnotes" @bind-Value="_notes" MaxLength="200" Span="12" />
|
||||
</div>
|
||||
<KhVSteps Items="Steps" Current="@(_chosen.Count > 0 ? 1 : 0)" Label="@T["Treasury.Remittances.New"]" />
|
||||
@if (CanWrite)
|
||||
{
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _chosen.Count == 0 || _bankId is null || _presentation is null)" @onclick="CreateAsync">
|
||||
<KhIcon Name="check" /> @T["Treasury.Remittances.Create"]
|
||||
</button>
|
||||
}
|
||||
</KhPanel>
|
||||
<KhPanel Tight="true">
|
||||
@if (_candidates.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Remittances.NoCandidates"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="gridwrap kh-scrollx">
|
||||
<table class="grid" aria-label="@T["Treasury.Remittances.Candidates"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="chkcol"><span class="sr-only">@T["Treasury.Select"]</span></th>
|
||||
<th scope="col">@T[_kind == RemittanceKind.SepaCreditTransfer ? "Treasury.Fields.Supplier" : "Treasury.Fields.Customer"]</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.Amount"]</th>
|
||||
<th scope="col">@T["Treasury.Remittances.PartyBank"]</th>
|
||||
<th scope="col">@T["Treasury.Remittances.Check"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var c in _candidates)
|
||||
{
|
||||
var item = c.Row.Item;
|
||||
var late = item.DueDate < Today;
|
||||
<tr class="@(!c.Ready ? "warn" : _chosen.Contains(item.Id) ? "sel" : null)">
|
||||
<td class="chkcol">
|
||||
<input type="checkbox" aria-label="@(T["Treasury.Select"] + " " + item.DocumentNumber)" disabled="@(!c.Ready)" checked="@_chosen.Contains(item.Id)"
|
||||
@onchange="e => Toggle(item.Id, e.Value is true)" />
|
||||
</td>
|
||||
<td><b>@c.Row.PartyName</b></td>
|
||||
<td class="code">@item.DocumentNumber</td>
|
||||
<td>@item.Installment</td>
|
||||
<td>@T.Date(item.DueDate)</td>
|
||||
<td class="num">@T.Money(item.Residual)</td>
|
||||
<td>@TreasuryScreens.ShortIban(c.Iban) @(c.Mandate is { } m ? "· " + m.Reference : null)</td>
|
||||
<td>
|
||||
@if (!c.Ready)
|
||||
{
|
||||
<KhBadge Tone="KhTone.Error">@string.Join(", ", c.Problems.Select(p => T[p]))</KhBadge>
|
||||
}
|
||||
else if (late)
|
||||
{
|
||||
<KhBadge Tone="KhTone.Warning">@T["Treasury.Remittances.Late"]</KhBadge>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhBadge Tone="KhTone.Ok">@T["Treasury.Remittances.Ok"]</KhBadge>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
<div class="filters"><span class="muted sm">@T["Treasury.Remittances.Footer"]</span></div>
|
||||
</KhPanel>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<KhPanel Tight="true">
|
||||
<div class="filters kh-ledger-filters">
|
||||
<KhSelect TValue="int" Label="@T["Treasury.Fields.Year"]" Name="ryear" Options="Years" Value="_year" ValueChanged="SetYearAsync" />
|
||||
</div>
|
||||
@if (_list.Count == 0)
|
||||
{
|
||||
<p class="kh-wempty">@T["Treasury.Remittances.None"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="grid" aria-label="@T["Treasury.Remittances.History"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Number"]</th>
|
||||
<th scope="col">@T["Treasury.Remittances.Kind"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Bank"]</th>
|
||||
<th scope="col">@T["Treasury.Remittances.PresentationDate"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Remittances.Effects"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Total"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _list)
|
||||
{
|
||||
var r = row.Remittance;
|
||||
<tr class="@(_open?.Row.Remittance.Id == r.Id ? "sel" : null) clickable" @onclick="() => OpenAsync(r.Id)">
|
||||
<td class="code"><a href="javascript:void(0)">@TreasuryScreens.Number(r)</a></td>
|
||||
<td>@T[TreasuryScreens.EnumKey(r.Kind)] @(r.Advance ? "· " + T["Treasury.Remittances.AdvanceShort"] : null)</td>
|
||||
<td>@row.Bank</td>
|
||||
<td>@T.Date(r.PresentationDate)</td>
|
||||
<td class="num">@r.ItemCount</td>
|
||||
<td class="num">@T.Money(r.TotalAmount)</td>
|
||||
<td><KhBadge Tone="TreasuryScreens.ToneOf(r.Status)">@T[TreasuryScreens.EnumKey(r.Status)]</KhBadge></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</KhPanel>
|
||||
|
||||
@if (_open is { } open)
|
||||
{
|
||||
var rem = open.Row.Remittance;
|
||||
<KhPanel Title="@T.Format("Treasury.Remittances.Detail", T[TreasuryScreens.EnumKey(rem.Kind)], TreasuryScreens.Number(rem))" Icon="layers" Tight="true">
|
||||
<Actions>
|
||||
@if (CanWrite)
|
||||
{
|
||||
@if (rem.Status is RemittanceStatus.Draft or RemittanceStatus.Generated)
|
||||
{
|
||||
<button type="button" class="btn sm primary" disabled="@_busy" @onclick="FileAsync"><KhIcon Name="download" /> @T[rem.Kind == RemittanceKind.Riba ? "Treasury.Remittances.FileCbi" : "Treasury.Remittances.FileXml"]</button>
|
||||
<button type="button" class="btn sm" disabled="@(_busy || rem.Status != RemittanceStatus.Generated)" @onclick="PresentAsync"><KhIcon Name="send" /> @T["Treasury.Remittances.Present"]</button>
|
||||
<button type="button" class="btn sm" disabled="@_busy" @onclick="DeleteAsync"><KhIcon Name="trash" /> @T["Treasury.Remittances.Delete"]</button>
|
||||
}
|
||||
@if (rem.Status == RemittanceStatus.Presented)
|
||||
{
|
||||
<button type="button" class="btn sm primary" disabled="@_busy" @onclick="() => OpenCredit(rem)"><KhIcon Name="check" /> @T["Treasury.Remittances.Credit"]</button>
|
||||
}
|
||||
}
|
||||
</Actions>
|
||||
<ChildContent>
|
||||
<table class="grid" aria-label="@T["Treasury.Remittances.Lines"]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">@T["Treasury.Fields.Party"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Document"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.DueDate"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Iban"]</th>
|
||||
<th scope="col">@T["Treasury.Remittances.EndToEnd"]</th>
|
||||
<th scope="col" class="num">@T["Treasury.Fields.Amount"]</th>
|
||||
<th scope="col">@T["Treasury.Fields.Status"]</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var line in open.Lines)
|
||||
{
|
||||
var l = line.Line;
|
||||
<tr>
|
||||
<td>@line.PartyName</td>
|
||||
<td class="code">@line.Item?.DocumentNumber</td>
|
||||
<td>@T.Date(l.DueDate)</td>
|
||||
<td>@TreasuryScreens.ShortIban(l.Iban) @(line.Mandate is { } m ? "· " + m : null)</td>
|
||||
<td class="code">@l.EndToEndId</td>
|
||||
<td class="num">@T.Money(l.Amount)</td>
|
||||
<td>
|
||||
<KhBadge Tone="@(l.Status == RemittanceLineStatus.Unpaid ? KhTone.Error : l.Status == RemittanceLineStatus.Paid ? KhTone.Ok : KhTone.Neutral)">@T[TreasuryScreens.EnumKey(l.Status)]</KhBadge>
|
||||
@if (l.UnpaidOn is { } u)
|
||||
{
|
||||
<span class="muted sm"> @T.Date(u) · @T.Money(l.UnpaidFees)</span>
|
||||
}
|
||||
</td>
|
||||
<td class="num">
|
||||
@if (CanWrite && rem.Status is RemittanceStatus.Draft or RemittanceStatus.Generated)
|
||||
{
|
||||
<KhIconButton Icon="x" Text="@T["Treasury.Remittances.RemoveLine"]" Disabled="_busy" OnClick="() => RemoveLineAsync(l)" />
|
||||
}
|
||||
else if (CanWrite && rem.Kind != RemittanceKind.SepaCreditTransfer && rem.Status is RemittanceStatus.Presented or RemittanceStatus.Closed && l.Status != RemittanceLineStatus.Unpaid)
|
||||
{
|
||||
<button type="button" class="btn sm" disabled="@_busy" @onclick="() => OpenUnpaid(l)"><KhIcon Name="alert" /> @T["Treasury.Remittances.Unpaid"]</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="filters">
|
||||
<span class="muted sm">
|
||||
@(rem.FileName is { } file ? T.Format("Treasury.Remittances.FileName", file) : null)
|
||||
@(rem.CreditedOn is { } credited ? " · " + T.Format("Treasury.Remittances.CreditedOn", T.Date(credited)) : null)
|
||||
</span>
|
||||
@if (rem.GlEntryId is { } entry)
|
||||
{
|
||||
<a class="btn sm" href="@LedgerScreens.EntryUrl(entry)"><KhIcon Name="book" /> @T["Treasury.Remittances.Entry"]</a>
|
||||
}
|
||||
@if (rem.CreditEntryId is { } credit)
|
||||
{
|
||||
<a class="btn sm" href="@LedgerScreens.EntryUrl(credit)"><KhIcon Name="book" /> @T["Treasury.Remittances.CreditEntry"]</a>
|
||||
}
|
||||
</div>
|
||||
</ChildContent>
|
||||
</KhPanel>
|
||||
}
|
||||
}
|
||||
|
||||
<KhDialog Open="_creditOpen" Title="@T["Treasury.Remittances.Credit"]" Icon="check" OnClose="() => _creditOpen = false">
|
||||
<ChildContent>
|
||||
<p>@T["Treasury.Remittances.CreditText"]</p>
|
||||
<div class="form plain">
|
||||
<KhDateBox Label="@T["Treasury.Remittances.CreditedOnLabel"]" Name="credited" @bind-Value="_creditOn" Required="true" Span="6" />
|
||||
</div>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _creditOpen = false">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(_busy || _creditOn is null)" @onclick="CreditAsync"><KhIcon Name="check" /> @T["Treasury.Remittances.Credit"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
|
||||
<KhDialog Open="_unpaid is not null" Title="@T["Treasury.Remittances.Unpaid"]" Icon="alert" OnClose="() => _unpaid = null">
|
||||
<ChildContent>
|
||||
<p>@T["Treasury.Remittances.UnpaidText"]</p>
|
||||
<div class="form plain">
|
||||
<KhDateBox Label="@T["Treasury.Fields.Date"]" Name="unpaidon" @bind-Value="_unpaidOn" Required="true" Span="6" />
|
||||
<KhNumberBox Label="@T["Treasury.Fields.Fees"]" Name="unpaidfees" @bind-Value="_unpaidFees" Decimals="2" Min="0" Span="6" />
|
||||
</div>
|
||||
</ChildContent>
|
||||
<Footer>
|
||||
<button type="button" class="btn" @onclick="() => _unpaid = null">@T["Common.Cancel"]</button>
|
||||
<button type="button" class="btn primary danger" disabled="@(_busy || _unpaidOn is null)" @onclick="UnpaidAsync"><KhIcon Name="alert" /> @T["Treasury.Remittances.Unpaid"]</button>
|
||||
</Footer>
|
||||
</KhDialog>
|
||||
</FinanceGuard>
|
||||
|
||||
@code {
|
||||
private string _tab = "new";
|
||||
private RemittanceKind _kind = RemittanceKind.Riba;
|
||||
private long? _bankId;
|
||||
private DateOnly? _presentation;
|
||||
private DateOnly? _dueUntil;
|
||||
private bool _advance;
|
||||
private string? _notes;
|
||||
private IReadOnlyList<RemittanceCandidate> _candidates = [];
|
||||
private readonly HashSet<long> _chosen = [];
|
||||
private TreasuryChoices? _choices;
|
||||
private int _year;
|
||||
private IReadOnlyList<RemittanceRow> _list = [];
|
||||
private (RemittanceRow Row, IReadOnlyList<RemittanceLineRow> Lines)? _open;
|
||||
private bool _busy;
|
||||
private bool _creditOpen;
|
||||
private DateOnly? _creditOn;
|
||||
private RemittanceLine? _unpaid;
|
||||
private DateOnly? _unpaidOn;
|
||||
private decimal? _unpaidFees;
|
||||
|
||||
private DateOnly Today => DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||||
|
||||
private bool CanWrite => Session.Permissions.Allows(TreasuryPermissions.ScheduleWrite);
|
||||
|
||||
private decimal SelectedTotal => _candidates.Where(c => _chosen.Contains(c.Row.Item.Id)).Sum(c => c.Row.Item.Residual);
|
||||
|
||||
private IReadOnlyList<KhTabItem> Tabs =>
|
||||
[
|
||||
new("new", "plus", T["Treasury.Remittances.New"]),
|
||||
new("history", "list", T["Treasury.Remittances.History"]),
|
||||
];
|
||||
|
||||
private IReadOnlyList<KhOption<RemittanceKind>> Kinds => TreasuryScreens.Choices<RemittanceKind>(T);
|
||||
|
||||
private IReadOnlyList<KhOption<long?>> Banks => TreasuryScreens.BankChoices(_choices?.Banks ?? []);
|
||||
|
||||
private IReadOnlyList<KhOption<int>> Years => [.. Enumerable.Range(Today.Year - 3, 5).Select(y => new KhOption<int>(y, y.ToString(System.Globalization.CultureInfo.InvariantCulture)))];
|
||||
|
||||
private IReadOnlyList<KhStep> Steps =>
|
||||
[
|
||||
new(T["Treasury.Remittances.Step.Select"], T.Format("Treasury.Remittances.Step.SelectText", _chosen.Count, _candidates.Count(c => !c.Ready))),
|
||||
new(T["Treasury.Remittances.Step.Check"], T["Treasury.Remittances.Step.CheckText"]),
|
||||
new(T["Treasury.Remittances.Step.File"], T[_kind == RemittanceKind.Riba ? "Treasury.Remittances.Step.FileCbi" : "Treasury.Remittances.Step.FileXml"]),
|
||||
new(T["Treasury.Remittances.Step.Post"], T["Treasury.Remittances.Step.PostText"]),
|
||||
new(T["Treasury.Remittances.Step.Credit"], T["Treasury.Remittances.Step.CreditText"]),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
_year = Today.Year;
|
||||
_presentation = Today;
|
||||
_dueUntil = Today.AddDays(30);
|
||||
if (FinanceGuard.Allowed(Session, TreasuryPermissions.ScheduleRead))
|
||||
{
|
||||
_choices = await Schedule.ChoicesAsync(Session.Actor!, Session.Company!.Code);
|
||||
_bankId = _choices.Banks.FirstOrDefault(b => b.IsDefault)?.Id ?? _choices.Banks.FirstOrDefault()?.Id;
|
||||
await LoadCandidatesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadCandidatesAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || _dueUntil is not { } until)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_candidates = await Remittances.CandidatesAsync(actor, company, _kind, until);
|
||||
_chosen.Clear();
|
||||
_chosen.UnionWith(_candidates.Where(c => c.Ready && c.Row.Item.DueDate >= Today).Select(c => c.Row.Item.Id));
|
||||
}
|
||||
|
||||
private async Task LoadListAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_list = await Remittances.ListAsync(actor, company, _year);
|
||||
}
|
||||
|
||||
private async Task SetTabAsync(string tab)
|
||||
{
|
||||
_tab = tab;
|
||||
if (tab == "history")
|
||||
{
|
||||
await LoadListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await LoadCandidatesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetKindAsync(RemittanceKind kind)
|
||||
{
|
||||
_kind = kind;
|
||||
await LoadCandidatesAsync();
|
||||
}
|
||||
|
||||
private async Task SetDueUntilAsync(DateOnly? date)
|
||||
{
|
||||
_dueUntil = date;
|
||||
await LoadCandidatesAsync();
|
||||
}
|
||||
|
||||
private async Task SetYearAsync(int year)
|
||||
{
|
||||
_year = year;
|
||||
_open = null;
|
||||
await LoadListAsync();
|
||||
}
|
||||
|
||||
private void Toggle(long id, bool on)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
_chosen.Add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_chosen.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenAsync(long id) => await RunAsync(async (actor, company) => _open = await Remittances.GetAsync(actor, company, id));
|
||||
|
||||
private async Task ReloadOpenAsync(long id)
|
||||
{
|
||||
await LoadListAsync();
|
||||
await OpenAsync(id);
|
||||
}
|
||||
|
||||
private async Task CreateAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_bankId is { } bank && _presentation is { } presented && _dueUntil is { } until)
|
||||
{
|
||||
var remittance = await Remittances.CreateAsync(actor, company, new RemittanceInput(_kind, bank, presented, until, _advance, _notes, [.. _chosen]));
|
||||
Toasts.Show(ToastKind.Success, T["Treasury.Remittances.Created"], TreasuryScreens.Number(remittance));
|
||||
_tab = "history";
|
||||
_year = remittance.Year;
|
||||
await ReloadOpenAsync(remittance.Id);
|
||||
}
|
||||
});
|
||||
|
||||
private async Task FileAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_open is { } open)
|
||||
{
|
||||
await LedgerScreens.DownloadAsync(JS, await Remittances.FileAsync(actor, company, open.Row.Remittance.Id));
|
||||
await ReloadOpenAsync(open.Row.Remittance.Id);
|
||||
}
|
||||
});
|
||||
|
||||
private async Task PresentAsync()
|
||||
{
|
||||
if (_open is not { } open
|
||||
|| !await Dialogs.ConfirmAsync(new ConfirmRequest(T["Treasury.Remittances.Present"], T["Treasury.Remittances.PresentText"], T["Treasury.Remittances.Present"], T["Common.Cancel"])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Remittances.PresentAsync(actor, company, open.Row.Remittance.Id);
|
||||
Toasts.Show(ToastKind.Success, T["Treasury.Remittances.Presented"], null);
|
||||
await ReloadOpenAsync(open.Row.Remittance.Id);
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenCredit(Remittance remittance)
|
||||
{
|
||||
_creditOn = remittance.DueUntil <= Today ? remittance.DueUntil : Today;
|
||||
_creditOpen = true;
|
||||
}
|
||||
|
||||
private async Task CreditAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_open is { } open && _creditOn is { } date)
|
||||
{
|
||||
await Remittances.CreditAsync(actor, company, open.Row.Remittance.Id, date);
|
||||
_creditOpen = false;
|
||||
await ReloadOpenAsync(open.Row.Remittance.Id);
|
||||
}
|
||||
});
|
||||
|
||||
private void OpenUnpaid(RemittanceLine line)
|
||||
{
|
||||
_unpaid = line;
|
||||
_unpaidOn = Today;
|
||||
_unpaidFees = null;
|
||||
}
|
||||
|
||||
private async Task UnpaidAsync() => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_open is { } open && _unpaid is { } line && _unpaidOn is { } date)
|
||||
{
|
||||
await Remittances.UnpaidAsync(actor, company, line.Id, date, _unpaidFees ?? 0m);
|
||||
_unpaid = null;
|
||||
Toasts.Show(ToastKind.Warning, T["Treasury.Remittances.UnpaidDone"], null);
|
||||
await ReloadOpenAsync(open.Row.Remittance.Id);
|
||||
}
|
||||
});
|
||||
|
||||
private async Task RemoveLineAsync(RemittanceLine line) => await RunAsync(async (actor, company) =>
|
||||
{
|
||||
if (_open is { } open)
|
||||
{
|
||||
await Remittances.RemoveLineAsync(actor, company, line.Id);
|
||||
await ReloadOpenAsync(open.Row.Remittance.Id);
|
||||
}
|
||||
});
|
||||
|
||||
private async Task DeleteAsync()
|
||||
{
|
||||
if (_open is not { } open
|
||||
|| !await Dialogs.ConfirmAsync(new ConfirmRequest(T["Treasury.Remittances.Delete"], T["Treasury.Remittances.DeleteText"], T["Treasury.Remittances.Delete"], T["Common.Cancel"]) { Danger = true }))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunAsync(async (actor, company) =>
|
||||
{
|
||||
await Remittances.DeleteAsync(actor, company, open.Row.Remittance.Id);
|
||||
_open = null;
|
||||
await LoadListAsync();
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,6 +244,9 @@ internal static class KhaemhatServices
|
||||
services.AddSingleton<JobRunFeedSource>();
|
||||
services.AddSingleton<ITodoSource>(sp => sp.GetRequiredService<JobRunFeedSource>());
|
||||
services.AddSingleton<IDoneSource>(sp => sp.GetRequiredService<JobRunFeedSource>());
|
||||
services.AddSingleton<Khaemhat.Application.Treasury.TreasuryFeedSource>();
|
||||
services.AddSingleton<ITodoSource>(sp => sp.GetRequiredService<Khaemhat.Application.Treasury.TreasuryFeedSource>());
|
||||
services.AddSingleton<IDeadlineSource>(sp => sp.GetRequiredService<Khaemhat.Application.Treasury.TreasuryFeedSource>());
|
||||
services.AddSingleton<SystemStatusService>();
|
||||
services.AddSingleton<TodoAggregator>();
|
||||
services.AddSingleton<DoneAggregator>();
|
||||
|
||||
@@ -50,7 +50,8 @@
|
||||
},
|
||||
"Areas": {
|
||||
"System": "Sistema",
|
||||
"Notifications": "Avvisi"
|
||||
"Notifications": "Avvisi",
|
||||
"Treasury": "Tesoreria"
|
||||
},
|
||||
"Coming": {
|
||||
"Text": "Questo widget si riempie con i dati di {0}, in arrivo con la milestone {1}. Intanto puoi già metterlo dove ti serve.",
|
||||
@@ -71,7 +72,10 @@
|
||||
"TrialEnds": "Fine del periodo di prova",
|
||||
"JobRanOnce": "Attività programmata",
|
||||
"JobRanTimes": "Eseguita {0} volte oggi",
|
||||
"JobFailed": "Attività «{0}» non riuscita"
|
||||
"JobFailed": "Attività «{0}» non riuscita",
|
||||
"DueReceivable": "Incasso da {0}: {1}",
|
||||
"DuePayable": "Pagamento a {0}: {1}",
|
||||
"Overdue": "{0} partite di clienti scadute da incassare ({1})"
|
||||
},
|
||||
"Widgets": {
|
||||
"Kpi": {
|
||||
|
||||
@@ -413,7 +413,14 @@
|
||||
"StampDuty": "Bollo",
|
||||
"Rounding": "Arrotondamenti",
|
||||
"VatSettlement": "Erario c/IVA",
|
||||
"SplitPaymentVat": "IVA split payment"
|
||||
"SplitPaymentVat": "IVA split payment",
|
||||
"AllowanceIncome": "Abbuoni attivi",
|
||||
"BankCharges": "Spese bancarie",
|
||||
"BillsForCollection": "Effetti all'incasso",
|
||||
"BankAdvances": "Anticipi su effetti",
|
||||
"ExchangeGain": "Utili su cambi",
|
||||
"ExchangeLoss": "Perdite su cambi",
|
||||
"LateInterest": "Interessi di mora attivi"
|
||||
},
|
||||
"AccountSide": {
|
||||
"Debit": "Dare",
|
||||
|
||||
@@ -99,10 +99,14 @@
|
||||
},
|
||||
"Finance": {
|
||||
"_": "Scadenzario",
|
||||
"OpenItems": "Scadenze",
|
||||
"Remittances": "Distinte RiBa e SEPA",
|
||||
"OpenItems": "Partite aperte",
|
||||
"Receipts": "Incassi",
|
||||
"Payments": "Pagamenti",
|
||||
"Dunning": "Solleciti",
|
||||
"Reconciliation": "Riconciliazione bancaria"
|
||||
"Remittances": "Distinte RiBa/SDD",
|
||||
"Mandates": "Mandati SDD",
|
||||
"Reconciliation": "Riconciliazione bancaria",
|
||||
"CashFlow": "Flusso di cassa"
|
||||
},
|
||||
"EInvoicing": {
|
||||
"_": "Fatt. elettronica",
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
{
|
||||
"Treasury": {
|
||||
"NoCompany": "Scegli un'azienda per lavorare sullo scadenzario",
|
||||
"NoModule": {
|
||||
"Title": "Tesoreria non attiva",
|
||||
"Lead": "La licenza di questa azienda non comprende il modulo Scadenzario e tesoreria (FIN). Attivalo da Amministrazione, Licenze."
|
||||
},
|
||||
"NotDone": "Operazione non eseguita",
|
||||
"Saved": "Salvato",
|
||||
"All": "Tutti",
|
||||
"Select": "Seleziona",
|
||||
"Export": "Esporta",
|
||||
"Fields": {
|
||||
"Allowance": "Abbuono",
|
||||
"Amount": "Importo",
|
||||
"Bank": "Banca",
|
||||
"Customer": "Cliente",
|
||||
"Supplier": "Fornitore",
|
||||
"Party": "Cliente o fornitore",
|
||||
"Date": "Data",
|
||||
"Days": "Gg",
|
||||
"Document": "Documento",
|
||||
"DueDate": "Scadenza",
|
||||
"Fees": "Spese",
|
||||
"From": "Dal",
|
||||
"To": "Al",
|
||||
"Iban": "IBAN",
|
||||
"Installment": "Rata",
|
||||
"Method": "Metodo",
|
||||
"Notes": "Note",
|
||||
"Number": "Numero",
|
||||
"Reference": "Riferimento",
|
||||
"Residual": "Residuo",
|
||||
"Status": "Stato",
|
||||
"Total": "Totale",
|
||||
"Year": "Anno",
|
||||
"Bic": "BIC"
|
||||
},
|
||||
"Aging": {
|
||||
"NotDue": "Non scaduto",
|
||||
"Days1To30": "Scaduto 1-30 gg",
|
||||
"Days31To60": "31-60 gg",
|
||||
"Days61To90": "61-90 gg",
|
||||
"Over90": "Oltre 90 gg",
|
||||
"Count": "{0} partite"
|
||||
},
|
||||
"Schedule": {
|
||||
"Title": "Partite aperte",
|
||||
"Heading": "Partite aperte",
|
||||
"Hint": "Scadenze di clienti e fornitori con anzianità dello scaduto. Seleziona le partite di una controparte per registrare l'incasso o il pagamento.",
|
||||
"OpenTotal": "Aperto {0}",
|
||||
"OverdueTotal": "Scaduto {0}",
|
||||
"Search": "Cerca controparte o documento",
|
||||
"View": "Mostra",
|
||||
"Direction": "Clienti o fornitori",
|
||||
"Customers": "Clienti",
|
||||
"Suppliers": "Fornitori",
|
||||
"SelectHint": "Le partite scelte devono essere della stessa controparte.",
|
||||
"None": "Nessuna partita con questi filtri.",
|
||||
"Overdue": "Scaduta",
|
||||
"DueSoon": "In scadenza",
|
||||
"Disputed": "Contestata",
|
||||
"Edit": "Modifica partita",
|
||||
"EditText": "Partita {0} rata {1} di {2}: scadenza, metodo, banca e contestazione.",
|
||||
"Footer": "{0} partite · {1} selezionate · residuo selezionato {2}"
|
||||
},
|
||||
"Statement": {
|
||||
"Open": "Estratto conto",
|
||||
"Title": "Estratto conto",
|
||||
"At": "situazione al {0}",
|
||||
"Interest": "Interessi di mora",
|
||||
"Payments": "Incassi e pagamenti registrati"
|
||||
},
|
||||
"Payment": {
|
||||
"NewReceipt": "Registra incasso",
|
||||
"NewPayment": "Registra pagamento",
|
||||
"Cash": "Cassa",
|
||||
"Items": "Partite da chiudere",
|
||||
"Collected": "Incassato",
|
||||
"Paid": "Pagato",
|
||||
"ResidualAfter": "Residuo dopo",
|
||||
"Save": "Registra e chiudi partite",
|
||||
"EntryReceipt": "Verrà generata la prima nota Banca (D) / Clienti (A) per {0}, con abbuoni per {1}.",
|
||||
"EntryPayment": "Verrà generata la prima nota Fornitori (D) / Banca (A) per {0}, con abbuoni per {1}.",
|
||||
"ReceiptSaved": "Incasso registrato",
|
||||
"PaymentSaved": "Pagamento registrato"
|
||||
},
|
||||
"Payments": {
|
||||
"Receipts": "Incassi",
|
||||
"Payments": "Pagamenti",
|
||||
"ReceiptsHint": "Gli incassi dai clienti del periodo con i documenti saldati e la registrazione contabile.",
|
||||
"PaymentsHint": "I pagamenti ai fornitori del periodo con i documenti saldati e la registrazione contabile.",
|
||||
"Documents": "Documenti",
|
||||
"Origin": "Origine",
|
||||
"Entry": "Registrazione",
|
||||
"Total": "{0} movimenti · {1}",
|
||||
"None": "Nessun movimento nel periodo.",
|
||||
"Cancel": "Annulla movimento",
|
||||
"CancelText": "Annullare il movimento di {0} di {1}? Le partite tornano aperte e la registrazione viene eliminata o stornata.",
|
||||
"Cancelled": "Movimento annullato"
|
||||
},
|
||||
"Remittances": {
|
||||
"Title": "Distinte",
|
||||
"Heading": "Distinte RiBa / SDD / bonifici",
|
||||
"Hint": "Raccogli gli effetti in scadenza, genera il file per l'home banking, contabilizza la presentazione, l'accredito e gli insoluti.",
|
||||
"New": "Nuova distinta",
|
||||
"History": "Storico distinte",
|
||||
"Kind": "Tipo",
|
||||
"Bank": "Banca di presentazione",
|
||||
"PresentationDate": "Data presentazione",
|
||||
"DueUntil": "Scadenze fino al",
|
||||
"Effects": "Effetti",
|
||||
"Advance": "Salvo buon fine (anticipo)",
|
||||
"AdvanceShort": "s.b.f.",
|
||||
"Create": "Crea distinta",
|
||||
"Candidates": "Effetti proponibili",
|
||||
"PartyBank": "Banca controparte",
|
||||
"Check": "Controllo",
|
||||
"Late": "Scaduta: escludere?",
|
||||
"Ok": "OK",
|
||||
"NoCandidates": "Nessuna partita con questo metodo entro la data scelta.",
|
||||
"Footer": "Formati: RiBa (CBI), SDD core/B2B (pain.008), bonifici SEPA (pain.001) · gli insoluti tornano come partite riaperte con spese",
|
||||
"None": "Nessuna distinta nell'anno.",
|
||||
"Detail": "Distinta {0} n. {1}",
|
||||
"Lines": "Effetti della distinta",
|
||||
"FileCbi": "Genera file CBI",
|
||||
"FileXml": "Genera file XML",
|
||||
"Present": "Contabilizza presentazione",
|
||||
"PresentText": "La distinta viene contabilizzata: gli effetti passano dai clienti alla banca (o i bonifici ai fornitori vengono registrati). Continuare?",
|
||||
"Presented": "Distinta contabilizzata",
|
||||
"Delete": "Elimina distinta",
|
||||
"DeleteText": "Eliminare la distinta? Le partite tornano disponibili.",
|
||||
"Created": "Distinta creata",
|
||||
"Credit": "Registra accredito",
|
||||
"CreditText": "La banca ha accreditato gli effetti: le partite si chiudono e l'anticipo, se c'è, viene estinto.",
|
||||
"CreditedOnLabel": "Data accredito",
|
||||
"CreditedOn": "accreditata il {0}",
|
||||
"CreditEntry": "Registrazione accredito",
|
||||
"Entry": "Registrazione presentazione",
|
||||
"EndToEnd": "Riferimento",
|
||||
"FileName": "file {0}",
|
||||
"RemoveLine": "Togli dalla distinta",
|
||||
"Unpaid": "Insoluto",
|
||||
"UnpaidText": "L'effetto è tornato insoluto: la partita si riapre e le spese della banca vengono addebitate al cliente.",
|
||||
"UnpaidDone": "Insoluto registrato",
|
||||
"Step": {
|
||||
"Select": "Selezione effetti",
|
||||
"SelectText": "{0} selezionati · {1} esclusi",
|
||||
"Check": "Controlli",
|
||||
"CheckText": "IBAN, ABI/CAB, mandati, scadenze",
|
||||
"File": "Generazione file",
|
||||
"FileCbi": "tracciato CBI RiBa standard",
|
||||
"FileXml": "XML SEPA pain.008 o pain.001",
|
||||
"Post": "Contabilizzazione",
|
||||
"PostText": "effetti attivi / clienti",
|
||||
"Credit": "Accredito e insoluti",
|
||||
"CreditText": "chiusura delle partite o riapertura con spese"
|
||||
}
|
||||
},
|
||||
"Mandates": {
|
||||
"Title": "Mandati SDD",
|
||||
"Heading": "Mandati SEPA Direct Debit",
|
||||
"Hint": "Ogni cliente che paga con addebito diretto ha bisogno di un mandato firmato. Il primo incasso esce come FRST, i successivi come RCUR.",
|
||||
"New": "Nuovo mandato",
|
||||
"Edit": "Modifica mandato",
|
||||
"None": "Nessun mandato registrato.",
|
||||
"Reference": "Riferimento mandato (UMR)",
|
||||
"Signed": "Firmato il",
|
||||
"Scheme": "Schema",
|
||||
"OneOff": "Una tantum",
|
||||
"LastCollection": "Ultimo incasso",
|
||||
"First": "Mai usato (FRST)",
|
||||
"Active": "Valido",
|
||||
"Revoked": "Revocato",
|
||||
"Revoke": "Revoca",
|
||||
"Restore": "Annulla revoca",
|
||||
"Delete": "Elimina mandato",
|
||||
"DeleteText": "Eliminare il mandato {0}?"
|
||||
},
|
||||
"Dunning": {
|
||||
"Title": "Solleciti",
|
||||
"Heading": "Solleciti di pagamento",
|
||||
"Preview": "Anteprima",
|
||||
"Send": "Invia {0} solleciti",
|
||||
"SendTitle": "Invia solleciti",
|
||||
"SendText": "Inviare {0} solleciti per e-mail o PEC? Le lettere senza indirizzo vengono preparate in PDF.",
|
||||
"Sent": "{0} inviati, {1} lettere",
|
||||
"Proposal": "Proposta di invio",
|
||||
"Rule": "regola: scaduto oltre i giorni del livello · escluse PA e partite contestate",
|
||||
"Nothing": "Nessun cliente da sollecitare.",
|
||||
"Items": "Partite",
|
||||
"MaxDays": "Gg max",
|
||||
"LastSent": "Ultimo sollecito",
|
||||
"NextLevel": "Prossimo livello",
|
||||
"Level": "Livello {0}",
|
||||
"Waiting": "In attesa",
|
||||
"Channel": "Canale",
|
||||
"Include": "Includi",
|
||||
"Blocked": "· bloccato",
|
||||
"Levels": "Livelli e modelli",
|
||||
"LevelColumn": "Livello",
|
||||
"After": "Dopo (gg)",
|
||||
"Template": "Modello",
|
||||
"Action": "Azione",
|
||||
"Automatic": "Automatico",
|
||||
"InterestYes": "sì (D.Lgs. 231/2002)",
|
||||
"InterestNo": "no",
|
||||
"EditLevel": "Modifica livello",
|
||||
"ChargeInterest": "Calcola interessi di mora",
|
||||
"Subject": "Oggetto",
|
||||
"Body": "Testo",
|
||||
"Placeholders": "Segnaposti: {cliente} {azienda} {elenco} {totale} {interessi} {riferimento} {giorni}",
|
||||
"History": "Registro invii",
|
||||
"NoHistory": "Nessun sollecito inviato.",
|
||||
"Recipients": "Destinatari",
|
||||
"SentBy": "Inviato da",
|
||||
"Customers": "Clienti con scaduto",
|
||||
"OverdueTotal": "Scaduto totale",
|
||||
"Today": "Da sollecitare oggi",
|
||||
"LastRun": "Ultimo invio",
|
||||
"Schedule": "Esecuzione automatica",
|
||||
"ScheduleText": "giorni feriali alle 7:00"
|
||||
},
|
||||
"Reconciliation": {
|
||||
"Title": "Riconciliazione bancaria",
|
||||
"Import": "Importa estratto conto",
|
||||
"Auto": "Abbina automatico",
|
||||
"ConfirmAll": "Conferma suggeriti ≥ 90%",
|
||||
"ShowOpen": "Da riconciliare",
|
||||
"Lines": "Movimenti",
|
||||
"Statements": "Estratti importati",
|
||||
"None": "Nessun movimento da riconciliare.",
|
||||
"Description": "Descrizione",
|
||||
"In": "Entrate",
|
||||
"Out": "Uscite",
|
||||
"Proposal": "Abbinamento proposto",
|
||||
"Confidence": "Conf.",
|
||||
"Confirm": "Conferma",
|
||||
"MatchItems": "Abbina a partite",
|
||||
"MatchPayment": "Abbina a incasso o pagamento registrato",
|
||||
"Post": "Registra su conto",
|
||||
"Ignore": "Ignora",
|
||||
"Reset": "Annulla abbinamento",
|
||||
"Match": "Abbina",
|
||||
"Chosen": "Totale partite scelte {0}",
|
||||
"EntryDescription": "Descrizione registrazione",
|
||||
"SaveRule": "Salva come regola (testo da cercare)",
|
||||
"SaveRuleHint": "Se scrivi un testo, i movimenti futuri che lo contengono verranno proposti su questo conto.",
|
||||
"Footer": "Abbinamento per importo, data, CRO/riferimento e nome; regole salvate per i ricorrenti",
|
||||
"NoStatements": "Nessun estratto conto importato.",
|
||||
"File": "File",
|
||||
"Format": "Formato",
|
||||
"Movements": "Movimenti",
|
||||
"Closing": "Saldo finale",
|
||||
"Account": "Conto",
|
||||
"BankBalance": "Saldo banca",
|
||||
"BookBalance": "Saldo contabile",
|
||||
"Difference": "Differenza",
|
||||
"ToMatch": "Movimenti",
|
||||
"ToMatchText": "{0} da riconciliare · {1}",
|
||||
"Imported": "{0} movimenti importati, {1} già presenti, {2} con proposta",
|
||||
"Refreshed": "{0} proposte trovate",
|
||||
"Confirmed": "{0} movimenti riconciliati"
|
||||
},
|
||||
"Rules": {
|
||||
"Title": "Regole",
|
||||
"New": "Nuova regola",
|
||||
"Edit": "Regola di abbinamento",
|
||||
"None": "Nessuna regola salvata.",
|
||||
"Name": "Nome",
|
||||
"Pattern": "Testo da cercare",
|
||||
"PatternHint": "Senza distinzione tra maiuscole e minuscole.",
|
||||
"Direction": "Movimenti",
|
||||
"Account": "Conto",
|
||||
"Uses": "Usi",
|
||||
"Disabled": "Disattivata",
|
||||
"Delete": "Elimina regola"
|
||||
},
|
||||
"CashFlow": {
|
||||
"Title": "Flusso di cassa",
|
||||
"Heading": "Flusso di cassa previsto",
|
||||
"Hint": "Disponibilità di oggi e movimenti attesi da scadenze, distinte, ordini, registrazioni ricorrenti e imposte. Lo scaduto cade nel primo periodo.",
|
||||
"Days": "Orizzonte",
|
||||
"DaysText": "{0} giorni",
|
||||
"Period": "Periodo",
|
||||
"Weeks": "Settimane",
|
||||
"Months": "Mesi",
|
||||
"Periods": "Andamento",
|
||||
"Balance": "Saldo",
|
||||
"Chart": "Grafico",
|
||||
"Accounts": "Banche e cassa oggi",
|
||||
"Movements": "Movimenti previsti",
|
||||
"NoMovements": "Nessun movimento previsto.",
|
||||
"Source": "Origine",
|
||||
"Today": "Disponibilità oggi",
|
||||
"TotalIn": "Entrate previste",
|
||||
"TotalOut": "Uscite previste",
|
||||
"End": "Saldo finale",
|
||||
"Lowest": "Punto più basso"
|
||||
},
|
||||
"Enums": {
|
||||
"OpenItemStatus": {
|
||||
"Open": "Aperta",
|
||||
"Partial": "Parziale",
|
||||
"Closed": "Chiusa",
|
||||
"Unpaid": "Insoluta",
|
||||
"InRemittance": "In distinta"
|
||||
},
|
||||
"ScheduleView": {
|
||||
"Open": "Aperte",
|
||||
"Overdue": "Scadute",
|
||||
"Unpaid": "Insolute",
|
||||
"InRemittance": "In distinta",
|
||||
"Disputed": "Contestate",
|
||||
"Closed": "Chiuse",
|
||||
"All": "Tutte"
|
||||
},
|
||||
"PaymentOrigin": {
|
||||
"Manual": "Manuale",
|
||||
"Remittance": "Distinta",
|
||||
"BankStatement": "Estratto conto"
|
||||
},
|
||||
"RemittanceKind": {
|
||||
"Riba": "RiBa (CBI)",
|
||||
"SddCore": "SDD Core",
|
||||
"SddB2b": "SDD B2B",
|
||||
"SepaCreditTransfer": "Bonifici SEPA"
|
||||
},
|
||||
"RemittanceStatus": {
|
||||
"Draft": "Bozza",
|
||||
"Generated": "File generato",
|
||||
"Presented": "Presentata",
|
||||
"Closed": "Chiusa"
|
||||
},
|
||||
"RemittanceLineStatus": {
|
||||
"Included": "In distinta",
|
||||
"Paid": "Pagato",
|
||||
"Unpaid": "Insoluto"
|
||||
},
|
||||
"SddScheme": {
|
||||
"Core": "Core (privati)",
|
||||
"B2b": "B2B (imprese)"
|
||||
},
|
||||
"StatementLineStatus": {
|
||||
"ToMatch": "Da abbinare",
|
||||
"Suggested": "Suggerito",
|
||||
"Matched": "Abbinato",
|
||||
"Ignored": "Ignorato"
|
||||
},
|
||||
"StatementMatchKind": {
|
||||
"None": "Nessuno",
|
||||
"OpenItems": "Partite",
|
||||
"Payment": "Movimento registrato",
|
||||
"TaxPayment": "F24",
|
||||
"Rule": "Regola",
|
||||
"RemittanceCredit": "Accredito distinta",
|
||||
"Unpaid": "Insoluto",
|
||||
"Entry": "Registrazione"
|
||||
},
|
||||
"StatementFormat": {
|
||||
"Csv": "CSV",
|
||||
"Camt053": "CAMT.053",
|
||||
"Cbi": "CBI"
|
||||
},
|
||||
"BankRuleDirection": {
|
||||
"Any": "Entrate e uscite",
|
||||
"In": "Entrate",
|
||||
"Out": "Uscite"
|
||||
},
|
||||
"DunningChannel": {
|
||||
"None": "Nessuno",
|
||||
"Email": "e-mail",
|
||||
"Pec": "PEC",
|
||||
"Letter": "Lettera PDF"
|
||||
},
|
||||
"DunningAction": {
|
||||
"None": "—",
|
||||
"NotifyAgent": "Avvisa l'agente",
|
||||
"BlockCustomer": "Blocca il cliente"
|
||||
},
|
||||
"DunningLetterStatus": {
|
||||
"Queued": "In coda",
|
||||
"Sent": "Inviato",
|
||||
"Failed": "Non inviato"
|
||||
},
|
||||
"CashFlowSource": {
|
||||
"Receivables": "Incassi da clienti",
|
||||
"Payables": "Pagamenti a fornitori",
|
||||
"SaleOrders": "Ordini clienti",
|
||||
"PurchaseOrders": "Ordini fornitori",
|
||||
"Recurring": "Ricorrenti",
|
||||
"Taxes": "Imposte"
|
||||
}
|
||||
}
|
||||
},
|
||||
"treasury": {
|
||||
"not-found": "L'elemento non esiste più.",
|
||||
"account-missing": "Manca il conto contabile: controlla il piano dei conti e le causali.",
|
||||
"money-account-missing": "Manca il conto della banca o della cassa: indica il conto contabile della banca.",
|
||||
"iban-invalid": "L'IBAN non è valido.",
|
||||
"payment": {
|
||||
"party-required": "Indica il cliente o il fornitore.",
|
||||
"items-required": "Scegli almeno una partita.",
|
||||
"amount-required": "Indica un importo diverso da zero.",
|
||||
"item-party": "Le partite devono essere della stessa controparte.",
|
||||
"over-settled": "L'importo supera il residuo della partita.",
|
||||
"unbalanced": "Il movimento non quadra con le partite.",
|
||||
"from-remittance": "Il movimento nasce da una distinta: annullalo dalla distinta."
|
||||
},
|
||||
"item": {
|
||||
"in-remittance": "La partita è in una distinta."
|
||||
},
|
||||
"remittance": {
|
||||
"empty": "La distinta non ha effetti.",
|
||||
"status": "La distinta non è nello stato giusto per questa operazione.",
|
||||
"bank": "La banca di presentazione non ha i dati richiesti (IBAN, SIA, CUC o identificativo creditore).",
|
||||
"iban": "IBAN o ABI/CAB mancanti",
|
||||
"mandate": "Mandato SDD mancante o revocato",
|
||||
"item": "La partita non è disponibile.",
|
||||
"format": "Il pacchetto fiscale non sa scrivere questo formato."
|
||||
},
|
||||
"mandate": {
|
||||
"duplicate": "Esiste già un mandato con questo riferimento.",
|
||||
"reference": "Il riferimento del mandato è obbligatorio (massimo 35 caratteri).",
|
||||
"used": "Il mandato è già stato usato in una distinta: revocalo invece di eliminarlo."
|
||||
},
|
||||
"statement": {
|
||||
"format": "Formato dell'estratto conto non riconosciuto (CAMT.053, CBI o CSV).",
|
||||
"empty": "L'estratto conto non contiene movimenti.",
|
||||
"account": "L'estratto conto è di un altro conto."
|
||||
},
|
||||
"match": {
|
||||
"done": "Il movimento è già riconciliato.",
|
||||
"amount": "L'importo non corrisponde."
|
||||
},
|
||||
"rule": {
|
||||
"pattern": "Scrivi il testo da cercare."
|
||||
},
|
||||
"dunning": {
|
||||
"recipient": "Nessun indirizzo e-mail o PEC: preparata la lettera PDF.",
|
||||
"level": "Livello di sollecito non valido."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,10 +74,11 @@ public static class MenuCatalog
|
||||
("Shell.Menu.Ledger.Parties", "partitari"), ("Shell.Menu.Ledger.VatRegisters", "registri-iva"),
|
||||
("Shell.Menu.Ledger.VatSettlement", "liquidazione-iva"), ("Shell.Menu.Ledger.Withholdings", "ritenute"),
|
||||
("Shell.Menu.Ledger.StampDuty", "bollo"), ("Shell.Menu.Ledger.Statements", "bilancio")),
|
||||
Area("Shell.Menu.Finance", "coins", "/scadenzario", ModuleCodes.Finance, "finance.schedule.read", "M9",
|
||||
("Shell.Menu.Finance.OpenItems", "scadenze"), ("Shell.Menu.Finance.Remittances", "distinte"), ("Shell.Menu.Finance.Dunning", "solleciti"),
|
||||
("Shell.Menu.Finance.Reconciliation", "riconciliazione")),
|
||||
Area("Shell.Menu.EInvoicing", "file-check", "/fatturazione-elettronica", ModuleCodes.EInvoicing, "einvoice.document.read", "M8",
|
||||
Area("Shell.Menu.Finance", "coins", "/scadenzario", ModuleCodes.Finance, "finance.schedule.read", null,
|
||||
("Shell.Menu.Finance.OpenItems", "scadenze"), ("Shell.Menu.Finance.Receipts", "incassi"), ("Shell.Menu.Finance.Payments", "pagamenti"),
|
||||
("Shell.Menu.Finance.Dunning", "solleciti"), ("Shell.Menu.Finance.Remittances", "distinte"), ("Shell.Menu.Finance.Mandates", "mandati"),
|
||||
("Shell.Menu.Finance.Reconciliation", "riconciliazione"), ("Shell.Menu.Finance.CashFlow", "flusso-di-cassa")),
|
||||
Area("Shell.Menu.EInvoicing", "file-check", "/fatturazione-elettronica", ModuleCodes.EInvoicing, "einvoice.document.read", "M9",
|
||||
("Shell.Menu.EInvoicing.Dashboard", "cruscotto"), ("Shell.Menu.EInvoicing.Channels", "canali"),
|
||||
("Shell.Menu.EInvoicing.IntentDeclarations", "dichiarazioni-intento")),
|
||||
Area("Shell.Menu.Assets", "building", "/cespiti", ModuleCodes.Assets, "assets.asset.read", "M10",
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
using System.Globalization;
|
||||
using Khaemhat.Application.Localization;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Core.Accounting;
|
||||
using Khaemhat.Core.Tables;
|
||||
using Khaemhat.Core.Treasury;
|
||||
using Khaemhat.Web.Ledger;
|
||||
using Khaemhat.Web.Ui;
|
||||
|
||||
namespace Khaemhat.Web.Treasury;
|
||||
|
||||
/// <summary>What the screens of the schedule and the treasury share (SPEC §11.8, mockups 053-057): addresses, texts and tones.</summary>
|
||||
public static class TreasuryScreens
|
||||
{
|
||||
/// <summary>The address of the area.</summary>
|
||||
public const string BasePath = "/scadenzario";
|
||||
|
||||
/// <summary>The key of the text of an enum value.</summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The key.</returns>
|
||||
public static string EnumKey(Enum value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
return "Treasury.Enums." + value.GetType().Name + "." + value;
|
||||
}
|
||||
|
||||
/// <summary>The choices of an enum.</summary>
|
||||
/// <typeparam name="TEnum">The enum.</typeparam>
|
||||
/// <param name="texts">The texts.</param>
|
||||
/// <returns>The choices in declaration order.</returns>
|
||||
public static IReadOnlyList<KhOption<TEnum>> Choices<TEnum>(ITexts texts)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(texts);
|
||||
return [.. Enum.GetValues<TEnum>().Select(v => new KhOption<TEnum>(v, texts[EnumKey(v)]))];
|
||||
}
|
||||
|
||||
/// <summary>The text of the errors of a refused operation.</summary>
|
||||
/// <param name="texts">The texts.</param>
|
||||
/// <param name="exception">The refusal.</param>
|
||||
/// <returns>The messages.</returns>
|
||||
public static string Errors(ITexts texts, ValidationFailedException exception) => LedgerScreens.Errors(texts, exception);
|
||||
|
||||
/// <summary>The tone of the state of an item; an open item past due is an error.</summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="today">Today.</param>
|
||||
/// <returns>The tone.</returns>
|
||||
public static KhTone ToneOf(OpenItem item, DateOnly today)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
return item.Status switch
|
||||
{
|
||||
OpenItemStatus.Closed => KhTone.Ok,
|
||||
OpenItemStatus.Unpaid => KhTone.Error,
|
||||
OpenItemStatus.InRemittance => KhTone.Info,
|
||||
OpenItemStatus.Partial => KhTone.Warning,
|
||||
_ when item.DueDate < today => KhTone.Error,
|
||||
_ when item.DueDate <= today.AddDays(7) => KhTone.Warning,
|
||||
_ => KhTone.Neutral,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The text of the state of an item: overdue and due soon are told apart from open.</summary>
|
||||
/// <param name="texts">The texts.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="today">Today.</param>
|
||||
/// <returns>The text.</returns>
|
||||
public static string StatusText(ITexts texts, OpenItem item, DateOnly today)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(texts);
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
var text = item.Status == OpenItemStatus.Open && item.DueDate < today ? texts["Treasury.Schedule.Overdue"]
|
||||
: item.Status == OpenItemStatus.Open && item.DueDate <= today.AddDays(7) ? texts["Treasury.Schedule.DueSoon"]
|
||||
: texts[EnumKey(item.Status)];
|
||||
return item.Disputed ? text + " · " + texts["Treasury.Schedule.Disputed"] : text;
|
||||
}
|
||||
|
||||
/// <summary>The tone of the state of a remittance.</summary>
|
||||
/// <param name="status">The state.</param>
|
||||
/// <returns>The tone.</returns>
|
||||
public static KhTone ToneOf(RemittanceStatus status) => status switch
|
||||
{
|
||||
RemittanceStatus.Draft => KhTone.Warning,
|
||||
RemittanceStatus.Generated => KhTone.Info,
|
||||
RemittanceStatus.Presented => KhTone.Accent,
|
||||
_ => KhTone.Ok,
|
||||
};
|
||||
|
||||
/// <summary>The tone of the state of a movement of the bank.</summary>
|
||||
/// <param name="status">The state.</param>
|
||||
/// <returns>The tone.</returns>
|
||||
public static KhTone ToneOf(StatementLineStatus status) => status switch
|
||||
{
|
||||
StatementLineStatus.Matched => KhTone.Ok,
|
||||
StatementLineStatus.Suggested => KhTone.Info,
|
||||
StatementLineStatus.Ignored => KhTone.Neutral,
|
||||
_ => KhTone.Warning,
|
||||
};
|
||||
|
||||
/// <summary>A number of a remittance as the screens show it.</summary>
|
||||
/// <param name="remittance">The remittance.</param>
|
||||
/// <returns>The text, year/number.</returns>
|
||||
public static string Number(Remittance remittance)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(remittance);
|
||||
return remittance.Year.ToString(CultureInfo.InvariantCulture) + "/" + remittance.Number.ToString("000", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>An IBAN shortened for a grid: country, check digits and the last four characters.</summary>
|
||||
/// <param name="iban">The IBAN.</param>
|
||||
/// <returns>The short text.</returns>
|
||||
public static string ShortIban(string? iban) =>
|
||||
string.IsNullOrEmpty(iban) || iban.Length < 10 ? iban ?? string.Empty : iban[..4] + "…" + iban[^4..];
|
||||
|
||||
/// <summary>The choices of the bank accounts.</summary>
|
||||
/// <param name="banks">The bank accounts.</param>
|
||||
/// <returns>The choices, code and name.</returns>
|
||||
public static IReadOnlyList<KhOption<long?>> BankChoices(IEnumerable<BankAccount> banks) =>
|
||||
[.. (banks ?? []).Select(b => new KhOption<long?>(b.Id, b.Code + " · " + (b.BankName ?? b.Description)))];
|
||||
|
||||
/// <summary>The choices of the payment methods.</summary>
|
||||
/// <param name="methods">The payment methods.</param>
|
||||
/// <returns>The choices, description and code of the e-invoice.</returns>
|
||||
public static IReadOnlyList<KhOption<long?>> MethodChoices(IEnumerable<PaymentMethod> methods) =>
|
||||
[.. (methods ?? []).Select(m => new KhOption<long?>(m.Id, m.Description + " (" + m.EInvoiceCode + ")"))];
|
||||
}
|
||||
@@ -436,3 +436,19 @@ h1[tabindex="-1"]:focus { outline: none; box-shadow: none; }
|
||||
.grid tr.err td { background: var(--kh-err-soft); }
|
||||
.grid tfoot td { border-top: 1px solid var(--kh-border); }
|
||||
@media (max-width: 1100px) { .kh-ledger-split, .kh-ledger-two { grid-template-columns: minmax(0, 1fr); } }
|
||||
|
||||
/* Schedule and treasury (M8): aging tiles, the remittance form beside its effects, the bars of the cash flow. */
|
||||
.kh-aging { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 10px 0 12px; }
|
||||
.kh-remit { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(0, 3fr); gap: 12px; align-items: start; }
|
||||
.kh-remit .kh-panel .btn.primary, .kh-remit .panel .btn.primary { margin-top: 12px; width: 100%; justify-content: center; }
|
||||
.kh-subhead { margin: 14px 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--kh-text-2); }
|
||||
.grid .chkcol { width: 32px; text-align: center; }
|
||||
.grid tr.warn td { background: var(--kh-warn-soft); }
|
||||
.grid tr.clickable { cursor: pointer; }
|
||||
.grid td.neg, .grid td .neg { color: var(--kh-err); }
|
||||
.grid td.pos { color: var(--kh-ok); }
|
||||
.btn.ok { color: var(--kh-ok); border-color: var(--kh-ok); }
|
||||
.kh-cfbarcol { width: 28%; }
|
||||
.kh-cfbar { display: block; height: 8px; border-radius: 4px; background: var(--kh-accent); min-width: 2px; }
|
||||
.kh-cfbar.neg { background: var(--kh-err); }
|
||||
@media (max-width: 1100px) { .kh-remit { grid-template-columns: minmax(0, 1fr); } }
|
||||
@@ -95,7 +95,7 @@ public sealed partial class LocalizationRulesTests
|
||||
keys.AddRange(UserPreferences.Accents.Select(a => "Pages.Profile.Accent." + a));
|
||||
keys.AddRange(Enum.GetValues<ToastKind>().Select(v => "Pages.Catalog.Windows.Toast." + v));
|
||||
|
||||
Assert.IsEmpty(keys.Where(k => !ShellTests.Texts.Contains(k)).ToList());
|
||||
Assert.IsEmpty(keys.Where(k => !ShellTests.Texts.Contains(k)).ToList(), string.Join(", ", keys.Where(k => !ShellTests.Texts.Contains(k))));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -115,7 +115,7 @@ public sealed partial class LocalizationRulesTests
|
||||
keys.AddRange(typeof(LedgerErrors).GetFields(BindingFlags.Public | BindingFlags.Static)
|
||||
.Where(f => f.IsLiteral).Select(f => (string)f.GetRawConstantValue()!));
|
||||
|
||||
Assert.IsEmpty(keys.Where(k => !ShellTests.Texts.Contains(k)).ToList());
|
||||
Assert.IsEmpty(keys.Where(k => !ShellTests.Texts.Contains(k)).ToList(), string.Join(", ", keys.Where(k => !ShellTests.Texts.Contains(k))));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Reference in new issue
Block a user