Totals and subtotals

Prev Next

Linda is happy because there is not much left to understand about her Quotation template.
However, she wants to look at the totals and subtotals table as it is totally essential. Vijay takes the time to explain this part to her.

Variables on the formatting

You will find in the code of the Quotation template page this section which is dedicated to the formatting of the sub-totals tables.

Depending on the value of the box :

  • Show discount

which is on the Quotation object, the colspans used thereafter are defined differently.

The tag apex:variable

With this tag, you can define a local variable that can be used in place of an expression specified in the component body.

Here is the Salesforce article on this subject: apex:variable.

We use these variables to give different values in the colspan to define the width of the columns of the tables that follow the main table. Let's look at the conditions in detail:

<apex:variable var="colspan1" value="{!IF(sofactoapp__Offre__c.sofactoapp__Afficher_la_remise__c, '6', '5')}" />

<apex:variable var="colspan2" value="{!IF(sofactoapp__Offre__c.sofactoapp__Afficher_la_remise__c, '4', '3')}" />

Reminder: The colspan attribute

The space is managed by the HTML attribute colspan which allows you to set the number of columns a cell should cover. The numbers in the condition refer to the table above (the table in the main structure).

Note: If you want to change this, please pay attention to the CSS of the whole section on subtotals.

Discount

Following the main table, a table on footer discounts is displayed first in this template.

<!-- Remise offre -->

<tr style="display:{!IF (sofactoapp__Offre__c.sofactoapp__Montant_remise_Offre__c >0, '', 'none')}">

<th class="alignleft" colspan="{!colspan2}">                            

<apex:outputText value="{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Raison_pour_remise__c.Label}"/>

</th>

<th class="aligncenter">                              

<apex:outputText value="{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Taux_de_remise__c.Label}"/>

</th>

<th class="aligncenter">                              

<apex:outputText value="{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Montant_remise_Offre__c.Label}"/>

</th>

</tr>

<tr style="display:{!IF (sofactoapp__Offre__c.sofactoapp__Montant_remise_Offre__c >0, '', 'none')}">

<td class="alignleft" colspan="{!colspan2}">

<apex:outputText value="{!sofactoapp__Offre__c.sofactoapp__Raison_pour_remise__c}" />

</td>

<td class="aligncenter" style="white-space:nowrap;">

<apex:outputText value="{0, number, ###.00}%">

<apex:param value="{!sofactoapp__Offre__c.sofactoapp__Taux_de_remise__c}" />

</apex:outputText>

</td>

<td class="alignright">

<apex:outputText value="{!sofactoapp__Offre__c.sofactoapp__Montant_remise_offre__c}" />

</td>

</tr>

The conditions

Let's now focus on the conditions of this part of the code. The entire <tr> is only displayed if the discount amount is greater than 0€.

<tr style="display:{!IF (sofactoapp__Offre__c.sofactoapp__Montant_remise_Offre__c >0, '', 'none')}">

You can also see in the code that the conditions and colspan configuration are present in the header code and in the table body.

Columns:

The headers are taken from the labels of the fields in our application.

Discount Reason:

The Discount Reason field must be filled in on the Quotation.

Discount rate:

The Discount Rate field is also present on the Quotation. The rate displayed on the PDF Quotation is limited to two decimal places.

Discount Amount:

The Discount Amount field is present on the Quotation.

Subtotals Table

This table is composed of three <tr> which contain three <td> each. As with the discount table, the first <td> is always empty. The second contains the header and the third the amount :

Amount excl. VAT

  • The header is the label for the Amount excl. VAT field.
  • The amount before tax corresponds to the Amount excl. VAT field on the Quotation.

VAT Amount

  • The header is the label for the VAT Amount field.
  • The amount before tax corresponds to the VAT Amount field on the Quotation.

Amount incl. VAT

  • The header is the label for the Amount incl. VAT field.
  • The amount before tax corresponds to the Amount incl. VAT field on the Quotation.

Let's get back to the code:

<!-- Total HT -->

<tr>

<td class="borderOff"></td>

<td colspan="{!colspan2}">

<b>{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Montant_HT_apres_remise__c.Label}</b>

</td>

<td class="alignright">

<apex:outputField value="{!sofactoapp__Offre__c.sofactoapp__Montant_HT_apres_remise__c}" />

</td>

</tr>

<!-- TVA -->

<tr>

<td class="borderOff"></td>

<td colspan="{!colspan2}">

<b>{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Montant_TVA_apres_remise__c.Label}</b>

</td>

<td class="alignright">

<apex:outputField value="{!sofactoapp__Offre__c.sofactoapp__Montant_TVA_apres_remise__c}" />

</td>

</tr>

<!-- Total TTC -->

<tr>

<td class="borderOff"></td>

<td colspan="{!colspan2}">

<b>{!$ObjectType.sofactoapp__Offre__c.Fields.sofactoapp__Montant_TTC_total__c.Label}</b>

</td>

<td class="alignright">

<apex:outputField value="{!sofactoapp__Offre__c.sofactoapp__Montant_TTC_total__c}" />

</td>

</tr>

As mentioned above, the structure of these three lines is always the same.

An empty <td>, then the variable width header column {!colspan2} and then the <td> that has the amount.