Bei Nummernkreisen auch Sonderzeichen erlauben (Perls eigener Algorithmus hinter...
[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        FROM ar LEFT JOIN dunning_config ON (dunning_config.id = ar.dunning_config_id)
164        LEFT JOIN dunning da ON (ar.id = da.trans_id AND dunning_config.dunning_level = da.dunning_level)
165        WHERE ar.id IN (|
166        . join(", ", map("?", @{ $form->{"inv_ids"} })) . qq|)|;
167
168   my $sth = prepare_execute_query($form, $dbh, $query, @{ $form->{"inv_ids"} });
169   my $first = 1;
170   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
171     if ($first) {
172       map({ $form->{"dn_$_"} = []; } keys(%{$ref}));
173       $first = 0;
174     }
175     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest);
176     map { $form->{$_} = $ref->{$_} } keys %$ref;
177     #print(STDERR Dumper($ref));
178     map { push(@{ $form->{"dn_$_"} }, $ref->{$_})} keys %$ref;
179   }
180   $sth->finish;
181
182   IS->customer_details($myconfig,$form);
183   #print(STDERR Dumper($form->{dn_invnumber}));
184   $form->{templates} = "$myconfig->{templates}";
185
186
187
188   $form->{language} = $form->get_template_language(\%myconfig);
189   $form->{printer_code} = $form->get_printer_code(\%myconfig);
190
191   if ($form->{language} ne "") {
192     $form->{language} = "_" . $form->{language};
193   }
194
195   if ($form->{printer_code} ne "") {
196     $form->{printer_code} = "_" . $form->{printer_code};
197   }
198
199   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
200   if ($form->{format} eq 'postscript') {
201     $form->{postscript} = 1;
202     $form->{IN} =~ s/html$/tex/;
203   } elsif ($form->{"format"} =~ /pdf/) {
204     $form->{pdf} = 1;
205     if ($form->{"format"} =~ /opendocument/) {
206       $form->{IN} =~ s/html$/odt/;
207     } else {
208       $form->{IN} =~ s/html$/tex/;
209     }
210   } elsif ($form->{"format"} =~ /opendocument/) {
211     $form->{"opendocument"} = 1;
212     $form->{"IN"} =~ s/html$/odt/;
213   }
214
215   if ($form->{"send_email"} && ($form->{email} ne "")) {
216     $form->{media} = 'email';
217   }
218
219   $form->{keep_tmpfile} = 0;
220   if ($form->{media} eq 'email') {
221     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
222       unless $form->{subject};
223     if (!$form->{email_attachment}) {
224       $form->{do_not_attach} = 1;
225     } else {
226       $form->{do_not_attach} = 0;
227     }
228     $form->{subject} = parse_strings($myconfig, $form, $userspath, $form->{email_subject});
229     $form->{message} = parse_strings($myconfig, $form, $userspath, $form->{email_body});
230
231     $form->{OUT} = "$sendmail";
232
233   } else {
234
235     my $filename = Common::unique_id() . $form->{login} . ".pdf";
236     $form->{OUT} = ">$spool/$filename";
237     push(@{ $form->{DUNNING_PDFS} }, $filename);
238     $form->{keep_tmpfile} = 1;
239   }
240
241   delete($form->{tmpfile});
242   $form->parse_template($myconfig, $userspath);
243
244   $dbh->commit;
245   $dbh->disconnect;
246
247   $main::lxdebug->leave_sub();
248 }
249
250 sub get_invoices {
251
252   $main::lxdebug->enter_sub();
253
254   my ($self, $myconfig, $form) = @_;
255
256   # connect to database
257   my $dbh = $form->dbconnect($myconfig);
258
259   my $where =
260     qq| WHERE (a.paid < a.amount)
261           AND (a.duedate < current_date)
262           AND (dnn.id =
263             (SELECT id FROM dunning_config
264              WHERE dunning_level >
265                (SELECT
266                   CASE
267                     WHEN a.dunning_config_id IS NULL
268                     THEN 0
269                     ELSE (SELECT dunning_level
270                           FROM dunning_config
271                           WHERE id = a.dunning_config_id
272                           ORDER BY dunning_level
273                           LIMIT 1)
274                   END
275                 FROM dunning_config LIMIT 1)
276              LIMIT 1)) |;
277   my @values;
278
279   $form->{customer_id} = $1 if ($form->{customer} =~ /--(\d+)$/);
280
281   if ($form->{customer_id}) {
282     $where .= qq| AND (a.customer_id = ?)|;
283     push(@values, $form->{customer_id});
284
285   } elsif ($form->{customer}) {
286     $where .= qq| AND (ct.name ILIKE ?)|;
287     push(@values, '%' . $form->{customer} . '%');
288   }
289
290   my %columns = (
291     "ordnumber" => "a.ordnumber",
292     "invnumber" => "a.invnumber",
293     "notes" => "a.notes",
294     );
295   foreach my $key (keys(%columns)) {
296     next unless ($form->{$key});
297     $where .= qq| AND $columns{$key} ILIKE ?|;
298     push(@values, '%' . $form->{$key} . '%');
299   }
300
301   if ($form->{dunning_level}) {
302     $where .= qq| AND a.dunning_config_id = ?|;
303     push(@values, conv_i($form->{dunning_level}));
304   }
305
306   $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount});
307   if ($form->{minamount}) {
308     $where .= qq| AND ((a.amount - a.paid) > ?) |;
309     push(@values, $form->{minamount});
310   }
311
312   $paymentdate = $form->{paymentuntil} ? $dbh->quote($form->{paymentuntil}) :
313     "current_date";
314
315   $query =
316     qq|SELECT a.id, a.ordnumber, a.transdate, a.invnumber, a.amount,
317          ct.name AS customername, a.customer_id, a.duedate,
318          da.fee AS old_fee, dnn.active, dnn.email, dnn.fee + da.fee AS fee,
319          dn.dunning_description, da.transdate AS dunning_date, da.duedate AS dunning_duedate,
320          a.duedate + dnn.terms - current_date AS nextlevel,
321          $paymentdate - a.duedate AS pastdue, dn.dunning_level,
322          current_date + dnn.payment_terms AS next_duedate,
323          dnn.dunning_description AS next_dunning_description, dnn.id AS next_dunning_config_id,
324          dnn.interest AS interest_rate, dnn.terms
325        FROM dunning_config dnn, ar a
326        JOIN customer ct ON (a.customer_id = ct.id)
327        LEFT JOIN dunning_config dn ON (dn.id = a.dunning_config_id)
328        LEFT JOIN dunning da ON ((da.trans_id = a.id) AND (dn.dunning_level = da.dunning_level))
329        $where
330        ORDER BY a.id, transdate, duedate, name|;
331
332   my $sth = prepare_execute_query($form, $dbh, $query, @values);
333
334   $form->{DUNNINGS} = [];
335
336   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
337     $ref->{interest} = ($ref->{amount} * $ref->{pastdue} * $ref->{interest_rate}) / 360;
338     $ref->{interest} = $form->round_amount($ref->{interest}, 2);
339     map({ $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest));
340     if ($ref->{pastdue} >= $ref->{terms}) {
341       push(@{ $form->{DUNNINGS} }, $ref);
342     }
343   }
344
345   $sth->finish;
346
347   $query = qq|SELECT id, dunning_description FROM dunning_config ORDER BY dunning_level|;
348   $form->{DUNNING_CONFIG} = selectall_hashref_query($form, $dbh, $query);
349
350   $dbh->disconnect;
351   $main::lxdebug->leave_sub();
352 }
353
354 sub get_dunning {
355
356   $main::lxdebug->enter_sub();
357
358   my ($self, $myconfig, $form) = @_;
359
360   # connect to database
361   my $dbh = $form->dbconnect($myconfig);
362
363   $where = qq| WHERE (da.trans_id = a.id)|;
364
365   my @values;
366
367   $form->{customer_id} = $1 if ($form->{customer} =~ /--(\d+)$/);
368
369   if ($form->{customer_id}) {
370     $where .= qq| AND (a.customer_id = ?)|;
371     push(@values, $form->{customer_id});
372
373   } elsif ($form->{customer}) {
374     $where .= qq| AND (ct.name ILIKE ?)|;
375     push(@values, '%' . $form->{customer} . '%');
376   }
377
378
379   my %columns = (
380     "ordnumber" => "a.ordnumber",
381     "invnumber" => "a.invnumber",
382     "notes" => "a.notes",
383     );
384   foreach my $key (keys(%columns)) {
385     next unless ($form->{$key});
386     $where .= qq| AND $columns{$key} ILIKE ?|;
387     push(@values, '%' . $form->{$key} . '%');
388   }
389
390   if ($form->{dunning_level}) {
391     $where .= qq| AND a.dunning_config_id = ?|;
392     push(@values, conv_i($form->{dunning_level}));
393   }
394
395   $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount});
396   if ($form->{minamount}) {
397     $where .= qq| AND ((a.amount - a.paid) > ?) |;
398     push(@values, $form->{minamount});
399   }
400
401   if (!$form->{showold}) {
402     $where .= qq| AND (a.amount > a.paid) AND (da.dunning_config_id = a.dunning_config_id) |;
403   }
404
405   if ($form->{transdatefrom}) {
406     $where .= qq| AND a.transdate >= ?|;
407     push(@values, $form->{transdatefrom});
408   }
409   if ($form->{transdateto}) {
410     $where .= qq| AND a.transdate <= ?|;
411     push(@values, $form->{transdateto});
412   }
413   if ($form->{dunningfrom}) {
414     $where .= qq| AND da.transdate >= ?|;
415     push(@values, $form->{dunningfrom});
416   }
417   if ($form->{dunningto}) {
418     $where .= qq| AND da.transdate >= ?|;
419     push(@values, $form->{dunningto});
420   }
421
422   $query =
423     qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount,
424          ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
425          da.interest, dn.dunning_description, da.transdate AS dunning_date,
426          da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id
427        FROM ar a
428        JOIN customer ct ON (a.customer_id = ct.id), dunning da
429        LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id)
430        $where
431        ORDER BY name, a.id|;
432
433   $form->{DUNNINGS} = selectall_hashref_query($form, $dbh, $query, @values);
434
435   foreach my $ref (@{ $form->{DUNNINGS} }) {
436     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest);
437   }
438
439   $dbh->disconnect;
440   $main::lxdebug->leave_sub();
441 }
442
443 sub parse_strings {
444
445   $main::lxdebug->enter_sub();
446
447   my ($myconfig, $form, $userspath, $string) = @_;
448
449   my $format = $form->{format};
450   $form->{format} = "html";
451
452   $tmpstring = "parse_string.html";
453   $tmpfile = "$myconfig->{templates}/$tmpstring";
454   open(OUT, ">$tmpfile") or $form->error("$tmpfile : $!");
455   print(OUT $string);
456   close(OUT);
457
458   my $in = $form->{IN};
459   $form->{IN} = $tmpstring;
460   $template = HTMLTemplate->new($tmpstring, $form, $myconfig, $userspath);
461
462   my $fileid = time;
463   $form->{tmpfile} = "$userspath/${fileid}.$tmpstring";
464   $out = $form->{OUT};
465   $form->{OUT} = ">$form->{tmpfile}";
466
467   if ($form->{OUT}) {
468     open(OUT, "$form->{OUT}") or $form->error("$form->{OUT} : $!");
469   }
470   if (!$template->parse(*OUT)) {
471     $form->cleanup();
472     $form->error("$form->{IN} : " . $template->get_error());
473   }
474
475   close(OUT);
476   my $result = "";
477   open(IN, $form->{tmpfile}) or $form->error($form->cleanup . "$form->{tmpfile} : $!");
478
479   while (<IN>) {
480     $result .= $_;
481   }
482
483   close(IN);
484 #   unlink($tmpfile);
485 #   unlink($form->{tmpfile});
486   $form->{IN} = $in;
487   $form->{format} = $format;
488
489   $main::lxdebug->leave_sub();
490   return $result;
491 }
492
493 sub melt_pdfs {
494
495   $main::lxdebug->enter_sub();
496
497   my ($self, $myconfig, $form, $userspath) = @_;
498
499   foreach my $file (@{ $form->{DUNNING_PDFS} }) {
500     $inputfiles .= " $userspath/$file ";
501   }
502
503   my $outputfile = "$userspath/dunning.pdf";
504   system("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$outputfile $inputfiles");
505   foreach my $file (@{ $form->{DUNNING_PDFS} }) {
506     unlink("$userspath/$file");
507   }
508   $out = "";
509
510   $form->{OUT} = $out;
511
512   my $numbytes = (-s $outputfile);
513   open(IN, $outputfile)
514     or $form->error($self->cleanup . "$outputfile : $!");
515
516   $form->{copies} = 1 unless $form->{media} eq 'printer';
517
518   chdir("$self->{cwd}");
519
520   for my $i (1 .. $form->{copies}) {
521     if ($form->{OUT}) {
522       open(OUT, $form->{OUT})
523         or $form->error($form->cleanup . "$form->{OUT} : $!");
524     } else {
525
526       # launch application
527       print qq|Content-Type: Application/PDF
528 Content-Disposition: attachment; filename="$outputfile"
529 Content-Length: $numbytes
530
531 |;
532
533       open(OUT, ">-") or $form->error($form->cleanup . "$!: STDOUT");
534
535     }
536
537     while (<IN>) {
538       print OUT $_;
539     }
540
541     close(OUT);
542
543     seek(IN, 0, 0);
544   }
545
546   close(IN);
547   unlink("$userspath/$outputfile");
548
549   $main::lxdebug->leave_sub();
550 }
551
552 sub print_dunning {
553   $main::lxdebug->enter_sub();
554
555   my ($self, $myconfig, $form, $dunning_id, $userspath,$spool, $sendmail) = @_;
556   # connect to database
557   my $dbh = $form->dbconnect_noauto($myconfig);
558
559   my $query =
560     qq|SELECT invnumber, ordnumber, customer_id, amount, netamount,
561          ar.transdate, ar.duedate, paid, amount - paid AS open_amount,
562          template AS formname, email_subject, email_body, email_attachment,
563          da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate
564        FROM dunning da
565        LEFT JOIN dunning_config ON (dunning_config.id = da.dunning_config_id)
566        LEFT JOIN ar ON (ar.id = da.trans_id)
567        WHERE (da.dunning_id = ?)|;
568
569   my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id);
570   my $first = 1;
571   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
572     if ($first) {
573       map({ $form->{"dn_$_"} = []; } keys(%{$ref}));
574       $first = 0;
575     }
576     map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest);
577     map { $form->{$_} = $ref->{$_} } keys %$ref;
578     map { push @{ $form->{"dn_$_"} }, $ref->{$_}} keys %$ref;
579   }
580   $sth->finish;
581
582   IS->customer_details($myconfig,$form);
583   $form->{templates} = "$myconfig->{templates}";
584
585   $form->{language} = $form->get_template_language(\%myconfig);
586   $form->{printer_code} = $form->get_printer_code(\%myconfig);
587
588   if ($form->{language} ne "") {
589     $form->{language} = "_" . $form->{language};
590   }
591
592   if ($form->{printer_code} ne "") {
593     $form->{printer_code} = "_" . $form->{printer_code};
594   }
595
596   $form->{IN} = "$form->{formname}$form->{language}$form->{printer_code}.html";
597   if ($form->{format} eq 'postscript') {
598     $form->{postscript} = 1;
599     $form->{IN} =~ s/html$/tex/;
600   } elsif ($form->{"format"} =~ /pdf/) {
601     $form->{pdf} = 1;
602     if ($form->{"format"} =~ /opendocument/) {
603       $form->{IN} =~ s/html$/odt/;
604     } else {
605       $form->{IN} =~ s/html$/tex/;
606     }
607   } elsif ($form->{"format"} =~ /opendocument/) {
608     $form->{"opendocument"} = 1;
609     $form->{"IN"} =~ s/html$/odt/;
610   }
611
612   if ($form->{"send_email"} && ($form->{email} ne "")) {
613     $form->{media} = 'email';
614   }
615
616   $form->{keep_tmpfile} = 0;
617   if ($form->{media} eq 'email') {
618     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
619       unless $form->{subject};
620     if (!$form->{email_attachment}) {
621       $form->{do_not_attach} = 1;
622     } else {
623       $form->{do_not_attach} = 0;
624     }
625     $form->{subject} = parse_strings($myconfig, $form, $userspath, $form->{email_subject});
626     $form->{message} = parse_strings($myconfig, $form, $userspath, $form->{email_body});
627
628     $form->{OUT} = "$sendmail";
629
630   } else {
631
632     my $filename = Common::unique_id() . $form->{login} . ".pdf";
633
634     push(@{ $form->{DUNNING_PDFS} }, $filename);
635     $form->{keep_tmpfile} = 1;
636   }
637
638   $form->parse_template($myconfig, $userspath);
639
640   $dbh->commit;
641   $dbh->disconnect;
642
643   $main::lxdebug->leave_sub();
644 }
645
646 1;