Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PaymentSolver.php 4.1KB

10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
9 месяцев назад
9 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace domain\Payment;
  3. use common\helpers\MeanPayment;
  4. use domain\Order\Order\Order;
  5. use domain\_\AbstractService;
  6. use domain\_\SolverInterface;
  7. class PaymentSolver extends AbstractService implements SolverInterface
  8. {
  9. public function isTypeDebit(Payment $payment): bool
  10. {
  11. return in_array($payment->getType(), [
  12. Payment::TYPE_DEBIT,
  13. Payment::TYPE_PAYMENT,
  14. ]);
  15. }
  16. public function isTypeCredit(Payment $payment): bool
  17. {
  18. return in_array($payment->getType(), [
  19. Payment::TYPE_CREDIT,
  20. Payment::TYPE_INITIAL_CREDIT,
  21. Payment::TYPE_REFUND
  22. ]);
  23. }
  24. public function sumAmountPaid(Payment $payment, float $amount = 0)
  25. {
  26. if($this->isTypeDebit($payment)) {
  27. $amount += $payment->amount;
  28. }
  29. else {
  30. $amount -= $payment->amount;
  31. }
  32. return $amount;
  33. }
  34. public function getAmount(Payment $payment, bool $format = false): string
  35. {
  36. if ($format) {
  37. return number_format($payment->getAmount(), 2, ',', ' ') . '&nbsp;€';
  38. } else {
  39. return $payment->getAmount();
  40. }
  41. }
  42. /**
  43. * Retourne le libellé du CreditHistory informant de son type et
  44. * éventuellement de la date de sa commande associée.
  45. *
  46. */
  47. public function getStrWording(Payment $payment, Order $order = null): string
  48. {
  49. $str = '';
  50. $type = $payment->getType();
  51. if (Payment::TYPE_INITIAL_CREDIT == $type) {
  52. $str = 'Crédit initial cagnotte';
  53. } elseif (Payment::TYPE_CREDIT == $type) {
  54. $str = 'Crédit cagnotte';
  55. } elseif (Payment::TYPE_PAYMENT == $type) {
  56. $str = 'Paiement';
  57. } elseif (Payment::TYPE_REFUND == $type) {
  58. $str = 'Remboursement';
  59. } elseif (Payment::TYPE_DEBIT == $type) {
  60. $str = 'Débit cagnotte';
  61. }
  62. if (Payment::TYPE_PAYMENT == $type || Payment::TYPE_REFUND == $type) {
  63. // Optimisation
  64. if(!$order) {
  65. $order = $payment->order;
  66. }
  67. if ($order && $order->distribution) {
  68. //$str .= '<br /><small>commande du <a href="'.\Yii::$app->urlManager->createUrl(['distribution/index', 'date' => $order->distribution->date]).'">' . date('d/m/Y', strtotime($order->distribution->date)).'</a></small>';
  69. $str .= '<br /><small>Commande du ' . date('d/m/Y', strtotime($order->distribution->date)).'</small>';
  70. } else {
  71. $str .= '<br /><small>Commande supprimée</small>';
  72. }
  73. }
  74. return $str;
  75. }
  76. public function getDate(Payment $payment, bool $format = false): string
  77. {
  78. $date = $payment->getDate();
  79. if ($format) {
  80. return date('d/m/Y à H:i:s', strtotime($date));
  81. } else {
  82. return $date;
  83. }
  84. }
  85. public function isMeanPaymentCredit(Payment $payment): bool
  86. {
  87. return $payment->mean_payment == MeanPayment::CREDIT;
  88. }
  89. public function isMeanPayment(Payment $payment, string $meanPayment): bool
  90. {
  91. return $payment->mean_payment == $meanPayment;
  92. }
  93. public function getStrMeanPayment(Payment $payment): string
  94. {
  95. return MeanPayment::getStrBy($payment->getMeanPayment());
  96. }
  97. public function getStrType(Payment $payment): string
  98. {
  99. switch($payment->type) {
  100. case Payment::TYPE_PAYMENT:
  101. return 'Paiement';
  102. case Payment::TYPE_DEBIT:
  103. return 'Débit';
  104. case Payment::TYPE_CREDIT:
  105. return 'Crédit';
  106. case Payment::TYPE_REFUND:
  107. return 'Remboursement';
  108. case Payment::TYPE_INITIAL_CREDIT:
  109. return 'Crédit initial';
  110. }
  111. return 'Type de paiement inconnu';
  112. }
  113. public function getStrUserAction(Payment $payment): string
  114. {
  115. $userAction = $payment->getUserActionObject();
  116. if ($userAction) {
  117. return $userAction->getName() . ' ' . $userAction->getlastname();
  118. } else {
  119. return 'Système';
  120. }
  121. }
  122. }