src/Entity/Order/Order.php line 40

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Entity\Order;
  12. use App\Entity\Customer\Customer;
  13. use App\Entity\Geographical\Address;
  14. use App\Entity\IdentifiableTrait;
  15. use App\Entity\Printer\Printer;
  16. use App\OrderProductionStates;
  17. use App\OrderStates;
  18. use App\Repository\Order\OrderRepository;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\ORM\Mapping as ORM;
  22. use Gedmo\Timestampable\Traits\TimestampableEntity;
  23. use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
  24. use Sylius\Component\Resource\Model\ResourceInterface;
  25. #[ORM\Entity(repositoryClassOrderRepository::class)]
  26. #[ORM\Table(name'app_order')]
  27. #[SyliusCrudRoutes(alias'app.order'path'/admin/orders'section'backend'templates'backend/order'grid'app_backend_order'only: ['index''show'], vars: [
  28.     'all' => [
  29.         'subheader' => 'app.ui.manage_your_orders',
  30.     ],
  31.     'index' => [
  32.         'icon' => 'cart',
  33.     ],
  34. ])]
  35. class Order implements ResourceInterface
  36. {
  37.     use IdentifiableTrait;
  38.     use TimestampableEntity;
  39.     #[ORM\ManyToOne(targetEntityCustomer::class, inversedBy'orders'cascade: ['persist'])]
  40.     #[ORM\JoinColumn(name"customer_id"referencedColumnName"id"onDelete"CASCADE")]
  41.     private ?Customer $customer null;
  42.     #[ORM\ManyToOne(targetEntityAddress::class, cascade:['persist''remove'])]
  43.     #[ORM\JoinColumn(name"shipping_address_id"referencedColumnName"id"onDelete"CASCADE")]
  44.     private ?Address $shippingAddress null;
  45.     #[ORM\Column(type'string')]
  46.     private string $state;
  47.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  48.     private ?\DateTimeImmutable $checkoutCompletedAt null;
  49.     #[ORM\Column(type'integer')]
  50.     private int $shippementAmount 0;
  51.     #[ORM\Column(type'string'nullabletrue)]
  52.     private ?string $number null;
  53.     #[ORM\OneToMany(mappedBy'order'targetEntityOrderItem::class, orphanRemovaltruecascade:['persist''remove'])]
  54.     private Collection $orderItems;
  55.     #[ORM\Column(type'integer')]
  56.     private int $total 0;
  57.     #[ORM\Column(length255)]
  58.     private ?string $productionState null;
  59.     #[ORM\ManyToOne(targetEntityPrinter::class, inversedBy'orders')]
  60.     #[ORM\JoinColumn(name'printer_id'referencedColumnName'id'onDelete'SET NULL')]
  61.     private ?Printer $printer null;
  62.     #[ORM\Column(type'text'nullabletrue)]
  63.     private ?string $adminComment null;
  64.     /** @var Collection<int, OrderAdminImage> */
  65.     #[ORM\OneToMany(mappedBy'order'targetEntityOrderAdminImage::class, orphanRemovaltruecascade: ['persist''remove'])]
  66.     private Collection $adminImages;
  67.     #[ORM\Column(type'boolean')]
  68.     private bool $isFromCode false;
  69.     /** Total in cents (€) for direct payment. null when paid with credits. */
  70.     #[ORM\Column(type'integer'nullabletrue)]
  71.     private ?int $totalAmountCents null;
  72.     /** credits | direct | complement */
  73.     #[ORM\Column(type'string'length20options: ['default' => 'credits'])]
  74.     private string $paymentMode 'credits';
  75.     public function __construct()
  76.     {
  77.         $this->state OrderStates::STATE_CART;
  78.         $this->productionState OrderProductionStates::STATE_AWAITING;
  79.         $this->orderItems = new ArrayCollection();
  80.         $this->adminImages = new ArrayCollection();
  81.     }
  82.     /**
  83.      * Get the value of customer
  84.      *
  85.      * @return ?Customer
  86.      */
  87.     public function getCustomer(): ?Customer
  88.     {
  89.         return $this->customer;
  90.     }
  91.     /**
  92.      * Set the value of customer
  93.      *
  94.      * @return self
  95.      */
  96.     public function setCustomer(?Customer $customer): self
  97.     {
  98.         $this->customer $customer;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Get the value of shippingAddress
  103.      *
  104.      * @return ?Address
  105.      */
  106.     public function getShippingAddress(): ?Address
  107.     {
  108.         return $this->shippingAddress;
  109.     }
  110.     /**
  111.      * Set the value of shippingAddress
  112.      *
  113.      * @return self
  114.      */
  115.     public function setShippingAddress(?Address $address): self
  116.     {
  117.         $this->shippingAddress $address;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Get the value of state
  122.      *
  123.      * @return string
  124.      */
  125.     public function getState(): string
  126.     {
  127.         return $this->state;
  128.     }
  129.     /**
  130.      * Set the value of state
  131.      *
  132.      * @return self
  133.      */
  134.     public function setState(string $state): self
  135.     {
  136.         $this->state $state;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Get the value of checkoutCompletedAt
  141.      *
  142.      * @return ?\DateTimeImmutable
  143.      */
  144.     public function getCheckoutCompletedAt(): ?\DateTimeImmutable
  145.     {
  146.         return $this->checkoutCompletedAt;
  147.     }
  148.     /**
  149.      * Set the value of checkoutCompletedAt
  150.      *
  151.      * @return self
  152.      */
  153.     public function setCheckoutCompletedAt(?\DateTimeImmutable $checkoutCompletedAt): self
  154.     {
  155.         $this->checkoutCompletedAt $checkoutCompletedAt;
  156.         return $this;
  157.     }
  158.     /**
  159.      * Get the value of shippementAmount
  160.      *
  161.      * @return int
  162.      */
  163.     public function getShippementAmount(): int
  164.     {
  165.         return $this->shippementAmount;
  166.     }
  167.     /**
  168.      * Set the value of shippementAmount
  169.      *
  170.      * @return self
  171.      */
  172.     public function setShippementAmount(int $shippementAmount): self
  173.     {
  174.         $this->shippementAmount $shippementAmount;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get the value of number
  179.      *
  180.      * @return ?string
  181.      */
  182.     public function getNumber(): ?string
  183.     {
  184.         return $this->number;
  185.     }
  186.     /**
  187.      * Set the value of number
  188.      *
  189.      * @return self
  190.      */
  191.     public function setNumber(?string $number): self
  192.     {
  193.         $this->number $number;
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Collection<int, OrderItem>
  198.      */
  199.     public function getOrderItems(): Collection
  200.     {
  201.         return $this->orderItems;
  202.     }
  203.     public function addOrderItem(OrderItem $orderItem): self
  204.     {
  205.         if (!$this->orderItems->contains($orderItem)) {
  206.             $this->orderItems->add($orderItem);
  207.             $orderItem->setOrder($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeOrderItem(OrderItem $orderItem): self
  212.     {
  213.         if ($this->orderItems->removeElement($orderItem)) {
  214.             if ($orderItem->getOrder() === $this) {
  215.                 $orderItem->setOrder(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     /**
  221.      * Get the value of total
  222.      *
  223.      * @return int
  224.      */
  225.     public function getTotal(): int
  226.     {
  227.         return $this->total;
  228.     }
  229.     /**
  230.      * Set the value of total
  231.      *
  232.      * @return self
  233.      */
  234.     public function setTotal(int $total): self
  235.     {
  236.         $this->total $total;
  237.         return $this;
  238.     }
  239.     public function getProductsCost(): int
  240.     {
  241.         $cost 0;
  242.         foreach ($this->getOrderItems() as $orderItem) {
  243.             $cost += $orderItem->getTotalPrice();
  244.         }
  245.         return $cost;
  246.     }
  247.     public function getFirstItem(): ?OrderItem
  248.     {
  249.         $orderItem $this->getOrderItems()->first();
  250.         return ($orderItem instanceof OrderItem) ? $orderItem null;
  251.     }
  252.     public function getFirstItemName(): ?string
  253.     {
  254.         return ($this->getFirstItem()) ? $this->getFirstItem()->getAlbumName() : null;
  255.     }
  256.     public function getFirstItemQuantity(): int
  257.     {
  258.         return ($this->getFirstItem()) ? $this->getFirstItem()->getQuantity() : 0;
  259.     }
  260.     public function getFirstItemPhotosCount(): int
  261.     {
  262.         return ($this->getFirstItem()) ? $this->getFirstItem()->getPhotosCount() : 0;
  263.     }
  264.     public function getFirstItemAlbumSize(): int
  265.     {
  266.         return ($this->getFirstItem()) ? $this->getFirstItem()->getProduct()->getAlbumSize() : 0;
  267.     }
  268.     public function getFirstItemMattePaper(): ?bool
  269.     {
  270.         return ($this->getFirstItem()) ? $this->getFirstItem()->getMattePaper() : null;
  271.     }
  272.     public function getFirstItemWithFrame(): ?bool
  273.     {
  274.         return ($this->getFirstItem()) ? $this->getFirstItem()->getWithFrame() : null;
  275.     }
  276.     public function getProductionState(): ?string
  277.     {
  278.         return $this->productionState;
  279.     }
  280.     public function setProductionState(string $productionState): self
  281.     {
  282.         $this->productionState $productionState;
  283.         return $this;
  284.     }
  285.     public function getPrinter(): ?Printer
  286.     {
  287.         return $this->printer;
  288.     }
  289.     public function setPrinter(?Printer $printer): self
  290.     {
  291.         $this->printer $printer;
  292.         return $this;
  293.     }
  294.     public function getAdminComment(): ?string
  295.     {
  296.         return $this->adminComment;
  297.     }
  298.     public function setAdminComment(?string $adminComment): self
  299.     {
  300.         $this->adminComment $adminComment;
  301.         return $this;
  302.     }
  303.     /** @return Collection<int, OrderAdminImage> */
  304.     public function getAdminImages(): Collection
  305.     {
  306.         return $this->adminImages;
  307.     }
  308.     public function addAdminImage(OrderAdminImage $adminImage): self
  309.     {
  310.         if (!$this->adminImages->contains($adminImage)) {
  311.             $this->adminImages->add($adminImage);
  312.             $adminImage->setOrder($this);
  313.         }
  314.         return $this;
  315.     }
  316.     public function removeAdminImage(OrderAdminImage $adminImage): self
  317.     {
  318.         if ($this->adminImages->removeElement($adminImage)) {
  319.             if ($adminImage->getOrder() === $this) {
  320.                 $adminImage->setOrder(null);
  321.             }
  322.         }
  323.         return $this;
  324.     }
  325.     public function isFromCode(): bool
  326.     {
  327.         return $this->isFromCode;
  328.     }
  329.     public function setIsFromCode(bool $isFromCode): self
  330.     {
  331.         $this->isFromCode $isFromCode;
  332.         return $this;
  333.     }
  334.     public function getTotalAmountCents(): ?int
  335.     {
  336.         return $this->totalAmountCents;
  337.     }
  338.     public function setTotalAmountCents(?int $totalAmountCents): self
  339.     {
  340.         $this->totalAmountCents $totalAmountCents;
  341.         return $this;
  342.     }
  343.     public function getPaymentMode(): string
  344.     {
  345.         return $this->paymentMode;
  346.     }
  347.     public function setPaymentMode(string $paymentMode): self
  348.     {
  349.         $this->paymentMode $paymentMode;
  350.         return $this;
  351.     }
  352.     public function isDirectPayment(): bool
  353.     {
  354.         return $this->paymentMode === 'direct' || $this->paymentMode === 'complement';
  355.     }
  356. }