--- /dev/null
+#=====================================================================
+# LX-Office ERP
+# Copyright (C) 2004
+# Based on SQL-Ledger Version 2.1.9
+# Web http://www.lx-office.org
+######################################################################
+#
+# Mixin for controllers to use ReportGenerator things
+#
+######################################################################
+
+use strict;
+
+use List::Util qw(max);
+
+use SL::Form;
+use SL::Common;
+use SL::MoreCommon;
+use SL::ReportGenerator;
+
+use Exporter 'import';
+our @EXPORT = qw(
+ action_report_generator_export_as_pdf action_report_generator_export_as_csv
+ action_report_generator_back report_generator_do
+);
+
+sub action_report_generator_export_as_pdf {
+ my ($self) = @_;
+ if ($::form->{report_generator_pdf_options_set}) {
+ my $saved_form = save_form();
+
+ $self->report_generator_do('PDF');
+
+ if ($::form->{report_generator_printed}) {
+ restore_form($saved_form);
+ $::form->{MESSAGE} = $::locale->text('The list has been printed.');
+ $self->report_generator_do('HTML');
+ }
+
+ return;
+ }
+
+ my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
+
+ $::form->get_lists('printers' => 'ALL_PRINTERS');
+ map { $_->{selected} = $::myconfig{default_printer_id} == $_->{id} } @{ $::form->{ALL_PRINTERS} };
+
+ $::form->{copies} = max $::myconfig{copies} * 1, 1;
+ $::form->{title} = $::locale->text('PDF export -- options');
+ $::form->header;
+ print $::form->parse_html_template('report_generator/pdf_export_options', {
+ 'HIDDEN' => \@form_values,
+ 'ALLOW_FONT_SELECTION' => SL::ReportGenerator->check_for_pdf_api, });
+}
+
+sub action_report_generator_export_as_csv {
+ my ($self) = @_;
+ if ($::form->{report_generator_csv_options_set}) {
+ $self->report_generator_do('CSV');
+ return;
+ }
+
+ my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
+
+ $::form->{title} = $::locale->text('CSV export -- options');
+ $::form->header;
+ print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
+}
+
+sub action_report_generator_back {
+ $_[0]->report_generator_do('HTML');
+}
+
+sub report_generator_set_default_sort {
+ my ($default_sortorder, $default_sortdir) = @_;
+
+ $::form->{sort} ||= $default_sortorder;
+ $::form->{sortdir} = $default_sortdir unless (defined $::form->{sortdir});
+ $::form->{sortdir} = $::form->{sortdir} ? 1 : 0;
+}
+
+sub report_generator_do {
+ my ($self, $format) = @_;
+
+ my $nextsub = $::form->{report_generator_nextsub};
+ if (!$nextsub) {
+ $::form->error($::locale->text('report_generator_nextsub is not defined.'));
+ }
+
+ foreach my $key (split m/ +/, $::form->{report_generator_variable_list}) {
+ $::form->{$key} = $::form->{"report_generator_hidden_${key}"};
+ }
+
+ $::form->{report_generator_output_format} = $format;
+
+ delete @{$::form}{map { "report_generator_$_" } qw(nextsub variable_list)};
+
+ $self->_run_action($nextsub);
+}
+
+1;
$self->{options} = {
'std_column_visibility' => 0,
'output_format' => 'HTML',
+ 'controller_class ' => '',
'allow_pdf_export' => 1,
'allow_csv_export' => 1,
'html_template' => 'report_generator/html_report',
'EXPORT_VARIABLE_LIST' => join(' ', @{ $self->{export}->{variable_list} }),
'EXPORT_NEXTSUB' => $self->{export}->{nextsub},
'DATA_PRESENT' => $self->{data_present},
+ 'CONTROLLER_DISPATCH' => $opts->{controller_class},
};
return $variables;
}
}
+sub check_for_pdf_api {
+ return eval { require PDF::API2; 1; } ? 1 : 0;
+}
+
1;
__END__
The template to be used for HTML reports. Default is 'report_generator/html_report'.
+=item controller_class
+
+If this is used from a C<SL::Controller::Base> based controller class, pass the
+class name here and make sure C<SL::Controller::Helper::ReportGenerator> is
+used in the controller. That way the exports stay functional.
+
=back
=head2 PDF Options
[%- USE T8 %]
[% USE HTML %]<body>
- <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>
-
<div class="listheading" width="100%">[% HTML.escape(title) %]</div>
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
<input type="hidden" name="report_generator_csv_options_set" value="1">
<input type="hidden" name="report_generator_dispatch_to" value="">
- <input type="hidden" name="action" value="report_generator_dispatcher">
<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_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 %]
+
</form>
</body>
[%- USE T8 %]
[% USE HTML %]<body>
- <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>
-
<style type="text/css">
<!--
.top_border {
[% FOREACH var = EXPORT_VARIABLES %]<input type="hidden" name="report_generator_hidden_[% var.key %]" value="[% HTML.escape(var.value) %]">
[% END %]
+[%- IF CONTROLLER_DISPATCH %]
+ <input type="hidden" name="action" value="[% CONTROLLER_DISPATCH %]/dispatch">
+ <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 %]">
+
+ <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>
+[%- 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="">
[% 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 %]
[% IF ALLOW_CSV_EXPORT %]<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_csv')" value="[% 'Export as CSV' | $T8 %]">[% END %]
</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 %]
+
</form>
[% END %]
[%- SET default_margin = LxERP.format_amount(1.5) %]
- <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>
-
<div class="listheading" width="100%">[% HTML.escape(title) %]</div>
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form">
<input type="hidden" name="report_generator_pdf_options_set" value="1">
<input type="hidden" name="report_generator_dispatch_to" value="">
- <input type="hidden" name="action" value="report_generator_dispatcher">
<table>
<tr>
[% END %]
</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 %]">
<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 %]
</form>
</body>