From 0486ebfdbed4a58bb58996cdff04b15e42f82cd7 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 29 Oct 2025 11:04:08 -0400 Subject: [PATCH] fix(parts): normalize drawing names for matching - Strip directories and extensions and compare using ToUpperInvariant - Improves resilience when sources differ in path/casing/extension formatting - Ensures accurate QtyNested across plates with duplicates --- PepApi.Core/PepHelper.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/PepApi.Core/PepHelper.cs b/PepApi.Core/PepHelper.cs index ae9a2ad..5e54603 100644 --- a/PepApi.Core/PepHelper.cs +++ b/PepApi.Core/PepHelper.cs @@ -117,14 +117,30 @@ namespace PepApi.Core part.QtyNested = 0; var nestedOn = new List(); - var partName = part.Name.ToUpper(); + // Normalize drawing names by stripping directories and extensions + // to make matching resilient to format differences between sources. + string Normalize(string? name) + { + if (string.IsNullOrWhiteSpace(name)) return string.Empty; + try + { + var fileOnly = System.IO.Path.GetFileNameWithoutExtension(name); + return fileOnly.ToUpperInvariant(); + } + catch + { + return name.Trim().ToUpperInvariant(); + } + } + + var partName = Normalize(part.Name); for (int i = 0; i < nest.Plates.Count; i++) { var plate = nest.Plates[i]; var qtyNested = 0; - qtyNested = plate.Parts.Count(p => p.DrawingName?.ToUpper() == partName); + qtyNested = plate.Parts.Count(p => Normalize(p.DrawingName) == partName); // plate.Duplicates is actually the quantity, so 1 Duplicate = 1 plate qtyNested *= plate.Duplicates;