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-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
namespace hiqdev\php\billing\action; |
11
|
|
|
|
12
|
|
|
use DateTimeImmutable; |
13
|
|
|
use hiqdev\php\billing\customer\CustomerInterface; |
14
|
|
|
use hiqdev\php\billing\sale\SaleInterface; |
15
|
|
|
use hiqdev\php\billing\target\TargetInterface; |
16
|
|
|
use hiqdev\php\billing\type\TypeInterface; |
17
|
|
|
use hiqdev\php\units\QuantityInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class TemporaryAction represents an action, that is generated for |
21
|
|
|
* runtime-only purposes such as, but not limited to: |
22
|
|
|
* |
23
|
|
|
* - Extending primary action with TemporaryActions, that represent client billing hierarchy |
24
|
|
|
* |
25
|
|
|
* Actions of this class MUST NOT be saved into the database and SHOULD be used |
26
|
|
|
* only for runtime calculations. |
27
|
|
|
* |
28
|
|
|
* @author Dmytro Naumenko <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class TemporaryAction extends Action |
31
|
|
|
{ |
32
|
|
|
private function __construct( |
33
|
|
|
$id, |
34
|
|
|
TypeInterface $type, |
35
|
|
|
TargetInterface $target, |
36
|
|
|
QuantityInterface $quantity, |
37
|
|
|
CustomerInterface $customer, |
38
|
|
|
DateTimeImmutable $time, |
39
|
|
|
SaleInterface $sale = null, |
40
|
|
|
ActionState $state = null, |
41
|
|
|
ActionInterface $parent = null |
42
|
|
|
) { |
43
|
|
|
parent::__construct($id, $type, $target, $quantity, $customer, $time, $sale, $state, $parent); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Creates Temporary Action out of generic $action |
48
|
|
|
* |
49
|
|
|
* @param ActionInterface $action |
50
|
|
|
* @param CustomerInterface $customer |
51
|
|
|
* @return TemporaryAction |
52
|
|
|
*/ |
53
|
|
|
public static function createAsSubaction(ActionInterface $action, CustomerInterface $customer): TemporaryAction |
54
|
|
|
{ |
55
|
|
|
return new self( |
56
|
|
|
null, |
57
|
|
|
$action->getType(), |
58
|
|
|
$action->getTarget(), |
59
|
|
|
$action->getQuantity(), |
60
|
|
|
$customer, |
61
|
|
|
$action->getTime(), |
62
|
|
|
null, |
63
|
|
|
$action->getState(), |
64
|
|
|
$action |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|