Announcement

Collapse
No announcement yet.

Invoicing broken: print to PDF blank page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invoicing broken: print to PDF blank page

    When I want to print an invoice to PDF (sales extension), I get a blank page. So basically my invoicing no longer works.
    In the data/logs I see the following error:

    Code:
    CRITICAL: Uncaught Exception ParseError: "syntax error, unexpected token ","" at /tmp/lci_oKfblm line 14 {"exception":"[object] (ParseError(code: 0): syntax error, unexpected token \",\" at /tmp/lci_oKfblm:14)"} []
    These are some details about the environment:
    Code:
    [B]EspoCRM Version 6.1.2[/B] [TABLE="class: table"]
    [TR="class: list-row"]
    [TD="class: cell, width: 35%"]Sales Pack[/TD]
     			[TD="class: cell, width: 12%"]1.0.13[/TD]
     		[/TR]
    [/TABLE]
    
    
    php --version
    PHP 8.0.2 (cli) (built: Feb 2 2021 18:26:02) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v4.0.2, Copyright (c) Zend Technologies
    
    httpd -v
    Server version: Apache/2.4.46 (Unix)
    Server built: Oct 14 2020 18:59:56

  • #2
    Hello,
    We can't reproduce the issue. It works as it should.
    Please, provide us with your exported Invoice PDF Template so we could investigate this issue.

    Comment


    • #3
      Originally posted by Maximus View Post
      Hello,
      We can't reproduce the issue. It works as it should.
      Please, provide us with your exported Invoice PDF Template so we could investigate this issue.
      Hello Maximus, I sent you the header + body in a private message + CSV export attached as a zipfile.
      Last edited by SpeedBullet; 02-15-2021, 01:49 PM.

      Comment


      • #4
        Hi,
        I've tried to reproduce the issue on different environments, but it works good.
        Please tell what is your web server php version (you can check it in Administration -> System requirement).

        Comment


        • #5
          PHP Versie 8.0.2
          The only things that aren't OK according to the system requirements, are things like timeouts and filesizes etc... I assume that's not too big of a deal? The white page comes immediately.

          Which code would I need to look into in order to debug this? I'm at a loss why this doesn't work.
          Last edited by SpeedBullet; 02-16-2021, 05:18 PM.

          Comment


          • #6
            Any news? I kinda need to create some invoices. Thanks.

            Comment


            • #7
              I have managed to find more info. I found where the tempfile was generated. Apparently there is a syntax error on line fourteen (the comma behind the closing parenthesis). Where do I find this code? Where does it come from?

              Code:
              sudo cat /tmp/systemd-private-5fdcb31bf79b47c380e4f4e3ead00cac-httpd.service-XKKHY8/tmp/lci_APfIDF
              
              <?php use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
              $helpers = array( 'numberFormat' => function() {
              $args = func_get_args();
              
              if (count($args) !== 2) {
              return null;
              }
              
              $context = $args[count($args) - 1];
              $number = $args[0] ?? null;
              
              if (is_null($number)) {
              return '';
              },
              );
              $partials = array();
              $cx = array(
              'flags' => array(
              'jstrue' => true,
              'jsobj' => true,
              'jslen' => true,
              'spvar' => true,
              'prop' => false,
              'method' => false,
              'lambda' => false,
              'mustlok' => false,
              'mustlam' => false,
              'mustsec' => false,
              'echo' => false,
              'partnc' => false,
              'knohlp' => false,
              'debug' => isset($options['debug']) ? $options['debug'] : 1,
              ),
              'constants' => array(),
              'helpers' => isset($options['helpers']) ? array_merge($helpers, $options['helpers']) : $helpers,
              'partials' => isset($options['partials']) ? array_merge($partials, $options['partials']) : $partials,
              'scopes' => array(),
              'sp_vars' => isset($options['data']) ? array_merge(array('root' => $in), $options['data']) : array('root' => $in),
              'blparam' => array(),
              'partialid' => 0,
              'runtime' => '\LightnCandy\Runtime',
              );
              
              $inary=is_array($in);

              Comment


              • #8
                Please advise...
                The code snippet above shows that the "helpers" function opens with { but doesn't close.
                I landed at vendor/zordius/lightncandy/src/Compiler.php line 100 and Exporter.php line 65.

                Not sure what to do to fix this. Any ideas?

                Comment


                • #9
                  Seems to help... same question though: is this the right way?
                  This issue has appeared after upgrading to PHP8. Parse error: syntax error, unexpected token "*" in /tmp/lci_7myMwD on line 2 I did a search and found the problem and I made a change in this file; ...


                  Why isn't anybody else experiencing this issue?
                  Are you also on php 8.0.2?

                  Comment


                  • #10
                    Hi,
                    sorry for the delayed reply.
                    Try to fix it by removing the coma ',' character after the '}' character in this block
                    PHP Code:
                    if (is_null($number)) {
                    return 
                    '';
                    }, 
                    After, try to build the Invoice again. Don't know whether it is required to clear cache after this change. Rather 'no' than 'yes', but try different ways.

                    Comment


                    • #11
                      Maximus, thanks for your suggestion. I realize the comma is indeed the problem. Deleting it isn't so simple, as the code seems to be auto generated when you click "Print to PDF". This generates a /tmp/lci_xxxxx file with some PHP+html code.

                      By analyzing the generated code, I found this auto-generated code is produced with the zordius/lightncandy vendor package via Compiler.php and Exporter.php.
                      While generating the problematic codesnippet for the "$helpers" variable, the extra comma part is also added. The code is quite complex.

                      Following the suggestion on github (link posted in post #9), this is now solved. The PDF gets printed as expected. However, just like the author of the fix, I wonder if this "fix" is good or just a dirty hack which might cause side effects. Also, this fix is only in my local code. This might be overwritten every time I update espocrm.

                      Comment


                      • #12
                        Hi,
                        Finally, I was able to reproduce the bug. The fix requires to change the coma ',' in the line #65 of the file /vendor/zordius/lightncandy/src/Exporter.php.
                        So steps to fix it:
                        1. Open the file /vendor/zordius/lightncandy/src/Exporter.php.
                        2. Find the line #65 with the context:
                        Code:
                        $ret .= ("            '$name' => " . static::closure($context, $func) . [COLOR=#e74c3c]",\n"[/COLOR]);
                        3. Replace ',' with '}' in the ",\n" element. E.g.:
                        Code:
                        $ret .= ("            '$name' => " . static::closure($context, $func) . [COLOR=#2ecc71]"}\n"[/COLOR]);

                        Comment


                        • #13
                          Maximus, as a matter of fact, I have also tried this and yes it does work.
                          However, the same questions remain: is this safe / doesn't it break other things?

                          Which fix is the most accurate, or put differently why is the suggestion on github not adequate? https://github.com/zordius/lightncandy/issues/348
                          Don't get me wrong, this is no negative reflection on your expertise, I'm just curious and I like to know how this works.

                          Thanks again for your time and effort.
                          Last edited by SpeedBullet; 02-18-2021, 01:14 PM.

                          Comment


                          • #14
                            > However, the same questions remain: is this safe / doesn't it break other things?

                            Our developers team is investigating this fix. I hope soon they will provide a stable fix.

                            Comment


                            • #15
                              Here's my fix:
                              An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ), - fix php 8.0 issue in exporter · yurikuzn/lightncandy@207d424

                              Comment

                              Working...
                              X