The document radars and records now serve /acquisti and /magazzino too: supplier orders, receipts, supplier invoices and credit notes, self-invoices and warehouse movements, with the supplier in place of the customer, the supplier's number and date, the protocol and VAT date of registered invoices, and reason and warehouses of a movement. Supplier invoices take their protocol from the purchase numbering, refuse a second document with the same supplier number in the same year and show price differences against their order or receipt. The Italian pack advises the self-invoice a received invoice needs (TD16-TD19, TD28) with its deadline, and the purchase service drafts it with the ordinary rate. A credit note of an invoice now moves its goods back instead of being skipped as already moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
256 lines
8.9 KiB
Plaintext
256 lines
8.9 KiB
Plaintext
@page "/vendite/{Segment}/{Id:long}/stampa"
|
||
@page "/acquisti/{Segment}/{Id:long}/stampa"
|
||
@page "/magazzino/{Segment}/{Id:long}/stampa"
|
||
@attribute [Authorize]
|
||
@using Khaemhat.Application.Documents
|
||
@using Khaemhat.Application.Security
|
||
@using Khaemhat.Web.Documents
|
||
@using Khaemhat.Web.Hosting
|
||
@inject ShellSession Session
|
||
@inject DocumentPrintService Prints
|
||
@inject DocumentEngine Engine
|
||
@inject FileGenerationService Generation
|
||
@inject ToastService Toasts
|
||
@inject NavigationManager Navigation
|
||
|
||
@* The print preview of a sales document (SPEC §9.4, issue #52, mockup 025): the A4 sheet in HTML from the same model
|
||
as the PDF, with Stampa (the print of the browser), the PDF made by Khaemhat and "Salva come allegato", which keeps
|
||
the PDF among the attachments of the document as a new version. *@
|
||
<KhPageTitle Text="@Heading" Icon="printer" />
|
||
|
||
@if (_model is null)
|
||
{
|
||
<div class="kh-message">
|
||
<KhIcon Name="@(_missing ? "alert" : "printer")" Class="lg" />
|
||
<h1>@(_missing ? T["Sales.NotFound"] : T["Common.Loading"])</h1>
|
||
</div>
|
||
}
|
||
else
|
||
{
|
||
<div class="phead">
|
||
<div>
|
||
<div class="crumbs"><a href="@BackUrl">@_model.Title @_model.Number</a> › <b>@T["Sales.Print.Title"]</b></div>
|
||
<h1>@Heading</h1>
|
||
</div>
|
||
</div>
|
||
|
||
<KhPrintPreview PdfUrl="@PdfUrl(false)" PdfDownloadUrl="@PdfUrl(true)" OnSaveAttachment="SaveAsync" Saving="_saving">
|
||
<div class="kh-sheet-head">
|
||
<div class="kh-print-company">
|
||
@if (_model.LogoAttachmentId is { } logo)
|
||
{
|
||
<img class="kh-print-logo" src="@FileEndpoints.View(logo)" alt="" />
|
||
}
|
||
<div>
|
||
<div class="kh-sheet-company">@_model.Company.Name</div>
|
||
@foreach (var line in _model.Company.Lines)
|
||
{
|
||
<div class="kh-sheet-muted">@line</div>
|
||
}
|
||
</div>
|
||
</div>
|
||
<div class="kh-sheet-title">
|
||
<div class="k">@_model.Title</div>
|
||
<div class="kh-print-number">@_model.Number</div>
|
||
<div class="n">@_model.Date</div>
|
||
@if (_model.Watermark is { } mark)
|
||
{
|
||
<div class="kh-print-mark">@mark</div>
|
||
}
|
||
</div>
|
||
</div>
|
||
|
||
<div class="kh-print-top">
|
||
<dl class="kh-print-fields">
|
||
@foreach (var field in _model.Fields)
|
||
{
|
||
<dt>@field.Label</dt>
|
||
<dd>@field.Value</dd>
|
||
}
|
||
</dl>
|
||
<div class="kh-print-party">
|
||
<div class="kh-sheet-muted">@_model.PartyLabel <span class="mono">@_model.Party.Code</span></div>
|
||
<b>@_model.Party.Name</b>
|
||
@foreach (var line in _model.Party.Lines)
|
||
{
|
||
<div>@line</div>
|
||
}
|
||
</div>
|
||
</div>
|
||
|
||
<table class="kh-sheet-table">
|
||
<thead>
|
||
<tr>
|
||
@for (var i = 0; i < _model.LineHeaders.Count; i++)
|
||
{
|
||
<th class="@(i >= 3 ? "num" : null)">@_model.LineHeaders[i]</th>
|
||
}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
@foreach (var line in _model.Lines)
|
||
{
|
||
if (line.IsDescription)
|
||
{
|
||
<tr class="kh-print-text"><td></td><td colspan="7">@line.Description</td></tr>
|
||
}
|
||
else
|
||
{
|
||
<tr>
|
||
<td class="mono">@line.Code</td>
|
||
<td>@line.Description</td>
|
||
<td>@line.Unit</td>
|
||
<td class="num">@line.Quantity</td>
|
||
<td class="num">@line.Price</td>
|
||
<td class="num">@line.Discount</td>
|
||
<td class="num">@line.Tax</td>
|
||
<td class="num">@line.Amount</td>
|
||
</tr>
|
||
}
|
||
}
|
||
</tbody>
|
||
</table>
|
||
|
||
@foreach (var note in _model.Notes)
|
||
{
|
||
<p class="kh-print-note">@note</p>
|
||
}
|
||
|
||
<div class="kh-print-sums">
|
||
<div>
|
||
@if (_model.Summary is { } summary)
|
||
{
|
||
@Table(summary)
|
||
}
|
||
@if (_model.Installments is { } installments)
|
||
{
|
||
@Table(installments)
|
||
}
|
||
</div>
|
||
<div class="kh-print-totals">
|
||
@foreach (var row in _model.Totals)
|
||
{
|
||
<span class="@(row.Strong ? "big" : null)">@row.Label</span>
|
||
<span class="@(row.Strong ? "big num" : "num")">@row.Value</span>
|
||
}
|
||
</div>
|
||
</div>
|
||
|
||
@if (_model.Transport.Count > 0)
|
||
{
|
||
<dl class="kh-print-transport">
|
||
@foreach (var field in _model.Transport)
|
||
{
|
||
<div><dt>@field.Label</dt><dd>@field.Value</dd></div>
|
||
}
|
||
</dl>
|
||
<div class="kh-print-signatures">
|
||
@foreach (var signature in _model.Signatures)
|
||
{
|
||
<div>@signature</div>
|
||
}
|
||
</div>
|
||
}
|
||
|
||
@if (_model.Footer is { } footer)
|
||
{
|
||
<p class="kh-sheet-foot">@footer</p>
|
||
}
|
||
</KhPrintPreview>
|
||
}
|
||
|
||
@code {
|
||
private SalesSection? _section;
|
||
private DocumentPrintModel? _model;
|
||
private bool _missing;
|
||
private bool _saving;
|
||
|
||
/// <summary>The radar segment, such as <c>fatture</c>.</summary>
|
||
[Parameter]
|
||
public string? Segment { get; set; }
|
||
|
||
/// <summary>The document.</summary>
|
||
[Parameter]
|
||
public long Id { get; set; }
|
||
|
||
private string Heading => _model is null ? T["Sales.Print.Title"] : T.Format("Sales.Print.Heading", _model.Title, _model.Number);
|
||
|
||
private string BackUrl => _section is null ? SalesScreens.BasePath : SalesScreens.RadarUrl(_section) + "/" + Id.ToString(T.Culture);
|
||
|
||
/// <inheritdoc />
|
||
protected override async Task OnParametersSetAsync()
|
||
{
|
||
await Session.EnsureLoadedAsync();
|
||
_section = SalesScreens.Find(SalesScreens.AreaOf(Navigation.ToBaseRelativePath(Navigation.Uri)), Segment);
|
||
if (_section is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||
{
|
||
_missing = true;
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
_model = await Prints.BuildAsync(actor, company, _section.Family, Id);
|
||
}
|
||
catch (Exception ex) when (ex is KeyNotFoundException or AccessDeniedException)
|
||
{
|
||
_missing = true;
|
||
}
|
||
}
|
||
|
||
private string? PdfUrl(bool download) =>
|
||
_section is null ? null : FileEndpoints.Generated(DocumentPrintService.EntityOf(_section.Family), Id, DocumentPdfGenerator.GeneratorCode, download);
|
||
|
||
private async Task SaveAsync()
|
||
{
|
||
if (_section is null || Session.Actor is not { } actor || Session.Company?.Code is not { } company)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_saving = true;
|
||
try
|
||
{
|
||
var saved = await Generation.GenerateAsync(actor, company, DocumentPrintService.EntityOf(_section.Family), Id, DocumentPdfGenerator.GeneratorCode);
|
||
await Engine.MarkPrintedAsync(actor, company, _section.Family, Id);
|
||
Toasts.Show(ToastKind.Success, T["Ui.Attachments.GeneratedToast"], saved.FileName);
|
||
}
|
||
catch (Exception ex) when (ex is AccessDeniedException or ValidationFailedException or KeyNotFoundException)
|
||
{
|
||
Toasts.Show(ToastKind.Error, T["Ui.Print.SaveAttachment"], T["Ui.Attachments.Denied"]);
|
||
}
|
||
finally
|
||
{
|
||
_saving = false;
|
||
}
|
||
}
|
||
|
||
private static RenderFragment Table(PrintTable table) => __builder =>
|
||
{
|
||
<div class="kh-print-block">
|
||
<div class="kh-print-block-title">@table.Title</div>
|
||
<table class="kh-sheet-table">
|
||
<thead>
|
||
<tr>
|
||
@for (var i = 0; i < table.Headers.Count; i++)
|
||
{
|
||
<th class="@(table.Numeric[i] ? "num" : null)">@table.Headers[i]</th>
|
||
}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
@foreach (var row in table.Rows)
|
||
{
|
||
<tr>
|
||
@for (var i = 0; i < row.Count; i++)
|
||
{
|
||
<td class="@(table.Numeric[i] ? "num" : null)">@row[i]</td>
|
||
}
|
||
</tr>
|
||
}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
};
|
||
}
|