salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.3k stars 2.04k forks source link

Invoice - Line Items: Groups - fields breaks PDFs #2170

Open SpudR opened 7 years ago

SpudR commented 7 years ago

Issue

Whilst I was looking for a field that was simply the unit cost x the quantity (which there doesn't seem to be - can you tell me?) I found this:

I have a PDF template which I have inserted all the possible price options from all the fields (to verify which value is correct). If I enter anything from the Invoices >> Line Items: Groups drop box, then the PDF breaks - sometimes it's blank, sometimes it generates that field then shows field names for any other results.

Grab the below, then manually insert the field name in the appropriate table cell - then create a PDF from an invoice (preferably with multiple items and quantities)

Here's the HTML so you don't have to manually enter it all:

<p> </p>
<p>$aos_products_quotes_product_qty x $aos_products_quotes_name @ </p>
<p>Here</p>
<div style="float: left;">
<table border="0">
<tbody>
<tr>
<td>Path</td>
<td>Value</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Total &gt;&gt; </td>
<td>$aos_invoices_total_amt</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Total (default Currency) &gt;&gt;</td>
<td>$aos_invoices_total_amt_usdollar</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Subtotal &gt;&gt;</td>
<td>$aos_invoices_subtotal_amount</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Subtotal (default Currency) &gt;&gt;</td>
<td>$aos_invoices_subtotal_amount_usdollar</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Tax &gt;&gt; </td>
<td>$aos_invoices_tax_amount</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Tax (default Currency) &gt;&gt;</td>
<td>$aos_invoices_tax_amount_usdollar</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Grand Total &gt;&gt;</td>
<td>$aos_invoices_total_amount</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Grand Total (default Currency) &gt;&gt;</td>
<td>$aos_invoices_total_amount_usdollar</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Subtotal + Tax &gt;&gt;</td>
<td>$aos_invoices_subtotal_tax_amount</td>
</tr>
<tr>
<td>Invoices &gt;&gt; Grand Total (default Currency) &gt;&gt;</td>
<td>$aos_invoices_subtotal_tax_amount_usdollar</td>
</tr>
</tbody>
</table>
</div>
<div style="float: left;">
<table border="0">
<tbody>
<tr>
<td>Path</td>
<td>Value</td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Total &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Total (default Currency) &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Subtotal &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Subtotal (default Currency) &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Tax &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Tax (default Currency) &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Subtotal + Tax &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Subtotal + Tax (default Currency) &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Group Total &gt;&gt; </td>
<td> </td>
</tr>
<tr>
<td>Line Items: Groups &gt;&gt; Group Total (default Currency) &gt;&gt; </td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div style="float: left;">
<table border="0">
<tbody>
<tr>
<td>Path </td>
<td>Value </td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Cost Price &gt;&gt; </td>
<td>$aos_products_quotes_product_cost_price</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Cost Price (default Currency) &gt;&gt;</td>
<td>$aos_products_quotes_product_cost_price_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; List Price &gt;&gt; </td>
<td>$aos_products_quotes_product_list_price</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; List Price (default Currency) &gt;&gt; </td>
<td>$aos_products_quotes_product_list_price_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Unit Price &gt;&gt;</td>
<td>$aos_products_quotes_product_unit_price</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Unit Price (default Currency) &gt;&gt; </td>
<td>$aos_products_quotes_product_unit_price_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Tax Amount &gt;&gt; </td>
<td>$aos_products_quotes_vat_amt</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Tax Amount (default Currency) &gt;&gt; </td>
<td>$aos_products_quotes_vat_amt_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Total Price &gt;&gt; </td>
<td>$aos_products_quotes_product_total_price</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Total Price (default Currency) &gt;&gt; </td>
<td>$aos_products_quotes_product_total_price_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Cost &gt;&gt;</td>
<td>$aos_products_cost</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Cost (default Currency) &gt;&gt; </td>
<td>$aos_products_cost_usdollar</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Price &gt;&gt; </td>
<td>$aos_products_price</td>
</tr>
<tr>
<td>Line Items: Products &gt;&gt; Price (default Currency) &gt;&gt; </td>
<td>$aos_products_price_usdollar</td>
</tr>
</tbody>
</table>
</div>
<div style="float: left;">
<table border="0">
<tbody>
<tr>
<td>Path </td>
<td>Value</td>
</tr>
<tr>
<td>Line Items: Services &gt;&gt; Sale Price &gt;&gt; </td>
<td>$aos_services_quotes_service_unit_price</td>
</tr>
<tr>
<td>Line Items: Services &gt;&gt; Total &gt;&gt; </td>
<td>$aos_services_quotes_service_total_price</td>
</tr>
</tbody>
</table>
</div>

Looks like it's broken in the demo too...

Expected Behavior

The PDF is created with all appropriate fields completed

Actual Behavior

PDF breaks (blank or just shows field names)

Steps to Reproduce

As above

Context

It's hard to find the correct field to enter in PDF templates, but this helps to identify the correct field.

Your Environment

shogunpol commented 7 years ago

The issue has been tested on recent version of SuiteCRM(7.7.4), and it appear, We will label this issue as a bug. @SpudR , thanks for raise this issue.

vladbar commented 7 years ago

Hello SpudR, thank you for the very good explanation of the problem and a good test example.

The reason why your test fails is that you don't follow the proper template structure.

For instance in case of group line items, the template need to "know" where the group starts - $aos_line_item_groups_name (please see the default Invoices -> Invoice Group Sample template).

If this variable is omitted, then in case of your test example, the following code modules/AOS_PDF_Templates/generatePdf.php function populate_group_lines() line 198 $parts = explode($firstValue, $text); will split the template into 3 parts instead of 2 parts as the first item it splits on is $aos_line_item_groups_total_amt and there is a similar variable $aos_line_item_groups_total_amt_usdollar, so it will split on this variable also. Then it processes the wrong parts and finally fails.

There are two possible options here:

  1. Either use a proper structure for the templates (see sample templates).
  2. Mark it as an enhancement and replace $parts = explode($firstValue, $text); with something like $parts = preg_split($exact_regex, $text);
SpudR commented 7 years ago

Ok - could you please update my test template to use this variable and therefore work? Should be a fairly easy thing to add a table row or two in there :)

vladbar commented 7 years ago

Adding just this variable will not help - in your template you also use Line Items: Services and Line Items: Products. Both of them would need to follow their related template structures.

vladbar commented 7 years ago

So instead of adding fields to the test template that you provided, the fields should be added to the appropriate templates with the correct structure. This will make it work. I tested all the fields listed in your template in the correct templates.

SpudR commented 7 years ago

Not sure I'm following this then - are you saying that these variables cannot be mixed? That each set of variables must follow its own structure? As you can see from my template you can show all the variables mentioned except the 'Line items: Groups' members... ???

halest commented 7 years ago

@SpudR I've just spent way too much time figuring this out. Instead ot the theoretical advice above, here is the practical solution: You need to put $aos_line_item_groups_total_amount at the end of the table so that the engine knows where to stop the grouping process:

`

$aos_line_item_groups_name
Menge Produkt Einzelpreis Gesamt
$aos_products_quotes_product_qty $aos_products_quotes_name $aos_products_quotes_product_unit_price € $aos_products_quotes_product_total_price €
$aos_products_quotes_item_description
Gruppensumme: $aos_line_item_groups_total_amount €
`