Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

576 linhas
18KB

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