creditHistorySolver = $this->loadService(CreditHistorySolver::class); } public function instanciateCreditHistory( string $type, float $amount, Producer $producer, User $user, User $userAction, string $meanPayment = null, Order $order = null ): CreditHistory { $creditHistory = new CreditHistory; $creditHistory->type = $type; $creditHistory->amount = round($amount, 2); $creditHistory->populateProducer($producer); $creditHistory->populateUser($user); $creditHistory->populateUserAction($userAction); if($order) { $creditHistory->populateOrder($order); } if($meanPayment) { $creditHistory->mean_payment = $meanPayment; } return $creditHistory; } // saveCreditHistory public function createCreditHistory( string $type, float $amount, Producer $producer, User $user, User $userAction, string $meanPayment = null, Order $order = null ): ?CreditHistory { if ($amount > -0.01 && $amount < 0.01) { return null; } $creditHistory = $this->instanciateCreditHistory($type, $amount, $producer, $user, $userAction, $meanPayment, $order); $creditHistory->setComment($creditHistory->getComment() . $this->creditHistorySolver->getStrComment($creditHistory)); $this->saveCreate($creditHistory); $creditHistory->trigger(CreditHistory::EVENT_CREATE, new Event(['creditHistory' => $creditHistory])); return $creditHistory; } }