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
@@ -85,6 +85,9 @@ public static class DocumentErrors
|
||||
|
||||
/// <summary>Error: a discount formula that cannot be read.</summary>
|
||||
public const string LineDiscountInvalid = "document.line.discount-invalid";
|
||||
|
||||
/// <summary>Error: a line of an invoice without its VAT code.</summary>
|
||||
public const string LineTaxRequired = "document.line.tax-required";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -290,6 +293,18 @@ public sealed class DocumentEngine
|
||||
errors.Add("Lines:" + DocumentErrors.LinesRequired);
|
||||
}
|
||||
|
||||
if (definition.Behavior.Has(DocumentEffects.Ledger))
|
||||
{
|
||||
// A document that goes to the VAT registers needs the VAT of every line with an amount.
|
||||
for (var i = 0; i < record.Lines.Count; i++)
|
||||
{
|
||||
if (record.Lines[i] is { Kind: not DocumentLineKind.Description, TaxCodeId: null })
|
||||
{
|
||||
errors.Add("Lines." + i.ToString(System.Globalization.CultureInfo.InvariantCulture) + "." + nameof(DocumentLine.TaxCodeId) + ":" + DocumentErrors.LineTaxRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.Count > 0 || record.Header.DocumentDate != draft.Header.DocumentDate)
|
||||
{
|
||||
throw errors.Count > 0 ? new ValidationFailedException(errors) : new Core.Common.ConcurrencyException();
|
||||
@@ -400,6 +415,26 @@ public sealed class DocumentEngine
|
||||
}, null, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Records that the document was printed (its PDF kept among the attachments); the state does not change.</summary>
|
||||
/// <param name="actor">Who prints: needs to read the document.</param>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="family">The family.</param>
|
||||
/// <param name="id">The document.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>A task.</returns>
|
||||
public Task MarkPrintedAsync(Actor actor, string companyCode, DocumentFamily family, long id, CancellationToken cancellationToken = default) =>
|
||||
MarkAsync(actor, companyCode, family, id, h => h.Printed = true, cancellationToken);
|
||||
|
||||
/// <summary>Records that the document was sent by e-mail; the state does not change.</summary>
|
||||
/// <param name="actor">Who sends: needs to read the document.</param>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="family">The family.</param>
|
||||
/// <param name="id">The document.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>A task.</returns>
|
||||
public Task MarkSentAsync(Actor actor, string companyCode, DocumentFamily family, long id, CancellationToken cancellationToken = default) =>
|
||||
MarkAsync(actor, companyCode, family, id, h => h.Sent = true, cancellationToken);
|
||||
|
||||
/// <summary>Deletes a draft.</summary>
|
||||
/// <param name="actor">Who deletes.</param>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
@@ -641,6 +676,26 @@ public sealed class DocumentEngine
|
||||
return await GetAsync(actor, company, family, id, cancellationToken).ConfigureAwait(false) ?? throw new KeyNotFoundException(DocumentErrors.NotFound);
|
||||
}
|
||||
|
||||
// Sets an output flag (printed, sent) with its trace in the history, whatever the state.
|
||||
private async Task MarkAsync(Actor actor, string companyCode, DocumentFamily family, long id, Action<DocumentHeader> change, CancellationToken cancellationToken)
|
||||
{
|
||||
var company = Company(actor, companyCode);
|
||||
var store = DocumentStores.Of(family);
|
||||
await using var uow = await _factory.CreateAsync(DatabaseScope.Company(company), cancellationToken).ConfigureAwait(false);
|
||||
await uow.BeginAsync(cancellationToken).ConfigureAwait(false);
|
||||
var header = await store.GetAsync(uow, id, cancellationToken).ConfigureAwait(false) ?? throw new KeyNotFoundException(DocumentErrors.NotFound);
|
||||
await _permissions.DemandAsync(actor, DocumentBehaviors.Of(header.Kind).ReadPermission, cancellationToken).ConfigureAwait(false);
|
||||
var old = header.Clone();
|
||||
change(header);
|
||||
if (old.Printed != header.Printed || old.Sent != header.Sent)
|
||||
{
|
||||
await store.UpdateAsync(uow, header, cancellationToken).ConfigureAwait(false);
|
||||
await store.RecordAsync(_audit, uow, AuditAction.Update, id, old, header, actor.UserName, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await uow.CommitAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Records the links of a confirmed document towards the lines it fulfils, then the fulfilment of those documents.
|
||||
private async Task LinkAsync(IUnitOfWork uow, DocumentDefinition definition, DocumentRecord record, string userName, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user