Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 09ce53203c | |||
| 3065bba7fb | |||
| da1407579d | |||
| 602b91006e | |||
| 7f3ffde3ff | |||
| 6be43958fa |
@@ -3,17 +3,12 @@ using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Services;
|
||||
using PyroFetes.Services.Pdf;
|
||||
using PyroFetes.Specifications.DeliveryNotes;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
public class GetDeliveryNotePdfEndpoint(
|
||||
DeliveryNotesRepository deliveryNotesRepository,
|
||||
DeliveryNotePdfService deliveryNotePdfService,
|
||||
SettingsRepository settingsRepository,
|
||||
StorageService storageService)
|
||||
public class GetDeliveryNotePdfEndpoint(DeliveryNotesRepository deliveryNotesRepository, IDeliveryNotePdfService deliveryNotePdfService, SettingsRepository settingsRepository)
|
||||
: Endpoint<GetDeliveryNotePdfDto, byte[]>
|
||||
{
|
||||
public override void Configure()
|
||||
@@ -36,7 +31,7 @@ public class GetDeliveryNotePdfEndpoint(
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = await deliveryNotePdfService.Generate(deliveryNote, setting!, storageService);
|
||||
byte[] bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!, setting!);
|
||||
|
||||
await Send.BytesAsync(
|
||||
bytes: bytes,
|
||||
|
||||
@@ -3,7 +3,6 @@ using FastEndpoints;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Services;
|
||||
using PyroFetes.Services.Pdf;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
@@ -11,9 +10,8 @@ namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||
|
||||
public class GetPurchaseOrderPdfEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
PurchaseOrderPdfService purchaseOrderPdfService,
|
||||
SettingsRepository settingsRepository,
|
||||
StorageService storageService)
|
||||
IPurchaseOrderPdfService purchaseOrderPdfService,
|
||||
SettingsRepository settingsRepository)
|
||||
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
|
||||
{
|
||||
public override void Configure()
|
||||
@@ -35,7 +33,7 @@ public class GetPurchaseOrderPdfEndpoint(
|
||||
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
||||
|
||||
byte[] bytes = await purchaseOrderPdfService.Generate(purchaseOrder, setting!, storageService);
|
||||
byte[] bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!, setting!);
|
||||
|
||||
await Send.BytesAsync(
|
||||
bytes: bytes,
|
||||
|
||||
@@ -3,7 +3,6 @@ using FastEndpoints;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Services;
|
||||
using PyroFetes.Services.Pdf;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
|
||||
@@ -11,9 +10,8 @@ namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
public class GetQuotationPdfEndpoint(
|
||||
QuotationsRepository quotationRepository,
|
||||
QuotationPdfService quotationPdfService,
|
||||
SettingsRepository settingsRepository,
|
||||
StorageService storageService)
|
||||
IQuotationPdfService quotationPdfService,
|
||||
SettingsRepository settingsRepository)
|
||||
: Endpoint<GetQuotationPdfDto, byte[]>
|
||||
{
|
||||
public override void Configure()
|
||||
@@ -35,7 +33,7 @@ public class GetQuotationPdfEndpoint(
|
||||
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
||||
|
||||
byte[] bytes = await quotationPdfService.Generate(quotation, setting!, storageService);
|
||||
byte[] bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!, setting!);
|
||||
|
||||
await Send.BytesAsync(
|
||||
bytes: bytes,
|
||||
|
||||
@@ -56,9 +56,9 @@ builder.Services.AddScoped<WareHouseRepository>();
|
||||
builder.Services.AddScoped<CustomersRepository>();
|
||||
|
||||
// Ajout des services
|
||||
builder.Services.AddScoped<DeliveryNotePdfService>();
|
||||
builder.Services.AddScoped<PurchaseOrderPdfService>();
|
||||
builder.Services.AddScoped<QuotationPdfService>();
|
||||
builder.Services.AddScoped<IDeliveryNotePdfService, DeliveryNotePdfService>();
|
||||
builder.Services.AddScoped<IPurchaseOrderPdfService, PurchaseOrderPdfService>();
|
||||
builder.Services.AddScoped<IQuotationPdfService, QuotationPdfService>();
|
||||
builder.Services.AddScoped<StorageService>();
|
||||
|
||||
MapperConfiguration mappingConfig = new(mc =>
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PyroFetesDbContext : DbContext
|
||||
{
|
||||
string connectionString =
|
||||
"Server=romaric-thibault.fr;" +
|
||||
"Database=PyroFetes-Sujet2-Cristiano;" +
|
||||
"Database=PyroFetes-Sujet2;" +
|
||||
"User Id=pyrofetes;" +
|
||||
"Password=Crablike8-Fringe-Swimmable;" +
|
||||
"TrustServerCertificate=true;";
|
||||
|
||||
@@ -5,14 +5,17 @@ using QuestPDF.Infrastructure;
|
||||
|
||||
namespace PyroFetes.Services.Pdf;
|
||||
|
||||
public class DeliveryNotePdfService
|
||||
public interface IDeliveryNotePdfService
|
||||
{
|
||||
private static readonly HttpClient HttpClient = new();
|
||||
byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes, Setting setting);
|
||||
}
|
||||
|
||||
public async Task<byte[]> Generate(DeliveryNote deliveryNote, Setting setting, StorageService storageService)
|
||||
public class DeliveryNotePdfService : IDeliveryNotePdfService
|
||||
{
|
||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
||||
public byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes, Setting setting)
|
||||
{
|
||||
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||
decimal total = 0;
|
||||
int totalQuantity = 0;
|
||||
Document document = Document.Create(container =>
|
||||
@@ -45,7 +48,7 @@ public class DeliveryNotePdfService
|
||||
// Logo + société à droite
|
||||
row.ConstantItem(200).Column(col =>
|
||||
{
|
||||
col.Item().AlignRight().Height(70).Image(logoBytes, ImageScaling.FitArea);
|
||||
col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
|
||||
col.Item().Height(20);
|
||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||
col.Item().Height(5);
|
||||
@@ -90,7 +93,7 @@ public class DeliveryNotePdfService
|
||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||
});
|
||||
|
||||
foreach (ProductDelivery l in deliveryNote.ProductDeliveries!)
|
||||
foreach (ProductDelivery l in lignes)
|
||||
{
|
||||
decimal price = l.Product!.Prices!
|
||||
.FirstOrDefault(x => x.SupplierId == l.DeliveryNote!.SupplierId && x.ProductId == l.ProductId)
|
||||
@@ -122,7 +125,7 @@ public class DeliveryNotePdfService
|
||||
});
|
||||
|
||||
// Signature en bas à droite
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signatureBytes, ImageScaling.FitArea); });
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea); });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,14 +5,17 @@ using QuestPDF.Infrastructure;
|
||||
|
||||
namespace PyroFetes.Services.Pdf;
|
||||
|
||||
public class PurchaseOrderPdfService
|
||||
public interface IPurchaseOrderPdfService
|
||||
{
|
||||
private static readonly HttpClient HttpClient = new();
|
||||
byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes, Setting setting);
|
||||
}
|
||||
|
||||
public async Task<byte[]> Generate(PurchaseOrder purchaseOrder, Setting setting, StorageService storageService)
|
||||
public class PurchaseOrderPdfService : IPurchaseOrderPdfService
|
||||
{
|
||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
||||
public byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes, Setting setting)
|
||||
{
|
||||
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||
int totalQuantity = 0;
|
||||
decimal total = 0;
|
||||
Document document = Document.Create(container =>
|
||||
@@ -42,7 +45,7 @@ public class PurchaseOrderPdfService
|
||||
// Logo + société à droite
|
||||
row.ConstantItem(200).Column(col =>
|
||||
{
|
||||
col.Item().AlignRight().Height(70).Image(logoBytes, ImageScaling.FitArea);
|
||||
col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
|
||||
col.Item().Height(20);
|
||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||
col.Item().Height(5);
|
||||
@@ -90,7 +93,7 @@ public class PurchaseOrderPdfService
|
||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||
});
|
||||
|
||||
foreach (PurchaseProduct l in purchaseOrder.PurchaseProducts!)
|
||||
foreach (PurchaseProduct l in lignes)
|
||||
{
|
||||
decimal price = l.Product!.Prices!
|
||||
.FirstOrDefault(x => x.SupplierId == l.PurchaseOrder!.SupplierId && x.ProductId == l.ProductId)
|
||||
@@ -138,7 +141,7 @@ public class PurchaseOrderPdfService
|
||||
});
|
||||
|
||||
// Signature en bas à droite
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signatureBytes, ImageScaling.FitArea); });
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea); });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,14 +5,17 @@ using QuestPDF.Infrastructure;
|
||||
|
||||
namespace PyroFetes.Services.Pdf;
|
||||
|
||||
public class QuotationPdfService
|
||||
public interface IQuotationPdfService
|
||||
{
|
||||
private static readonly HttpClient HttpClient = new();
|
||||
byte[] Generate(Quotation quotation, List<QuotationProduct> lignes, Setting setting);
|
||||
}
|
||||
|
||||
public async Task<byte[]> Generate(Quotation quotation, Setting setting, StorageService storageService)
|
||||
public class QuotationPdfService : IQuotationPdfService
|
||||
{
|
||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
||||
public byte[] Generate(Quotation quotation, List<QuotationProduct> lignes, Setting setting)
|
||||
{
|
||||
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||
decimal total = 0;
|
||||
Document document = Document.Create(container =>
|
||||
{
|
||||
@@ -39,7 +42,7 @@ public class QuotationPdfService
|
||||
// Logo + société à droite
|
||||
row.ConstantItem(200).Column(col =>
|
||||
{
|
||||
col.Item().AlignRight().Height(70).Image(logoBytes, ImageScaling.FitArea);
|
||||
col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
|
||||
col.Item().Height(20);
|
||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||
col.Item().Height(5);
|
||||
@@ -87,7 +90,7 @@ public class QuotationPdfService
|
||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||
});
|
||||
|
||||
foreach (QuotationProduct l in quotation.QuotationProducts!)
|
||||
foreach (QuotationProduct l in lignes)
|
||||
{
|
||||
decimal price = l.Product!.Prices!
|
||||
.FirstOrDefault(x => x.SupplierId == l.Quotation!.SupplierId && x.ProductId == l.ProductId)
|
||||
@@ -131,7 +134,7 @@ public class QuotationPdfService
|
||||
});
|
||||
|
||||
// Signature en bas à droite
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signatureBytes, ImageScaling.FitArea); });
|
||||
page.Footer().AlignRight().Column(col => { col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea); });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class StorageService(IAmazonS3 amazonS3, IConfiguration config)
|
||||
{
|
||||
if (file.Length == 0) throw new Exception("Fichier vide");
|
||||
|
||||
string key = $"settings/{type}/{Guid.NewGuid()}";
|
||||
string key = $"settings/{type}";
|
||||
|
||||
using MemoryStream memoryStream = new();
|
||||
await file.CopyToAsync(memoryStream, ct);
|
||||
|
||||
Reference in New Issue
Block a user