PDF template of the invoice

Prev Next

Following the implementation and application of the index review, D'Angelo wants to show his colleagues in the sales team, Pedro and Clara, the final step: displaying the indices on the PDF invoices.

From an invoice generated from their subscription, D'Angelo previews the PDF of the invoice:

 

Pedro asks what the revised price comment means. D'Angelo launches into the explanation.    

Explanation of the information displayed on the PDF template

The comment explains the calculation of the indexes:

P0 = the base price.
P1 = the revalued price.
S0 = the reference index coefficient.
S1 = the index coefficient applied.


Let's check the calculation for the first invoice line item Floor cleaning:

P0 = 89 000,00 €
S0 = 1,00
S1 = 1,06
P1 = 89 000,00 € x 1,06 = 94 340,00 €

Clara finds that the display is not very clear, as the decimals are not displayed on the PDF.

D'Angelo looks in the Visualforce code of the PDF template to find why.

Modification of the code of the Visualforce page

If you want to change the display of the index revision in the invoice PDF, this is how you do it.      

Go to the Visualforce page

First, we need to access the Visualforce page.
If you don't have access to the Visualforce pages, you should first read these Salesforce articles:

Steps

1.Go to Setup.
2. Type Pages in the search box.
3. Go to Visualforce Pages.


4. Open your PDF template.


Note: if you do not know the name of your template:
(1) Go to an invoice and preview the PDF by clicking on Create PDF

 
(2) If you drag the mouse over the black bar below the buttons, the template name will be displayed.
 


OK, we have opened the Visualforce page of your invoice. Now let's take a look at the part we're interested in, the indexes.

     

Explanation of the code

To understand the code, let's go through it line by line.
The part we are interested in starts with this comment:

<!-- Indices/ Indexes -->


The structure is as follows:

The whole section that deals with indexes is in a <table> (table), in which there is a <tr> (table row/ table line), in which there is only a <td> (table detail/ table cell).

Display conditions:

Inside the <td> we use a <apex:outputPanel> to put a condition on the display of indices on the invoice.
The condition is !NOT(ISBLANK(sofactoapp__Factures_Client__c.sofactoapp__IndiceId__c))
 

 
If the Index (ID) field is empty on the invoice, the indices will not be displayed on the invoice PDF.

Display on the PDF:

Then you see the hard coded line:

  • Prix révisé selon la formule P1 = P0 x (S1 / S0)

Note:

  1. This is not good practice, as a custom label should be used to make it easier to change this information, without having to touch the Visualforce page each time it is changed, and to make a translation easily.

  2. If you want to take advantage of this to make your code cleaner, here is the article that explains how to display a custom label in a Visualforce page: PDF templates - How to customize your Visualforce template

  3. However, we have opted for the hard-coded addition, as this allows you to save the code, without having to create custom labels first.


The second line shows the explanation for S0:

S0 = indice {!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Indice__r.Name}
  • S0 = index (also hard-coded).

  • Name you have given to the index related to the subscription.

<apex:param value="{!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Date_indice_reference__c}" />
  • The reference index date of the subscription

 <apex:outputText value="{!FLOOR(sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Coefficient_indice_reference__c)}" />
  • The coefficient of the subscription reference index

The third line shows the explanation for S1:

 <apex:outputText value="S1 = indice {!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Indice__r.Name}
  • S1 = index (also hard-coded).

  • Name you have given to the index related to the subscription.

 <apex:param value="{!sofactoapp__Factures_Client__c.sofactoapp__Date_indice__c}" />
  • The index date of the invoice

 <apex:outputText value="{!FLOOR(sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Coefficient_indice_reference__c)}" />
  • The coefficient of the invoice index

 <apex:outputText value="{!FLOOR(sofactoapp__Factures_Client__c.sofactoapp__Coefficient_indice_date__c)}" /> 
  • Index coefficient at date of invoice

 

If, following this explanation, you want to embellish this part of your invoice, here are the articles that will help you


And here is the full code, if you want to add it to your Visualforce page.

Full code to copy

<!-- Indices/ Indexes -->

<table>
<tr>
<td class="borderOff">
<apex:outputPanel layout="none" rendered="{!NOT(ISBLANK(sofactoapp__Factures_Client__c.sofactoapp__IndiceId__c))}">
<br />
<br />Prix révisé selon la formule P1 = P0 x (S1 / S0)
<br />
<apex:outputText value="S0 = indice {!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Indice__r.Name} {0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Date_indice_reference__c}" />
</apex:outputText>
&nbsp;=&nbsp;
<apex:outputText value="{!FLOOR(sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Coefficient_indice_reference__c)}" />
<br />
<apex:outputText value="S1 = indice {!sofactoapp__Factures_Client__c.sofactoapp__Abonnement__r.sofactoapp__Indice__r.Name} {0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!sofactoapp__Factures_Client__c.sofactoapp__Date_indice__c}" />
</apex:outputText>
&nbsp;=&nbsp;
<apex:outputText value="{!FLOOR(sofactoapp__Factures_Client__c.sofactoapp__Coefficient_indice_date__c)}" />
<br />
</apex:outputPanel>
</td>
</tr>
</table>

Correction of the display of coefficients

D'Angelo has found the hidden defect for the decimals! On the coefficients, the function FLOOR is applied. So the coefficients are displayed without decimals.
He still looks in the Salesforce article: Fonction floor to better understand.

Then it connects to its updated partial copy sandbox to test the display if it removes the FLOOR function for both coefficients on the Visualforce page, but the result is that the coefficients are displayed with 4 decimal places.

He reads again the article PDF templates - How to beautify your PDF template.
Then he uses this code:

<apex:outputText value="{0, number, ###.00}">
<apex:param value="{!sofactoapp__Factures_Client__c.sofactoapp__Coefficient_indice_date__c}"/>
</apex:outputText>


for both coefficients, and this is the display on the PDF :


Clara and Pedro are really happy with the result. They just tell their colleagues not to type the word Clue in the name of the clues, to avoid redundancy of the word on the PDF invoices.