Revision 40e0911a
Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt
SL/Controller/Helper/ReportGenerator.pm | ||
---|---|---|
report_generator_list_objects
|
||
);
|
||
|
||
sub _setup_action_bar {
|
||
my ($self, $type) = @_;
|
||
|
||
my $key = $::form->{CONTROLLER_DISPATCH} ? 'action' : 'report_generator_form.report_generator_dispatch_to';
|
||
my $value = $::form->{CONTROLLER_DISPATCH} ? $::form->{CONTROLLER_DISPATCH} . "/" : '';
|
||
|
||
$::request->layout->get('actionbar')->add(
|
||
action => [
|
||
$type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
|
||
submit => [ '#report_generator_form', { $key => "${value}report_generator_export_as_${type}" } ],
|
||
],
|
||
action => [
|
||
$::locale->text('Back'),
|
||
submit => [ '#report_generator_form', { $key => "${value}report_generator_back" } ],
|
||
],
|
||
);
|
||
}
|
||
|
||
sub action_report_generator_export_as_pdf {
|
||
my ($self) = @_;
|
||
|
||
... | ... | |
|
||
$::form->{copies} = max $::myconfig{copies} * 1, 1;
|
||
$::form->{title} = $::locale->text('PDF export -- options');
|
||
|
||
_setup_action_bar($self, 'pdf'); # Sub not exported, therefore don't call via object.
|
||
|
||
$::form->header;
|
||
print $::form->parse_html_template('report_generator/pdf_export_options', {
|
||
'HIDDEN' => \@form_values,
|
||
... | ... | |
my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
|
||
|
||
$::form->{title} = $::locale->text('CSV export -- options');
|
||
|
||
_setup_action_bar($self, 'csv'); # Sub not exported, therefore don't call via object.
|
||
|
||
$::form->header;
|
||
print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
|
||
}
|
||
... | ... | |
$params{report}->add_data(\%data);
|
||
}
|
||
|
||
my %options = %{ $params{options} || {} };
|
||
$options{action_bar} //= $params{action_bar};
|
||
|
||
if ($params{layout}) {
|
||
return $params{report}->generate_with_headers(%{ $params{options} || {}});
|
||
return $params{report}->generate_with_headers(%options);
|
||
} else {
|
||
my $html = $params{report}->generate_html_content(%{ $params{options} || {}});
|
||
my $html = $params{report}->generate_html_content(%options);
|
||
$self->render(\$html , { layout => 0, process => 0 });
|
||
}
|
||
}
|
||
... | ... | |
An optional hash reference that's passed verbatim to the function
|
||
L<SL::ReportGenerator/generate_with_headers>.
|
||
|
||
=item C<action_bar>
|
||
|
||
If the buttons for exporting PDF and/or CSV variants are included in
|
||
the action bar. Otherwise they're rendered at the bottom of the page.
|
||
|
||
The value can be either a specific action bar instance or simply 1 in
|
||
which case the default action bar is used:
|
||
C<$::request-E<gt>layout-E<gt>get('actionbar')>.
|
||
|
||
=back
|
||
|
||
=back
|
SL/ReportGenerator.pm | ||
---|---|---|
|
||
use Data::Dumper;
|
||
use List::Util qw(max);
|
||
use Scalar::Util qw(blessed);
|
||
use Text::CSV_XS;
|
||
#use PDF::API2; # these two eat up to .75s on startup. only load them if we actually need them
|
||
#use PDF::Table;
|
||
... | ... | |
}
|
||
|
||
if ($format eq 'html') {
|
||
my $content = $self->generate_html_content(%params);
|
||
my $title = $form->{title};
|
||
$form->{title} = $self->{title} if ($self->{title});
|
||
$form->header(no_layout => $params{no_layout});
|
||
$form->{title} = $title;
|
||
|
||
print $self->generate_html_content();
|
||
print $content;
|
||
|
||
} elsif ($format eq 'csv') {
|
||
# FIXME: don't do mini http in here
|
||
... | ... | |
}
|
||
|
||
sub prepare_html_content {
|
||
my $self = shift;
|
||
my ($self, %params) = @_;
|
||
|
||
my ($column, $name, @column_headers);
|
||
|
||
... | ... | |
'DATA_PRESENT' => $self->{data_present},
|
||
'CONTROLLER_DISPATCH' => $opts->{controller_class},
|
||
'TABLE_CLASS' => $opts->{table_class},
|
||
'SKIP_BUTTONS' => !!$params{action_bar},
|
||
};
|
||
|
||
return $variables;
|
||
}
|
||
|
||
sub setup_action_bar {
|
||
my ($self, $action_bar, $variables) = @_;
|
||
|
||
my @actions;
|
||
foreach my $type (qw(pdf csv)) {
|
||
next unless $variables->{"ALLOW_" . uc($type) . "_EXPORT"};
|
||
|
||
my $key = $variables->{CONTROLLER_DISPATCH} ? 'action' : 'report_generator_dispatch_to';
|
||
my $value = "report_generator_export_as_${type}";
|
||
$value = $variables->{CONTROLLER_DISPATCH} . "/${value}" if $variables->{CONTROLLER_DISPATCH};
|
||
|
||
push @actions, action => [
|
||
$type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
|
||
submit => [ '#report_generator_form', { $key => $value } ],
|
||
];
|
||
}
|
||
|
||
if (scalar(@actions) > 1) {
|
||
@actions = (
|
||
combobox => [
|
||
action => [ $::locale->text('Export') ],
|
||
@actions,
|
||
],
|
||
);
|
||
}
|
||
|
||
$action_bar = ($::request->layout->get('actionbar'))[0] unless blessed($action_bar);
|
||
$action_bar->add(@actions) if @actions;
|
||
}
|
||
|
||
sub generate_html_content {
|
||
my $self = shift;
|
||
my $variables = $self->prepare_html_content();
|
||
my ($self, %params) = @_;
|
||
my $variables = $self->prepare_html_content(%params);
|
||
|
||
$self->setup_action_bar($params{action_bar}, $variables) if $params{action_bar};
|
||
|
||
my $stuff = $self->{form}->parse_html_template($self->{options}->{html_template}, $variables);
|
||
return $stuff;
|
||
... | ... | |
my $content = $pdf->stringify();
|
||
|
||
$main::lxdebug->message(LXDebug->DEBUG2(),"addattachments ?? =".$form->{report_generator_addattachments}." GL=".$form->{GL});
|
||
if ( $form->{report_generator_addattachments} eq 'yes' && $form->{GL}) {
|
||
if ($form->{report_generator_addattachments} && $form->{GL}) {
|
||
$content = $self->append_gl_pdf_attachments($form,$content);
|
||
}
|
||
|
bin/mozilla/reportgenerator.pl | ||
---|---|---|
}
|
||
|
||
|
||
sub report_generator_setup_action_bar {
|
||
my ($type, %params) = @_;
|
||
|
||
$::request->layout->get('actionbar')->add(
|
||
combobox => [
|
||
action => [
|
||
$type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
|
||
submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_export_as_${type}" } ],
|
||
],
|
||
action => [
|
||
$::locale->text('PDF export with attachments'),
|
||
submit => [ '#report_generator_form', { report_generator_dispatch_to => "report_generator_export_as_pdf", report_generator_addattachments => 1 } ],
|
||
only_if => $params{allow_attachments},
|
||
],
|
||
],
|
||
action => [
|
||
$::locale->text('Back'),
|
||
submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_back" } ],
|
||
],
|
||
);
|
||
}
|
||
|
||
sub report_generator_export_as_pdf {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
... | ... | |
$form->{copies} = max $myconfig{copies} * 1, 1;
|
||
|
||
my $allow_font_selection = 1;
|
||
my $allow_attachments = 0;
|
||
eval { require PDF::API2; };
|
||
$allow_font_selection = 0 if ($@);
|
||
$allow_attachments = 1 if $form->{report_generator_hidden_l_attachments};
|
||
|
||
$form->{title} = $locale->text('PDF export -- options');
|
||
|
||
report_generator_setup_action_bar('pdf', allow_attachments => !!$form->{report_generator_hidden_l_attachments});
|
||
|
||
$form->header();
|
||
print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN' => \@form_values,
|
||
'ALLOW_ATTACHMENTS' => $allow_attachments,
|
||
'ALLOW_FONT_SELECTION' => $allow_font_selection, });
|
||
|
||
$main::lxdebug->leave_sub();
|
||
... | ... | |
my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
|
||
|
||
$form->{title} = $locale->text('CSV export -- options');
|
||
|
||
report_generator_setup_action_bar('csv');
|
||
|
||
$form->header();
|
||
print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
|
||
|
locale/de/all | ||
---|---|---|
'CN' => 'Kd-Nr.',
|
||
'CR' => 'H',
|
||
'CSS style for pictures' => 'CSS Style für Bilder',
|
||
'CSV export' => 'CSV-Export',
|
||
'CSV export -- options' => 'CSV-Export -- Optionen',
|
||
'CSV import: ar transactions' => 'CSV Import: Debitorenbuchungen',
|
||
'CSV import: bank transactions' => 'CSV Import: Bankbewegungen',
|
||
... | ... | |
'PAYMENT POSTED' => 'Rechnung gebucht',
|
||
'PDF' => 'PDF',
|
||
'PDF (OpenDocument/OASIS)' => 'PDF (OpenDocument/OASIS)',
|
||
'PDF export' => 'PDF-Export',
|
||
'PDF export -- options' => 'PDF-Export -- Optionen',
|
||
'PDF export with attachments' => 'Als PDF mit Anhängen exportieren',
|
||
'PLZ Grosskunden' => 'PLZ Grosskunden',
|
||
'POSTED' => 'Gebucht',
|
||
'POSTED AS NEW' => 'Als neu gebucht',
|
templates/webpages/report_generator/csv_export_options.html | ||
---|---|---|
|
||
<h1>[% HTML.escape(title) %]</h1>
|
||
|
||
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
|
||
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form" id="report_generator_form">
|
||
|
||
[%- FOREACH var = HIDDEN %]
|
||
<input type="hidden" name="[% HTML.escape(var.key) %]" value="[% HTML.escape(var.value) %]">
|
||
... | ... | |
</table>
|
||
|
||
[%- IF CONTROLLER_DISPATCH %]
|
||
<p>
|
||
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch">
|
||
<input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]">
|
||
<input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]">
|
||
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
|
||
</p>
|
||
[%- ELSE %]
|
||
<p>
|
||
<input type="hidden" name="action" value="report_generator_dispatcher">
|
||
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_csv')" value="[% 'Export as CSV' | $T8 %]">
|
||
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]">
|
||
</p>
|
||
<script type="text/javascript"><!--
|
||
function submit_report_generator_form(nextsub) {
|
||
document.report_generator_form.report_generator_dispatch_to.value = nextsub;
|
||
document.report_generator_form.submit();
|
||
} // -->
|
||
</script>
|
||
[%- END %]
|
||
|
||
|
templates/webpages/report_generator/html_report.html | ||
---|---|---|
[% IF DATA_PRESENT %]
|
||
<p>
|
||
<table [% IF TABLE_CLASS %]class="[% TABLE_CLASS %]"[% END %] id="report_table_id" width="100%">
|
||
<thead>
|
||
[%- FOREACH row = HEADER_ROWS %]
|
||
<tr>
|
||
[% FOREACH col = row %]
|
||
... | ... | |
[% END %]
|
||
</tr>
|
||
[%- END %]
|
||
</thead>
|
||
|
||
<tbody>
|
||
[% FOREACH row = ROWS %]
|
||
[% IF row.IS_CONTROL %]
|
||
[% IF row.IS_COLSPAN_DATA %]<tr><td colspan="[% row.NUM_COLUMNS %]">[% row.data %]</td></tr>[% END %]
|
||
... | ... | |
[% END %]
|
||
[% END %]
|
||
|
||
</tbody>
|
||
</table>
|
||
<hr size="3" noshade>
|
||
</p>
|
||
... | ... | |
[% END %]
|
||
|
||
[% IF SHOW_EXPORT_BUTTONS %]
|
||
<form action="[% HTML.escape(script) %]" name="report_generator_form" method="post">
|
||
<form action="[% HTML.escape(script) %]" name="report_generator_form" id="report_generator_form" method="post">
|
||
[% FOREACH var = EXPORT_VARIABLES %]<input type="hidden" name="report_generator_hidden_[% var.key %]" value="[% HTML.escape(var.value) %]">
|
||
[% END %]
|
||
|
||
[%- IF CONTROLLER_DISPATCH %]
|
||
[% IF !SKIP_BUTTONS %]
|
||
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH %]/dispatch">
|
||
[%- END %][%# !SKIP_BUTTONS %]
|
||
<input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]">
|
||
<input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]">
|
||
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
|
||
|
||
[% IF !SKIP_BUTTONS %]
|
||
<p>
|
||
[% 'List export' | $T8 %]<br>
|
||
[% IF ALLOW_PDF_EXPORT %]<input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]">[% END %]
|
||
[% IF ALLOW_CSV_EXPORT %]<input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]">[% END %]
|
||
</p>
|
||
[%- END %][%# !SKIP_BUTTONS %]
|
||
[%- ELSE %]
|
||
<input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]">
|
||
<input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]">
|
||
<input type="hidden" name="report_generator_dispatch_to" value="">
|
||
<input type="hidden" name="action" value="report_generator_dispatcher">
|
||
|
||
[% IF !SKIP_BUTTONS %]
|
||
<p>
|
||
[% 'List export' | $T8 %]<br>
|
||
[% IF ALLOW_PDF_EXPORT %]<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf')" value="[% 'Export as PDF' | $T8 %]">[% END %]
|
||
... | ... | |
document.report_generator_form.submit();
|
||
} // -->
|
||
</script>
|
||
[%- END %][%# !SKIP_BUTTONS %]
|
||
[%- END %]
|
||
|
||
</form>
|
templates/webpages/report_generator/pdf_export_options.html | ||
---|---|---|
|
||
<h1>[% HTML.escape(title) %]</h1>
|
||
|
||
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
|
||
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form" id="report_generator_form">
|
||
|
||
[%- FOREACH var = HIDDEN %]
|
||
<input type="hidden" name="[% HTML.escape(var.key) %]" value="[% HTML.escape(var.value) %]">
|
||
... | ... | |
|
||
<input type="hidden" name="report_generator_pdf_options_set" value="1">
|
||
<input type="hidden" name="report_generator_dispatch_to" value="">
|
||
<input type="hidden" name="report_generator_addattachments" value="">
|
||
|
||
<table>
|
||
<tr>
|
||
... | ... | |
</table>
|
||
|
||
[%- IF CONTROLLER_DISPATCH %]
|
||
<p>
|
||
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch">
|
||
<input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]">
|
||
<input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]">
|
||
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]">
|
||
</p>
|
||
[%- ELSE %]
|
||
<p>
|
||
<input type="hidden" name="action" value="report_generator_dispatcher">
|
||
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf','')" value="[% 'Export as PDF' | $T8 %]">
|
||
[%- IF ALLOW_ATTACHMENTS %]
|
||
<input type="submit" class="submit"
|
||
onclick="submit_report_generator_form('report_generator_export_as_pdf','yes')"
|
||
value="[% 'Export as PDF with attachments' | $T8 %]">
|
||
[%- END %]
|
||
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]">
|
||
</p>
|
||
<script type="text/javascript"><!--
|
||
function submit_report_generator_form(nextsub,att) {
|
||
document.report_generator_form.report_generator_dispatch_to.value = nextsub;
|
||
document.report_generator_form.report_generator_addattachments.value = att;
|
||
document.report_generator_form.submit();
|
||
} // -->
|
||
</script>
|
||
[%- END %]
|
||
|
||
</form>
|
Auch abrufbar als: Unified diff
ActionBar: Unterstützung in ReportGenerator