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);
16 use SL::MoreCommon qw(restore_form save_form);
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_setup_action_bar {
38 my ($type, %params) = @_;
40 for my $bar ($::request->layout->get('actionbar')) {
44 $type eq 'pdf' ? $::locale->text('PDF export') : $::locale->text('CSV export'),
45 submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_export_as_${type}" } ],
48 $::locale->text('PDF export with attachments'),
49 submit => [ '#report_generator_form', { report_generator_dispatch_to => "report_generator_export_as_pdf", report_generator_addattachments => 1 } ],
50 only_if => $params{allow_attachments},
54 $::locale->text('Back'),
55 submit => [ '#report_generator_form', { 'report_generator_dispatch_to' => "report_generator_back" } ],
61 sub report_generator_export_as_pdf {
62 $main::lxdebug->enter_sub();
64 my $form = $main::form;
65 my %myconfig = %main::myconfig;
66 my $locale = $main::locale;
68 if ($form->{report_generator_pdf_options_set}) {
69 my $saved_form = save_form();
71 report_generator_do('PDF');
73 if ($form->{report_generator_printed}) {
74 restore_form($saved_form);
75 $form->{MESSAGE} = $locale->text('The list has been printed.');
76 report_generator_do('HTML');
79 $main::lxdebug->leave_sub();
83 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
85 $form->get_lists('printers' => 'ALL_PRINTERS');
86 map { $_->{selected} = $myconfig{default_printer_id} == $_->{id} } @{ $form->{ALL_PRINTERS} };
88 $form->{copies} = max $myconfig{copies} * 1, 1;
90 my $allow_font_selection = 1;
91 eval { require PDF::API2; };
92 $allow_font_selection = 0 if ($@);
94 $form->{title} = $locale->text('PDF export -- options');
96 report_generator_setup_action_bar('pdf', allow_attachments => !!$form->{report_generator_hidden_l_attachments});
99 print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN' => \@form_values,
100 'ALLOW_FONT_SELECTION' => $allow_font_selection, });
102 $main::lxdebug->leave_sub();
105 sub report_generator_export_as_csv {
106 $main::lxdebug->enter_sub();
108 my $form = $main::form;
109 my $locale = $main::locale;
111 if ($form->{report_generator_csv_options_set}) {
112 report_generator_do('CSV');
113 $main::lxdebug->leave_sub();
117 my @form_values = $form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $form });
119 $form->{title} = $locale->text('CSV export -- options');
121 report_generator_setup_action_bar('csv');
124 print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
126 $main::lxdebug->leave_sub();
129 sub report_generator_back {
130 $main::lxdebug->enter_sub();
132 report_generator_do('HTML');
134 $main::lxdebug->leave_sub();
137 sub report_generator_do {
138 $main::lxdebug->enter_sub();
142 my $form = $main::form;
143 my $locale = $main::locale;
145 my $nextsub = $form->{report_generator_nextsub};
147 $form->error($locale->text('report_generator_nextsub is not defined.'));
150 foreach my $key (split m/ +/, $form->{report_generator_variable_list}) {
151 $form->{$key} = $form->{"report_generator_hidden_${key}"};
154 $form->{report_generator_output_format} = $format;
156 delete @{$form}{map { "report_generator_$_" } qw(nextsub variable_list)};
160 $main::lxdebug->leave_sub();
163 sub report_generator_dispatcher {
164 $main::lxdebug->enter_sub();
166 my $form = $main::form;
167 my $locale = $main::locale;
169 my $nextsub = $form->{report_generator_dispatch_to};
171 $form->error($locale->text('report_generator_dispatch_to is not defined.'));
174 delete $form->{report_generator_dispatch_to};
178 $main::lxdebug->leave_sub();