|
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-2019, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\models\decorators\client; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\inputs\TextInput; |
|
14
|
|
|
use hipanel\modules\finance\models\decorators\AbstractResourceDecorator; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
|
|
17
|
|
|
abstract class AbstractClientResourceDecorator extends AbstractResourceDecorator |
|
18
|
|
|
{ |
|
19
|
|
|
public $resource; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct($resource) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct($resource); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function displayTitle() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->resource->getTypes()[$this->resource->type]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getPrepaidQuantity() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->resource->quantity; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getOverusePrice() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->resource->price; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function displayUnit() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->resource->unit; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function toUnit(): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->displayUnit(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function displayOverusePrice() |
|
52
|
|
|
{ |
|
53
|
|
|
return Yii::$app->formatter->asCurrency($this->getOverusePrice(), $this->resource->currency); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function displayPrepaidAmount() |
|
57
|
|
|
{ |
|
58
|
|
|
return \Yii::t('hipanel:finance:tariff', '{amount} {unit}', [ |
|
59
|
|
|
'amount' => $this->getPrepaidQuantity(), |
|
60
|
|
|
'unit' => $this->displayUnit(), |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function prepaidAmountType() |
|
65
|
|
|
{ |
|
66
|
|
|
return new TextInput(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|