Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

OrderShopModel.php 17KB

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