@@ -402,14 +402,17 @@ class UserController extends BackendController | |||
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | |||
$paymentContainer->getUtils() | |||
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $user); | |||
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $this->getUserCurrent()); | |||
if($creditForm->send_mail) { | |||
$paymentContainer->getNotifier() | |||
->notifyUserCreditMovement($user, $creditForm->type, $creditForm->amount); | |||
if(!$user->email) { | |||
$this->addFlash('error', "L'utilisateur n'a pas pu être prévenu car son adresse email n'est pas définie."); | |||
} | |||
} | |||
$this->setFlash('success', 'Crédit mis à jour.'); | |||
$this->addFlash('success', 'Crédit mis à jour.'); | |||
return $this->refresh(); | |||
} |
@@ -18,21 +18,27 @@ class PaymentNotifier extends AbstractNotifier | |||
public function notifyUserCreditMovement(User $user, string $type, float $amount) | |||
{ | |||
$producer = $this->getProducerContext(); | |||
$credit = $this->userRepository->getCredit($user, true); | |||
$this->mailer->sendFromProducer( | |||
'Mouvement de crédit', | |||
'creditUser', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'credit' => $credit, | |||
'type' => $type, | |||
'amount' => $amount | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
if($user->email) { | |||
$producer = $this->getProducerContext(); | |||
$credit = $this->userRepository->getCredit($user, true); | |||
$this->mailer->sendFromProducer( | |||
'Mouvement de crédit', | |||
'creditUser', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'credit' => $credit, | |||
'type' => $type, | |||
'amount' => $amount | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
return true; | |||
} | |||
return false; | |||
} | |||
} |