Completed
Push — master ( f7bdb9...8d2b6e )
by Andrii
10:42
created

displayOverusePrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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