Skip to content

Commit 6bb20fb

Browse files
author
Marcel Diegelmann
committed
Entferne Projektbezogene Logik bzw. Verweise auf Baugruppen, da nicht benötigt. Überarbeitung Exporter: Aufnahme von Parts aus Subassemblies.
1 parent abbadb9 commit 6bb20fb

22 files changed

+195
-170
lines changed

src/Controller/AssemblyController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use App\Entity\AssemblySystem\Assembly;
3030
use App\Entity\AssemblySystem\AssemblyBOMEntry;
3131
use App\Entity\Parts\Part;
32-
use App\Entity\UserSystem\User;
3332
use App\Exceptions\InvalidRegexException;
3433
use App\Form\AssemblySystem\AssemblyAddPartsType;
3534
use App\Form\AssemblySystem\AssemblyBuildType;

src/DataTables/AssemblyBomEntriesDataTable.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
use App\DataTables\Column\LocaleDateTimeColumn;
2727
use App\DataTables\Column\MarkdownColumn;
2828
use App\DataTables\Helpers\AssemblyDataTableHelper;
29-
use App\DataTables\Helpers\ProjectDataTableHelper;
3029
use App\DataTables\Helpers\ColumnSortHelper;
3130
use App\DataTables\Helpers\PartDataTableHelper;
3231
use App\Entity\AssemblySystem\Assembly;
3332
use App\Entity\Attachments\Attachment;
3433
use App\Entity\Parts\Part;
3534
use App\Entity\AssemblySystem\AssemblyBOMEntry;
36-
use App\Entity\ProjectSystem\Project;
3735
use App\Services\Formatters\AmountFormatter;
3836
use App\Settings\BehaviorSettings\TableSettings;
3937
use Doctrine\ORM\QueryBuilder;
@@ -49,7 +47,6 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface
4947
public function __construct(
5048
private readonly TranslatorInterface $translator,
5149
private readonly PartDataTableHelper $partDataTableHelper,
52-
private readonly ProjectDataTableHelper $projectDataTableHelper,
5350
private readonly AssemblyDataTableHelper $assemblyDataTableHelper,
5451
private readonly AmountFormatter $amountFormatter,
5552
private readonly ColumnSortHelper $csh,
@@ -90,7 +87,7 @@ public function configure(DataTable $dataTable, array $options): void
9087
'label' => $this->translator->trans('part.table.name'),
9188
'orderField' => 'NATSORT(part.name)',
9289
'render' => function ($value, AssemblyBOMEntry $context) {
93-
if(!$context->getPart() instanceof Part && !$context->getReferencedAssembly() instanceof Assembly && !$context->getProject() instanceof Project) {
90+
if(!$context->getPart() instanceof Part && !$context->getReferencedAssembly() instanceof Assembly) {
9491
return htmlspecialchars((string) $context->getName());
9592
}
9693

@@ -105,13 +102,6 @@ public function configure(DataTable $dataTable, array $options): void
105102
$tmp = $this->assemblyDataTableHelper->renderName($context->getReferencedAssembly());
106103
$tmp = $this->translator->trans('part.table.name.value.for_assembly', ['%value%' => $tmp]);
107104

108-
if($context->getName() !== null && $context->getName() !== '') {
109-
$tmp .= '<br><b>'.htmlspecialchars($context->getName()).'</b>';
110-
}
111-
} elseif ($context->getProject() !== null) {
112-
$tmp = $this->projectDataTableHelper->renderName($context->getProject());
113-
$tmp = $this->translator->trans('part.table.name.value.for_project', ['%value%' => $tmp]);
114-
115105
if($context->getName() !== null && $context->getName() !== '') {
116106
$tmp .= '<br><b>'.htmlspecialchars($context->getName()).'</b>';
117107
}

src/Entity/AssemblySystem/Assembly.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class Assembly extends AbstractStructuralDBElement
118118
#[Groups(['extended', 'full', 'import'])]
119119
#[ORM\OneToMany(targetEntity: AssemblyBOMEntry::class, mappedBy: 'assembly', cascade: ['persist', 'remove'], orphanRemoval: true)]
120120
#[UniqueObjectCollection(message: 'assembly.bom_entry.part_already_in_bom', fields: ['part'])]
121-
#[UniqueObjectCollection(message: 'assembly.bom_entry.project_already_in_bom', fields: ['project'])]
122121
#[UniqueObjectCollection(message: 'assembly.bom_entry.name_already_in_bom', fields: ['name'])]
123122
protected Collection $bom_entries;
124123

@@ -137,7 +136,7 @@ class Assembly extends AbstractStructuralDBElement
137136
* @var string|null The internal ipn number of the assembly
138137
*/
139138
#[Assert\Length(max: 100)]
140-
#[Groups(['extended', 'full', 'project:read', 'project:write', 'import'])]
139+
#[Groups(['extended', 'full', 'assembly:read', 'assembly:write', 'import'])]
141140
#[ORM\Column(type: Types::STRING, length: 100, unique: true, nullable: true)]
142141
#[Length(max: 100)]
143142
protected ?string $ipn = null;

src/Entity/AssemblySystem/AssemblyBOMEntry.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
use ApiPlatform\Serializer\Filter\PropertyFilter;
3737
use App\ApiPlatform\Filter\LikeFilter;
3838
use App\Entity\Contracts\TimeStampableInterface;
39-
use App\Entity\ProjectSystem\Project;
4039
use App\Repository\DBElementRepository;
4140
use App\Validator\Constraints\AssemblySystem\AssemblyCycle;
4241
use App\Validator\Constraints\AssemblySystem\AssemblyInvalidBomEntry;
@@ -252,17 +251,6 @@ public function setReferencedAssembly(?Assembly $referencedAssembly): AssemblyBO
252251
return $this;
253252
}
254253

255-
public function getProject(): ?Project
256-
{
257-
return $this->project;
258-
}
259-
260-
public function setProject(?Project $project): AssemblyBOMEntry
261-
{
262-
$this->project = $project;
263-
return $this;
264-
}
265-
266254
/**
267255
* Returns the price of this BOM entry, if existing.
268256
* Prices are only valid on non-Part BOM entries.
@@ -300,6 +288,15 @@ public function isPartBomEntry(): bool
300288
return $this->part instanceof Part;
301289
}
302290

291+
/**
292+
* Checks whether this BOM entry is a assembly associated BOM entry or not.
293+
* @return bool True if this BOM entry is a assembly associated BOM entry, false otherwise.
294+
*/
295+
public function isAssemblyBomEntry(): bool
296+
{
297+
return $this->referencedAssembly !== null;
298+
}
299+
303300
#[Assert\Callback]
304301
public function validate(ExecutionContextInterface $context, $payload): void
305302
{
@@ -335,7 +332,7 @@ public function getComparableFields(): array
335332
return [
336333
'name' => $this->getName(),
337334
'part' => $this->getPart()?->getID(),
338-
'project' => $this->getProject()?->getID(),
335+
'referencedAssembly' => $this->getReferencedAssembly()?->getID(),
339336
];
340337
}
341338
}

src/EventSubscriber/UserSystem/PartUniqueIpnSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ private function ensureUniqueIpn(Part $part): void
7070
$part->setIpn($originalIpn . "_$increment");
7171
}
7272
}
73-
}
73+
}

src/Form/AssemblySystem/AssemblyBOMEntryType.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3939
->add('part', PartSelectType::class, [
4040
'required' => false,
4141
])
42-
->add('project', ProjectSelectType::class, [
43-
'label' => 'assembly.bom.project',
44-
'required' => false,
45-
])
4642
->add('referencedAssembly', AssemblySelectType::class, [
4743
'label' => 'assembly.bom.referencedAssembly',
4844
'required' => false,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
7+
*
8+
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as published
12+
* by the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
namespace App\Helpers\Assemblies;
24+
25+
use App\Entity\AssemblySystem\Assembly;
26+
use App\Entity\Parts\Part;
27+
28+
class AssemblyPartAggregator
29+
{
30+
/**
31+
* Aggregate the required parts and their total quantities for an assembly.
32+
*
33+
* @param Assembly $assembly The assembly to process.
34+
* @param float $multiplier The quantity multiplier from the parent assembly.
35+
* @return array Array of parts with their aggregated quantities, keyed by Part ID.
36+
*/
37+
public function getAggregatedParts(Assembly $assembly, float $multiplier): array
38+
{
39+
$aggregatedParts = [];
40+
41+
// Start processing the assembly recursively
42+
$this->processAssembly($assembly, $multiplier, $aggregatedParts);
43+
44+
// Return the final aggregated list of parts
45+
return $aggregatedParts;
46+
}
47+
48+
/**
49+
* Recursive helper to process an assembly and all its BOM entries.
50+
*
51+
* @param Assembly $assembly The current assembly to process.
52+
* @param float $multiplier The quantity multiplier from the parent assembly.
53+
* @param array &$aggregatedParts The array to accumulate parts and their quantities.
54+
*/
55+
private function processAssembly(Assembly $assembly, float $multiplier, array &$aggregatedParts): void
56+
{
57+
foreach ($assembly->getBomEntries() as $bomEntry) {
58+
// If the BOM entry refers to a part, add its quantity
59+
if ($bomEntry->getPart() instanceof Part) {
60+
$part = $bomEntry->getPart();
61+
62+
if (!isset($aggregatedParts[$part->getId()])) {
63+
$aggregatedParts[$part->getId()] = [
64+
'part' => $part,
65+
'assembly' => $assembly,
66+
'quantity' => $bomEntry->getQuantity(),
67+
'multiplier' => $multiplier,
68+
];
69+
}
70+
} elseif ($bomEntry->getReferencedAssembly() instanceof Assembly) {
71+
// If the BOM entry refers to another assembly, process it recursively
72+
$this->processAssembly($bomEntry->getReferencedAssembly(), $bomEntry->getQuantity(), $aggregatedParts);
73+
} else {
74+
$aggregatedParts[] = [
75+
'part' => null,
76+
'assembly' => $assembly,
77+
'quantity' => $bomEntry->getQuantity(),
78+
'multiplier' => $multiplier,
79+
];
80+
}
81+
}
82+
}
83+
}

src/Services/AssemblySystem/AssemblyBuildHelper.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
use App\Entity\Parts\Part;
2828
use App\Helpers\Assemblies\AssemblyBuildRequest;
2929
use App\Services\Parts\PartLotWithdrawAddHelper;
30-
use App\Services\ProjectSystem\ProjectBuildHelper;
3130

3231
/**
3332
* @see \App\Tests\Services\AssemblySystem\AssemblyBuildHelperTest
3433
*/
3534
class AssemblyBuildHelper
3635
{
3736
public function __construct(
38-
private readonly PartLotWithdrawAddHelper $withdraw_add_helper,
39-
private readonly ProjectBuildHelper $projectBuildHelper
37+
private readonly PartLotWithdrawAddHelper $withdraw_add_helper
4038
) {
4139
}
4240

@@ -70,15 +68,15 @@ public function getMaximumBuildableCount(Assembly $assembly): int
7068
/** @var AssemblyBOMEntry $bom_entry */
7169
foreach ($assembly->getBomEntries() as $bom_entry) {
7270
//Skip BOM entries without a part (as we can not determine that)
73-
if (!$bom_entry->isPartBomEntry() && $bom_entry->getProject() === null) {
71+
if (!$bom_entry->isPartBomEntry() && !$bom_entry->isAssemblyBomEntry()) {
7472
continue;
7573
}
7674

77-
//The maximum buildable count for the whole project is the minimum of all BOM entries
75+
//The maximum buildable count for the whole assembly is the minimum of all BOM entries
7876
if ($bom_entry->getPart() !== null) {
7977
$maximum_buildable_count = min($maximum_buildable_count, $this->getMaximumBuildableCountForBOMEntry($bom_entry));
8078
} elseif ($bom_entry->getReferencedAssembly() !== null) {
81-
$maximum_buildable_count = min($maximum_buildable_count, $this->projectBuildHelper->getMaximumBuildableCount($bom_entry->getReferencedAssembly()));
79+
$maximum_buildable_count = min($maximum_buildable_count, $this->getMaximumBuildableCount($bom_entry->getReferencedAssembly()));
8280
}
8381
}
8482

@@ -105,7 +103,7 @@ public function isBOMEntryBuildable(AssemblyBOMEntry $bom_entry, int $number_of_
105103
}
106104

107105
/**
108-
* Returns the project BOM entries for which parts are missing in the stock for the given number of builds
106+
* Returns the referenced assembly BOM entries for which parts are missing in the stock for the given number of builds
109107
* @param Assembly $assembly The assembly for which the BOM entries should be checked
110108
* @param int $number_of_builds How often should the assembly be build?
111109
* @return AssemblyBOMEntry[]

0 commit comments

Comments
 (0)