Seen while checking M6 in the browser: the stock take toolbar crowded the panel title, the reorder and stock take tables ran past their panel, and the movements dialog cut the balance column. Confirmed supplier receipts have no number of their own and showed "Bozza"; they now read "Senza numero". The self-invoice advice no longer doubles the full stop, and a single price difference reads in the singular. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
199 lines
9.4 KiB
Plaintext
199 lines
9.4 KiB
Plaintext
@page "/vendite/{Segment}"
|
|
@page "/acquisti/{Segment}"
|
|
@page "/magazzino/{Segment}"
|
|
@attribute [Authorize]
|
|
@using Khaemhat.Application.Documents
|
|
@using Khaemhat.Core.Documents
|
|
@using Khaemhat.Web.Documents
|
|
@inject ShellSession Session
|
|
@inject DocumentEngine Engine
|
|
@inject DocumentEditor Editor
|
|
@inject NavigationManager Navigation
|
|
@inject TimeProvider Clock
|
|
|
|
@* The radar of a kind of documents (SPEC §11.3-§11.6): quotations, orders, delivery notes, invoices (with pro forma
|
|
and fees), credit and debit notes; supplier orders, receipts, supplier invoices, self-invoices; warehouse
|
|
movements. Search on number, reference and party; filters for state, type and year; totals of the page. Enter or
|
|
double click opens the document. *@
|
|
<KhPageTitle Text="@Title" Icon="@(_section?.Icon ?? "cart")" />
|
|
|
|
@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["Sales.NoCompany"]</h1></div>
|
|
}
|
|
else if (_section is null)
|
|
{
|
|
<div class="kh-message"><KhIcon Name="alert" Class="lg" /><h1>@T["Pages.NotFound.Title"]</h1></div>
|
|
}
|
|
else if (!CanRead)
|
|
{
|
|
<div class="kh-message">
|
|
<KhIcon Name="lock" Class="lg" />
|
|
<h1>@T["Pages.AccessDenied.Title"]</h1>
|
|
<p class="lead">@T["Pages.AccessDenied.Lead"]</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
@if (_section.Area == SalesScreens.PurchasesPath && _section.Segment == "autofatture")
|
|
{
|
|
<Khaemhat.Web.Components.Purchases.PendingSelfInvoicesPanel />
|
|
}
|
|
<KhRadar TItem="DocumentRow" @key="_section.Area + _section.Segment" Id="@(_section.Area == SalesScreens.BasePath ? "sales." + _section.Segment : _section.Area + "." + _section.Segment)" Columns="Columns" Source="ListAsync" KeyOf="r => r.Id" Selectable="false"
|
|
OnOpen="Open" QuickFilters="QuickFilters" RowClass="RowClassOf" SearchPlaceholder="@T["Sales.Radar.Search"]" ExportName="@_section.Segment"
|
|
Label="@Title">
|
|
<Toolbar>
|
|
@if (NewTypes.Count > 0)
|
|
{
|
|
<button type="button" class="btn primary" @onclick="New"><KhIcon Name="plus" /> @T["Sales.Sections." + _section.Key + ".New"]</button>
|
|
}
|
|
@if (_section.Area == SalesScreens.BasePath && _section.Segment == "fatture" && Session.Permissions.Allows("sales.invoice.write"))
|
|
{
|
|
<a class="btn" href="@SalesScreens.DeferredInvoicingUrl"><KhIcon Name="layers" /> @T["Sales.Deferred.Title"]</a>
|
|
}
|
|
@if (_section.Area == SalesScreens.PurchasesPath && _section.Segment == "fatture" && Session.Permissions.Allows("purchases.invoice.write"))
|
|
{
|
|
<a class="btn" href="acquisti/importa-fatture"><KhIcon Name="upload" /> @T["Shell.Menu.Purchases.Import"]</a>
|
|
}
|
|
</Toolbar>
|
|
</KhRadar>
|
|
|
|
<KhDialog Open="_choosing" Title="@T["Sales.NewDocument"]" Icon="plus" OnClose="() => _choosing = false">
|
|
<ChildContent>
|
|
<div class="kh-choice-list">
|
|
@foreach (var type in NewTypes)
|
|
{
|
|
<button type="button" class="btn kh-choice" @onclick="() => Create(type.Code)">
|
|
<span class="code">@type.Code</span>
|
|
<b>@type.Type.Description</b>
|
|
<span class="muted sm">@T["Sales.Hints.Kinds." + type.Kind]</span>
|
|
</button>
|
|
}
|
|
</div>
|
|
</ChildContent>
|
|
</KhDialog>
|
|
}
|
|
|
|
@code {
|
|
private SalesSection? _section;
|
|
private IReadOnlyList<DocumentDefinition> _definitions = [];
|
|
private bool _loaded;
|
|
private bool _choosing;
|
|
|
|
/// <summary>The radar segment, such as <c>fatture</c>.</summary>
|
|
[Parameter]
|
|
public string? Segment { get; set; }
|
|
|
|
private string Title => _section is null ? T["Shell.Menu.Sales"] : T["Sales.Sections." + _section.Key + ".Title"];
|
|
|
|
private bool Internal => _section?.Direction == DocumentDirection.Internal;
|
|
|
|
private bool CanRead => _section is not null && Session.Permissions.Allows(DocumentBehaviors.Of(_section.Kinds[0]).ReadPermission);
|
|
|
|
private DateOnly Today => DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(Clock.GetUtcNow(), TimeZoneInfo.Local).DateTime);
|
|
|
|
// The types of the radar the user may create, in the order of the section.
|
|
private List<DocumentDefinition> NewTypes => _section is null ? [] :
|
|
[.. _section.NewTypes.Select(code => _definitions.FirstOrDefault(d => d.Code == code)).OfType<DocumentDefinition>()
|
|
.Where(d => Session.Permissions.Allows(d.Behavior.WritePermission))];
|
|
|
|
private IReadOnlyList<KhColumn<DocumentRow>> Columns =>
|
|
[
|
|
new("number", T[_section?.Kinds.Contains(DocumentKind.PurchaseInvoice) == true ? "Purchases.Fields.Protocol" : "Sales.Fields.DocumentNumber"], r => SalesScreens.Number(T, r.DocumentNumber, r.Status)) { Kind = KhColumnKind.Code, Width = "130px" },
|
|
new("date", T["Sales.Fields.DocumentDate"], r => r.Date) { Kind = KhColumnKind.Date, Width = "100px" },
|
|
new("type", T["Sales.Radar.Kind"], r => SalesScreens.KindName(T, r.Kind)) { Width = "150px", Sortable = false, Visible = _section?.Kinds.Count > 1 },
|
|
new("party", T[SalesScreens.PartyLabel(_section?.Direction ?? DocumentDirection.Sale)], r => r.PartyName) { Sortable = false, Visible = !Internal },
|
|
new("reference", T[_section?.Direction == DocumentDirection.Purchase ? "Purchases.Fields.SupplierNumber" : "Sales.Fields.ExternalReference"], r => r.Reference) { Width = "140px" },
|
|
new("validUntil", T["Sales.Fields.ValidUntil"], r => r.ValidUntil) { Kind = KhColumnKind.Date, Width = "100px", Visible = _section?.Segment == "preventivi" },
|
|
new("delivery", T["Sales.Fields.DeliveryDate"], r => r.DeliveryDate) { Kind = KhColumnKind.Date, Width = "100px", Visible = _section?.Segment is "ordini" or "ddt" or "ricevimenti" },
|
|
new("taxable", T["Sales.Totals.Taxable"], r => r.Taxable) { Kind = KhColumnKind.Money, Width = "120px", Visible = !Internal },
|
|
new("total", T["Sales.Totals.Total"], r => r.Total) { Kind = KhColumnKind.Money, Width = "120px", Visible = !Internal },
|
|
new("status", T["Sales.Radar.State"], r => StateOf(r).Text)
|
|
{
|
|
Width = "130px",
|
|
Template = r => @<KhBadge Tone="StateOf(r).Tone">@StateOf(r).Text</KhBadge>,
|
|
},
|
|
];
|
|
|
|
private IReadOnlyList<KhQuickFilter> QuickFilters
|
|
{
|
|
get
|
|
{
|
|
var filters = new List<KhQuickFilter>
|
|
{
|
|
new("status", T["Sales.Radar.State"], [new(string.Empty, T["Sales.Radar.All"]), .. States.Select(s => new KhOption<string>(s.ToString(), T["Sales.States." + s]))]),
|
|
};
|
|
if (_section is { Kinds.Count: > 1 })
|
|
{
|
|
filters.Add(new("kind", T["Sales.Radar.Kind"], [new(string.Empty, T["Sales.Radar.All"]), .. _section.Kinds.Select(k => new KhOption<string>(k.ToString(), SalesScreens.KindName(T, k)))]));
|
|
}
|
|
|
|
var year = Today.Year;
|
|
filters.Add(new("year", T["Sales.Radar.Year"],
|
|
[new(string.Empty, T["Sales.Radar.All"]), .. Enumerable.Range(0, 3).Select(i => new KhOption<string>((year - i).ToString(T.Culture), (year - i).ToString(T.Culture)))]));
|
|
return filters;
|
|
}
|
|
}
|
|
|
|
// The states that make sense for the life cycle of the radar.
|
|
private IEnumerable<DocumentStatus> States => _section is null ? [] :
|
|
DocumentBehaviors.Of(_section.Kinds[0]).Lifecycle == DocumentLifecycle.Invoice && _section.Kinds.All(k => DocumentBehaviors.Of(k).Lifecycle == DocumentLifecycle.Invoice)
|
|
? [DocumentStatus.Draft, DocumentStatus.Issued, DocumentStatus.Cancelled]
|
|
: [DocumentStatus.Draft, DocumentStatus.Confirmed, DocumentStatus.PartiallyFulfilled, DocumentStatus.Fulfilled, DocumentStatus.Closed, DocumentStatus.Cancelled, DocumentStatus.Issued];
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Session.EnsureLoadedAsync();
|
|
_section = SalesScreens.Find(SalesScreens.AreaOf(Navigation.ToBaseRelativePath(Navigation.Uri)), Segment);
|
|
if (!_loaded && Session.Actor is { } actor && Session.Company?.Code is { } company)
|
|
{
|
|
_definitions = await Engine.DefinitionsAsync(actor, company);
|
|
}
|
|
|
|
_loaded = true;
|
|
}
|
|
|
|
private (string Text, KhTone Tone) StateOf(DocumentRow row) => SalesScreens.State(T, row.Kind, row.Status, row.ValidUntil, Today);
|
|
|
|
private static string? RowClassOf(DocumentRow row) => row.Status == DocumentStatus.Cancelled ? "muted" : null;
|
|
|
|
private Task<ListPage<DocumentRow>> ListAsync(ListQuery query, CancellationToken cancellationToken) =>
|
|
Session.Actor is { } actor && Session.Company?.Code is { } company && _section is not null
|
|
? Editor.ListAsync(actor, company, _section.Family, _section.Kinds, query, cancellationToken)
|
|
: Task.FromResult(new ListPage<DocumentRow>([], 0, new Dictionary<string, decimal>()));
|
|
|
|
private void Open(DocumentRow row)
|
|
{
|
|
if (SalesScreens.RecordUrl(row.Kind, row.Id) is { } url)
|
|
{
|
|
Navigation.NavigateTo(url);
|
|
}
|
|
}
|
|
|
|
private void New()
|
|
{
|
|
if (NewTypes.Count == 1)
|
|
{
|
|
Create(NewTypes[0].Code);
|
|
}
|
|
else
|
|
{
|
|
_choosing = true;
|
|
}
|
|
}
|
|
|
|
private void Create(string code)
|
|
{
|
|
_choosing = false;
|
|
if (_section is not null)
|
|
{
|
|
Navigation.NavigateTo(SalesScreens.NewUrl(_section, code));
|
|
}
|
|
}
|
|
}
|