Completed
Push — master ( 290f71...5c7d58 )
by Tobias
01:52
created

Invoice::withInvoiceDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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