|
- <?php
-
-
-
- namespace backend\models;
-
- use common\helpers\GlobalParam;
- use common\logic\Payment\Module\PaymentModule;
- use common\logic\Producer\Producer\Module\ProducerModule;
- use common\logic\User\User\Module\UserModule;
- use common\logic\User\UserProducer\Module\UserProducerModule;
- use yii\base\Model;
-
-
- class CreditForm extends Model
- {
-
- public $id_user ;
- public $id_user_action ;
- public $id_producer ;
- public $type ;
- public $amount ;
- public $mean_payment ;
- public $comment ;
- public $send_mail = 1;
-
-
-
- public function rules()
- {
- return [
- [['amount'], 'required'],
- [['id_user', 'id_user_action', 'id_producer'], 'integer'],
- [['date','send_mail'], 'safe'],
- [['amount'], 'double'],
- [['type', 'mean_payment'], 'string', 'max' => 255],
- [['comment'], 'string', 'max' => 2048],
- ];
- }
-
-
-
- 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',
- ];
- }
-
-
-
- public function save()
- {
- $userModule = UserModule::getInstance();
- $userProducerModule = UserProducerModule::getInstance();
- $paymentManager = PaymentModule::getInstance();
-
- if ($this->validate()) {
- $user = $userModule->findOneUserById($this->id_user);
- $paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userModule->getCurrent(), $this->comment);
-
-
- if($this->send_mail) {
- $producer = GlobalParam::getCurrentProducer() ;
- $userProducer = $userProducerModule->findOneUserProducer($user);
-
- \Yii::$app->mailerService->sendFromProducer(
- 'Mouvement de crédit',
- 'creditUser',
- [
- 'user' => $user,
- 'producer' => $producer,
- 'userProducer' => $userProducer,
- 'creditForm' => $this
- ],
- $user->email,
- $producer
- );
- }
- }
- }
-
- }
|