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

43 lines
1.3KB

  1. <?php
  2. namespace common\logic\User\CreditHistory;
  3. use common\logic\BaseService;
  4. use common\logic\BuilderInterface;
  5. use common\logic\User\UserProducer\UserProducerBuilder;
  6. class CreditHistoryBuilder extends BaseService implements BuilderInterface
  7. {
  8. protected CreditHistorySolver $creditHistorySolver;
  9. protected UserProducerBuilder $userProducerBuilder;
  10. public function __construct()
  11. {
  12. $this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
  13. $this->userProducerBuilder = $this->loadService(UserProducerBuilder::class);
  14. }
  15. public function instanciate(): CreditHistory
  16. {
  17. $creditHistory = new CreditHistory();
  18. return $creditHistory;
  19. }
  20. public function save(CreditHistory $creditHistory): bool
  21. {
  22. if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) {
  23. return false;
  24. }
  25. // Initialisation du commentaire avant sauvegarde
  26. $creditHistory->setComment($creditHistory->getComment() . $this->creditHistorySolver->getStrComment($creditHistory));
  27. $creditHistory->save();
  28. // Mise à jour du crédit au niveau de UserProducer
  29. $this->userProducerBuilder->updateCredit($creditHistory);
  30. return true;
  31. }
  32. }