Completed
Push — master ( 0272da...851765 )
by Andrii
08:55
created

Purse::getFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 getInvoices()
57
    {
58
        return $this->getDocumentsOfType('invoice');
59
    }
60
61
    public function getAcceptances()
62
    {
63
        return $this->getDocumentsOfType('acceptance');
64
    }
65
66
    public function getDocumentsOfType($type)
67
    {
68
        $res = [];
69
        foreach ($this->documents as $id => $doc) {
0 ignored issues
show
Documentation introduced by
The property documents does not exist on object<hipanel\modules\finance\models\Purse>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
70
            if ($doc->type === $type) {
71
                $res[$id] = $doc;
72
            }
73
        }
74
75
        return $res;
76
    }
77
78
    public function getClientModel()
79
    {
80
        return $this->hasOne(Client::class, ['id' => 'client_id']);
81
    }
82
83
    public function getContact()
84
    {
85
        return $this->hasOne(Contact::class, ['id' => 'contact_id']);
86
    }
87
88
    public function getRequisite()
89
    {
90
        return $this->hasOne(Contact::class, ['id' => 'requisite_id']);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function attributeLabels()
97
    {
98
        return $this->mergeAttributeLabels([
99
            'provided_services' => Yii::t('hipanel:finance', 'Provided services'),
100
            'currency' => Yii::t('hipanel:finance', 'Currency'),
101
            'invoices' => Yii::t('hipanel:finance', 'Invoices'),
102
            'contact_id' => Yii::t('hipanel:finance', 'Contact'),
103
            'requisite_id' => Yii::t('hipanel:finance', 'Requisite'),
104
        ]);
105
    }
106
107
    public function scenarioActions()
108
    {
109
        return [
110
            'update-contact' => 'update',
111
            'update-requisite' => 'update',
112
        ];
113
    }
114
}
115