mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 13:49:33 +00:00
Assemblies einführen
This commit is contained in:
parent
e1418dfdc1
commit
f0748a2123
107 changed files with 14096 additions and 98 deletions
358
src/Entity/AssemblySystem/Assembly.php
Normal file
358
src/Entity/AssemblySystem/Assembly.php
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\AssemblySystem;
|
||||
|
||||
use App\Repository\AssemblyRepository;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Link;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\OpenApi\Model\Operation;
|
||||
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
||||
use App\ApiPlatform\Filter\LikeFilter;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Validator\Constraints\UniqueObjectCollection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Attachments\AssemblyAttachment;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use App\Entity\Parameters\AssemblyParameter;
|
||||
use App\Entity\Parts\Part;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* This class represents a assembly in the database.
|
||||
*
|
||||
* @extends AbstractStructuralDBElement<AssemblyAttachment, AssemblyParameter>
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: AssemblyRepository::class)]
|
||||
#[ORM\Table(name: 'assemblies')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(security: 'is_granted("read", object)'),
|
||||
new GetCollection(security: 'is_granted("@assemblies.read")'),
|
||||
new Post(securityPostDenormalize: 'is_granted("create", object)'),
|
||||
new Patch(security: 'is_granted("edit", object)'),
|
||||
new Delete(security: 'is_granted("delete", object)'),
|
||||
],
|
||||
normalizationContext: ['groups' => ['assembly:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
|
||||
denormalizationContext: ['groups' => ['assembly:write', 'api:basic:write', 'attachment:write', 'parameter:write'], 'openapi_definition_name' => 'Write'],
|
||||
)]
|
||||
#[ApiResource(
|
||||
uriTemplate: '/assemblies/{id}/children.{_format}',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
openapi: new Operation(summary: 'Retrieves the children elements of a assembly.'),
|
||||
security: 'is_granted("@assemblies.read")'
|
||||
)
|
||||
],
|
||||
uriVariables: [
|
||||
'id' => new Link(fromProperty: 'children', fromClass: Assembly::class)
|
||||
],
|
||||
normalizationContext: ['groups' => ['assembly:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
|
||||
)]
|
||||
#[ApiFilter(PropertyFilter::class)]
|
||||
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
|
||||
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
|
||||
class Assembly extends AbstractStructuralDBElement
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
#[ORM\JoinColumn(name: 'parent_id')]
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: false)]
|
||||
protected ?AbstractStructuralDBElement $parent = null;
|
||||
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, AssemblyBOMEntry>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\OneToMany(mappedBy: 'assembly', targetEntity: AssemblyBOMEntry::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[UniqueObjectCollection(message: 'assembly.bom_entry.part_already_in_bom', fields: ['part'])]
|
||||
#[UniqueObjectCollection(message: 'assembly.bom_entry.name_already_in_bom', fields: ['name'])]
|
||||
protected Collection $bom_entries;
|
||||
|
||||
#[ORM\Column(type: Types::INTEGER)]
|
||||
protected int $order_quantity = 0;
|
||||
|
||||
/**
|
||||
* @var string|null The current status of the assembly
|
||||
*/
|
||||
#[Assert\Choice(['draft', 'planning', 'in_production', 'finished', 'archived'])]
|
||||
#[Groups(['extended', 'full', 'assembly:read', 'assembly:write', 'import'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 64, nullable: true)]
|
||||
protected ?string $status = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var Part|null The (optional) part that represents the builds of this assembly in the stock
|
||||
*/
|
||||
#[ORM\OneToOne(mappedBy: 'built_assembly', targetEntity: Part::class, cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
protected ?Part $build_part = null;
|
||||
|
||||
#[ORM\Column(type: Types::BOOLEAN)]
|
||||
protected bool $order_only_missing_parts = false;
|
||||
|
||||
#[Groups(['simple', 'extended', 'full', 'assembly:read', 'assembly:write'])]
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
protected string $description = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, AssemblyAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AssemblyAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: AssemblyAttachment::class)]
|
||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
protected ?Attachment $master_picture_attachment = null;
|
||||
|
||||
/** @var Collection<int, AssemblyParameter>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AssemblyParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['assembly:read', 'assembly:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
#[Groups(['assembly:read'])]
|
||||
protected ?\DateTimeImmutable $addedDate = null;
|
||||
#[Groups(['assembly:read'])]
|
||||
protected ?\DateTimeImmutable $lastModified = null;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->attachments = new ArrayCollection();
|
||||
$this->parameters = new ArrayCollection();
|
||||
parent::__construct();
|
||||
$this->bom_entries = new ArrayCollection();
|
||||
$this->children = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
//When cloning this assembly, we have to clone each bom entry too.
|
||||
if ($this->id) {
|
||||
$bom_entries = $this->bom_entries;
|
||||
$this->bom_entries = new ArrayCollection();
|
||||
//Set master attachment is needed
|
||||
foreach ($bom_entries as $bom_entry) {
|
||||
$clone = clone $bom_entry;
|
||||
$this->addBomEntry($clone);
|
||||
}
|
||||
}
|
||||
|
||||
//Parent has to be last call, as it resets the ID
|
||||
parent::__clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order quantity of this assembly.
|
||||
*
|
||||
* @return int the order quantity
|
||||
*/
|
||||
public function getOrderQuantity(): int
|
||||
{
|
||||
return $this->order_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "order_only_missing_parts" attribute.
|
||||
*
|
||||
* @return bool the "order_only_missing_parts" attribute
|
||||
*/
|
||||
public function getOrderOnlyMissingParts(): bool
|
||||
{
|
||||
return $this->order_only_missing_parts;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the order quantity.
|
||||
*
|
||||
* @param int $new_order_quantity the new order quantity
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrderQuantity(int $new_order_quantity): self
|
||||
{
|
||||
if ($new_order_quantity < 0) {
|
||||
throw new InvalidArgumentException('The new order quantity must not be negative!');
|
||||
}
|
||||
$this->order_quantity = $new_order_quantity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "order_only_missing_parts" attribute.
|
||||
*
|
||||
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute
|
||||
*/
|
||||
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self
|
||||
{
|
||||
$this->order_only_missing_parts = $new_order_only_missing_parts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBomEntries(): Collection
|
||||
{
|
||||
return $this->bom_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addBomEntry(AssemblyBOMEntry $entry): self
|
||||
{
|
||||
$entry->setAssembly($this);
|
||||
$this->bom_entries->add($entry);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function removeBomEntry(AssemblyBOMEntry $entry): self
|
||||
{
|
||||
$this->bom_entries->removeElement($entry);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): Assembly
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): ?string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
*/
|
||||
public function setStatus(?string $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this assembly has an associated part representing the builds of this assembly in the stock.
|
||||
*/
|
||||
public function hasBuildPart(): bool
|
||||
{
|
||||
return $this->build_part instanceof Part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the part representing the builds of this assembly in the stock, if it is existing
|
||||
*/
|
||||
public function getBuildPart(): ?Part
|
||||
{
|
||||
return $this->build_part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the part representing the builds of this assembly in the stock.
|
||||
*/
|
||||
public function setBuildPart(?Part $build_part): void
|
||||
{
|
||||
$this->build_part = $build_part;
|
||||
if ($build_part instanceof Part) {
|
||||
$build_part->setBuiltAssembly($this);
|
||||
}
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
//If this assembly has subassemblies, and these have builds part, they must be included in the BOM
|
||||
foreach ($this->getChildren() as $child) {
|
||||
if (!$child->getBuildPart() instanceof Part) {
|
||||
continue;
|
||||
}
|
||||
//We have to search all bom entries for the build part
|
||||
$found = false;
|
||||
foreach ($this->getBomEntries() as $bom_entry) {
|
||||
if ($bom_entry->getPart() === $child->getBuildPart()) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//When the build part is not found, we have to add an error
|
||||
if (!$found) {
|
||||
$context->buildViolation('assembly.bom_has_to_include_all_subelement_parts')
|
||||
->atPath('bom_entries')
|
||||
->setParameter('%assembly_name%', $child->getName())
|
||||
->setParameter('%part_name%', $child->getBuildPart()->getName())
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
302
src/Entity/AssemblySystem/AssemblyBOMEntry.php
Normal file
302
src/Entity/AssemblySystem/AssemblyBOMEntry.php
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\AssemblySystem;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Link;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\OpenApi\Model\Operation;
|
||||
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
||||
use App\ApiPlatform\Filter\LikeFilter;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Repository\DBElementRepository;
|
||||
use App\Validator\UniqueValidatableInterface;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Validator\Constraints\BigDecimal\BigDecimalPositive;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* The AssemblyBOMEntry class represents an entry in a assembly's BOM.
|
||||
*/
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\Entity(repositoryClass: DBElementRepository::class)]
|
||||
#[ORM\Table('assembly_bom_entries')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(uriTemplate: '/assembly_bom_entries/{id}.{_format}', security: 'is_granted("read", object)',),
|
||||
new GetCollection(uriTemplate: '/assembly_bom_entries.{_format}', security: 'is_granted("@assemblies.read")',),
|
||||
new Post(uriTemplate: '/assembly_bom_entries.{_format}', securityPostDenormalize: 'is_granted("create", object)',),
|
||||
new Patch(uriTemplate: '/assembly_bom_entries/{id}.{_format}', security: 'is_granted("edit", object)',),
|
||||
new Delete(uriTemplate: '/assembly_bom_entries/{id}.{_format}', security: 'is_granted("delete", object)',),
|
||||
],
|
||||
normalizationContext: ['groups' => ['bom_entry:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
|
||||
denormalizationContext: ['groups' => ['bom_entry:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
|
||||
)]
|
||||
#[ApiResource(
|
||||
uriTemplate: '/assemblies/{id}/bom.{_format}',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
openapi: new Operation(summary: 'Retrieves the BOM entries of the given assembly.'),
|
||||
security: 'is_granted("@assemblies.read")'
|
||||
)
|
||||
],
|
||||
uriVariables: [
|
||||
'id' => new Link(fromProperty: 'bom_entries', fromClass: Assembly::class)
|
||||
],
|
||||
normalizationContext: ['groups' => ['bom_entry:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
|
||||
)]
|
||||
#[ApiFilter(PropertyFilter::class)]
|
||||
#[ApiFilter(LikeFilter::class, properties: ["name", "comment", 'mountnames'])]
|
||||
#[ApiFilter(RangeFilter::class, properties: ['quantity'])]
|
||||
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified', 'quantity'])]
|
||||
class AssemblyBOMEntry extends AbstractDBElement implements UniqueValidatableInterface, TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
#[Assert\Positive]
|
||||
#[ORM\Column(name: 'quantity', type: Types::FLOAT)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'simple', 'extended', 'full'])]
|
||||
protected float $quantity = 1.0;
|
||||
|
||||
/**
|
||||
* @var string A comma separated list of the names, where this parts should be placed
|
||||
*/
|
||||
#[ORM\Column(name: 'mountnames', type: Types::TEXT)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'simple', 'extended', 'full'])]
|
||||
protected string $mountnames = '';
|
||||
|
||||
/**
|
||||
* @var string|null An optional name describing this BOM entry (useful for non-part entries)
|
||||
*/
|
||||
#[Assert\Expression('this.getPart() !== null or this.getName() !== null', message: 'validator.assembly.bom_entry.name_or_part_needed')]
|
||||
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'simple', 'extended', 'full'])]
|
||||
protected ?string $name = null;
|
||||
|
||||
/**
|
||||
* @var string An optional comment for this BOM entry
|
||||
*/
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'extended', 'full'])]
|
||||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var Assembly|null
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: Assembly::class, inversedBy: 'bom_entries')]
|
||||
#[ORM\JoinColumn(name: 'id_assembly', nullable: true)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', ])]
|
||||
protected ?Assembly $assembly = null;
|
||||
|
||||
/**
|
||||
* @var Part|null The part associated with this
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'assembly_bom_entries')]
|
||||
#[ORM\JoinColumn(name: 'id_part')]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'full'])]
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var BigDecimal|null The price of this non-part BOM entry
|
||||
*/
|
||||
#[Assert\AtLeastOneOf([new BigDecimalPositive(), new Assert\IsNull()])]
|
||||
#[ORM\Column(type: 'big_decimal', precision: 11, scale: 5, nullable: true)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'extended', 'full'])]
|
||||
protected ?BigDecimal $price = null;
|
||||
|
||||
/**
|
||||
* @var ?Currency The currency for the price of this non-part BOM entry
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: Currency::class)]
|
||||
#[ORM\JoinColumn]
|
||||
#[Selectable]
|
||||
protected ?Currency $price_currency = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getQuantity(): float
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function setQuantity(float $quantity): AssemblyBOMEntry
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMountnames(): string
|
||||
{
|
||||
return $this->mountnames;
|
||||
}
|
||||
|
||||
public function setMountnames(string $mountnames): AssemblyBOMEntry
|
||||
{
|
||||
$this->mountnames = $mountnames;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName(?string $name): AssemblyBOMEntry
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComment(): string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
public function setComment(string $comment): AssemblyBOMEntry
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAssembly(): ?Assembly
|
||||
{
|
||||
return $this->assembly;
|
||||
}
|
||||
|
||||
public function setAssembly(?Assembly $assembly): AssemblyBOMEntry
|
||||
{
|
||||
$this->assembly = $assembly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPart(): ?Part
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
||||
public function setPart(?Part $part): AssemblyBOMEntry
|
||||
{
|
||||
$this->part = $part;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price of this BOM entry, if existing.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
*/
|
||||
public function getPrice(): ?BigDecimal
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the price of this BOM entry.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
*/
|
||||
public function setPrice(?BigDecimal $price): void
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
public function getPriceCurrency(): ?Currency
|
||||
{
|
||||
return $this->price_currency;
|
||||
}
|
||||
|
||||
public function setPriceCurrency(?Currency $price_currency): void
|
||||
{
|
||||
$this->price_currency = $price_currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this BOM entry is a part associated BOM entry or not.
|
||||
* @return bool True if this BOM entry is a part associated BOM entry, false otherwise.
|
||||
*/
|
||||
public function isPartBomEntry(): bool
|
||||
{
|
||||
return $this->part instanceof Part;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
//Round quantity to whole numbers, if the part is not a decimal part
|
||||
if ($this->part instanceof Part && (!$this->part->getPartUnit() || $this->part->getPartUnit()->isInteger())) {
|
||||
$this->quantity = round($this->quantity);
|
||||
}
|
||||
//Non-Part BOM entries are rounded
|
||||
if (!$this->part instanceof Part) {
|
||||
$this->quantity = round($this->quantity);
|
||||
}
|
||||
|
||||
//Check that the part is not the build representation part of this assembly or one of its parents
|
||||
if ($this->part && $this->part->getBuiltAssembly() instanceof Assembly) {
|
||||
//Get the associated assembly
|
||||
$associated_assembly = $this->part->getBuiltAssembly();
|
||||
//Check that it is not the same as the current assembly neither one of its parents
|
||||
$current_assembly = $this->assembly;
|
||||
while ($current_assembly) {
|
||||
if ($associated_assembly === $current_assembly) {
|
||||
$context->buildViolation('assembly.bom_entry.can_not_add_own_builds_part')
|
||||
->atPath('part')
|
||||
->addViolation();
|
||||
}
|
||||
$current_assembly = $current_assembly->getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getComparableFields(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'part' => $this->getPart()?->getID(),
|
||||
];
|
||||
}
|
||||
}
|
||||
48
src/Entity/Attachments/AssemblyAttachment.php
Normal file
48
src/Entity/Attachments/AssemblyAttachment.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Attachments;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Serializer\APIPlatform\OverrideClassDenormalizer;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
|
||||
/**
|
||||
* A attachment attached to a device element.
|
||||
* @extends Attachment<Assembly>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
class AssemblyAttachment extends Attachment
|
||||
{
|
||||
final public const ALLOWED_ELEMENT_CLASS = Assembly::class;
|
||||
/**
|
||||
* @var Assembly|null the element this attachment is associated with
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: Assembly::class, inversedBy: 'attachments')]
|
||||
#[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')]
|
||||
#[Context(denormalizationContext: [OverrideClassDenormalizer::CONTEXT_KEY => self::ALLOWED_ELEMENT_CLASS])]
|
||||
protected ?AttachmentContainingDBElement $element = null;
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ use function in_array;
|
|||
#[DiscriminatorMap(typeProperty: '_type', mapping: self::API_DISCRIMINATOR_MAP)]
|
||||
abstract class Attachment extends AbstractNamedDBElement
|
||||
{
|
||||
private const ORM_DISCRIMINATOR_MAP = ['Part' => PartAttachment::class, 'Device' => ProjectAttachment::class,
|
||||
private const ORM_DISCRIMINATOR_MAP = ['Part' => PartAttachment::class, 'Device' => ProjectAttachment::class, 'Assembly' => AssemblyAttachment::class,
|
||||
'AttachmentType' => AttachmentTypeAttachment::class,
|
||||
'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class,
|
||||
'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class,
|
||||
|
|
@ -107,7 +107,8 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
/*
|
||||
* The discriminator map used for API platform. The key should be the same as the api platform short type (the @type JSONLD field).
|
||||
*/
|
||||
private const API_DISCRIMINATOR_MAP = ["Part" => PartAttachment::class, "Project" => ProjectAttachment::class, "AttachmentType" => AttachmentTypeAttachment::class,
|
||||
private const API_DISCRIMINATOR_MAP = ["Part" => PartAttachment::class, "Project" => ProjectAttachment::class, "Assembly" => AssemblyAttachment::class,
|
||||
"AttachmentType" => AttachmentTypeAttachment::class,
|
||||
"Category" => CategoryAttachment::class, "Footprint" => FootprintAttachment::class, "Manufacturer" => ManufacturerAttachment::class,
|
||||
"Currency" => CurrencyAttachment::class, "Group" => GroupAttachment::class, "MeasurementUnit" => MeasurementUnitAttachment::class,
|
||||
"StorageLocation" => StorageLocationAttachment::class, "Supplier" => SupplierAttachment::class, "User" => UserAttachment::class, "LabelProfile" => LabelAttachment::class];
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Base;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\AssemblySystem\AssemblyBOMEntry;
|
||||
use App\Entity\Attachments\AssemblyAttachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentTypeAttachment;
|
||||
|
|
@ -68,7 +71,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
* Every database table which are managed with this class (or a subclass of it)
|
||||
* must have the table row "id"!! The ID is the unique key to identify the elements.
|
||||
*/
|
||||
#[DiscriminatorMap(typeProperty: 'type', mapping: ['attachment_type' => AttachmentType::class, 'attachment' => Attachment::class, 'attachment_type_attachment' => AttachmentTypeAttachment::class, 'category_attachment' => CategoryAttachment::class, 'currency_attachment' => CurrencyAttachment::class, 'footprint_attachment' => FootprintAttachment::class, 'group_attachment' => GroupAttachment::class, 'label_attachment' => LabelAttachment::class, 'manufacturer_attachment' => ManufacturerAttachment::class, 'measurement_unit_attachment' => MeasurementUnitAttachment::class, 'part_attachment' => PartAttachment::class, 'project_attachment' => ProjectAttachment::class, 'storelocation_attachment' => StorageLocationAttachment::class, 'supplier_attachment' => SupplierAttachment::class, 'user_attachment' => UserAttachment::class, 'category' => Category::class, 'project' => Project::class, 'project_bom_entry' => ProjectBOMEntry::class, 'footprint' => Footprint::class, 'group' => Group::class, 'manufacturer' => Manufacturer::class, 'orderdetail' => Orderdetail::class, 'part' => Part::class, 'pricedetail' => Pricedetail::class, 'storelocation' => StorageLocation::class, 'part_lot' => PartLot::class, 'currency' => Currency::class, 'measurement_unit' => MeasurementUnit::class, 'parameter' => AbstractParameter::class, 'supplier' => Supplier::class, 'user' => User::class])]
|
||||
#[DiscriminatorMap(typeProperty: 'type', mapping: ['attachment_type' => AttachmentType::class, 'attachment' => Attachment::class, 'attachment_type_attachment' => AttachmentTypeAttachment::class, 'category_attachment' => CategoryAttachment::class, 'currency_attachment' => CurrencyAttachment::class, 'footprint_attachment' => FootprintAttachment::class, 'group_attachment' => GroupAttachment::class, 'label_attachment' => LabelAttachment::class, 'manufacturer_attachment' => ManufacturerAttachment::class, 'measurement_unit_attachment' => MeasurementUnitAttachment::class, 'part_attachment' => PartAttachment::class, 'project_attachment' => ProjectAttachment::class, 'assembly_attachment' => AssemblyAttachment::class, 'storelocation_attachment' => StorageLocationAttachment::class, 'supplier_attachment' => SupplierAttachment::class, 'user_attachment' => UserAttachment::class, 'category' => Category::class, 'project' => Project::class, 'project_bom_entry' => ProjectBOMEntry::class, 'assembly' => Assembly::class, 'assembly_bom_entry' => AssemblyBOMEntry::class, 'footprint' => Footprint::class, 'group' => Group::class, 'manufacturer' => Manufacturer::class, 'orderdetail' => Orderdetail::class, 'part' => Part::class, 'pricedetail' => Pricedetail::class, 'storelocation' => StorageLocation::class, 'part_lot' => PartLot::class, 'currency' => Currency::class, 'measurement_unit' => MeasurementUnit::class, 'parameter' => AbstractParameter::class, 'supplier' => Supplier::class, 'user' => User::class])]
|
||||
#[ORM\MappedSuperclass(repositoryClass: DBElementRepository::class)]
|
||||
abstract class AbstractDBElement implements JsonSerializable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Attachments\AssemblyAttachment;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Attachments\AttachmentTypeAttachment;
|
||||
|
|
@ -58,6 +60,7 @@ use App\Entity\Attachments\UserAttachment;
|
|||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithEventUndoInterface;
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\Parameters\AssemblyParameter;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parameters\AttachmentTypeParameter;
|
||||
|
|
@ -147,6 +150,7 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
|
|||
{
|
||||
if (is_a($abstract_class, AbstractParameter::class, true)) {
|
||||
return match ($this->getTargetClass()) {
|
||||
Assembly::class => AssemblyParameter::class,
|
||||
AttachmentType::class => AttachmentTypeParameter::class,
|
||||
Category::class => CategoryParameter::class,
|
||||
Currency::class => CurrencyParameter::class,
|
||||
|
|
@ -168,6 +172,7 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
|
|||
Category::class => CategoryAttachment::class,
|
||||
Currency::class => CurrencyAttachment::class,
|
||||
Project::class => ProjectAttachment::class,
|
||||
Assembly::class => AssemblyAttachment::class,
|
||||
Footprint::class => FootprintAttachment::class,
|
||||
Group::class => GroupAttachment::class,
|
||||
Manufacturer::class => ManufacturerAttachment::class,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\AssemblySystem\AssemblyBOMEntry;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\InfoProviderSystem\BulkInfoProviderImportJob;
|
||||
|
|
@ -72,6 +74,9 @@ enum LogTargetType: int
|
|||
case BULK_INFO_PROVIDER_IMPORT_JOB = 21;
|
||||
case BULK_INFO_PROVIDER_IMPORT_JOB_PART = 22;
|
||||
|
||||
case ASSEMBLY = 23;
|
||||
case ASSEMBLY_BOM_ENTRY = 24;
|
||||
|
||||
/**
|
||||
* Returns the class name of the target type or null if the target type is NONE.
|
||||
* @return string|null
|
||||
|
|
@ -86,6 +91,8 @@ enum LogTargetType: int
|
|||
self::CATEGORY => Category::class,
|
||||
self::PROJECT => Project::class,
|
||||
self::BOM_ENTRY => ProjectBOMEntry::class,
|
||||
self::ASSEMBLY => Assembly::class,
|
||||
self::ASSEMBLY_BOM_ENTRY => AssemblyBOMEntry::class,
|
||||
self::FOOTPRINT => Footprint::class,
|
||||
self::GROUP => Group::class,
|
||||
self::MANUFACTURER => Manufacturer::class,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ use function sprintf;
|
|||
#[ORM\DiscriminatorMap([0 => CategoryParameter::class, 1 => CurrencyParameter::class, 2 => ProjectParameter::class,
|
||||
3 => FootprintParameter::class, 4 => GroupParameter::class, 5 => ManufacturerParameter::class,
|
||||
6 => MeasurementUnitParameter::class, 7 => PartParameter::class, 8 => StorageLocationParameter::class,
|
||||
9 => SupplierParameter::class, 10 => AttachmentTypeParameter::class])]
|
||||
9 => SupplierParameter::class, 10 => AttachmentTypeParameter::class, 11 => AssemblyParameter::class])]
|
||||
#[ORM\Table('parameters')]
|
||||
#[ORM\Index(columns: ['name'], name: 'parameter_name_idx')]
|
||||
#[ORM\Index(columns: ['param_group'], name: 'parameter_group_idx')]
|
||||
|
|
@ -103,7 +103,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
|||
*/
|
||||
private const API_DISCRIMINATOR_MAP = ["Part" => PartParameter::class,
|
||||
"AttachmentType" => AttachmentTypeParameter::class, "Category" => CategoryParameter::class, "Currency" => CurrencyParameter::class,
|
||||
"Project" => ProjectParameter::class, "Footprint" => FootprintParameter::class, "Group" => GroupParameter::class,
|
||||
"Project" => ProjectParameter::class, "Assembly" => AssemblyParameter::class, "Footprint" => FootprintParameter::class, "Group" => GroupParameter::class,
|
||||
"Manufacturer" => ManufacturerParameter::class, "MeasurementUnit" => MeasurementUnitParameter::class,
|
||||
"StorageLocation" => StorageLocationParameter::class, "Supplier" => SupplierParameter::class];
|
||||
|
||||
|
|
|
|||
65
src/Entity/Parameters/AssemblyParameter.php
Normal file
65
src/Entity/Parameters/AssemblyParameter.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Parameters;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Repository\ParameterRepository;
|
||||
use App\Serializer\APIPlatform\OverrideClassDenormalizer;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
|
||||
#[UniqueEntity(fields: ['name', 'group', 'element'])]
|
||||
#[ORM\Entity(repositoryClass: ParameterRepository::class)]
|
||||
class AssemblyParameter extends AbstractParameter
|
||||
{
|
||||
final public const ALLOWED_ELEMENT_CLASS = Assembly::class;
|
||||
|
||||
/**
|
||||
* @var Assembly the element this para is associated with
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: Assembly::class, inversedBy: 'parameters')]
|
||||
#[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')]
|
||||
#[Context(denormalizationContext: [OverrideClassDenormalizer::CONTEXT_KEY => self::ALLOWED_ELEMENT_CLASS])]
|
||||
protected ?AbstractDBElement $element = null;
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use App\Entity\Parts\PartTraits\AssemblyTrait;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
|
|
@ -125,6 +126,7 @@ class Part extends AttachmentContainingDBElement
|
|||
use OrderTrait;
|
||||
use ParametersTrait;
|
||||
use ProjectTrait;
|
||||
use AssemblyTrait;
|
||||
use AssociationTrait;
|
||||
use EDATrait;
|
||||
|
||||
|
|
@ -186,6 +188,7 @@ class Part extends AttachmentContainingDBElement
|
|||
$this->orderdetails = new ArrayCollection();
|
||||
$this->parameters = new ArrayCollection();
|
||||
$this->project_bom_entries = new ArrayCollection();
|
||||
$this->assembly_bom_entries = new ArrayCollection();
|
||||
|
||||
$this->associated_parts_as_owner = new ArrayCollection();
|
||||
$this->associated_parts_as_other = new ArrayCollection();
|
||||
|
|
|
|||
83
src/Entity/Parts/PartTraits/AssemblyTrait.php
Normal file
83
src/Entity/Parts/PartTraits/AssemblyTrait.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Parts\PartTraits;
|
||||
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\AssemblySystem\AssemblyBOMEntry;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
trait AssemblyTrait
|
||||
{
|
||||
/**
|
||||
* @var Collection<AssemblyBOMEntry> $assembly_bom_entries
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'part', targetEntity: AssemblyBOMEntry::class, cascade: ['remove'], orphanRemoval: true)]
|
||||
protected Collection $assembly_bom_entries;
|
||||
|
||||
/**
|
||||
* @var Assembly|null If a assembly is set here, then this part is special and represents the builds of an assembly.
|
||||
*/
|
||||
#[ORM\OneToOne(inversedBy: 'build_part', targetEntity: Assembly::class)]
|
||||
#[ORM\JoinColumn]
|
||||
protected ?Assembly $built_assembly = null;
|
||||
|
||||
/**
|
||||
* Returns all AssemblyBOMEntry that use this part.
|
||||
*
|
||||
* @phpstan-return Collection<int, AssemblyBOMEntry>
|
||||
*/
|
||||
public function getAssemblyBomEntries(): Collection
|
||||
{
|
||||
return $this->assembly_bom_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this part represents the builds of a assembly
|
||||
* @return bool True if it represents the builds, false if not
|
||||
*/
|
||||
#[Groups(['part:read'])]
|
||||
public function isAssemblyBuildPart(): bool
|
||||
{
|
||||
return $this->built_assembly !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assembly that this part represents the builds of, or null if it doesn't
|
||||
*/
|
||||
public function getBuiltAssembly(): ?Assembly
|
||||
{
|
||||
return $this->built_assembly;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the assembly that this part represents the builds of
|
||||
* @param Assembly|null $built_assembly The assembly that this part represents the builds of, or null if it is not a build part
|
||||
*/
|
||||
public function setBuiltAssembly(?Assembly $built_assembly): self
|
||||
{
|
||||
$this->built_assembly = $built_assembly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all assemblies which uses this part.
|
||||
*
|
||||
* @return Assembly[] all assemblies which uses this part as a one-dimensional array of Assembly objects
|
||||
*/
|
||||
public function getAssemblies(): array
|
||||
{
|
||||
$assemblies = [];
|
||||
|
||||
foreach($this->assembly_bom_entries as $entry) {
|
||||
$assemblies[] = $entry->getAssembly();
|
||||
}
|
||||
|
||||
return $assemblies;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +108,7 @@ class Project extends AbstractStructuralDBElement
|
|||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\OneToMany(mappedBy: 'project', targetEntity: ProjectBOMEntry::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[UniqueObjectCollection(message: 'project.bom_entry.part_already_in_bom', fields: ['part'])]
|
||||
#[UniqueObjectCollection(message: 'project.bom_entry.assembly_already_in_bom', fields: ['assembly'])]
|
||||
#[UniqueObjectCollection(message: 'project.bom_entry.name_already_in_bom', fields: ['name'])]
|
||||
protected Collection $bom_entries;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use ApiPlatform\Metadata\Post;
|
|||
use ApiPlatform\OpenApi\Model\Operation;
|
||||
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
||||
use App\ApiPlatform\Filter\LikeFilter;
|
||||
use App\Entity\AssemblySystem\Assembly;
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use App\Validator\UniqueValidatableInterface;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
|
@ -103,7 +104,10 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
/**
|
||||
* @var string|null An optional name describing this BOM entry (useful for non-part entries)
|
||||
*/
|
||||
#[Assert\Expression('this.getPart() !== null or this.getName() !== null', message: 'validator.project.bom_entry.name_or_part_needed')]
|
||||
#[Assert\Expression(
|
||||
'this.getPart() !== null or this.getAssembly() !== null or (this.getName() !== null and this.getName() != "")',
|
||||
message: 'validator.project.bom_entry.part_or_assembly_needed'
|
||||
)]
|
||||
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', 'import', 'simple', 'extended', 'full'])]
|
||||
protected ?string $name = null;
|
||||
|
|
@ -131,6 +135,18 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
#[Groups(['bom_entry:read', 'bom_entry:write', 'full'])]
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var Assembly|null The associated assembly
|
||||
*/
|
||||
#[Assert\Expression(
|
||||
'(this.getPart() === null or this.getAssembly() === null) and (this.getName() === null or (this.getName() != null and this.getName() != ""))',
|
||||
message: 'validator.project.bom_entry.only_part_or_assembly_allowed'
|
||||
)]
|
||||
#[ORM\ManyToOne(targetEntity: Assembly::class, inversedBy: 'assembly_bom_entries')]
|
||||
#[ORM\JoinColumn(name: 'id_assembly')]
|
||||
#[Groups(['bom_entry:read', 'bom_entry:write', ])]
|
||||
protected ?Assembly $assembly = null;
|
||||
|
||||
/**
|
||||
* @var BigDecimal|null The price of this non-part BOM entry
|
||||
*/
|
||||
|
|
@ -212,8 +228,6 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getPart(): ?Part
|
||||
{
|
||||
return $this->part;
|
||||
|
|
@ -225,6 +239,16 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getAssembly(): ?Assembly
|
||||
{
|
||||
return $this->assembly;
|
||||
}
|
||||
|
||||
public function setAssembly(?Assembly $assembly): void
|
||||
{
|
||||
$this->assembly = $assembly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price of this BOM entry, if existing.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
|
|
@ -262,6 +286,15 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
return $this->part instanceof Part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this BOM entry is a assembly associated BOM entry or not.
|
||||
* @return bool True if this BOM entry is a assembly associated BOM entry, false otherwise.
|
||||
*/
|
||||
public function isAssemblyBomEntry(): bool
|
||||
{
|
||||
return $this->assembly instanceof Assembly;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
|
|
@ -323,6 +356,7 @@ class ProjectBOMEntry extends AbstractDBElement implements UniqueValidatableInte
|
|||
return [
|
||||
'name' => $this->getName(),
|
||||
'part' => $this->getPart()?->getID(),
|
||||
'assembly' => $this->getAssembly()?->getID(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue