Advanced PDF for saved search
I have made a saved search and I have managed to filter it using one of the columns and then use if else statements to break the report down into departmental sections, with a total for each department at the bottom.
Everything is pretty much perfect except the department field is listed next to every name, as the items are grouped into departmental sections this is not necessary.
Is there a way I can just show the department field on the first line, and not show it again until it changes? I have been trying to thing of a statement or way of doing this and I just cant think of it.
Here if the if else code so far
</thead>
<!– Initialise some variables for the first dept line we encounter –>
<#assign last_dept_line = result.dept >
<#assign pay_amount = 0 >
</#if>
<!– If the current dept is different than the last one, print a subtotal line –>
<#if last_dept_line != result.dept >
<tr style=”background-color: #e3e3e3;”>
<td align=”right” colspan=”23″>
Subtotal for ${last_dept_line}:
</td>
<td align=”right” colspan=”4″>
$${pay_amount?string[“,##0.001″]}
</td>
</tr>
<!– Update the dept_line and pay_amount variables –>
<#assign last_dept_line = result.dept >
<#assign pay_amount = 0 >
</#if>
<!– Add the current line’s amount to pay_amount –>
<#assign pay_amount = pay_amount + result.amount >
<tr>
<td align=”center” colspan=”3″ line-height=”150%”>${item.quantity}</td>
<td colspan=”9″><span class=”itemname”>${result.name}</span><br /4{result.rate}</td>
<td colspan=”3″4{result.hrs}</td>
<td colspan=”/”>${result.days}</td>
<td colspan=”3″4{result.dept}</td>
<td align=”right” colspan=”4″>${result.rate}</td>
<td align=”right” colspan=”4″4{result.amount}</td>
</tr>
</#list><!– end items –>
<!– Write a subtotal line after the last line –>
<tr style=”background-color: #e3e3e3;”>
<td align=”right” colspan=”23″›
Total for ${last_dept_line}:
</td>
<td align=”right” colspan=”4″>
${pay_amount?string[“,##0.00”]}
</td>
</tr>
</table>
Essentially what I would like is to add the department on the first line and not thereafter.
Thanks.
Chris Abbott
Could you please share a sample of the output that you are seeing?
mercedes_brokenrubik
I don’t quite visualize it without the output, but I would imagine something like this:
<#list [‘a’, ‘a’, ‘a’, ‘b’, ‘c’] as record >
<#if last_dpt??>
<#if last_dpt != record>
${record}
</#if>
<#else>
${record}
</#if>
<#global last_dpt=record >
</#list>