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.

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