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;
|
||||
}
|
||||
Reference in new issue
Block a user