1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Billing Library |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/php-billing |
6
|
|
|
* @package php-billing |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\charge; |
12
|
|
|
|
13
|
|
|
use hiqdev\php\billing\bill\Bill; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Andrii Vasyliev <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class Generalizer implements GeneralizerInterface |
19
|
|
|
{ |
20
|
1 |
|
public function createBill(ChargeInterface $charge) |
21
|
|
|
{ |
22
|
1 |
|
return new Bill( |
23
|
1 |
|
null, |
24
|
1 |
|
$this->generalizeType($charge), |
25
|
1 |
|
$this->generalizeTime($charge), |
26
|
1 |
|
$this->generalizeSum($charge), |
27
|
1 |
|
$this->generalizeQuantity($charge), |
28
|
1 |
|
$this->generalizeCustomer($charge), |
29
|
1 |
|
$this->generalizeTarget($charge), |
30
|
1 |
|
$this->generalizePlan($charge), |
31
|
1 |
|
[$charge] |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function generalizeType(ChargeInterface $charge) |
36
|
|
|
{ |
37
|
1 |
|
return $charge->getPrice()->getType(); |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
public function generalizeTime(ChargeInterface $charge) |
41
|
|
|
{ |
42
|
1 |
|
return $charge->getAction()->getTime()->modify('first day of this month midnight'); |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public function generalizeSum(ChargeInterface $charge) |
46
|
|
|
{ |
47
|
1 |
|
return $charge->getSum(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public function generalizeQuantity(ChargeInterface $charge) |
51
|
|
|
{ |
52
|
1 |
|
return $charge->getUsage(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
public function generalizeCustomer(ChargeInterface $charge) |
56
|
|
|
{ |
57
|
1 |
|
return $charge->getAction()->getCustomer(); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function generalizeTarget(ChargeInterface $charge) |
61
|
|
|
{ |
62
|
1 |
|
return $charge->getAction()->getTarget(); |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
public function generalizePlan(ChargeInterface $charge) |
66
|
|
|
{ |
67
|
1 |
|
return $charge->getPrice()->getPlan(); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|