You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OrderShop.php 17KB

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