Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3ffde3ff | ||
| 6be43958fa |
@@ -1,6 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.DeliveryNote.Request;
|
|
||||||
|
|
||||||
public class GetDeliveryNotePdfDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ public class GetPriceDto
|
|||||||
public string? SupplierEmail { get; set; }
|
public string? SupplierEmail { get; set; }
|
||||||
public string? SupplierPhone { get; set; }
|
public string? SupplierPhone { get; set; }
|
||||||
public string? SupplierAddress { get; set; }
|
public string? SupplierAddress { get; set; }
|
||||||
public string? SupplierZipCode { get; set; }
|
public int SupplierZipCode { get; set; }
|
||||||
public string? SupplierCity { get; set; }
|
public string? SupplierCity { get; set; }
|
||||||
public int SupplierDeliveryDelay { get; set; }
|
public int SupplierDeliveryDelay { get; set; }
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ public class GetPriceDto
|
|||||||
public string? ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public int ProductCaliber { get; set; }
|
public decimal ProductCaliber { get; set; }
|
||||||
public string? ProductApprovalNumber { get; set; }
|
public int ProductApprovalNumber { get; set; }
|
||||||
public decimal ProductWeight { get; set; }
|
public decimal ProductWeight { get; set; }
|
||||||
public decimal ProductNec { get; set; }
|
public decimal ProductNec { get; set; }
|
||||||
public string? ProductImage { get; set; }
|
public string? ProductImage { get; set; }
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.PurchaseOrder.Request;
|
|
||||||
|
|
||||||
public class GetPurchaseOrderPdfDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Quotation.Request;
|
|
||||||
|
|
||||||
public class GetQuotationPdfDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
using PyroFetes.DTO.Price.Response;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Supplier.Response;
|
namespace PyroFetes.DTO.Supplier.Response;
|
||||||
|
|
||||||
public class GetSupplierDto
|
public class GetSupplierDto
|
||||||
@@ -13,6 +10,4 @@ public class GetSupplierDto
|
|||||||
public string? ZipCode { get; set; }
|
public string? ZipCode { get; set; }
|
||||||
public string? City { get; set; }
|
public string? City { get; set; }
|
||||||
public int DeliveryDelay { get; set; }
|
public int DeliveryDelay { get; set; }
|
||||||
public List<GetProductDto>? Products { get; set; }
|
|
||||||
public List<GetPriceDto>? Prices { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.Endpoints.Quotations;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
using PyroFetes.Repositories;
|
|
||||||
using PyroFetes.Specifications.DeliveryNotes;
|
|
||||||
using PyroFetes.Specifications.Quotations;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
|
||||||
|
|
||||||
public class DeleteDeliveryNoteRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteDeliveryNoteEndpoint(
|
|
||||||
DeliveryNotesRepository deliveryNotesRepository) : Endpoint<DeleteDeliveryNoteRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/deliveryNotes/{@Id}", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
|
|
||||||
|
|
||||||
if (deliveryNote == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await deliveryNotesRepository.DeleteAsync(deliveryNote, ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.DeliveryNote.Request;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
using PyroFetes.Repositories;
|
|
||||||
using PyroFetes.Services.Pdf;
|
|
||||||
using PyroFetes.Specifications.DeliveryNotes;
|
|
||||||
using PyroFetes.Specifications.Quotations;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
|
||||||
|
|
||||||
public class GetDeliveryNotePdfEndpoint(
|
|
||||||
DeliveryNotesRepository deliveryNotesRepository,
|
|
||||||
IDeliveryNotePdfService deliveryNotePdfService)
|
|
||||||
: Endpoint<GetDeliveryNotePdfDto, byte[]>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/deliveryNotes/{@Id}/pdf", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
DeliveryNote? deliveryNote = await deliveryNotesRepository
|
|
||||||
.FirstOrDefaultAsync(new GetDeliveryNoteByIdWithProductsSpec(req.Id), ct);
|
|
||||||
|
|
||||||
if (deliveryNote == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!);
|
|
||||||
|
|
||||||
await Send.BytesAsync(
|
|
||||||
bytes: bytes,
|
|
||||||
contentType: "application/pdf",
|
|
||||||
fileName: $"bon-de-livraison-{deliveryNote.Id}.pdf",
|
|
||||||
cancellation: ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -30,12 +30,6 @@ public class PatchRealDeliveryDateEndpoint(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deliveryNoteToPath.RealDeliveryDate != null)
|
|
||||||
{
|
|
||||||
await Send.StringAsync("Impossible de modifier la date.", 400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate;
|
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate;
|
||||||
|
|
||||||
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
|
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.Endpoints.Deliverers;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
using PyroFetes.Repositories;
|
|
||||||
using PyroFetes.Specifications.Deliverers;
|
|
||||||
using PyroFetes.Specifications.Products;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Products;
|
|
||||||
|
|
||||||
public class DeleteProductsRequest
|
|
||||||
{
|
|
||||||
public int ProductId { get; set; }
|
|
||||||
}
|
|
||||||
public class DeleteProductEndpoint(ProductsRepository productsRepository) : Endpoint<DeleteProductsRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/products/{@id}", x=>new {x.ProductId});
|
|
||||||
AllowAnonymous();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteProductsRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
|
||||||
|
|
||||||
if (product == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await productsRepository.DeleteAsync(product, ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
using PyroFetes.Repositories;
|
|
||||||
using PyroFetes.Services.Pdf;
|
|
||||||
using PyroFetes.Specifications.PurchaseOrders;
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseOrders;
|
|
||||||
|
|
||||||
public class GetPurchaseOrderPdfEndpoint(
|
|
||||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
|
||||||
IPurchaseOrderPdfService purchaseOrderPdfService)
|
|
||||||
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/purchaseOrders/{@Id}/pdf", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository
|
|
||||||
.FirstOrDefaultAsync(new GetPurchaseOrderByIdWithProductsSpec(req.Id), ct);
|
|
||||||
|
|
||||||
if (purchaseOrder == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!);
|
|
||||||
|
|
||||||
await Send.BytesAsync(
|
|
||||||
bytes: bytes,
|
|
||||||
contentType: "application/pdf",
|
|
||||||
fileName: $"bon-de-commande-{purchaseOrder.Id}.pdf",
|
|
||||||
cancellation: ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.Quotation.Request;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
using PyroFetes.Repositories;
|
|
||||||
using PyroFetes.Services.Pdf;
|
|
||||||
using PyroFetes.Specifications.Quotations;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Quotations;
|
|
||||||
|
|
||||||
public class GetQuotationPdfEndpoint(
|
|
||||||
QuotationsRepository quotationRepository,
|
|
||||||
IQuotationPdfService quotationPdfService)
|
|
||||||
: Endpoint<GetQuotationPdfDto, byte[]>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/quotations/{@Id}/pdf", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Quotation? quotation = await quotationRepository
|
|
||||||
.FirstOrDefaultAsync(new GetQuotationByIdWithProductsSpec(req.Id), ct);
|
|
||||||
|
|
||||||
if (quotation == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!);
|
|
||||||
|
|
||||||
await Send.BytesAsync(
|
|
||||||
bytes: bytes,
|
|
||||||
contentType: "application/pdf",
|
|
||||||
fileName: $"devis-{quotation.Id}.pdf",
|
|
||||||
cancellation: ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ using PyroFetes.DTO.User.Request;
|
|||||||
using PyroFetes.DTO.User.Response;
|
using PyroFetes.DTO.User.Response;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Specifications.Users;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Users;
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
@@ -20,14 +19,6 @@ public class CreateUserEndpoint(
|
|||||||
|
|
||||||
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
|
||||||
|
|
||||||
if (ckeckName != null)
|
|
||||||
{
|
|
||||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||||
|
|
||||||
User user = new User()
|
User user = new User()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class UpdateUserEndpoint(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ckeckName != null && ckeckName.Id != user.Id)
|
if (ckeckName != null)
|
||||||
{
|
{
|
||||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -31,10 +31,9 @@ public class GetTotalQuantityEndpoint(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int? totalQuantityNullable = await warehouseProductsRepository.
|
int totalQuantity =
|
||||||
SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
|
await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId),
|
||||||
|
wp => wp.Quantity, ct);
|
||||||
int totalQuantity = totalQuantityNullable ?? 0;
|
|
||||||
|
|
||||||
GetTotalQuantityDto responseDto = new()
|
GetTotalQuantityDto responseDto = new()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using PyroFetes.DTO.PurchaseProduct.Response;
|
|||||||
using PyroFetes.DTO.Quotation.Response;
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
using PyroFetes.DTO.SettingDTO.Response;
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
using PyroFetes.DTO.Supplier.Response;
|
|
||||||
using PyroFetes.DTO.User.Response;
|
using PyroFetes.DTO.User.Response;
|
||||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
@@ -22,8 +21,6 @@ public class EntityToDtoMappings : Profile
|
|||||||
{
|
{
|
||||||
CreateMap<Deliverer, GetDelivererDto>();
|
CreateMap<Deliverer, GetDelivererDto>();
|
||||||
|
|
||||||
CreateMap<Supplier, GetSupplierDto>();
|
|
||||||
|
|
||||||
CreateMap<DeliveryNote, GetDeliveryNoteDto>();
|
CreateMap<DeliveryNote, GetDeliveryNoteDto>();
|
||||||
|
|
||||||
CreateMap<Price, GetPriceDto>();
|
CreateMap<Price, GetPriceDto>();
|
||||||
|
|||||||
@@ -4,17 +4,11 @@ using PyroFetes;
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using FastEndpoints.Swagger;
|
using FastEndpoints.Swagger;
|
||||||
using FastEndpoints.Security;
|
using FastEndpoints.Security;
|
||||||
using Microsoft.Net.Http.Headers;
|
|
||||||
using PyroFetes.MappingProfiles;
|
using PyroFetes.MappingProfiles;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
using PyroFetes.Services.Pdf;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Configurer la licence QuestPDF
|
|
||||||
QuestPDF.Settings.License = LicenseType.Community;
|
|
||||||
|
|
||||||
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
||||||
@@ -31,8 +25,7 @@ builder.Services
|
|||||||
policyBuilder
|
policyBuilder
|
||||||
.WithOrigins("http://localhost:4200")
|
.WithOrigins("http://localhost:4200")
|
||||||
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
|
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader();
|
||||||
.WithExposedHeaders(HeaderNames.ContentDisposition);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -53,11 +46,6 @@ builder.Services.AddScoped<SettingsRepository>();
|
|||||||
builder.Services.AddScoped<UsersRepository>();
|
builder.Services.AddScoped<UsersRepository>();
|
||||||
builder.Services.AddScoped<WarehouseProductsRepository>();
|
builder.Services.AddScoped<WarehouseProductsRepository>();
|
||||||
|
|
||||||
// Ajout des services
|
|
||||||
builder.Services.AddScoped<IDeliveryNotePdfService, DeliveryNotePdfService>();
|
|
||||||
builder.Services.AddScoped<IPurchaseOrderPdfService, PurchaseOrderPdfService>();
|
|
||||||
builder.Services.AddScoped<IQuotationPdfService, QuotationPdfService>();
|
|
||||||
|
|
||||||
MapperConfiguration mappingConfig = new(mc =>
|
MapperConfiguration mappingConfig = new(mc =>
|
||||||
{
|
{
|
||||||
mc.AddCollectionMappers();
|
mc.AddCollectionMappers();
|
||||||
|
|||||||
@@ -23,21 +23,7 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
||||||
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
||||||
<PackageReference Include="Plainquire.Page" Version="6.5.0" />
|
<PackageReference Include="Plainquire.Page" Version="6.5.0" />
|
||||||
<PackageReference Include="QuestPDF" Version="2025.7.4" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\Images\logo.jpg" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Update="wwwroot\Images\logo.jpg">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\Images\signature.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
using PyroFetes.Models;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace PyroFetes.Services.Pdf;
|
|
||||||
|
|
||||||
public interface IDeliveryNotePdfService
|
|
||||||
{
|
|
||||||
byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeliveryNotePdfService : IDeliveryNotePdfService
|
|
||||||
{
|
|
||||||
public byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes)
|
|
||||||
{
|
|
||||||
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg");
|
|
||||||
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png");
|
|
||||||
int total = 0;
|
|
||||||
int totalQuantity = 0;
|
|
||||||
var document = Document.Create(container =>
|
|
||||||
{
|
|
||||||
container.Page(page =>
|
|
||||||
{
|
|
||||||
page.Size(PageSizes.A4);
|
|
||||||
page.Margin(30);
|
|
||||||
page.DefaultTextStyle(x => x.FontSize(11));
|
|
||||||
|
|
||||||
page.Header().Row(row =>
|
|
||||||
{
|
|
||||||
// Client à gauche
|
|
||||||
row.RelativeItem().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("Transporteur").SemiBold().FontSize(12);
|
|
||||||
col.Item().Text($"{deliveryNote.Deliverer?.Transporter}");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignLeft().Text($"Expédiée le {deliveryNote.ExpeditionDate}");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignLeft().Text($"Estimée au {deliveryNote.EstimateDeliveryDate}");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignLeft().Text($"Reçu le {deliveryNote.RealDeliveryDate}");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Logo + société à droite
|
|
||||||
row.ConstantItem(200).Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea);
|
|
||||||
col.Item().Height(20);
|
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("24, rue La Fosse Mardeau\n41700 Le Controis-en-Sologne");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("Téléphone: 02 54 78 77 66");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("SIRET: 82031463100012");
|
|
||||||
col.Item().Height(40);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
page.Content().Column(col =>
|
|
||||||
{
|
|
||||||
// Titre + date
|
|
||||||
col.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeItem().Text($"Bon de livraison n° {deliveryNote.TrackingNumber}")
|
|
||||||
.FontSize(16).SemiBold();
|
|
||||||
});
|
|
||||||
col.Item().Height(20);
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
|
|
||||||
// Tableau des lignes
|
|
||||||
col.Item().Table(table =>
|
|
||||||
{
|
|
||||||
table.ColumnsDefinition(columns =>
|
|
||||||
{
|
|
||||||
columns.RelativeColumn(4); // Produit
|
|
||||||
columns.RelativeColumn(2); // Qté
|
|
||||||
columns.RelativeColumn(2); // PU
|
|
||||||
columns.RelativeColumn(2); // Total
|
|
||||||
});
|
|
||||||
|
|
||||||
// En-têtes
|
|
||||||
table.Header(header =>
|
|
||||||
{
|
|
||||||
header.Cell().Element(CellHeader).Text("Produit");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Qté");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("PU");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var l in lignes)
|
|
||||||
{
|
|
||||||
table.Cell().Element(CellBody).Text(l.Product?.Name);
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString());
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity:n2} €");
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity * l.Quantity:n2} €");
|
|
||||||
|
|
||||||
totalQuantity += l.Quantity;
|
|
||||||
total += l.Quantity * l.Quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
IContainer CellHeader(IContainer c) =>
|
|
||||||
c.BorderBottom(1).PaddingVertical(5).DefaultTextStyle(x => x.SemiBold());
|
|
||||||
|
|
||||||
IContainer CellBody(IContainer c) =>
|
|
||||||
c.PaddingVertical(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
col.Item().Height(30);
|
|
||||||
|
|
||||||
col.Item().AlignRight().Text($"Total: {totalQuantity:n2} produits");
|
|
||||||
col.Item().AlignRight().Text($"Total HT: {total:n2} €");
|
|
||||||
col.Item().AlignRight().Text("Taxe : 20 %");
|
|
||||||
col.Item().AlignRight().Text($"Total TTC: {(total * 1.2):n2} €");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Signature en bas à droite
|
|
||||||
page.Footer().AlignRight().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return document.GeneratePdf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
using PyroFetes.Models;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace PyroFetes.Services.Pdf;
|
|
||||||
|
|
||||||
public interface IPurchaseOrderPdfService
|
|
||||||
{
|
|
||||||
byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PurchaseOrderPdfService : IPurchaseOrderPdfService
|
|
||||||
{
|
|
||||||
public byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes)
|
|
||||||
{
|
|
||||||
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg");
|
|
||||||
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png");
|
|
||||||
int totalQuantity = 0;
|
|
||||||
int total = 0;
|
|
||||||
var document = Document.Create(container =>
|
|
||||||
{
|
|
||||||
container.Page(page =>
|
|
||||||
{
|
|
||||||
page.Size(PageSizes.A4);
|
|
||||||
page.Margin(30);
|
|
||||||
page.DefaultTextStyle(x => x.FontSize(11));
|
|
||||||
|
|
||||||
page.Header().Row(row =>
|
|
||||||
{
|
|
||||||
// Client à gauche
|
|
||||||
row.RelativeItem().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("Fournisseur").SemiBold().FontSize(12);
|
|
||||||
col.Item().Text("Mettre fournisseur ici");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Logo + société à droite
|
|
||||||
row.ConstantItem(200).Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea);
|
|
||||||
col.Item().Height(20);
|
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("24, rue La Fosse Mardeau\n41700 Le Controis-en-Sologne");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("Téléphone: 02 54 78 77 66");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("SIRET: 82031463100012");
|
|
||||||
col.Item().Height(40);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
page.Content().Column(col =>
|
|
||||||
{
|
|
||||||
// Titre + date
|
|
||||||
col.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeItem().Text($"Bon de commande n° {purchaseOrder.Id}")
|
|
||||||
.FontSize(16).SemiBold();
|
|
||||||
|
|
||||||
row.ConstantItem(200).AlignRight().Text(
|
|
||||||
$"Le {DateTime.Now:dd/MM/yyyy}");
|
|
||||||
});
|
|
||||||
col.Item().Height(20);
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
|
|
||||||
// Tableau des lignes
|
|
||||||
col.Item().Table(table =>
|
|
||||||
{
|
|
||||||
table.ColumnsDefinition(columns =>
|
|
||||||
{
|
|
||||||
columns.RelativeColumn(4); // Produit
|
|
||||||
columns.RelativeColumn(1); // Qté
|
|
||||||
columns.RelativeColumn(2); // PU
|
|
||||||
columns.RelativeColumn(2); // Total
|
|
||||||
});
|
|
||||||
|
|
||||||
// En-têtes
|
|
||||||
table.Header(header =>
|
|
||||||
{
|
|
||||||
header.Cell().Element(CellHeader).Text("Produit");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Qté");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("PU");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var l in lignes)
|
|
||||||
{
|
|
||||||
table.Cell().Element(CellBody).Text(l.Product?.Name);
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString());
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity:n2} €");
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity * l.Quantity:n2} €");
|
|
||||||
|
|
||||||
totalQuantity += l.Quantity;
|
|
||||||
total += l.Quantity * l.Quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
IContainer CellHeader(IContainer c) =>
|
|
||||||
c.BorderBottom(1).PaddingVertical(5).DefaultTextStyle(x => x.SemiBold());
|
|
||||||
|
|
||||||
IContainer CellBody(IContainer c) =>
|
|
||||||
c.PaddingVertical(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
col.Item().Height(30);
|
|
||||||
|
|
||||||
col.Item().Row(row =>
|
|
||||||
{
|
|
||||||
// Colonne gauche : conditions de vente
|
|
||||||
row.RelativeItem().Column(left =>
|
|
||||||
{
|
|
||||||
left.Item().Text("Conditions de vente")
|
|
||||||
.SemiBold().FontSize(12);
|
|
||||||
left.Item().Text(purchaseOrder.PurchaseConditions)
|
|
||||||
.FontSize(9);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Colonne droite : totaux
|
|
||||||
row.ConstantItem(180).Column(right =>
|
|
||||||
{
|
|
||||||
right.Item().AlignRight().Text($"Total: {totalQuantity:n2} produits");
|
|
||||||
right.Item().AlignRight().Text($"Total HT: {total:n2} €");
|
|
||||||
right.Item().AlignRight().Text("Taxe: 20 %");
|
|
||||||
right.Item().AlignRight().Text($"Total TTC: {(total * 1.2):n2} €");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Signature en bas à droite
|
|
||||||
page.Footer().AlignRight().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return document.GeneratePdf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
using PyroFetes.Models;
|
|
||||||
using QuestPDF.Companion;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace PyroFetes.Services.Pdf;
|
|
||||||
|
|
||||||
public interface IQuotationPdfService
|
|
||||||
{
|
|
||||||
byte[] Generate(Quotation quotation, List<QuotationProduct> lignes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class QuotationPdfService : IQuotationPdfService
|
|
||||||
{
|
|
||||||
public byte[] Generate(Quotation quotation, List<QuotationProduct> lignes)
|
|
||||||
{
|
|
||||||
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg");
|
|
||||||
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png");
|
|
||||||
int total = 0;
|
|
||||||
var document = Document.Create(container =>
|
|
||||||
{
|
|
||||||
container.Page(page =>
|
|
||||||
{
|
|
||||||
page.Size(PageSizes.A4);
|
|
||||||
page.Margin(30);
|
|
||||||
page.DefaultTextStyle(x => x.FontSize(11));
|
|
||||||
|
|
||||||
page.Header().Row(row =>
|
|
||||||
{
|
|
||||||
// Client à gauche
|
|
||||||
row.RelativeItem().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("");
|
|
||||||
col.Item().Text("Client").SemiBold().FontSize(12);
|
|
||||||
col.Item().Text($"{quotation.Customer}");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Logo + société à droite
|
|
||||||
row.ConstantItem(200).Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea);
|
|
||||||
col.Item().Height(20);
|
|
||||||
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("24, rue La Fosse Mardeau\n41700 Le Controis-en-Sologne");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("Téléphone: 02 54 78 77 66");
|
|
||||||
col.Item().Height(5);
|
|
||||||
col.Item().AlignRight().Text("SIRET: 82031463100012");
|
|
||||||
col.Item().Height(40);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
page.Content().Column(col =>
|
|
||||||
{
|
|
||||||
// Titre + date
|
|
||||||
col.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeItem().Text($"Devis n° {quotation.Id}")
|
|
||||||
.FontSize(16).SemiBold();
|
|
||||||
|
|
||||||
row.ConstantItem(200).AlignRight().Text(
|
|
||||||
$"Le {DateTime.Now:dd/MM/yyyy}");
|
|
||||||
});
|
|
||||||
col.Item().Height(20);
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
|
|
||||||
// Tableau des lignes
|
|
||||||
col.Item().Table(table =>
|
|
||||||
{
|
|
||||||
table.ColumnsDefinition(columns =>
|
|
||||||
{
|
|
||||||
columns.RelativeColumn(10); // Produit
|
|
||||||
columns.RelativeColumn(2); // Qté
|
|
||||||
columns.RelativeColumn(3); // PU
|
|
||||||
columns.RelativeColumn(3); // Total
|
|
||||||
});
|
|
||||||
|
|
||||||
// En-têtes
|
|
||||||
table.Header(header =>
|
|
||||||
{
|
|
||||||
header.Cell().Element(CellHeader).Text("Produit");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Qté");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("PU");
|
|
||||||
header.Cell().Element(CellHeader).AlignRight().Text("Total");
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var l in lignes)
|
|
||||||
{
|
|
||||||
table.Cell().Element(CellBody).Text(l.Product?.Name);
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString());
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity:n2} €");
|
|
||||||
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity * l.Quantity:n2} €");
|
|
||||||
|
|
||||||
total = total + l.Quantity * l.Quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
IContainer CellHeader(IContainer c) =>
|
|
||||||
c.BorderBottom(1).PaddingVertical(5).DefaultTextStyle(x => x.SemiBold());
|
|
||||||
|
|
||||||
IContainer CellBody(IContainer c) =>
|
|
||||||
c.PaddingVertical(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
col.Item().LineHorizontal(1);
|
|
||||||
col.Item().Height(30);
|
|
||||||
|
|
||||||
col.Item().Row(row =>
|
|
||||||
{
|
|
||||||
// Colonne gauche : conditions de vente
|
|
||||||
row.RelativeItem().Column(left =>
|
|
||||||
{
|
|
||||||
left.Item().Text("Conditions de vente")
|
|
||||||
.SemiBold().FontSize(12);
|
|
||||||
left.Item().Text(quotation.ConditionsSale)
|
|
||||||
.FontSize(9);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Colonne droite : totaux
|
|
||||||
row.ConstantItem(180).Column(right =>
|
|
||||||
{
|
|
||||||
right.Item().AlignRight().Text($"Total HT : {total:n2} €");
|
|
||||||
right.Item().AlignRight().Text("Taxe : 20 %");
|
|
||||||
right.Item().AlignRight().Text($"Total TTC : {(total * 1.2):n2} €");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Signature en bas à droite
|
|
||||||
page.Footer().AlignRight().Column(col =>
|
|
||||||
{
|
|
||||||
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pour avoir la vue du PDF en temps réel
|
|
||||||
// document.ShowInCompanion();
|
|
||||||
|
|
||||||
return document.GeneratePdf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using Ardalis.Specification;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Specifications.DeliveryNotes;
|
|
||||||
|
|
||||||
public class GetDeliveryNoteByIdWithProductsSpec : Specification<DeliveryNote>
|
|
||||||
{
|
|
||||||
public GetDeliveryNoteByIdWithProductsSpec(int deliveryNoteId)
|
|
||||||
{
|
|
||||||
Query
|
|
||||||
.Where(d => d.Id == deliveryNoteId)
|
|
||||||
.Include(d => d.ProductDeliveries!)
|
|
||||||
.ThenInclude(dp => dp.Product);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using Ardalis.Specification;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Specifications.PurchaseOrders;
|
|
||||||
|
|
||||||
public class GetPurchaseOrderByIdWithProductsSpec : Specification<PurchaseOrder>
|
|
||||||
{
|
|
||||||
public GetPurchaseOrderByIdWithProductsSpec(int purchaseOrderId)
|
|
||||||
{
|
|
||||||
Query
|
|
||||||
.Where(p => p.Id == purchaseOrderId)
|
|
||||||
.Include(p => p.PurchaseProducts!)
|
|
||||||
.ThenInclude(pp => pp.Product);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using Ardalis.Specification;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Specifications.Quotations;
|
|
||||||
|
|
||||||
public class GetQuotationByIdWithProductsSpec : Specification<Quotation>
|
|
||||||
{
|
|
||||||
public GetQuotationByIdWithProductsSpec(int quotationId)
|
|
||||||
{
|
|
||||||
Query
|
|
||||||
.Where(q => q.Id == quotationId)
|
|
||||||
.Include(q => q.QuotationProducts!)
|
|
||||||
.ThenInclude(qp => qp.Product);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB |
Reference in New Issue
Block a user