Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

194 lines
5.0KB

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