feat: automatic codes and automatic filling (#43)
Parties, items and the CRM archives need codes given by the system without
duplicates, and the address and bank fields should fill themselves; this adds
both before the party and item screens that use them.
- CodeMask ({seq:0000}, {anno}, {categoria}) and code_sequences (migration
015): one sequence per rule, year and category, taken under a lock in the
transaction that saves the record, skipping codes written by hand
- CodeRuleService: rules in company settings with the masks of SPEC 11.12,
validation, preview of the next code, manual code allowed or not
- AutoFillService: municipality from postal code and back, personal tax code,
VIES, bank and BIC from the IBAN, delivery date on working days, options
that can be switched off (the ECB job honours its option)
- IBankDirectory.ReadIban gives ABI and CAB even without the ABI list; the
Italian pack now registers the directory
- Company preferences page (mockup 074) at /tabelle/preferenze, in the menu
- aria-checked now renders true/false on switch rows and profile radios
- ADR 0027, wiki, CHANGELOG, STATUS, DATA-MODEL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9bcf8c1082
commit
07555de700
27 files changed
+1627
-40
No files matched your search
@@ -99,7 +99,7 @@
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.Density"]">
|
||||
@foreach (var density in Enum.GetValues<Density>())
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.Density == density ? "on" : null)" aria-checked="@(Draft.Density == density)"
|
||||
<button type="button" role="radio" class="@(Draft.Density == density ? "on" : null)" aria-checked="@(Draft.Density == density ? "true" : "false")"
|
||||
@onclick="() => ChangeAsync(Draft with { Density = density })">@T["Pages.Profile.Density." + density]</button>
|
||||
}
|
||||
</div>
|
||||
@@ -110,7 +110,7 @@
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.TextSize"]">
|
||||
@foreach (var size in UserPreferences.TextSizes)
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.TextSize == size ? "on" : null)" aria-checked="@(Draft.TextSize == size)"
|
||||
<button type="button" role="radio" class="@(Draft.TextSize == size ? "on" : null)" aria-checked="@(Draft.TextSize == size ? "true" : "false")"
|
||||
@onclick="() => ChangeAsync(Draft with { TextSize = size })">@T.Format("Pages.Profile.TextSize.Value", size)</button>
|
||||
}
|
||||
</div>
|
||||
@@ -121,7 +121,7 @@
|
||||
<div class="kh-seg" role="radiogroup" aria-label="@T["Pages.Profile.Menu"]">
|
||||
@foreach (var (value, key) in MenuChoices)
|
||||
{
|
||||
<button type="button" role="radio" class="@(Draft.MenuCollapsed == value ? "on" : null)" aria-checked="@(Draft.MenuCollapsed == value)"
|
||||
<button type="button" role="radio" class="@(Draft.MenuCollapsed == value ? "on" : null)" aria-checked="@(Draft.MenuCollapsed == value ? "true" : "false")"
|
||||
@onclick="() => ChangeAsync(Draft with { MenuCollapsed = value })">@T[key]</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
@page "/tabelle/preferenze"
|
||||
@attribute [Authorize]
|
||||
@using Khaemhat.Application.Licensing
|
||||
@using Khaemhat.Application.Security
|
||||
@using Khaemhat.Application.Tables
|
||||
@using Khaemhat.Core.Tables
|
||||
@using Khaemhat.Web.Tables
|
||||
@inject ShellSession Session
|
||||
@inject CodeRuleService Codes
|
||||
@inject AutoFillService AutoFill
|
||||
@inject TableService Tables
|
||||
@inject ILicenseGate License
|
||||
@inject ToastService Toasts
|
||||
@inject TimeProvider Clock
|
||||
|
||||
@* Company preferences (SPEC §11.12, mockup 074): the masks of the automatic codes with the preview of the next code,
|
||||
and the automatic filling options. The other tabs of the mockup arrive with the documents and the e-mails. *@
|
||||
<KhPageTitle Text="@T["CompanyPreferences.Title"]" Icon="settings" />
|
||||
|
||||
<TablesGuard>
|
||||
<div class="phead">
|
||||
<div>
|
||||
<div class="crumbs"><a href="@TableScreens.BasePath">@T["Shell.Menu.CompanyTables"]</a> / @T["CompanyPreferences.Title"]</div>
|
||||
<h1>@T["CompanyPreferences.Heading"]</h1>
|
||||
<div class="sub">@T["CompanyPreferences.Hint"]</div>
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
@if (_modified)
|
||||
{
|
||||
<KhBadge Tone="KhTone.Warning">@T["CompanyTables.Modified"]</KhBadge>
|
||||
}
|
||||
<div class="toolbar">
|
||||
<button type="button" class="btn" disabled="@(!_modified)" @onclick="UndoAsync"><KhIcon Name="undo" /> @T["CompanyTables.Undo"]</button>
|
||||
<button type="button" class="btn primary" disabled="@(!_modified || !CanWrite || _busy)" @onclick="SaveAsync"><KhIcon Name="save" /> @T["Common.Save"]</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_loaded)
|
||||
{
|
||||
<section class="panel kh-tables-profile">
|
||||
<KhTabs Items="TabItems" Active="@_tab" ActiveChanged="t => _tab = t" Label="@T["CompanyPreferences.Title"]" />
|
||||
@if (_tab == "codes")
|
||||
{
|
||||
<KhForm Validation="_validation" ReadOnly="!CanWrite" Layout="KhFormLayout.Groups">
|
||||
@foreach (var group in CodeRuleService.Definitions.GroupBy(d => d.Group))
|
||||
{
|
||||
<KhFieldGroup Title="@T["CompanyPreferences.Groups." + group.Key]" Icon="@GroupIcon(group.Key)">
|
||||
@foreach (var definition in group)
|
||||
{
|
||||
var rule = _rules[definition.Key];
|
||||
<KhTextBox Label="@T["CompanyPreferences.Rules." + definition.Key]" Name="@(definition.Key + "." + CodeRuleService.MaskField)" Mono="true"
|
||||
Value="@rule.Mask" MaxLength="40" ReadOnly="!CanWrite" Hint="@HintOf(definition)"
|
||||
ValueChanged="v => ChangeMaskAsync(definition.Key, v)" Span="6" />
|
||||
}
|
||||
<KhCheck Label="@T["CompanyPreferences.AllowManual"]" Name="@(group.Key + ".manual")" Value="group.All(d => _rules[d.Key].AllowManual)"
|
||||
ValueChanged="v => SetManual(group.Key, v)" ReadOnly="!CanWrite" Span="12" />
|
||||
@if (group.Key == "items")
|
||||
{
|
||||
<KhCheck Label="@T["CompanyPreferences.UniqueBarcode"]" Name="items.unique-barcode" Value="UniqueBarcode"
|
||||
ValueChanged="SetUniqueBarcode" ReadOnly="!CanWrite" Span="12" />
|
||||
}
|
||||
</KhFieldGroup>
|
||||
}
|
||||
<KhFieldGroup Title="@T["CompanyPreferences.Groups.documents"]" Icon="file">
|
||||
<p class="muted c12">@T["CompanyPreferences.Numerators"] <a href="/tabelle/numeratori">@T["CompanyPreferences.NumeratorsLink"]</a></p>
|
||||
</KhFieldGroup>
|
||||
</KhForm>
|
||||
<p class="muted kh-pad"><KhIcon Name="info" /> @T["CompanyPreferences.Placeholders"]</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="kh-pad kh-autofill">
|
||||
@foreach (var option in AutoFillService.Options)
|
||||
{
|
||||
<KhSwitchRow Label="@T["CompanyPreferences.Options." + option.Key]" Hint="@T["CompanyPreferences.Options." + option.Key + ".Hint"]"
|
||||
Value="_options.GetValueOrDefault(option.Key)" ValueChanged="v => SetOption(option.Key, v)" />
|
||||
}
|
||||
<p class="muted"><KhIcon Name="info" /> @T["CompanyPreferences.AutoFillHint"]</p>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
</TablesGuard>
|
||||
|
||||
@code {
|
||||
private readonly KhValidation _validation = new();
|
||||
private Dictionary<string, CodeRule> _rules = new(StringComparer.Ordinal);
|
||||
private Dictionary<string, CodeRule> _savedRules = new(StringComparer.Ordinal);
|
||||
private Dictionary<string, bool> _options = new(StringComparer.Ordinal);
|
||||
private Dictionary<string, bool> _savedOptions = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, string?> _previews = new(StringComparer.Ordinal);
|
||||
private string? _category;
|
||||
private string _tab = "codes";
|
||||
private bool _loaded;
|
||||
private bool _modified;
|
||||
private bool _busy;
|
||||
|
||||
private bool CanWrite => Session.Permissions.Allows(TableService.WritePermission);
|
||||
|
||||
private bool UniqueBarcode => _rules.TryGetValue("items", out var items) && items.UniqueBarcode;
|
||||
|
||||
private IReadOnlyList<KhTabItem> TabItems =>
|
||||
[
|
||||
new("codes", "key", T["CompanyPreferences.Tabs.codes"], _validation.Messages.Count is > 0 and var n ? n : null),
|
||||
new("autofill", "zap", T["CompanyPreferences.Tabs.autofill"], null),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.EnsureLoadedAsync();
|
||||
if (Session.Actor is { } actor && Session.Company?.Code is { } company && Session.Permissions.Allows(TableService.ReadPermission))
|
||||
{
|
||||
_category = (await Tables.ActiveAsync<ItemCategory>(actor, company)).OrderBy(c => c.Code, StringComparer.Ordinal).FirstOrDefault()?.Code ?? "GEN";
|
||||
Show(await Codes.RulesAsync(actor, company), await AutoFill.OptionsAsync(actor, company));
|
||||
await PreviewAllAsync();
|
||||
_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void Show(IReadOnlyList<CodeRule> rules, IReadOnlyDictionary<string, bool> options)
|
||||
{
|
||||
_rules = rules.ToDictionary(r => r.Key, StringComparer.Ordinal);
|
||||
_savedRules = new(_rules, StringComparer.Ordinal);
|
||||
_options = options.ToDictionary(o => o.Key, o => o.Value, StringComparer.Ordinal);
|
||||
_savedOptions = new(_options, StringComparer.Ordinal);
|
||||
_modified = false;
|
||||
_validation.Clear();
|
||||
}
|
||||
|
||||
private string HintOf(CodeRuleDefinition definition)
|
||||
{
|
||||
if (!License.IsModuleActive(definition.Module))
|
||||
{
|
||||
return T.Format("CompanyPreferences.ModuleOff", definition.Module);
|
||||
}
|
||||
|
||||
return _previews.GetValueOrDefault(definition.Key) is { } next ? T.Format("CompanyPreferences.Next", next) : T["CompanyPreferences.NextInvalid"];
|
||||
}
|
||||
|
||||
private static string GroupIcon(string group) => group switch
|
||||
{
|
||||
"parties" => "users",
|
||||
"items" => "box",
|
||||
_ => "target",
|
||||
};
|
||||
|
||||
private async Task ChangeMaskAsync(string key, string? mask)
|
||||
{
|
||||
_rules[key] = _rules[key] with { Mask = (mask ?? string.Empty).Trim() };
|
||||
_modified = true;
|
||||
await PreviewAsync(key);
|
||||
}
|
||||
|
||||
private void SetManual(string group, bool allow)
|
||||
{
|
||||
foreach (var definition in CodeRuleService.Definitions.Where(d => d.Group == group))
|
||||
{
|
||||
_rules[definition.Key] = _rules[definition.Key] with { AllowManual = allow };
|
||||
}
|
||||
|
||||
_modified = true;
|
||||
}
|
||||
|
||||
private void SetUniqueBarcode(bool unique)
|
||||
{
|
||||
_rules["items"] = _rules["items"] with { UniqueBarcode = unique };
|
||||
_modified = true;
|
||||
}
|
||||
|
||||
private void SetOption(string key, bool on)
|
||||
{
|
||||
if (!CanWrite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_options[key] = on;
|
||||
_modified = true;
|
||||
}
|
||||
|
||||
private async Task PreviewAllAsync()
|
||||
{
|
||||
foreach (var key in _rules.Keys.ToList())
|
||||
{
|
||||
await PreviewAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PreviewAsync(string key)
|
||||
{
|
||||
if (Session.Actor is { } actor && Session.Company?.Code is { } company)
|
||||
{
|
||||
var today = DateOnly.FromDateTime(Clock.GetLocalNow().DateTime);
|
||||
_previews[key] = await Codes.PreviewAsync(actor, company, _rules[key], today, _category);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UndoAsync()
|
||||
{
|
||||
Show([.. _savedRules.Values], _savedOptions);
|
||||
await PreviewAllAsync();
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_busy = true;
|
||||
_validation.Clear();
|
||||
try
|
||||
{
|
||||
var problems = CodeRuleService.Validate(_rules.Values);
|
||||
if (problems.Count > 0)
|
||||
{
|
||||
Refuse(problems.Select(p => ((string?)p.Field, p.Code)));
|
||||
return;
|
||||
}
|
||||
|
||||
var rules = await Codes.SaveAsync(actor, company, [.. _rules.Values]);
|
||||
var options = await AutoFill.SaveOptionsAsync(actor, company, _options);
|
||||
Show(rules, options);
|
||||
await PreviewAllAsync();
|
||||
Toasts.Show(ToastKind.Success, T["CompanyPreferences.Saved"], null);
|
||||
}
|
||||
catch (ValidationFailedException ex)
|
||||
{
|
||||
Refuse(ex.Errors.Select(TableValues.SplitError));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Refuse(IEnumerable<(string? Field, string Code)> errors)
|
||||
{
|
||||
foreach (var (field, code) in errors)
|
||||
{
|
||||
_validation.Add(field, T.Contains(code) ? T[code] : T["CompanyTables.UnknownError"]);
|
||||
}
|
||||
|
||||
_tab = "codes";
|
||||
Toasts.Show(ToastKind.Error, T["CompanyTables.NotSaved"], T["CompanyTables.FixFields"]);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
[
|
||||
("/tabelle/profilo-azienda", "building", "CompanyTables.Profile.Title", "CompanyTables.Profile.Hint"),
|
||||
("/tabelle/esercizi", "calendar", "CompanyTables.FiscalYears.Title", "CompanyTables.FiscalYears.Hint"),
|
||||
("/tabelle/preferenze", "settings", "CompanyPreferences.Title", "CompanyPreferences.Hint"),
|
||||
("/tabelle/cambi", "euro", "CompanyTables.Rates.Title", "CompanyTables.Rates.Hint"),
|
||||
];
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
@* An on/off option with its label and a short explanation (mockup 008). The whole row is the switch. *@
|
||||
<button type="button" class="kh-switch-row" role="switch" aria-checked="@Value" @onclick="() => ValueChanged.InvokeAsync(!Value)">
|
||||
<button type="button" class="kh-switch-row" role="switch" aria-checked="@(Value ? "true" : "false")" @onclick="() => ValueChanged.InvokeAsync(!Value)">
|
||||
<span class="grow">
|
||||
<span class="t">@Label</span>
|
||||
@if (!string.IsNullOrEmpty(Hint))
|
||||
|
||||
@@ -142,6 +142,8 @@ internal static class KhaemhatServices
|
||||
services.AddSingleton<CompanyProfileService>();
|
||||
services.AddSingleton<FiscalYearService>();
|
||||
services.AddSingleton<PaymentTermService>();
|
||||
services.AddSingleton<CodeRuleService>();
|
||||
services.AddSingleton<AutoFillService>();
|
||||
services.AddSingleton<ExchangeRateService>();
|
||||
services.AddHttpClient<EcbRatesClient>(c => c.Timeout = TimeSpan.FromSeconds(30));
|
||||
services.AddHttpClient<ViesClient>(c => c.Timeout = TimeSpan.FromSeconds(20));
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"CompanyPreferences": {
|
||||
"Title": "Preferenze azienda",
|
||||
"Heading": "Preferenze azienda · codici automatici e compilazione",
|
||||
"Hint": "Maschere dei codici automatici e campi che Khaemhat compila da solo.",
|
||||
"Saved": "Preferenze salvate",
|
||||
"Tabs": {
|
||||
"codes": "Codici automatici",
|
||||
"autofill": "Compilazione automatica"
|
||||
},
|
||||
"Groups": {
|
||||
"parties": "Anagrafiche",
|
||||
"items": "Articoli e cespiti",
|
||||
"crm": "CRM e servizi",
|
||||
"documents": "Documenti e contabilità"
|
||||
},
|
||||
"Rules": {
|
||||
"customers": "Clienti",
|
||||
"suppliers": "Fornitori",
|
||||
"leads": "Contatti e lead",
|
||||
"items": "Articoli",
|
||||
"assets": "Cespiti",
|
||||
"opportunities": "Opportunità",
|
||||
"tickets": "Ticket",
|
||||
"service-contracts": "Contratti di servizio",
|
||||
"interventions": "Interventi"
|
||||
},
|
||||
"Next": "Prossimo codice: {0}",
|
||||
"NextInvalid": "Maschera non valida",
|
||||
"ModuleOff": "Modulo {0} non attivo: la maschera vale quando lo attivi.",
|
||||
"AllowManual": "Consenti codice manuale",
|
||||
"UniqueBarcode": "Blocca duplicati per EAN",
|
||||
"Placeholders": "Segnaposto: {seq:0000} progressivo con le cifre indicate, {anno} anno, {categoria} codice della categoria (solo articoli). Il progressivo riparte ogni anno se la maschera contiene l'anno e va per categoria se contiene la categoria. Cambiare una maschera non riscrive i codici già assegnati.",
|
||||
"Numerators": "Fatture, protocollo degli acquisti, registrazioni e gli altri documenti sono numerati dai numeratori, per anno e sezionale.",
|
||||
"NumeratorsLink": "Apri i numeratori",
|
||||
"AutoFillHint": "Le opzioni spente non compilano nulla: i campi restano da scrivere a mano.",
|
||||
"Options": {
|
||||
"postal-code": {
|
||||
"_": "Comune, provincia e regione dal CAP",
|
||||
"Hint": "Scrivendo il CAP propone il comune; scrivendo il comune propone CAP e provincia."
|
||||
},
|
||||
"tax-code": {
|
||||
"_": "Codice fiscale dai dati anagrafici",
|
||||
"Hint": "Calcola il codice fiscale delle persone fisiche da nome, cognome, data e comune di nascita."
|
||||
},
|
||||
"vies": {
|
||||
"_": "Verifica P.IVA UE (VIES) al salvataggio",
|
||||
"Hint": "Interroga il servizio VIES della Commissione europea e salva l'esito sulla controparte."
|
||||
},
|
||||
"bank-from-iban": {
|
||||
"_": "Banca e BIC dall'IBAN",
|
||||
"Hint": "Legge ABI e CAB dall'IBAN e propone banca e BIC già usati per la stessa banca."
|
||||
},
|
||||
"ecb-rates": {
|
||||
"_": "Cambi BCE giornalieri",
|
||||
"Hint": "Scarica ogni giorno lavorativo i cambi di riferimento della Banca centrale europea."
|
||||
},
|
||||
"item-description": {
|
||||
"_": "Descrizione articolo nelle righe",
|
||||
"Hint": "Copia la descrizione dell'articolo nella riga del documento."
|
||||
},
|
||||
"last-price": {
|
||||
"_": "Ultimo prezzo praticato al cliente",
|
||||
"Hint": "Mostra nella riga l'ultimo prezzo fatto al cliente per lo stesso articolo."
|
||||
},
|
||||
"last-document": {
|
||||
"_": "Proponi ultimo documento simile",
|
||||
"Hint": "Un nuovo documento parte dalle righe dell'ultimo dello stesso tipo e cliente."
|
||||
},
|
||||
"delivery-date": {
|
||||
"_": "Data di consegna = data + lead time",
|
||||
"Hint": "Calcola la consegna prevista dal tempo di approvvigionamento, spostandola al primo giorno lavorativo."
|
||||
},
|
||||
"accounts": {
|
||||
"_": "Conti contabili da articolo, categoria e causale",
|
||||
"Hint": "Propone i conti di ricavo e di costo nelle registrazioni dei documenti."
|
||||
}
|
||||
}
|
||||
},
|
||||
"codes": {
|
||||
"mask": {
|
||||
"sequence": "La maschera deve contenere una volta il progressivo, ad esempio {seq:0000}.",
|
||||
"placeholder": "Segnaposto non riconosciuto: usa {seq:0000}, {anno} o {categoria}.",
|
||||
"character": "Nella maschera sono ammessi lettere, cifre e i caratteri - _ / .",
|
||||
"too-long": "I codici di questa maschera sono più lunghi di quanto ammette la tabella.",
|
||||
"category": "Questa tabella non ha categorie: togli {categoria}."
|
||||
},
|
||||
"manual": "Il codice viene assegnato in automatico: lascia il campo vuoto.",
|
||||
"category-required": "Il codice usa la categoria: scegli prima la categoria.",
|
||||
"too-long": "Il codice è più lungo di quanto ammette la tabella.",
|
||||
"exhausted": "Nessun codice libero trovato: controlla la maschera e i codici scritti a mano."
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,7 @@
|
||||
"_": "Tabelle azienda",
|
||||
"Profile": "Profilo azienda",
|
||||
"FiscalYears": "Esercizi e periodi",
|
||||
"Preferences": "Preferenze e codici automatici",
|
||||
"TaxCodes": "Codici IVA",
|
||||
"Payments": "Pagamenti",
|
||||
"Numerators": "Numeratori",
|
||||
|
||||
@@ -89,6 +89,7 @@ public static class MenuCatalog
|
||||
[
|
||||
Area("Shell.Menu.CompanyTables", "layers", "/tabelle", ModuleCodes.Core, "company.settings.read", null,
|
||||
("Shell.Menu.CompanyTables.Profile", "profilo-azienda"), ("Shell.Menu.CompanyTables.FiscalYears", "esercizi"),
|
||||
("Shell.Menu.CompanyTables.Preferences", "preferenze"),
|
||||
("Shell.Menu.CompanyTables.TaxCodes", "codici-iva"), ("Shell.Menu.CompanyTables.Payments", "pagamenti"),
|
||||
("Shell.Menu.CompanyTables.Numerators", "numeratori"), ("Shell.Menu.CompanyTables.Warehouses", "depositi"),
|
||||
("Shell.Menu.CompanyTables.Currencies", "valute"), ("Shell.Menu.CompanyTables.ExchangeRates", "cambi")),
|
||||
|
||||
Reference in new issue
Block a user