INSLYPROD-1654 - EE Logo issue for invoice to docx - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of INSLYPROD-1654 - EE Logo issue for invoice to docx .php
- <?php
- $xml =<<<XML
- <invoice>
- <rows>
- <row type="row-type-1">
- <sum>100</sum>
- <tax>10</tax>
- <description>Desc 1</description>
- </row>
- <row type="row-type-2">
- <sum>200</sum>
- <tax>20</tax>
- <description>Desc 2</description>
- </row>
- <row type="row-type-3">
- <sum>300</sum>
- <tax>40</tax>
- <description>Desc 3</description>
- </row>
- </rows>
- </invoice>
- XML;
- $templateData = json_decode(json_encode((array)simplexml_load_string($xml)), true);
- print_r($templateData);
- function fixupInvoiceRows(array $templateData): array
- {
- if (array_key_first($templateData['rows']['row']) === "@attributes") {
- $templateData['rows']['row'] = [$templateData['rows']['row']];
- }
- //Invoice rows descriptions
- foreach ($templateData['rows']['row'] as $rowKey => $row) {
- if (!is_array($row['description'])) {
- $templateData['rows']['row'][$rowKey]['description'] = [$row['description']];
- }
- }
- return $templateData;
- }
- echo "\n\n .-------------------------------------------\n";
- print_r(fixupInvoiceRows($templateData));