Beim Speichern/Anlegen von Mahstufen müssen die Kundendaten vor dem Generieren der...
[kivitendo-erp.git] / SL / DN.pm
1 #======================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors:
16 #
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #======================================================================
30 #
31 # Dunning process module
32 #
33 #======================================================================
34
35 package DN;
36
37 use SL::Template;
38 use SL::IS;
39 use SL::Common;
40 use SL::DBUtils;
41 use Data::Dumper;
42
43 sub get_config {
44   $main::lxdebug->enter_sub();
45
46   my ($self, $myconfig, $form) = @_;
47
48   # connect to database
49   my $dbh = $form->dbconnect($myconfig);
50
51   my $query =
52     qq|SELECT * | .
53     qq|FROM dunning_config | .
54     qq|ORDER BY dunning_level|;
55   $form->{DUNNING} = selectall_hashref_query($form, $dbh, $query);
56
57   foreach my $ref (@{ $form->{DUNNING} }) {
58     $ref->{fee} = $form->format_amount($myconfig, $ref->{fee}, 2);
59     $ref->{interest} = $form->format_amount($myconfig, ($ref->{interest} * 100));
60   }
61
62   $dbh->disconnect();
63
64   $main::lxdebug->leave_sub();
65 }
66
67 sub save_config {
68   $main::lxdebug->enter_sub();
69
70   my ($self, $myconfig, $form) = @_;
71
72   # connect to database
73   my $dbh = $form->dbconnect_noauto($myconfig);
74
75   my ($query, @values);
76
77   for my $i (1 .. $form->{rowcount}) {
78     $form->{"fee_$i"} = $form->parse_amount($myconfig, $form->{"fee_$i"}) * 1;
79     $form->{"interest_$i"} = $form->parse_amount($myconfig, $form->{"interest_$i"}) / 100;
80
81     if (($form->{"dunning_level_$i"} ne "") &&
82         ($form->{"dunning_description_$i"} ne "")) {
83       @values = (conv_i($form->{"dunning_level_$i"}), $form->{"dunning_description_$i"},
84                  $form->{"email_subject_$i"}, $form->{"email_body_$i"},
85                  $form->{"template_$i"}, $form->{"fee_$i"}, $form->{"interest_$i"},
86                  $form->{"active_$i"} ? 't' : 'f', $form->{"auto_$i"} ? 't' : 'f', $form->{"email_$i"} ? 't' : 'f',
87                  $form->{"email_attachment_$i"} ? 't' : 'f', conv_i($form->{"payment_terms_$i"}), conv_i($form->{"terms_$i"}));
88       if ($form->{"id_$i"}) {
89         $query =
90           qq|UPDATE dunning_config SET
91                dunning_level = ?, dunning_description = ?,
92                email_subject = ?, email_body = ?,
93                template = ?, fee = ?, interest = ?,
94                active = ?, auto = ?, email = ?,
95                email_attachment = ?, payment_terms = ?, terms = ?
96              WHERE id = ?|;
97         push(@values, conv_i($form->{"id_$i"}));
98       } else {
99         $query =
100           qq|INSERT INTO dunning_config
101                (dunning_level, dunning_description, email_subject, email_body,
102                 template, fee, interest, active, auto, email,
103                 email_attachment, payment_terms, terms)
104              VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
105       }
106       do_query($form, $dbh, $query, @values);
107     }
108
109     if (($form->{"dunning_description_$i"} eq "") && ($form->{"id_$i"})) {
110       $query = qq|DELETE FROM dunning_config WHERE id = ?|;
111       do_query($form, $dbh, $query, $form->{"id_$i"});
112     }
113   }
114
115   $dbh->commit;
116   $dbh->disconnect;
117
118   $main::lxdebug->leave_sub();
119 }
120
121 sub save_dunning {
122   $main::lxdebug->enter_sub();
123
124   my ($self, $myconfig, $form, $rows, $userspath, $spool, $sendmail) = @_;
125   # connect to database
126   my $dbh = $form->dbconnect_noauto($myconfig);
127
128   my ($query, @values);
129
130   my ($dunning_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
131
132   foreach my $row (@{ $rows }) {
133
134     $form->{"interest_$row"} = $form->parse_amount($myconfig,$form->{"interest_$row"});
135     $form->{"fee_$row"} = $form->parse_amount($myconfig,$form->{"fee_$row"});
136     $form->{send_email} = $form->{"email_$row"};
137
138     $query = qq|UPDATE ar SET dunning_config_id = ? WHERE id = ?|;
139     @values = ($form->{"next_dunning_config_id_$row"},
140                $form->{"inv_id_$row"});
141     do_query($form, $dbh, $query, @values);
142
143     $query =
144       qq|INSERT INTO dunning (dunning_id, dunning_config_id, dunning_level,
145                               trans_id, fee, interest, transdate, duedate)
146          VALUES (?, ?, (SELECT dunning_level FROM dunning_config WHERE id = ?),
147                  ?, ?, ?, current_date, ?)|;
148     @values = ($dunning_id,
149                conv_i($form->{"next_dunning_config_id_$row"}),
150                conv_i($form->{"next_dunning_config_id_$row"}),
151                conv_i($form->{"inv_id_$row"}), $form->{"fee_$row"},
152                $form->{"interest_$row"},
153                conv_date($form->{"next_duedate_$row"}));
154     do_query($form, $dbh, $query, @values);
155   }
156
157   my $query =
158     qq|SELECT invnumber, ordnumber, customer_id, amount, netamount,
159          ar.transdate, ar.duedate, paid, amount - paid AS open_amount,
160          template AS formname, email_subject, email_body, email_attachment,
161          da.fee, da.interest, da.transdate AS dunning_date,
162          da.duedate AS dunning_duedate,
163          c.name, c.street, c.zipcode, c.city, c.country, c.department_1, c.department_2
164        FROM ar
165        LEFT JOIN dunning_config ON (dunning_config.id = ar.dunning_config_id)
166        LEFT JOIN dunning da ON (ar.id = da.trans_id AND dunning_config.dunning_level = da.dunning_level)
167        LEFT JOIN customer c ON (ar.customer_id = c.id)
168        WHERE ar.id IN (|
169        . join(", ", map("?", @{ $form->{"inv_ids"} })) . qq|)|;
170
171   my $sth = prepare_execute_query($form, $dbh, $query, @{ $form->{"inv_ids"} });
172   my $first = 1;
173   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
174     if ($first) {
175       map({ $form->{"dn_$_"} = []; } keys(%{$ref}));
176       $first = 0;
177     }
178     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest);
179     map { $form->{$_} = $ref->{$_} } keys %$ref;
180     #print(STDERR Dumper($ref));
181     map { push(@{ $form->{"dn_$_"} }, $ref->{$_})} keys %$ref;
182   }
183   $sth->finish;
184
185   IS->customer_details($myconfig,$form);
186   #print(STDERR Dumper($form->{dn_invnumber}));
187   $form->{templates} = "$myconfig->{templates}";
188
189
190
191   $form->{language} = $form->get_template_language(\%myconfig);
192   $form->{printer_code} = $form->get_printer_code(\%myconfig);
193
194   if ($form->{language} ne "") {
195     $form->{language} = "_" . $form->{language};
196   }
197
198   if ($form->{printer_code} ne "") {
199     $form->{printer_code} = "_" . $form->{printer_code};
200   }
201
202   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
203   if ($form->{format} eq 'postscript') {
204     $form->{postscript} = 1;
205     $form->{IN} =~ s/html$/tex/;
206   } elsif ($form->{"format"} =~ /pdf/) {
207     $form->{pdf} = 1;
208     if ($form->{"format"} =~ /opendocument/) {
209       $form->{IN} =~ s/html$/odt/;
210     } else {
211       $form->{IN} =~ s/html$/tex/;
212     }
213   } elsif ($form->{"format"} =~ /opendocument/) {
214     $form->{"opendocument"} = 1;
215     $form->{"IN"} =~ s/html$/odt/;
216   }
217
218   if ($form->{"send_email"} && ($form->{email} ne "")) {
219     $form->{media} = 'email';
220   }
221
222   $form->{keep_tmpfile} = 0;
223   if ($form->{media} eq 'email') {
224     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
225       unless $form->{subject};
226     if (!$form->{email_attachment}) {
227       $form->{do_not_attach} = 1;
228     } else {
229       $form->{do_not_attach} = 0;
230     }
231     $form->{subject} = parse_strings($myconfig, $form, $userspath, $form->{email_subject});
232     $form->{message} = parse_strings($myconfig, $form, $userspath, $form->{email_body});
233
234     $form->{OUT} = "$sendmail";
235
236   } else {
237
238     my $filename = Common::unique_id() . $form->{login} . ".pdf";
239     $form->{OUT} = ">$spool/$filename";
240     push(@{ $form->{DUNNING_PDFS} }, $filename);
241     $form->{keep_tmpfile} = 1;
242   }
243
244   delete($form->{tmpfile});
245   $form->parse_template($myconfig, $userspath);
246
247   $dbh->commit;
248   $dbh->disconnect;
249
250   $main::lxdebug->leave_sub();
251 }
252
253 sub get_invoices {
254
255   $main::lxdebug->enter_sub();
256
257   my ($self, $myconfig, $form) = @_;
258
259   # connect to database
260   my $dbh = $form->dbconnect($myconfig);
261
262   my $where =
263     qq| WHERE (a.paid < a.amount)
264           AND (a.duedate < current_date)
265           AND (dnn.id =
266             (SELECT id FROM dunning_config
267              WHERE dunning_level >
268                (SELECT
269                   CASE
270                     WHEN a.dunning_config_id IS NULL
271                     THEN 0
272                     ELSE (SELECT dunning_level
273                           FROM dunning_config
274                           WHERE id = a.dunning_config_id
275                           ORDER BY dunning_level
276                           LIMIT 1)
277                   END
278                 FROM dunning_config LIMIT 1)
279              LIMIT 1)) |;
280   my @values;
281
282   $form->{customer_id} = $1 if ($form->{customer} =~ /--(\d+)$/);
283
284   if ($form->{customer_id}) {
285     $where .= qq| AND (a.customer_id = ?)|;
286     push(@values, $form->{customer_id});
287
288   } elsif ($form->{customer}) {
289     $where .= qq| AND (ct.name ILIKE ?)|;
290     push(@values, '%' . $form->{customer} . '%');
291   }
292
293   my %columns = (
294     "ordnumber" => "a.ordnumber",
295     "invnumber" => "a.invnumber",
296     "notes" => "a.notes",
297     );
298   foreach my $key (keys(%columns)) {
299     next unless ($form->{$key});
300     $where .= qq| AND $columns{$key} ILIKE ?|;
301     push(@values, '%' . $form->{$key} . '%');
302   }
303
304   if ($form->{dunning_level}) {
305     $where .= qq| AND a.dunning_config_id = ?|;
306     push(@values, conv_i($form->{dunning_level}));
307   }
308
309   $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount});
310   if ($form->{minamount}) {
311     $where .= qq| AND ((a.amount - a.paid) > ?) |;
312     push(@values, $form->{minamount});
313   }
314
315   $paymentdate = $form->{paymentuntil} ? $dbh->quote($form->{paymentuntil}) :
316     "current_date";
317
318   $query =
319     qq|SELECT a.id, a.ordnumber, a.transdate, a.invnumber, a.amount,
320          ct.name AS customername, a.customer_id, a.duedate,
321          da.fee AS old_fee, dnn.active, dnn.email, dnn.fee + da.fee AS fee,
322          dn.dunning_description, da.transdate AS dunning_date, da.duedate AS dunning_duedate,
323          a.duedate + dnn.terms - current_date AS nextlevel,
324          $paymentdate - a.duedate AS pastdue, dn.dunning_level,
325          current_date + dnn.payment_terms AS next_duedate,
326          dnn.dunning_description AS next_dunning_description, dnn.id AS next_dunning_config_id,
327          dnn.interest AS interest_rate, dnn.terms
328        FROM dunning_config dnn, ar a
329        JOIN customer ct ON (a.customer_id = ct.id)
330        LEFT JOIN dunning_config dn ON (dn.id = a.dunning_config_id)
331        LEFT JOIN dunning da ON ((da.trans_id = a.id) AND (dn.dunning_level = da.dunning_level))
332        $where
333        ORDER BY a.id, transdate, duedate, name|;
334
335   my $sth = prepare_execute_query($form, $dbh, $query, @values);
336
337   $form->{DUNNINGS} = [];
338
339   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
340     $ref->{interest} = ($ref->{amount} * $ref->{pastdue} * $ref->{interest_rate}) / 360;
341     $ref->{interest} = $form->round_amount($ref->{interest}, 2);
342     map({ $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest));
343     if ($ref->{pastdue} >= $ref->{terms}) {
344       push(@{ $form->{DUNNINGS} }, $ref);
345     }
346   }
347
348   $sth->finish;
349
350   $query = qq|SELECT id, dunning_description FROM dunning_config ORDER BY dunning_level|;
351   $form->{DUNNING_CONFIG} = selectall_hashref_query($form, $dbh, $query);
352
353   $dbh->disconnect;
354   $main::lxdebug->leave_sub();
355 }
356
357 sub get_dunning {
358
359   $main::lxdebug->enter_sub();
360
361   my ($self, $myconfig, $form) = @_;
362
363   # connect to database
364   my $dbh = $form->dbconnect($myconfig);
365
366   $where = qq| WHERE (da.trans_id = a.id)|;
367
368   my @values;
369
370   $form->{customer_id} = $1 if ($form->{customer} =~ /--(\d+)$/);
371
372   if ($form->{customer_id}) {
373     $where .= qq| AND (a.customer_id = ?)|;
374     push(@values, $form->{customer_id});
375
376   } elsif ($form->{customer}) {
377     $where .= qq| AND (ct.name ILIKE ?)|;
378     push(@values, '%' . $form->{customer} . '%');
379   }
380
381
382   my %columns = (
383     "ordnumber" => "a.ordnumber",
384     "invnumber" => "a.invnumber",
385     "notes" => "a.notes",
386     );
387   foreach my $key (keys(%columns)) {
388     next unless ($form->{$key});
389     $where .= qq| AND $columns{$key} ILIKE ?|;
390     push(@values, '%' . $form->{$key} . '%');
391   }
392
393   if ($form->{dunning_level}) {
394     $where .= qq| AND a.dunning_config_id = ?|;
395     push(@values, conv_i($form->{dunning_level}));
396   }
397
398   $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount});
399   if ($form->{minamount}) {
400     $where .= qq| AND ((a.amount - a.paid) > ?) |;
401     push(@values, $form->{minamount});
402   }
403
404   if (!$form->{showold}) {
405     $where .= qq| AND (a.amount > a.paid) AND (da.dunning_config_id = a.dunning_config_id) |;
406   }
407
408   if ($form->{transdatefrom}) {
409     $where .= qq| AND a.transdate >= ?|;
410     push(@values, $form->{transdatefrom});
411   }
412   if ($form->{transdateto}) {
413     $where .= qq| AND a.transdate <= ?|;
414     push(@values, $form->{transdateto});
415   }
416   if ($form->{dunningfrom}) {
417     $where .= qq| AND da.transdate >= ?|;
418     push(@values, $form->{dunningfrom});
419   }
420   if ($form->{dunningto}) {
421     $where .= qq| AND da.transdate >= ?|;
422     push(@values, $form->{dunningto});
423   }
424
425   $query =
426     qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount,
427          ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
428          da.interest, dn.dunning_description, da.transdate AS dunning_date,
429          da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id
430        FROM ar a
431        JOIN customer ct ON (a.customer_id = ct.id), dunning da
432        LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id)
433        $where
434        ORDER BY name, a.id|;
435
436   $form->{DUNNINGS} = selectall_hashref_query($form, $dbh, $query, @values);
437
438   foreach my $ref (@{ $form->{DUNNINGS} }) {
439     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest);
440   }
441
442   $dbh->disconnect;
443   $main::lxdebug->leave_sub();
444 }
445
446 sub parse_strings {
447
448   $main::lxdebug->enter_sub();
449
450   my ($myconfig, $form, $userspath, $string) = @_;
451
452   my $format = $form->{format};
453   $form->{format} = "html";
454
455   $tmpstring = "parse_string.html";
456   $tmpfile = "$myconfig->{templates}/$tmpstring";
457   open(OUT, ">$tmpfile") or $form->error("$tmpfile : $!");
458   print(OUT $string);
459   close(OUT);
460
461   my $in = $form->{IN};
462   $form->{IN} = $tmpstring;
463   $template = HTMLTemplate->new($tmpstring, $form, $myconfig, $userspath);
464
465   my $fileid = time;
466   $form->{tmpfile} = "$userspath/${fileid}.$tmpstring";
467   $out = $form->{OUT};
468   $form->{OUT} = ">$form->{tmpfile}";
469
470   if ($form->{OUT}) {
471     open(OUT, "$form->{OUT}") or $form->error("$form->{OUT} : $!");
472   }
473   if (!$template->parse(*OUT)) {
474     $form->cleanup();
475     $form->error("$form->{IN} : " . $template->get_error());
476   }
477
478   close(OUT);
479   my $result = "";
480   open(IN, $form->{tmpfile}) or $form->error($form->cleanup . "$form->{tmpfile} : $!");
481
482   while (<IN>) {
483     $result .= $_;
484   }
485
486   close(IN);
487 #   unlink($tmpfile);
488 #   unlink($form->{tmpfile});
489   $form->{IN} = $in;
490   $form->{format} = $format;
491
492   $main::lxdebug->leave_sub();
493   return $result;
494 }
495
496 sub melt_pdfs {
497
498   $main::lxdebug->enter_sub();
499
500   my ($self, $myconfig, $form, $userspath) = @_;
501
502   foreach my $file (@{ $form->{DUNNING_PDFS} }) {
503     $inputfiles .= " $userspath/$file ";
504   }
505
506   my $outputfile = "$userspath/dunning.pdf";
507   system("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$outputfile $inputfiles");
508   foreach my $file (@{ $form->{DUNNING_PDFS} }) {
509     unlink("$userspath/$file");
510   }
511   $out = "";
512
513   $form->{OUT} = $out;
514
515   my $numbytes = (-s $outputfile);
516   open(IN, $outputfile)
517     or $form->error($self->cleanup . "$outputfile : $!");
518
519   $form->{copies} = 1 unless $form->{media} eq 'printer';
520
521   chdir("$self->{cwd}");
522
523   for my $i (1 .. $form->{copies}) {
524     if ($form->{OUT}) {
525       open(OUT, $form->{OUT})
526         or $form->error($form->cleanup . "$form->{OUT} : $!");
527     } else {
528
529       # launch application
530       print qq|Content-Type: Application/PDF
531 Content-Disposition: attachment; filename="$outputfile"
532 Content-Length: $numbytes
533
534 |;
535
536       open(OUT, ">-") or $form->error($form->cleanup . "$!: STDOUT");
537
538     }
539
540     while (<IN>) {
541       print OUT $_;
542     }
543
544     close(OUT);
545
546     seek(IN, 0, 0);
547   }
548
549   close(IN);
550   unlink("$userspath/$outputfile");
551
552   $main::lxdebug->leave_sub();
553 }
554
555 sub print_dunning {
556   $main::lxdebug->enter_sub();
557
558   my ($self, $myconfig, $form, $dunning_id, $userspath,$spool, $sendmail) = @_;
559   # connect to database
560   my $dbh = $form->dbconnect_noauto($myconfig);
561
562   my $query =
563     qq|SELECT invnumber, ordnumber, customer_id, amount, netamount,
564          ar.transdate, ar.duedate, paid, amount - paid AS open_amount,
565          template AS formname, email_subject, email_body, email_attachment,
566          da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate
567        FROM dunning da
568        LEFT JOIN dunning_config ON (dunning_config.id = da.dunning_config_id)
569        LEFT JOIN ar ON (ar.id = da.trans_id)
570        WHERE (da.dunning_id = ?)|;
571
572   my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id);
573   my $first = 1;
574   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
575     if ($first) {
576       map({ $form->{"dn_$_"} = []; } keys(%{$ref}));
577       $first = 0;
578     }
579     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest);
580     map { $form->{$_} = $ref->{$_} } keys %$ref;
581     map { push @{ $form->{"dn_$_"} }, $ref->{$_}} keys %$ref;
582   }
583   $sth->finish;
584
585   IS->customer_details($myconfig,$form);
586   $form->{templates} = "$myconfig->{templates}";
587
588   $form->{language} = $form->get_template_language(\%myconfig);
589   $form->{printer_code} = $form->get_printer_code(\%myconfig);
590
591   if ($form->{language} ne "") {
592     $form->{language} = "_" . $form->{language};
593   }
594
595   if ($form->{printer_code} ne "") {
596     $form->{printer_code} = "_" . $form->{printer_code};
597   }
598
599   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
600   if ($form->{format} eq 'postscript') {
601     $form->{postscript} = 1;
602     $form->{IN} =~ s/html$/tex/;
603   } elsif ($form->{"format"} =~ /pdf/) {
604     $form->{pdf} = 1;
605     if ($form->{"format"} =~ /opendocument/) {
606       $form->{IN} =~ s/html$/odt/;
607     } else {
608       $form->{IN} =~ s/html$/tex/;
609     }
610   } elsif ($form->{"format"} =~ /opendocument/) {
611     $form->{"opendocument"} = 1;
612     $form->{"IN"} =~ s/html$/odt/;
613   }
614
615   if ($form->{"send_email"} && ($form->{email} ne "")) {
616     $form->{media} = 'email';
617   }
618
619   $form->{keep_tmpfile} = 0;
620   if ($form->{media} eq 'email') {
621     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
622       unless $form->{subject};
623     if (!$form->{email_attachment}) {
624       $form->{do_not_attach} = 1;
625     } else {
626       $form->{do_not_attach} = 0;
627     }
628     $form->{subject} = parse_strings($myconfig, $form, $userspath, $form->{email_subject});
629     $form->{message} = parse_strings($myconfig, $form, $userspath, $form->{email_body});
630
631     $form->{OUT} = "$sendmail";
632
633   } else {
634
635     my $filename = Common::unique_id() . $form->{login} . ".pdf";
636
637     push(@{ $form->{DUNNING_PDFS} }, $filename);
638     $form->{keep_tmpfile} = 1;
639   }
640
641   $form->parse_template($myconfig, $userspath);
642
643   $dbh->commit;
644   $dbh->disconnect;
645
646   $main::lxdebug->leave_sub();
647 }
648
649 1;