1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 ######################################################################
8 # Mixin for controllers to use ReportGenerator things
10 ######################################################################
14 use List::Util qw(max);
19 use SL::ReportGenerator;
21 use Exporter 'import';
23 action_report_generator_export_as_pdf action_report_generator_export_as_csv
24 action_report_generator_back report_generator_do
27 sub action_report_generator_export_as_pdf {
29 if ($::form->{report_generator_pdf_options_set}) {
30 my $saved_form = save_form();
32 $self->report_generator_do('PDF');
34 if ($::form->{report_generator_printed}) {
35 restore_form($saved_form);
36 $::form->{MESSAGE} = $::locale->text('The list has been printed.');
37 $self->report_generator_do('HTML');
43 my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
45 $::form->get_lists('printers' => 'ALL_PRINTERS');
46 map { $_->{selected} = $::myconfig{default_printer_id} == $_->{id} } @{ $::form->{ALL_PRINTERS} };
48 $::form->{copies} = max $::myconfig{copies} * 1, 1;
49 $::form->{title} = $::locale->text('PDF export -- options');
51 print $::form->parse_html_template('report_generator/pdf_export_options', {
52 'HIDDEN' => \@form_values,
53 'ALLOW_FONT_SELECTION' => SL::ReportGenerator->check_for_pdf_api, });
56 sub action_report_generator_export_as_csv {
58 if ($::form->{report_generator_csv_options_set}) {
59 $self->report_generator_do('CSV');
63 my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form });
65 $::form->{title} = $::locale->text('CSV export -- options');
67 print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
70 sub action_report_generator_back {
71 $_[0]->report_generator_do('HTML');
74 sub report_generator_set_default_sort {
75 my ($default_sortorder, $default_sortdir) = @_;
77 $::form->{sort} ||= $default_sortorder;
78 $::form->{sortdir} = $default_sortdir unless (defined $::form->{sortdir});
79 $::form->{sortdir} = $::form->{sortdir} ? 1 : 0;
82 sub report_generator_do {
83 my ($self, $format) = @_;
85 my $nextsub = $::form->{report_generator_nextsub};
87 $::form->error($::locale->text('report_generator_nextsub is not defined.'));
90 foreach my $key (split m/ +/, $::form->{report_generator_variable_list}) {
91 $::form->{$key} = $::form->{"report_generator_hidden_${key}"};
94 $::form->{report_generator_output_format} = $format;
96 delete @{$::form}{map { "report_generator_$_" } qw(nextsub variable_list)};
98 $self->_run_action($nextsub);