Skip to content

Commit 29529c6

Browse files
feat: Add printing functionality for Avoir documents in AddOrUpdateAvoir and AvoirsList components
- Implemented print button in AddOrUpdateAvoir component, allowing users to print Avoir documents after saving. - Enhanced AvoirsList component with a print option for each Avoir, improving accessibility and user experience. - Integrated PrintAvoirService for generating PDF documents and handling print requests, including success and error notifications. - Updated UI elements and styles for better interaction and visibility of print options.
1 parent 3e0f98e commit 29529c6

File tree

6 files changed

+452
-1
lines changed

6 files changed

+452
-1
lines changed

src/WebApps/TunNetCom.SilkRoadErp.Sales.WebApp/Components/Pages/Avoirs/AddOrUpdateAvoir.razor

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
@using TunNetCom.SilkRoadErp.Sales.WebApp.Components.Pages.Avoirs
1818
@using TunNetCom.SilkRoadErp.Sales.Contracts.Customers
1919
@using TunNetCom.SilkRoadErp.Sales.Contracts.Common
20+
@using TunNetCom.SilkRoadErp.Sales.Domain.Entites
21+
@using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.Avoirs
22+
@using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Infrastructure
2023

2124
@inject IStringLocalizer<SharedResource> Localizer
2225
@inject Radzen.NotificationService NotificationService
@@ -27,6 +30,8 @@
2730
@inject IAppParametersClient appParametersClient
2831
@inject ILogger<AddOrUpdateAvoir> logger
2932
@inject DialogService DialogService
33+
@inject PrintAvoirService PrintAvoirService
34+
@inject IPrintService PrintServiceInfra
3035

3136
<style>
3237
.header-actions {
@@ -140,6 +145,16 @@ else
140145
<RadzenDropDownDataGridColumn Property="@nameof(CustomerResponse.Name)" Title="@Localizer["name"]" Width="220px" />
141146
</Columns>
142147
</RadzenDropDownDataGrid>
148+
@if (IsAvoirSaved)
149+
{
150+
<RadzenButton Icon="print"
151+
Text="Imprimer"
152+
ButtonStyle="ButtonStyle.Light"
153+
Size="ButtonSize.Medium"
154+
Click="@OnPrintAvoir"
155+
Title="Imprimer l'avoir client"
156+
Style="margin-left: 8px;" />
157+
}
143158
</div>
144159
</div>
145160

@@ -190,6 +205,8 @@ else
190205
private GetAppParametersResponse getAppParametersResponse;
191206
private int? selectedCustomerId;
192207

208+
private bool IsAvoirSaved => !string.IsNullOrEmpty(avoirNumber) && int.TryParse(avoirNumber, out var n) && n > 0;
209+
193210
protected override async Task OnInitializedAsync()
194211
{
195212
await base.OnInitializedAsync();
@@ -523,6 +540,58 @@ else
523540
LineItemCalculator.UpdateTotals(orders, out totalHt, out totalVat, out totalTtc);
524541
}
525542

543+
private async Task OnPrintAvoir()
544+
{
545+
if (!int.TryParse(avoirNumber, out var avoirNum) || avoirNum <= 0) return;
546+
await PrintAvoirAsync(avoirNum);
547+
}
548+
549+
private async Task PrintAvoirAsync(int avoirNum)
550+
{
551+
try
552+
{
553+
var pdfResult = await PrintAvoirService.GenerateAvoirPdfAsync(avoirNum, _cancellationTokenSource.Token);
554+
555+
if (pdfResult.IsSuccess)
556+
{
557+
var printOptions = new PrintOptions
558+
{
559+
Mode = PrintMode.Download,
560+
FileName = $"AvoirClient_{avoirNum}.pdf",
561+
DocumentType = DocumentTypes.Avoirs,
562+
DocumentId = avoirNum
563+
};
564+
565+
await PrintServiceInfra.PrintAsync(pdfResult.Value, printOptions, _cancellationTokenSource.Token);
566+
NotificationService.Notify(new NotificationMessage
567+
{
568+
Severity = NotificationSeverity.Success,
569+
Summary = Localizer["success"],
570+
Detail = "L'avoir client a été généré avec succès."
571+
});
572+
}
573+
else
574+
{
575+
NotificationService.Notify(new NotificationMessage
576+
{
577+
Severity = NotificationSeverity.Error,
578+
Summary = Localizer["error"],
579+
Detail = pdfResult.Errors.FirstOrDefault()?.Message ?? "Erreur lors de la génération du PDF."
580+
});
581+
}
582+
}
583+
catch (Exception ex)
584+
{
585+
logger.LogError(ex, "Error printing avoir client {Num}", avoirNum);
586+
NotificationService.Notify(new NotificationMessage
587+
{
588+
Severity = NotificationSeverity.Error,
589+
Summary = Localizer["error"],
590+
Detail = $"Erreur lors de l'impression: {ex.Message}"
591+
});
592+
}
593+
}
594+
526595
public async Task ShowDialog((int ProductId, string ProductReference) args)
527596
{
528597
await DialogService.OpenAsync<ProductHistoryDialog>($"{Localizer["history"]} {Localizer["article"]} {args.ProductReference}",

src/WebApps/TunNetCom.SilkRoadErp.Sales.WebApp/Components/Pages/Avoirs/AvoirsList.razor

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
@inject Radzen.NotificationService NotificationService
2424
@inject DialogService DialogService
2525
@using TunNetCom.SilkRoadErp.Sales.Domain.Entites
26+
@using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.Avoirs
27+
@using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Infrastructure
28+
@inject PrintAvoirService PrintAvoirService
29+
@inject IPrintService PrintServiceInfra
2630

2731
<div class="invoices-list-container">
2832
<div class="search-header">
@@ -158,10 +162,18 @@
158162
</RadzenDataGridColumn>
159163
<RadzenDataGridColumn TItem="AvoirBaseInfo"
160164
Title="@Localizer["actions_label"]"
161-
Width="100px"
165+
Width="140px"
162166
Sortable="false"
163167
Filterable="false">
164168
<Template Context="item">
169+
<RadzenButton Icon="print"
170+
ButtonStyle="ButtonStyle.Secondary"
171+
Variant="Variant.Flat"
172+
Size="ButtonSize.Small"
173+
Click="@(() => PrintAvoirAsync(item.Num))"
174+
Title="Imprimer"
175+
AriaLabel="Imprimer"
176+
Style="margin-right: 4px;" />
165177
<RadzenButton Icon="edit"
166178
ButtonStyle="ButtonStyle.Primary"
167179
Variant="Variant.Flat"
@@ -608,6 +620,52 @@
608620
NavigationManager.NavigateTo($"/AddOrUpdateAvoir/{num}");
609621
}
610622

623+
private async Task PrintAvoirAsync(int avoirNum)
624+
{
625+
try
626+
{
627+
var pdfResult = await PrintAvoirService.GenerateAvoirPdfAsync(avoirNum, default);
628+
629+
if (pdfResult.IsSuccess)
630+
{
631+
var printOptions = new PrintOptions
632+
{
633+
Mode = PrintMode.Download,
634+
FileName = $"AvoirClient_{avoirNum}.pdf",
635+
DocumentType = DocumentTypes.Avoirs,
636+
DocumentId = avoirNum
637+
};
638+
639+
await PrintServiceInfra.PrintAsync(pdfResult.Value, printOptions, default);
640+
NotificationService.Notify(new NotificationMessage
641+
{
642+
Severity = NotificationSeverity.Success,
643+
Summary = Localizer["Success"],
644+
Detail = "L'avoir client a été généré avec succès."
645+
});
646+
}
647+
else
648+
{
649+
NotificationService.Notify(new NotificationMessage
650+
{
651+
Severity = NotificationSeverity.Error,
652+
Summary = Localizer["Error"],
653+
Detail = pdfResult.Errors.FirstOrDefault()?.Message ?? "Erreur lors de la génération du PDF."
654+
});
655+
}
656+
}
657+
catch (Exception ex)
658+
{
659+
_logger.LogError(ex, "Error printing avoir client {Num}", avoirNum);
660+
NotificationService.Notify(new NotificationMessage
661+
{
662+
Severity = NotificationSeverity.Error,
663+
Summary = Localizer["Error"],
664+
Detail = $"Erreur lors de l'impression: {ex.Message}"
665+
});
666+
}
667+
}
668+
611669
private string GetStatusStyle(int statut)
612670
{
613671
return statut == 1

src/WebApps/TunNetCom.SilkRoadErp.Sales.WebApp/PrintEngine/Infrastructure/PrintEngineStartupExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.RetourMarchandiseFournisseur;
1616
using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.AvoirFournisseur;
1717
using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.FactureAvoirFournisseur;
18+
using TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.Avoirs;
1819
using TunNetCom.SilkRoadErp.Sales.HttpClients.Services.PrintHistory;
1920

2021
namespace TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Infrastructure;
@@ -39,6 +40,7 @@ public static void AddPrintEngine(this IServiceCollection services, IConfigurati
3940
_ = services.AddScoped<PrintRetourFournisseurService>();
4041
_ = services.AddScoped<PrintAvoirFournisseurService>();
4142
_ = services.AddScoped<PrintFactureAvoirFournisseurService>();
43+
_ = services.AddScoped<PrintAvoirService>();
4244
_ = services.AddScoped(typeof(IPrintPdfService<,>), typeof(PrintPdfPlayWrightService<,>));
4345

4446
// Register printing services
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace TunNetCom.SilkRoadErp.Sales.WebApp.PrintEngine.Reports.Avoirs;
2+
3+
/// <summary>
4+
/// Modèle pour l'impression de l'avoir client
5+
/// </summary>
6+
public class PrintAvoirModel
7+
{
8+
public int Num { get; set; }
9+
public DateTime Date { get; set; }
10+
11+
public int? ClientId { get; set; }
12+
public PrintAvoirClientInfo? Client { get; set; }
13+
14+
public List<PrintAvoirLineModel> Lines { get; set; } = new();
15+
16+
public decimal TotalExcludingTax { get; set; }
17+
public decimal TotalVat { get; set; }
18+
public decimal TotalTTC { get; set; }
19+
20+
public decimal Base19 { get; set; }
21+
public decimal Base13 { get; set; }
22+
public decimal Base7 { get; set; }
23+
public decimal Tva19 { get; set; }
24+
public decimal Tva13 { get; set; }
25+
public decimal Tva7 { get; set; }
26+
27+
public double VatRate0 { get; set; }
28+
public double VatRate7 { get; set; }
29+
public double VatRate13 { get; set; }
30+
public double VatRate19 { get; set; }
31+
}
32+
33+
public class PrintAvoirClientInfo
34+
{
35+
public int Id { get; set; }
36+
public string Nom { get; set; } = string.Empty;
37+
public string? Adresse { get; set; }
38+
public string? Tel { get; set; }
39+
public string? Matricule { get; set; }
40+
public string? Code { get; set; }
41+
}
42+
43+
public class PrintAvoirLineModel
44+
{
45+
public int IdLi { get; set; }
46+
public string RefProduit { get; set; } = string.Empty;
47+
public string DesignationLi { get; set; } = string.Empty;
48+
public int QteLi { get; set; }
49+
public decimal PrixHt { get; set; }
50+
public double Remise { get; set; }
51+
public decimal TotHt { get; set; }
52+
public double Tva { get; set; }
53+
public decimal TotTtc { get; set; }
54+
}

0 commit comments

Comments
 (0)