forked from hiqdev/hipanel-module-stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartSellForm.php
52 lines (44 loc) · 1.45 KB
/
PartSellForm.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
<?php
namespace hipanel\modules\stock\forms;
use hipanel\modules\stock\models\Part;
use Yii;
class PartSellForm extends Part
{
public function attributes()
{
return array_merge(parent::attributes(), ['contact_id', 'time', 'sums', 'client_id', 'description', 'ids', 'bill_id', 'reason']);
}
public function rules()
{
return array_merge(parent::rules(), [
[['contact_id', 'time', 'currency'], 'required'],
[['bill_id'], 'integer'],
[['client_id', 'contact_id'], 'integer'],
[['description'], 'string'],
[['ids'], 'each', 'rule' => ['integer']],
[['sums'], 'each', 'rule' => ['required']],
[['sums'], 'each', 'rule' => ['number']],
[['reason'], 'string'],
]);
}
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), [
'time' => Yii::t('hipanel:stock', 'Sell datetime'),
'contact_id' => Yii::t('hipanel', 'Contact'),
'description' => Yii::t('hipanel', 'Description'),
'bill_id' => Yii::t('hipanel', 'Bill'),
'reason' => Yii::t('hipanel', 'Reason'),
]);
}
public function getTotalSum(): float
{
$result = 0;
if (!empty($this->sums)) {
foreach ($this->sums as $sum) {
$result += is_numeric($sum) ? (float)$sum : 0;
}
}
return $result;
}
}