->set_where( $report->{where} )
->set_having( $report->{having} )
->set_order_by( $report->{order_by} )
+ ->set_do_rollup( $report->{do_rollup} )
->set_pivot_data( $report->{pivot_data} )
->set_pivot_label( $report->{pivot_label} )
->set_pivot_default( $report->{pivot_default} );
return $self->{_is_subquery};
}
+sub do_rollup {
+ my $self = shift;
+ return $self->builder->{_do_rollup};
+}
+
sub pivot_data {
my $self = shift;
return $self->builder->{_pivot_data};
return $self->builder->{_pivot_default};
}
+sub set_do_rollup {
+ my $self = shift;
+ my $p = shift;
+ $self->builder->{_do_rollup} = $p if (defined $p);
+ return $self;
+}
+
sub set_pivot_default {
my $self = shift;
my $p = shift;
my @group_by = $self->group_by_list;
- $sql .= ' GROUP BY ' . join(', ', @group_by) . "\n" if (@group_by);
+ # The GROUP BY clause is used to generate distinct rows even if there are no aggregates in the select list
+ my $rollup_start = 'ROLLUP (';
+ my $rollup_end = ')';
+
+ $rollup_start = $rollup_end = ''
+ if (!$self->do_rollup or scalar(@group_by) == scalar(@{$self->{_select}})); # No ROLLUP if there are no aggregates, or not requested
+
+ $sql .= " GROUP BY $rollup_start" . join(', ', @group_by) . "$rollup_end\n" if (@group_by);
$sql .= " HAVING " . join("\n\tAND ", map { $_->toSQL } @{ $self->{_having} }) . "\n" if (@{ $self->{_having} });
$sql .= ' ORDER BY ' . join(', ', map { $_->toSQL } @{ $self->{_order_by} }) . "\n" if (@{ $self->{_order_by} });
$b->register_params( $report_data );
$r->{resultset} = $b->parse_report( OpenSRF::Utils::JSON->JSON2perl( $r->{report}->{template}->{data} ) );
+ $r->{resultset}->set_do_rollup($report_data->{__do_rollup}) if $report_data->{__do_rollup};
$r->{resultset}->set_pivot_data($report_data->{__pivot_data}) if $report_data->{__pivot_data};
$r->{resultset}->set_pivot_label($report_data->{__pivot_label}) if $report_data->{__pivot_label};
$r->{resultset}->set_pivot_default($report_data->{__pivot_default}) if $report_data->{__pivot_default};
<!ENTITY reports.oils_rpt_editor.store_report_definition "Choose a folder to store this report definition: ">
<!ENTITY reports.oils_rpt_editor.selected_folder "Selected Folder: ">
<!ENTITY reports.oils_rpt_editor.output_options "Output Options">
+<!ENTITY reports.oils_rpt_editor.do_rollup "Calculate grouping subtotals">
<!ENTITY reports.oils_rpt_editor.excel_output "Excel Output">
<!ENTITY reports.oils_rpt_editor.csv_output "CSV Output">
<!ENTITY reports.oils_rpt_editor.html_output "HTML Output">
<ul>
<li><input type="checkbox" id="oils_rpt_format_excel" value="t" checked="checked"/><span>&reports.oils_rpt_editor.excel_output;</span></li>
<li><input type="checkbox" id="oils_rpt_format_csv" value="t"/><span>&reports.oils_rpt_editor.csv_output;</span></li>
+ <li><input type="checkbox" id="oils_rpt_editor_do_rollup" value="1" checked="checked"/><span>&reports.oils_rpt_editor.do_rollup;</span></li>
<li>
<input type="checkbox" id="oils_rpt_format_html" value="t" checked="checked"/>&reports.oils_rpt_editor.html_output;
<ul>
setSelector(DOM.oils_rpt_editor_pivot_label, rpt_data.__pivot_label);
if (rpt_data.__pivot_data)
setSelector(DOM.oils_rpt_editor_pivot_data, rpt_data.__pivot_data);
+ DOM.oils_rpt_editor_do_rollup.checked = rpt_data.__do_rollup == '1';
}
if (run = this.last_run) {
data.__pivot_label = getSelectorVal(DOM.oils_rpt_editor_pivot_label);
data.__pivot_data = getSelectorVal(DOM.oils_rpt_editor_pivot_data);
}
-
+ data.__do_rollup = DOM.oils_rpt_editor_do_rollup.checked ? '1' : '0';
data = js2JSON(data);
_debug("complete report data = "+data);