mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-08-03 15:11:40 +00:00
Aggregationslogik in AssemblyPartAggregator entfernen. Sub-Assembly Rows ebenfalls via processBomEntriesWithAggregatedParts ermitteln
This commit is contained in:
parent
ad3fd27d10
commit
6b5c3ee52b
2 changed files with 5 additions and 93 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue