src/Entity/Order.php line 75
<?phpnamespace App\Entity;use ApiPlatform\Metadata\Link;use App\Controller\Api\Order\ApiEstablishmentOrderInvoiceController;use App\Controller\Api\Order\ApiOrderShipmentTimerController;use App\Dto\CreateOrderInput;use App\Kimia;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\GetCollection;use ApiPlatform\Metadata\Post;use App\Controller\Api\Order\ApiEstablishmentOrderNewController;use App\Controller\Api\Order\ApiOrderShipmentOverController;use App\Controller\Api\Order\ApiOrderShipmentStartController;use App\Repository\OrderRepository;use App\State\Order\OrderCreateProcessor;use App\Trait\ArrayableTrait;use App\Trait\CurrentStateTrait;use App\Trait\DateTrait;use DateTimeImmutable;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;#[ORM\Entity(repositoryClass: OrderRepository::class)]#[ORM\Table(name: '`order`')]#[ApiResource(operations: [new GetCollection(normalizationContext: ['groups' => ['order:list']]),new GetCollection(uriTemplate: "/departments/{departmentId}/orders",uriVariables: ['departmentId' => new Link(toProperty: 'department', fromClass: Department::class),],normalizationContext: ['groups' => ['order:list']]),new GetCollection(uriTemplate: "/employees/{waiterId}/orders",uriVariables: ['waiterId' => new Link(toProperty: 'waiter', fromClass: Employee::class),],normalizationContext: ['groups' => ['order:list']]),new Get(),new Get(uriTemplate: "/orders/{id}/invoice",controller: ApiEstablishmentOrderInvoiceController::class,),new Get(uriTemplate: "/orders/{id}/timer",controller: ApiOrderShipmentTimerController::class,normalizationContext: ['groups' => ['order:timer']]),new Post(input: CreateOrderInput::class,processor: OrderCreateProcessor::class),new Post(uriTemplate: "/orders/{id}/start",controller: ApiOrderShipmentStartController::class,),new Post(uriTemplate: "/orders/{id}/over",controller: ApiOrderShipmentOverController::class,),],normalizationContext: ['groups' => ['order:list', 'order:view']],paginationClientEnabled: true)]class Order{use ArrayableTrait;use DateTrait;use CurrentStateTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['order:list'])]private ?int $id = null;#[ORM\Column(length: 255)]#[Groups(['order:list'])]private ?string $reference = null;#[ORM\Column(length: 255, nullable: true)]#[Groups(['order:list'])]private ?string $name = null;#[ORM\Column(length: 255, nullable: true)]#[Groups(['order:list'])]private ?string $phone = null;#[ORM\Column]#[Groups(['order:list'])]private ?float $amount = null;#[ORM\Column(nullable: true)]#[Groups(['order:list'])]private ?float $payout = null;#[ORM\Column(length: 255)]#[Groups(['order:list'])]private ?string $method = null;#[ORM\Column]#[Groups(['order:list'])]private ?int $status = null;#[ORM\OneToMany(mappedBy: 'command', targetEntity: OrderItems::class, cascade: ["persist"], orphanRemoval: true)]#[Groups(['order:list'])]private Collection $orderItems;#[ORM\ManyToOne(inversedBy: 'orders')]#[ORM\JoinColumn(nullable: true)]#[Groups(['order:list'])]private ?Department $department = null;#[ORM\OneToMany(mappedBy: 'command', targetEntity: Invoice::class, cascade: ["persist"], orphanRemoval: true)]private Collection $invoice;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]#[Groups(['order:list'])]private ?Currency $currency = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?User $author = null;#[ORM\ManyToOne(inversedBy: 'orders')]#[Groups(['order:view'])]private ?Employee $waiter = null;#[ORM\Column]#[Groups(['order:view'])]private ?bool $isDeliverable;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]#[Groups(['order:view'])]private ?Rate $rate = null;#[ORM\OneToMany(mappedBy: 'command', targetEntity: Shipment::class, orphanRemoval: true)]#[Groups(['order:list', 'order:view'])]private Collection $shipment;#[ORM\ManyToOne(inversedBy: 'orders')]#[ORM\JoinColumn(nullable: false)]private ?Establishment $establishment = null;#[ORM\Column(options: ['default' => false])]private ?bool $isProforma = false;#[ORM\OneToOne(mappedBy: 'orderCommand', cascade: ['persist', 'remove'])]private ?Transaction $transaction = null;#[ORM\ManyToMany(targetEntity: Client::class, inversedBy: 'orders')]#[Groups(['order:list'])]private Collection $clients;#[ORM\Column(options: ['default' => 1])]private ?int $clientPrincipalI = 1;public function __construct(){$this->currentState = 'new';$this->isDeliverable = 0;if (is_null($this->reference)) $this->reference = strtoupper(uniqid('OD-'));if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();$this->updatedAt = new DateTimeImmutable();$this->orderItems = new ArrayCollection();$this->invoice = new ArrayCollection();$this->shipment = new ArrayCollection();$this->status = Kimia::STATUS_INIT;$this->clients = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getReference(): ?string{return $this->reference;}public function setReference(string $reference): self{$this->reference = $reference;return $this;}public function getName(): ?string{return $this->name;}public function setName(?string $name): self{$this->name = $name;return $this;}public function getPhone(): ?string{return $this->phone;}public function setPhone(?string $phone): self{$this->phone = $phone;return $this;}public function getAmount(): ?float{return $this->amount;}public function getAmountRest(): ?float{return $this->amount - $this->getPayout();}public function setAmount(float $amount): self{$this->amount = $amount;return $this;}public function getPayout(): ?float{//return count($this->invoice) != 0 ? $this->amount - $this->getAmountRest() : $this->payout;return $this->payout;}public function setPayout(?float $payout): self{$this->payout = $payout;return $this;}public function getMethod(): ?string{return $this->method;}public function setMethod(string $method): self{$this->method = $method;return $this;}public function getStatus(): ?int{return $this->status;}public static function getStatusListForView(): array{return [Kimia::STATUS_INIT => "<span class='badge badge-soft-info'>Initié</span>",Kimia::STATUS_ACCEPTED => "<span class='badge badge-soft-info'>Accepté</span>",Kimia::STATUS_SUCCESS => "<span class='badge badge-soft-success'>Succès</span>",Kimia::STATUS_PROCESS => "<span class='badge badge-soft-warning'>En cours</span>",Kimia::STATUS_ERROR => "<span class='badge badge-soft-danger'>Erreur</span>",Kimia::STATUS_CANCEL => "<span class='badge badge-soft-secondary'>Annulé</span>",Kimia::STATUS_FAILED => "<span class='badge badge-soft-secondary'>Échoué</span>",Kimia::STATUS_PROFORMA => "<span class='badge badge-soft-warning'>Proforma</span>",];}public function setStatus(int $status): self{$this->status = $status;return $this;}/*** @return Collection<int, OrderItems>*/public function getOrderItems(): Collection{return $this->orderItems;}public function addOrderItem(OrderItems $orderItem): self{if (!$this->orderItems->contains($orderItem)) {$this->orderItems->add($orderItem);$orderItem->setCommand($this);}return $this;}public function removeOrderItem(OrderItems $orderItem): self{if ($this->orderItems->removeElement($orderItem)) {// set the owning side to null (unless already changed)if ($orderItem->getCommand() === $this) {$orderItem->setCommand(null);}}return $this;}public function getDepartment(): ?Department{return $this->department;}public function setDepartment(?Department $department): self{$this->department = $department;return $this;}/*** @return Collection<int, Invoice>*/public function getInvoice(): Collection{return $this->invoice;}public function addInvoice(Invoice $invoice): self{if (!$this->invoice->contains($invoice)) {$this->invoice->add($invoice);$invoice->setCommand($this);}return $this;}public function removeInvoice(Invoice $invoice): self{if ($this->invoice->removeElement($invoice)) {// set the owning side to null (unless already changed)if ($invoice->getCommand() === $this) {$invoice->setCommand(null);}}return $this;}public function getCurrency(): ?Currency{return $this->currency;}public function setCurrency(?Currency $currency): self{$this->currency = $currency;return $this;}public function getAuthor(): ?User{return $this->author;}public function setAuthor(?User $author): self{$this->author = $author;return $this;}public function getWaiter(): ?Employee{return $this->waiter;}public function setWaiter(?Employee $waiter): self{$this->waiter = $waiter;return $this;}public function isIsDeliverable(): ?bool{return $this->isDeliverable;}public function setIsDeliverable(bool $isDeliverable): self{$this->isDeliverable = $isDeliverable;return $this;}public function getIsClosed(): bool{return $this->payout >= $this->getAmount();}public function getRate(): ?Rate{return $this->rate;}public function setRate(?Rate $rate): self{$this->rate = $rate;return $this;}/*** @return Collection<int, Shipment>*/public function getShipment(): Collection{return $this->shipment;}#[Groups(['order:list'])]public function getCurrentShipment(): ?Shipment{$shipments = $this->getShipment()->map(function (Shipment $shipment) {if ($shipment->getCurrentState() == "notShipped" || $shipment->getCurrentState() == Kimia::STATUS_INIT) {return $shipment;}return null;});return $shipments->first() ?: null;}#[Groups(['order:list'])]public function getCurrentDestination(): ?string{return $this->getCurrentShipment()?->getDestination() ?: null;}public function addShipment(Shipment $shipment): self{if (!$this->shipment->contains($shipment)) {$this->shipment->add($shipment);$shipment->setCommand($this);}return $this;}public function removeShipment(Shipment $shipment): self{if ($this->shipment->removeElement($shipment)) {// set the owning side to null (unless already changed)if ($shipment->getCommand() === $this) {$shipment->setCommand(null);}}return $this;}public function getEstablishment(): ?Establishment{return $this->establishment;}public function setEstablishment(?Establishment $establishment): self{$this->establishment = $establishment;return $this;}public function isIsProforma(): ?bool{return $this->isProforma;}public function setIsProforma(bool $isProforma): static{$this->isProforma = $isProforma;return $this;}public function getTransaction(): ?Transaction{return $this->transaction;}public function setTransaction(?Transaction $transaction): static{// unset the owning side of the relation if necessaryif ($transaction === null && $this->transaction !== null) {$this->transaction->setOrderCommand(null);}// set the owning side of the relation if necessaryif ($transaction !== null && $transaction->getOrderCommand() !== $this) {$transaction->setOrderCommand($this);}$this->transaction = $transaction;return $this;}public function __toString(): string{return $this->reference;}/*** @return Collection<int, Client>*/public function getClients(): Collection{return $this->clients;}public function addClient(Client $client): static{if (!$this->clients->contains($client)) {$this->clients->add($client);}return $this;}public function removeClient(Client $client): static{$this->clients->removeElement($client);return $this;}public function getClientPrincipalI(): ?int{return $this->clientPrincipalI;}public function getClientPrincipalInt(): ?int{return $this->clientPrincipalI - 1;}public function setClientPrincipalI(int $clientPrincipalI): static{$this->clientPrincipalI = $clientPrincipalI;return $this;}}