|
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) { |
|
|
|
|
|
|
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
|
|
|
|
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@propertyannotation to your class or interface to document the existence of this variable.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.