2019-08-12 15:47:57 +02:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
namespace App\Entity\Parts;
|
|
|
|
|
2024-03-03 19:57:31 +01:00
|
|
|
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
2023-10-03 16:29:04 +02:00
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
|
2023-09-03 23:58:09 +02:00
|
|
|
use ApiPlatform\Metadata\ApiFilter;
|
2023-11-25 01:17:35 +01:00
|
|
|
use ApiPlatform\Metadata\ApiProperty;
|
2023-09-03 23:58:09 +02:00
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
|
|
use ApiPlatform\Metadata\Delete;
|
|
|
|
use ApiPlatform\Metadata\Get;
|
|
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
|
|
use ApiPlatform\Metadata\Patch;
|
|
|
|
use ApiPlatform\Metadata\Post;
|
|
|
|
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
2023-10-03 16:29:04 +02:00
|
|
|
use App\ApiPlatform\Filter\LikeFilter;
|
2024-03-09 00:11:00 +01:00
|
|
|
use App\Validator\Constraints\Year2038BugWorkaround;
|
2023-06-11 14:55:06 +02:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
2020-02-01 19:48:07 +01:00
|
|
|
use App\Entity\Base\AbstractDBElement;
|
2019-08-12 18:04:53 +02:00
|
|
|
use App\Entity\Base\TimestampTrait;
|
2020-03-28 18:55:02 +01:00
|
|
|
use App\Entity\Contracts\NamedElementInterface;
|
2020-02-16 23:48:57 +01:00
|
|
|
use App\Entity\Contracts\TimeStampableInterface;
|
2023-04-02 19:10:36 +02:00
|
|
|
use App\Entity\UserSystem\User;
|
2019-08-12 21:47:25 +02:00
|
|
|
use App\Validator\Constraints\Selectable;
|
2019-09-04 23:20:10 +02:00
|
|
|
use App\Validator\Constraints\ValidPartLot;
|
2020-01-05 22:49:00 +01:00
|
|
|
use DateTime;
|
2019-08-12 15:47:57 +02:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2020-01-05 22:49:00 +01:00
|
|
|
use Exception;
|
2023-11-17 23:05:47 +01:00
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
2023-03-12 01:12:35 +01:00
|
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
2019-08-12 15:47:57 +02:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2024-03-06 19:46:11 +01:00
|
|
|
use Symfony\Component\Validator\Constraints\Length;
|
2023-04-02 23:58:15 +02:00
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This entity describes a lot where parts can be stored.
|
|
|
|
* It is the connection between a part and its store locations.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2023-06-11 15:02:59 +02:00
|
|
|
* @see \App\Tests\Entity\Parts\PartLotTest
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-05-28 01:51:13 +02:00
|
|
|
#[ORM\Entity]
|
|
|
|
#[ORM\HasLifecycleCallbacks]
|
|
|
|
#[ORM\Table(name: 'part_lots')]
|
2023-11-12 22:06:05 +01:00
|
|
|
#[ORM\Index(columns: ['instock_unknown', 'expiration_date', 'id_part'], name: 'part_lots_idx_instock_un_expiration_id_part')]
|
|
|
|
#[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')]
|
|
|
|
#[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')]
|
2023-06-11 19:32:15 +02:00
|
|
|
#[ValidPartLot]
|
2023-11-17 23:05:47 +01:00
|
|
|
#[UniqueEntity(['vendor_barcode'], message: 'validator.part_lot.vendor_barcode_must_be_unique')]
|
2023-09-03 23:58:09 +02:00
|
|
|
#[ApiResource(
|
|
|
|
operations: [
|
|
|
|
new Get(security: 'is_granted("read", object)'),
|
|
|
|
new GetCollection(security: 'is_granted("@parts.read")'),
|
|
|
|
new Post(securityPostDenormalize: 'is_granted("create", object)'),
|
|
|
|
new Patch(security: 'is_granted("edit", object)'),
|
|
|
|
new Delete(security: 'is_granted("delete", object)'),
|
|
|
|
],
|
2023-09-18 21:31:55 +02:00
|
|
|
normalizationContext: ['groups' => ['part_lot:read', 'part_lot:read:standalone', 'api:basic:read', 'pricedetail:read'], 'openapi_definition_name' => 'Read'],
|
2023-09-03 23:58:09 +02:00
|
|
|
denormalizationContext: ['groups' => ['part_lot:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
|
|
|
|
)]
|
|
|
|
#[ApiFilter(PropertyFilter::class)]
|
2023-10-03 16:29:04 +02:00
|
|
|
#[ApiFilter(LikeFilter::class, properties: ["description", "comment"])]
|
2024-03-03 19:57:31 +01:00
|
|
|
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
|
2023-10-03 16:29:04 +02:00
|
|
|
#[ApiFilter(BooleanFilter::class, properties: ['instock_unknown', 'needs_refill'])]
|
|
|
|
#[ApiFilter(RangeFilter::class, properties: ['amount'])]
|
|
|
|
#[ApiFilter(OrderFilter::class, properties: ['description', 'comment', 'addedDate', 'lastModified'])]
|
2020-03-28 18:55:02 +01:00
|
|
|
class PartLot extends AbstractDBElement implements TimeStampableInterface, NamedElementInterface
|
2019-08-12 15:47:57 +02:00
|
|
|
{
|
2019-08-12 18:04:53 +02:00
|
|
|
use TimestampTrait;
|
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
/**
|
|
|
|
* @var string A short description about this lot, shown in table
|
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['simple', 'extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::TEXT)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected string $description = '';
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
2020-08-21 21:36:22 +02:00
|
|
|
* @var string a comment stored with this lot
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::TEXT)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected string $comment = '';
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
2023-05-28 01:51:13 +02:00
|
|
|
* @var \DateTimeInterface|null Set a time until when the lot must be used.
|
2020-01-05 22:49:00 +01:00
|
|
|
* Set to null, if the lot can be used indefinitely.
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2024-03-03 19:57:31 +01:00
|
|
|
#[ORM\Column(name: 'expiration_date', type: Types::DATETIME_MUTABLE, nullable: true)]
|
2024-03-09 00:11:00 +01:00
|
|
|
#[Year2038BugWorkaround]
|
2023-05-28 01:51:13 +02:00
|
|
|
protected ?\DateTimeInterface $expiration_date = null;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
2023-09-04 22:57:40 +02:00
|
|
|
* @var StorageLocation|null The storelocation of this lot
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['simple', 'extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-09-04 22:57:40 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: StorageLocation::class, fetch: 'EAGER')]
|
2023-05-28 01:51:13 +02:00
|
|
|
#[ORM\JoinColumn(name: 'id_store_location')]
|
2024-03-03 19:57:31 +01:00
|
|
|
#[Selectable]
|
2023-09-04 22:57:40 +02:00
|
|
|
protected ?StorageLocation $storage_location = null;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool If this is set to true, the instock amount is marked as not known
|
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['simple', 'extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::BOOLEAN)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected bool $instock_unknown = false;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
2023-09-17 12:50:32 +02:00
|
|
|
* @var float The amount of parts in this lot. For integer-quantities this value is rounded to the next integer.
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Assert\PositiveOrZero]
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['simple', 'extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::FLOAT)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected float $amount = 0.0;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
|
|
|
/**
|
2020-08-21 21:36:22 +02:00
|
|
|
* @var bool determines if this lot was manually marked for refilling
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::BOOLEAN)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected bool $needs_refill = false;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
2020-01-05 22:49:00 +01:00
|
|
|
/**
|
2023-06-18 00:00:58 +02:00
|
|
|
* @var Part|null The part that is stored in this lot
|
2020-01-05 22:49:00 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Assert\NotNull]
|
2023-06-13 20:24:54 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'partLots')]
|
2023-05-28 01:51:13 +02:00
|
|
|
#[ORM\JoinColumn(name: 'id_part', nullable: false, onDelete: 'CASCADE')]
|
2023-09-18 21:31:55 +02:00
|
|
|
#[Groups(['part_lot:read:standalone', 'part_lot:write'])]
|
2023-11-25 01:17:35 +01:00
|
|
|
#[ApiProperty(writableLink: false)]
|
2023-06-18 00:00:58 +02:00
|
|
|
protected ?Part $part = null;
|
2020-01-05 22:49:00 +01:00
|
|
|
|
2023-04-02 19:10:36 +02:00
|
|
|
/**
|
|
|
|
* @var User|null The owner of this part lot
|
|
|
|
*/
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
2023-05-28 01:51:13 +02:00
|
|
|
#[ORM\JoinColumn(name: 'id_owner', onDelete: 'SET NULL')]
|
2023-09-03 23:58:09 +02:00
|
|
|
#[Groups(['part_lot:read', 'part_lot:write'])]
|
2023-11-25 01:17:35 +01:00
|
|
|
#[ApiProperty(writableLink: false)]
|
2023-04-03 22:23:53 +02:00
|
|
|
protected ?User $owner = null;
|
2023-04-02 19:10:36 +02:00
|
|
|
|
2023-11-12 22:06:05 +01:00
|
|
|
/**
|
|
|
|
* @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor)
|
|
|
|
*/
|
|
|
|
#[ORM\Column(type: Types::STRING, nullable: true)]
|
2023-11-17 23:05:47 +01:00
|
|
|
#[Groups(['part_lot:read', 'part_lot:write'])]
|
2024-03-06 19:46:11 +01:00
|
|
|
#[Length(max: 255)]
|
2023-11-12 22:06:05 +01:00
|
|
|
protected ?string $vendor_barcode = null;
|
|
|
|
|
2020-03-15 13:56:31 +01:00
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
if ($this->id) {
|
|
|
|
$this->addedDate = null;
|
|
|
|
}
|
|
|
|
parent::__clone();
|
|
|
|
}
|
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
/**
|
|
|
|
* Check if the current part lot is expired.
|
2023-04-15 23:14:53 +02:00
|
|
|
* This is the case, if the expiration date is greater the current date.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-08-16 22:54:23 +02:00
|
|
|
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2020-01-05 22:49:00 +01:00
|
|
|
* @throws Exception If an error with the DateTime occurs
|
2019-08-16 22:54:23 +02:00
|
|
|
*/
|
|
|
|
public function isExpired(): ?bool
|
|
|
|
{
|
2023-06-11 14:15:46 +02:00
|
|
|
if (!$this->expiration_date instanceof \DateTimeInterface) {
|
2019-08-16 22:54:23 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if the expiration date is bigger then current time
|
2020-01-05 22:49:00 +01:00
|
|
|
return $this->expiration_date < new DateTime('now');
|
2019-08-16 22:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the description of the part lot. Similar to a "name" of the part lot.
|
|
|
|
*/
|
|
|
|
public function getDescription(): string
|
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the description of the part lot.
|
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setDescription(string $description): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->description = $description;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the comment for this part lot.
|
|
|
|
*/
|
|
|
|
public function getComment(): string
|
|
|
|
{
|
|
|
|
return $this->comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the comment for this part lot.
|
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setComment(string $comment): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->comment = $comment;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
|
|
|
|
*/
|
2023-05-28 01:51:13 +02:00
|
|
|
public function getExpirationDate(): ?\DateTimeInterface
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
return $this->expiration_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-15 23:14:53 +02:00
|
|
|
* Sets the expiration date for the part lot. Set to null, if the part lot does not expire.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
|
|
|
*
|
2019-08-16 22:54:23 +02:00
|
|
|
*/
|
2023-05-28 01:51:13 +02:00
|
|
|
public function setExpirationDate(?\DateTimeInterface $expiration_date): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->expiration_date = $expiration_date;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-10 14:00:56 +01:00
|
|
|
* Gets the storage location, where this part lot is stored.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2023-09-04 22:57:40 +02:00
|
|
|
* @return StorageLocation|null The store location where this part is stored
|
2019-08-16 22:54:23 +02:00
|
|
|
*/
|
2023-09-04 22:57:40 +02:00
|
|
|
public function getStorageLocation(): ?StorageLocation
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
return $this->storage_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Sets the storage location, where this part lot is stored.
|
2019-08-16 22:54:23 +02:00
|
|
|
*/
|
2023-09-04 22:57:40 +02:00
|
|
|
public function setStorageLocation(?StorageLocation $storage_location): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->storage_location = $storage_location;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the part that is stored in this part lot.
|
|
|
|
*/
|
2023-06-18 00:00:58 +02:00
|
|
|
public function getPart(): ?Part
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
return $this->part;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the part that is stored in this part lot.
|
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setPart(Part $part): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->part = $part;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the instock value in the part lot is unknown.
|
|
|
|
*/
|
|
|
|
public function isInstockUnknown(): bool
|
|
|
|
{
|
|
|
|
return $this->instock_unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the unknown instock status of this part lot.
|
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setInstockUnknown(bool $instock_unknown): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->instock_unknown = $instock_unknown;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAmount(): float
|
|
|
|
{
|
2020-08-21 21:36:22 +02:00
|
|
|
if ($this->part instanceof Part && !$this->part->useFloatAmount()) {
|
2019-08-16 22:54:23 +02:00
|
|
|
return round($this->amount);
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2022-12-18 19:45:04 +01:00
|
|
|
return $this->amount;
|
2019-08-16 22:54:23 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 15:13:23 +02:00
|
|
|
/**
|
|
|
|
* Sets the amount of parts in the part lot.
|
|
|
|
* If null is passed, amount will be set to unknown.
|
2020-04-10 13:05:08 +02:00
|
|
|
*
|
2020-03-30 15:13:23 +02:00
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setAmount(?float $new_amount): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
2020-03-30 15:13:23 +02:00
|
|
|
//Treat null like unknown amount
|
2020-04-10 13:05:08 +02:00
|
|
|
if (null === $new_amount) {
|
2020-03-30 15:13:23 +02:00
|
|
|
$this->instock_unknown = true;
|
|
|
|
$new_amount = 0.0;
|
|
|
|
}
|
|
|
|
|
2019-11-09 00:47:20 +01:00
|
|
|
$this->amount = $new_amount;
|
|
|
|
|
2019-08-19 23:31:16 +02:00
|
|
|
return $this;
|
2019-08-16 22:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isNeedsRefill(): bool
|
|
|
|
{
|
|
|
|
return $this->needs_refill;
|
|
|
|
}
|
|
|
|
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setNeedsRefill(bool $needs_refill): self
|
2019-08-16 22:54:23 +02:00
|
|
|
{
|
|
|
|
$this->needs_refill = $needs_refill;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-16 22:54:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2020-03-28 18:55:02 +01:00
|
|
|
|
2023-04-02 19:10:36 +02:00
|
|
|
/**
|
|
|
|
* Returns the owner of this part lot.
|
|
|
|
*/
|
|
|
|
public function getOwner(): ?User
|
|
|
|
{
|
|
|
|
return $this->owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the owner of this part lot.
|
|
|
|
*/
|
|
|
|
public function setOwner(?User $owner): PartLot
|
|
|
|
{
|
|
|
|
$this->owner = $owner;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-28 18:55:02 +01:00
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
2023-04-02 23:58:15 +02:00
|
|
|
|
2023-11-17 23:05:47 +01:00
|
|
|
/**
|
|
|
|
* The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor), or
|
|
|
|
* null if no barcode is set.
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getVendorBarcode(): ?string
|
|
|
|
{
|
|
|
|
return $this->vendor_barcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the content of the barcode of this part lot (e.g. a barcode on the package put by the vendor).
|
|
|
|
* @param string|null $vendor_barcode
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setVendorBarcode(?string $vendor_barcode): PartLot
|
|
|
|
{
|
|
|
|
$this->vendor_barcode = $vendor_barcode;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Assert\Callback]
|
2023-06-18 15:37:42 +02:00
|
|
|
public function validate(ExecutionContextInterface $context, $payload): void
|
2023-04-02 23:58:15 +02:00
|
|
|
{
|
2023-04-08 00:50:42 +02:00
|
|
|
//Ensure that the owner is not the anonymous user
|
|
|
|
if ($this->getOwner() && $this->getOwner()->isAnonymousUser()) {
|
|
|
|
$context->buildViolation('validator.part_lot.owner_must_not_be_anonymous')
|
|
|
|
->atPath('owner')
|
|
|
|
->addViolation();
|
|
|
|
}
|
|
|
|
|
2023-04-02 23:58:15 +02:00
|
|
|
//When the storage location sets the owner must match, the part lot owner must match the storage location owner
|
|
|
|
if ($this->getStorageLocation() && $this->getStorageLocation()->isPartOwnerMustMatch()
|
2023-06-11 14:15:46 +02:00
|
|
|
&& $this->getStorageLocation()->getOwner() && $this->getOwner() && ($this->getOwner() !== $this->getStorageLocation()->getOwner()
|
2023-06-11 19:32:15 +02:00
|
|
|
&& $this->owner->getID() !== $this->getStorageLocation()->getOwner()->getID())) {
|
2023-06-11 14:15:46 +02:00
|
|
|
$context->buildViolation('validator.part_lot.owner_must_match_storage_location_owner')
|
|
|
|
->setParameter('%owner_name%', $this->getStorageLocation()->getOwner()->getFullName(true))
|
|
|
|
->atPath('owner')
|
|
|
|
->addViolation();
|
2023-04-02 23:58:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
}
|