src/Entity/Common/Observation.php line 82
<?php
namespace App\Entity\Common;
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\Put;
use App\Doctrine\Type\Common\ObservationStatus;
use App\Doctrine\Type\Common\ObservationType;
use App\Dto\Common\IncidentResolutionInput;
use App\Entity\Delete\Batch;
use App\Entity\Delete\Withdrawal;
use App\Entity\Finance\BaseQuotation;
use App\Entity\Finance\Bill;
use App\Entity\Finance\Quotation;
use App\Entity\Identity\User;
use App\Entity\Sales\WorkOrder;
use App\Processor\Common\IncidentResolutionProcessor;
use App\Validator\IsValidEnumArray\IsValidEnumArray;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Table(name: 'observation')]
#[ORM\Index(columns: ['work_order_id'], name: 'observation_work_order_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'observation_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'observation_updated_by_idx')]
#[ORM\Entity]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Patch(inputFormats: ['json' => ['application/merge-patch+json']], input: IncidentResolutionInput::class, processor: IncidentResolutionProcessor::class),
new Put(),
new Delete(),
],
)]
#[ApiResource(
uriTemplate: '/work_orders/{slug}/observations',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'observations', fromClass: WorkOrder::class),
],
order: ['id' => 'DESC'],
)]
#[ApiResource(
uriTemplate: '/finance/quotations/{identifier}/observations',
operations: [new GetCollection()],
uriVariables: [
'identifier' => new Link(fromProperty: 'observations', fromClass: Quotation::class),
],
)]
#[ApiResource(
uriTemplate: '/finance/bills/{identifier}/observations',
operations: [new GetCollection()],
uriVariables: [
'identifier' => new Link(fromProperty: 'observations', fromClass: Bill::class),
],
)]
#[ApiResource(
uriTemplate: '/xpediting/batches/{slug}/observations',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'observations', fromClass: Batch::class),
],
)]
#[ApiResource(
uriTemplate: '/nventory/withdrawals/{slug}/observations',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'observations', fromClass: Withdrawal::class),
],
)]
class Observation
{
use Blameable;
use Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'observation_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: WorkOrder::class, inversedBy: 'observations')]
#[ORM\JoinColumn(name: 'work_order_id')]
private ?WorkOrder $workOrder = null;
#[ORM\ManyToOne(targetEntity: Batch::class, inversedBy: 'observations')]
#[ORM\JoinColumn(name: 'batch_id')]
private ?Batch $batch = null;
#[ORM\ManyToOne(targetEntity: BaseQuotation::class, inversedBy: 'observations')]
#[ORM\JoinColumn(name: 'bill_id')]
private ?BaseQuotation $quotation = null;
#[ORM\ManyToOne(targetEntity: Withdrawal::class, inversedBy: 'observations')]
#[ORM\JoinColumn(name: 'withdrawal_id')]
private ?Withdrawal $withdrawal = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: false)]
private ?string $comment = null;
#[Assert\NotNull]
#[IsValidEnumArray(enum: ObservationType::class)]
#[ORM\Column(type: Types::STRING, nullable: false, enumType: ObservationType::class)]
private ?ObservationType $type = null;
#[Assert\NotNull]
#[IsValidEnumArray(enum: ObservationStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: ObservationStatus::class)]
private ?ObservationStatus $status = null;
#[Assert\Type(type: Types::DATE_MUTABLE)]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?DateTimeInterface $resolvedOn = null;
#[Gedmo\Blameable(on: 'create')]
#[ApiProperty(readableLink: true)]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: false)]
protected ?User $createdBy = null;
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (empty($this->workOrder) && empty($this->quotation)) {
$context->buildViolation('Observation must be attached to either, an work order, or a quotation/bill')
->atPath('workOrder')
->addViolation();
$context->buildViolation('Observation must be attached to either, an work order, or a quotation/bill')
->atPath('quotation')
->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getWorkOrder(): ?WorkOrder
{
return $this->workOrder;
}
public function setWorkOrder(?WorkOrder $workOrder): self
{
$this->workOrder = $workOrder;
return $this;
}
public function getBatch(): ?Batch
{
return $this->batch;
}
public function setBatch(?Batch $batch): self
{
$this->batch = $batch;
return $this;
}
public function getQuotation(): ?BaseQuotation
{
return $this->quotation;
}
public function setQuotation(?BaseQuotation $quotation): self
{
$this->quotation = $quotation;
return $this;
}
public function getWithdrawal(): ?Withdrawal
{
return $this->withdrawal;
}
public function setWithdrawal(?Withdrawal $withdrawal): self
{
$this->withdrawal = $withdrawal;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getType(): ?ObservationType
{
return $this->type;
}
public function setType(ObservationType $type): static
{
$this->type = $type;
return $this;
}
public function getStatus(): ?ObservationStatus
{
return $this->status;
}
public function setStatus(ObservationStatus $status): self
{
$this->status = $status;
return $this;
}
public function getResolvedOn(): ?DateTimeInterface
{
return $this->resolvedOn;
}
public function setResolvedOn(?DateTimeInterface $resolvedOn): self
{
$this->resolvedOn = $resolvedOn;
return $this;
}
}