99use Carbon \Carbon ;
1010use Dompdf \Dompdf ;
1111use Elegantly \Invoices \Concerns \FormatForPdf ;
12+ use Elegantly \Invoices \Contracts \HasLabel ;
1213use Elegantly \Invoices \Enums \InvoiceState ;
1314use Elegantly \Invoices \Enums \InvoiceType ;
1415use Elegantly \Invoices \InvoiceDiscount ;
@@ -25,10 +26,6 @@ class PdfInvoice
2526{
2627 use FormatForPdf;
2728
28- public string $ type ;
29-
30- public string $ state ;
31-
3229 public string $ template ;
3330
3431 /**
@@ -40,8 +37,8 @@ class PdfInvoice
4037 * @param array<string, mixed> $templateData
4138 */
4239 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,
4542 public ?string $ serial_number = null ,
4643 public ?Carbon $ created_at = null ,
4744 public ?Carbon $ due_at = null ,
@@ -63,9 +60,6 @@ public function __construct(
6360
6461 public ?string $ logo = null ,
6562 ) {
66- $ this ->type = $ type instanceof InvoiceType ? $ type ->getLabel () : $ type ;
67- $ this ->state = $ state instanceof InvoiceState ? $ state ->getLabel () : $ state ;
68-
6963 // @phpstan-ignore-next-line
7064 $ this ->logo = $ logo ?? config ('invoices.pdf.logo ' ) ?? config ('invoices.default_logo ' );
7165 // @phpstan-ignore-next-line
@@ -74,6 +68,16 @@ public function __construct(
7468 $ this ->templateData = config ('invoices.pdf.template_data ' ) ?? [];
7569 }
7670
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+
7781 public function getFilename (): string
7882 {
7983 return str ($ this ->serial_number )
0 commit comments