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.

617 Zeilen
16KB

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