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.

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