Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3065bba7fb | |||
| da1407579d | |||
| 602b91006e | |||
| 7f3ffde3ff | |||
| 6be43958fa |
@@ -3,23 +3,18 @@ using FastEndpoints;
|
|||||||
using PyroFetes.DTO.DeliveryNote.Request;
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
using PyroFetes.Services.Pdf;
|
using PyroFetes.Services.Pdf;
|
||||||
using PyroFetes.Specifications.DeliveryNotes;
|
using PyroFetes.Specifications.DeliveryNotes;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
public class GetDeliveryNotePdfEndpoint(
|
public class GetDeliveryNotePdfEndpoint(DeliveryNotesRepository deliveryNotesRepository, IDeliveryNotePdfService deliveryNotePdfService, SettingsRepository settingsRepository)
|
||||||
DeliveryNotesRepository deliveryNotesRepository,
|
|
||||||
DeliveryNotePdfService deliveryNotePdfService,
|
|
||||||
SettingsRepository settingsRepository,
|
|
||||||
StorageService storageService)
|
|
||||||
: Endpoint<GetDeliveryNotePdfDto, byte[]>
|
: Endpoint<GetDeliveryNotePdfDto, byte[]>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/deliveryNotes/{@Id}/pdf", x => new { x.Id });
|
Get("/deliveryNotes/{@Id}/pdf", x => new { x.Id });
|
||||||
Roles("Admin", "Employe");
|
Roles("Admin","Employe");
|
||||||
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +31,7 @@ public class GetDeliveryNotePdfEndpoint(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = await deliveryNotePdfService.Generate(deliveryNote, setting!, storageService);
|
byte[] bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!, setting!);
|
||||||
|
|
||||||
await Send.BytesAsync(
|
await Send.BytesAsync(
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using FastEndpoints;
|
|||||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
using PyroFetes.Services.Pdf;
|
using PyroFetes.Services.Pdf;
|
||||||
using PyroFetes.Specifications.PurchaseOrders;
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
|
||||||
@@ -11,9 +10,8 @@ namespace PyroFetes.Endpoints.PurchaseOrders;
|
|||||||
|
|
||||||
public class GetPurchaseOrderPdfEndpoint(
|
public class GetPurchaseOrderPdfEndpoint(
|
||||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
PurchaseOrderPdfService purchaseOrderPdfService,
|
IPurchaseOrderPdfService purchaseOrderPdfService,
|
||||||
SettingsRepository settingsRepository,
|
SettingsRepository settingsRepository)
|
||||||
StorageService storageService)
|
|
||||||
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
|
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
@@ -35,7 +33,7 @@ public class GetPurchaseOrderPdfEndpoint(
|
|||||||
|
|
||||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
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(
|
await Send.BytesAsync(
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using FastEndpoints;
|
|||||||
using PyroFetes.DTO.Quotation.Request;
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
using PyroFetes.Services.Pdf;
|
using PyroFetes.Services.Pdf;
|
||||||
using PyroFetes.Specifications.Quotations;
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
@@ -11,9 +10,8 @@ namespace PyroFetes.Endpoints.Quotations;
|
|||||||
|
|
||||||
public class GetQuotationPdfEndpoint(
|
public class GetQuotationPdfEndpoint(
|
||||||
QuotationsRepository quotationRepository,
|
QuotationsRepository quotationRepository,
|
||||||
QuotationPdfService quotationPdfService,
|
IQuotationPdfService quotationPdfService,
|
||||||
SettingsRepository settingsRepository,
|
SettingsRepository settingsRepository)
|
||||||
StorageService storageService)
|
|
||||||
: Endpoint<GetQuotationPdfDto, byte[]>
|
: Endpoint<GetQuotationPdfDto, byte[]>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
@@ -35,7 +33,7 @@ public class GetQuotationPdfEndpoint(
|
|||||||
|
|
||||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
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(
|
await Send.BytesAsync(
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Response;
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
public class GetSettingEndpoint(SettingsRepository settingsRepository, StorageService storageService) : EndpointWithoutRequest<GetSettingDto>
|
public class GetSettingEndpoint(SettingsRepository settingsRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<GetSettingDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -24,13 +23,6 @@ public class GetSettingEndpoint(SettingsRepository settingsRepository, StorageSe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetSettingDto settingDto = new()
|
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||||
{
|
|
||||||
Id = setting.Id,
|
|
||||||
ElectronicSignature = storageService.GetUrl(setting.ElectronicSignature!),
|
|
||||||
Logo = storageService.GetUrl(setting.Logo!)
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(settingDto, ct);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,10 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Request;
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settingsRepository, StorageService storageService) : Endpoint<PatchSettingElectronicSignatureDto>
|
public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settingsRepository) : Endpoint<PatchSettingElectronicSignatureDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -26,8 +25,12 @@ public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settings
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string key = await storageService.UploadFile(req.ElectronicSignature!, "electronicSignature", ct);
|
// Encodage en base64
|
||||||
setting.ElectronicSignature = key;
|
using MemoryStream memoryStream = new();
|
||||||
|
if (req.ElectronicSignature != null) await req.ElectronicSignature.CopyToAsync(memoryStream, ct);
|
||||||
|
byte[] signatureBytes = memoryStream.ToArray();
|
||||||
|
|
||||||
|
setting.ElectronicSignature = Convert.ToBase64String(signatureBytes);
|
||||||
|
|
||||||
await settingsRepository.SaveChangesAsync(ct);
|
await settingsRepository.SaveChangesAsync(ct);
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Request;
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Settings;
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository, StorageService storageService) : Endpoint<PatchSettingLogoDto>
|
public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository) : Endpoint<PatchSettingLogoDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -25,9 +24,12 @@ public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository, Sto
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string key = await storageService.UploadFile(req.Logo!, "logo", ct);
|
// Encodage en base64
|
||||||
|
using MemoryStream memoryStream = new();
|
||||||
|
if (req.Logo != null) await req.Logo.CopyToAsync(memoryStream, ct);
|
||||||
|
byte[] logoBytes = memoryStream.ToArray();
|
||||||
|
|
||||||
setting.Logo = key;
|
setting.Logo = Convert.ToBase64String(logoBytes);
|
||||||
|
|
||||||
await settingsRepository.SaveChangesAsync(ct);
|
await settingsRepository.SaveChangesAsync(ct);
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
|
|||||||
+3
-32
@@ -1,5 +1,3 @@
|
|||||||
using Amazon.S3;
|
|
||||||
using Amazon.S3.Model;
|
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using AutoMapper.EquivalencyExpression;
|
using AutoMapper.EquivalencyExpression;
|
||||||
using PyroFetes;
|
using PyroFetes;
|
||||||
@@ -9,7 +7,6 @@ using FastEndpoints.Security;
|
|||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
using PyroFetes.MappingProfiles;
|
using PyroFetes.MappingProfiles;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services;
|
|
||||||
using PyroFetes.Services.Pdf;
|
using PyroFetes.Services.Pdf;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
@@ -56,10 +53,9 @@ builder.Services.AddScoped<WareHouseRepository>();
|
|||||||
builder.Services.AddScoped<CustomersRepository>();
|
builder.Services.AddScoped<CustomersRepository>();
|
||||||
|
|
||||||
// Ajout des services
|
// Ajout des services
|
||||||
builder.Services.AddScoped<DeliveryNotePdfService>();
|
builder.Services.AddScoped<IDeliveryNotePdfService, DeliveryNotePdfService>();
|
||||||
builder.Services.AddScoped<PurchaseOrderPdfService>();
|
builder.Services.AddScoped<IPurchaseOrderPdfService, PurchaseOrderPdfService>();
|
||||||
builder.Services.AddScoped<QuotationPdfService>();
|
builder.Services.AddScoped<IQuotationPdfService, QuotationPdfService>();
|
||||||
builder.Services.AddScoped<StorageService>();
|
|
||||||
|
|
||||||
MapperConfiguration mappingConfig = new(mc =>
|
MapperConfiguration mappingConfig = new(mc =>
|
||||||
{
|
{
|
||||||
@@ -72,31 +68,6 @@ MapperConfiguration mappingConfig = new(mc =>
|
|||||||
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
|
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
|
||||||
builder.Services.AddSingleton(mapper);
|
builder.Services.AddSingleton(mapper);
|
||||||
|
|
||||||
// RUSTFS
|
|
||||||
IConfigurationSection config = builder.Configuration.GetSection("RustFS");
|
|
||||||
|
|
||||||
AmazonS3Client s3Client = new(
|
|
||||||
config["AccessKey"],
|
|
||||||
config["SecretKey"],
|
|
||||||
new AmazonS3Config
|
|
||||||
{
|
|
||||||
ServiceURL = config["ServiceUrl"],
|
|
||||||
ForcePathStyle = true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ListBucketsResponse? buckets = await s3Client.ListBucketsAsync();
|
|
||||||
bool exist = buckets?.Buckets?.Any(x => x.BucketName == config["BucketName"]) == true;
|
|
||||||
if (!exist)
|
|
||||||
{
|
|
||||||
await s3Client.PutBucketAsync(new PutBucketRequest
|
|
||||||
{
|
|
||||||
BucketName = config["BucketName"]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Services.AddSingleton<IAmazonS3>(s3Client);
|
|
||||||
|
|
||||||
// On construit l'application en lui donnant vie
|
// On construit l'application en lui donnant vie
|
||||||
WebApplication app = builder.Build();
|
WebApplication app = builder.Build();
|
||||||
app.UseAuthentication()
|
app.UseAuthentication()
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="9.3.1" />
|
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="9.3.1" />
|
||||||
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||||
<PackageReference Include="AutoMapper.Collection" Version="11.0.0" />
|
<PackageReference Include="AutoMapper.Collection" Version="11.0.0" />
|
||||||
<PackageReference Include="AWSSDK.S3" Version="4.0.24" />
|
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
||||||
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class PyroFetesDbContext : DbContext
|
|||||||
{
|
{
|
||||||
string connectionString =
|
string connectionString =
|
||||||
"Server=romaric-thibault.fr;" +
|
"Server=romaric-thibault.fr;" +
|
||||||
"Database=PyroFetes-Sujet2-Cristiano;" +
|
"Database=PyroFetes-Sujet2;" +
|
||||||
"User Id=pyrofetes;" +
|
"User Id=pyrofetes;" +
|
||||||
"Password=Crablike8-Fringe-Swimmable;" +
|
"Password=Crablike8-Fringe-Swimmable;" +
|
||||||
"TrustServerCertificate=true;";
|
"TrustServerCertificate=true;";
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ using QuestPDF.Infrastructure;
|
|||||||
|
|
||||||
namespace PyroFetes.Services.Pdf;
|
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
|
||||||
|
{
|
||||||
|
public byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes, Setting setting)
|
||||||
{
|
{
|
||||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||||
decimal total = 0;
|
decimal total = 0;
|
||||||
int totalQuantity = 0;
|
int totalQuantity = 0;
|
||||||
Document document = Document.Create(container =>
|
Document document = Document.Create(container =>
|
||||||
@@ -45,7 +48,7 @@ public class DeliveryNotePdfService
|
|||||||
// Logo + société à droite
|
// Logo + société à droite
|
||||||
row.ConstantItem(200).Column(col =>
|
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().Height(20);
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||||
col.Item().Height(5);
|
col.Item().Height(5);
|
||||||
@@ -90,7 +93,7 @@ public class DeliveryNotePdfService
|
|||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (ProductDelivery l in deliveryNote.ProductDeliveries!)
|
foreach (ProductDelivery l in lignes)
|
||||||
{
|
{
|
||||||
decimal price = l.Product!.Prices!
|
decimal price = l.Product!.Prices!
|
||||||
.FirstOrDefault(x => x.SupplierId == l.DeliveryNote!.SupplierId && x.ProductId == l.ProductId)
|
.FirstOrDefault(x => x.SupplierId == l.DeliveryNote!.SupplierId && x.ProductId == l.ProductId)
|
||||||
@@ -122,7 +125,7 @@ public class DeliveryNotePdfService
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Signature en bas à droite
|
// 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;
|
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
|
||||||
|
{
|
||||||
|
public byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes, Setting setting)
|
||||||
{
|
{
|
||||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||||
int totalQuantity = 0;
|
int totalQuantity = 0;
|
||||||
decimal total = 0;
|
decimal total = 0;
|
||||||
Document document = Document.Create(container =>
|
Document document = Document.Create(container =>
|
||||||
@@ -42,7 +45,7 @@ public class PurchaseOrderPdfService
|
|||||||
// Logo + société à droite
|
// Logo + société à droite
|
||||||
row.ConstantItem(200).Column(col =>
|
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().Height(20);
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||||
col.Item().Height(5);
|
col.Item().Height(5);
|
||||||
@@ -90,7 +93,7 @@ public class PurchaseOrderPdfService
|
|||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (PurchaseProduct l in purchaseOrder.PurchaseProducts!)
|
foreach (PurchaseProduct l in lignes)
|
||||||
{
|
{
|
||||||
decimal price = l.Product!.Prices!
|
decimal price = l.Product!.Prices!
|
||||||
.FirstOrDefault(x => x.SupplierId == l.PurchaseOrder!.SupplierId && x.ProductId == l.ProductId)
|
.FirstOrDefault(x => x.SupplierId == l.PurchaseOrder!.SupplierId && x.ProductId == l.ProductId)
|
||||||
@@ -138,7 +141,7 @@ public class PurchaseOrderPdfService
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Signature en bas à droite
|
// 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;
|
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
|
||||||
|
{
|
||||||
|
public byte[] Generate(Quotation quotation, List<QuotationProduct> lignes, Setting setting)
|
||||||
{
|
{
|
||||||
byte[] logoBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.Logo!));
|
byte[] logo = Convert.FromBase64String(setting.Logo!);
|
||||||
byte[] signatureBytes = await HttpClient.GetByteArrayAsync(storageService.GetUrl(setting.ElectronicSignature!));
|
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
|
||||||
decimal total = 0;
|
decimal total = 0;
|
||||||
Document document = Document.Create(container =>
|
Document document = Document.Create(container =>
|
||||||
{
|
{
|
||||||
@@ -39,7 +42,7 @@ public class QuotationPdfService
|
|||||||
// Logo + société à droite
|
// Logo + société à droite
|
||||||
row.ConstantItem(200).Column(col =>
|
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().Height(20);
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
||||||
col.Item().Height(5);
|
col.Item().Height(5);
|
||||||
@@ -87,7 +90,7 @@ public class QuotationPdfService
|
|||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (QuotationProduct l in quotation.QuotationProducts!)
|
foreach (QuotationProduct l in lignes)
|
||||||
{
|
{
|
||||||
decimal price = l.Product!.Prices!
|
decimal price = l.Product!.Prices!
|
||||||
.FirstOrDefault(x => x.SupplierId == l.Quotation!.SupplierId && x.ProductId == l.ProductId)
|
.FirstOrDefault(x => x.SupplierId == l.Quotation!.SupplierId && x.ProductId == l.ProductId)
|
||||||
@@ -131,7 +134,7 @@ public class QuotationPdfService
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Signature en bas à droite
|
// 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); });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
using Amazon.S3;
|
|
||||||
using Amazon.S3.Model;
|
|
||||||
|
|
||||||
namespace PyroFetes.Services;
|
|
||||||
|
|
||||||
public class StorageService(IAmazonS3 amazonS3, IConfiguration config)
|
|
||||||
{
|
|
||||||
private readonly string _bucket = config["RustFs:BucketName"]!;
|
|
||||||
private readonly string _url = config["RustFs:ServiceUrl"]!;
|
|
||||||
|
|
||||||
public async Task<string> UploadFile(IFormFile file, string type, CancellationToken ct)
|
|
||||||
{
|
|
||||||
if (file.Length == 0) throw new Exception("Fichier vide");
|
|
||||||
|
|
||||||
string key = $"settings/{type}/{Guid.NewGuid()}";
|
|
||||||
|
|
||||||
using MemoryStream memoryStream = new();
|
|
||||||
await file.CopyToAsync(memoryStream, ct);
|
|
||||||
memoryStream.Position = 0;
|
|
||||||
|
|
||||||
PutObjectRequest uploadRequest = new()
|
|
||||||
{
|
|
||||||
BucketName = _bucket,
|
|
||||||
ContentType = file.ContentType,
|
|
||||||
InputStream = memoryStream,
|
|
||||||
Key = key,
|
|
||||||
};
|
|
||||||
|
|
||||||
await amazonS3.PutObjectAsync(uploadRequest, ct);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? GetUrl(string key)
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(key) ? null : $"{_url}/{_bucket}/{key}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,11 +4,5 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"RustFS": {
|
|
||||||
"ServiceUrl": "https://stockage.sanchezvende.fr",
|
|
||||||
"AccessKey": "Admin_Beready_Exam2026",
|
|
||||||
"SecretKey": "4dm1n-Pr0j_2026-B3r34d7",
|
|
||||||
"BucketName": "images"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user