Sub-totalling with List Builder
set groupby "stage_description"
2. Add a new groupby section to end of the list. "type multivar" just tells List Builder to tell ad_page_contract that the groupby is not a multiple element. All the curly brackets are unfortunately needed – the first list element is the text which is displayed in front of each group; you can put HTML tags and more in here. The second list element tells List Builder that we are grouping by stage_description – this seems repetitive so maybe there’s a better way to do this, but I can't see any issues with it. You can also have an orderby clause in here if you need one.
-groupby {
type multivar
values {
{ {[_ payment.Financial_Stage]} { {groupby stage_description} } }
}
}
3. Modify the financial_amount element to add aggregation information. aggregate can be one of “sum”, “average” or “count”. The aggregate_group_label allows you to put some text and a currency symbol before each sub-total. aggregate_label does the same for the grand total.
financial_amount {
label "[_ payment.Amount]"
aggregate "sum"
aggregate_group_label "[_ payment.Sub-Total]: [lc_get -locale $locale currency_symbol]"
aggregate_label "[_ payment.Grand-Total]: [lc_get -locale $locale currency_symbol]"
}
4. Gotchas to look out for:
you need to use the -pass_properties section to allow List Builder to see program variables outside the list scope e.g. $locale.
List builder doesn't differentiate between currency and numbers – it just treats the aggregated column as a number. However, it does use the acs-lang formatting when displaying (specifically lc_numeric), which should be good enough for most cases. You need to do your own formatting on the individual line items. Here's how to use display_eval to format the financial_amount element:
display_eval {[lc_monetary -label_p "t" $financial_amount $locale ]}
Noquoting can be painful but the following workaround should suffice – note the triple underscore:
display_template {@financial.financial_amount___display;noquote@}
Our finished example:
-elements {
stage_description {
label "[_ payment.Financial_Stages]"
}
financial_amount {
label "[_ payment.Amount]"
aggregate "sum"
aggregate_group_label "[_ payment.Sub-Total]: [lc_get -locale $locale currency_symbol]"
aggregate_label "[_ payment.Grand-Total]: [lc_get -locale $locale currency_symbol]"
display_eval {[lc_monetary -label_p "t" $financial_amount $locale ]}
display_template {@financial.financial_amount___display;noquote@}
}
}
-groupby {
type multivar
values {
{ {[_ payment.Financial_Stage]} { {groupby stage_description} } }
}
}
A good example from OpenACS CVS:
04:48 PM, 14 Mar 2007 by Brian Fenton Permalink | Comments (0)
| January 2007 | ||||||
| S | M | T | W | T | F | S |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Request notifications