forked from yiisoft/yii2-app-advanced
/
Coa.php
129 lines (117 loc) · 2.96 KB
/
Coa.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace biz\models;
use Yii;
/**
* This is the model class for table "coa".
*
* @property integer $id_coa
* @property integer $id_coa_parent
* @property string $cd_account
* @property string $nm_account
* @property integer $coa_type
* @property string $normal_balance
* @property string $create_date
* @property integer $create_by
* @property string $update_date
* @property integer $update_by
* @property string $nmCoaType
*
* @property GlDetail[] $glDetails
* @property EntriSheetDtl[] $entriSheetDtls
* @property Coa $idCoaParent
* @property Coa[] $coas
*/
class Coa extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'coa';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['cd_account', 'nm_account', 'coa_type', 'normal_balance'], 'required'],
[['id_coa_parent'], 'safe'],
[['cd_account'], 'string', 'max' => 16],
[['cd_account'], 'checkCoaCode'],
[['nm_account'], 'string', 'max' => 64],
[['normal_balance'], 'string', 'max' => 1]
];
}
public function checkCoaCode($attribute)
{
$coa = $this->idCoaParent;
if($coa && strpos($this->$attribute, rtrim($coa->cd_account,'0'))!==0){
$this->addError($attribute, 'Code Account prefix invalid');
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_coa' => 'Id Coa',
'id_coa_parent' => 'Id Coa Parent',
'cd_account' => 'Cd Account',
'nm_account' => 'Nm Account',
'coa_type' => 'Coa Type',
'normal_balance' => 'Normal Balance',
'create_date' => 'Create Date',
'create_by' => 'Create By',
'update_date' => 'Update Date',
'update_by' => 'Update By',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getGlDetails()
{
return $this->hasMany(GlDetail::className(), ['id_coa' => 'id_coa']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getEntriSheetDtls()
{
return $this->hasMany(EntriSheetDtl::className(), ['id_coa' => 'id_coa']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdCoaParent()
{
return $this->hasOne(Coa::className(), ['id_coa' => 'id_coa_parent']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCoas()
{
return $this->hasMany(Coa::className(), ['id_coa_parent' => 'id_coa']);
}
/**
* @return string
*/
public function getNmCoaType()
{
return \biz\tools\Helper::getCoaType()[$this->coa_type];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'biz\behaviors\AutoTimestamp',
'biz\behaviors\AutoUser',
];
}
}