1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Model\Invoice; |
6
|
|
|
|
7
|
|
|
use Billogram\Model\CreatableFromArray; |
8
|
|
|
use Billogram\Model\Customer\Customer; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Invoice implements CreatableFromArray |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $id; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
private $invoiceNo; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
private $ocrNumber; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Customer |
32
|
|
|
*/ |
33
|
|
|
private $customer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Billogram\Model\Invoice\Item[] |
37
|
|
|
*/ |
38
|
|
|
private $items; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var |
42
|
|
|
*/ |
43
|
|
|
private $invoiceDate; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var \DateTime |
47
|
|
|
*/ |
48
|
|
|
private $dueDate; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
private $dueDays; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
private $invoiceFee; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
private $invoiceFeeVat; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var int |
67
|
|
|
*/ |
68
|
|
|
private $reminderFee; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
private $interestRate; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var int |
77
|
|
|
*/ |
78
|
|
|
private $interestFee; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
private $currency; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var AdditionalInformation |
87
|
|
|
*/ |
88
|
|
|
private $info; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var RegionalInformation |
92
|
|
|
*/ |
93
|
|
|
private $regionalSweden; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var string |
97
|
|
|
*/ |
98
|
|
|
private $deliveryMethod; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var string |
102
|
|
|
*/ |
103
|
|
|
private $state; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
*/ |
108
|
|
|
private $url; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var array |
112
|
|
|
*/ |
113
|
|
|
private $flags; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var EventData |
117
|
|
|
*/ |
118
|
|
|
private $events; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var int |
122
|
|
|
*/ |
123
|
|
|
private $remainingSum; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var int |
127
|
|
|
*/ |
128
|
|
|
private $totalSum; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var int |
132
|
|
|
*/ |
133
|
|
|
private $roundingValue; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var bool |
137
|
|
|
*/ |
138
|
|
|
private $automaticReminders = true; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var AutomaticReminder[] |
142
|
|
|
*/ |
143
|
|
|
private $automaticRemindersSettings; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var int |
147
|
|
|
*/ |
148
|
|
|
private $reminderCount; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var \DateTime |
152
|
|
|
*/ |
153
|
|
|
private $createdAt; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var \DateTime |
157
|
|
|
*/ |
158
|
|
|
private $attestedAt; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @var \DateTime |
162
|
|
|
*/ |
163
|
|
|
private $updateAt; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @var BillogramCallback |
167
|
|
|
*/ |
168
|
|
|
private $callbacks; |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @var DetailedSums |
172
|
|
|
*/ |
173
|
|
|
private $detailedSums; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @var string |
177
|
|
|
*/ |
178
|
|
|
private $attachment; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @var ReminderCollection |
182
|
|
|
*/ |
183
|
|
|
private $automaticCollection; |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getId(): string |
189
|
|
|
{ |
190
|
|
|
return $this->id; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $id |
195
|
|
|
* |
196
|
|
|
* @return Invoice |
197
|
|
|
*/ |
198
|
|
|
public function withId(string $id) |
199
|
|
|
{ |
200
|
|
|
$new = clone $this; |
201
|
|
|
$new->id = $id; |
202
|
|
|
|
203
|
|
|
return $new; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return int |
208
|
|
|
*/ |
209
|
|
|
public function getInvoiceNo(): int |
210
|
|
|
{ |
211
|
|
|
return $this->invoiceNo; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param int $invoiceNo |
216
|
|
|
* |
217
|
|
|
* @return Invoice |
218
|
|
|
*/ |
219
|
|
|
public function withInvoiceNo(int $invoiceNo) |
220
|
|
|
{ |
221
|
|
|
$new = clone $this; |
222
|
|
|
$new->invoiceNo = $invoiceNo; |
223
|
|
|
|
224
|
|
|
return $new; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return int |
229
|
|
|
*/ |
230
|
|
|
public function getOcrNumber(): int |
231
|
|
|
{ |
232
|
|
|
return $this->ocrNumber; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param int $ocrNumber |
237
|
|
|
* |
238
|
|
|
* @return Invoice |
239
|
|
|
*/ |
240
|
|
|
public function withOcrNumber(int $ocrNumber) |
241
|
|
|
{ |
242
|
|
|
$new = clone $this; |
243
|
|
|
$new->ocrNumber = $ocrNumber; |
244
|
|
|
|
245
|
|
|
return $new; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return Customer |
250
|
|
|
*/ |
251
|
|
|
public function getCustomer(): Customer |
252
|
|
|
{ |
253
|
|
|
return $this->customer; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @param Customer $customer |
258
|
|
|
* |
259
|
|
|
* @return Invoice |
260
|
|
|
*/ |
261
|
2 |
|
public function withCustomer(Customer $customer) |
262
|
|
|
{ |
263
|
2 |
|
$new = clone $this; |
264
|
2 |
|
$new->customer = $customer; |
265
|
|
|
|
266
|
2 |
|
return $new; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return \Billogram\Model\Invoice\Item[] |
271
|
|
|
*/ |
272
|
|
|
public function getItems(): array |
273
|
|
|
{ |
274
|
|
|
return $this->items; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param \Billogram\Model\Invoice\Item[] $items |
279
|
|
|
* |
280
|
|
|
* @return Invoice |
281
|
|
|
*/ |
282
|
2 |
|
public function withItems(array $items) |
283
|
|
|
{ |
284
|
2 |
|
$new = clone $this; |
285
|
2 |
|
$new->items = $items; |
286
|
|
|
|
287
|
2 |
|
return $new; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return int |
292
|
|
|
*/ |
293
|
|
|
public function getInvoiceDate(): int |
294
|
|
|
{ |
295
|
|
|
return $this->invoiceDate; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @param string $invoiceDate |
300
|
|
|
* |
301
|
|
|
* @return Invoice |
302
|
|
|
*/ |
303
|
2 |
|
public function withInvoiceDate(string $invoiceDate) |
304
|
|
|
{ |
305
|
2 |
|
$new = clone $this; |
306
|
2 |
|
$new->invoiceDate = $invoiceDate; |
307
|
|
|
|
308
|
2 |
|
return $new; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return \DateTime |
313
|
|
|
*/ |
314
|
|
|
public function getDueDate(): \DateTime |
315
|
|
|
{ |
316
|
|
|
return $this->dueDate; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @param \DateTime $dueDate |
321
|
|
|
* |
322
|
|
|
* @return Invoice |
323
|
|
|
*/ |
324
|
|
|
public function withDueDate(\DateTime $dueDate) |
325
|
|
|
{ |
326
|
|
|
$new = clone $this; |
327
|
|
|
$new->dueDate = $dueDate; |
328
|
|
|
|
329
|
|
|
return $new; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @return int |
334
|
|
|
*/ |
335
|
|
|
public function getDueDays(): int |
336
|
|
|
{ |
337
|
|
|
return $this->dueDays; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param int $dueDays |
342
|
|
|
* |
343
|
|
|
* @return Invoice |
344
|
|
|
*/ |
345
|
|
|
public function withDueDays(int $dueDays) |
346
|
|
|
{ |
347
|
|
|
$new = clone $this; |
348
|
|
|
$new->dueDays = $dueDays; |
349
|
|
|
|
350
|
|
|
return $new; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @return int |
355
|
|
|
*/ |
356
|
|
|
public function getInvoiceFee(): int |
357
|
|
|
{ |
358
|
|
|
return $this->invoiceFee; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @param int $invoiceFee |
363
|
|
|
* |
364
|
|
|
* @return Invoice |
365
|
|
|
*/ |
366
|
|
|
public function withInvoiceFee(int $invoiceFee) |
367
|
|
|
{ |
368
|
|
|
$new = clone $this; |
369
|
|
|
$new->invoiceFee = $invoiceFee; |
370
|
|
|
|
371
|
|
|
return $new; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* @return int |
376
|
|
|
*/ |
377
|
|
|
public function getInvoiceFeeVat(): int |
378
|
|
|
{ |
379
|
|
|
return $this->invoiceFeeVat; |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @param int $invoiceFeeVat |
384
|
|
|
* |
385
|
|
|
* @return Invoice |
386
|
|
|
*/ |
387
|
|
|
public function withInvoiceFeeVat(int $invoiceFeeVat) |
388
|
|
|
{ |
389
|
|
|
$new = clone $this; |
390
|
|
|
$new->invoiceFeeVat = $invoiceFeeVat; |
391
|
|
|
|
392
|
|
|
return $new; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @return int |
397
|
|
|
*/ |
398
|
|
|
public function getReminderFee(): int |
399
|
|
|
{ |
400
|
|
|
return $this->reminderFee; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @param int $reminderFee |
405
|
|
|
* |
406
|
|
|
* @return Invoice |
407
|
|
|
*/ |
408
|
|
|
public function withReminderFee(int $reminderFee) |
409
|
|
|
{ |
410
|
|
|
$new = clone $this; |
411
|
|
|
$new->reminderFee = $reminderFee; |
412
|
|
|
|
413
|
|
|
return $new; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @return int |
418
|
|
|
*/ |
419
|
|
|
public function getInterestRate(): int |
420
|
|
|
{ |
421
|
|
|
return $this->interestRate; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @param int $interestRate |
426
|
|
|
* |
427
|
|
|
* @return Invoice |
428
|
|
|
*/ |
429
|
|
|
public function withInterestRate(int $interestRate) |
430
|
|
|
{ |
431
|
|
|
$new = clone $this; |
432
|
|
|
$new->interestRate = $interestRate; |
433
|
|
|
|
434
|
|
|
return $new; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* @return int |
439
|
|
|
*/ |
440
|
|
|
public function getInterestFee(): int |
441
|
|
|
{ |
442
|
|
|
return $this->interestFee; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @param int $interestFee |
447
|
|
|
* |
448
|
|
|
* @return Invoice |
449
|
|
|
*/ |
450
|
|
|
public function withInterestFee(int $interestFee) |
451
|
|
|
{ |
452
|
|
|
$new = clone $this; |
453
|
|
|
$new->interestFee = $interestFee; |
454
|
|
|
|
455
|
|
|
return $new; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return string |
460
|
|
|
*/ |
461
|
|
|
public function getCurrency(): string |
462
|
|
|
{ |
463
|
|
|
return $this->currency; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @param string $currency |
468
|
|
|
* |
469
|
|
|
* @return Invoice |
470
|
|
|
*/ |
471
|
|
|
public function withCurrency(string $currency) |
472
|
|
|
{ |
473
|
|
|
$new = clone $this; |
474
|
|
|
$this->currency = $currency; |
475
|
|
|
|
476
|
|
|
return $new; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* @return AdditionalInformation |
481
|
|
|
*/ |
482
|
|
|
public function getInfo(): AdditionalInformation |
483
|
|
|
{ |
484
|
|
|
return $this->info; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @param AdditionalInformation $info |
489
|
|
|
* |
490
|
|
|
* @return Invoice |
491
|
|
|
*/ |
492
|
|
|
public function withInfo(AdditionalInformation $info) |
493
|
|
|
{ |
494
|
|
|
$new = clone $this; |
495
|
|
|
$new->info = $info; |
496
|
|
|
|
497
|
|
|
return $new; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* @return RegionalInformation |
502
|
|
|
*/ |
503
|
|
|
public function getRegionalSweden(): RegionalInformation |
504
|
|
|
{ |
505
|
|
|
return $this->regionalSweden; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* @param RegionalInformation $regionalSweden |
510
|
|
|
* |
511
|
|
|
* @return Invoice |
512
|
|
|
*/ |
513
|
|
|
public function withRegionalSweden(RegionalInformation $regionalSweden) |
514
|
|
|
{ |
515
|
|
|
$new = clone $this; |
516
|
|
|
$new->regionalSweden = $regionalSweden; |
517
|
|
|
|
518
|
|
|
return $new; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* @return string |
523
|
|
|
*/ |
524
|
|
|
public function getDeliveryMethod(): string |
525
|
|
|
{ |
526
|
|
|
return $this->deliveryMethod; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @param string $deliveryMethod |
531
|
|
|
* |
532
|
|
|
* @return Invoice |
533
|
|
|
*/ |
534
|
|
|
public function withDeliveryMethod(string $deliveryMethod) |
535
|
|
|
{ |
536
|
|
|
$new = clone $this; |
537
|
|
|
$new->deliveryMethod = $deliveryMethod; |
538
|
|
|
|
539
|
|
|
return $new; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @return string |
544
|
|
|
*/ |
545
|
|
|
public function getState(): string |
546
|
|
|
{ |
547
|
|
|
return $this->state; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* @param string $state |
552
|
|
|
* |
553
|
|
|
* @return Invoice |
554
|
|
|
*/ |
555
|
|
|
public function swithState(string $state) |
556
|
|
|
{ |
557
|
|
|
$new = clone $this; |
558
|
|
|
$new->state = $state; |
559
|
|
|
|
560
|
|
|
return $new; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @return string |
565
|
|
|
*/ |
566
|
|
|
public function getUrl(): string |
567
|
|
|
{ |
568
|
|
|
return $this->url; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* @param string $url |
573
|
|
|
* |
574
|
|
|
* @return Invoice |
575
|
|
|
*/ |
576
|
|
|
public function withUrl(string $url) |
577
|
|
|
{ |
578
|
|
|
$new = clone $this; |
579
|
|
|
$new->url = $url; |
580
|
|
|
|
581
|
|
|
return $new; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* @return array |
586
|
|
|
*/ |
587
|
|
|
public function getFlags(): array |
588
|
|
|
{ |
589
|
|
|
return $this->flags; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* @param array $flags |
594
|
|
|
* |
595
|
|
|
* @return Invoice |
596
|
|
|
*/ |
597
|
|
|
public function withFlags(array $flags) |
598
|
|
|
{ |
599
|
|
|
$new = clone $this; |
600
|
|
|
$new->flags = $flags; |
601
|
|
|
|
602
|
|
|
return $new; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* @return EventData |
607
|
|
|
*/ |
608
|
|
|
public function getEvents(): EventData |
609
|
|
|
{ |
610
|
|
|
return $this->events; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* @param EventData $events |
615
|
|
|
* |
616
|
|
|
* @return Invoice |
617
|
|
|
*/ |
618
|
|
|
public function withEvents(EventData $events) |
619
|
|
|
{ |
620
|
|
|
$new = clone $this; |
621
|
|
|
$new->events = $events; |
622
|
|
|
|
623
|
|
|
return $new; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* @return int |
628
|
|
|
*/ |
629
|
|
|
public function getRemainingSum(): int |
630
|
|
|
{ |
631
|
|
|
return $this->remainingSum; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* @param int $remainingSum |
636
|
|
|
* |
637
|
|
|
* @return Invoice |
638
|
|
|
*/ |
639
|
|
|
public function withRemainingSum(int $remainingSum) |
640
|
|
|
{ |
641
|
|
|
$new = clone $this; |
642
|
|
|
$new->remainingSum = $remainingSum; |
643
|
|
|
|
644
|
|
|
return $new; |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* @return int |
649
|
|
|
*/ |
650
|
|
|
public function getTotalSum(): int |
651
|
|
|
{ |
652
|
|
|
return $this->totalSum; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @param int $totalSum |
657
|
|
|
* |
658
|
|
|
* @return Invoice |
659
|
|
|
*/ |
660
|
|
|
public function withTotalSum(int $totalSum) |
661
|
|
|
{ |
662
|
|
|
$new = clone $this; |
663
|
|
|
$new->totalSum = $totalSum; |
664
|
|
|
|
665
|
|
|
return $new; |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* @return bool |
670
|
|
|
*/ |
671
|
|
|
public function isAutomaticReminders(): bool |
672
|
|
|
{ |
673
|
|
|
return $this->automaticReminders; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* @param bool $automaticReminders |
678
|
|
|
* |
679
|
|
|
* @return Invoice |
680
|
|
|
*/ |
681
|
|
|
public function withAutomaticReminders(bool $automaticReminders) |
682
|
|
|
{ |
683
|
|
|
$new = clone $this; |
684
|
|
|
$new->automaticReminders = $automaticReminders; |
685
|
|
|
|
686
|
|
|
return $new; |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
/** |
690
|
|
|
* @return AutomaticReminder[] |
691
|
|
|
*/ |
692
|
|
|
public function getAutomaticRemindersSettings(): array |
693
|
|
|
{ |
694
|
|
|
return $this->automaticRemindersSettings; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* @param AutomaticReminder[] $automaticRemindersSettings |
699
|
|
|
* |
700
|
|
|
* @return Invoice |
701
|
|
|
*/ |
702
|
|
|
public function withAutomaticRemindersSettings(array $automaticRemindersSettings) |
703
|
|
|
{ |
704
|
|
|
$new = clone $this; |
705
|
|
|
$new->automaticRemindersSettings = $automaticRemindersSettings; |
706
|
|
|
|
707
|
|
|
return $new; |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
/** |
711
|
|
|
* @return int |
712
|
|
|
*/ |
713
|
|
|
public function getReminderCount(): int |
714
|
|
|
{ |
715
|
|
|
return $this->reminderCount; |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
/** |
719
|
|
|
* @param int $reminderCount |
720
|
|
|
* |
721
|
|
|
* @return Invoice |
722
|
|
|
*/ |
723
|
|
|
public function withReminderCount(int $reminderCount) |
724
|
|
|
{ |
725
|
|
|
$new = clone $this; |
726
|
|
|
$new->reminderCount = $reminderCount; |
727
|
|
|
|
728
|
|
|
return $new; |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* @return \DateTime |
733
|
|
|
*/ |
734
|
|
|
public function getCreatedAt(): \DateTime |
735
|
|
|
{ |
736
|
|
|
return $this->createdAt; |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
/** |
740
|
|
|
* @param \DateTime $createdAt |
741
|
|
|
* |
742
|
|
|
* @return Invoice |
743
|
|
|
*/ |
744
|
|
|
public function withCreatedAt(\DateTime $createdAt) |
745
|
|
|
{ |
746
|
|
|
$new = clone $this; |
747
|
|
|
$new->createdAt = $createdAt; |
748
|
|
|
|
749
|
|
|
return $new; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
|
|
* @return \DateTime |
754
|
|
|
*/ |
755
|
|
|
public function getAttestedAt(): \DateTime |
756
|
|
|
{ |
757
|
|
|
return $this->attestedAt; |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* @param \DateTime $attestedAt |
762
|
|
|
* |
763
|
|
|
* @return Invoice |
764
|
|
|
*/ |
765
|
|
|
public function withAttestedAt(\DateTime $attestedAt) |
766
|
|
|
{ |
767
|
|
|
$new = clone $this; |
768
|
|
|
$new->attestedAt = $attestedAt; |
769
|
|
|
|
770
|
|
|
return $new; |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* @return \DateTime |
775
|
|
|
*/ |
776
|
|
|
public function getUpdateAt(): \DateTime |
777
|
|
|
{ |
778
|
|
|
return $this->updateAt; |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* @param \DateTime $updateAt |
783
|
|
|
* |
784
|
|
|
* @return Invoice |
785
|
|
|
*/ |
786
|
|
|
public function withUpdateAt(\DateTime $updateAt) |
787
|
|
|
{ |
788
|
|
|
$new = clone $this; |
789
|
|
|
$new->updateAt = $updateAt; |
790
|
|
|
|
791
|
|
|
return $new; |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
/** |
795
|
|
|
* @return BillogramCallback |
796
|
|
|
*/ |
797
|
|
|
public function getCallbacks(): BillogramCallback |
798
|
|
|
{ |
799
|
|
|
return $this->callbacks; |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
/** |
803
|
|
|
* @param BillogramCallback $callbacks |
804
|
|
|
* |
805
|
|
|
* @return Invoice |
806
|
|
|
*/ |
807
|
|
|
public function withCallbacks(BillogramCallback $callbacks) |
808
|
|
|
{ |
809
|
|
|
$new = clone $this; |
810
|
|
|
$new->callbacks = $callbacks; |
811
|
|
|
|
812
|
|
|
return $new; |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
/** |
816
|
|
|
* @return DetailedSums |
817
|
|
|
*/ |
818
|
|
|
public function getDetailedSums(): DetailedSums |
819
|
|
|
{ |
820
|
|
|
return $this->detailedSums; |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* @param DetailedSums $detailedSums |
825
|
|
|
* |
826
|
|
|
* @return Invoice |
827
|
|
|
*/ |
828
|
|
|
public function withDetailedSums(DetailedSums $detailedSums) |
829
|
|
|
{ |
830
|
|
|
$new = clone $this; |
831
|
|
|
$new->detailedSums = $detailedSums; |
832
|
|
|
|
833
|
|
|
return $new; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* @return string |
838
|
|
|
*/ |
839
|
|
|
public function getAttachment(): string |
840
|
|
|
{ |
841
|
|
|
return $this->attachment; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* @param string $attachment |
846
|
|
|
* |
847
|
|
|
* @return Invoice |
848
|
|
|
*/ |
849
|
|
|
public function withAttachment(string $attachment) |
850
|
|
|
{ |
851
|
|
|
$new = clone $this; |
852
|
|
|
$new->attachment = $attachment; |
853
|
|
|
|
854
|
|
|
return $new; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
/** |
858
|
|
|
* @return ReminderCollection |
859
|
|
|
*/ |
860
|
|
|
public function getAutomaticCollection(): ReminderCollection |
861
|
|
|
{ |
862
|
|
|
return $this->automaticCollection; |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
/** |
866
|
|
|
* @param ReminderCollection $automaticCollection |
867
|
|
|
* |
868
|
|
|
* @return Invoice |
869
|
|
|
*/ |
870
|
|
|
public function withAutomaticCollection(ReminderCollection $automaticCollection) |
871
|
|
|
{ |
872
|
|
|
$new = clone $this; |
873
|
|
|
$new->automaticCollection = $automaticCollection; |
874
|
|
|
|
875
|
|
|
return $new; |
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
/** |
879
|
|
|
* @return int |
880
|
|
|
*/ |
881
|
|
|
public function getRoundingValue(): int |
882
|
|
|
{ |
883
|
|
|
return $this->roundingValue; |
884
|
|
|
} |
885
|
|
|
|
886
|
2 |
|
public function toArray() |
887
|
|
|
{ |
888
|
2 |
|
$data = []; |
889
|
2 |
|
if (null !== $this->customer) { |
890
|
2 |
|
$data['customer'] = $this->customer->toArray(); |
891
|
|
|
} |
892
|
|
|
|
893
|
2 |
|
if (!empty($this->automaticCollection)) { |
894
|
1 |
|
$data['automatic_collection'] = $this->automaticCollection->toArray(); |
895
|
|
|
} |
896
|
|
|
|
897
|
2 |
|
if (!empty($this->items)) { |
898
|
2 |
|
foreach ($this->items as $item) { |
899
|
2 |
|
$data['items'][] = $item->toArray(); |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
|
903
|
|
|
$map = [ |
904
|
2 |
|
'id' => 'id', |
905
|
|
|
'invoiceNo' => 'invoice_no', |
906
|
|
|
'invoiceDate' => 'invoice_date', |
907
|
|
|
'ocrNumber' => 'ocr_number', |
908
|
|
|
'dueDate' => 'due_date', |
909
|
|
|
'dueDays' => 'due_days', |
910
|
|
|
'invoiceFee' => 'invoice_fee', |
911
|
|
|
'invoiceFeeVat' => 'invoice_fee_vat', |
912
|
|
|
'reminderFee' => 'reminder_fee', |
913
|
|
|
'interestRate' => 'interest_rate', |
914
|
|
|
'interestFee' => 'interest_fee', |
915
|
|
|
'currency' => 'currency', |
916
|
|
|
'info' => 'info', |
917
|
|
|
'regionalSweden' => 'regional_sweden', |
918
|
|
|
'deliveryMethod' => 'delivery_method', |
919
|
|
|
'state' => 'state', |
920
|
|
|
'url' => 'url', |
921
|
|
|
'flags' => 'flags', |
922
|
|
|
'events' => 'events', |
923
|
|
|
'remainingSum' => 'remaining_sum', |
924
|
|
|
'totalSum' => 'total_sum', |
925
|
|
|
'roundingValue' => 'rounding_value', |
926
|
|
|
'automaticReminders' => 'automatic_reminders', |
927
|
|
|
'automaticRemindersSettings' => 'automatic_reminders_settings', |
928
|
|
|
'reminderCount' => 'reminder_count', |
929
|
|
|
'createdAt' => 'created_at', |
930
|
|
|
'updateAt' => 'update_at', |
931
|
|
|
'attestedAt' => 'attested_at', |
932
|
|
|
'callbacks' => 'callbacks', |
933
|
|
|
'detailedSums' => 'detailed_sums', |
934
|
|
|
'attachment' => 'attachment', |
935
|
|
|
]; |
936
|
|
|
|
937
|
2 |
|
foreach ($map as $property => $keyName) { |
938
|
2 |
|
if ($this->$property !== null) { |
939
|
2 |
|
$data[$keyName] = $this->$property; |
940
|
|
|
} |
941
|
|
|
} |
942
|
|
|
|
943
|
2 |
|
return $data; |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
/** |
947
|
|
|
* Create an API response object from the HTTP response from the API server. |
948
|
|
|
* |
949
|
|
|
* @param array $data |
950
|
|
|
* |
951
|
|
|
* @return self |
952
|
|
|
*/ |
953
|
4 |
|
public static function createFromArray(array $data) |
954
|
|
|
{ |
955
|
4 |
|
$data = $data['data']; |
956
|
4 |
|
$invoice = new self(); |
957
|
4 |
|
$invoice->id = $data['id'] ?? null; |
958
|
4 |
|
$invoice->createdAt = isset($data['created_at']) ? new \DateTime($data['created_at']) : null; |
959
|
4 |
|
$invoice->updateAt = isset($data['update_at']) ? new \DateTime($data['update_at']) : null; |
960
|
4 |
|
$invoice->attestedAt = isset($data['attested_at']) ? new \DateTime($data['attested_at']) : null; |
961
|
4 |
|
$invoice->currency = $data['currency'] ?? null; |
962
|
4 |
|
$invoice->reminderFee = $data['reminder_fee'] ?? null; |
963
|
4 |
|
$invoice->interestRate = $data['interest_rate'] ?? null; |
964
|
4 |
|
$invoice->state = $data['state'] ?? null; |
965
|
4 |
|
$invoice->attachment = $data['attachment'] ?? null; |
966
|
4 |
|
$invoice->automaticReminders = $data['automatic_reminders'] ?? null; |
967
|
4 |
|
if (array_key_exists('automatic_reminders_settings', $data)) { |
968
|
3 |
|
foreach ($data['automatic_reminders_settings'] as $setting) { |
969
|
|
|
$automaticReminder = AutomaticReminder::createFromArray($setting) ?? null; |
970
|
|
|
$invoice->automaticRemindersSettings[] = $automaticReminder; |
971
|
|
|
} |
972
|
|
|
} |
973
|
4 |
|
if (array_key_exists('automatic_collection', $data)) { |
974
|
3 |
|
$invoice->automaticCollection = ReminderCollection::createFromArray($data['automatic_collection']) ?? null; |
975
|
|
|
} |
976
|
4 |
|
$invoice->roundingValue = $data['rounding_value'] ?? null; |
977
|
4 |
|
$invoice->ocrNumber = $data['ocr_number'] ?? null; |
978
|
4 |
|
if (array_key_exists('events', $data)) { |
979
|
3 |
|
foreach ($data['events'] as $eventArray) { |
980
|
3 |
|
$event = Event::createFromArray($eventArray) ?? null; |
981
|
3 |
|
$invoice->events[] = $event; |
982
|
|
|
} |
983
|
|
|
} |
984
|
4 |
|
$invoice->dueDate = $data['due_date'] ?? null; |
985
|
4 |
|
$invoice->dueDays = $data['due_days'] ?? null; |
986
|
4 |
|
$invoice->invoiceDate = $data['invoice_date'] ?? null; |
987
|
4 |
|
if (array_key_exists('callbacks', $data)) { |
988
|
3 |
|
$invoice->callbacks = BillogramCallback::createFromArray($data['callbacks']) ?? null; |
989
|
|
|
} |
990
|
4 |
|
$invoice->interestFee = $data['interest_fee'] ?? null; |
991
|
4 |
|
$invoice->invoiceNo = $data['invoice_no'] ?? null; |
992
|
4 |
|
$invoice->customer = Customer::createFromArray($data['customer']) ?? null; |
|
|
|
|
993
|
4 |
|
if (array_key_exists('info', $data)) { |
994
|
3 |
|
$invoice->info = AdditionalInformation::createFromArray($data['info']) ?? null; |
995
|
|
|
} |
996
|
4 |
|
$invoice->invoiceFee = $data['invoice_fee'] ?? null; |
997
|
4 |
|
$invoice->invoiceFeeVat = $data['invoice_fee_vat'] ?? null; |
998
|
4 |
|
if (array_key_exists('items', $data)) { |
999
|
3 |
|
foreach ($data['items'] as $item) { |
1000
|
3 |
|
$item = \Billogram\Model\Invoice\Item::createFromArray($item) ?? null; |
1001
|
3 |
|
$invoice->items[] = $item; |
1002
|
|
|
} |
1003
|
|
|
} |
1004
|
4 |
|
$invoice->totalSum = $data['total_sum'] ?? null; |
1005
|
4 |
|
$invoice->remainingSum = $data['remaining_sum'] ?? null; |
1006
|
4 |
|
$invoice->reminderCount = $data['reminder_count'] ?? null; |
1007
|
4 |
|
$invoice->deliveryMethod = $data['delivery_method'] ?? null; |
1008
|
4 |
|
$invoice->url = $data['url'] ?? null; |
1009
|
4 |
|
$invoice->flags = $data['flags'] ?? null; |
1010
|
4 |
|
if (array_key_exists('regional_sweden', $data) && array_key_exists('regional_sweden', $data)) { |
1011
|
3 |
|
$invoice->regionalSweden = RegionalInformation::createFromArray($data['regional_sweden']) ?? null; |
1012
|
3 |
|
$invoice->detailedSums = DetailedSums::createFromArray($data['detailed_sums']) ?? null; |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
4 |
|
return $invoice; |
1016
|
|
|
} |
1017
|
|
|
} |
1018
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.