Completed
Push — master ( 7131b7...0d0c35 )
by Dmitry
03:44
created

Purse::scenarioCommands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\models;
13
14
use hipanel\models\File;
15
use hipanel\modules\client\models\Contact;
16
use Yii;
17
18
class Purse extends \hipanel\base\Model
19
{
20
    use \hipanel\base\ModelTrait;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function rules()
26
    {
27
        return [
28
            [['id', 'client_id', 'seller_id'],      'integer'],
29
            [['client', 'seller'],                  'safe'],
30
            [['provided_services'],                 'safe'],
31
            [['contact_id', 'requisite_id'],        'integer'],
32
            [['currency_id'],                       'integer'],
33
            [['currency'],                          'safe'],
34
            [['no'],                                'integer'],
35
            [['credit', 'balance'],                 'number'],
36
37
            [['month'],                             'date', 'on' => 'update-monthly-invoice'],
38
            [['id', 'contact_id'],                  'required', 'on' => ['update-contact']],
39
            [['id', 'requisite_id'],                'required', 'on' => ['update-requisite']],
40
        ];
41
    }
42
43
    public function getFiles()
44
    {
45
        return $this->hasMany(File::class, ['object_id' => 'id']);
46
    }
47
48
    public function getContact()
49
    {
50
        return $this->hasOne(Contact::class, ['id' => 'contact_id']);
51
    }
52
53
    public function getRequisite()
54
    {
55
        return $this->hasOne(Contact::class, ['id' => 'requisite_id']);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function attributeLabels()
62
    {
63
        return $this->mergeAttributeLabels([
64
            'provided_services' => Yii::t('hipanel:finance', 'Provided services'),
65
            'currency'          => Yii::t('hipanel:finance', 'Currency'),
66
            'invoices'          => Yii::t('hipanel:finance', 'Invoices'),
67
        ]);
68
    }
69
70
    public function scenarioCommands()
71
    {
72
        return [
73
            'update-contact' => 'update',
74
            'update-requisite' => 'update',
75
        ];
76
    }
77
}
78