|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\models; |
|
4
|
|
|
|
|
5
|
|
|
use hipanel\modules\finance\logic\bill\QuantityTrait; |
|
6
|
|
|
use Yii; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Charge |
|
10
|
|
|
* |
|
11
|
|
|
* @author Dmytro Naumenko <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @property int $id |
|
14
|
|
|
* @property string $unit |
|
15
|
|
|
* @property string $quantity |
|
16
|
|
|
* @property int $parent_id |
|
17
|
|
|
* @property string $type |
|
18
|
|
|
* @property string $name |
|
19
|
|
|
* @property string $ftype |
|
20
|
|
|
* @property string $currency |
|
21
|
|
|
* @property float $sum |
|
22
|
|
|
* @property int object_id |
|
23
|
|
|
* @property int common_object_id |
|
24
|
|
|
* @property string common_object_name |
|
25
|
|
|
*/ |
|
26
|
|
|
class Charge extends \hiqdev\hiart\ActiveRecord |
|
27
|
|
|
{ |
|
28
|
|
|
use QuantityTrait; |
|
29
|
|
|
|
|
30
|
|
|
const SCENARIO_CREATE = 'create'; |
|
31
|
|
|
const SCENARIO_UPDATE = 'update'; |
|
32
|
|
|
|
|
33
|
|
|
private $isNewRecord; |
|
34
|
|
|
|
|
35
|
|
|
public function rules() |
|
36
|
|
|
{ |
|
37
|
|
|
return [ |
|
38
|
|
|
[['id', 'type_id', 'object_id', 'bill_id', 'parent_id', 'common_object_id'], 'integer'], |
|
39
|
|
|
[['class', 'name', 'unit', 'common_object_name'], 'string'], |
|
40
|
|
|
[['type', 'label', 'ftype', 'time', 'type_label', 'currency'], 'safe'], |
|
41
|
|
|
[['sum', 'quantity'], 'number'], |
|
42
|
|
|
[['unit'], 'default', 'value' => 'items', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
|
43
|
|
|
[['object_id', 'sum', 'type', 'quantity', 'unit'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
|
44
|
|
|
[['id'], 'safe', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]] |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function attributeLabels() |
|
49
|
|
|
{ |
|
50
|
|
|
return array_merge(parent::attributeLabels(), [ |
|
51
|
|
|
'sum' => Yii::t('hipanel', 'Sum'), |
|
52
|
|
|
'type' => Yii::t('hipanel', 'Type'), |
|
53
|
|
|
'quantity' => Yii::t('hipanel', 'Quantity'), |
|
54
|
|
|
'label' => Yii::t('hipanel', 'Description'), |
|
55
|
|
|
'time' => Yii::t('hipanel', 'Time'), |
|
56
|
|
|
'object_id' => Yii::t('hipanel', 'Object'), |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function markAsNotNew() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->isNewRecord = false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getIsNewRecord() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->isNewRecord !== false && parent::getIsNewRecord(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function typeLabel(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return Yii::t('hipanel.finance.priceTypes', \yii\helpers\Inflector::titleize($this->type)); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function isMonthly(): bool |
|
76
|
|
|
{ |
|
77
|
|
|
return strpos($this->ftype, 'monthly,') === 0; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|