Compare commits

...

21 Commits

Author SHA1 Message Date
e21e2afea4 fix error 2025-12-04 17:11:34 +01:00
17978e7c19 change response in endpoint to generate pdf 2025-12-04 16:38:27 +01:00
6a20676b32 added showcompagnon 2025-12-04 15:06:36 +01:00
e440dcd2b5 added pdf generation for all orders 2025-12-03 17:41:19 +01:00
bee1cfb0e3 added PDF generation for quotation 2025-12-03 17:00:02 +01:00
d709654410 fix error in GetTotalQuantityEndpoint.cs 2025-11-30 16:59:28 +01:00
4a82c51133 fixed errors 2025-11-30 15:43:59 +01:00
8a04adeec3 updated GetSupplierDto.cs 2025-11-30 15:35:08 +01:00
db9219e80f fix error in PatchRealDeliveryDateEndpoint.cs 2025-11-30 14:50:21 +01:00
9e6834754f added DeleteDeliveryNoteEndpoint.cs 2025-11-30 14:23:30 +01:00
efa7a0be6f added DeleteProductEndpoint.cs 2025-11-29 21:58:20 +01:00
2a439ccbb5 added mapper 2025-11-28 09:51:12 +01:00
5c6798a647 fixed errors 2025-11-27 17:24:48 +01:00
Cristiano
50a5f371dd Fixed Database 2025-11-27 14:35:35 +01:00
86c5d6ae7b new migration 2025-11-27 13:41:55 +01:00
1c0432a2c4 updated length of password in User.cs 2025-11-27 13:40:02 +01:00
3e8f36457e fixed errors in database 2025-11-26 20:37:49 +01:00
5d68ee6992 fix length on approval number 2025-11-26 19:43:54 +01:00
Cristiano
d26284d552 Merge branch 'feature/repositories-refactor' into develop 2025-11-20 16:45:55 +01:00
Cristiano
d537051bea Fix Type errors 2025-11-20 16:45:44 +01:00
Cristiano
3ad506f869 Retired /api in all the endpoints 2025-11-20 16:33:56 +01:00
88 changed files with 8895 additions and 85 deletions

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.DeliveryNote.Request;
public class GetDeliveryNotePdfDto
{
public int Id { get; set; }
}

View File

@@ -17,8 +17,8 @@ public class CreatePriceDto
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 decimal ProductCaliber { get; set; } public int ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; } public string? 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; }

View File

@@ -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 int SupplierZipCode { get; set; } public string? 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 decimal ProductCaliber { get; set; } public int ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; } public string? 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; }

View File

@@ -5,8 +5,8 @@ public class CreateProductDto
public string? References { get; set; } public string? References { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public decimal Duration {get; set;} public decimal Duration {get; set;}
public decimal Caliber { get; set; } public int Caliber { get; set; }
public int ApprovalNumber { get; set; } public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; } public decimal Weight { get; set; }
public decimal Nec { get; set; } public decimal Nec { get; set; }
public string? Image { get; set; } public string? Image { get; set; }

View File

@@ -6,8 +6,8 @@ public class UpdateProductDto
public string? References { get; set; } public string? References { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public decimal Duration {get; set;} public decimal Duration {get; set;}
public decimal Caliber { get; set; } public int Caliber { get; set; }
public int ApprovalNumber { get; set; } public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; } public decimal Weight { get; set; }
public decimal Nec { get; set; } public decimal Nec { get; set; }
public string? Image { get; set; } public string? Image { get; set; }

View File

@@ -6,8 +6,8 @@ public class GetProductDto
public string? References { get; set; } public string? References { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public decimal Duration {get; set;} public decimal Duration {get; set;}
public decimal Caliber { get; set; } public int Caliber { get; set; }
public int ApprovalNumber { get; set; } public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; } public decimal Weight { get; set; }
public decimal Nec { get; set; } public decimal Nec { get; set; }
public string? Image { get; set; } public string? Image { get; set; }

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.PurchaseOrder.Request;
public class GetPurchaseOrderPdfDto
{
public int Id { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.Quotation.Request;
public class GetQuotationPdfDto
{
public int Id { get; set; }
}

View File

@@ -1,3 +1,6 @@
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
@@ -10,4 +13,6 @@ 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; }
} }

View File

@@ -12,7 +12,7 @@ public class CreateDelivererEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("api/deliverers"); Post("/deliverers");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -13,7 +13,7 @@ public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository)
{ {
public override void Configure() public override void Configure()
{ {
Delete("api/deliverers/{@id}", x=>new {x.DelivererId}); Delete("/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -10,7 +10,7 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
{ {
public override void Configure() public override void Configure()
{ {
Get("api/deliverers"); Get("/deliverers");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -18,7 +18,7 @@ public class GetDelivererEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("api/deliverers/{@id}", x=>new {x.DelivererId}); Get("/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class UpdateDelivererEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Put("api/deliverers/{@id}", x=>new {x.Id}); Put("/deliverers/{@id}", x=>new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -17,7 +17,7 @@ public class CreateDeliveryNoteEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/DeliveryNote"); Post("/deliveryNotes");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -0,0 +1,38 @@
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);
}
}

View File

@@ -8,7 +8,7 @@ public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRep
{ {
public override void Configure() public override void Configure()
{ {
Get("api/deliveryNotes"); Get("/deliveryNotes");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -16,7 +16,7 @@ public class GetDeliveryNoteEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId}); Get("/deliveryNotes/{@id}", x=> new {x.DeliveryNoteId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -0,0 +1,43 @@
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);
}
}

View File

@@ -15,7 +15,7 @@ public class PatchRealDeliveryDateEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/deliveryNote/{@id}", x=> new {x.Id}); Patch("/deliveryNotes/{@id}", x=> new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }
@@ -30,6 +30,12 @@ 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);

View File

@@ -17,7 +17,7 @@ public class CreatePriceEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/prices"); Post("/prices");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -16,7 +16,7 @@ public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<D
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId}); Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -13,7 +13,7 @@ public class PatchPriceEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId }); Patch("/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -0,0 +1,38 @@
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);
}
}

View File

@@ -10,7 +10,7 @@ public class GetAllProductsEndpoint(ProductsRepository productsRepository) : End
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/products"); Get("/products");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -18,7 +18,7 @@ public class GetProductEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/products/{@Id}", x => new {x.Id}); Get("/products/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchProductMinimalStockEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id }); Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class UpdateProductEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Put("/api/products/{@Id}", x => new {x.Id}); Put("/products/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -17,7 +17,7 @@ public class DeletePurchaseOrderEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id}); Delete("/purchaseOrders/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -10,7 +10,7 @@ public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrders
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/purchaseOrders"); Get("/purchaseOrders");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -19,7 +19,7 @@ public class GetPurchaseOrderEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/purchaseOrders/{@Id}", x => new {x.Id}); Get("/purchaseOrders/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -0,0 +1,41 @@
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);
}
}

View File

@@ -15,7 +15,7 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id }); Patch("/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -17,7 +17,7 @@ public class CreatePurchaseProductEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/purchaseProducts"); Post("/purchaseProducts");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -16,7 +16,7 @@ public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchasePr
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId}); Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchPurchaseProductQuantityEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId }); Patch("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -17,7 +17,7 @@ public class CreateQuotationProductEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/quotationProduct"); Post("/quotationProducts");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -16,7 +16,7 @@ public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotatio
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId}); Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchQuotationProductQuantityEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId }); Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -17,7 +17,7 @@ public class DeleteQuotationEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/quotations/{@Id}", x => new {x.Id}); Delete("/quotations/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -11,7 +11,7 @@ public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository)
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/quotations"); Get("/quotations");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -19,7 +19,7 @@ public class GetQuotationEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/quotations/{@Id}", x => new {x.Id}); Get("/quotations/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -0,0 +1,42 @@
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);
}
}

View File

@@ -15,7 +15,7 @@ public class PatchQuotationConditionsSaleEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id }); Patch("/quotations/{@Id}/saleConditions", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -12,7 +12,7 @@ public class CreateSettingEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/setting"); Post("/settings");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -15,7 +15,7 @@ public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endp
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/setting/{@Id}", x => new {x.Id}); Delete("/settings/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -18,7 +18,7 @@ public class GetSettingEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/setting/{@Id}", x => new {x.Id}); Get("/settings/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchSettingElectronicSignatureEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchSettingLogoEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/setting/{@Id}/Logo", x => new {x.Id}); Patch("/settings/{@Id}/logo", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -12,7 +12,7 @@ public class CreateSupplierEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/suppliers"); Post("/suppliers");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -15,7 +15,7 @@ public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : E
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/suppliers/{@Id}", x => new {x.Id}); Delete("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -9,7 +9,7 @@ public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) :
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/suppliers"); Get("/suppliers");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -18,7 +18,7 @@ public class GetSupplierEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/suppliers/{@Id}", x => new {x.Id}); Get("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -8,13 +8,13 @@ using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers; namespace PyroFetes.Endpoints.Suppliers;
public class PatchSupplierDeleveryDelayEndpoint( public class PatchSupplierDeliveryDelayEndpoint(
SuppliersRepository suppliersRepository, SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto> AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class UpdateSupplierEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Put("/api/suppliers/{@Id}", x => new {x.Id}); Put("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -13,7 +13,7 @@ public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<Con
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/users/connect"); Post("/users/connection");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -4,6 +4,7 @@ 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;
@@ -13,12 +14,20 @@ public class CreateUserEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Post("/api/users"); Post("/users");
AllowAnonymous(); AllowAnonymous();
} }
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()

View File

@@ -15,7 +15,7 @@ public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint<Dele
{ {
public override void Configure() public override void Configure()
{ {
Delete("/api/users/{@Id}", x => new {x.Id}); Delete("/users/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -9,7 +9,7 @@ public class GetAllUsersEndpoint(UsersRepository usersRepository) : EndpointWith
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/users"); Get("/users");
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -18,7 +18,7 @@ public class GetUserEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/users/{@Id}", x => new {x.Id}); Get("/users/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -14,7 +14,7 @@ public class PatchUserPasswordEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/users/{@Id}/Password", x => new { x.Id }); Patch("/users/{@Id}/password", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }

View File

@@ -15,7 +15,7 @@ public class UpdateUserEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Put("/api/users/{@Id}", x => new {x.Id}); Put("/users/{@Id}", x => new {x.Id});
AllowAnonymous(); AllowAnonymous();
} }
@@ -30,7 +30,7 @@ public class UpdateUserEndpoint(
return; return;
} }
if (ckeckName != null) if (ckeckName != null && ckeckName.Id != user.Id)
{ {
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;

View File

@@ -17,7 +17,7 @@ public class GetTotalQuantityEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/api/wareHouseProduct/{@ProductId}", x => new { x.ProductId }); Get("/wareHouseProducts/{@ProductId}", x => new { x.ProductId });
AllowAnonymous(); AllowAnonymous();
} }
@@ -31,9 +31,10 @@ public class GetTotalQuantityEndpoint(
return; return;
} }
int totalQuantity = int? totalQuantityNullable = await warehouseProductsRepository.
await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId), SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
wp => wp.Quantity, ct);
int totalQuantity = totalQuantityNullable ?? 0;
GetTotalQuantityDto responseDto = new() GetTotalQuantityDto responseDto = new()
{ {

View File

@@ -6,23 +6,27 @@ using PyroFetes.Models;
namespace PyroFetes.Endpoints.WareHouseProducts; namespace PyroFetes.Endpoints.WareHouseProducts;
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto> public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/wareHouseProduct/{@ProductId}/{@WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId }); Patch("/wareHouseProducts/{@ProductId}/{@WareHouseId}/quantity", x => new { x.ProductId, x.WareHouseId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct) public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
{ {
WarehouseProduct? wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct); WarehouseProduct? wareHouseProduct =
await database.WarehouseProducts.SingleOrDefaultAsync(
wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
if (wareHouseProduct == null) if (wareHouseProduct == null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
wareHouseProduct.Quantity = req.Quantity; wareHouseProduct.Quantity = req.Quantity;
await database.SaveChangesAsync(ct); await database.SaveChangesAsync(ct);

View File

@@ -9,6 +9,7 @@ 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;
@@ -21,6 +22,8 @@ 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>();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class FixTypeErrors : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(5)",
maxLength: 5,
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "Caliber",
table: "Products",
type: "int",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(18,2)");
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ZipCode",
table: "Suppliers",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(5)",
oldMaxLength: 5);
migrationBuilder.AlterColumn<decimal>(
name: "Caliber",
table: "Products",
type: "decimal(18,2)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "ApprovalNumber",
table: "Products",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class UpdatedDatabaseProductType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(100)",
oldMaxLength: 100);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class UpdatedLengthOfPassword : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Password",
table: "Users",
type: "nvarchar(60)",
maxLength: 60,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(50)",
oldMaxLength: 50);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Password",
table: "Users",
type: "nvarchar(50)",
maxLength: 50,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(60)",
oldMaxLength: 60);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class FixZipCode : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Warehouses",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(5)",
oldMaxLength: 5);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ZipCode",
table: "Warehouses",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(5)",
maxLength: 5,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

View File

@@ -503,11 +503,13 @@ namespace PyroFetes.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApprovalNumber") b.Property<string>("ApprovalNumber")
.HasColumnType("int"); .IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<decimal>("Caliber") b.Property<int>("Caliber")
.HasColumnType("decimal(18,2)"); .HasColumnType("int");
b.Property<int>("ClassificationId") b.Property<int>("ClassificationId")
.HasColumnType("int"); .HasColumnType("int");
@@ -1113,8 +1115,9 @@ namespace PyroFetes.Migrations
.HasMaxLength(30) .HasMaxLength(30)
.HasColumnType("nvarchar(30)"); .HasColumnType("nvarchar(30)");
b.Property<int>("ZipCode") b.Property<string>("ZipCode")
.HasColumnType("int"); .IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@@ -1178,8 +1181,8 @@ namespace PyroFetes.Migrations
b.Property<string>("Password") b.Property<string>("Password")
.IsRequired() .IsRequired()
.HasMaxLength(50) .HasMaxLength(60)
.HasColumnType("nvarchar(50)"); .HasColumnType("nvarchar(60)");
b.Property<string>("Salt") b.Property<string>("Salt")
.IsRequired() .IsRequired()
@@ -1223,8 +1226,9 @@ namespace PyroFetes.Migrations
.HasMaxLength(100) .HasMaxLength(100)
.HasColumnType("nvarchar(100)"); .HasColumnType("nvarchar(100)");
b.Property<int>("ZipCode") b.Property<string>("ZipCode")
.HasColumnType("int"); .IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");

View File

@@ -8,8 +8,8 @@ namespace PyroFetes.Models
[Required, MaxLength(20)] public string? Reference { get; set; } [Required, MaxLength(20)] public string? Reference { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; } [Required, MaxLength(100)] public string? Name { get; set; }
[Required] public decimal Duration {get; set;} [Required] public decimal Duration {get; set;}
[Required] public decimal Caliber { get; set; } [Required] public int Caliber { get; set; }
[Required] public int ApprovalNumber { get; set; } [Required, MaxLength(100)] public string? ApprovalNumber { get; set; }
[Required] public decimal Weight { get; set; } [Required] public decimal Weight { get; set; }
[Required] public decimal Nec { get; set; } [Required] public decimal Nec { get; set; }
[Required] public string? Image { get; set; } [Required] public string? Image { get; set; }

View File

@@ -9,7 +9,7 @@ public class Supplier
[Required, MaxLength(100)] public string? Email { get; set; } [Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(30)] public string? Phone { get; set; } [Required, MaxLength(30)] public string? Phone { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; } [Required, MaxLength(100)] public string? Address { get; set; }
[Required,MaxLength(5),MinLength(5)] public string? ZipCode { get; set; } [Required,Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; } [Required, MaxLength(100)] public string? City { get; set; }
[Required] public int DeliveryDelay { get; set; } [Required] public int DeliveryDelay { get; set; }

View File

@@ -6,7 +6,7 @@ public class User
{ {
[Key] public int Id { get; set; } [Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; } [Required, MaxLength(100)] public string? Name { get; set; }
[Required, MinLength(12), MaxLength(50)] public string? Password { get; set; } [Required, MaxLength(60)] public string? Password { get; set; }
[Required, MaxLength(100)] public string? Salt { get; set; } [Required, MaxLength(100)] public string? Salt { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; } [Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(100)] public string? Fonction { get; set; } [Required, MaxLength(100)] public string? Fonction { get; set; }

View File

@@ -10,7 +10,7 @@ public class Warehouse
[Required] public int Current {get; set;} [Required] public int Current {get; set;}
[Required] public int MinWeight {get; set;} [Required] public int MinWeight {get; set;}
[Required, MaxLength(100)] public string? Address { get; set; } [Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; } [Required, Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; } [Required, MaxLength(100)] public string? City { get; set; }
public List<WarehouseProduct>? WarehouseProducts { get; set; } public List<WarehouseProduct>? WarehouseProducts { get; set; }

View File

@@ -4,11 +4,17 @@ 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")
@@ -25,7 +31,8 @@ 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);
}); });
}); });
@@ -46,6 +53,11 @@ 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();

View File

@@ -23,7 +23,21 @@
<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>

View File

@@ -0,0 +1,133 @@
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();
}
}

View File

@@ -0,0 +1,146 @@
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();
}
}

View File

@@ -0,0 +1,147 @@
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();
}
}

View File

@@ -0,0 +1,15 @@
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);
}
}

View File

@@ -0,0 +1,15 @@
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);
}
}

View File

@@ -0,0 +1,15 @@
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.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB