Fixed error of display with price of product in all documents

This commit is contained in:
2026-05-25 16:38:33 +01:00
parent 48b9db6e1c
commit 3cb619cfa6
12 changed files with 2128 additions and 27 deletions
@@ -7,6 +7,7 @@ public class CreateDeliveryNoteDto
public DateOnly ExpeditionDate { get; set; }
public int DelivererId { get; set; }
public int SupplierId { get; set; }
public Dictionary<int, int>? ProductQuantities { get; set; }
}
@@ -6,6 +6,7 @@ public class GetPurchaseOrderDto
{
public int Id { get; set; }
public string? PurchaseConditions { get; set; }
public int SupplierId { get; set; }
public string? SupplierName { get; set; }
public List<GetPurchaseProductDto>? Products { get; set; }
}
@@ -4,6 +4,7 @@ using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.DeliveryNotes;
@@ -11,6 +12,7 @@ public class CreateDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository,
DeliverersRepository deliverersRepository,
ProductsRepository productsRepository,
SuppliersRepository suppliersRepository,
ProductDeliveriesRepository productDeliveriesRepository) : Endpoint<CreateDeliveryNoteDto>
{
public override void Configure()
@@ -22,7 +24,8 @@ public class CreateDeliveryNoteEndpoint(
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct)
{
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
if (deliverer is null)
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct);
if (deliverer is null || supplier is null)
{
await Send.NotFoundAsync(ct);
return;
@@ -36,6 +39,8 @@ public class CreateDeliveryNoteEndpoint(
ExpeditionDate = req.ExpeditionDate,
DelivererId = deliverer.Id,
Deliverer = deliverer,
SupplierId = req.SupplierId,
Supplier = supplier
};
await deliveryNotesRepository.AddAsync(newDeliveryNote, ct);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class AddedMissingFieldForSupplierInDeliveryNote : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "SupplierId",
table: "DeliveryNotes",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_DeliveryNotes_SupplierId",
table: "DeliveryNotes",
column: "SupplierId");
migrationBuilder.AddForeignKey(
name: "FK_DeliveryNotes_Suppliers_SupplierId",
table: "DeliveryNotes",
column: "SupplierId",
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DeliveryNotes_Suppliers_SupplierId",
table: "DeliveryNotes");
migrationBuilder.DropIndex(
name: "IX_DeliveryNotes_SupplierId",
table: "DeliveryNotes");
migrationBuilder.DropColumn(
name: "SupplierId",
table: "DeliveryNotes");
}
}
}
@@ -329,6 +329,9 @@ namespace PyroFetes.Migrations
b.Property<DateOnly?>("RealDeliveryDate")
.HasColumnType("date");
b.Property<int>("SupplierId")
.HasColumnType("int");
b.Property<string>("TrackingNumber")
.IsRequired()
.HasMaxLength(100)
@@ -338,6 +341,8 @@ namespace PyroFetes.Migrations
b.HasIndex("DelivererId");
b.HasIndex("SupplierId");
b.ToTable("DeliveryNotes");
});
@@ -1353,7 +1358,15 @@ namespace PyroFetes.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PyroFetes.Models.Supplier", "Supplier")
.WithMany("DeliveryNotes")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Deliverer");
b.Navigation("Supplier");
});
modelBuilder.Entity("PyroFetes.Models.ExperienceLevel", b =>
@@ -1969,6 +1982,8 @@ namespace PyroFetes.Migrations
modelBuilder.Entity("PyroFetes.Models.Supplier", b =>
{
b.Navigation("DeliveryNotes");
b.Navigation("Prices");
b.Navigation("PurchaseOrders");
@@ -16,7 +16,7 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
{
byte[] logo = Convert.FromBase64String(setting.Logo!);
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
int total = 0;
decimal total = 0;
int totalQuantity = 0;
Document document = Document.Create(container =>
{
@@ -42,7 +42,7 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
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}");
col.Item().AlignLeft().Text(deliveryNote.RealDeliveryDate is null ? "Pas encore arrivée à destination" : $"Reçu le {deliveryNote.RealDeliveryDate}");
});
// Logo + société à droite
@@ -95,13 +95,17 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
foreach (ProductDelivery l in lignes)
{
decimal price = l.Product!.Prices!
.FirstOrDefault(x => x.SupplierId == l.DeliveryNote!.SupplierId && x.ProductId == l.ProductId)
?.SellingPrice ?? 0;
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} €");
table.Cell().Element(CellBody).AlignRight().Text($"{price:n2} €");
table.Cell().Element(CellBody).AlignRight().Text($"{l.Quantity * price:n2} €");
totalQuantity += l.Quantity;
total += l.Quantity * l.Quantity;
total += l.Quantity * price;
}
IContainer CellHeader(IContainer c) =>
@@ -114,10 +118,10 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
col.Item().LineHorizontal(1);
col.Item().Height(30);
col.Item().AlignRight().Text($"Total: {totalQuantity:n2} produits");
col.Item().AlignRight().Text($"Total: {totalQuantity} 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} €");
col.Item().AlignRight().Text($"Total TTC: {total * (decimal)1.2:n2} €");
});
// Signature en bas à droite
@@ -35,8 +35,11 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
col.Item().Text("");
col.Item().Text("");
col.Item().Text("");
col.Item().Text("Fournisseur").SemiBold().FontSize(12);
col.Item().Text("Mettre fournisseur ici");
col.Item().Text("Fournisseur :").SemiBold().FontSize(12);
col.Item().Text($"{purchaseOrder.Supplier?.Name}");
col.Item().Text($"{purchaseOrder.Supplier?.Address}");
col.Item().Text($"{purchaseOrder.Supplier?.ZipCode} {purchaseOrder.Supplier?.City}");
col.Item().Text($"{purchaseOrder.Supplier?.DeliveryDelay} jours de délai moyen de livraison");
});
// Logo + société à droite
@@ -93,7 +96,7 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
foreach (PurchaseProduct l in lignes)
{
decimal price = l.Product!.Prices!
.FirstOrDefault(p => p.SupplierId == l.PurchaseOrder!.SupplierId)
.FirstOrDefault(x => x.SupplierId == l.PurchaseOrder!.SupplierId && x.ProductId == l.ProductId)
?.SellingPrice ?? 0;
table.Cell().Element(CellBody).Text(l.Product?.Name);
@@ -129,10 +132,10 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
// Colonne droite : totaux
row.ConstantItem(180).Column(right =>
{
right.Item().AlignRight().Text($"Total: {totalQuantity:n2} produits");
right.Item().AlignRight().Text($"Total: {totalQuantity} 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} €");
right.Item().AlignRight().Text($"Total TTC: {total * (decimal)1.2:n2} €");
});
});
});
+11 -9
View File
@@ -16,7 +16,7 @@ public class QuotationPdfService : IQuotationPdfService
{
byte[] logo = Convert.FromBase64String(setting.Logo!);
byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
int total = 0;
decimal total = 0;
Document document = Document.Create(container =>
{
container.Page(page =>
@@ -91,19 +91,21 @@ public class QuotationPdfService : IQuotationPdfService
foreach (QuotationProduct l in lignes)
{
decimal price = l.Product!.Prices!
.FirstOrDefault(x => x.SupplierId == l.Quotation!.SupplierId && x.ProductId == l.ProductId)
?.SellingPrice ?? 0;
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} €");
table.Cell().Element(CellBody).AlignRight().Text($"{price:n2} €");
table.Cell().Element(CellBody).AlignRight().Text($"{price * l.Quantity:n2} €");
total = total + l.Quantity * l.Quantity;
total += l.Quantity * price;
}
IContainer CellHeader(IContainer c) =>
c.BorderBottom(1).PaddingVertical(5).DefaultTextStyle(x => x.SemiBold());
IContainer CellHeader(IContainer c) => c.BorderBottom(1).PaddingVertical(5).DefaultTextStyle(x => x.SemiBold());
IContainer CellBody(IContainer c) =>
c.PaddingVertical(2);
IContainer CellBody(IContainer c) => c.PaddingVertical(2);
});
col.Item().LineHorizontal(1);
@@ -125,7 +127,7 @@ public class QuotationPdfService : IQuotationPdfService
{
right.Item().AlignRight().Text($"Total HT : {total:n2} €");
right.Item().AlignRight().Text("Taxe : 20 %");
right.Item().AlignRight().Text($"Total TTC : {(total * 1.2):n2} €");
right.Item().AlignRight().Text($"Total TTC : {total * (decimal)1.2:n2} €");
});
});
});
@@ -8,8 +8,11 @@ public class GetDeliveryNoteByIdWithProductsSpec : SingleResultSpecification<Del
public GetDeliveryNoteByIdWithProductsSpec(int deliveryNoteId)
{
Query
.Where(x => x.Id == deliveryNoteId)
.Include(x => x.ProductDeliveries!)
.ThenInclude(p => p.Product);
.ThenInclude(p => p.Product)
.ThenInclude(x => x!.Prices)
.Include(x => x.Deliverer)
.Include(x => x.Supplier)
.Where(x => x.Id == deliveryNoteId);
}
}
@@ -11,6 +11,7 @@ public class GetPurchaseOrderByIdWithProductsSpec : SingleResultSpecification<Pu
.Where(x => x.Id == purchaseOrderId)
.Include(x => x.PurchaseProducts!)
.ThenInclude(p => p.Product)
.ThenInclude(p => p!.Prices);
.ThenInclude(p => p!.Prices)
.Include(x => x.Supplier);
}
}
@@ -10,6 +10,7 @@ public class GetQuotationByIdWithProductsSpec : SingleResultSpecification<Quotat
Query
.Where(x => x.Id == quotationId)
.Include(x => x.QuotationProducts!)
.ThenInclude(p => p.Product);
.ThenInclude(x => x.Product)
.ThenInclude(x => x!.Prices);
}
}