-
Notifications
You must be signed in to change notification settings - Fork 0
/
SalesDtl.php
executable file
·132 lines (117 loc) · 3.23 KB
/
SalesDtl.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
<?php
namespace backend\models\sales;
use Yii;
use backend\models\master\Product;
use backend\models\master\Uom;
use backend\models\master\Cogs;
use backend\models\master\ProductUom;
use mdm\converter\DateConverter;
/**
* This is the model class for table "sales_dtl".
*
* @property integer $sales_id
* @property integer $product_id
* @property integer $uom_id
* @property double $qty
* @property double $price
* @property double $cogs
* @property double $discount
* @property double $total_release
*
* @property Sales $sales
* @property Product $product
*/
class SalesDtl extends \yii\db\ActiveRecord {
public $total_release;
public $fr_date;
public $to_date;
public $pname;
public $sdate;
public $faktur;
public $ctgr;
public $hari;
public $disc;
public $branch_id;
public $group_name;
public $amount;
/**
* @inheritdoc
*/
public static function tableName() {
return '{{%sales_dtl}}';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['product_id', 'uom_id', 'qty', 'price'], 'required'],
[['sales_id', 'product_id', 'uom_id'], 'integer'],
[['cogs'], 'default', 'value' => function() {
$cogs = Cogs::findOne($this->product_id);
return $cogs ? $cogs->cogs : null;
}],
[['cogs'], 'required'],
[['qty', 'price', 'cogs', 'discount', 'total_release'], 'number'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'sales_id' => 'Sales ID',
'product_id' => 'Product ID',
'uom_id' => 'Uom ID',
'qty' => 'Qty',
'price' => 'Price',
'discount' => 'Discount',
'total_release' => 'Total Release',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getSales() {
return $this->hasOne(Sales::className(), ['id' => 'sales_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProduct() {
return $this->hasOne(Product::className(), ['id' => 'product_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUom() {
return $this->hasOne(Uom::className(), ['id' => 'uom_id']);
}
/**
* @return Double
*/
public function getTotalLine() {
$post_discount = (1 - ($this->discount / 100));
return ($this->qty * $this->price) * $post_discount;
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductUom() {
return $this->hasOne(ProductUom::className(), ['product_id' => 'product_id', 'uom_id' => 'uom_id']);
}
public function behaviors() {
return[
[
'class' => DateConverter::className(),
'type' => 'date', // 'date', 'time', 'datetime'
'logicalFormat' => 'php:d-m-Y',
'attributes' => [
'FrDate' => 'fr_date', // date is original attribute
'ToDate' => 'to_date', // date is original attribute
'SDate' => 'sdate', // date is original attribute
]
]
];
}
}