You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1KB

  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 save(CreditHistoryModel $creditHistory): bool
  16. {
  17. if ($creditHistory->getAmount() > -0.01 && $creditHistory->getAmount() < 0.01) {
  18. return false;
  19. }
  20. // Initialisation du commentaire avant sauvegarde
  21. $creditHistory->setComment($creditHistory->getComment() . $this->creditHistorySolver->getStrComment($creditHistory));
  22. $creditHistory->save();
  23. // Mise à jour du crédit au niveau de UserProducer
  24. $this->userProducerBuilder->updateCredit($creditHistory);
  25. return true;
  26. }
  27. }