/
Transfer.php
148 lines (133 loc) · 3.42 KB
/
Transfer.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace rest\models\inventory;
use Yii;
use rest\classes\ActiveRecord;
use rest\models\master\Branch;
/**
* This is the model class for table "{{%transfer}}".
*
* @property integer $id
* @property string $number
* @property integer $branch_id
* @property integer $branch_dest_id
* @property string $date
* @property integer $status
* @property string $created_at
* @property integer $created_by
* @property string $updated_at
* @property integer $updated_by
*
* @property TransferDtl[] $items
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 3.0
*/
class Transfer extends ActiveRecord
{
const STATUS_DRAFT = 10;
const STATUS_PROCESS = 20;
const STATUS_CLOSE = 90;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%transfer}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['branch_id', 'branch_dest_id', 'date', 'items'], 'required'],
[['status'], 'default', 'value' => static::STATUS_DRAFT],
[['branch_id', 'branch_dest_id', 'status', 'created_by', 'updated_by'], 'integer'],
[['date', 'created_at', 'updated_at'], 'safe'],
[['number'], 'string', 'max' => 16]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'number' => 'Number',
'branch_id' => 'Branch ID',
'branch_dest_id' => 'Branch Dest ID',
'date' => 'Date',
'status' => 'Status',
'created_at' => 'Created At',
'created_by' => 'Created By',
'updated_at' => 'Updated At',
'updated_by' => 'Updated By',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getItems()
{
return $this->hasMany(TransferDtl::className(), ['transfer_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBranch()
{
return $this->hasOne(Branch::className(), ['id'=>'branch_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getBranchDest()
{
return $this->hasOne(Branch::className(), ['id'=>'branch_dest_id']);
}
public function getIssues()
{
return $this->hasMany(GoodsMovement::className(), ['reff_id' => 'id'])
->onCondition(['reff_type' => 300]);
}
public function getReceives()
{
return $this->hasMany(GoodsMovement::className(), ['reff_id' => 'id'])
->onCondition(['reff_type' => 400]);
}
/**
* @inheritdoc
*/
public function behaviors()
{
return[
'yii\behaviors\TimestampBehavior',
'yii\behaviors\BlameableBehavior',
[
'class' => 'mdm\autonumber\Behavior',
'digit' => 6,
'attribute' => 'number',
'value' => 'IT' . date('y.?')
],
'rest\classes\StatusConverter',
'mdm\behaviors\ar\RelationBehavior',
];
}
public function fields()
{
$fields = parent::fields();
$fields['nmStatus'] = 'nmStatus';
return $fields;
}
public function extraFields()
{
return[
'items',
'branch',
'branchDest',
'issues',
'receives',
];
}
}