1 | <?php |
||
12 | class InvoiceBuilder |
||
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 OcrTools Tools for validating and creating ocr numbers |
||
38 | */ |
||
39 | private $ocrTools; |
||
40 | |||
41 | /** |
||
42 | * @var ItemBasket Container of charged items |
||
43 | */ |
||
44 | private $itemBasket; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTimeImmutable 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 |
|
131 | |||
132 | /** |
||
133 | * Set seller |
||
134 | */ |
||
135 | 8 | public function setSeller(AgentInterface $seller): self |
|
140 | |||
141 | /** |
||
142 | * Get seller |
||
143 | * |
||
144 | * @throws Exception If seller is not set |
||
145 | */ |
||
146 | 6 | public function getSeller(): AgentInterface |
|
153 | |||
154 | /** |
||
155 | * Set buyer |
||
156 | */ |
||
157 | 8 | public function setBuyer(AgentInterface $buyer): self |
|
162 | |||
163 | /** |
||
164 | * Get buyer |
||
165 | * |
||
166 | * @throws Exception If buyer is not set |
||
167 | */ |
||
168 | 6 | public function getBuyer(): AgentInterface |
|
175 | |||
176 | /** |
||
177 | * Set invoice reference number |
||
178 | */ |
||
179 | 1 | public function setOcr(string $ocr): self |
|
185 | |||
186 | /** |
||
187 | * Generate invoice reference number from serial number |
||
188 | */ |
||
189 | 1 | public function generateOcr(): self |
|
194 | |||
195 | /** |
||
196 | * Add billable to invoice |
||
197 | */ |
||
198 | 1 | public function addItem(Billable $billable): self |
|
203 | |||
204 | /** |
||
205 | * Set date of invoice creation |
||
206 | */ |
||
207 | 1 | public function setBillDate(\DateTimeImmutable $date): self |
|
212 | |||
213 | /** |
||
214 | * Set number of days before invoice expires |
||
215 | */ |
||
216 | 1 | public function setExpiresAfter(int $nrOfDays): self |
|
221 | |||
222 | /** |
||
223 | * Set deduction (amount prepaid) |
||
224 | */ |
||
225 | 1 | public function setDeduction(Amount $deduction): self |
|
230 | } |
||
231 |