src/Entity/Common/Observation.php line 82

  1. <?php
  2. namespace App\Entity\Common;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Link;
  9. use ApiPlatform\Metadata\Patch;
  10. use ApiPlatform\Metadata\Put;
  11. use App\Doctrine\Type\Common\ObservationStatus;
  12. use App\Doctrine\Type\Common\ObservationType;
  13. use App\Dto\Common\IncidentResolutionInput;
  14. use App\Entity\Delete\Batch;
  15. use App\Entity\Delete\Withdrawal;
  16. use App\Entity\Finance\BaseQuotation;
  17. use App\Entity\Finance\Bill;
  18. use App\Entity\Finance\Quotation;
  19. use App\Entity\Identity\User;
  20. use App\Entity\Sales\WorkOrder;
  21. use App\Processor\Common\IncidentResolutionProcessor;
  22. use App\Validator\IsValidEnumArray\IsValidEnumArray;
  23. use DateTimeInterface;
  24. use Doctrine\DBAL\Types\Types;
  25. use Doctrine\ORM\Mapping as ORM;
  26. use Gedmo\Mapping\Annotation as Gedmo;
  27. use Symfony\Component\Validator\Constraints as Assert;
  28. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  29. #[ORM\Table(name'observation')]
  30. #[ORM\Index(columns: ['work_order_id'], name'observation_work_order_id_idx')]
  31. #[ORM\Index(columns: ['created_by'], name'observation_created_by_idx')]
  32. #[ORM\Index(columns: ['updated_by'], name'observation_updated_by_idx')]
  33. #[ORM\Entity]
  34. #[ApiResource(
  35.     operations: [
  36.         new Get(),
  37.         new GetCollection(),
  38.         new Patch(inputFormats: ['json' => ['application/merge-patch+json']], inputIncidentResolutionInput::class, processorIncidentResolutionProcessor::class),
  39.         new Put(),
  40.         new Delete(),
  41.     ],
  42. )]
  43. #[ApiResource(
  44.     uriTemplate'/work_orders/{slug}/observations',
  45.     operations: [new GetCollection()],
  46.     uriVariables: [
  47.         'slug' => new Link(fromProperty'observations'fromClassWorkOrder::class),
  48.     ],
  49.     order: ['id' => 'DESC'],
  50. )]
  51. #[ApiResource(
  52.     uriTemplate'/finance/quotations/{identifier}/observations',
  53.     operations: [new GetCollection()],
  54.     uriVariables: [
  55.         'identifier' => new Link(fromProperty'observations'fromClassQuotation::class),
  56.     ],
  57. )]
  58. #[ApiResource(
  59.     uriTemplate'/finance/bills/{identifier}/observations',
  60.     operations: [new GetCollection()],
  61.     uriVariables: [
  62.         'identifier' => new Link(fromProperty'observations'fromClassBill::class),
  63.     ],
  64. )]
  65. #[ApiResource(
  66.     uriTemplate'/xpediting/batches/{slug}/observations',
  67.     operations: [new GetCollection()],
  68.     uriVariables: [
  69.         'slug' => new Link(fromProperty'observations'fromClassBatch::class),
  70.     ],
  71. )]
  72. #[ApiResource(
  73.     uriTemplate'/nventory/withdrawals/{slug}/observations',
  74.     operations: [new GetCollection()],
  75.     uriVariables: [
  76.         'slug' => new Link(fromProperty'observations'fromClassWithdrawal::class),
  77.     ],
  78. )]
  79. class Observation
  80. {
  81.     use Blameable;
  82.     use Trackable;
  83.     #[ORM\Id]
  84.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  85.     #[ORM\SequenceGenerator(sequenceName'observation_id_seq')]
  86.     #[ORM\Column(typeTypes::INTEGER)]
  87.     private ?int $id null;
  88.     #[ORM\ManyToOne(targetEntityWorkOrder::class, inversedBy'observations')]
  89.     #[ORM\JoinColumn(name'work_order_id')]
  90.     private ?WorkOrder $workOrder null;
  91.     #[ORM\ManyToOne(targetEntityBatch::class, inversedBy'observations')]
  92.     #[ORM\JoinColumn(name'batch_id')]
  93.     private ?Batch $batch null;
  94.     #[ORM\ManyToOne(targetEntityBaseQuotation::class, inversedBy'observations')]
  95.     #[ORM\JoinColumn(name'bill_id')]
  96.     private ?BaseQuotation $quotation null;
  97.     #[ORM\ManyToOne(targetEntityWithdrawal::class, inversedBy'observations')]
  98.     #[ORM\JoinColumn(name'withdrawal_id')]
  99.     private ?Withdrawal $withdrawal null;
  100.     #[Assert\NotBlank]
  101.     #[Assert\Type(typeTypes::STRING)]
  102.     #[ORM\Column(typeTypes::STRINGnullablefalse)]
  103.     private ?string $comment null;
  104.     #[Assert\NotNull]
  105.     #[IsValidEnumArray(enumObservationType::class)]
  106.     #[ORM\Column(typeTypes::STRINGnullablefalseenumTypeObservationType::class)]
  107.     private ?ObservationType $type null;
  108.     #[Assert\NotNull]
  109.     #[IsValidEnumArray(enumObservationStatus::class)]
  110.     #[ORM\Column(typeTypes::STRINGenumTypeObservationStatus::class)]
  111.     private ?ObservationStatus $status null;
  112.     #[Assert\Type(typeTypes::DATE_MUTABLE)]
  113.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  114.     private ?DateTimeInterface $resolvedOn null;
  115.     #[Gedmo\Blameable(on'create')]
  116.     #[ApiProperty(readableLinktrue)]
  117.     #[ORM\ManyToOne(targetEntityUser::class)]
  118.     #[ORM\JoinColumn(name'created_by'nullablefalse)]
  119.     protected ?User $createdBy null;
  120.     #[Assert\Callback]
  121.     public function validate(ExecutionContextInterface $context$payload): void
  122.     {
  123.         if (empty($this->workOrder) && empty($this->quotation)) {
  124.             $context->buildViolation('Observation must be attached to either, an work order, or a quotation/bill')
  125.                 ->atPath('workOrder')
  126.                 ->addViolation();
  127.             $context->buildViolation('Observation must be attached to either, an work order, or a quotation/bill')
  128.                 ->atPath('quotation')
  129.                 ->addViolation();
  130.         }
  131.     }
  132.     public function getId(): ?int
  133.     {
  134.         return $this->id;
  135.     }
  136.     public function getWorkOrder(): ?WorkOrder
  137.     {
  138.         return $this->workOrder;
  139.     }
  140.     public function setWorkOrder(?WorkOrder $workOrder): self
  141.     {
  142.         $this->workOrder $workOrder;
  143.         return $this;
  144.     }
  145.     public function getBatch(): ?Batch
  146.     {
  147.         return $this->batch;
  148.     }
  149.     public function setBatch(?Batch $batch): self
  150.     {
  151.         $this->batch $batch;
  152.         return $this;
  153.     }
  154.     public function getQuotation(): ?BaseQuotation
  155.     {
  156.         return $this->quotation;
  157.     }
  158.     public function setQuotation(?BaseQuotation $quotation): self
  159.     {
  160.         $this->quotation $quotation;
  161.         return $this;
  162.     }
  163.     public function getWithdrawal(): ?Withdrawal
  164.     {
  165.         return $this->withdrawal;
  166.     }
  167.     public function setWithdrawal(?Withdrawal $withdrawal): self
  168.     {
  169.         $this->withdrawal $withdrawal;
  170.         return $this;
  171.     }
  172.     public function getComment(): ?string
  173.     {
  174.         return $this->comment;
  175.     }
  176.     public function setComment(?string $comment): self
  177.     {
  178.         $this->comment $comment;
  179.         return $this;
  180.     }
  181.     public function getType(): ?ObservationType
  182.     {
  183.         return $this->type;
  184.     }
  185.     public function setType(ObservationType $type): static
  186.     {
  187.         $this->type $type;
  188.         return $this;
  189.     }
  190.     public function getStatus(): ?ObservationStatus
  191.     {
  192.         return $this->status;
  193.     }
  194.     public function setStatus(ObservationStatus $status): self
  195.     {
  196.         $this->status $status;
  197.         return $this;
  198.     }
  199.     public function getResolvedOn(): ?DateTimeInterface
  200.     {
  201.         return $this->resolvedOn;
  202.     }
  203.     public function setResolvedOn(?DateTimeInterface $resolvedOn): self
  204.     {
  205.         $this->resolvedOn $resolvedOn;
  206.         return $this;
  207.     }
  208. }