1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 ######################################################################
8 # Stuff that can be used from other modules
10 ######################################################################
12 use List::Util qw(max);
17 use SL::ReportGenerator;
21 sub report_generator_set_default_sort {
22 $main::lxdebug->enter_sub();
24 my $form = $main::form;
26 my $default_sortorder = shift;
27 my $default_sortdir = shift;
29 $form->{sort} ||= $default_sortorder;
30 $form->{sortdir} = $default_sortdir unless (defined $form->{sortdir});
31 $form->{sortdir} = $form->{sortdir} ? 1 : 0;
33 $main::lxdebug->leave_sub();
37 sub report_generator_export_as_pdf {
38 $main::lxdebug->enter_sub();
40 my $form = $main::form;
41 my %myconfig = %main::myconfig;
42 my $locale = $main::locale;
44 if ($form->{report_generator_pdf_options_set}) {
45 my $saved_form = save_form();
47 report_generator_do('PDF');
49 if ($form->{report_generator_printed}) {
50 restore_form($saved_form);
51 $form->{MESSAGE} = $locale->text('The list has been printed.');
52 report_generator_do('HTML');
55 $main::lxdebug->leave_sub();
59 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
61 $form->get_lists('printers' => 'ALL_PRINTERS');
62 map { $_->{selected} = $myconfig{default_printer_id} == $_->{id} } @{ $form->{ALL_PRINTERS} };
64 $form->{copies} = max $myconfig{copies} * 1, 1;
66 my $allow_font_selection = 1;
67 eval { require PDF::API2; };
68 $allow_font_selection = 0 if ($@);
70 $form->{title} = $locale->text('PDF export -- options');
72 print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN' => \@form_values,
73 'ALLOW_FONT_SELECTION' => $allow_font_selection, });
75 $main::lxdebug->leave_sub();
78 sub report_generator_export_as_csv {
79 $main::lxdebug->enter_sub();
81 my $form = $main::form;
82 my $locale = $main::locale;
84 if ($form->{report_generator_csv_options_set}) {
85 report_generator_do('CSV');
86 $main::lxdebug->leave_sub();
90 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
92 $form->{title} = $locale->text('CSV export -- options');
94 print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
96 $main::lxdebug->leave_sub();
99 sub report_generator_back {
100 $main::lxdebug->enter_sub();
102 report_generator_do('HTML');
104 $main::lxdebug->leave_sub();
107 sub report_generator_do {
108 $main::lxdebug->enter_sub();
112 my $form = $main::form;
113 my $locale = $main::locale;
115 my $nextsub = $form->{report_generator_nextsub};
117 $form->error($locale->text('report_generator_nextsub is not defined.'));
120 foreach my $key (split m/ +/, $form->{report_generator_variable_list}) {
121 $form->{$key} = $form->{"report_generator_hidden_${key}"};
124 $form->{report_generator_output_format} = $format;
126 delete @{$form}{map { "report_generator_$_" } qw(nextsub variable_list)};
130 $main::lxdebug->leave_sub();
133 sub report_generator_dispatcher {
134 $main::lxdebug->enter_sub();
136 my $form = $main::form;
137 my $locale = $main::locale;
139 my $nextsub = $form->{report_generator_dispatch_to};
141 $form->error($locale->text('report_generator_dispatch_to is not defined.'));
144 delete $form->{report_generator_dispatch_to};
148 $main::lxdebug->leave_sub();