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;
19 sub report_generator_set_default_sort {
20 $lxdebug->enter_sub();
22 my $default_sortorder = shift;
23 my $default_sortdir = shift;
25 $form->{sort} ||= $default_sortorder;
26 $form->{sortdir} = $default_sortdir unless (defined $form->{sortdir});
27 $form->{sortdir} = $form->{sortdir} ? 1 : 0;
29 $lxdebug->leave_sub();
33 sub report_generator_export_as_pdf {
34 $lxdebug->enter_sub();
36 if ($form->{report_generator_pdf_options_set}) {
37 my $saved_form = save_form();
39 report_generator_do('PDF');
41 if ($form->{report_generator_printed}) {
42 restore_form($saved_form);
43 $form->{MESSAGE} = $locale->text('The list has been printed.');
44 report_generator_do('HTML');
47 $lxdebug->leave_sub();
51 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
53 $form->get_lists('printers' => 'ALL_PRINTERS');
54 map { $_->{selected} = $myconfig{default_printer_id} == $_->{id} } @{ $form->{ALL_PRINTERS} };
56 $form->{copies} = max $myconfig{copies} * 1, 1;
58 my $allow_font_selection = 1;
59 eval { require PDF::API2; };
60 $allow_font_selection = 0 if ($@);
62 $form->{title} = $locale->text('PDF export -- options');
64 print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN' => \@form_values,
65 'ALLOW_FONT_SELECTION' => $allow_font_selection, });
67 $lxdebug->leave_sub();
70 sub report_generator_export_as_csv {
71 $lxdebug->enter_sub();
73 if ($form->{report_generator_csv_options_set}) {
74 report_generator_do('CSV');
75 $lxdebug->leave_sub();
79 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
81 $form->{title} = $locale->text('CSV export -- options');
83 print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
85 $lxdebug->leave_sub();
88 sub report_generator_back {
89 $lxdebug->enter_sub();
91 report_generator_do('HTML');
93 $lxdebug->leave_sub();
96 sub report_generator_do {
97 $lxdebug->enter_sub();
101 my $nextsub = $form->{report_generator_nextsub};
103 $form->error($locale->text('report_generator_nextsub is not defined.'));
106 foreach my $key (split m/ +/, $form->{report_generator_variable_list}) {
107 $form->{$key} = $form->{"report_generator_hidden_${key}"};
110 $form->{report_generator_output_format} = $format;
112 delete @{$form}{map { "report_generator_$_" } qw(nextsub variable_list)};
116 $lxdebug->leave_sub();
119 sub report_generator_dispatcher {
120 $lxdebug->enter_sub();
122 my $nextsub = $form->{report_generator_dispatch_to};
124 $form->error($locale->text('report_generator_dispatch_to is not defined.'));
127 delete $form->{report_generator_dispatch_to};
131 $lxdebug->leave_sub();