Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

565 Zeilen
17KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\OrderStatus;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Lc\ShopBundle\Context\DocumentInterface;
  9. use Lc\ShopBundle\Context\FilterMerchantInterface;
  10. /**
  11. * @ORM\MappedSuperclass()
  12. */
  13. abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface
  14. {
  15. /**
  16. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
  17. * @ORM\JoinColumn(nullable=false)
  18. */
  19. protected $merchant;
  20. /**
  21. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders")
  22. */
  23. protected $user;
  24. /**
  25. * @ORM\ManyToOne(targetEntity="App\Entity\Visitor", inversedBy="orders")
  26. */
  27. protected $visitor;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
  30. */
  31. protected $invoiceAddress;
  32. /**
  33. * @ORM\Column(type="text", nullable=true)
  34. */
  35. protected $invoiceAddressText;
  36. /**
  37. * @ORM\Column(type="datetime", nullable=true)
  38. */
  39. protected $validationDate;
  40. /**
  41. * @ORM\Column(type="text", nullable=true)
  42. */
  43. protected $comment;
  44. /**
  45. * @ORM\Column(type="boolean", nullable=true)
  46. */
  47. protected $autoPayment;
  48. /**
  49. * @ORM\Column(type="string", length=31, nullable=true)
  50. */
  51. protected $meanPayment;
  52. /**
  53. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderStatusHistoryInterface", mappedBy="orderShop", orphanRemoval=true)
  54. */
  55. protected $orderStatusHistories;
  56. /**
  57. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true)
  58. */
  59. protected $orderPayments;
  60. /**
  61. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true)
  62. */
  63. protected $orderProducts;
  64. /**
  65. * @ORM\Column(type="text", nullable=true)
  66. */
  67. protected $deliveryInfos;
  68. /**
  69. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface")
  70. * @ORM\JoinColumn(nullable=false)
  71. */
  72. protected $orderStatus;
  73. /**
  74. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCartInterface", mappedBy="orderShop", orphanRemoval=true)
  75. */
  76. protected $orderReductionCarts;
  77. /**
  78. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCreditInterface", mappedBy="orderShop", orphanRemoval=true)
  79. */
  80. protected $orderReductionCredits;
  81. /**
  82. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\DocumentInterface", inversedBy="orderShops")
  83. */
  84. protected $documents;
  85. /**
  86. * @Gedmo\Blameable(on="create")
  87. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  88. * @ORM\JoinColumn(nullable=true)
  89. */
  90. protected $createdBy;
  91. /**
  92. * @Gedmo\Blameable(on="update")
  93. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  94. * @ORM\JoinColumn(nullable=true)
  95. */
  96. protected $updatedBy;
  97. /**
  98. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="orderShop")
  99. */
  100. protected $tickets;
  101. public function __construct()
  102. {
  103. $this->orderStatusHistories = new ArrayCollection();
  104. $this->orderPayments = new ArrayCollection();
  105. $this->orderProducts = new ArrayCollection();
  106. $this->creditHistories = new ArrayCollection();
  107. $this->orderReductionCarts = new ArrayCollection();
  108. $this->orderReductionCredits = new ArrayCollection();
  109. $this->documents = new ArrayCollection();
  110. }
  111. public function __toString()
  112. {
  113. if($this->getValidationDate()) {
  114. return 'Commande du '.$this->getValidationDate()->format('d/m/Y') ;
  115. }
  116. else {
  117. return 'Commande #'.$this->getId() ;
  118. }
  119. }
  120. public function getValidationDate(): ?\DateTimeInterface
  121. {
  122. return $this->validationDate;
  123. }
  124. public function setValidationDate(\DateTimeInterface $validationDate): self
  125. {
  126. $this->validationDate = $validationDate;
  127. return $this;
  128. }
  129. public function getDateCreated()
  130. {
  131. $orderStatusHistory = $this->getOrderStatusHistory('new');
  132. if ($orderStatusHistory) {
  133. return $orderStatusHistory->getCreatedAt();
  134. }
  135. return null;
  136. }
  137. public function getOrderStatusHistory($status)
  138. {
  139. $orderStatusHistories = $this->getOrderStatusHistories();
  140. if (count($orderStatusHistories) > 0) {
  141. foreach ($orderStatusHistories as $orderStatusHistory) {
  142. if ($orderStatusHistory->getOrderStatus() == $status) {
  143. return $orderStatusHistory;
  144. }
  145. }
  146. }
  147. return null;
  148. }
  149. public function getMerchant(): ?Merchant
  150. {
  151. return $this->merchant;
  152. }
  153. public function setMerchant(?Merchant $merchant): self
  154. {
  155. $this->merchant = $merchant;
  156. return $this;
  157. }
  158. public function getUser(): ?User
  159. {
  160. return $this->user;
  161. }
  162. public function setUser(?User $user): self
  163. {
  164. $this->user = $user;
  165. return $this;
  166. }
  167. public function getInvoiceAddress(): ?Address
  168. {
  169. return $this->invoiceAddress;
  170. }
  171. public function setInvoiceAddress(?Address $invoiceAddress): self
  172. {
  173. $this->invoiceAddress = $invoiceAddress;
  174. return $this;
  175. }
  176. public function getInvoiceAddressText(): ?string
  177. {
  178. return $this->invoiceAddressText;
  179. }
  180. public function setInvoiceAddressText(string $invoiceAddressText): self
  181. {
  182. $this->invoiceAddressText = $invoiceAddressText;
  183. return $this;
  184. }
  185. public function getComment(): ?string
  186. {
  187. return $this->comment;
  188. }
  189. public function setComment(?string $comment): self
  190. {
  191. $this->comment = $comment;
  192. return $this;
  193. }
  194. public function getAutoPayment(): ?bool
  195. {
  196. return $this->autoPayment;
  197. }
  198. public function setAutoPayment(bool $autoPayment): self
  199. {
  200. $this->autoPayment = $autoPayment;
  201. return $this;
  202. }
  203. public function getMeanPayment(): ?string
  204. {
  205. return $this->meanPayment;
  206. }
  207. public function setMeanPayment(string $meanPayment): self
  208. {
  209. $this->meanPayment = $meanPayment;
  210. return $this;
  211. }
  212. /**
  213. * @return Collection|OrderStatusHistory[]
  214. */
  215. public function getOrderStatusHistories(): Collection
  216. {
  217. return $this->orderStatusHistories;
  218. }
  219. public function addOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  220. {
  221. if (!$this->orderStatusHistories->contains($orderStatusHistory)) {
  222. $this->orderStatusHistories[] = $orderStatusHistory;
  223. $orderStatusHistory->setOrderShop($this);
  224. }
  225. return $this;
  226. }
  227. public function removeOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  228. {
  229. if ($this->orderStatusHistories->contains($orderStatusHistory)) {
  230. $this->orderStatusHistories->removeElement($orderStatusHistory);
  231. // set the owning side to null (unless already changed)
  232. if ($orderStatusHistory->getOrderShop() === $this) {
  233. $orderStatusHistory->setOrderShop(null);
  234. }
  235. }
  236. return $this;
  237. }
  238. /**
  239. * @return Collection|OrderPayment[]
  240. */
  241. public function getOrderPayments(): Collection
  242. {
  243. return $this->orderPayments;
  244. }
  245. public function addOrderPayment(OrderPayment $orderPayment): self
  246. {
  247. if (!$this->orderPayments->contains($orderPayment)) {
  248. $this->orderPayments[] = $orderPayment;
  249. $orderPayment->setOrderShop($this);
  250. }
  251. return $this;
  252. }
  253. public function removeOrderPayment(OrderPayment $orderPayment): self
  254. {
  255. if ($this->orderPayments->contains($orderPayment)) {
  256. $this->orderPayments->removeElement($orderPayment);
  257. // set the owning side to null (unless already changed)
  258. if ($orderPayment->getOrderShop() === $this) {
  259. $orderPayment->setOrderShop(null);
  260. }
  261. }
  262. return $this;
  263. }
  264. /**
  265. * @return Collection|OrderProduct[]
  266. */
  267. public function getOrderProducts(): Collection
  268. {
  269. return $this->orderProducts;
  270. }
  271. public function addOrderProduct(OrderProduct $orderProduct): self
  272. {
  273. if (!$this->orderProducts->contains($orderProduct)) {
  274. $this->orderProducts[] = $orderProduct;
  275. $orderProduct->setOrderShop($this);
  276. }
  277. return $this;
  278. }
  279. public function removeOrderProduct(OrderProduct $orderProduct): self
  280. {
  281. if ($this->orderProducts->contains($orderProduct)) {
  282. $this->orderProducts->removeElement($orderProduct);
  283. // set the owning side to null (unless already changed)
  284. if ($orderProduct->getOrderShop() === $this) {
  285. $orderProduct->setOrderShop(null);
  286. }
  287. }
  288. return $this;
  289. }
  290. /**
  291. * @return Collection|CreditHistory[]
  292. */
  293. public function getCreditHistories(): Collection
  294. {
  295. return $this->creditHistories;
  296. }
  297. public function addCreditHistory(CreditHistory $creditHistory): self
  298. {
  299. if (!$this->creditHistories->contains($creditHistory)) {
  300. $this->creditHistories[] = $creditHistory;
  301. $creditHistory->setOrderShop($this);
  302. }
  303. return $this;
  304. }
  305. public function removeCreditHistory(CreditHistory $creditHistory): self
  306. {
  307. if ($this->creditHistories->contains($creditHistory)) {
  308. $this->creditHistories->removeElement($creditHistory);
  309. // set the owning side to null (unless already changed)
  310. if ($creditHistory->getOrderShop() === $this) {
  311. $creditHistory->setOrderShop(null);
  312. }
  313. }
  314. return $this;
  315. }
  316. public function getVisitor(): ?Visitor
  317. {
  318. return $this->visitor;
  319. }
  320. public function setVisitor(?Visitor $visitor): self
  321. {
  322. $this->visitor = $visitor;
  323. return $this;
  324. }
  325. public function getDeliveryInfos(): ?string
  326. {
  327. return $this->deliveryInfos;
  328. }
  329. public function setDeliveryInfos(?string $deliveryInfos): self
  330. {
  331. $this->deliveryInfos = $deliveryInfos;
  332. return $this;
  333. }
  334. public function getOrderStatus(): ?OrderStatus
  335. {
  336. return $this->orderStatus;
  337. }
  338. public function setOrderStatusProtected(?OrderStatus $orderStatus): self
  339. {
  340. $this->orderStatus = $orderStatus;
  341. return $this;
  342. }
  343. /**
  344. * @return Collection|OrderReductionCart[]
  345. */
  346. public function getOrderReductionCarts(): Collection
  347. {
  348. return $this->orderReductionCarts;
  349. }
  350. public function addOrderReductionCart(OrderReductionCart $orderReductionCart): self
  351. {
  352. if (!$this->orderReductionCarts->contains($orderReductionCart)) {
  353. $this->orderReductionCarts[] = $orderReductionCart;
  354. $orderReductionCart->setOrderShop($this);
  355. }
  356. return $this;
  357. }
  358. public function removeOrderReductionCart(OrderReductionCart $orderReductionCart): self
  359. {
  360. if ($this->orderReductionCarts->contains($orderReductionCart)) {
  361. $this->orderReductionCarts->removeElement($orderReductionCart);
  362. // set the owning side to null (unless already changed)
  363. if ($orderReductionCart->getOrderShop() === $this) {
  364. $orderReductionCart->setOrderShop(null);
  365. }
  366. }
  367. return $this;
  368. }
  369. /**
  370. * @return Collection|OrderReductionCart[]
  371. */
  372. public function getOrderReductionCredits(): Collection
  373. {
  374. return $this->orderReductionCredits;
  375. }
  376. public function addOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  377. {
  378. if (!$this->orderReductionCredits->contains($orderReductionCredit)) {
  379. $this->orderReductionCredits[] = $orderReductionCredit;
  380. $orderReductionCredit->setOrderShop($this);
  381. }
  382. return $this;
  383. }
  384. public function removeOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  385. {
  386. if ($this->orderReductionCredits->contains($orderReductionCredit)) {
  387. $this->orderReductionCredits->removeElement($orderReductionCredit);
  388. // set the owning side to null (unless already changed)
  389. if ($orderReductionCredit->getOrderShop() === $this) {
  390. $orderReductionCredit->setOrderShop(null);
  391. }
  392. }
  393. return $this;
  394. }
  395. /**
  396. * @return Collection|Document[]
  397. */
  398. public function getDocuments(): Collection
  399. {
  400. return $this->documents;
  401. }
  402. public function addDocument(Document $document): self
  403. {
  404. if (!$this->documents->contains($document)) {
  405. $this->documents[] = $document;
  406. }
  407. return $this;
  408. }
  409. public function removeDocument(Document $document): self
  410. {
  411. if ($this->documents->contains($document)) {
  412. $this->documents->removeElement($document);
  413. }
  414. return $this;
  415. }
  416. /**
  417. * @return Collection|Ticket[]
  418. */
  419. public function getTickets(): Collection
  420. {
  421. return $this->tickets;
  422. }
  423. public function addTicket(Ticket $ticket): self
  424. {
  425. if (!$this->tickets->contains($ticket)) {
  426. $this->tickets[] = $ticket;
  427. $ticket->setOrderShop($this);
  428. }
  429. return $this;
  430. }
  431. public function removeTicket(Ticket $ticket): self
  432. {
  433. if ($this->tickets->contains($ticket)) {
  434. $this->tickets->removeElement($ticket);
  435. // set the owning side to null (unless already changed)
  436. if ($ticket->getOrderShop() === $this) {
  437. $ticket->setOrderShop(null);
  438. }
  439. }
  440. return $this;
  441. }
  442. public function isValid() {
  443. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsValid) > 0) {
  444. return true ;
  445. }
  446. return false ;
  447. }
  448. public function isCart() {
  449. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsCart) > 0) {
  450. return true ;
  451. }
  452. return false ;
  453. }
  454. }