Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

518 lines
16KB

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