255], [['comment'], 'string', 'max' => 2048], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id_user' => 'Utilisateur', 'id_user_action' => 'Utilisateur', 'date' => 'Date', 'amount' => 'Montant', 'type' => 'Type', 'id_producer' => 'Producteur', 'mean_payment' => 'Moyen de paiement', 'comment' => 'Commentaire', 'send_mail' => 'Prévenir l\'utilisateur', ]; } /** * Enregistre un modèle CreditHistorique. */ public function save() { $userManager = UserManager::getInstance(); $userProducerManager = UserProducerManager::getInstance(); $paymentManager = PaymentManager::getInstance(); if ($this->validate()) { $user = $userManager->findOneUserById($this->id_user); $paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userManager->getCurrent(), $this->comment); // on prévient l'utilisateur que son compte vient d'être crédité if($this->send_mail) { $producer = GlobalParam::getCurrentProducer() ; $userProducer = $userProducerManager->findOneUserProducer($user); \Yii::$app->mailerService->sendFromProducer( 'Mouvement de crédit', 'creditUser', [ 'user' => $user, 'producer' => $producer, 'userProducer' => $userProducer, 'creditForm' => $this ], $user->email, $producer ); } } } }