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\providers; |
12
|
|
|
|
13
|
|
|
use Yii; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FormulaExamplesProvider. |
17
|
|
|
* |
18
|
|
|
* @author Dmytro Naumenko <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class FormulaExamplesProvider |
21
|
|
|
{ |
22
|
|
|
public function getGroups() |
23
|
|
|
{ |
24
|
|
|
$result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Fixed discount'), $this->fixedDiscountFormulas()); |
|
|
|
|
25
|
|
|
$result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Growing discount'), $this->growingDiscountFormulas()); |
26
|
|
|
$result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Leasing'), $this->leasingFormulas()); |
27
|
|
|
$result[] = $this->groupOf(Yii::t('hipanel.finance.price', 'Monthly Cap'), $this->leasingFormulas()); |
28
|
|
|
|
29
|
|
|
return $result; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private function fixedDiscountFormulas() |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
sprintf("discount.fixed('10%%').since('%s').reason('because')", date('m.Y')), |
36
|
|
|
sprintf("discount.fixed('11 USD').since('%s').reason('agreed')", date('m.Y')), |
37
|
|
|
sprintf("discount.fixed('20%%').till('%s').reason('loyalty')", date('m.Y', strtotime('+6 months'))), |
38
|
|
|
sprintf("discount.fixed('5 tb').since('%s').reason('bonus')", date('m.Y')) => Yii::t('hipanel.finance.price', 'Applicable for overuse prices. The example will compensate up to 5 TB of overuse as discount. Make sure to use appropriate unit, such as <code>items</code>, <code>gbps</code> or <code>hours</code>.'), |
39
|
|
|
sprintf("discount.fixed('5 tb').as('deposit,compensation').since('%s').reason('bonus')", date('m.Y')) => Yii::t('hipanel.finance.price', 'Applicable for overuse prices. Will compensate up to 5 TB of overuse as a separate Compensation bill. You can use any other bill type in option <code>.as()</code>, such as <code>deposit,creditnote</code> or <code>correction,positive</code>.'), |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function growingDiscountFormulas() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
sprintf("discount.since('%s').grows('10pp').every('month').reason('because')", date('m.Y')) => Yii::t('hipanel.finance.price', '<code>10pp</code> means "10 percent points". A percent point is the arithmetic difference of two percentages. For example, moving up from 40% to 50% is a 10 percentage point increase, but is an actual 25% percent increase in what is being measured.'), |
47
|
|
|
sprintf("discount.since('%s').grows('10%%').every('month').max('100%%').reason('because')", date('m.Y')), |
48
|
|
|
sprintf("discount.since('%s').grows('20 USD').every('2 months').min('30 USD').max('80 USD')", date('m.Y')), |
49
|
|
|
sprintf("discount.since('%s').grows('1%%').every('1 months').min('5%%').max('25%%')", date('m.Y')), |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function leasingFormulas() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
sprintf("leasing.since('%s').lasts('3 months').reason('TEST')", date('m.Y')), |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function mpnthlyCapFomulas() |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
|
|
"cap.monthly('28 days')" => Yii::t('hipanel.finance.price', |
64
|
|
|
'The given formula is useful only for monthly prices. When the monthly invoice consumption exceeds the given cap, two charges will be produced: first at the price amount for 28 days, and second for 0 cents for the rest days of month.' |
65
|
|
|
), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function groupOf($name, $formulas) |
70
|
|
|
{ |
71
|
|
|
return ['name' => $name, 'formulas' => $formulas]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.