Completed
Push — master ( aee475...546d98 )
by Andrii
06:36
created

Purse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 74
ccs 0
cts 54
cp 0
rs 10
c 2
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 19 1
A getFiles() 0 4 1
A getDocuments() 0 4 1
A getClientModel() 0 4 1
A getContact() 0 4 1
A getRequisite() 0 4 1
A attributeLabels() 0 10 1
A scenarioActions() 0 7 1
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\models;
12
13
use hipanel\models\File;
14
use hipanel\modules\client\models\Client;
15
use hipanel\modules\client\models\Contact;
16
use hipanel\modules\document\models\Document;
17
use Yii;
18
19
class Purse extends \hipanel\base\Model
20
{
21
    use \hipanel\base\ModelTrait;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function rules()
27
    {
28
        return [
29
            [['id', 'client_id', 'seller_id'], 'integer'],
30
            [['client', 'seller'], 'safe'],
31
            [['provided_services'], 'safe'],
32
            [['contact_id', 'requisite_id'], 'integer'],
33
            [['currency_id'], 'integer'],
34
            [['currency'], 'safe'],
35
            [['no'], 'integer'],
36
            [['credit', 'balance'], 'number'],
37
38
            [['id', 'contact_id'], 'required', 'on' => ['update-contact']],
39
            [['id', 'requisite_id'], 'required', 'on' => ['update-requisite']],
40
41
            [['month'], 'date', 'on' => 'generate-and-save-document'],
42
            [['type'], 'string', 'on' => 'generate-and-save-document'],
43
        ];
44
    }
45
46
    public function getFiles()
47
    {
48
        return $this->hasMany(File::class, ['object_id' => 'id']);
49
    }
50
51
    public function getDocuments()
52
    {
53
        return $this->hasMany(Document::class, ['object_id' => 'id']);
54
    }
55
56
    public function getClientModel()
57
    {
58
        return $this->hasOne(Client::class, ['id' => 'client_id']);
59
    }
60
61
    public function getContact()
62
    {
63
        return $this->hasOne(Contact::class, ['id' => 'contact_id']);
64
    }
65
66
    public function getRequisite()
67
    {
68
        return $this->hasOne(Contact::class, ['id' => 'requisite_id']);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function attributeLabels()
75
    {
76
        return $this->mergeAttributeLabels([
77
            'provided_services' => Yii::t('hipanel:finance', 'Provided services'),
78
            'currency' => Yii::t('hipanel:finance', 'Currency'),
79
            'invoices' => Yii::t('hipanel:finance', 'Invoices'),
80
            'contact_id' => Yii::t('hipanel:finance', 'Contact'),
81
            'requisite_id' => Yii::t('hipanel:finance', 'Requisite'),
82
        ]);
83
    }
84
85
    public function scenarioActions()
86
    {
87
        return [
88
            'update-contact' => 'update',
89
            'update-requisite' => 'update',
90
        ];
91
    }
92
}
93