|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- <?php
-
- namespace Lc\ShopBundle\Model;
-
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Doctrine\ORM\Mapping as ORM;
- use Lc\ShopBundle\Context\DocumentInterface;
- use Lc\ShopBundle\Context\FilterMerchantInterface;
- use Lc\ShopBundle\Services\Order\OrderUtils;
- use Lc\ShopBundle\Model\OrderStatus ;
-
- /**
- * @ORM\MappedSuperclass()
- */
- abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface
- {
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $merchant;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders")
- */
- protected $user;
-
- /**
- * @ORM\ManyToOne(targetEntity="App\Entity\Visitor", inversedBy="orders")
- */
- protected $visitor;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
- */
- protected $invoiceAddress;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $invoiceAddressText;
-
- /**
- * @ORM\Column(type="datetime", nullable=true)
- */
- protected $validationDate;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $comment;
-
- /**
- * @ORM\Column(type="boolean", nullable=true)
- */
- protected $autoPayment;
-
- /**
- * @ORM\Column(type="string", length=31, nullable=true)
- */
- protected $meanPayment;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderStatusHistoryInterface", mappedBy="orderShop", orphanRemoval=true)
- */
- protected $orderStatusHistories;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true)
- */
- protected $orderPayments;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true)
- */
- protected $orderProducts;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- */
- protected $deliveryInfos;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $orderStatus;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCartInterface", mappedBy="orderShop", orphanRemoval=true)
- */
- protected $orderReductionCarts;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCreditInterface", mappedBy="orderShop", orphanRemoval=true)
- */
- protected $orderReductionCredits;
-
- /**
- * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\DocumentInterface", inversedBy="orderShops")
- */
- protected $documents;
-
- /**
- * @Gedmo\Blameable(on="create")
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
- * @ORM\JoinColumn(nullable=true)
- */
- protected $createdBy;
-
- /**
- * @Gedmo\Blameable(on="update")
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
- * @ORM\JoinColumn(nullable=true)
- */
- protected $updatedBy;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="orderShop")
- */
- protected $tickets;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\SectionInterface", inversedBy="orderShops")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $section;
-
- public function __construct()
- {
- $this->orderStatusHistories = new ArrayCollection();
- $this->orderPayments = new ArrayCollection();
- $this->orderProducts = new ArrayCollection();
- $this->creditHistories = new ArrayCollection();
- $this->orderReductionCarts = new ArrayCollection();
- $this->orderReductionCredits = new ArrayCollection();
- $this->documents = new ArrayCollection();
- }
-
- public function __toString()
- {
- if($this->getValidationDate()) {
- return 'Commande du '.$this->getValidationDate()->format('d/m/Y') ;
- }
- else {
- return 'Commande #'.$this->getId() ;
- }
- }
-
- public function getValidationDate(): ?\DateTimeInterface
- {
- return $this->validationDate;
- }
-
- public function setValidationDate(\DateTimeInterface $validationDate): self
- {
- $this->validationDate = $validationDate;
-
- return $this;
- }
-
- public function getDateCreated()
- {
- $orderStatusHistory = $this->getOrderStatusHistory(OrderStatus::ALIAS_WAITING_DELIVERY);
- if ($orderStatusHistory) {
- return $orderStatusHistory->getCreatedAt();
- }
-
- return null;
- }
-
- public function getOrderStatusHistory($status)
- {
- $orderStatusHistories = $this->getOrderStatusHistories();
- if (count($orderStatusHistories) > 0) {
- foreach ($orderStatusHistories as $orderStatusHistory) {
- if ($orderStatusHistory->getOrderStatus() == $status) {
- return $orderStatusHistory;
- }
- }
- }
-
- return null;
- }
-
- public function getMerchant(): ?Merchant
- {
- return $this->merchant;
- }
-
- public function setMerchant(?Merchant $merchant): self
- {
- $this->merchant = $merchant;
-
- return $this;
- }
-
- public function getUser(): ?User
- {
- return $this->user;
- }
-
- public function setUser(?User $user): self
- {
- $this->user = $user;
-
- return $this;
- }
-
- public function getInvoiceAddress(): ?Address
- {
- return $this->invoiceAddress;
- }
-
- public function setInvoiceAddress(?Address $invoiceAddress): self
- {
- $this->invoiceAddress = $invoiceAddress;
-
- return $this;
- }
-
- public function getInvoiceAddressText(): ?string
- {
- return $this->invoiceAddressText;
- }
-
- public function setInvoiceAddressText(string $invoiceAddressText): self
- {
- $this->invoiceAddressText = $invoiceAddressText;
-
- return $this;
- }
-
- public function getComment(): ?string
- {
- return $this->comment;
- }
-
- public function setComment(?string $comment): self
- {
- $this->comment = $comment;
-
- return $this;
- }
-
- public function getAutoPayment(): ?bool
- {
- return $this->autoPayment;
- }
-
- public function setAutoPayment(bool $autoPayment): self
- {
- $this->autoPayment = $autoPayment;
-
- return $this;
- }
-
- public function getMeanPayment(): ?string
- {
- return $this->meanPayment;
- }
-
- public function setMeanPayment(string $meanPayment): self
- {
- $this->meanPayment = $meanPayment;
-
- return $this;
- }
-
- /**
- * @return Collection|OrderStatusHistory[]
- */
- public function getOrderStatusHistories(): Collection
- {
- return $this->orderStatusHistories;
- }
-
- public function addOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
- {
- if (!$this->orderStatusHistories->contains($orderStatusHistory)) {
- $this->orderStatusHistories[] = $orderStatusHistory;
- $orderStatusHistory->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
- {
- if ($this->orderStatusHistories->contains($orderStatusHistory)) {
- $this->orderStatusHistories->removeElement($orderStatusHistory);
- // set the owning side to null (unless already changed)
- if ($orderStatusHistory->getOrderShop() === $this) {
- $orderStatusHistory->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- /**
- * @return Collection|OrderPayment[]
- */
- public function getOrderPayments(): Collection
- {
- return $this->orderPayments;
- }
-
- public function addOrderPayment(OrderPayment $orderPayment): self
- {
- if (!$this->orderPayments->contains($orderPayment)) {
- $this->orderPayments[] = $orderPayment;
- $orderPayment->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeOrderPayment(OrderPayment $orderPayment): self
- {
- if ($this->orderPayments->contains($orderPayment)) {
- $this->orderPayments->removeElement($orderPayment);
- // set the owning side to null (unless already changed)
- if ($orderPayment->getOrderShop() === $this) {
- $orderPayment->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- /**
- * @return Collection|OrderProduct[]
- */
- public function getOrderProducts(): Collection
- {
- return $this->orderProducts;
- }
-
- public function addOrderProduct(OrderProduct $orderProduct): self
- {
- if (!$this->orderProducts->contains($orderProduct)) {
- $this->orderProducts[] = $orderProduct;
- $orderProduct->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeOrderProduct(OrderProduct $orderProduct): self
- {
- if ($this->orderProducts->contains($orderProduct)) {
- $this->orderProducts->removeElement($orderProduct);
- // set the owning side to null (unless already changed)
- if ($orderProduct->getOrderShop() === $this) {
- $orderProduct->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- /**
- * @return Collection|CreditHistory[]
- */
- public function getCreditHistories(): Collection
- {
- return $this->creditHistories;
- }
-
- public function addCreditHistory(CreditHistory $creditHistory): self
- {
- if (!$this->creditHistories->contains($creditHistory)) {
- $this->creditHistories[] = $creditHistory;
- $creditHistory->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeCreditHistory(CreditHistory $creditHistory): self
- {
- if ($this->creditHistories->contains($creditHistory)) {
- $this->creditHistories->removeElement($creditHistory);
- // set the owning side to null (unless already changed)
- if ($creditHistory->getOrderShop() === $this) {
- $creditHistory->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- public function getVisitor(): ?Visitor
- {
- return $this->visitor;
- }
-
- public function setVisitor(?Visitor $visitor): self
- {
- $this->visitor = $visitor;
-
- return $this;
- }
-
- public function getDeliveryInfos(): ?string
- {
- return $this->deliveryInfos;
- }
-
- public function setDeliveryInfos(?string $deliveryInfos): self
- {
- $this->deliveryInfos = $deliveryInfos;
-
- return $this;
- }
-
-
- public function getOrderStatus(): ?OrderStatus
- {
- return $this->orderStatus;
- }
-
- public function setOrderStatusProtected(?OrderStatus $orderStatus): self
- {
- $this->orderStatus = $orderStatus;
-
- return $this;
- }
-
-
- /**
- * @return Collection|OrderReductionCart[]
- */
- public function getOrderReductionCarts(): Collection
- {
- return $this->orderReductionCarts;
- }
-
- public function addOrderReductionCart(OrderReductionCart $orderReductionCart): self
- {
- if (!$this->orderReductionCarts->contains($orderReductionCart)) {
- $this->orderReductionCarts[] = $orderReductionCart;
- $orderReductionCart->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeOrderReductionCart(OrderReductionCart $orderReductionCart): self
- {
- if ($this->orderReductionCarts->contains($orderReductionCart)) {
- $this->orderReductionCarts->removeElement($orderReductionCart);
- // set the owning side to null (unless already changed)
- if ($orderReductionCart->getOrderShop() === $this) {
- $orderReductionCart->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- /**
- * @return Collection|OrderReductionCart[]
- */
- public function getOrderReductionCredits(): Collection
- {
- return $this->orderReductionCredits;
- }
-
- public function addOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
- {
- if (!$this->orderReductionCredits->contains($orderReductionCredit)) {
- $this->orderReductionCredits[] = $orderReductionCredit;
- $orderReductionCredit->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
- {
- if ($this->orderReductionCredits->contains($orderReductionCredit)) {
- $this->orderReductionCredits->removeElement($orderReductionCredit);
- // set the owning side to null (unless already changed)
- if ($orderReductionCredit->getOrderShop() === $this) {
- $orderReductionCredit->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- /**
- * @return Collection|Document[]
- */
- public function getDocuments(): Collection
- {
- return $this->documents;
- }
-
- public function addDocument(Document $document): self
- {
- if (!$this->documents->contains($document)) {
- $this->documents[] = $document;
- }
-
- return $this;
- }
-
- public function removeDocument(Document $document): self
- {
- if ($this->documents->contains($document)) {
- $this->documents->removeElement($document);
- }
-
- return $this;
- }
-
- public function getDocumentInvoice(): Document
- {
- foreach($this->getDocuments() as $document) {
- if($document->getType() == Document::TYPE_INVOICE) {
- return $document ;
- }
- }
-
- return false ;
- }
-
- /**
- * @return Collection|Ticket[]
- */
- public function getTickets(): Collection
- {
- return $this->tickets;
- }
-
- public function addTicket(Ticket $ticket): self
- {
- if (!$this->tickets->contains($ticket)) {
- $this->tickets[] = $ticket;
- $ticket->setOrderShop($this);
- }
-
- return $this;
- }
-
- public function removeTicket(Ticket $ticket): self
- {
- if ($this->tickets->contains($ticket)) {
- $this->tickets->removeElement($ticket);
- // set the owning side to null (unless already changed)
- if ($ticket->getOrderShop() === $this) {
- $ticket->setOrderShop(null);
- }
- }
-
- return $this;
- }
-
- public function isValid() {
- if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsValid) > 0) {
- return true ;
- }
-
- return false ;
- }
-
- public function isCart() {
- if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsCart) > 0) {
- return true ;
- }
-
- return false ;
- }
-
- public function getSection(): ?Section
- {
- return $this->section;
- }
-
- public function setSection(?Section $section): self
- {
- $this->section = $section;
-
- return $this;
- }
-
- }
|