1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace byrokrat\billing; |
6
|
|
|
|
7
|
|
|
use byrokrat\amount\Amount; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Generic invoice container object |
11
|
|
|
*/ |
12
|
|
|
class Invoice |
13
|
|
|
{ |
14
|
|
|
use AttributesTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string Invoice serial number |
18
|
|
|
*/ |
19
|
|
|
private $serial; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var AgentInterface Registered seller |
23
|
|
|
*/ |
24
|
|
|
private $seller; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var AgentInterface Registered buyer |
28
|
|
|
*/ |
29
|
|
|
private $buyer; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string Payment reference number |
33
|
|
|
*/ |
34
|
|
|
private $ocr; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ItemBasket Container for charged items |
38
|
|
|
*/ |
39
|
|
|
private $itemBasket = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \DateTimeImmutable Creation date |
43
|
|
|
*/ |
44
|
|
|
private $billDate; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var integer Number of days before invoice expires |
48
|
|
|
*/ |
49
|
|
|
private $expiresAfter; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Amount Prepaid amound to deduct |
53
|
|
|
*/ |
54
|
|
|
private $deduction; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Construct invoice |
58
|
|
|
* |
59
|
|
|
* @param string $serial Invoice serial number |
60
|
|
|
* @param AgentInterface $seller Registered seller |
61
|
|
|
* @param AgentInterface $buyer Registered buyer |
62
|
|
|
* @param string $message Invoice message |
|
|
|
|
63
|
|
|
* @param string $ocr Payment reference number |
64
|
|
|
* @param ItemBasket $itemBasket Container for charged items |
65
|
|
|
* @param \DateTimeImmutable $billDate Date of invoice creation |
66
|
|
|
* @param integer $expiresAfter Nr of days before invoice expires |
67
|
|
|
* @param Amount $deduction Prepaid amound to deduct |
68
|
|
|
*/ |
69
|
15 |
|
public function __construct( |
70
|
|
|
string $serial, |
71
|
|
|
AgentInterface $seller, |
72
|
|
|
AgentInterface $buyer, |
73
|
|
|
string $ocr = '', |
74
|
|
|
ItemBasket $itemBasket = null, |
75
|
|
|
\DateTimeImmutable $billDate = null, |
76
|
|
|
int $expiresAfter = 30, |
77
|
|
|
Amount $deduction = null |
78
|
|
|
) { |
79
|
15 |
|
$this->serial = $serial; |
80
|
15 |
|
$this->seller = $seller; |
81
|
15 |
|
$this->buyer = $buyer; |
82
|
15 |
|
$this->itemBasket = $itemBasket; |
83
|
15 |
|
$this->ocr = $ocr; |
84
|
15 |
|
$this->billDate = $billDate ?: new \DateTimeImmutable; |
85
|
15 |
|
$this->expiresAfter = $expiresAfter; |
86
|
15 |
|
$this->deduction = $deduction; |
87
|
15 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get invoice serial number |
91
|
|
|
*/ |
92
|
1 |
|
public function getSerial(): string |
93
|
|
|
{ |
94
|
1 |
|
return $this->serial; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get seller |
99
|
|
|
*/ |
100
|
1 |
|
public function getSeller(): AgentInterface |
101
|
|
|
{ |
102
|
1 |
|
return $this->seller; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get buyer |
107
|
|
|
*/ |
108
|
1 |
|
public function getBuyer(): AgentInterface |
109
|
|
|
{ |
110
|
1 |
|
return $this->buyer; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get invoice reference number |
115
|
|
|
*/ |
116
|
4 |
|
public function getOcr(): string |
117
|
|
|
{ |
118
|
4 |
|
return $this->ocr; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get item container |
123
|
|
|
*/ |
124
|
4 |
|
public function getItems(): ItemBasket |
125
|
|
|
{ |
126
|
4 |
|
return $this->itemBasket; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get charged amount (including VAT and deduction) |
131
|
|
|
*/ |
132
|
3 |
|
public function getInvoiceTotal(): Amount |
133
|
|
|
{ |
134
|
3 |
|
return $this->getItems()->getTotalCost()->subtract($this->getDeduction()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get date of invoice creation |
139
|
|
|
*/ |
140
|
3 |
|
public function getBillDate(): \DateTimeImmutable |
141
|
|
|
{ |
142
|
3 |
|
return $this->billDate; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get number of days before invoice expires |
147
|
|
|
*/ |
148
|
1 |
|
public function getExpiresAfter(): int |
149
|
|
|
{ |
150
|
1 |
|
return $this->expiresAfter; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get date when invoice expires |
155
|
|
|
*/ |
156
|
1 |
|
public function getExpirationDate(): \DateTimeImmutable |
157
|
|
|
{ |
158
|
1 |
|
return $this->billDate->add(new \DateInterval("P{$this->getExpiresAfter()}D")); |
159
|
|
|
$expireDate = clone $this->billDate; |
|
|
|
|
160
|
|
|
$expireDate->add(new \DateInterval("P{$this->getExpiresAfter()}D")); |
161
|
|
|
|
162
|
|
|
return $expireDate; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get prepaid amound to deduct |
167
|
|
|
*/ |
168
|
5 |
|
public function getDeduction(): Amount |
169
|
|
|
{ |
170
|
5 |
|
if (!isset($this->deduction)) { |
171
|
1 |
|
return $this->itemBasket->createCurrencyObject('0'); |
172
|
|
|
} |
173
|
|
|
|
174
|
4 |
|
return $this->deduction; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.