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.

560 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. return 'Commande du '.$this->getValidationDate()->format('d/m/Y') ;
  114. }
  115. public function getValidationDate(): ?\DateTimeInterface
  116. {
  117. return $this->validationDate;
  118. }
  119. public function setValidationDate(\DateTimeInterface $validationDate): self
  120. {
  121. $this->validationDate = $validationDate;
  122. return $this;
  123. }
  124. public function getDateCreated()
  125. {
  126. $orderStatusHistory = $this->getOrderStatusHistory('new');
  127. if ($orderStatusHistory) {
  128. return $orderStatusHistory->getCreatedAt();
  129. }
  130. return null;
  131. }
  132. public function getOrderStatusHistory($status)
  133. {
  134. $orderStatusHistories = $this->getOrderStatusHistories();
  135. if (count($orderStatusHistories) > 0) {
  136. foreach ($orderStatusHistories as $orderStatusHistory) {
  137. if ($orderStatusHistory->getOrderStatus() == $status) {
  138. return $orderStatusHistory;
  139. }
  140. }
  141. }
  142. return null;
  143. }
  144. public function getMerchant(): ?Merchant
  145. {
  146. return $this->merchant;
  147. }
  148. public function setMerchant(?Merchant $merchant): self
  149. {
  150. $this->merchant = $merchant;
  151. return $this;
  152. }
  153. public function getUser(): ?User
  154. {
  155. return $this->user;
  156. }
  157. public function setUser(?User $user): self
  158. {
  159. $this->user = $user;
  160. return $this;
  161. }
  162. public function getInvoiceAddress(): ?Address
  163. {
  164. return $this->invoiceAddress;
  165. }
  166. public function setInvoiceAddress(?Address $invoiceAddress): self
  167. {
  168. $this->invoiceAddress = $invoiceAddress;
  169. return $this;
  170. }
  171. public function getInvoiceAddressText(): ?string
  172. {
  173. return $this->invoiceAddressText;
  174. }
  175. public function setInvoiceAddressText(string $invoiceAddressText): self
  176. {
  177. $this->invoiceAddressText = $invoiceAddressText;
  178. return $this;
  179. }
  180. public function getComment(): ?string
  181. {
  182. return $this->comment;
  183. }
  184. public function setComment(?string $comment): self
  185. {
  186. $this->comment = $comment;
  187. return $this;
  188. }
  189. public function getAutoPayment(): ?bool
  190. {
  191. return $this->autoPayment;
  192. }
  193. public function setAutoPayment(bool $autoPayment): self
  194. {
  195. $this->autoPayment = $autoPayment;
  196. return $this;
  197. }
  198. public function getMeanPayment(): ?string
  199. {
  200. return $this->meanPayment;
  201. }
  202. public function setMeanPayment(string $meanPayment): self
  203. {
  204. $this->meanPayment = $meanPayment;
  205. return $this;
  206. }
  207. /**
  208. * @return Collection|OrderStatusHistory[]
  209. */
  210. public function getOrderStatusHistories(): Collection
  211. {
  212. return $this->orderStatusHistories;
  213. }
  214. public function addOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  215. {
  216. if (!$this->orderStatusHistories->contains($orderStatusHistory)) {
  217. $this->orderStatusHistories[] = $orderStatusHistory;
  218. $orderStatusHistory->setOrderShop($this);
  219. }
  220. return $this;
  221. }
  222. public function removeOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  223. {
  224. if ($this->orderStatusHistories->contains($orderStatusHistory)) {
  225. $this->orderStatusHistories->removeElement($orderStatusHistory);
  226. // set the owning side to null (unless already changed)
  227. if ($orderStatusHistory->getOrderShop() === $this) {
  228. $orderStatusHistory->setOrderShop(null);
  229. }
  230. }
  231. return $this;
  232. }
  233. /**
  234. * @return Collection|OrderPayment[]
  235. */
  236. public function getOrderPayments(): Collection
  237. {
  238. return $this->orderPayments;
  239. }
  240. public function addOrderPayment(OrderPayment $orderPayment): self
  241. {
  242. if (!$this->orderPayments->contains($orderPayment)) {
  243. $this->orderPayments[] = $orderPayment;
  244. $orderPayment->setOrderShop($this);
  245. }
  246. return $this;
  247. }
  248. public function removeOrderPayment(OrderPayment $orderPayment): self
  249. {
  250. if ($this->orderPayments->contains($orderPayment)) {
  251. $this->orderPayments->removeElement($orderPayment);
  252. // set the owning side to null (unless already changed)
  253. if ($orderPayment->getOrderShop() === $this) {
  254. $orderPayment->setOrderShop(null);
  255. }
  256. }
  257. return $this;
  258. }
  259. /**
  260. * @return Collection|OrderProduct[]
  261. */
  262. public function getOrderProducts(): Collection
  263. {
  264. return $this->orderProducts;
  265. }
  266. public function addOrderProduct(OrderProduct $orderProduct): self
  267. {
  268. if (!$this->orderProducts->contains($orderProduct)) {
  269. $this->orderProducts[] = $orderProduct;
  270. $orderProduct->setOrderShop($this);
  271. }
  272. return $this;
  273. }
  274. public function removeOrderProduct(OrderProduct $orderProduct): self
  275. {
  276. if ($this->orderProducts->contains($orderProduct)) {
  277. $this->orderProducts->removeElement($orderProduct);
  278. // set the owning side to null (unless already changed)
  279. if ($orderProduct->getOrderShop() === $this) {
  280. $orderProduct->setOrderShop(null);
  281. }
  282. }
  283. return $this;
  284. }
  285. /**
  286. * @return Collection|CreditHistory[]
  287. */
  288. public function getCreditHistories(): Collection
  289. {
  290. return $this->creditHistories;
  291. }
  292. public function addCreditHistory(CreditHistory $creditHistory): self
  293. {
  294. if (!$this->creditHistories->contains($creditHistory)) {
  295. $this->creditHistories[] = $creditHistory;
  296. $creditHistory->setOrderShop($this);
  297. }
  298. return $this;
  299. }
  300. public function removeCreditHistory(CreditHistory $creditHistory): self
  301. {
  302. if ($this->creditHistories->contains($creditHistory)) {
  303. $this->creditHistories->removeElement($creditHistory);
  304. // set the owning side to null (unless already changed)
  305. if ($creditHistory->getOrderShop() === $this) {
  306. $creditHistory->setOrderShop(null);
  307. }
  308. }
  309. return $this;
  310. }
  311. public function getVisitor(): ?Visitor
  312. {
  313. return $this->visitor;
  314. }
  315. public function setVisitor(?Visitor $visitor): self
  316. {
  317. $this->visitor = $visitor;
  318. return $this;
  319. }
  320. public function getDeliveryInfos(): ?string
  321. {
  322. return $this->deliveryInfos;
  323. }
  324. public function setDeliveryInfos(?string $deliveryInfos): self
  325. {
  326. $this->deliveryInfos = $deliveryInfos;
  327. return $this;
  328. }
  329. public function getOrderStatus(): ?OrderStatus
  330. {
  331. return $this->orderStatus;
  332. }
  333. public function setOrderStatusProtected(?OrderStatus $orderStatus): self
  334. {
  335. $this->orderStatus = $orderStatus;
  336. return $this;
  337. }
  338. /**
  339. * @return Collection|OrderReductionCart[]
  340. */
  341. public function getOrderReductionCarts(): Collection
  342. {
  343. return $this->orderReductionCarts;
  344. }
  345. public function addOrderReductionCart(OrderReductionCart $orderReductionCart): self
  346. {
  347. if (!$this->orderReductionCarts->contains($orderReductionCart)) {
  348. $this->orderReductionCarts[] = $orderReductionCart;
  349. $orderReductionCart->setOrderShop($this);
  350. }
  351. return $this;
  352. }
  353. public function removeOrderReductionCart(OrderReductionCart $orderReductionCart): self
  354. {
  355. if ($this->orderReductionCarts->contains($orderReductionCart)) {
  356. $this->orderReductionCarts->removeElement($orderReductionCart);
  357. // set the owning side to null (unless already changed)
  358. if ($orderReductionCart->getOrderShop() === $this) {
  359. $orderReductionCart->setOrderShop(null);
  360. }
  361. }
  362. return $this;
  363. }
  364. /**
  365. * @return Collection|OrderReductionCart[]
  366. */
  367. public function getOrderReductionCredits(): Collection
  368. {
  369. return $this->orderReductionCredits;
  370. }
  371. public function addOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  372. {
  373. if (!$this->orderReductionCredits->contains($orderReductionCredit)) {
  374. $this->orderReductionCredits[] = $orderReductionCredit;
  375. $orderReductionCredit->setOrderShop($this);
  376. }
  377. return $this;
  378. }
  379. public function removeOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  380. {
  381. if ($this->orderReductionCredits->contains($orderReductionCredit)) {
  382. $this->orderReductionCredits->removeElement($orderReductionCredit);
  383. // set the owning side to null (unless already changed)
  384. if ($orderReductionCredit->getOrderShop() === $this) {
  385. $orderReductionCredit->setOrderShop(null);
  386. }
  387. }
  388. return $this;
  389. }
  390. /**
  391. * @return Collection|Document[]
  392. */
  393. public function getDocuments(): Collection
  394. {
  395. return $this->documents;
  396. }
  397. public function addDocument(Document $document): self
  398. {
  399. if (!$this->documents->contains($document)) {
  400. $this->documents[] = $document;
  401. }
  402. return $this;
  403. }
  404. public function removeDocument(Document $document): self
  405. {
  406. if ($this->documents->contains($document)) {
  407. $this->documents->removeElement($document);
  408. }
  409. return $this;
  410. }
  411. /**
  412. * @return Collection|Ticket[]
  413. */
  414. public function getTickets(): Collection
  415. {
  416. return $this->tickets;
  417. }
  418. public function addTicket(Ticket $ticket): self
  419. {
  420. if (!$this->tickets->contains($ticket)) {
  421. $this->tickets[] = $ticket;
  422. $ticket->setOrderShop($this);
  423. }
  424. return $this;
  425. }
  426. public function removeTicket(Ticket $ticket): self
  427. {
  428. if ($this->tickets->contains($ticket)) {
  429. $this->tickets->removeElement($ticket);
  430. // set the owning side to null (unless already changed)
  431. if ($ticket->getOrderShop() === $this) {
  432. $ticket->setOrderShop(null);
  433. }
  434. }
  435. return $this;
  436. }
  437. public function isValid() {
  438. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsValid) > 0) {
  439. return true ;
  440. }
  441. return false ;
  442. }
  443. public function isCart() {
  444. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsCart) > 0) {
  445. return true ;
  446. }
  447. return false ;
  448. }
  449. }