Revision 71421f7b
Von Tamino Steinert vor 3 Monaten hinzugefügt
- ID 71421f7bcc9d9596a15c8f195972266f77ec30aa
- Vorgänger 2f62cb2f
SL/Controller/Part.pm | ||
---|---|---|
28 | 28 |
use SL::Helper::CreatePDF qw(:all); |
29 | 29 |
use SL::Helper::PrintOptions; |
30 | 30 |
use SL::JSON; |
31 |
use SL::MIME; |
|
31 | 32 |
use SL::Locale::String qw(t8); |
32 | 33 |
use SL::MoreCommon qw(save_form); |
33 | 34 |
use SL::Presenter::EscapedText qw(escape is_escaped); |
... | ... | |
137 | 138 |
$self->js->flash('info', t8('The item has been saved.')); |
138 | 139 |
|
139 | 140 |
my $formname = $::form->{print_options}->{formname}; |
140 |
my $language = $::form->{print_options}->{language}; |
|
141 | 141 |
my $format = $::form->{print_options}->{format}; |
142 | 142 |
my $media = $::form->{print_options}->{media}; |
143 | 143 |
my $printer_id = $::form->{print_options}->{printer_id}; |
144 | 144 |
my $copies = $::form->{print_options}->{copies}; |
145 |
my $language; |
|
146 |
if ($::form->{print_options}->{language_id}) { |
|
147 |
$language = SL::DB::Manager::Language->find_by( |
|
148 |
id => $::form->{print_options}->{language_id} |
|
149 |
); |
|
150 |
} |
|
145 | 151 |
|
146 | 152 |
my %result; |
147 | 153 |
eval { |
148 |
%result = SL::Template::LaTeX->parse_and_create_pdf( |
|
149 |
$formname . ".tex", |
|
150 |
SELF => $self, |
|
151 |
part => $self->part, |
|
152 |
template_meta => { |
|
153 |
formname => 'part', |
|
154 |
language => $language, |
|
155 |
extension => 'pdf', |
|
156 |
format => $format, |
|
157 |
media => $media, |
|
158 |
today => DateTime->today, |
|
159 |
lxconfig => \%::lx_office_conf, |
|
160 |
}, |
|
161 |
); |
|
162 |
if ($result{error}) { |
|
163 |
die t8('Conversion to PDF failed: #1', $result{error}); |
|
154 |
|
|
155 |
my $template_ext; |
|
156 |
my $template_type; |
|
157 |
if ($format =~ /(opendocument|oasis)/i) { |
|
158 |
$template_ext = 'odt'; |
|
159 |
$template_type = 'OpenDocument'; |
|
160 |
} elsif ($format =~ m{html}i) { |
|
161 |
$template_ext = 'html'; |
|
162 |
$template_type = 'HTML'; |
|
163 |
} |
|
164 |
|
|
165 |
# search for the template |
|
166 |
my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template( |
|
167 |
name => $formname, |
|
168 |
extension => $template_ext, |
|
169 |
language => $language, |
|
170 |
printer_id => $printer_id, |
|
171 |
); |
|
172 |
if (!defined $template_file) { |
|
173 |
die t8('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files); |
|
164 | 174 |
} |
165 | 175 |
|
166 |
my $pdf = $result{file_name}; |
|
176 |
my $print_form = Form->new(''); |
|
177 |
$print_form->{part} = $self->part; |
|
178 |
|
|
179 |
# for doc_filename |
|
180 |
$print_form->{type} = 'part'; |
|
181 |
$print_form->{formname} = $formname; |
|
182 |
$print_form->{format} = $format; |
|
183 |
$print_form->{partnumber} = $self->part->partnumber; |
|
184 |
$print_form->{language} = $language && ("_" . |
|
185 |
($language->template_code || $language->description) |
|
186 |
); |
|
187 |
|
|
188 |
# for tempalte variables |
|
189 |
$print_form->{template_meta}->{language} = $language; |
|
190 |
$print_form->{media} = $media; |
|
191 |
$print_form->{media} = 'file' if $print_form->{media} eq 'screen'; |
|
192 |
my $default = SL::DB::Default->get; |
|
193 |
$print_form->{employee_company} = $default->company; |
|
194 |
$print_form->{currency} = $default->currency->name; |
|
195 |
|
|
196 |
my $document = SL::Helper::CreatePDF->create_pdf( |
|
197 |
format => $format, |
|
198 |
template_type => $template_type, |
|
199 |
template => $template_file, |
|
200 |
variables => $print_form, |
|
201 |
variable_content_types => { |
|
202 |
notes => 'html', |
|
203 |
# TODO: html cvars |
|
204 |
}, |
|
205 |
); |
|
167 | 206 |
|
168 | 207 |
if ($media eq 'screen') { |
169 |
my $file_name = $formname . '.pdf'; |
|
170 |
$file_name =~ s{[^\w\.]+}{_}g; |
|
208 |
my $doc_filename = $print_form->generate_attachment_filename(); |
|
171 | 209 |
|
172 | 210 |
$self->send_file( |
173 |
$pdf,
|
|
174 |
type => 'application/pdf',
|
|
175 |
name => $file_name,
|
|
211 |
\$document,
|
|
212 |
type => SL::MIME->mime_type_from_ext($doc_filename),
|
|
213 |
name => $doc_filename,
|
|
176 | 214 |
js_no_render => 1, |
177 | 215 |
); |
178 | 216 |
unlink $result{file_name}; |
Auch abrufbar als: Unified diff
S:C:Part: Drucken angepasst