From 6b5c3ee52b00d6dffe50390d4fc2f94ee417a403 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Mon, 27 Jul 2026 10:24:06 +0200 Subject: [PATCH] Aggregationslogik in AssemblyPartAggregator entfernen. Sub-Assembly Rows ebenfalls via processBomEntriesWithAggregatedParts ermitteln --- .../Assemblies/AssemblyPartAggregator.php | 59 ------------------- .../ImportExportSystem/EntityExporter.php | 39 ++---------- 2 files changed, 5 insertions(+), 93 deletions(-) diff --git a/src/Helpers/Assemblies/AssemblyPartAggregator.php b/src/Helpers/Assemblies/AssemblyPartAggregator.php index ecf336f4..e4139049 100644 --- a/src/Helpers/Assemblies/AssemblyPartAggregator.php +++ b/src/Helpers/Assemblies/AssemblyPartAggregator.php @@ -35,65 +35,6 @@ class AssemblyPartAggregator { } - /** - * Aggregate the required parts and their total quantities for an assembly. - * - * @param Assembly $assembly The assembly to process. - * @param float $multiplier The quantity multiplier from the parent assembly. - * @return array Array of parts with their aggregated quantities, keyed by Part ID. - */ - public function getAggregatedParts(Assembly $assembly, float $multiplier): array - { - $aggregatedParts = []; - - // Start processing the assembly recursively - $this->processAssembly($assembly, $multiplier, $aggregatedParts); - - // Return the final aggregated list of parts - return $aggregatedParts; - } - - /** - * Recursive helper to process an assembly and all its BOM entries. - * - * @param Assembly $assembly The current assembly to process. - * @param float $multiplier The quantity multiplier from the parent assembly. - * @param array &$aggregatedParts The array to accumulate parts and their quantities. - */ - private function processAssembly(Assembly $assembly, float $multiplier, array &$aggregatedParts): void - { - /** @var AssemblyBOMEntry $bomEntry */ - foreach ($assembly->getBomEntries() as $bomEntry) { - // If the BOM entry refers to a part, add its quantity - if ($bomEntry->getPart() instanceof Part) { - $part = $bomEntry->getPart(); - - if (!isset($aggregatedParts[$part->getId()])) { - $aggregatedParts[$part->getId()] = [ - 'part' => $part, - 'assembly' => $assembly, - 'name' => $bomEntry->getName(), - 'designator' => $bomEntry->getDesignator(), - 'quantity' => $bomEntry->getQuantity(), - 'multiplier' => $multiplier, - ]; - } - } elseif ($bomEntry->getReferencedAssembly() instanceof Assembly) { - // If the BOM entry refers to another assembly, process it recursively - $this->processAssembly($bomEntry->getReferencedAssembly(), $bomEntry->getQuantity(), $aggregatedParts); - } else { - $aggregatedParts[] = [ - 'part' => null, - 'assembly' => $assembly, - 'name' => $bomEntry->getName(), - 'designator' => $bomEntry->getDesignator(), - 'quantity' => $bomEntry->getQuantity(), - 'multiplier' => $multiplier, - ]; - } - } - } - /** * Exports a hierarchical Bill of Materials (BOM) for assemblies and parts in a readable format, * including the multiplier for each part and assembly. diff --git a/src/Services/ImportExportSystem/EntityExporter.php b/src/Services/ImportExportSystem/EntityExporter.php index ef7db978..85408d73 100644 --- a/src/Services/ImportExportSystem/EntityExporter.php +++ b/src/Services/ImportExportSystem/EntityExporter.php @@ -569,9 +569,10 @@ class EntityExporter * * @param Assembly $assembly The assembly being processed. * @param int $depth The current depth in the hierarchy. + * @param string|null $type The type of the entity being processed. * @return array Processed BOM entries and aggregated parts rows. */ - private function processBomEntriesWithAggregatedParts(Assembly $assembly, int $depth): array + private function processBomEntriesWithAggregatedParts(Assembly $assembly, int $depth, ?string $type = null): array { $rows = []; @@ -581,7 +582,7 @@ class EntityExporter $rows[] = [ 'Id' => $assembly->getId(), 'ParentId' => '', - 'Type' => 'assembly_bom_entry', + 'Type' => $type ?? 'assembly_bom_entry', 'AssemblyIpn' => $assembly->getIpn(), 'AssemblyStatus' => $bomEntry->getReferencedAssembly() ? $assembly->getStatus() : '-', 'AssemblyNameHierarchical' => str_repeat('--', $depth) . '> ' . $assembly->getName(), @@ -608,38 +609,8 @@ class EntityExporter if ($bomEntry->getReferencedAssembly() instanceof Assembly) { $referencedAssembly = $bomEntry->getReferencedAssembly(); - // Get aggregated parts for the referenced assembly - $aggregatedParts = $this->assemblyPartAggregator->getAggregatedParts($referencedAssembly, $bomEntry->getQuantity());; - - foreach ($aggregatedParts as $partData) { - $partAssembly = $partData['assembly'] ?? null; - - $rows[] = [ - 'Id' => $assembly->getId(), - 'ParentId' => '', - 'Type' => 'subassembly_part_list', - 'AssemblyIpn' => $partAssembly ? $partAssembly->getIpn() : '', - 'AssemblyStatus' => $partAssembly ? $partAssembly->getStatus() : '-', - 'AssemblyNameHierarchical' => '', - 'AssemblyName' => $partAssembly ? $partAssembly->getName() : '', - 'AssemblyFullName' => $this->getFullName($partAssembly), - - //BOM relevant attributes - 'Quantity' => $partData['quantity'], - 'PartId' => $partData['part']?->getId(), - 'PartName' => $partData['part']?->getName(), - 'Ipn' => $partData['part']?->getIpn(), - 'Manufacturer' => $partData['part']?->getManufacturer()?->getName() ?? '-', - 'Mpn' => $partData['part']?->getManufacturerProductNumber(), - 'Name' => $partData['name'] ?? '', - 'Designator' => $partData['designator'], - 'Description' => $partData['part']?->getDescription(), - 'ReferencedAssemblyId' => '-', - 'ReferencedAssemblyIpn' => '-', - 'ReferencedAssemblyStatus' => '-', - 'ReferencedAssemblyFullName' => '-', - ]; - } + $subAssemblyRows = $this->processBomEntriesWithAggregatedParts($referencedAssembly, $depth + 1, 'subassembly_part_list'); + $rows = array_merge($rows, $subAssemblyRows); } }