src/Entity/Shipment.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Kimia;
  4. use App\Repository\ShipmentRepository;
  5. use App\Trait\CurrentStateTrait;
  6. use DateTimeImmutable;
  7. use DateTimeInterface;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClass: ShipmentRepository::class)]
  12. class Shipment
  13. {
  14.     use CurrentStateTrait;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     #[Groups(['order:list'])]
  19.     private ?int $id = null;
  20.     #[ORM\Column(length: 255)]
  21.     #[Groups(['order:list'])]
  22.     private ?string $trackingNumber = null;
  23.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  24.     #[Groups(['order:list'])]
  25.     private ?DateTimeInterface $createdAt = null;
  26.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  27.     #[Groups(['order:list'])]
  28.     private ?DateTimeInterface $shippedAt = null;
  29.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  30.     #[Groups(['order:list'])]
  31.     private ?DateTimeInterface $deliveredAt = null;
  32.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  33.     #[Groups(['order:list'])]
  34.     private ?DateTimeInterface $cancelledAt = null;
  35.     #[ORM\ManyToOne(cascade: ["persist", "remove"])]
  36.     #[ORM\JoinColumn(nullable: false)]
  37.     #[Groups(['order:list'])]
  38.     private ?Address $destination = null;
  39.     #[ORM\Column(nullable: true)]
  40.     private ?float $amount = null;
  41.     #[ORM\ManyToOne]
  42.     #[ORM\JoinColumn(nullable: true)]
  43.     private ?Currency $currency = null;
  44.     #[ORM\ManyToOne(inversedBy: 'shipment')]
  45.     #[ORM\JoinColumn(nullable: false)]
  46.     private ?Order $command = null;
  47.     #[ORM\ManyToOne]
  48.     #[ORM\JoinColumn(nullable: false)]
  49.     private ?User $author = null;
  50.     public function __construct()
  51.     {
  52.         $this->currentState = "notShipped";
  53.         if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();
  54.         if (is_null($this->trackingNumber)) $this->trackingNumber = strtoupper(uniqid('TN-', false));
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getTrackingNumber(): ?string
  61.     {
  62.         return $this->trackingNumber;
  63.     }
  64.     public function setTrackingNumber(string $trackingNumber): self
  65.     {
  66.         $this->trackingNumber = $trackingNumber;
  67.         return $this;
  68.     }
  69.     public static function getCurrentStateListForView(): array
  70.     {
  71.         return [
  72.             Kimia::STATUS_INIT => "<span class='badge badge-soft-info'>Initié</span>",
  73.             Kimia::STATUS_SUCCESS => "<span class='badge badge-soft-success'>Succès</span>",
  74.             Kimia::STATUS_PROCESS => "<span class='badge badge-soft-warning'>En cours</span>",
  75.             Kimia::STATUS_ERROR => "<span class='badge badge-soft-danger'>Erreur</span>",
  76.             Kimia::STATUS_CANCEL => "<span class='badge badge-soft-secondary'>Annulé</span>",
  77.         ];
  78.     }
  79.     public function getCreatedAt(): ?DateTimeInterface
  80.     {
  81.         return $this->createdAt;
  82.     }
  83.     public function setCreatedAt(DateTimeInterface $createdAt): self
  84.     {
  85.         $this->createdAt = $createdAt;
  86.         return $this;
  87.     }
  88.     public function getShippedAt(): ?DateTimeInterface
  89.     {
  90.         return $this->shippedAt;
  91.     }
  92.     public function setShippedAt(?DateTimeInterface $shippedAt): self
  93.     {
  94.         $this->shippedAt = $shippedAt;
  95.         return $this;
  96.     }
  97.     public function getDeliveredAt(): ?DateTimeInterface
  98.     {
  99.         return $this->deliveredAt;
  100.     }
  101.     public function setDeliveredAt(?DateTimeInterface $deliveredAt): self
  102.     {
  103.         $this->deliveredAt = $deliveredAt;
  104.         return $this;
  105.     }
  106.     public function getCancelledAt(): ?DateTimeInterface
  107.     {
  108.         return $this->cancelledAt;
  109.     }
  110.     public function setCancelledAt(?DateTimeInterface $cancelledAt): self
  111.     {
  112.         $this->cancelledAt = $cancelledAt;
  113.         return $this;
  114.     }
  115.     public function getDestination(): ?Address
  116.     {
  117.         return $this->destination;
  118.     }
  119.     public function setDestination(?Address $destination): self
  120.     {
  121.         $this->destination = $destination;
  122.         return $this;
  123.     }
  124.     public function getAmount(): ?float
  125.     {
  126.         return $this->amount;
  127.     }
  128.     public function setAmount(?float $amount): self
  129.     {
  130.         $this->amount = $amount;
  131.         return $this;
  132.     }
  133.     public function getCurrency(): ?Currency
  134.     {
  135.         return $this->currency;
  136.     }
  137.     public function setCurrency(?Currency $currency): self
  138.     {
  139.         $this->currency = $currency;
  140.         return $this;
  141.     }
  142.     public function getCommand(): ?Order
  143.     {
  144.         return $this->command;
  145.     }
  146.     public function setCommand(?Order $command): self
  147.     {
  148.         $this->command = $command;
  149.         return $this;
  150.     }
  151.     public function getAuthor(): ?User
  152.     {
  153.         return $this->author;
  154.     }
  155.     public function setAuthor(?User $author): self
  156.     {
  157.         $this->author = $author;
  158.         return $this;
  159.     }
  160.     public function __toString(): string
  161.     {
  162.         return $this->trackingNumber;
  163.     }
  164. }