9
9
use Carbon \Carbon ;
10
10
use Dompdf \Dompdf ;
11
11
use Elegantly \Invoices \Concerns \FormatForPdf ;
12
+ use Elegantly \Invoices \Contracts \HasLabel ;
12
13
use Elegantly \Invoices \Enums \InvoiceState ;
13
14
use Elegantly \Invoices \Enums \InvoiceType ;
14
15
use Elegantly \Invoices \InvoiceDiscount ;
@@ -25,10 +26,6 @@ class PdfInvoice
25
26
{
26
27
use FormatForPdf;
27
28
28
- public string $ type ;
29
-
30
- public string $ state ;
31
-
32
29
public string $ template ;
33
30
34
31
/**
@@ -40,8 +37,8 @@ class PdfInvoice
40
37
* @param array<string, mixed> $templateData
41
38
*/
42
39
public function __construct (
43
- InvoiceType |string $ type = InvoiceType::Invoice,
44
- InvoiceState |string $ state = InvoiceState::Draft,
40
+ public HasLabel |string $ type = InvoiceType::Invoice,
41
+ public HasLabel |string $ state = InvoiceState::Draft,
45
42
public ?string $ serial_number = null ,
46
43
public ?Carbon $ created_at = null ,
47
44
public ?Carbon $ due_at = null ,
@@ -63,9 +60,6 @@ public function __construct(
63
60
64
61
public ?string $ logo = null ,
65
62
) {
66
- $ this ->type = $ type instanceof InvoiceType ? $ type ->getLabel () : $ type ;
67
- $ this ->state = $ state instanceof InvoiceState ? $ state ->getLabel () : $ state ;
68
-
69
63
// @phpstan-ignore-next-line
70
64
$ this ->logo = $ logo ?? config ('invoices.pdf.logo ' ) ?? config ('invoices.default_logo ' );
71
65
// @phpstan-ignore-next-line
@@ -74,6 +68,16 @@ public function __construct(
74
68
$ this ->templateData = config ('invoices.pdf.template_data ' ) ?? [];
75
69
}
76
70
71
+ public function getTypeLabel (): ?string
72
+ {
73
+ return $ this ->type instanceof HasLabel ? $ this ->type ->getLabel () : $ this ->type ;
74
+ }
75
+
76
+ public function getStateLabel (): ?string
77
+ {
78
+ return $ this ->state instanceof HasLabel ? $ this ->state ->getLabel () : $ this ->state ;
79
+ }
80
+
77
81
public function getFilename (): string
78
82
{
79
83
return str ($ this ->serial_number )
0 commit comments