forked from yiisoft/yii2-app-advanced
/
TransferHdr.php
162 lines (148 loc) · 4.35 KB
/
TransferHdr.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace biz\models;
use Yii;
/**
* This is the model class for table "transfer_hdr".
*
* @property integer $id_transfer
* @property string $transfer_num
* @property integer $id_warehouse_source
* @property integer $id_warehouse_dest
* @property string $transfer_date
* @property string $receive_date
* @property integer $status
* @property string $create_date
* @property integer $create_by
* @property string $update_date
* @property integer $update_by
*
* @property string $nmStatus
* @property string $transferDate
* @property string $receiveDate
*
* @property Warehouse $idWarehouseSource
* @property Warehouse $idWarehouseDest
* @property TransferDtl[] $transferDtls
* @property TransferNoticeDtl[] $transferNoticeDtls
* @property Product[] $idProducts
* @property TransferNotice $transferNotice
*/
class TransferHdr extends \yii\db\ActiveRecord
{
const STATUS_DRAFT = 1;
const STATUS_ISSUE = 2;
const STATUS_DRAFT_RECEIVE = 3;
const STATUS_CONFIRM = 4;
const STATUS_CONFIRM_REJECT = 5;
const STATUS_CONFIRM_APPROVE = 6;
const STATUS_RECEIVE = 7;
const SCENARIO_RECEIVE = 'receive';
/**
* @inheritdoc
*/
public static function tableName()
{
return 'transfer_hdr';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_warehouse_source', 'id_warehouse_dest', 'transferDate', 'status'], 'required'],
[['receiveDate'], 'required', 'on' => [static::SCENARIO_RECEIVE]],
[['id_warehouse_source', 'id_warehouse_dest', 'status'], 'integer'],
[['transfer_date', 'receive_date'], 'safe']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_transfer' => 'Id Transfer',
'transfer_num' => 'Transfer Num',
'id_warehouse_source' => 'Id Warehouse Source',
'id_warehouse_dest' => 'Id Warehouse Dest',
'transfer_date' => 'Transfer Date',
'receive_date' => 'Receive Date',
'status' => 'Status',
'create_date' => 'Create Date',
'create_by' => 'Create By',
'update_date' => 'Update Date',
'update_by' => 'Update By',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdWarehouseSource()
{
return $this->hasOne(Warehouse::className(), ['id_warehouse' => 'id_warehouse_source']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdWarehouseDest()
{
return $this->hasOne(Warehouse::className(), ['id_warehouse' => 'id_warehouse_dest']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTransferDtls()
{
return $this->hasMany(TransferDtl::className(), ['id_transfer' => 'id_transfer'])
->orderBy([new \yii\db\Expression('transfer_qty_send=0 ASC')]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdProducts()
{
return $this->hasMany(Product::className(), ['id_product' => 'id_product'])->viaTable('transfer_dtl', ['id_transfer' => 'id_transfer']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTransferNotice()
{
return $this->hasOne(TransferNotice::className(), ['id_transfer' => 'id_transfer']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTransferNoticeDtls()
{
return $this->hasMany(TransferNoticeDtl::className(), ['id_transfer' => 'id_transfer'])->viaTable('transfer_notice', ['id_transfer' => 'id_transfer']);
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'biz\behaviors\AutoTimestamp',
'biz\behaviors\AutoUser',
[
'class' => 'mdm\autonumber\Behavior',
'digit' => 4,
'group' => 'transfer',
'attribute' => 'transfer_num',
'value' => 'IN' . date('y.?')
],
[
'class' => 'biz\behaviors\DateConverter',
'attributes' => [
'transferDate' => 'transfer_date',
'receiveDate' => 'receive_date'
]
],
[
'class'=>'biz\behaviors\StatusBehavior'
]
];
}
}