Quotations, orders, delivery notes, invoices and credit notes get their radars and one document screen (lines, header, transport, links, attachments) with the transformations of the engine, so a quotation reaches the invoice without retyping. The deferred invoicing groups the open delivery notes of a period by customer, payment and destination into one invoice each. Every document prints from one model: an HTML preview on screen and a PDF drawn by the in-house writer, kept among the attachments as a new version. "Invia per e-mail" proposes recipient, subject and text from the templates, attaches the PDF and hands it to a background queue that talks SMTP itself (no external library); the outcome goes to the log, section E-mail/PEC. The demo company now has a year of sales in every state, made through the engine, and run-dev.sh no longer writes to a stray B:\b folder under Git Bash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f12848865d
commit
826042f828
31 files changed
+5682
-16
No files matched your search
@@ -0,0 +1,120 @@
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Application.Tables;
|
||||
using Khaemhat.Core.Tables;
|
||||
using Khaemhat.Web.Tables;
|
||||
using Khaemhat.Web.Ui;
|
||||
|
||||
namespace Khaemhat.Web.Documents;
|
||||
|
||||
/// <summary>
|
||||
/// The choices of the document screens, read once per page from the company tables: conditions, transport, the VAT
|
||||
/// codes and units of the lines. Values are ids, except the currencies (by code); texts are <c>code · description</c>.
|
||||
/// </summary>
|
||||
public sealed class DocumentLookups
|
||||
{
|
||||
/// <summary>No choices, before loading.</summary>
|
||||
public static DocumentLookups Empty { get; } = new();
|
||||
|
||||
/// <summary>Payment terms.</summary>
|
||||
public IReadOnlyList<KhOption<string>> PaymentTerms { get; private init; } = [];
|
||||
|
||||
/// <summary>Payment methods.</summary>
|
||||
public IReadOnlyList<KhOption<string>> PaymentMethods { get; private init; } = [];
|
||||
|
||||
/// <summary>Price lists.</summary>
|
||||
public IReadOnlyList<KhOption<string>> PriceLists { get; private init; } = [];
|
||||
|
||||
/// <summary>Salespeople.</summary>
|
||||
public IReadOnlyList<KhOption<string>> Salespeople { get; private init; } = [];
|
||||
|
||||
/// <summary>The company bank accounts.</summary>
|
||||
public IReadOnlyList<KhOption<string>> BankAccounts { get; private init; } = [];
|
||||
|
||||
/// <summary>Warehouses.</summary>
|
||||
public IReadOnlyList<KhOption<string>> Warehouses { get; private init; } = [];
|
||||
|
||||
/// <summary>Carriers.</summary>
|
||||
public IReadOnlyList<KhOption<string>> Carriers { get; private init; } = [];
|
||||
|
||||
/// <summary>Shipping terms (porto).</summary>
|
||||
public IReadOnlyList<KhOption<string>> ShippingTerms { get; private init; } = [];
|
||||
|
||||
/// <summary>Reasons of transport.</summary>
|
||||
public IReadOnlyList<KhOption<string>> TransportReasons { get; private init; } = [];
|
||||
|
||||
/// <summary>Appearances of the goods.</summary>
|
||||
public IReadOnlyList<KhOption<string>> GoodsAppearances { get; private init; } = [];
|
||||
|
||||
/// <summary>VAT codes.</summary>
|
||||
public IReadOnlyList<KhOption<string>> TaxCodes { get; private init; } = [];
|
||||
|
||||
/// <summary>Units of measure.</summary>
|
||||
public IReadOnlyList<KhOption<string>> Units { get; private init; } = [];
|
||||
|
||||
/// <summary>Currencies, by code.</summary>
|
||||
public IReadOnlyList<KhOption<string>> Currencies { get; private init; } = [];
|
||||
|
||||
/// <summary>Reads the choices.</summary>
|
||||
/// <param name="tables">The tables.</param>
|
||||
/// <param name="actor">Who reads.</param>
|
||||
/// <param name="company">The company.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>The choices.</returns>
|
||||
public static async Task<DocumentLookups> ReadAsync(TableService tables, Actor actor, string company, CancellationToken cancellationToken = default) => new()
|
||||
{
|
||||
PaymentTerms = await ReadAsync<PaymentTerm>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
PaymentMethods = await ReadAsync<PaymentMethod>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
PriceLists = await ReadAsync<PriceList>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
Salespeople = await ReadAsync<Salesperson>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
BankAccounts = await ReadAsync<BankAccount>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
Warehouses = await ReadAsync<Warehouse>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
Carriers = await ReadAsync<Carrier>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
ShippingTerms = await ReadAsync<ShippingTerm>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
TransportReasons = await ReadAsync<TransportReason>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
GoodsAppearances = await ReadAsync<GoodsAppearance>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
TaxCodes = await ReadAsync<TaxCode>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
Units = await ReadAsync<UnitOfMeasure>(tables, actor, company, false, cancellationToken).ConfigureAwait(false),
|
||||
Currencies = await ReadAsync<Currency>(tables, actor, company, true, cancellationToken).ConfigureAwait(false),
|
||||
};
|
||||
|
||||
/// <summary>The code of a choice (the part before <c> · </c>).</summary>
|
||||
/// <param name="options">The choices.</param>
|
||||
/// <param name="id">The id.</param>
|
||||
/// <returns>The code, or <see langword="null"/>.</returns>
|
||||
public static string? CodeOf(IReadOnlyList<KhOption<string>> options, long? id)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
if (id is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var value = id.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
var text = options.FirstOrDefault(o => o.Value == value)?.Text;
|
||||
return text is null ? null : text.Split(" · ", 2)[0];
|
||||
}
|
||||
|
||||
/// <summary>The id of the choice with a code, ignoring case.</summary>
|
||||
/// <param name="options">The choices.</param>
|
||||
/// <param name="code">The code typed.</param>
|
||||
/// <returns>The id, or <see langword="null"/>.</returns>
|
||||
public static long? IdOf(IReadOnlyList<KhOption<string>> options, string? code)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var wanted = code.Trim();
|
||||
var match = options.FirstOrDefault(o => string.Equals(o.Text.Split(" · ", 2)[0], wanted, StringComparison.OrdinalIgnoreCase));
|
||||
return match is null ? null : long.Parse(match.Value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<KhOption<string>>> ReadAsync<T>(TableService tables, Actor actor, string company, bool byCode,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var choices = await TableValues.LookupAsync(tables, typeof(T), byCode, actor, company, cancellationToken).ConfigureAwait(false);
|
||||
return [.. choices.Select(c => new KhOption<string>(c.Value, c.Text))];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user