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.

CreditHistoryBuilder.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace common\logic\User\CreditHistory\Service;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\Order\Order\Model\Order;
  5. use common\logic\Order\Order\Service\OrderSolver;
  6. use common\logic\Producer\Producer\Model\Producer;
  7. use common\logic\User\CreditHistory\Model\CreditHistory;
  8. use common\logic\User\User\Model\User;
  9. use yii\base\Event;
  10. class CreditHistoryBuilder extends AbstractBuilder
  11. {
  12. protected CreditHistorySolver $creditHistorySolver;
  13. protected OrderSolver $orderSolver;
  14. public function loadDependencies(): void
  15. {
  16. $this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
  17. $this->orderSolver = $this->loadService(OrderSolver::class);
  18. }
  19. public function instanciateCreditHistory(
  20. string $type,
  21. float $amount,
  22. Producer $producer,
  23. User $user,
  24. User $userAction,
  25. string $meanPayment = null,
  26. Order $order = null
  27. ): CreditHistory
  28. {
  29. $creditHistory = new CreditHistory;
  30. $creditHistory->type = $type;
  31. $creditHistory->amount = round($amount, 2);
  32. $creditHistory->populateProducer($producer);
  33. $creditHistory->populateUser($user);
  34. $creditHistory->populateUserAction($userAction);
  35. if($order) {
  36. $creditHistory->populateOrder($order);
  37. }
  38. if($meanPayment) {
  39. $creditHistory->mean_payment = $meanPayment;
  40. }
  41. return $creditHistory;
  42. }
  43. // saveCreditHistory
  44. public function createCreditHistory(
  45. string $type,
  46. float $amount,
  47. Producer $producer,
  48. User $user,
  49. User $userAction,
  50. string $meanPayment = null,
  51. Order $order = null
  52. ): ?CreditHistory
  53. {
  54. if ($amount > -0.01 && $amount < 0.01) {
  55. return null;
  56. }
  57. $creditHistory = $this->instanciateCreditHistory($type, $amount, $producer, $user, $userAction, $meanPayment, $order);
  58. $creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($creditHistory));
  59. $this->create($creditHistory);
  60. return $creditHistory;
  61. }
  62. }