Customers, suppliers, prospects and leads live in one parties archive with a kind and a subject type (ADR 0029). A customer that also supplies carries is_also_supplier, so it shows in both radars with one code. - Three radars (/anagrafiche/clienti, /fornitori, /contatti) with search, quick filters and bulk disable/enable; the record has eight tabs (main data, addresses, contacts, terms, fiscal and SDI, banks, notes and attachments, history) on the MasterDataPage base. - PartyService saves the whole record in one transaction, checks it with the fiscal pack (VAT number, tax code, recipient code, country), treats a duplicate VAT number or a consumer without tax code as warnings, fills the default recipient code, runs VIES after commit for EU companies, and converts prospects/leads (new customer code, old one kept as previous_code) and suppliers (become customers that also supply). - Delete falls back to disable when the party is referenced. - DemoPartiesSeeder adds 3 salespeople and 21 parties with fictitious but formally valid identifiers; SeedAsync now runs demo seeders when asked. - Test host accepts service overrides so VIES can be stubbed. Docs: ADR 0029, wiki Anagrafiche and demo data pages, regenerated data model, CHANGELOG and STATUS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
940 lines
57 KiB
Plaintext
940 lines
57 KiB
Plaintext
@page "/anagrafiche/clienti/nuovo"
|
|
@page "/anagrafiche/clienti/{Id:long}"
|
|
@page "/anagrafiche/fornitori/nuovo"
|
|
@page "/anagrafiche/fornitori/{Id:long}"
|
|
@page "/anagrafiche/contatti/nuovo"
|
|
@page "/anagrafiche/contatti/{Id:long}"
|
|
@attribute [Authorize]
|
|
@inherits MasterDataPage<PartyRecord>
|
|
@using Khaemhat.Application.Audit
|
|
@using Khaemhat.Application.Parties
|
|
@using Khaemhat.Application.Security
|
|
@using Khaemhat.Application.Tables
|
|
@using Khaemhat.Core.Common
|
|
@using Khaemhat.Core.Parties
|
|
@using Khaemhat.Fiscal.Abstractions
|
|
@using Khaemhat.Infrastructure.Http
|
|
@using Khaemhat.Web.Parties
|
|
@using Khaemhat.Web.Tables
|
|
@inject ShellSession Session
|
|
@inject PartyService Parties
|
|
@inject TableService Tables
|
|
@inject AutoFillService AutoFill
|
|
@inject AttachmentService Attachments
|
|
|
|
@* The record of a party (SPEC §11.2, mockups 014-016): header with identity and conditions, tabs for main data,
|
|
addresses, contacts, terms, fiscal data and e-invoice, banks, notes with attachments, history. The checks are those
|
|
of PartyService: errors stop the save and open the tab of the first one, warnings are shown after saving. *@
|
|
<KhPageTitle Text="@PageTitle" Icon="@KindIcon" />
|
|
|
|
@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["Parties.NoCompany"]</h1></div>
|
|
}
|
|
else if (!Session.Permissions.Allows(PartyService.ReadPermission))
|
|
{
|
|
<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 (Record is null)
|
|
{
|
|
<div class="kh-message">
|
|
<KhIcon Name="alert" Class="lg" />
|
|
<h1>@T["Parties.NotFound"]</h1>
|
|
<a class="btn" href="@PartyScreens.RadarUrl(_archive)">@T["Parties.Archives." + _archive]</a>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<KhRecordLayout Page="this">
|
|
<Heading>
|
|
<KhDocHead KindIcon="@KindIcon" KindLabel="@T["Parties.Kinds." + P.Kind]" Number="@(P.Code.Length > 0 ? P.Code : T["Parties.CodeAuto"])"
|
|
PartyName="@(P.Name.Length > 0 ? P.Name : T["Parties.NewTitle"])" PartyLines="HeadLines">
|
|
<Facts>
|
|
<span>@T["Parties.SubjectTypes." + P.SubjectType]</span>
|
|
@if (P.PreviousCode is { } previous)
|
|
{
|
|
<span>· @T["Parties.Fields.PreviousCode"] <b>@previous</b></span>
|
|
}
|
|
</Facts>
|
|
<State>
|
|
@if (P.Disabled)
|
|
{
|
|
<KhBadge Tone="KhTone.Neutral">@T["Parties.States.Disabled"]</KhBadge>
|
|
}
|
|
else if (Record.Sales.Blocked)
|
|
{
|
|
<KhBadge Tone="KhTone.Error">@T["Parties.States.Blocked"]</KhBadge>
|
|
}
|
|
else if (!IsNew)
|
|
{
|
|
<KhBadge Tone="KhTone.Ok">@T["Parties.States.Active"]</KhBadge>
|
|
}
|
|
@if (P.Kind == PartyKind.Customer && P.IsAlsoSupplier)
|
|
{
|
|
<KhBadge Tone="KhTone.Accent">@T["Parties.States.AlsoSupplier"]</KhBadge>
|
|
}
|
|
@if (P.IsDemo)
|
|
{
|
|
<KhBadge Tone="KhTone.Info">@T["Parties.States.Demo"]</KhBadge>
|
|
}
|
|
@if (IsModified)
|
|
{
|
|
<KhBadge Tone="KhTone.Warning">@T["CompanyTables.Modified"]</KhBadge>
|
|
}
|
|
</State>
|
|
<Chips>
|
|
@if (PartyScreens.Describe(_lookups.PaymentTerms, PaymentTermId, full: true) is { } payment)
|
|
{
|
|
<KhChip Icon="coins" Text="@T["Parties.Fields.PaymentTermId"]" Value="@payment" />
|
|
}
|
|
@if (P.IsCustomer && PartyScreens.Describe(_lookups.PriceLists, Record.Sales.PriceListId) is { } list)
|
|
{
|
|
<KhChip Icon="tag" Text="@T["Parties.Fields.PriceListId"]" Value="@list" />
|
|
}
|
|
@if (PartyScreens.Describe(_lookups.Salespeople, P.SalespersonId, full: true) is { } salesperson)
|
|
{
|
|
<KhChip Icon="user" Text="@T["Parties.Fields.SalespersonId"]" Value="@salesperson" />
|
|
}
|
|
@if (P.VatCheck != VatCheckStatus.None)
|
|
{
|
|
<KhChip Icon="@(P.VatCheck == VatCheckStatus.Valid ? "shield-check" : "alert")" Text="VIES" Value="@T["Parties.Vies." + P.VatCheck]"
|
|
Tone="@(P.VatCheck == VatCheckStatus.Valid ? KhTone.Ok : KhTone.Warning)"
|
|
Title="@(P.VatCheckedAt is { } at ? T.Format("Parties.Vies.Checked", T.Date(DateOnly.FromDateTime(at.ToLocalTime()))) : null)" />
|
|
}
|
|
@if (Record.Fiscal.SplitPayment)
|
|
{
|
|
<KhChip Icon="file-check" Text="@T["Parties.Fields.SplitPayment"]" />
|
|
}
|
|
</Chips>
|
|
</KhDocHead>
|
|
</Heading>
|
|
<ChildContent>
|
|
<KhForm Validation="Validation" ReadOnly="IsReadOnly" Layout="KhFormLayout.Groups" @ref="Form">
|
|
@switch (ActiveTab)
|
|
{
|
|
case PartyScreens.Tabs.Main:
|
|
<KhFieldGroup Title="@T["Parties.Groups.Identity"]" Icon="user">
|
|
<KhTextBox Label="@T["Parties.Fields.Code"]" Name="Code" Value="@P.Code" ValueChanged="v => Change(() => P.Code = v ?? string.Empty)" Mono="true"
|
|
Placeholder="@T["Parties.CodeAuto"]" Span="4" MaxLength="30" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.Kind"]" Name="Kind" Options="KindChoices" Value="@P.Kind.ToString()" Span="4"
|
|
Disabled="@(!IsNew || _archive != PartyArchive.Contacts)" ValueChanged="SetKind" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.SubjectType"]" Name="SubjectType" Options="SubjectChoices" Value="@P.SubjectType.ToString()" Span="4"
|
|
ValueChanged="SetSubjectAsync" />
|
|
@if (P.SubjectType == SubjectType.Person)
|
|
{
|
|
<KhTextBox Label="@T["Parties.Fields.LastName"]" Name="LastName" Value="@P.LastName" ValueChanged="v => Change(() => P.LastName = v)" MaxLength="80" />
|
|
<KhTextBox Label="@T["Parties.Fields.FirstName"]" Name="FirstName" Value="@P.FirstName" ValueChanged="v => Change(() => P.FirstName = v)" MaxLength="80" />
|
|
}
|
|
<KhTextBox Label="@T["Parties.Fields.Name"]" Name="Name" Value="@P.Name" ValueChanged="v => Change(() => P.Name = v ?? string.Empty)" Span="12" MaxLength="200"
|
|
Required="@(P.SubjectType != SubjectType.Person)" />
|
|
<KhTextBox Label="@T["Parties.Fields.VatNumber"]" Name="VatNumber" Value="@P.VatNumber" ValueChanged="v => Change(() => P.VatNumber = v)" Mono="true" Span="4" MaxLength="30" />
|
|
<KhTextBox Label="@T["Parties.Fields.TaxCode"]" Name="TaxCode" Value="@P.TaxCode" ValueChanged="v => Change(() => P.TaxCode = v)" Mono="true" Span="4" MaxLength="30" />
|
|
<KhTextBox Label="@T["Parties.Fields.Rea"]" Name="Rea" Value="@P.Rea" ValueChanged="v => Change(() => P.Rea = v)" Span="4" MaxLength="20" />
|
|
<KhTextBox Label="@T["Parties.Fields.FiscalName"]" Name="FiscalName" Value="@P.FiscalName" ValueChanged="v => Change(() => P.FiscalName = v)" Span="12" MaxLength="200" />
|
|
</KhFieldGroup>
|
|
@if (P.SubjectType == SubjectType.Person && !IsReadOnly)
|
|
{
|
|
<KhFieldGroup Title="@T["Parties.Groups.Birth"]" Icon="calendar">
|
|
<KhDateBox Label="@T["Parties.Fields.BirthDate"]" Name="BirthDate" @bind-Value="_birthDate" Span="4" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.Sex"]" Name="Sex" Options="SexChoices" @bind-Value="_sex" Span="2" />
|
|
<KhTextBox Label="@T["Parties.Fields.BirthPlace"]" Name="BirthPlace" @bind-Value="_birthPlace" Span="6" />
|
|
<div class="c12">
|
|
<button type="button" class="btn" @onclick="ComputeTaxCodeAsync"><KhIcon Name="refresh" /> @T["Parties.Actions.TaxCode"]</button>
|
|
</div>
|
|
</KhFieldGroup>
|
|
}
|
|
<KhFieldGroup Title="@T["Parties.Groups.Office"]" Icon="building">
|
|
<KhTextBox Label="@T["Parties.Fields.Address"]" Name="Address" Value="@P.Address" ValueChanged="v => Change(() => P.Address = v)" Span="9" MaxLength="200" />
|
|
<KhTextBox Label="@T["Parties.Fields.StreetNumber"]" Name="StreetNumber" Value="@P.StreetNumber" ValueChanged="v => Change(() => P.StreetNumber = v)" Span="3" MaxLength="20" />
|
|
<KhTextBox Label="@T["Parties.Fields.PostalCode"]" Name="PostalCode" Value="@P.PostalCode" ValueChanged="SetPostalCodeAsync" Mono="true" Span="3" MaxLength="10" />
|
|
<KhTextBox Label="@T["Parties.Fields.City"]" Name="City" Value="@P.City" ValueChanged="SetCityAsync" Span="6" MaxLength="100" />
|
|
<KhTextBox Label="@T["Parties.Fields.Province"]" Name="Province" Value="@P.Province" ValueChanged="v => Change(() => P.Province = v)" Span="3" MaxLength="10" />
|
|
@if (_places.Count > 1)
|
|
{
|
|
<div class="c12 kh-places">
|
|
<span class="muted sm">@T.Format("Parties.Actions.Places", _places.Count)</span>
|
|
@foreach (var place in _places)
|
|
{
|
|
<button type="button" class="btn sm" @onclick="() => PickPlace(place)">@place.Name (@place.ProvinceCode)</button>
|
|
}
|
|
</div>
|
|
}
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CountryCode"]" Name="CountryCode" Options="_lookups.Countries" Value="@P.CountryCode" Span="6"
|
|
ValueChanged="v => Change(() => P.CountryCode = v ?? string.Empty)" Required="true" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Reach"]" Icon="phone">
|
|
<KhTextBox Label="@T["Parties.Fields.Phone"]" Name="Phone" Value="@P.Phone" ValueChanged="v => Change(() => P.Phone = v)" Type="tel" MaxLength="40" />
|
|
<KhTextBox Label="@T["Parties.Fields.Email"]" Name="Email" Value="@P.Email" ValueChanged="v => Change(() => P.Email = v)" Type="email" MaxLength="200" />
|
|
<KhTextBox Label="@T["Parties.Fields.Pec"]" Name="Pec" Value="@P.Pec" ValueChanged="v => Change(() => P.Pec = v)" Type="email" MaxLength="200" />
|
|
<KhTextBox Label="@T["Parties.Fields.Website"]" Name="Website" Value="@P.Website" ValueChanged="v => Change(() => P.Website = v)" MaxLength="200" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Classification"]" Icon="tag" Wide="true">
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CategoryId"]" Name="CategoryId" Options="_lookups.Categories" Empty="" Span="4"
|
|
Value="@PartyScreens.Text(P.CategoryId)" ValueChanged="v => Change(() => P.CategoryId = PartyScreens.Id(v))" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.SalespersonId"]" Name="SalespersonId" Options="_lookups.Salespeople" Empty="" Span="4"
|
|
Value="@PartyScreens.Text(P.SalespersonId)" ValueChanged="v => Change(() => P.SalespersonId = PartyScreens.Id(v))" />
|
|
<KhDateBox Label="@T["Parties.Fields.Since"]" Name="Since" Value="P.Since" ValueChanged="v => Change(() => P.Since = v)" Span="4" />
|
|
<KhTextBox Label="@T["Parties.Fields.Language"]" Name="Language" Value="@P.Language" ValueChanged="v => Change(() => P.Language = v ?? string.Empty)" Span="2" MaxLength="5" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CurrencyCode"]" Name="CurrencyCode" Options="_lookups.Currencies" Value="@P.CurrencyCode" Span="4"
|
|
ValueChanged="v => Change(() => P.CurrencyCode = v ?? string.Empty)" />
|
|
<KhCheck Label="@T["Parties.Fields.PrivacyAccepted"]" Name="PrivacyAccepted" Value="P.PrivacyAccepted" ValueChanged="v => Change(() => P.PrivacyAccepted = v)" Span="3" />
|
|
<KhCheck Label="@T["Parties.Fields.Marketing"]" Name="Marketing" Value="P.Marketing" ValueChanged="v => Change(() => P.Marketing = v)" Span="3" />
|
|
@if (P.Kind == PartyKind.Customer)
|
|
{
|
|
<KhCheck Label="@T["Parties.Fields.IsAlsoSupplier"]" Name="IsAlsoSupplier" Value="P.IsAlsoSupplier" ValueChanged="v => Change(() => P.IsAlsoSupplier = v)" Span="4" />
|
|
}
|
|
<KhCheck Label="@T["Parties.Fields.Disabled"]" Name="Disabled" Value="P.Disabled" ValueChanged="v => Change(() => P.Disabled = v)" Span="4" />
|
|
</KhFieldGroup>
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Addresses:
|
|
@for (var i = 0; i < Record.Addresses.Count; i++)
|
|
{
|
|
var index = i;
|
|
var a = Record.Addresses[i];
|
|
<KhFieldGroup Title="@(string.IsNullOrWhiteSpace(a.Name) ? T["Parties.AddressKinds." + a.Kind] : a.Name)" Icon="pin" Wide="true">
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.AddressKind"]" Name="@Key("Addresses", index, "Kind")" Options="AddressKindChoices" Value="@a.Kind.ToString()" Span="3"
|
|
ValueChanged="v => SetAddressKind(a, v)" />
|
|
<KhTextBox Label="@T["Parties.Fields.AddressName"]" Name="@Key("Addresses", index, "Name")" Value="@a.Name" ValueChanged="v => Change(() => a.Name = v ?? string.Empty)" Span="6" Required="true" MaxLength="200" />
|
|
<KhCheck Label="@T["Parties.Fields.IsDefault"]" Name="@Key("Addresses", index, "IsDefault")" Value="a.IsDefault" ValueChanged="v => Change(() => a.IsDefault = v)" Span="3" />
|
|
<KhTextBox Label="@T["Parties.Fields.Address"]" Name="@Key("Addresses", index, "Address")" Value="@a.Address" ValueChanged="v => Change(() => a.Address = v)" Span="5" MaxLength="200" />
|
|
<KhTextBox Label="@T["Parties.Fields.StreetNumber"]" Name="@Key("Addresses", index, "StreetNumber")" Value="@a.StreetNumber" ValueChanged="v => Change(() => a.StreetNumber = v)" Span="1" MaxLength="20" />
|
|
<KhTextBox Label="@T["Parties.Fields.PostalCode"]" Name="@Key("Addresses", index, "PostalCode")" Value="@a.PostalCode" ValueChanged="v => Change(() => a.PostalCode = v)" Mono="true" Span="2" MaxLength="10" />
|
|
<KhTextBox Label="@T["Parties.Fields.City"]" Name="@Key("Addresses", index, "City")" Value="@a.City" ValueChanged="v => Change(() => a.City = v)" Span="2" MaxLength="100" />
|
|
<KhTextBox Label="@T["Parties.Fields.Province"]" Name="@Key("Addresses", index, "Province")" Value="@a.Province" ValueChanged="v => Change(() => a.Province = v)" Span="1" MaxLength="10" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CountryCode"]" Name="@Key("Addresses", index, "CountryCode")" Options="_lookups.Countries" Value="@a.CountryCode" Span="1"
|
|
ValueChanged="v => Change(() => a.CountryCode = v ?? string.Empty)" />
|
|
<KhTextBox Label="@T["Parties.Fields.Notes"]" Name="@Key("Addresses", index, "Notes")" Value="@a.Notes" ValueChanged="v => Change(() => a.Notes = v)" Span="10" />
|
|
@if (!IsReadOnly)
|
|
{
|
|
<div class="c2 kh-endrow">
|
|
<button type="button" class="btn danger" @onclick="() => Remove(Record.Addresses, index)"><KhIcon Name="trash" /> @T["Parties.Actions.Remove"]</button>
|
|
</div>
|
|
}
|
|
</KhFieldGroup>
|
|
}
|
|
<DetailFooter Empty="@(Record.Addresses.Count == 0 ? T["Parties.Empty.Addresses"] : null)" CanAdd="!IsReadOnly" AddText="@T["Parties.Actions.AddAddress"]"
|
|
OnAdd="() => Add(Record.Addresses, new PartyAddress { CountryCode = P.CountryCode, Kind = PartyAddressKind.Delivery, IsDefault = Record.Addresses.Count == 0 })" />
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Contacts:
|
|
@for (var i = 0; i < Record.Contacts.Count; i++)
|
|
{
|
|
var index = i;
|
|
var c = Record.Contacts[i];
|
|
<KhFieldGroup Title="@(string.IsNullOrWhiteSpace(c.Name) ? T["Parties.Actions.AddContact"] : c.Name)" Icon="user" Wide="true">
|
|
<KhTextBox Label="@T["Parties.Fields.ContactName"]" Name="@Key("Contacts", index, "Name")" Value="@c.Name" ValueChanged="v => Change(() => c.Name = v ?? string.Empty)" Span="4" Required="true" MaxLength="120" />
|
|
<KhTextBox Label="@T["Parties.Fields.Role"]" Name="@Key("Contacts", index, "Role")" Value="@c.Role" ValueChanged="v => Change(() => c.Role = v)" Span="3" MaxLength="80" />
|
|
<KhTextBox Label="@T["Parties.Fields.Phone"]" Name="@Key("Contacts", index, "Phone")" Value="@c.Phone" ValueChanged="v => Change(() => c.Phone = v)" Type="tel" Span="2" MaxLength="40" />
|
|
<KhTextBox Label="@T["Parties.Fields.Mobile"]" Name="@Key("Contacts", index, "Mobile")" Value="@c.Mobile" ValueChanged="v => Change(() => c.Mobile = v)" Type="tel" Span="3" MaxLength="40" />
|
|
<KhTextBox Label="@T["Parties.Fields.Email"]" Name="@Key("Contacts", index, "Email")" Value="@c.Email" ValueChanged="v => Change(() => c.Email = v)" Type="email" Span="4" MaxLength="200" />
|
|
<KhCheck Label="@T["Parties.Fields.MainContact"]" Name="@Key("Contacts", index, "IsDefault")" Value="c.IsDefault" ValueChanged="v => Change(() => c.IsDefault = v)" Span="3" />
|
|
<KhTextBox Label="@T["Parties.Fields.Notes"]" Name="@Key("Contacts", index, "Notes")" Value="@c.Notes" ValueChanged="v => Change(() => c.Notes = v)" Span="3" />
|
|
@if (!IsReadOnly)
|
|
{
|
|
<div class="c2 kh-endrow">
|
|
<button type="button" class="btn danger" @onclick="() => Remove(Record.Contacts, index)"><KhIcon Name="trash" /> @T["Parties.Actions.Remove"]</button>
|
|
</div>
|
|
}
|
|
</KhFieldGroup>
|
|
}
|
|
<DetailFooter Empty="@(Record.Contacts.Count == 0 ? T["Parties.Empty.Contacts"] : null)" CanAdd="!IsReadOnly" AddText="@T["Parties.Actions.AddContact"]"
|
|
OnAdd="() => Add(Record.Contacts, new PartyContact { IsDefault = Record.Contacts.Count == 0 })" />
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Terms:
|
|
@if (!P.IsCustomer && !P.IsSupplier)
|
|
{
|
|
<p class="muted kh-pad"><KhIcon Name="info" /> @T["Parties.NoTerms"]</p>
|
|
}
|
|
@if (P.IsCustomer)
|
|
{
|
|
var s = Record.Sales;
|
|
<KhFieldGroup Title="@T["Parties.Groups.Sales"]" Icon="cart">
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.PaymentTermId"]" Name="Sales.PaymentTermId" Options="_lookups.PaymentTerms" Empty="" Span="12"
|
|
Value="@PartyScreens.Text(s.PaymentTermId)" ValueChanged="v => Change(() => s.PaymentTermId = PartyScreens.Id(v))" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.PriceListId"]" Name="Sales.PriceListId" Options="_lookups.PriceLists" Empty=""
|
|
Value="@PartyScreens.Text(s.PriceListId)" ValueChanged="v => Change(() => s.PriceListId = PartyScreens.Id(v))" />
|
|
<KhNumberBox Label="@T["Parties.Fields.Discount1"]" Name="Sales.Discount1" Value="s.Discount1" ValueChanged="v => Change(() => s.Discount1 = v)" Min="0" Max="100" Span="3" />
|
|
<KhNumberBox Label="@T["Parties.Fields.Discount2"]" Name="Sales.Discount2" Value="s.Discount2" ValueChanged="v => Change(() => s.Discount2 = v)" Min="0" Max="100" Span="3" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CompanyBankAccountId"]" Name="Sales.CompanyBankAccountId" Options="_lookups.BankAccounts" Empty=""
|
|
Value="@PartyScreens.Text(s.CompanyBankAccountId)" ValueChanged="v => Change(() => s.CompanyBankAccountId = PartyScreens.Id(v))" />
|
|
<KhNumberBox Label="@T["Parties.Fields.CreditLimit"]" Name="Sales.CreditLimit" Value="s.CreditLimit" ValueChanged="v => Change(() => s.CreditLimit = v)" Min="0" Span="3" />
|
|
<KhCheck Label="@T["Parties.Fields.Blocked"]" Name="Sales.Blocked" Value="s.Blocked" ValueChanged="v => Change(() => s.Blocked = v)" Span="3" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Delivery"]" Icon="truck">
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.CarrierId"]" Name="Sales.CarrierId" Options="_lookups.Carriers" Empty=""
|
|
Value="@PartyScreens.Text(s.CarrierId)" ValueChanged="v => Change(() => s.CarrierId = PartyScreens.Id(v))" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.ShippingTermId"]" Name="Sales.ShippingTermId" Options="_lookups.ShippingTerms" Empty=""
|
|
Value="@PartyScreens.Text(s.ShippingTermId)" ValueChanged="v => Change(() => s.ShippingTermId = PartyScreens.Id(v))" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.WarehouseId"]" Name="Sales.WarehouseId" Options="_lookups.Warehouses" Empty=""
|
|
Value="@PartyScreens.Text(s.WarehouseId)" ValueChanged="v => Change(() => s.WarehouseId = PartyScreens.Id(v))" />
|
|
<KhNumberBox Label="@T["Parties.Fields.InvoiceDay"]" Name="Sales.InvoiceDay" Value="s.InvoiceDay" ValueChanged="v => Change(() => s.InvoiceDay = (int?)v)" Min="1" Max="31" Decimals="0" Span="3" />
|
|
<KhCheck Label="@T["Parties.Fields.GroupDeliveryNotes"]" Name="Sales.GroupDeliveryNotes" Value="s.GroupDeliveryNotes" ValueChanged="v => Change(() => s.GroupDeliveryNotes = v)" Span="3" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.SendDocuments"]" Name="Sales.SendDocuments" Options="DeliveryChoices" Value="@s.SendDocuments.ToString()" Span="4"
|
|
ValueChanged="v => SetDelivery(s, v)" />
|
|
<KhTextBox Label="@T["Parties.Fields.DocumentsEmail"]" Name="Sales.DocumentsEmail" Value="@s.DocumentsEmail" ValueChanged="v => Change(() => s.DocumentsEmail = v)" Type="email" Span="8" MaxLength="200" />
|
|
</KhFieldGroup>
|
|
}
|
|
@if (P.IsSupplier)
|
|
{
|
|
var u = Record.Purchase;
|
|
<KhFieldGroup Title="@T["Parties.Groups.Purchase"]" Icon="box" Wide="true">
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.PaymentTermId"]" Name="Purchase.PaymentTermId" Options="_lookups.PaymentTerms" Empty="" Span="4"
|
|
Value="@PartyScreens.Text(u.PaymentTermId)" ValueChanged="v => Change(() => u.PaymentTermId = PartyScreens.Id(v))" />
|
|
<KhNumberBox Label="@T["Parties.Fields.LeadTimeDays"]" Name="Purchase.LeadTimeDays" Value="u.LeadTimeDays" ValueChanged="v => Change(() => u.LeadTimeDays = (int?)v)" Min="0" Decimals="0" Span="2" />
|
|
<KhNumberBox Label="@T["Parties.Fields.MinimumOrder"]" Name="Purchase.MinimumOrder" Value="u.MinimumOrder" ValueChanged="v => Change(() => u.MinimumOrder = v)" Min="0" Span="2" />
|
|
<KhNumberBox Label="@T["Parties.Fields.Discount"]" Name="Purchase.Discount" Value="u.Discount" ValueChanged="v => Change(() => u.Discount = v)" Min="0" Max="100" Span="2" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.ShippingTermId"]" Name="Purchase.ShippingTermId" Options="_lookups.ShippingTerms" Empty="" Span="2"
|
|
Value="@PartyScreens.Text(u.ShippingTermId)" ValueChanged="v => Change(() => u.ShippingTermId = PartyScreens.Id(v))" />
|
|
<KhTextBox Label="@T["Parties.Fields.VatRegisterCode"]" Name="Purchase.VatRegisterCode" Value="@u.VatRegisterCode" ValueChanged="v => Change(() => u.VatRegisterCode = v)" Span="2" MaxLength="10" />
|
|
<KhTextBox Label="@T["Parties.Fields.CostAccountCode"]" Name="Purchase.CostAccountCode" Value="@u.CostAccountCode" ValueChanged="v => Change(() => u.CostAccountCode = v)" Mono="true" Span="3" MaxLength="20" />
|
|
<KhTextBox Label="@T["Parties.Fields.OrdersEmail"]" Name="Purchase.OrdersEmail" Value="@u.OrdersEmail" ValueChanged="v => Change(() => u.OrdersEmail = v)" Type="email" Span="7" MaxLength="200" />
|
|
</KhFieldGroup>
|
|
}
|
|
@if (P.IsCustomer || P.IsSupplier)
|
|
{
|
|
<KhFieldGroup Title="@T["Parties.Groups.Accounts"]" Icon="book" Wide="true">
|
|
@if (P.IsCustomer)
|
|
{
|
|
<KhTextBox Label="@T["Parties.Fields.CustomerAccountCode"]" Name="CustomerAccountCode" Value="@P.CustomerAccountCode" ValueChanged="v => Change(() => P.CustomerAccountCode = v)" Mono="true" Span="3" MaxLength="20" />
|
|
}
|
|
@if (P.IsSupplier)
|
|
{
|
|
<KhTextBox Label="@T["Parties.Fields.SupplierAccountCode"]" Name="SupplierAccountCode" Value="@P.SupplierAccountCode" ValueChanged="v => Change(() => P.SupplierAccountCode = v)" Mono="true" Span="3" MaxLength="20" />
|
|
}
|
|
<p class="muted sm c6">@T["Parties.AccountsHint"]</p>
|
|
</KhFieldGroup>
|
|
<p class="muted kh-pad sm"><KhIcon Name="info" /> @T["Parties.TermsHint"]</p>
|
|
}
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Fiscal:
|
|
var f = Record.Fiscal;
|
|
<KhFieldGroup Title="@T["Parties.Groups.EInvoice"]" Icon="send">
|
|
<KhTextBox Label="@T["Parties.Fields.RecipientCode"]" Name="Fiscal.RecipientCode" Value="@f.RecipientCode" ValueChanged="v => Change(() => f.RecipientCode = v)" Mono="true" Span="4" MaxLength="7" />
|
|
<KhTextBox Label="@T["Parties.Fields.RecipientPec"]" Name="Fiscal.RecipientPec" Value="@f.RecipientPec" ValueChanged="v => Change(() => f.RecipientPec = v)" Type="email" Span="8" MaxLength="200" />
|
|
<KhTextBox Label="@T["Parties.Fields.AdministrationReference"]" Name="Fiscal.AdministrationReference" Value="@f.AdministrationReference" ValueChanged="v => Change(() => f.AdministrationReference = v)" Span="6" MaxLength="20" />
|
|
<KhTextBox Label="@T["Parties.Fields.OurCode"]" Name="Fiscal.OurCode" Value="@f.OurCode" ValueChanged="v => Change(() => f.OurCode = v)" Span="6" MaxLength="40" />
|
|
<KhCheck Label="@T["Parties.Fields.AttachPdf"]" Name="Fiscal.AttachPdf" Value="f.AttachPdf" ValueChanged="v => Change(() => f.AttachPdf = v)" />
|
|
<KhCheck Label="@T["Parties.Fields.SendCopy"]" Name="Fiscal.SendCopy" Value="f.SendCopy" ValueChanged="v => Change(() => f.SendCopy = v)" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Vat"]" Icon="euro">
|
|
<KhCheck Label="@T["Parties.Fields.SplitPayment"]" Name="Fiscal.SplitPayment" Value="f.SplitPayment" ValueChanged="v => Change(() => f.SplitPayment = v)" />
|
|
<KhCheck Label="@T["Parties.Fields.ReverseCharge"]" Name="Fiscal.ReverseCharge" Value="f.ReverseCharge" ValueChanged="v => Change(() => f.ReverseCharge = v)" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.TaxCodeId"]" Name="Fiscal.TaxCodeId" Options="_lookups.TaxCodes" Empty="" Span="12"
|
|
Value="@PartyScreens.Text(f.TaxCodeId)" ValueChanged="v => Change(() => f.TaxCodeId = PartyScreens.Id(v))" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.Exigibility"]" Name="Fiscal.Exigibility" Options="ExigibilityChoices" Empty="" Value="@f.Exigibility"
|
|
ValueChanged="v => Change(() => f.Exigibility = v)" Disabled="f.SplitPayment" />
|
|
<KhCheck Label="@T["Parties.Fields.StampDutyCharged"]" Name="Fiscal.StampDutyCharged" Value="f.StampDutyCharged" ValueChanged="v => Change(() => f.StampDutyCharged = v)" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Withholding"]" Icon="coins">
|
|
<KhCheck Label="@T["Parties.Fields.Withholding"]" Name="Fiscal.Withholding" Value="f.Withholding" ValueChanged="v => Change(() => f.Withholding = v)" Span="4" />
|
|
<KhNumberBox Label="@T["Parties.Fields.WithholdingRate"]" Name="Fiscal.WithholdingRate" Value="f.WithholdingRate" ValueChanged="v => Change(() => f.WithholdingRate = v)" Min="0" Max="100" Span="4" />
|
|
<KhTextBox Label="@T["Parties.Fields.WithholdingReason"]" Name="Fiscal.WithholdingReason" Value="@f.WithholdingReason" ValueChanged="v => Change(() => f.WithholdingReason = v)" Mono="true" Span="4" MaxLength="4" />
|
|
<KhTextBox Label="@T["Parties.Fields.PensionFund"]" Name="Fiscal.PensionFund" Value="@f.PensionFund" ValueChanged="v => Change(() => f.PensionFund = v)" Mono="true" Span="4" MaxLength="4" />
|
|
<KhNumberBox Label="@T["Parties.Fields.PensionFundRate"]" Name="Fiscal.PensionFundRate" Value="f.PensionFundRate" ValueChanged="v => Change(() => f.PensionFundRate = v)" Min="0" Max="100" Span="4" />
|
|
<KhCheck Label="@T["Parties.Fields.Enasarco"]" Name="Fiscal.Enasarco" Value="f.Enasarco" ValueChanged="v => Change(() => f.Enasarco = v)" Span="4" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Codes"]" Icon="key">
|
|
<KhTextBox Label="@T["Parties.Fields.Gln"]" Name="Fiscal.Gln" Value="@f.Gln" ValueChanged="v => Change(() => f.Gln = v)" Mono="true" MaxLength="13" />
|
|
<KhTextBox Label="@T["Parties.Fields.Eori"]" Name="Fiscal.Eori" Value="@f.Eori" ValueChanged="v => Change(() => f.Eori = v)" Mono="true" MaxLength="17" />
|
|
</KhFieldGroup>
|
|
<KhFieldGroup Title="@T["Parties.Groups.Intent"]" Icon="file-check" Wide="true">
|
|
<KhCheck Label="@T["Parties.Fields.IntentActive"]" Name="Fiscal.IntentActive" Value="f.IntentActive" ValueChanged="v => Change(() => f.IntentActive = v)" Span="3" />
|
|
<KhTextBox Label="@T["Parties.Fields.IntentNumber"]" Name="Fiscal.IntentNumber" Value="@f.IntentNumber" ValueChanged="v => Change(() => f.IntentNumber = v)" Span="3" MaxLength="40" />
|
|
<KhDateBox Label="@T["Parties.Fields.IntentDate"]" Name="Fiscal.IntentDate" Value="f.IntentDate" ValueChanged="v => Change(() => f.IntentDate = v)" Span="2" />
|
|
<KhTextBox Label="@T["Parties.Fields.IntentProtocol"]" Name="Fiscal.IntentProtocol" Value="@f.IntentProtocol" ValueChanged="v => Change(() => f.IntentProtocol = v)" Mono="true" Span="4" MaxLength="40" />
|
|
<KhSelect TValue="string" Label="@T["Parties.Fields.IntentTaxCodeId"]" Name="Fiscal.IntentTaxCodeId" Options="_lookups.TaxCodes" Empty="" Span="4"
|
|
Value="@PartyScreens.Text(f.IntentTaxCodeId)" ValueChanged="v => Change(() => f.IntentTaxCodeId = PartyScreens.Id(v))" />
|
|
<KhNumberBox Label="@T["Parties.Fields.IntentCeiling"]" Name="Fiscal.IntentCeiling" Value="f.IntentCeiling" ValueChanged="v => Change(() => f.IntentCeiling = v)" Min="0" Span="2" />
|
|
<KhNumberBox Label="@T["Parties.Fields.IntentUsed"]" Name="Fiscal.IntentUsed" Value="f.IntentUsed" ReadOnly="true" Span="2" />
|
|
<KhNumberBox Label="@T["Parties.Fields.IntentRemaining"]" Name="Fiscal.IntentRemaining" Value="f.IntentRemaining" ReadOnly="true" Span="2" />
|
|
<KhDateBox Label="@T["Parties.Fields.IntentFrom"]" Name="Fiscal.IntentFrom" Value="f.IntentFrom" ValueChanged="v => Change(() => f.IntentFrom = v)" Span="1" />
|
|
<KhDateBox Label="@T["Parties.Fields.IntentTo"]" Name="Fiscal.IntentTo" Value="f.IntentTo" ValueChanged="v => Change(() => f.IntentTo = v)" Span="1" />
|
|
<p class="muted sm c12">@T["Parties.IntentHint"]</p>
|
|
</KhFieldGroup>
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Banks:
|
|
@for (var i = 0; i < Record.BankAccounts.Count; i++)
|
|
{
|
|
var index = i;
|
|
var b = Record.BankAccounts[i];
|
|
<KhFieldGroup Title="@(b.BankName ?? T["Parties.Fields.Iban"])" Icon="euro" Wide="true">
|
|
<KhTextBox Label="@T["Parties.Fields.Iban"]" Name="@Key("BankAccounts", index, "Iban")" Value="@b.Iban" ValueChanged="v => SetIbanAsync(b, v)" Mono="true" Span="5" Required="true" MaxLength="42" />
|
|
<KhTextBox Label="@T["Parties.Fields.BankName"]" Name="@Key("BankAccounts", index, "BankName")" Value="@b.BankName" ValueChanged="v => Change(() => b.BankName = v)" Span="4" MaxLength="100" />
|
|
<KhTextBox Label="@T["Parties.Fields.Bic"]" Name="@Key("BankAccounts", index, "Bic")" Value="@b.Bic" ValueChanged="v => Change(() => b.Bic = v)" Mono="true" Span="3" MaxLength="11" />
|
|
<KhTextBox Label="@T["Parties.Fields.BankCode"]" Name="@Key("BankAccounts", index, "BankCode")" Value="@b.BankCode" ReadOnly="true" Mono="true" Span="2" />
|
|
<KhTextBox Label="@T["Parties.Fields.BranchCode"]" Name="@Key("BankAccounts", index, "BranchCode")" Value="@b.BranchCode" ReadOnly="true" Mono="true" Span="2" />
|
|
<KhCheck Label="@T["Parties.Fields.IsDefault"]" Name="@Key("BankAccounts", index, "IsDefault")" Value="b.IsDefault" ValueChanged="v => Change(() => b.IsDefault = v)" Span="4" />
|
|
@if (!IsReadOnly)
|
|
{
|
|
<div class="c4 kh-endrow">
|
|
<button type="button" class="btn danger" @onclick="() => Remove(Record.BankAccounts, index)"><KhIcon Name="trash" /> @T["Parties.Actions.Remove"]</button>
|
|
</div>
|
|
}
|
|
</KhFieldGroup>
|
|
}
|
|
<DetailFooter Empty="@(Record.BankAccounts.Count == 0 ? T["Parties.Empty.Banks"] : null)" CanAdd="!IsReadOnly" AddText="@T["Parties.Actions.AddBank"]"
|
|
OnAdd="() => Add(Record.BankAccounts, new PartyBankAccount { IsDefault = Record.BankAccounts.Count == 0 })" />
|
|
break;
|
|
|
|
case PartyScreens.Tabs.Notes:
|
|
<KhFieldGroup Title="@T["Parties.Groups.Notes"]" Icon="edit" Wide="true">
|
|
<KhTextArea Label="@T["Parties.Fields.Notes"]" Name="Notes" Value="@P.Notes" ValueChanged="v => Change(() => P.Notes = v)" Span="12" Rows="6" />
|
|
</KhFieldGroup>
|
|
break;
|
|
}
|
|
</KhForm>
|
|
@if (ActiveTab == PartyScreens.Tabs.Notes && !IsNew && Session.Permissions.Allows(AttachmentService.ReadPermission))
|
|
{
|
|
<div class="kh-tab-body"><KhAttachmentList Entity="@PartyService.Entity" EntityId="P.Id" OnCountChanged="c => _attachments = c" /></div>
|
|
}
|
|
@if (ActiveTab == PartyScreens.Tabs.History)
|
|
{
|
|
<div class="kh-tab-body"><KhAuditList Items="_history" FieldName="FieldLabel" /></div>
|
|
}
|
|
</ChildContent>
|
|
</KhRecordLayout>
|
|
}
|
|
|
|
@code {
|
|
private PartyArchive _archive;
|
|
private PartyLookups _lookups = PartyLookups.Empty;
|
|
private IReadOnlyList<AuditItem> _history = [];
|
|
private IReadOnlyList<PlaceSuggestion> _places = [];
|
|
private int _attachments;
|
|
private bool _loaded;
|
|
private bool _busy;
|
|
private DateOnly? _birthDate;
|
|
private string? _sex;
|
|
private string? _birthPlace;
|
|
|
|
/// <summary>The party, absent for a new one.</summary>
|
|
[Parameter]
|
|
public long? Id { get; set; }
|
|
|
|
/// <summary>The kind of a new party among the contacts (<c>?tipo=lead</c>).</summary>
|
|
[SupplyParameterFromQuery(Name = "tipo")]
|
|
public string? Kind { get; set; }
|
|
|
|
private Party P => Record!.Party;
|
|
|
|
private bool CanWrite => Session.Permissions.Allows(PartyService.WritePermission);
|
|
|
|
private string KindIcon => Record?.Party.Kind switch
|
|
{
|
|
PartyKind.Supplier => "truck",
|
|
PartyKind.Prospect or PartyKind.Lead => "target",
|
|
_ => "users",
|
|
};
|
|
|
|
private string PageTitle => Record is null ? T["Parties.Archives." + _archive]
|
|
: IsNew ? T["Parties.New." + Record.Party.Kind]
|
|
: (Record.Party.Code + " · " + Record.Party.Name);
|
|
|
|
private long? PaymentTermId => P.IsCustomer ? Record!.Sales.PaymentTermId : Record!.Purchase.PaymentTermId;
|
|
|
|
private IReadOnlyList<string> HeadLines
|
|
{
|
|
get
|
|
{
|
|
var lines = new List<string>();
|
|
var street = string.Join(' ', new[] { P.Address, P.StreetNumber }.Where(s => !string.IsNullOrWhiteSpace(s)));
|
|
var place = string.Join(' ', new[] { P.PostalCode, P.City, P.Province is { } p ? "(" + p + ")" : null }.Where(s => !string.IsNullOrWhiteSpace(s)));
|
|
if (string.Join(" · ", new[] { street, place }.Where(s => s.Length > 0)) is { Length: > 0 } address)
|
|
{
|
|
lines.Add(address);
|
|
}
|
|
|
|
var ids = new List<string>();
|
|
if (P.VatNumber is { } vat)
|
|
{
|
|
ids.Add(T["Parties.Fields.VatNumber"] + " " + (P.CountryCode == "IT" ? vat : P.CountryCode + vat));
|
|
}
|
|
|
|
if (P.TaxCode is { } tax && tax != P.VatNumber)
|
|
{
|
|
ids.Add(T["Parties.Fields.TaxCode"] + " " + tax);
|
|
}
|
|
|
|
if (ids.Count > 0)
|
|
{
|
|
lines.Add(string.Join(" · ", ids));
|
|
}
|
|
|
|
if (string.Join(" · ", new[] { P.Phone, P.Email ?? P.Pec }.Where(s => !string.IsNullOrWhiteSpace(s))) is { Length: > 0 } reach)
|
|
{
|
|
lines.Add(reach);
|
|
}
|
|
|
|
return lines;
|
|
}
|
|
}
|
|
|
|
private IReadOnlyList<KhOption<string>> KindChoices => PartyScreens.Choices<PartyKind>(T, "Kinds");
|
|
|
|
private IReadOnlyList<KhOption<string>> SubjectChoices => PartyScreens.Choices<SubjectType>(T, "SubjectTypes");
|
|
|
|
private IReadOnlyList<KhOption<string>> AddressKindChoices => PartyScreens.Choices<PartyAddressKind>(T, "AddressKinds");
|
|
|
|
private IReadOnlyList<KhOption<string>> DeliveryChoices => PartyScreens.Choices<DocumentDelivery>(T, "Delivery");
|
|
|
|
private IReadOnlyList<KhOption<string>> SexChoices => PartyScreens.Choices<PersonSex>(T, "Sexes");
|
|
|
|
private IReadOnlyList<KhOption<string>> ExigibilityChoices => [.. new[] { "I", "D", "S" }.Select(v => new KhOption<string>(v, T["Parties.Exigibilities." + v]))];
|
|
|
|
/// <inheritdoc />
|
|
public override bool IsReadOnly => !CanWrite;
|
|
|
|
/// <inheritdoc />
|
|
protected override bool IsNew => Record is { Party.Id: 0 };
|
|
|
|
/// <inheritdoc />
|
|
protected override bool CanDelete => base.CanDelete && Session.Permissions.Allows(PartyService.DeletePermission);
|
|
|
|
/// <inheritdoc />
|
|
protected override string? NewUrl => CanWrite ? PartyScreens.NewUrl(_archive) : null;
|
|
|
|
/// <inheritdoc />
|
|
protected override int? AttachmentCount => IsNew || Record is null ? null : _attachments;
|
|
|
|
/// <inheritdoc />
|
|
public override IReadOnlyList<KhTabItem> Tabs => Record is null ? [] :
|
|
[
|
|
TabOf(PartyScreens.Tabs.Main, "user", "Main"),
|
|
TabOf(PartyScreens.Tabs.Addresses, "pin", "Addresses", Record.Addresses.Count),
|
|
TabOf(PartyScreens.Tabs.Contacts, "phone", "Contacts", Record.Contacts.Count),
|
|
TabOf(PartyScreens.Tabs.Terms, "coins", "Terms"),
|
|
TabOf(PartyScreens.Tabs.Fiscal, "file-check", "Fiscal"),
|
|
TabOf(PartyScreens.Tabs.Banks, "euro", "Banks", Record.BankAccounts.Count),
|
|
TabOf(PartyScreens.Tabs.Notes, "paperclip", "Notes", IsNew ? null : _attachments),
|
|
TabOf(PartyScreens.Tabs.History, "history", "History"),
|
|
];
|
|
|
|
private KhTabItem TabOf(string id, string icon, string text, int? count = null)
|
|
{
|
|
// A tab with errors shows how many; otherwise how many details it holds.
|
|
var errors = Validation.Messages.Count(m => PartyScreens.TabOf(m.Field) == id);
|
|
return new(id, icon, T["Parties.Tabs." + text], errors > 0 ? errors : count is > 0 ? count : null);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_archive = PartyScreens.ArchiveOf(Navigation.ToBaseRelativePath(Navigation.Uri));
|
|
await Session.EnsureLoadedAsync();
|
|
if (Session.Actor is { } actor && Session.Company?.Code is { } company && Session.Permissions.Allows(PartyService.ReadPermission))
|
|
{
|
|
if (!_loaded)
|
|
{
|
|
_lookups = await PartyLookups.ForRecordAsync(Tables, actor, company);
|
|
}
|
|
|
|
if (Record is null || Record.Party.Id != (Id ?? 0))
|
|
{
|
|
await ReloadAsync();
|
|
MarkSaved();
|
|
}
|
|
}
|
|
|
|
_loaded = true;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task ReloadAsync()
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Validation.Clear();
|
|
_places = [];
|
|
if (Id is { } id)
|
|
{
|
|
Record = await Parties.GetAsync(actor, company, id);
|
|
await LoadSideAsync(actor, company);
|
|
}
|
|
else
|
|
{
|
|
Record = await Parties.NewAsync(actor, company, PartyScreens.KindOf(_archive, Kind));
|
|
_history = [];
|
|
_attachments = 0;
|
|
}
|
|
}
|
|
|
|
private async Task LoadSideAsync(Actor actor, string company)
|
|
{
|
|
if (Record is not { Party.Id: > 0 } record)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_history = [.. (await Parties.HistoryAsync(actor, company, record.Party.Id)).Select(AuditTrailService.Item)];
|
|
_attachments = Session.Permissions.Allows(AttachmentService.ReadPermission)
|
|
? await Attachments.CountAsync(actor, company, PartyService.Entity, record.Party.Id)
|
|
: 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task<bool> SaveCoreAsync()
|
|
{
|
|
if (Record is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company || _busy)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_busy = true;
|
|
Validation.Clear();
|
|
try
|
|
{
|
|
var wasNew = IsNew;
|
|
var problems = await Parties.ValidateAsync(actor, company, Record);
|
|
if (problems.Any(p => !p.IsWarning))
|
|
{
|
|
Refuse(problems.Where(p => !p.IsWarning).Select(p => ((string?)p.Field, p.Code)));
|
|
return false;
|
|
}
|
|
|
|
Record = await Parties.SaveAsync(actor, company, Record);
|
|
await LoadSideAsync(actor, company);
|
|
if (problems.Count > 0)
|
|
{
|
|
Toasts.Show(ToastKind.Warning, T.Format("Parties.Actions.Warnings", string.Join(" ", problems.Select(p => Message(p.Code)))));
|
|
}
|
|
|
|
if (wasNew)
|
|
{
|
|
MarkSaved();
|
|
Navigation.NavigateTo(PartyScreens.RecordUrl(_archive, Record.Party.Id), new NavigationOptions { ReplaceHistoryEntry = true });
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (ValidationFailedException ex)
|
|
{
|
|
Refuse(ex.Errors.Select(TableValues.SplitError));
|
|
return false;
|
|
}
|
|
catch (ConcurrencyException)
|
|
{
|
|
Toasts.Show(ToastKind.Error, T["CompanyTables.NotSaved"], T["CompanyTables.Concurrency"]);
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
_busy = false;
|
|
}
|
|
}
|
|
|
|
private void Refuse(IEnumerable<(string? Field, string Code)> errors)
|
|
{
|
|
foreach (var (field, code) in errors)
|
|
{
|
|
Validation.Add(field, Message(code));
|
|
}
|
|
|
|
// Show the tab of the first error when the open one has none.
|
|
if (!Validation.Messages.Any(m => PartyScreens.TabOf(m.Field) == ActiveTab) && Validation.Messages.FirstOrDefault() is { } first)
|
|
{
|
|
_ = ShowTabAsync(PartyScreens.TabOf(first.Field));
|
|
}
|
|
}
|
|
|
|
private string Message(string code) => T.Contains(code) ? T[code] : T["CompanyTables.UnknownError"];
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task DeleteCoreAsync()
|
|
{
|
|
if (Record is not { Party.Id: > 0 } record || Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (await Parties.DeleteAsync(actor, company, record.Party.Id) == PartyDeleteOutcome.Disabled)
|
|
{
|
|
Toasts.Show(ToastKind.Info, T["Parties.Actions.DeletedInstead"]);
|
|
}
|
|
|
|
Navigation.NavigateTo(PartyScreens.RadarUrl(_archive));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override Task RadarAsync()
|
|
{
|
|
Navigation.NavigateTo(PartyScreens.RadarUrl(_archive));
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override Task AttachmentsAsync() => ShowTabAsync(PartyScreens.Tabs.Notes);
|
|
|
|
/// <inheritdoc />
|
|
protected override IEnumerable<ToolbarItem> ContextActions()
|
|
{
|
|
if (Record is null || IsNew || !CanWrite)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (P.VatNumber is not null && P.SubjectType is SubjectType.EuCompany or SubjectType.Company)
|
|
{
|
|
yield return new ToolbarItem("vies", "shield-check", T["Parties.Actions.Vies"])
|
|
{
|
|
Kind = ToolbarKind.Action, Disabled = IsModified || _busy, OnClick = CheckVatAsync,
|
|
};
|
|
}
|
|
|
|
if (P.Kind != PartyKind.Customer)
|
|
{
|
|
yield return new ToolbarItem("convert", "users", T["Parties.Actions.Convert"])
|
|
{
|
|
Kind = ToolbarKind.Action, Primary = P.Kind is PartyKind.Prospect or PartyKind.Lead, Disabled = IsModified || _busy, OnClick = ConvertAsync,
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override IEnumerable<ToolbarItem> MenuCommands()
|
|
{
|
|
if (Record is null || IsNew || !CanWrite)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
yield return new ToolbarItem("disable", P.Disabled ? "check-circle" : "x-circle", T[P.Disabled ? "Parties.Actions.Enable" : "Parties.Actions.Disable"])
|
|
{
|
|
Kind = ToolbarKind.Menu, Disabled = IsModified || _busy, OnClick = ToggleDisabledAsync,
|
|
};
|
|
}
|
|
|
|
private async Task CheckVatAsync()
|
|
{
|
|
if (Record is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_busy = true;
|
|
try
|
|
{
|
|
var result = await Parties.CheckVatAsync(actor, company, P.Id);
|
|
if (result is null)
|
|
{
|
|
Toasts.Show(ToastKind.Warning, T["Parties.Vies.NeedsVat"]);
|
|
return;
|
|
}
|
|
|
|
Record = await Parties.GetAsync(actor, company, P.Id) ?? Record;
|
|
var tone = result.Status == ViesStatus.Valid ? ToastKind.Success : result.Status == ViesStatus.Invalid ? ToastKind.Error : ToastKind.Warning;
|
|
Toasts.Show(tone, T["Parties.Vies." + result.Status], result.Name);
|
|
await LoadSideAsync(actor, company);
|
|
}
|
|
finally
|
|
{
|
|
_busy = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task ConvertAsync()
|
|
{
|
|
if (Record is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company
|
|
|| !await Dialogs.ConfirmAsync(new(T["Parties.Actions.ConvertTitle"], T["Parties.Actions.ConvertText"], T["Parties.Actions.Convert"], T["Common.Cancel"])))
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var converted = await Parties.ConvertToCustomerAsync(actor, company, P.Id);
|
|
Toasts.Show(ToastKind.Success, T.Format("Parties.Actions.Converted", converted.Party.Code));
|
|
Record = converted;
|
|
Navigation.NavigateTo(PartyScreens.RecordUrl(PartyArchive.Customers, converted.Party.Id));
|
|
}
|
|
catch (ValidationFailedException ex)
|
|
{
|
|
Toasts.Show(ToastKind.Error, T["CompanyTables.NotSaved"], string.Join(" ", ex.Errors.Select(TableValues.SplitError).Select(e => Message(e.Code))));
|
|
}
|
|
}
|
|
|
|
private async Task ToggleDisabledAsync()
|
|
{
|
|
if (Record is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var disabled = !P.Disabled;
|
|
await Parties.SetDisabledAsync(actor, company, [P.Id], disabled);
|
|
Toasts.Show(ToastKind.Success, T.Format(disabled ? "Parties.Actions.Disabled" : "Parties.Actions.Enabled", 1));
|
|
Record = await Parties.GetAsync(actor, company, P.Id) ?? Record;
|
|
await LoadSideAsync(actor, company);
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void Change(Action change)
|
|
{
|
|
change();
|
|
MarkModified();
|
|
}
|
|
|
|
private static string Key(string list, int index, string field) => list + "." + index.ToString(System.Globalization.CultureInfo.InvariantCulture) + "." + field;
|
|
|
|
private void Add<TDetail>(List<TDetail> list, TDetail detail)
|
|
{
|
|
list.Add(detail);
|
|
MarkModified();
|
|
}
|
|
|
|
private void Remove<TDetail>(List<TDetail> list, int index)
|
|
{
|
|
if (index < list.Count)
|
|
{
|
|
list.RemoveAt(index);
|
|
Validation.Clear();
|
|
MarkModified();
|
|
}
|
|
}
|
|
|
|
private void SetKind(string? value) => Change(() => P.Kind = Enum.Parse<PartyKind>(value!));
|
|
|
|
private void SetAddressKind(PartyAddress address, string? value) => Change(() => address.Kind = Enum.Parse<PartyAddressKind>(value!));
|
|
|
|
private void SetDelivery(PartySalesTerms terms, string? value) => Change(() => terms.SendDocuments = Enum.Parse<DocumentDelivery>(value!));
|
|
|
|
private Task SetSubjectAsync(string? value)
|
|
{
|
|
Change(() =>
|
|
{
|
|
P.SubjectType = Enum.Parse<SubjectType>(value!);
|
|
// A foreign subject lives abroad: the country is chosen again.
|
|
if (P.SubjectType is SubjectType.EuCompany or SubjectType.NonEuCompany && P.CountryCode == "IT")
|
|
{
|
|
P.CountryCode = string.Empty;
|
|
}
|
|
else if (P.SubjectType is SubjectType.Company or SubjectType.PublicAdministration or SubjectType.FlatRate or SubjectType.Person && P.CountryCode.Length == 0)
|
|
{
|
|
P.CountryCode = "IT";
|
|
}
|
|
});
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task SetPostalCodeAsync(string? value)
|
|
{
|
|
Change(() => P.PostalCode = value);
|
|
_places = [];
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || P.CountryCode != "IT"
|
|
|| !await AutoFill.IsOnAsync(company, AutoFillService.PostalCode))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var places = await AutoFill.PlacesByPostalCodeAsync(actor, company, value);
|
|
if (places.Count == 1)
|
|
{
|
|
PickPlace(places[0]);
|
|
}
|
|
else if (!places.Any(p => string.Equals(p.Name, P.City, StringComparison.CurrentCultureIgnoreCase)))
|
|
{
|
|
_places = places;
|
|
}
|
|
}
|
|
|
|
private async Task SetCityAsync(string? value)
|
|
{
|
|
Change(() => P.City = value);
|
|
_places = [];
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || P.CountryCode != "IT"
|
|
|| !await AutoFill.IsOnAsync(company, AutoFillService.PostalCode))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var exact = (await AutoFill.PlacesByNameAsync(actor, company, value))
|
|
.Where(p => string.Equals(p.Name, value?.Trim(), StringComparison.CurrentCultureIgnoreCase)).ToList();
|
|
if (exact.Count == 1)
|
|
{
|
|
P.Province = exact[0].ProvinceCode;
|
|
// A single postal code is filled; a city with many keeps what was typed.
|
|
if (string.IsNullOrWhiteSpace(P.PostalCode) && exact[0].PostalCode is { } code && code.All(char.IsAsciiDigit))
|
|
{
|
|
P.PostalCode = code;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PickPlace(PlaceSuggestion place)
|
|
{
|
|
P.City = place.Name;
|
|
P.Province = place.ProvinceCode;
|
|
_places = [];
|
|
MarkModified();
|
|
}
|
|
|
|
private async Task SetIbanAsync(PartyBankAccount account, string? value)
|
|
{
|
|
Change(() => account.Iban = value ?? string.Empty);
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || !await AutoFill.IsOnAsync(company, AutoFillService.BankFromIban))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (await AutoFill.BankFromIbanAsync(actor, company, value) is { } bank)
|
|
{
|
|
account.BankCode = bank.BankCode;
|
|
account.BranchCode = bank.BranchCode;
|
|
account.BankName ??= bank.Name;
|
|
account.Bic ??= bank.Bic;
|
|
}
|
|
}
|
|
|
|
private async Task ComputeTaxCodeAsync()
|
|
{
|
|
if (Session.Actor is not { } actor || Session.Company?.Code is not { } company || Record is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var place = _birthPlace?.Trim().ToUpperInvariant();
|
|
if (place is { Length: > 0 } && !(place.Length == 4 && char.IsAsciiLetter(place[0]) && place[1..].All(char.IsAsciiDigit)))
|
|
{
|
|
// A name: the municipality with exactly that name.
|
|
place = (await AutoFill.PlacesByNameAsync(actor, company, _birthPlace))
|
|
.FirstOrDefault(p => string.Equals(p.Name, _birthPlace?.Trim(), StringComparison.CurrentCultureIgnoreCase))?.MunicipalityCode;
|
|
}
|
|
|
|
string? code = null;
|
|
if (_birthDate is { } date && Enum.TryParse<PersonSex>(_sex, out var sex) && place is { Length: > 0 })
|
|
{
|
|
code = await AutoFill.PersonalTaxCodeAsync(company, new PersonalTaxCodeData(P.LastName ?? string.Empty, P.FirstName ?? string.Empty, date, sex, place));
|
|
}
|
|
|
|
if (code is null)
|
|
{
|
|
Toasts.Show(ToastKind.Warning, T["Parties.Actions.TaxCodeMissing"]);
|
|
return;
|
|
}
|
|
|
|
Change(() => P.TaxCode = code);
|
|
Toasts.Show(ToastKind.Success, T["Parties.Actions.TaxCodeDone"], code);
|
|
}
|
|
|
|
private string? FieldLabel(string field)
|
|
{
|
|
var key = "Parties.Fields." + field.Split('.')[^1];
|
|
return T.Contains(key) ? T[key] : null;
|
|
}
|
|
}
|