您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

619 行
17KB

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