Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

194 lines
5.1KB

  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\Extension\BlameableNullableTrait;
  11. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  12. /**
  13. * @ORM\MappedSuperclass()
  14. */
  15. abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffInterface
  16. {
  17. use PayoffTrait;
  18. use BlameableNullableTrait;
  19. const TYPE_CREDIT = 'credit';
  20. const TYPE_DEBIT = 'debit';
  21. const MEAN_PAYMENT_CREDIT_CARD = 'cb';
  22. const MEAN_PAYMENT_CHEQUE = 'cheque';
  23. const MEAN_PAYMENT_CREDIT = 'credit';
  24. const MEAN_PAYMENT_TRANSFER = 'transfer';
  25. const MEAN_PAYMENT_CASH = 'cash';
  26. const MEAN_PAYMENT_GIFT = 'transfer-gift';
  27. /**
  28. * @ORM\Column(type="float", nullable=true)
  29. */
  30. protected $amount;
  31. /**
  32. * @ORM\Column(type="string", length=31)
  33. */
  34. protected $type;
  35. /**
  36. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\User\UserMerchantInterface", inversedBy="creditHistories")
  37. * @ORM\JoinColumn(nullable=false)
  38. */
  39. protected $userMerchant;
  40. /**
  41. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderPaymentInterface", cascade={"persist", "remove"})
  42. */
  43. protected $orderPayment;
  44. /**
  45. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderRefundInterface", cascade={"persist", "remove"})
  46. */
  47. protected $orderRefund;
  48. public function __toString(){
  49. //Todo a écrire
  50. return $this->getType();
  51. }
  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. }