add changes to backend transfers2

This commit is contained in:
2015-10-20 09:02:57 +02:00
parent 71384b6453
commit 1a1477b26b
14 changed files with 174 additions and 61 deletions

View File

@@ -7,6 +7,8 @@ use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use common\components\AccountAwareBehavior;
use common\components\UserAwareBehavior;
use yii\base\Object;
use common\models\Transfer;
/**
* This is the model class for table "money_movement".
@@ -23,6 +25,10 @@ use common\components\UserAwareBehavior;
*/
class MoneyMovement extends \yii\db\ActiveRecord
{
const TYPE_OUT = 10;
public $_account;
/**
* @inheritdoc
@@ -58,13 +64,22 @@ class MoneyMovement extends \yii\db\ActiveRecord
public function rules()
{
return [
[['id_account', 'id_user', 'name', 'type', 'money'], 'required'],
[['id_account', 'id_user', 'type', 'money'], 'integer'],
[['id_account', 'name', 'money'], 'required'],
[['id_account' , 'money'], 'integer'],
[['name'], 'string', 'max' => 64],
[['comment'], 'string', 'max' => 255]
[['comment'], 'string', 'max' => 255],
[['id_account'], 'validateAccount'],
];
}
public function validateAccount($attribute,$params){
$this->_account = Account::findOne(['id_account' => $this->id_account] );
if ( !isset( $this->_account ) ){
$this->addError($attribute, Yii::t('common/money-movement', 'Invalid account!'));
}
}
/**
* @inheritdoc
*/
@@ -82,4 +97,19 @@ class MoneyMovement extends \yii\db\ActiveRecord
'updated_at' => Yii::t('common/money-movement', 'Updated At'),
];
}
public function afterSave($insert, $changedAttributes){
parent::afterSave($insert, $changedAttributes);
if ( $insert) {
$this->createTransfer();
}
}
protected function createTransfer(){
$transfer = Transfer::createMoneyMovementOutTransfer($this->_account, $this);
$transfer->id_user = Yii::$app->user->id;
$transfer->save();
}
}