creditHistorySolver = $this->loadService(CreditHistorySolver::class); } public function instanciate( 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->id_producer = $producer->id; $creditHistory->populateRelation('producer', $producer); $creditHistory->id_user = $user->id; $creditHistory->populateRelation('user', $user); $creditHistory->id_user_action = $userAction->id; $creditHistory->populateRelation('userAction', $userAction); if($order) { $creditHistory->id_order = $order->id; $creditHistory->populateRelation('order', $order); } if($meanPayment) { $creditHistory->mean_payment = $meanPayment; } return $creditHistory; } // saveCreditHistory public function create( 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->instanciate($type, $amount, $producer, $user, $userAction, $meanPayment, $order); // Initialisation du commentaire avant sauvegarde $creditHistory->setComment($creditHistory->getComment() . $this->creditHistorySolver->getStrComment($creditHistory)); $creditHistory->save(); // Mise à jour du crédit au niveau de UserProducer // @TODO : à gérer avec les événements //$this->userProducerBuilder->updateCredit($creditHistory); return $creditHistory; } }