1 | <?php |
||
12 | class InvoiceBuilder |
||
13 | { |
||
14 | use AttributesTrait; |
||
15 | |||
16 | /** |
||
17 | * @var OcrTools Tools for validating and creating ocr numbers |
||
18 | */ |
||
19 | private $ocrTools; |
||
20 | |||
21 | /** |
||
22 | * @var string Invoice serial number |
||
23 | */ |
||
24 | private $serial; |
||
25 | |||
26 | /** |
||
27 | * @var ?AgentInterface Registered seller |
||
28 | */ |
||
29 | private $seller; |
||
30 | |||
31 | /** |
||
32 | * @var ?AgentInterface Registered buyer |
||
33 | */ |
||
34 | private $buyer; |
||
35 | |||
36 | /** |
||
37 | * @var string Payment reference number |
||
38 | */ |
||
39 | private $ocr; |
||
40 | |||
41 | /** |
||
42 | * @var ItemBasket Container of charged items |
||
43 | */ |
||
44 | private $itemBasket; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTimeInterface Invoice creation date |
||
48 | */ |
||
49 | private $billDate; |
||
50 | |||
51 | /** |
||
52 | * @var int Number of days before invoice expires |
||
53 | */ |
||
54 | private $expiresAfter; |
||
55 | |||
56 | /** |
||
57 | * @var ?Amount Prepaid amound to deduct |
||
58 | */ |
||
59 | private $deduction; |
||
60 | |||
61 | /** |
||
62 | * Reset values at construct |
||
63 | */ |
||
64 | 8 | public function __construct(OcrTools $ocrTools = null) |
|
69 | |||
70 | /** |
||
71 | * Reset builder values |
||
72 | */ |
||
73 | 8 | public function reset(): self |
|
86 | |||
87 | /** |
||
88 | * Build invoice |
||
89 | */ |
||
90 | 5 | public function buildInvoice(): Invoice |
|
109 | |||
110 | /** |
||
111 | * Set invoice serial number |
||
112 | */ |
||
113 | 8 | public function setSerial(string $serial): self |
|
118 | |||
119 | /** |
||
120 | * Get invoice serial number |
||
121 | * |
||
122 | * @throws Exception If serial is not set |
||
123 | */ |
||
124 | 6 | public function getSerial(): string |
|
132 | |||
133 | /** |
||
134 | * Set seller |
||
135 | */ |
||
136 | 8 | public function setSeller(AgentInterface $seller): self |
|
141 | |||
142 | /** |
||
143 | * Get seller |
||
144 | * |
||
145 | * @throws Exception If seller is not set |
||
146 | */ |
||
147 | 6 | public function getSeller(): AgentInterface |
|
155 | |||
156 | /** |
||
157 | * Set buyer |
||
158 | */ |
||
159 | 8 | public function setBuyer(AgentInterface $buyer): self |
|
164 | |||
165 | /** |
||
166 | * Get buyer |
||
167 | * |
||
168 | * @throws Exception If buyer is not set |
||
169 | */ |
||
170 | 6 | public function getBuyer(): AgentInterface |
|
178 | |||
179 | /** |
||
180 | * Set invoice reference number |
||
181 | */ |
||
182 | 1 | public function setOcr(string $ocr): self |
|
187 | |||
188 | /** |
||
189 | * Generate invoice reference number from serial number |
||
190 | */ |
||
191 | 1 | public function generateOcr(): self |
|
196 | |||
197 | /** |
||
198 | * Add billable to invoice |
||
199 | */ |
||
200 | 1 | public function addItem(Billable $billable): self |
|
205 | |||
206 | /** |
||
207 | * Set date of invoice creation |
||
208 | */ |
||
209 | 1 | public function setBillDate(\DateTimeInterface $date): self |
|
214 | |||
215 | /** |
||
216 | * Set number of days before invoice expires |
||
217 | */ |
||
218 | 1 | public function setExpiresAfter(int $nrOfDays): self |
|
223 | |||
224 | /** |
||
225 | * Set deduction (amount prepaid) |
||
226 | */ |
||
227 | 1 | public function setDeduction(Amount $deduction): self |
|
232 | } |
||
233 |