No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

100 líneas
3.0KB

  1. <?php
  2. namespace common\logic\User\CreditHistory\Service;
  3. use common\helpers\MeanPayment;
  4. use common\logic\AbstractService;
  5. use common\logic\SolverInterface;
  6. use common\logic\User\CreditHistory\Model\CreditHistory;
  7. use yii\helpers\Html;
  8. class CreditHistorySolver extends AbstractService implements SolverInterface
  9. {
  10. public function isTypeDebit(CreditHistory $creditHistory): bool
  11. {
  12. return in_array($creditHistory->getType(), [
  13. CreditHistory::TYPE_DEBIT,
  14. CreditHistory::TYPE_PAYMENT,
  15. ]);
  16. }
  17. public function isTypeCredit(CreditHistory $creditHistory): bool
  18. {
  19. return in_array($creditHistory->getType(), [
  20. CreditHistory::TYPE_CREDIT,
  21. CreditHistory::TYPE_INITIAL_CREDIT,
  22. CreditHistory::TYPE_REFUND
  23. ]);
  24. }
  25. public function getAmount(CreditHistory $creditHistory, bool $format = false): string
  26. {
  27. if ($format) {
  28. return number_format($creditHistory->getAmount(), 2) . '&nbsp;€';
  29. } else {
  30. return $creditHistory->getAmount();
  31. }
  32. }
  33. /**
  34. * Retourne le libellé du CreditHistory informant de son type et
  35. * éventuellement de la date de sa commande associée.
  36. *
  37. */
  38. public function getStrWording(CreditHistory $creditHistory): string
  39. {
  40. $str = '';
  41. $type = $creditHistory->getType();
  42. if (CreditHistory::TYPE_INITIAL_CREDIT == $type) {
  43. $str = 'Crédit initial';
  44. } elseif (CreditHistory::TYPE_CREDIT == $type) {
  45. $str = 'Crédit';
  46. } elseif (CreditHistory::TYPE_PAYMENT == $type) {
  47. $str = 'Paiement';
  48. } elseif (CreditHistory::TYPE_REFUND == $type) {
  49. $str = 'Remboursement';
  50. } elseif (CreditHistory::TYPE_DEBIT == $type) {
  51. $str = 'Débit';
  52. }
  53. if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) {
  54. $order = $creditHistory->getOrderObject();
  55. if ($order && $order->distribution) {
  56. $str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
  57. } else {
  58. $str .= '<br />Commande supprimée';
  59. }
  60. }
  61. return $str;
  62. }
  63. public function getDate(CreditHistory $creditHistory, bool $format = false): string
  64. {
  65. $date = $creditHistory->getDate();
  66. if ($format) {
  67. return date('d/m/Y à H:i:s', strtotime($date));
  68. } else {
  69. return $date;
  70. }
  71. }
  72. public function getStrMeanPayment(CreditHistory $creditHistory): string
  73. {
  74. return MeanPayment::getStrBy($creditHistory->getMeanPayment());
  75. }
  76. // strUserAction
  77. public function getStrUserAction(CreditHistory $creditHistory): string
  78. {
  79. $userAction = $creditHistory->getUserActionObject();
  80. if ($userAction) {
  81. return $userAction->getName() . ' ' . $userAction->getlastname();
  82. } else {
  83. return 'Système';
  84. }
  85. }
  86. }