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.

Name: INSLYPROD-1654 - EE Logo issue for invoice to docx fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of INSLYPROD-1654 - EE Logo issue for invoice to docx .php

  1. <?php
  2.  
  3. $xml =<<<XML
  4. <invoice>
  5.     <rows>
  6.         <row type="row-type-1">
  7.             <sum>100</sum>
  8.             <tax>10</tax>
  9.             <description>Desc 1</description>
  10.         </row>
  11.         <row type="row-type-2">
  12.             <sum>200</sum>
  13.             <tax>20</tax>
  14.             <description>Desc 2</description>
  15.         </row>
  16.         <row type="row-type-3">
  17.             <sum>300</sum>
  18.             <tax>40</tax>
  19.             <description>Desc 3</description>
  20.         </row>
  21.  
  22.     </rows>
  23. </invoice>
  24.  
  25. XML;
  26.  
  27.  
  28. $templateData = json_decode(json_encode((array)simplexml_load_string($xml)), true);
  29.  
  30.  
  31. print_r($templateData);
  32.  
  33.  
  34. function fixupInvoiceRows(array $templateData): array
  35. {
  36.     if (array_key_first($templateData['rows']['row']) === "@attributes") {
  37.         $templateData['rows']['row'] = [$templateData['rows']['row']];
  38.     }
  39.  
  40.  
  41.     //Invoice rows descriptions
  42.     foreach ($templateData['rows']['row'] as $rowKey => $row) {
  43.         if (!is_array($row['description'])) {
  44.             $templateData['rows']['row'][$rowKey]['description'] = [$row['description']];
  45.         }
  46.     }
  47.     return $templateData;
  48. }
  49.  
  50. echo "\n\n .-------------------------------------------\n";
  51.  
  52. print_r(fixupInvoiceRows($templateData));
  53.  
File Description
  • INSLYPROD-1654 - EE Logo issue for invoice to docx
  • PHP Code
  • 05 Feb-2020
  • 1.18 Kb
You can Share it: