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.

185 satır
5.5KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\OrderPayment;
  4. use App\Entity\OrderRefund;
  5. use App\Entity\UserMerchant;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Lc\ShopBundle\Context\OrderPaymentInterface;
  8. use Lc\ShopBundle\Context\OrderRefundInterface;
  9. use Lc\ShopBundle\Context\PayoffInterface;
  10. use Lc\ShopBundle\Context\UserMerchantInterface;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. /**
  13. * @ORM\MappedSuperclass()
  14. */
  15. abstract class CreditHistory extends AbstractEntity implements PayoffInterface
  16. {
  17. use PayoffTrait;
  18. const TYPE_CREDIT = 'credit';
  19. const TYPE_DEBIT = 'debit';
  20. /**
  21. * @ORM\Column(type="float", nullable=true)
  22. */
  23. protected $amount;
  24. /**
  25. * @ORM\Column(type="string", length=31)
  26. */
  27. protected $type;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserMerchantInterface", inversedBy="creditHistories")
  30. * @ORM\JoinColumn(nullable=false)
  31. */
  32. protected $userMerchant;
  33. /**
  34. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", cascade={"persist", "remove"})
  35. */
  36. protected $orderPayment;
  37. /**
  38. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\OrderRefundInterface", cascade={"persist", "remove"})
  39. */
  40. protected $orderRefund;
  41. /**
  42. * @Gedmo\Blameable(on="create")
  43. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  44. * @ORM\JoinColumn(nullable=true)
  45. */
  46. protected $createdBy;
  47. /**
  48. * @Gedmo\Blameable(on="update")
  49. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  50. * @ORM\JoinColumn(nullable=true)
  51. */
  52. protected $updatedBy;
  53. public function getAmount(): ?float
  54. {
  55. return $this->amount;
  56. }
  57. public function setAmount(?float $amount): self
  58. {
  59. $this->amount = $amount;
  60. return $this;
  61. }
  62. public function getAmountInherited(): float
  63. {
  64. if ($this->getOrderPayment() !== null) {
  65. return $this->getOrderPayment()->getAmount();
  66. } else if ($this->getOrderRefund() !== null) {
  67. return $this->getOrderRefund()->getAmount();
  68. } else {
  69. return $this->getAmount();
  70. }
  71. }
  72. public function getMeanPaymentInherited(): string
  73. {
  74. if ($this->getOrderPayment() !== null) {
  75. return $this->getOrderPayment()->getMeanPayment();
  76. } else if ($this->getOrderRefund() !== null) {
  77. return $this->getOrderRefund()->getMeanPayment();
  78. } else {
  79. return $this->getMeanPayment();
  80. }
  81. }
  82. public function getPaidAtInherited (): ?\DateTimeInterface
  83. {
  84. if ($this->getOrderPayment() !== null) {
  85. return $this->getOrderPayment()->getPaidAt();
  86. } else if ($this->getOrderRefund() !== null) {
  87. return $this->getOrderRefund()->getPaidAt();
  88. } else {
  89. return $this->getPaidAt();
  90. }
  91. }
  92. public function getReferenceInherited (): ?string
  93. {
  94. if ($this->getOrderPayment() !== null) {
  95. return $this->getOrderPayment()->getReference();
  96. } else if ($this->getOrderRefund() !== null) {
  97. return $this->getOrderRefund()->getReference();
  98. } else {
  99. return $this->getReference();
  100. }
  101. }
  102. public function getCommentInherited (): ?string
  103. {
  104. if ($this->getOrderPayment() !== null) {
  105. return $this->getOrderPayment()->getComment();
  106. } else if ($this->getOrderRefund() !== null) {
  107. return $this->getOrderRefund()->getComment();
  108. } else {
  109. return $this->getComment();
  110. }
  111. }
  112. public function getMeanPaymentInheritedLabel(): string
  113. {
  114. return 'field.default.meanPaymentOptions.'.$this->getMeanPaymentInherited() ;
  115. }
  116. public function getType(): ?string
  117. {
  118. return $this->type;
  119. }
  120. public function setType(string $type): self
  121. {
  122. $this->type = $type;
  123. return $this;
  124. }
  125. public function getUserMerchant(): ?UserMerchantInterface
  126. {
  127. return $this->userMerchant;
  128. }
  129. public function setUserMerchant(?UserMerchantInterface $userMerchant): self
  130. {
  131. $this->userMerchant = $userMerchant;
  132. return $this;
  133. }
  134. public function getOrderPayment(): ?OrderPaymentInterface
  135. {
  136. return $this->orderPayment;
  137. }
  138. public function setOrderPayment(?OrderPaymentInterface $orderPayment): self
  139. {
  140. $this->orderPayment = $orderPayment;
  141. return $this;
  142. }
  143. public function getOrderRefund(): ?OrderRefundInterface
  144. {
  145. return $this->orderRefund;
  146. }
  147. public function setOrderRefund(?OrderRefundInterface $orderRefund): self
  148. {
  149. $this->orderRefund = $orderRefund;
  150. return $this;
  151. }
  152. }