| 1 | package SelectPdf::InvoiceClient; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use SelectPdf::ApiEnums; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use SelectPdf::AsyncJobClient; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use SelectPdf::HtmlToPdfClient; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(SelectPdf::HtmlToPdfClient); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '1.6.0'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | SelectPdf::InvoiceClient - Create ZUGFeRD / Factur-X hybrid electronic invoices with SelectPdf Online API. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | Create a hybrid electronic invoice from an HTML string and save it into a file on disk. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | use SelectPdf; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | print "This is SelectPdf-$SelectPdf::VERSION\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | my $apiKey = "Your API key here"; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | my $invoiceHtml = "<html><body><h1>Invoice INV-2026-001</h1></body></html>"; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | my $invoiceXml = "factur-x.xml"; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | my $local_file = "Invoice.pdf"; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | my $client = SelectPdf::InvoiceClient->new($apiKey); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | $client | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ->setInvoiceXmlFile($invoiceXml) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ->setZugferdProfile(SelectPdf::ZugferdProfile::En16931) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ->setDocTitle("Invoice INV-2026-001") | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | $client->createFromHtmlStringToFile($invoiceHtml, $local_file); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | print "Finished! Number of pages: " . $client->getNumberOfPages() . ".\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | print "An error occurred: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | A hybrid electronic invoice is one PDF/A-3 file carrying both halves of the invoice: the page a human reads, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | and the XML a recipient's accounting system reads. This client converts a URL or an HTML string into the visible | ||||||||||||||||||||||||||||||||||||||||||
| 51 | invoice and embeds the XML into it as an associated file, with the metadata invoice software looks for. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | It derives from SelectPdf::HtmlToPdfClient, so every conversion setting - page size, margins, headers, footers, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | rendering engine - applies here too. Use the createFrom* methods rather than the inherited convert* methods: | ||||||||||||||||||||||||||||||||||||||||||
| 55 | the invoice endpoint takes a multipart request, because the XML is uploaded as a file part. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | The carrier document must be PDF/A-3. The default is PdfA3A, the accessible level, which the standards recommend | ||||||||||||||||||||||||||||||||||||||||||
| 58 | because it makes the visible invoice readable by assistive technology as well as archivable. Because PdfA3A is a | ||||||||||||||||||||||||||||||||||||||||||
| 59 | tagged standard, a request that does not set a rendering engine is promoted to Chromium by the API, which reports | ||||||||||||||||||||||||||||||||||||||||||
| 60 | the engine used in the X-SelectPdf-Engine response header. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | There is no way to attach an invoice XML to an existing PDF you already have: the XML can only be embedded into a | ||||||||||||||||||||||||||||||||||||||||||
| 63 | document created as PDF/A-3. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | For more details and full list of parameters see L<Html To Pdf API Parameters|https://selectpdf.com/html-to-pdf-api-parameters/#invoicing>. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head2 new( $apiKey ) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | Construct the Invoice Client. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | my $client = SelectPdf::InvoiceClient->new($apiKey); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | Unlike SelectPdf::HtmlToPdfClient, this client has no demo mode - the keyless demo endpoint does not produce | ||||||||||||||||||||||||||||||||||||||||||
| 76 | electronic invoices - so an API key is required. The constructor dies when no API key is supplied. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | - $apiKey API Key. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $apiKey = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | if (not defined($apiKey) or $apiKey eq "" or lc(_trim($apiKey)) eq "demo") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $apiKey or $apiKey eq "" or lc _trim($apiKey) eq "demo"
not defined $apiKey or $apiKey eq ""
MC/DC33%1/3
not defined $apiKey or $apiKey eq "" or lc _trim($apiKey) eq "demo"
not defined $apiKey
$apiKey eq ""
lc _trim($apiKey) eq "demo"
Truth table50%2/4
not(A) or B or C
A= not defined $apiKeyB= $apiKey eq ""C= lc _trim($apiKey) eq "demo"
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | die "An API key is required to create electronic invoices. The keyless demo endpoint does not support them."; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $self = $type->SUPER::new($apiKey); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # API endpoint | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self->{apiEndpoint} = "https://selectpdf.com/api2/invoice/"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # The carrier has to be PDF/A-3; default to the accessible level, which | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # the standards recommend. Overridable with setPdfStandard. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $self->{parameters}{"pdf_standard"} = SelectPdf::PdfStandard::PdfA3A; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | bless $self, $type; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | sub _trim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | $value =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =head2 setInvoiceXmlFile( $invoiceXmlFile ) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | Set the invoice XML from a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | Only the content of the file is used - the name recorded inside the PDF is the one the standard prescribes | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ("factur-x.xml", or "xrechnung.xml" for the XRECHNUNG profile), because recipients look it up by name. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | - $invoiceXmlFile: Path to the local invoice XML file. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | - Reference to the current object. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub setInvoiceXmlFile($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setInvoiceXmlFile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my($self, $invoiceXmlFile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | delete $self->{binaryData}{"zugferd_xml"}; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $self->{files}{"zugferd_xml"} = $invoiceXmlFile; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =head2 setInvoiceXml( $invoiceXml ) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | Set the invoice XML from memory. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | A character string (with the UTF-8 flag on) is encoded as UTF-8 before it is sent; any other string is sent as-is, as bytes. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | - $invoiceXml: The invoice XML content. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | - Reference to the current object. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub setInvoiceXml($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setInvoiceXml: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my($self, $invoiceXml) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | $invoiceXml = "" if (not defined($invoiceXml)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | $invoiceXml = Encode::encode('UTF-8', $invoiceXml) if (utf8::is_utf8($invoiceXml)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | delete $self->{files}{"zugferd_xml"}; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $self->{binaryData}{"zugferd_xml"} = $invoiceXml; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =head2 setZugferdProfile( $profile ) | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | Set the data profile of the invoice XML - how much of the EN 16931 semantic model it carries. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | - $profile: Invoice profile. Possible values: Minimum, Basic_WL, Basic, En16931, Extended, XRechnung (see SelectPdf::ZugferdProfile constants). | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | - Reference to the current object. | ||||||||||||||||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | sub setZugferdProfile($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setZugferdProfile: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my($self, $profile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | if (not defined($profile) or $profile !~ m/^(Minimum|Basic_WL|Basic|En16931|Extended|XRechnung)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $profile and $profile =~ /^(Minimum|Basic_WL|Basic|En16931|Extended|XRechnung)$/i
MC/DC0%0/2
defined $profile and $profile =~ /^(Minimum|Basic_WL|Basic|En16931|Extended|XRechnung)$/i
defined $profile
$profile =~ /^(Minimum|Basic_WL|Basic|En16931|Extended|XRechnung)$/i
Truth table33%1/3
A and B
A= defined $profileB= $profile =~ /^(Minimum|Basic_WL|Basic|En16931|Extended|XRechnung)$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | die ("Allowed values for Zugferd Profile: Minimum, Basic_WL, Basic, En16931, Extended, XRechnung."); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $self->{parameters}{"zugferd_profile"} = $profile; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =head2 setZugferdRelationship( $relationship ) | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | Set how the embedded invoice XML relates to the visible invoice page. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | Optional. When not set, the API derives it from the profile: Alternative for Minimum and Basic_WL, and Data for the rest. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | Minimum and Basic_WL combined with Data are rejected, because those profiles do not carry a complete invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | - $relationship: Relationship. Possible values: Data, Alternative, Source, Supplement (see SelectPdf::ZugferdRelationship constants). | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | - Reference to the current object. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | sub setZugferdRelationship($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setZugferdRelationship: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my($self, $relationship) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | if (not defined($relationship) or $relationship !~ m/^(Data|Alternative|Source|Supplement)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $relationship and $relationship =~ /^(Data|Alternative|Source|Supplement)$/i
MC/DC0%0/2
defined $relationship and $relationship =~ /^(Data|Alternative|Source|Supplement)$/i
defined $relationship
$relationship =~ /^(Data|Alternative|Source|Supplement)$/i
Truth table33%1/3
A and B
A= defined $relationshipB= $relationship =~ /^(Data|Alternative|Source|Supplement)$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | die ("Allowed values for Zugferd Relationship: Data, Alternative, Source, Supplement."); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $self->{parameters}{"zugferd_relationship"} = $relationship; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | =head2 setZugferdSchema( $schema ) | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | Set the metadata schema used to identify the hybrid invoice inside the PDF. Default is FacturX10. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | - $schema: Schema. Possible values: FacturX10, Zugferd20 (see SelectPdf::ZugferdSchema constants). | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | - Reference to the current object. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | sub setZugferdSchema($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setZugferdSchema: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | if (not defined($schema) or $schema !~ m/^(FacturX10|Zugferd20)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $schema and $schema =~ /^(FacturX10|Zugferd20)$/i
MC/DC0%0/2
defined $schema and $schema =~ /^(FacturX10|Zugferd20)$/i
defined $schema
$schema =~ /^(FacturX10|Zugferd20)$/i
Truth table33%1/3
A and B
A= defined $schemaB= $schema =~ /^(FacturX10|Zugferd20)$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | die ("Allowed values for Zugferd Schema: FacturX10, Zugferd20."); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | $self->{parameters}{"zugferd_schema"} = $schema; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | =head2 createFromUrl( $url ) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | Create the hybrid invoice from the specified url. The page at the url becomes the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | $content = $client->createFromUrl($url); | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | - $url Address of the web page with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub createFromUrl($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromUrl: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $self->_prepareUrl($url); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->{parameters}{"async"} = "False"; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $self->SUPER::performPostAsMultipartFormData(); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | =head2 createFromUrlToFile( $url, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | Create the hybrid invoice from the specified url and write it to a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | $client->createFromUrlToFile($url, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | - $url Address of the web page with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub createFromUrlToFile($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromUrlToFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my($self, $url, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $content = $self->createFromUrl($url); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | _writeFile($filePath, $content); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | =head2 createFromUrlAsync( $url ) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | Create the hybrid invoice from the specified url, using an asynchronous call. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | $content = $client->createFromUrlAsync($url); | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | - $url Address of the web page with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 284 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub createFromUrlAsync($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromUrlAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->_prepareUrl($url); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $self->_runAsyncJob(); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | =head2 createFromUrlToFileAsync( $url, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | Create the hybrid invoice from the specified url, using an asynchronous call, and write it to a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | $client->createFromUrlToFileAsync($url, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | - $url Address of the web page with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 303 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub createFromUrlToFileAsync($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromUrlToFileAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my($self, $url, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $content = $self->createFromUrlAsync($url); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | _writeFile($filePath, $content); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | =head2 createFromHtmlString( $htmlString ) | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | Create the hybrid invoice from the specified HTML string, which becomes the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | $content = $client->createFromHtmlString($htmlString); | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | ▶ | sub createFromHtmlString($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlString: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | my($self, $htmlString) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | return $self->createFromHtmlStringWithBaseUrl($htmlString, ""); | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | =head2 createFromHtmlStringWithBaseUrl( $htmlString, $baseUrl ) | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | Create the hybrid invoice from the specified HTML string. Use a base url to resolve relative paths to resources. | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | $content = $client->createFromHtmlStringWithBaseUrl($htmlString, $baseUrl); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 346 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | ▶ | sub createFromHtmlStringWithBaseUrl($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringWithBaseUrl: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | my($self, $htmlString, $baseUrl) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | $self->_prepareHtml($htmlString, $baseUrl); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $self->{parameters}{"async"} = "False"; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return $self->SUPER::performPostAsMultipartFormData(); | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | =head2 createFromHtmlStringToFile( $htmlString, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | Create the hybrid invoice from the specified HTML string and write it to a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | $client->createFromHtmlStringToFile($htmlString, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub createFromHtmlStringToFile($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringToFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my($self, $htmlString, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->createFromHtmlStringWithBaseUrlToFile($htmlString, "", $filePath); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | =head2 createFromHtmlStringWithBaseUrlToFile( $htmlString, $baseUrl, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | Create the hybrid invoice from the specified HTML string and write it to a local file. Use a base url to resolve relative paths to resources. | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | $client->createFromHtmlStringWithBaseUrlToFile($htmlString, $baseUrl, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 387 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | sub createFromHtmlStringWithBaseUrlToFile($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringWithBaseUrlToFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my($self, $htmlString, $baseUrl, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my $content = $self->createFromHtmlStringWithBaseUrl($htmlString, $baseUrl); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | _writeFile($filePath, $content); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | =head2 createFromHtmlStringAsync( $htmlString ) | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | Create the hybrid invoice from the specified HTML string, using an asynchronous call. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | $content = $client->createFromHtmlStringAsync($htmlString); | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 408 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | sub createFromHtmlStringAsync($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my($self, $htmlString) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return $self->createFromHtmlStringWithBaseUrlAsync($htmlString, ""); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | =head2 createFromHtmlStringWithBaseUrlAsync( $htmlString, $baseUrl ) | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | Create the hybrid invoice from the specified HTML string, using an asynchronous call. Use a base url to resolve relative paths to resources. | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | $content = $client->createFromHtmlStringWithBaseUrlAsync($htmlString, $baseUrl); | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url. | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | - Byte array containing the resulted PDF. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub createFromHtmlStringWithBaseUrlAsync($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringWithBaseUrlAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my($self, $htmlString, $baseUrl) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $self->_prepareHtml($htmlString, $baseUrl); | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $self->_runAsyncJob(); | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | =head2 createFromHtmlStringToFileAsync( $htmlString, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | Create the hybrid invoice from the specified HTML string, using an asynchronous call, and write it to a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | $client->createFromHtmlStringToFileAsync($htmlString, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 449 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | sub createFromHtmlStringToFileAsync($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringToFileAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my($self, $htmlString, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->createFromHtmlStringWithBaseUrlToFileAsync($htmlString, "", $filePath); | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | =head2 createFromHtmlStringWithBaseUrlToFileAsync( $htmlString, $baseUrl, $filePath ) | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | Create the hybrid invoice from the specified HTML string, using an asynchronous call, and write it to a local file. | ||||||||||||||||||||||||||||||||||||||||||
| 459 | Use a base url to resolve relative paths to resources. | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | $client->createFromHtmlStringWithBaseUrlToFileAsync($htmlString, $baseUrl, $filePath); | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | - $htmlString HTML string with the visible invoice. | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | - $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url. | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | - $filePath Local file including path if necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 470 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub createFromHtmlStringWithBaseUrlToFileAsync($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createFromHtmlStringWithBaseUrlToFileAsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my($self, $htmlString, $baseUrl, $filePath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | my $content = $self->createFromHtmlStringWithBaseUrlAsync($htmlString, $baseUrl); | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | _writeFile($filePath, $content); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | # --- internals ------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | sub _prepareUrl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepareUrl: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if (not defined($url) or $url !~ m/^https?:\/\//i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $url and $url =~ m[^https?://]i
MC/DC0%0/2
defined $url and $url =~ m[^https?://]i
defined $url
$url =~ m[^https?://]i
Truth table0%0/3
A and B
A= defined $urlB= $url =~ m[^https?://]i
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | die "The supported protocols for the converted webpage are http:// and https://."; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ($url =~ m/^http:\/\/localhost/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | die "Cannot convert local urls. SelectPdf online API can only convert publicly available urls."; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $self->_requireInvoiceXml(); | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->{parameters}{"url"} = $url; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $self->{parameters}{"html"} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $self->{parameters}{"base_url"} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | ▶ | sub _prepareHtml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepareHtml: called CC=2 SCAR=12.4
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | my($self, $htmlString, $baseUrl) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $self->_requireInvoiceXml(); | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->{parameters}{"url"} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->{parameters}{"html"} = $htmlString; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | $self->{parameters}{"base_url"} = defined($baseUrl) ? $baseUrl : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | # Fail here rather than spending a round trip on a request the API will | ||||||||||||||||||||||||||||||||||||||||||
| 506 | # reject with the same message. | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | ▶ | sub _requireInvoiceXml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_requireInvoiceXml: called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | ▶ | if (not exists($self->{files}{"zugferd_xml"}) and not exists($self->{binaryData}{"zugferd_xml"})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"files"}{"zugferd_xml"} or exists $self->{"binaryData"}{"zugferd_xml"}
MC/DC0%0/2
exists $self->{"files"}{"zugferd_xml"} or exists $self->{"binaryData"}{"zugferd_xml"}
exists $self->{"files"}{"zugferd_xml"}
exists $self->{"binaryData"}{"zugferd_xml"}
Truth table33%1/3
A or B
A= exists $self->{"files"}{"zugferd_xml"}B= exists $self->{"binaryData"}{"zugferd_xml"}
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | die "The invoice XML was not specified. Call setInvoiceXmlFile or setInvoiceXml before creating the invoice."; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if (not defined($self->{parameters}{"zugferd_profile"}) or $self->{parameters}{"zugferd_profile"} eq "") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"parameters"}{"zugferd_profile"} or $self->{"parameters"}{"zugferd_profile"} eq ""
MC/DC0%0/2
not defined $self->{"parameters"}{"zugferd_profile"} or $self->{"parameters"}{"zugferd_profile"} eq ""
not defined $self->{"parameters"}{"zugferd_profile"}
$self->{"parameters"}{"zugferd_profile"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $self->{"parameters"}{"zugferd_profile"}B= $self->{"parameters"}{"zugferd_profile"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | die "The invoice profile was not specified. Call setZugferdProfile before creating the invoice."; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub _runAsyncJob { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_runAsyncJob: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | my $JobID = $self->SUPER::startAsyncJobMultipartFormData() or die "An error occurred launching the asynchronous call."; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my $noPings = 0; | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | while ($noPings < $self->{AsyncCallsMaxPings}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $noPings++; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | # sleep for a few seconds before next ping | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | sleep($self->{AsyncCallsPingInterval}); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | my $asyncJobClient = new SelectPdf::AsyncJobClient($self->{parameters}{"key"}, $JobID); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $asyncJobClient->setApiEndpoint($self->{apiAsyncEndpoint}); | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $result = $asyncJobClient->getResult(); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | if ($asyncJobClient->finished) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $self->{numberOfPages} = $asyncJobClient->getNumberOfPages(); | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $self->{creditsTotal} = $asyncJobClient->getCreditsTotal(); | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $self->{creditsRemaining} = $asyncJobClient->getCreditsRemaining(); | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | die "Asynchronous call did not finish in expected timeframe."; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | sub _writeFile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_writeFile: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | my($filePath, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | my $file = IO::File->new( $filePath, '>' ) or die "Unable to open output file - $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $file->binmode; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $file->print( $content ); | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $file->close; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||