Revision 1320854c
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
SL/Controller/Helper/ReportGenerator.pm | ||
---|---|---|
1 |
#===================================================================== |
|
2 |
# LX-Office ERP |
|
3 |
# Copyright (C) 2004 |
|
4 |
# Based on SQL-Ledger Version 2.1.9 |
|
5 |
# Web http://www.lx-office.org |
|
6 |
###################################################################### |
|
7 |
# |
|
8 |
# Mixin for controllers to use ReportGenerator things |
|
9 |
# |
|
10 |
###################################################################### |
|
11 |
|
|
12 |
use strict; |
|
13 |
|
|
14 |
use List::Util qw(max); |
|
15 |
|
|
16 |
use SL::Form; |
|
17 |
use SL::Common; |
|
18 |
use SL::MoreCommon; |
|
19 |
use SL::ReportGenerator; |
|
20 |
|
|
21 |
use Exporter 'import'; |
|
22 |
our @EXPORT = qw( |
|
23 |
action_report_generator_export_as_pdf action_report_generator_export_as_csv |
|
24 |
action_report_generator_back report_generator_do |
|
25 |
); |
|
26 |
|
|
27 |
sub action_report_generator_export_as_pdf { |
|
28 |
my ($self) = @_; |
|
29 |
if ($::form->{report_generator_pdf_options_set}) { |
|
30 |
my $saved_form = save_form(); |
|
31 |
|
|
32 |
$self->report_generator_do('PDF'); |
|
33 |
|
|
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'); |
|
38 |
} |
|
39 |
|
|
40 |
return; |
|
41 |
} |
|
42 |
|
|
43 |
my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form }); |
|
44 |
|
|
45 |
$::form->get_lists('printers' => 'ALL_PRINTERS'); |
|
46 |
map { $_->{selected} = $::myconfig{default_printer_id} == $_->{id} } @{ $::form->{ALL_PRINTERS} }; |
|
47 |
|
|
48 |
$::form->{copies} = max $::myconfig{copies} * 1, 1; |
|
49 |
$::form->{title} = $::locale->text('PDF export -- options'); |
|
50 |
$::form->header; |
|
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, }); |
|
54 |
} |
|
55 |
|
|
56 |
sub action_report_generator_export_as_csv { |
|
57 |
my ($self) = @_; |
|
58 |
if ($::form->{report_generator_csv_options_set}) { |
|
59 |
$self->report_generator_do('CSV'); |
|
60 |
return; |
|
61 |
} |
|
62 |
|
|
63 |
my @form_values = $::form->flatten_variables(grep { ($_ ne 'login') && ($_ ne 'password') } keys %{ $::form }); |
|
64 |
|
|
65 |
$::form->{title} = $::locale->text('CSV export -- options'); |
|
66 |
$::form->header; |
|
67 |
print $::form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values }); |
|
68 |
} |
|
69 |
|
|
70 |
sub action_report_generator_back { |
|
71 |
$_[0]->report_generator_do('HTML'); |
|
72 |
} |
|
73 |
|
|
74 |
sub report_generator_set_default_sort { |
|
75 |
my ($default_sortorder, $default_sortdir) = @_; |
|
76 |
|
|
77 |
$::form->{sort} ||= $default_sortorder; |
|
78 |
$::form->{sortdir} = $default_sortdir unless (defined $::form->{sortdir}); |
|
79 |
$::form->{sortdir} = $::form->{sortdir} ? 1 : 0; |
|
80 |
} |
|
81 |
|
|
82 |
sub report_generator_do { |
|
83 |
my ($self, $format) = @_; |
|
84 |
|
|
85 |
my $nextsub = $::form->{report_generator_nextsub}; |
|
86 |
if (!$nextsub) { |
|
87 |
$::form->error($::locale->text('report_generator_nextsub is not defined.')); |
|
88 |
} |
|
89 |
|
|
90 |
foreach my $key (split m/ +/, $::form->{report_generator_variable_list}) { |
|
91 |
$::form->{$key} = $::form->{"report_generator_hidden_${key}"}; |
|
92 |
} |
|
93 |
|
|
94 |
$::form->{report_generator_output_format} = $format; |
|
95 |
|
|
96 |
delete @{$::form}{map { "report_generator_$_" } qw(nextsub variable_list)}; |
|
97 |
|
|
98 |
$self->_run_action($nextsub); |
|
99 |
} |
|
100 |
|
|
101 |
1; |
SL/ReportGenerator.pm | ||
---|---|---|
23 | 23 |
$self->{options} = { |
24 | 24 |
'std_column_visibility' => 0, |
25 | 25 |
'output_format' => 'HTML', |
26 |
'controller_class ' => '', |
|
26 | 27 |
'allow_pdf_export' => 1, |
27 | 28 |
'allow_csv_export' => 1, |
28 | 29 |
'html_template' => 'report_generator/html_report', |
... | ... | |
389 | 390 |
'EXPORT_VARIABLE_LIST' => join(' ', @{ $self->{export}->{variable_list} }), |
390 | 391 |
'EXPORT_NEXTSUB' => $self->{export}->{nextsub}, |
391 | 392 |
'DATA_PRESENT' => $self->{data_present}, |
393 |
'CONTROLLER_DISPATCH' => $opts->{controller_class}, |
|
392 | 394 |
}; |
393 | 395 |
|
394 | 396 |
return $variables; |
... | ... | |
768 | 770 |
} |
769 | 771 |
} |
770 | 772 |
|
773 |
sub check_for_pdf_api { |
|
774 |
return eval { require PDF::API2; 1; } ? 1 : 0; |
|
775 |
} |
|
776 |
|
|
771 | 777 |
1; |
772 | 778 |
|
773 | 779 |
__END__ |
... | ... | |
921 | 927 |
|
922 | 928 |
The template to be used for HTML reports. Default is 'report_generator/html_report'. |
923 | 929 |
|
930 |
=item controller_class |
|
931 |
|
|
932 |
If this is used from a C<SL::Controller::Base> based controller class, pass the |
|
933 |
class name here and make sure C<SL::Controller::Helper::ReportGenerator> is |
|
934 |
used in the controller. That way the exports stay functional. |
|
935 |
|
|
924 | 936 |
=back |
925 | 937 |
|
926 | 938 |
=head2 PDF Options |
templates/webpages/report_generator/csv_export_options.html | ||
---|---|---|
1 | 1 |
[%- USE T8 %] |
2 | 2 |
[% USE HTML %]<body> |
3 | 3 |
|
4 |
<script type="text/javascript"> |
|
5 |
<!-- |
|
6 |
function submit_report_generator_form(nextsub) { |
|
7 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
8 |
document.report_generator_form.submit(); |
|
9 |
} |
|
10 |
|
|
11 |
--> |
|
12 |
</script> |
|
13 |
|
|
14 | 4 |
<div class="listheading" width="100%">[% HTML.escape(title) %]</div> |
15 | 5 |
|
16 | 6 |
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form"> |
... | ... | |
21 | 11 |
|
22 | 12 |
<input type="hidden" name="report_generator_csv_options_set" value="1"> |
23 | 13 |
<input type="hidden" name="report_generator_dispatch_to" value=""> |
24 |
<input type="hidden" name="action" value="report_generator_dispatcher"> |
|
25 | 14 |
|
26 | 15 |
<table> |
27 | 16 |
<tr> |
... | ... | |
77 | 66 |
|
78 | 67 |
</table> |
79 | 68 |
|
69 |
[%- IF CONTROLLER_DISPATCH %] |
|
70 |
<p> |
|
71 |
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch"> |
|
72 |
<input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]"> |
|
73 |
<input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]"> |
|
74 |
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]"> |
|
75 |
</p> |
|
76 |
[%- ELSE %] |
|
80 | 77 |
<p> |
78 |
<input type="hidden" name="action" value="report_generator_dispatcher"> |
|
81 | 79 |
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_csv')" value="[% 'Export as CSV' | $T8 %]"> |
82 | 80 |
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]"> |
83 | 81 |
</p> |
82 |
<script type="text/javascript"><!-- |
|
83 |
function submit_report_generator_form(nextsub) { |
|
84 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
85 |
document.report_generator_form.submit(); |
|
86 |
} // --> |
|
87 |
</script> |
|
88 |
[%- END %] |
|
89 |
|
|
84 | 90 |
|
85 | 91 |
</form> |
86 | 92 |
</body> |
templates/webpages/report_generator/html_report.html | ||
---|---|---|
1 | 1 |
[%- USE T8 %] |
2 | 2 |
[% USE HTML %]<body> |
3 | 3 |
|
4 |
<script type="text/javascript"> |
|
5 |
<!-- |
|
6 |
function submit_report_generator_form(nextsub) { |
|
7 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
8 |
document.report_generator_form.submit(); |
|
9 |
} |
|
10 |
|
|
11 |
--> |
|
12 |
</script> |
|
13 |
|
|
14 | 4 |
<style type="text/css"> |
15 | 5 |
<!-- |
16 | 6 |
.top_border { |
... | ... | |
106 | 96 |
[% FOREACH var = EXPORT_VARIABLES %]<input type="hidden" name="report_generator_hidden_[% var.key %]" value="[% HTML.escape(var.value) %]"> |
107 | 97 |
[% END %] |
108 | 98 |
|
99 |
[%- IF CONTROLLER_DISPATCH %] |
|
100 |
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH %]/dispatch"> |
|
101 |
<input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]"> |
|
102 |
<input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]"> |
|
103 |
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]"> |
|
104 |
|
|
105 |
<p> |
|
106 |
[% 'List export' | $T8 %]<br> |
|
107 |
[% IF ALLOW_PDF_EXPORT %]<input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]">[% END %] |
|
108 |
[% IF ALLOW_CSV_EXPORT %]<input type="submit" name="action_report_generator_export_as_csv" value="[% 'Export as CSV' | $T8 %]">[% END %] |
|
109 |
</p> |
|
110 |
[%- ELSE %] |
|
109 | 111 |
<input type="hidden" name="report_generator_nextsub" value="[% HTML.escape(EXPORT_NEXTSUB) %]"> |
110 | 112 |
<input type="hidden" name="report_generator_variable_list" value="[% HTML.escape(EXPORT_VARIABLE_LIST) %]"> |
111 | 113 |
<input type="hidden" name="report_generator_dispatch_to" value=""> |
... | ... | |
116 | 118 |
[% 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 %] |
117 | 119 |
[% 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 %] |
118 | 120 |
</p> |
121 |
<script type="text/javascript"> <!-- |
|
122 |
function submit_report_generator_form(nextsub) { |
|
123 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
124 |
document.report_generator_form.submit(); |
|
125 |
} // --> |
|
126 |
</script> |
|
127 |
[%- END %] |
|
128 |
|
|
119 | 129 |
</form> |
120 | 130 |
[% END %] |
121 | 131 |
|
templates/webpages/report_generator/pdf_export_options.html | ||
---|---|---|
3 | 3 |
|
4 | 4 |
[%- SET default_margin = LxERP.format_amount(1.5) %] |
5 | 5 |
|
6 |
<script type="text/javascript"> |
|
7 |
<!-- |
|
8 |
function submit_report_generator_form(nextsub) { |
|
9 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
10 |
document.report_generator_form.submit(); |
|
11 |
} |
|
12 |
|
|
13 |
--> |
|
14 |
</script> |
|
15 |
|
|
16 | 6 |
<div class="listheading" width="100%">[% HTML.escape(title) %]</div> |
17 | 7 |
|
18 | 8 |
<form action="[% HTML.escape(script) %]" method="post" name="report_generator_form"> |
... | ... | |
23 | 13 |
|
24 | 14 |
<input type="hidden" name="report_generator_pdf_options_set" value="1"> |
25 | 15 |
<input type="hidden" name="report_generator_dispatch_to" value=""> |
26 |
<input type="hidden" name="action" value="report_generator_dispatcher"> |
|
27 | 16 |
|
28 | 17 |
<table> |
29 | 18 |
<tr> |
... | ... | |
134 | 123 |
[% END %] |
135 | 124 |
</table> |
136 | 125 |
|
126 |
[%- IF CONTROLLER_DISPATCH %] |
|
127 |
<p> |
|
128 |
<input type="hidden" name="action" value="[% CONTROLLER_DISPATCH | html %]/dispatch"> |
|
129 |
<input type="submit" name="action_report_generator_export_as_pdf" value="[% 'Export as PDF' | $T8 %]"> |
|
130 |
<input type="submit" name="action_report_generator_back" value="[% 'Back' | $T8 %]"> |
|
131 |
<input type="hidden" name="CONTROLLER_DISPATCH" value="[% CONTROLLER_DISPATCH | html %]"> |
|
132 |
</p> |
|
133 |
[%- ELSE %] |
|
137 | 134 |
<p> |
135 |
<input type="hidden" name="action" value="report_generator_dispatcher"> |
|
138 | 136 |
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf')" value="[% 'Export as PDF' | $T8 %]"> |
139 | 137 |
<input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]"> |
140 | 138 |
</p> |
139 |
<script type="text/javascript"><!-- |
|
140 |
function submit_report_generator_form(nextsub) { |
|
141 |
document.report_generator_form.report_generator_dispatch_to.value = nextsub; |
|
142 |
document.report_generator_form.submit(); |
|
143 |
} // --> |
|
144 |
</script> |
|
145 |
[%- END %] |
|
141 | 146 |
|
142 | 147 |
</form> |
143 | 148 |
</body> |
Auch abrufbar als: Unified diff
SL::Controller::Base wrapper für ReportGenerator