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.

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, CreditHistoryInterface
  16. {
  17. use PayoffTrait;
  18. const TYPE_CREDIT = 'credit';
  19. const TYPE_DEBIT = 'debit';
  20. const MEAN_PAYMENT_CREDIT_CARD = 'cb';
  21. const MEAN_PAYMENT_CHEQUE = 'cheque';
  22. const MEAN_PAYMENT_CREDIT = 'credit';
  23. const MEAN_PAYMENT_TRANSFER = 'transfer';
  24. const MEAN_PAYMENT_CASH = 'cash';
  25. const MEAN_PAYMENT_GIFT = 'transfer-gift';
  26. /**
  27. * @ORM\Column(type="float", nullable=true)
  28. */
  29. protected $amount;
  30. /**
  31. * @ORM\Column(type="string", length=31)
  32. */
  33. protected $type;
  34. /**
  35. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\User\UserMerchantInterface", inversedBy="creditHistories")
  36. * @ORM\JoinColumn(nullable=false)
  37. */
  38. protected $userMerchant;
  39. /**
  40. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderPaymentInterface", cascade={"persist", "remove"})
  41. */
  42. protected $orderPayment;
  43. /**
  44. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderRefundInterface", cascade={"persist", "remove"})
  45. */
  46. protected $orderRefund;
  47. public function __toString(){
  48. //Todo a écrire
  49. return $this->getType();
  50. }
  51. public function getAmount(): ?float
  52. {
  53. return $this->amount;
  54. }
  55. public function setAmount(?float $amount): self
  56. {
  57. $this->amount = $amount;
  58. return $this;
  59. }
  60. public function getAmountInherited(): float
  61. {
  62. if ($this->getOrderPayment() !== null) {
  63. return $this->getOrderPayment()->getAmount();
  64. } else {
  65. if ($this->getOrderRefund() !== null) {
  66. return $this->getOrderRefund()->getAmount();
  67. } else {
  68. return $this->getAmount();
  69. }
  70. }
  71. }
  72. public function getMeanPaymentInherited(): string
  73. {
  74. if ($this->getOrderPayment() !== null) {
  75. return $this->getOrderPayment()->getMeanPayment();
  76. } else {
  77. if ($this->getOrderRefund() !== null) {
  78. return $this->getOrderRefund()->getMeanPayment();
  79. } else {
  80. return $this->getMeanPayment();
  81. }
  82. }
  83. }
  84. public function getPaidAtInherited(): ?\DateTimeInterface
  85. {
  86. if ($this->getOrderPayment() !== null) {
  87. return $this->getOrderPayment()->getPaidAt();
  88. } else {
  89. if ($this->getOrderRefund() !== null) {
  90. return $this->getOrderRefund()->getPaidAt();
  91. } else {
  92. return $this->getPaidAt();
  93. }
  94. }
  95. }
  96. public function getReferenceInherited(): ?string
  97. {
  98. if ($this->getOrderPayment() !== null) {
  99. return $this->getOrderPayment()->getReference();
  100. } else {
  101. if ($this->getOrderRefund() !== null) {
  102. return $this->getOrderRefund()->getReference();
  103. } else {
  104. return $this->getReference();
  105. }
  106. }
  107. }
  108. public function getCommentInherited(): ?string
  109. {
  110. if ($this->getOrderPayment() !== null) {
  111. return $this->getOrderPayment()->getComment();
  112. } else {
  113. if ($this->getOrderRefund() !== null) {
  114. return $this->getOrderRefund()->getComment();
  115. } else {
  116. return $this->getComment();
  117. }
  118. }
  119. }
  120. public function getMeanPaymentInheritedLabel(): string
  121. {
  122. return 'field.default.meanPaymentOptions.' . $this->getMeanPaymentInherited();
  123. }
  124. public function getType(): ?string
  125. {
  126. return $this->type;
  127. }
  128. public function setType(string $type): self
  129. {
  130. $this->type = $type;
  131. return $this;
  132. }
  133. public function getUserMerchant(): ?UserMerchantInterface
  134. {
  135. return $this->userMerchant;
  136. }
  137. public function setUserMerchant(?UserMerchantInterface $userMerchant): self
  138. {
  139. $this->userMerchant = $userMerchant;
  140. return $this;
  141. }
  142. public function getOrderPayment(): ?OrderPaymentInterface
  143. {
  144. return $this->orderPayment;
  145. }
  146. public function setOrderPayment(?OrderPaymentInterface $orderPayment): self
  147. {
  148. $this->orderPayment = $orderPayment;
  149. return $this;
  150. }
  151. public function getOrderRefund(): ?OrderRefundInterface
  152. {
  153. return $this->orderRefund;
  154. }
  155. public function setOrderRefund(?OrderRefundInterface $orderRefund): self
  156. {
  157. $this->orderRefund = $orderRefund;
  158. return $this;
  159. }
  160. }