Completed
Push — master ( 80ef37...72ea33 )
by Dmitry
06:10
created

Charge   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 4
dl 0
loc 49
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 12 1
A attributeLabels() 0 11 1
A markAsNotNew() 0 4 1
A getIsNewRecord() 0 4 2
A typeLabel() 0 4 1
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
 */
21
class Charge extends \hiqdev\hiart\ActiveRecord
22
{
23
    use QuantityTrait;
24
25
    const SCENARIO_CREATE = 'create';
26
    const SCENARIO_UPDATE = 'update';
27
28
    private $isNewRecord;
29
30
    public function rules()
31
    {
32
        return [
33
            [['id', 'type_id', 'object_id', 'bill_id', 'parent_id'], 'integer'],
34
            [['class', 'name', 'unit'], 'string'],
35
            [['type', 'label', 'ftype', 'time', 'type_label', 'currency'], 'safe'],
36
            [['sum', 'quantity'], 'number'],
37
            [['unit'], 'default', 'value' => 'items', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
38
            [['object_id', 'sum', 'type', 'quantity', 'unit'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
39
            [['id'], 'safe', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]]
40
        ];
41
    }
42
43
    public function attributeLabels()
44
    {
45
        return array_merge(parent::attributeLabels(), [
46
            'sum' => Yii::t('hipanel', 'Sum'),
47
            'type' => Yii::t('hipanel', 'Type'),
48
            'quantity' => Yii::t('hipanel', 'Quantity'),
49
            'label' => Yii::t('hipanel', 'Description'),
50
            'time' => Yii::t('hipanel', 'Time'),
51
            'object_id' => Yii::t('hipanel', 'Object'),
52
        ]);
53
    }
54
55
    public function markAsNotNew()
56
    {
57
        $this->isNewRecord = false;
58
    }
59
60
    public function getIsNewRecord()
61
    {
62
        return $this->isNewRecord !== false && parent::getIsNewRecord();
63
    }
64
65
    public function typeLabel(): string
66
    {
67
        return Yii::t('hipanel.finance.priceTypes', \yii\helpers\Inflector::titleize($this->type));
68
    }
69
}
70