Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDF maker outputs variable name when empty
#1
I updated my CoreBOS install to the latest files, github dated 4-11-2015. I've got it all working pretty nicely, but have one problem. I used to make PDF templates that output either a product or a service, based on what was listed. I used variables for both in the same table cell, since an empty value would just not be shown.

For instance, I could use
Code:
$PRODUCT_NAME$ $SERVICE_NAME$
which would output an empty string for productname when the line is a service and an empty string for servicename when the line was a product. I did NOT update PDF maker, but the behaviour has changed, I can no longer do this because for instance when I have a line that is product, the PDF will also output $SERVICE_NAME$.

In other words, the system doesn't recognise these values as variables anymore when they're empty.

Check image to see what I mean


Attached Files Thumbnail(s)
   
Reply
#2
Hi.

You are using the incorrect variables. If you try to print the product/service lines, you need to put this variable between the #PRODUCTBLOC_START# and #PRODUCTBLOC_END#.
But you have to use "Common fields for Products & Services" picklist. This picklist has the variable that you need.

Only you can use the picklist: Available fields for Products or Available fields for Services, if your are sure that you print a product or service.
Reply
#3
Hi Omar,

Well this sounds viable, but the behaviour used to be different, and this 'old' behaviour is what we need. When you create say a quote and you want to offer a product and the time needed to install that product on site, you need to be able to quote both products and services on one quote.

Keep in mind this used to work, and I have not changed my PDF maker version or anything in the PDF templates. I just updated coreBOS.

In the old behaviour, maybe the variable name for products would not exist on a line for a service, but that would result in a service description and leave the product variables blank. This way I could list products and services in one quote. Now I cannot, because any service would have the product variable name and vice versa. In the mixed dropdown, I can only choose the description, not the names. And I can't use any custom fields for products this way (we use a custom field for the brand name).

EDIT
Yes we are using the variables between the productblocks, as I said these templates used to work fine and nothing has changed in them. I've been using PDF maker for years and built all templates myself.

Let me be more specific about my problem by posting an example from one of my templates:

Code:
<div>#PRODUCTBLOC_START#</div>

<table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse; font-family:arial; font-size:10pt; width:100%">
    <tbody>
        <tr>
            <td style="text-align:left; vertical-align:top; width:35%">
            <p><strong>$PRODUCTS_CF_543$ $PRODUCTS_PRODUCTNAME$</strong></p>

            <p><span style="font-size:10px"><span style="font-family:arial,helvetica,sans-serif">$PRODUCTS_DESCRIPTION$</span></span></p>

            <p><strong>$SERVICES_SERVICENAME$</strong></p>

            <p><span style="font-family:verdana; font-size:x-small">$SERVICES_DESCRIPTION$</span></p>
            </td>
            <td style="width:30%">$PRODUCTS_IMAGENAME$</td>
            <td style="text-align:center; width:10%">$PRODUCTQUANTITY$ Stuk(s)</td>
            <td style="text-align:right; width:25%">
            <table border="0" cellpadding="0" cellspacing="0" style="font-size:12px; width:100%" summary="">
                <tbody>
                    <tr>
                        <td style="height:25px; width:50%">Bruto:</td>
                        <td style="width:10%">$CURRENCYSYMBOL$</td>
                        <td style="text-align:right; width:40%">$PRODUCTTOTAL$</td>
                    </tr>
                    <tr>
                        <td style="height:25px; width:50%">Korting:</td>
                        <td style="width:10%">$CURRENCYSYMBOL$</td>
                        <td style="text-align:right; width:40%">$PRODUCTDISCOUNT$</td>
                    </tr>
                    <tr>
                        <td style="height:25px; width:50%"><strong>Netto:</strong></td>
                        <td style="text-align:right; width:10%"><strong>$CURRENCYSYMBOL$</strong></td>
                        <td style="text-align:right; width:40%"><strong>$PRODUCTSTOTALAFTERDISCOUNT$</strong></td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>

<hr />
<div>#PRODUCTBLOC_END#</div>

In the above (note that I wrapped the productblocs in DIV's because else the WYSIWYG editor will wrap them in P tags that create unwanted line spaces) example look at the first table cell.

It starts with the Product brand name (The customfield 543) and the product name. Next line is the product description. After that the same for services, in the same table cell. Now in the old behaviour, let's say we are quoting a product. There will be nothing for service name and service description. The template would output the product brand name, product name and product description and leave the service part blank because there was no service.

The other way around also worked. When the template would reach a service, the product stuff would be left blank and the line would output as if there were no product variables in place. This way, the template would be flexible and would self-decide, no matter what was thrown at it.

In the new behaviour, let's say we have a product quoted, this would work fine but also the variable names for services would be printed, as in the attached image from post 1.

This also poses a problem for the image tag. If we output a template that has multiple products, some of which have no image, or no image was chosen when generating the PDF, the template will output the variable name "$PRODUCTS_IMAGENAME$" in stead of just leaving the table cell empty.

I hope this clears up what I mean.
Reply
#4
Another example of my problem: check out the two attached images. One is the letterhead from an invoice that has a contact assigned to it. The second line shows the contact name as excepted. The second one is the letterhead of an invoice using the exact same template, but this invoice doesn't have a contact related to it. It's quite clear that PDF maker doesn't understand this anymore, and prints the variable names. I shall do some more testing to see if I can locate this.

If anyone has any idea how this can happen I'd be very happy to get some clues. This problem is holding me back to update the entire system at this point, I've got all other issues sorted out.

I've been looking around in the PDF maker files, as far as they aren't encrypted (I get it, it's commercial so they have to protect it, not a complaint).

I've noticed in PDFMaker.php there is a private method called "mpdf_processing":
Code:
private function mpdf_processing(&$mpdf, $templateid, $when) {
        $path = 'modules/PDFMaker/mpdf_processing/';
        switch ($when) {
            case "pre":
                $filename = 'preprocessing.php';
                $functionname = 'pdfmaker_mpdf_preprocessing';
                break;
            case "post":
                $filename = 'postprocessing.php';
                $functionname = 'pdfmaker_mpdf_postprocessing';
                break;
        }
        if (is_file($path . $filename) && is_readable($path . $filename)) {
            require_once($path . $filename);
            $functionname($mpdf, $templateid);
        }
    }

I thnk maybe somewhere in this processing there is an issue, but the weird thing is, I can't find the folder 'modules/PDFMaker/mpdf_processing/'. It doesn't exist in respect to the root.

Basically the 'generate PDF button' fires the 'CreatePDFFromTemplate' action, which is a file that does nothing but include 'checkGenerate.php'. That last file is totally encrypted, so I'm at a dead end.


Attached Files Thumbnail(s)
       
Reply
#5
About the variable notation inside PDF maker (the $VARNAME$), it is different than Smarty notation we see in tpl files. Does anyone know how and where these variable names into information to be retrieved from the database? Maybe I can continue my search here.
Reply
#6
Hi.

I've been doing some tests and you have reason, there is something that we change in corebos that affect to pdfmaker.

I'm trying to fix this problem and inform you here when you can update.
Reply
#7
Ah great, thanks a million for the effort. If you have the time please post here what the problem was, so I can learn from it.
Reply
#8
The problem was fixed. You can update your code.

We introduce this problem when we sync all the modules with the vtlib module code base. The directory to create a new module.
In the construct before we call the function getColumnFields("Contacts" or "Service", ...) but now we have getColumnFields($currentModule).
This was the problem, because the current module when call to construct was "PDFMaker" and not the related module.

Now we use the class name for not have this kind of problems.

You can do a git pull in your code and you can see the next commits:

https://github.com/tsolucio/corebos/comm...966f2fd366
https://github.com/tsolucio/corebos/comm...c75c119463

Thank you for find this problem and contribute to the project.

Regards,

Omar.
Reply
#9
You are a genius. I will study this and see what I can learn. In the meantime it seems like it's working again.
Reply
#10
Thank you and wellcome! :-)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)