add transfer-moneymovement
This commit is contained in:
25
common/components/AccountAwareBehavior.php
Normal file
25
common/components/AccountAwareBehavior.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use yii\base\Behavior;
|
||||
use common\models\Account;
|
||||
|
||||
class AccountAwareBehavior extends Behavior{
|
||||
|
||||
|
||||
public function getAccountName(){
|
||||
$result = "";
|
||||
$account = $this->owner->account;
|
||||
if (isset($account)){
|
||||
$result = $account->name;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getAccount(){
|
||||
return $this->owner->hasOne( Account::className(), ["id_account" =>"id_account" ] ) ;
|
||||
}
|
||||
|
||||
}
|
||||
25
common/components/UserAwareBehavior.php
Normal file
25
common/components/UserAwareBehavior.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use yii\base\Behavior;
|
||||
use common\models\User;
|
||||
|
||||
class UserAwareBehavior extends Behavior{
|
||||
|
||||
|
||||
public function getUserName(){
|
||||
$result = "";
|
||||
$user = $this->owner->user;
|
||||
if (isset($user)){
|
||||
$result = $user->username;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getUser(){
|
||||
return $this->owner->hasOne( User::className(), ["id" =>"id_user" ] ) ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use common\components\AccountAwareBehavior;
|
||||
use common\components\UserAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "money_movement".
|
||||
@@ -19,6 +23,7 @@ use Yii;
|
||||
*/
|
||||
class MoneyMovement extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -27,15 +32,34 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
return 'money_movement';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
],
|
||||
[
|
||||
'class' => AccountAwareBehavior::className(),
|
||||
],
|
||||
[
|
||||
'class' => UserAwareBehavior::className(),
|
||||
],
|
||||
], parent::behaviors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_account', 'id_user', 'name', 'type', 'money', 'created_at', 'updated_at'], 'required'],
|
||||
[['id_account', 'id_user', 'name', 'type', 'money'], 'required'],
|
||||
[['id_account', 'id_user', 'type', 'money'], 'integer'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['name'], 'string', 'max' => 64],
|
||||
[['comment'], 'string', 'max' => 255]
|
||||
];
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace common\models;
|
||||
use Yii;
|
||||
use yii\base\Object;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use common\components\AccountAwareBehavior;
|
||||
use common\components\UserAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "transfer".
|
||||
@@ -25,18 +28,40 @@ use yii\helpers\ArrayHelper;
|
||||
* @property string $comment
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property integer $direction
|
||||
*/
|
||||
class Transfer extends \yii\db\ActiveRecord
|
||||
class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
|
||||
const TYPE_PRODUCT = 10;
|
||||
const TYPE_TICKET = 20;
|
||||
const TYPE_MONEY_MOVEMENT_OUT = 30; //MONEY OUT FROM ACCOUNT
|
||||
|
||||
const STATUS_NOT_PAID = 10;
|
||||
const STATUS_PAID = 20;
|
||||
|
||||
const DIRECTION_IN = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY )
|
||||
const DIRECTION_OUT = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY )
|
||||
const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY )
|
||||
const DIRECTION_IN = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY )
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
],
|
||||
// [
|
||||
// 'class' => AccountAwareBehavior::className(),
|
||||
// ],
|
||||
// [
|
||||
// 'class' => UserAwareBehavior::className(),
|
||||
// ],
|
||||
], parent::behaviors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -318,4 +343,6 @@ class Transfer extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user