255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'id_user' => 'Utilisateur', 'id_user_action' => 'Utilisateur', 'id_commande' => 'Commande', 'date' => 'Date', 'montant' => 'Montant', 'type' => 'Type', 'id_etablissement' => 'Établissement', 'moyen_paiement' => 'Moyen de paiement', ]; } public function getUser() { return $this->hasOne(User::className(),['id' => 'id_user']) ; } public function getUserAction() { return $this->hasOne(User::className(),['id' => 'id_user_action']) ; } public function getCommande() { return $this->hasOne(Commande::className(),['id' => 'id_commande']) ; } public function getLibelleType() { if($this->type == 'paiement') return 'Paiement' ; elseif($this->type == 'remboursement') return 'Remboursement' ; } public function save($runValidation = true, $attributeNames = NULL) { parent::save($runValidation, $attributeNames) ; $user_etablissement = UserEtablissement::findOne([ 'id_user' => $this->id_user, 'id_etablissement' => $this->id_etablissement ]) ; if($user_etablissement) { if($this->type == self::TYPE_CREDIT || $this->type == self::TYPE_CREDIT_INITIAL || $this->type == self::TYPE_REMBOURSEMENT) { $user_etablissement->credit += $this->montant ; $user_etablissement->save() ; } elseif($this->type == self::TYPE_PAIEMENT) { $user_etablissement->credit -= $this->montant ; } $user_etablissement->save() ; } } }