Revision 7afe92af
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Controller/Letter.pm | ||
---|---|---|
178 | 178 |
my $display_form = $::form->{display_form} || "display_form"; |
179 | 179 |
my $letter = $self->_update; |
180 | 180 |
|
181 |
$self->export_letter_to_form($letter); |
|
182 |
$::form->{formname} = "letter"; |
|
183 |
$::form->{type} = "letter"; |
|
184 |
$::form->{format} = "pdf"; |
|
185 |
|
|
186 |
my $language_saved = $::form->{language_id}; |
|
187 |
my $greeting_saved = $::form->{greeting}; |
|
188 |
my $cp_id_saved = $::form->{cp_id}; |
|
189 |
|
|
190 |
$::form->{customer_id} = $self->letter->customer_id; |
|
191 |
IS->customer_details(\%::myconfig, $::form); |
|
192 |
|
|
193 |
if (!$cp_id_saved) { |
|
194 |
# No contact was selected. Delete all contact variables because |
|
195 |
# IS->customer_details() and IR->vendor_details() get the default |
|
196 |
# contact anyway. |
|
197 |
map({ delete($::form->{$_}); } grep(/^cp_/, keys(%{ $::form }))); |
|
198 |
} |
|
199 |
|
|
200 |
$::form->{greeting} = $greeting_saved; |
|
201 |
$::form->{language_id} = $language_saved; |
|
202 |
|
|
203 |
if ($::form->{cp_id}) { |
|
204 |
CT->get_contact(\%::myconfig, $::form); |
|
205 |
} |
|
206 |
|
|
207 |
$::form->{cp_contact_formal} = ($::form->{cp_greeting} ? "$::form->{cp_greeting} " : '') . ($::form->{cp_givenname} ? "$::form->{cp_givenname} " : '') . $::form->{cp_name}; |
|
208 |
|
|
209 |
$::form->get_employee_data('prefix' => 'employee', 'id' => $letter->{employee_id}); |
|
210 |
$::form->get_employee_data('prefix' => 'salesman', 'id' => $letter->{salesman_id}); |
|
211 |
|
|
212 | 181 |
my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template( |
213 | 182 |
name => 'letter', |
214 | 183 |
printer_id => $::form->{printer_id}, |
... | ... | |
221 | 190 |
$::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files)); |
222 | 191 |
} |
223 | 192 |
|
224 |
my %create_params = ( |
|
225 |
template => $template_file, |
|
226 |
variables => $::form, |
|
227 |
return => 'file_name', |
|
228 |
variable_content_types => { |
|
229 |
body => 'html', |
|
230 |
}, |
|
231 |
); |
|
232 |
|
|
233 |
my $pdf_file_name; |
|
193 |
my %result; |
|
234 | 194 |
eval { |
235 |
$pdf_file_name = SL::Helper::CreatePDF->create_pdf(%create_params); |
|
195 |
%result = SL::Template::LaTeX->parse_and_create_pdf( |
|
196 |
$template_file, |
|
197 |
SELF => $self, |
|
198 |
FORM => $::form, |
|
199 |
letter => $letter, |
|
200 |
template_meta => { |
|
201 |
formname => 'letter', |
|
202 |
language => SL::DB::Language->new, |
|
203 |
extension => 'pdf', |
|
204 |
format => $::form->{format}, |
|
205 |
media => $::form->{media}, |
|
206 |
printer => SL::DB::Manager::Printer->find_by_or_create(id => $::form->{printer_id} || undef), |
|
207 |
today => DateTime->today, |
|
208 |
}, |
|
209 |
); |
|
210 |
|
|
211 |
die $result{error} if $result{error}; |
|
236 | 212 |
|
237 |
$::form->{letternumber} = $self->letter->letternumber; |
|
213 |
$::form->{type} = 'letter'; |
|
214 |
$::form->{formname} = 'letter'; |
|
215 |
$::form->{letternumber} = $letter->letternumber; |
|
238 | 216 |
my $attachment_name = $::form->generate_attachment_filename; |
239 | 217 |
|
240 | 218 |
if ($::instance_conf->get_webdav_documents) { |
... | ... | |
242 | 220 |
filename => $attachment_name, |
243 | 221 |
webdav => SL::Webdav->new( |
244 | 222 |
type => 'letter', |
245 |
number => $self->letter->letternumber,
|
|
223 |
number => $letter->letternumber, |
|
246 | 224 |
), |
247 | 225 |
); |
248 | 226 |
|
249 |
$webdav_file->store(file => $pdf_file_name);
|
|
227 |
$webdav_file->store(file => $result{file_name});
|
|
250 | 228 |
} |
251 | 229 |
|
252 | 230 |
# set some form defaults for printing webdav copy variables |
... | ... | |
255 | 233 |
my $signature = $::myconfig{signature}; |
256 | 234 |
$mail->{$_} = $params{email}->{$_} for qw(to cc subject message bcc); |
257 | 235 |
$mail->{from} = qq|"$::myconfig{name}" <$::myconfig{email}>|; |
258 |
$mail->{attachments} = [{ filename => $pdf_file_name,
|
|
236 |
$mail->{attachments} = [{ filename => $result{file_name},
|
|
259 | 237 |
name => $params{email}->{attachment_filename} }]; |
260 | 238 |
$mail->{message} .= "\n-- \n$signature"; |
261 | 239 |
$mail->{message} =~ s/\r//g; |
262 | 240 |
|
263 | 241 |
$mail->send; |
264 |
unlink $pdf_file_name;
|
|
242 |
unlink $result{file_name};
|
|
265 | 243 |
|
266 | 244 |
flash_later('info', t8('The email has been sent.')); |
267 |
$self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id);
|
|
245 |
$self->redirect_to(action => 'edit', 'letter.id' => $letter->id); |
|
268 | 246 |
|
269 | 247 |
return 1; |
270 | 248 |
} |
271 | 249 |
|
272 | 250 |
if (!$::form->{printer_id} || $::form->{media} eq 'screen') { |
273 |
$self->send_file($pdf_file_name, name => $attachment_name);
|
|
274 |
unlink $pdf_file_name;
|
|
251 |
$self->send_file($result{file_name}, name => $attachment_name);
|
|
252 |
unlink $result{file_name};
|
|
275 | 253 |
|
276 | 254 |
return 1; |
277 | 255 |
} |
... | ... | |
279 | 257 |
my $printer = SL::DB::Printer->new(id => $::form->{printer_id})->load; |
280 | 258 |
$printer->print_document( |
281 | 259 |
copies => $::form->{copies}, |
282 |
file_name => $pdf_file_name,
|
|
260 |
file_name => $result{file_name},
|
|
283 | 261 |
); |
284 | 262 |
|
285 |
unlink $pdf_file_name;
|
|
263 |
unlink $result{file_name};
|
|
286 | 264 |
|
287 | 265 |
flash_later('info', t8('The documents have been sent to the printer \'#1\'.', $printer->printer_description)); |
288 |
$self->redirect_to(action => 'edit', 'letter.id' => $self->letter->id, media => 'printer', printer_id => $::form->{printer_id});
|
|
266 |
$self->redirect_to(action => 'edit', 'letter.id' => $letter->id, media => 'printer', printer_id => $::form->{printer_id}); |
|
289 | 267 |
1; |
290 | 268 |
} or do { |
291 |
unlink $pdf_file_name if $pdf_file_name;
|
|
269 |
unlink $result{file_name} if $result{file_name};
|
|
292 | 270 |
$::form->error(t8("Creating the PDF failed:") . " " . $@); |
293 | 271 |
}; |
294 | 272 |
} |
SL/DB/Contact.pm | ||
---|---|---|
45 | 45 |
. join '', map { " ($_)" } grep $_, $self->cp_abteilung; |
46 | 46 |
} |
47 | 47 |
|
48 |
sub formal_greeting { |
|
49 |
my ($self) = @_; |
|
50 |
die 'not an accessor' if @_ > 1; |
|
51 |
join ' ', grep $_, $self->cp_greeting, $self->cp_givenname, $self->cp_name; |
|
52 |
} |
|
53 |
|
|
48 | 54 |
1; |
templates/print/RB/letter.tex | ||
---|---|---|
1 |
% config: use-template-toolkit=1 |
|
2 |
% config: tag-style=$( )$ |
|
3 |
$( USE KiviLatex )$ |
|
4 |
$( USE P )$ |
|
5 |
$( SET customer = letter.customer )$ |
|
1 | 6 |
\input{inheaders.tex} |
2 |
|
|
7 |
$( KiviLatex.required_packages_for_html )$ |
|
3 | 8 |
|
4 | 9 |
% Variablen, die in settings verwendet werden |
5 |
\newcommand{\lxlangcode} {<%template_meta.language.template_code%>}
|
|
6 |
\newcommand{\lxmedia} {<%media%>}
|
|
7 |
\newcommand{\lxcurrency} {<%currency%>}
|
|
8 |
\newcommand{\lxtitlebar} {<%titlebar%>}
|
|
10 |
\newcommand{\lxlangcode}{$(template_meta.language.template_code)$}
|
|
11 |
\newcommand{\lxmedia}{$(template_meta.media)$}
|
|
12 |
\newcommand{\lxcurrency}{}
|
|
13 |
\newcommand{\lxtitlebar}{}
|
|
9 | 14 |
|
10 | 15 |
% settings: Einstellungen, Logo, Briefpapier, Kopfzeile, Fusszeile |
11 | 16 |
\input{insettings.tex} |
12 | 17 |
|
13 | 18 |
% laufende Kopfzeile: |
14 |
%\ourhead{}{}{<%subject%>}{<%letternumber%>}{<%date%>}
|
|
19 |
%\ourhead{}{}{$( KiviLatex.filter(letter.subject) )$}{$( KiviLatex.filter(letter.letternumber) )$}{$( KiviLatex.filter(letter.date.to_kivitendo) )$}
|
|
15 | 20 |
\ourhead{}{}{}{}{} |
16 | 21 |
|
17 | 22 |
\begin{document} |
... | ... | |
22 | 27 |
|
23 | 28 |
\begin{minipage}{14cm} |
24 | 29 |
|
25 |
<%name%>
|
|
30 |
$( KiviLatex.filter(customer.name) )$
|
|
26 | 31 |
|
27 |
<%contact_formal%>
|
|
32 |
$( KiviLatex.filter(letter.contact.formar_greeting) )$
|
|
28 | 33 |
|
29 |
<%street%>
|
|
34 |
$( KiviLatex.filter(customer.street) )$
|
|
30 | 35 |
|
31 |
<%zipcode%> <%city%>
|
|
36 |
$( KiviLatex.filter(customer.zipcode) )$ $( KiviLatex.filter(customer.city) )$
|
|
32 | 37 |
|
33 |
<%country%>
|
|
38 |
$( KiviLatex.filter(customer.country) )$
|
|
34 | 39 |
|
35 | 40 |
\end{minipage} |
36 | 41 |
|
37 | 42 |
\vspace{2.5cm} |
38 |
\hfill <%date%>
|
|
43 |
\hfill $( KiviLatex.filter(letter.date.to_kivitendo) )$
|
|
39 | 44 |
|
40 |
<%if reference%> |
|
41 |
\textbf{\ihrzeichen : <%reference%>} |
|
42 |
<%end if%> |
|
45 |
$( IF letter.reference )$ |
|
46 |
\textbf{\ihrzeichen : $( KiviLatex.filter(letter.reference) )$} |
|
43 | 47 |
|
44 | 48 |
\vspace{1cm} |
49 |
$( END )$ |
|
45 | 50 |
|
46 |
<%if subject%> |
|
47 |
\textbf{\betreff : <%subject%>} |
|
48 |
<%end if%> |
|
51 |
$( IF letter.subject )$ |
|
52 |
\textbf{\betreff : $( KiviLatex.filter(letter.subject) )$} |
|
49 | 53 |
|
50 | 54 |
\vspace{1cm} |
55 |
$( END )$ |
|
51 | 56 |
|
52 |
<%greeting%>
|
|
57 |
$( KiviLatex.filter(letter.greeting) )$
|
|
53 | 58 |
|
54 | 59 |
\vspace{0.5cm} |
55 | 60 |
|
56 |
<%body%>
|
|
61 |
$( KiviLatex.filter_html(letter.body) )$
|
|
57 | 62 |
|
58 | 63 |
\vspace{0.5cm} |
59 | 64 |
|
60 |
<%company_name%> |
|
61 |
|
|
62 |
\vspace*{0.5cm} |
|
63 |
|
|
64 | 65 |
\begin{minipage}{6cm} |
65 | 66 |
|
66 |
\textbf{<%employee_name%>}
|
|
67 |
\textbf{$( KiviLatex.filter(letter.employee.name) )$}
|
|
67 | 68 |
|
68 | 69 |
\end{minipage} |
69 | 70 |
\begin{minipage}{6cm} |
70 | 71 |
|
71 |
\textbf{<%salesman_name%>}
|
|
72 |
\textbf{$( KiviLatex.filter(letter.salesman.name) )$}
|
|
72 | 73 |
|
73 | 74 |
\end{minipage} |
74 | 75 |
|
Auch abrufbar als: Unified diff
Brieffunktion: Umstellung Druck auf Template Toolkit
Damit wird auch alter Backendcode wie IS->get_customer() nicht mehr
benötigt.