1 #======================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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., 51 Franklin Street, Fifth Floor, Boston,
30 #======================================================================
32 # Dunning process module
34 #======================================================================
44 use SL::GenericTranslations;
52 use SL::Util qw(trim);
57 use File::Slurp qw(read_file);
62 $main::lxdebug->enter_sub();
64 my ($self, $myconfig, $form) = @_;
67 my $dbh = SL::DB->client->dbh;
71 qq|FROM dunning_config | .
72 qq|ORDER BY dunning_level|;
73 $form->{DUNNING} = selectall_hashref_query($form, $dbh, $query);
75 foreach my $ref (@{ $form->{DUNNING} }) {
76 $ref->{fee} = $form->format_amount($myconfig, $ref->{fee}, 2);
77 $ref->{interest_rate} = $form->format_amount($myconfig, ($ref->{interest_rate} * 100));
81 qq|SELECT dunning_ar_amount_fee, dunning_ar_amount_interest, dunning_ar, dunning_creator,
82 dunning_original_invoice_creation_mode
84 ($form->{AR_amount_fee}, $form->{AR_amount_interest}, $form->{AR}, $form->{dunning_creator},
85 $form->{dunning_original_invoice_creation_mode})
86 = selectrow_query($form, $dbh, $query);
88 $main::lxdebug->leave_sub();
92 my ($self, $myconfig, $form) = @_;
93 $main::lxdebug->enter_sub();
95 my $rc = SL::DB->client->with_transaction(\&_save_config, $self, $myconfig, $form);
97 $::lxdebug->leave_sub;
102 my ($self, $myconfig, $form) = @_;
104 my $dbh = SL::DB->client->dbh;
106 my ($query, @values);
108 for my $i (1 .. $form->{rowcount}) {
109 $form->{"fee_$i"} = $form->parse_amount($myconfig, $form->{"fee_$i"}) * 1;
110 $form->{"interest_rate_$i"} = $form->parse_amount($myconfig, $form->{"interest_rate_$i"}) / 100;
112 if (($form->{"dunning_level_$i"} ne "") &&
113 ($form->{"dunning_description_$i"} ne "")) {
114 @values = (conv_i($form->{"dunning_level_$i"}), $form->{"dunning_description_$i"},
115 $form->{"email_subject_$i"}, $form->{"email_body_$i"},
116 $form->{"template_$i"}, $form->{"fee_$i"}, $form->{"interest_rate_$i"},
117 $form->{"active_$i"} ? 't' : 'f', $form->{"auto_$i"} ? 't' : 'f', $form->{"email_$i"} ? 't' : 'f',
118 $form->{"email_attachment_$i"} ? 't' : 'f', conv_i($form->{"payment_terms_$i"}), conv_i($form->{"terms_$i"}),
119 $form->{"create_invoices_for_fees_$i"} ? 't' : 'f',
120 $form->{"print_original_invoice_$i"} ? 't' : 'f');
121 if ($form->{"id_$i"}) {
123 qq|UPDATE dunning_config SET
124 dunning_level = ?, dunning_description = ?,
125 email_subject = ?, email_body = ?,
126 template = ?, fee = ?, interest_rate = ?,
127 active = ?, auto = ?, email = ?,
128 email_attachment = ?, payment_terms = ?, terms = ?,
129 create_invoices_for_fees = ?,
130 print_original_invoice = ?
132 push(@values, conv_i($form->{"id_$i"}));
135 qq|INSERT INTO dunning_config
136 (dunning_level, dunning_description, email_subject, email_body,
137 template, fee, interest_rate, active, auto, email,
138 email_attachment, payment_terms, terms, create_invoices_for_fees,
139 print_original_invoice)
140 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
142 do_query($form, $dbh, $query, @values);
145 if (($form->{"dunning_description_$i"} eq "") && ($form->{"id_$i"})) {
146 $query = qq|DELETE FROM dunning_config WHERE id = ?|;
147 do_query($form, $dbh, $query, $form->{"id_$i"});
151 $query = qq|UPDATE defaults SET dunning_ar_amount_fee = ?, dunning_ar_amount_interest = ?, dunning_ar = ?,
152 dunning_creator = ?, dunning_original_invoice_creation_mode = ?|;
153 @values = (conv_i($form->{AR_amount_fee}), conv_i($form->{AR_amount_interest}), conv_i($form->{AR}),
154 $form->{dunning_creator}, $form->{dunning_original_invoice_creation_mode});
155 do_query($form, $dbh, $query, @values);
160 sub create_invoice_for_fees {
161 $main::lxdebug->enter_sub();
163 my ($self, $myconfig, $form, $dbh, $dunning_id) = @_;
165 my ($query, @values, $sth, $ref);
167 $query = qq|SELECT dcfg.create_invoices_for_fees
169 LEFT JOIN dunning_config dcfg ON (d.dunning_config_id = dcfg.id)
170 WHERE d.dunning_id = ?|;
171 my ($create_invoices_for_fees) = selectrow_query($form, $dbh, $query, $dunning_id);
173 if (!$create_invoices_for_fees) {
174 $main::lxdebug->leave_sub();
178 $query = qq|SELECT dunning_ar_amount_fee, dunning_ar_amount_interest, dunning_ar FROM defaults|;
179 ($form->{AR_amount_fee}, $form->{AR_amount_interest}, $form->{AR}) = selectrow_query($form, $dbh, $query);
185 SELECT MAX(d_fee.fee)
187 WHERE (d_fee.trans_id = d.trans_id)
188 AND (d_fee.dunning_id <> ?)
189 AND NOT (d_fee.fee_interest_ar_id ISNULL)
194 SELECT MAX(d_interest.interest)
195 FROM dunning d_interest
196 WHERE (d_interest.trans_id = d.trans_id)
197 AND (d_interest.dunning_id <> ?)
198 AND NOT (d_interest.fee_interest_ar_id ISNULL)
200 AS max_previous_interest,
203 WHERE dunning_id = ?|;
204 @values = ($dunning_id, $dunning_id, $dunning_id);
205 $sth = prepare_execute_query($form, $dbh, $query, @values);
207 my ($fee_remaining, $interest_remaining) = (0, 0);
208 my ($fee_total, $interest_total) = (0, 0);
212 while (my $ref = $sth->fetchrow_hashref()) {
213 $fee_remaining += $form->round_amount($ref->{fee}, 2);
214 $fee_remaining -= $form->round_amount($ref->{max_previous_fee}, 2);
215 $fee_total += $form->round_amount($ref->{fee}, 2);
216 $interest_remaining += $form->round_amount($ref->{interest}, 2);
217 $interest_remaining -= $form->round_amount($ref->{max_previous_interest}, 2);
218 $interest_total += $form->round_amount($ref->{interest}, 2);
219 push @link_ids, $ref->{link_id};
224 my $amount = $fee_remaining + $interest_remaining;
227 $main::lxdebug->leave_sub();
231 my ($ar_id) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
232 my $curr = $form->get_default_currency($myconfig);
233 my $trans_number = SL::TransNumber->new(type => 'invoice', dbh => $dbh);
236 qq|INSERT INTO ar (id, invnumber, transdate, gldate, customer_id,
237 taxincluded, amount, netamount, paid, duedate,
238 invoice, currency_id, taxzone_id, notes,
243 current_date, -- transdate
244 current_date, -- gldate
246 (SELECT ar.customer_id
248 LEFT JOIN ar ON (dn.trans_id = ar.id)
249 WHERE dn.dunning_id = ?
256 (SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1),
258 (SELECT id FROM currencies WHERE name = ?), -- curr
260 (SELECT taxzone_id FROM customer WHERE id =
261 (SELECT ar.customer_id
263 LEFT JOIN ar ON (dn.trans_id = ar.id)
264 WHERE dn.dunning_id = ?
269 (SELECT id FROM employee WHERE login = ?)
271 @values = ($ar_id, # id
272 $trans_number->create_unique, # invnumber
273 $dunning_id, # customer_id
276 $dunning_id, # duedate
277 $curr, # default currency
278 $dunning_id, # taxzone_id
279 sprintf($main::locale->text('Automatically created invoice for fee and interest for dunning %s'), $dunning_id), # notes
280 $::myconfig{login}); # employee_id
281 do_query($form, $dbh, $query, @values);
283 RecordLinks->create_links(
286 'from_table' => 'dunning',
287 'from_ids' => \@link_ids,
293 qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, taxkey, tax_id, chart_link)
294 VALUES (?, ?, ?, current_date, current_date, 0,
295 (SELECT id FROM tax WHERE (taxkey = 0) AND (rate = 0)),
296 (SELECT link FROM chart WHERE id = ?))|;
297 $sth = prepare_query($form, $dbh, $query);
299 @values = ($ar_id, conv_i($form->{AR_amount_fee}), $fee_remaining, conv_i($form->{AR_amount_fee}));
300 do_statement($form, $sth, $query, @values);
302 if ($interest_remaining) {
303 @values = ($ar_id, conv_i($form->{AR_amount_interest}), $interest_remaining, conv_i($form->{AR_amount_interest}));
304 do_statement($form, $sth, $query, @values);
307 @values = ($ar_id, conv_i($form->{AR}), -1 * $amount, conv_i($form->{AR}));
308 do_statement($form, $sth, $query, @values);
312 $query = qq|UPDATE dunning SET fee_interest_ar_id = ? WHERE dunning_id = ?|;
313 do_query($form, $dbh, $query, $ar_id, $dunning_id);
315 $main::lxdebug->leave_sub();
320 my ($self, $myconfig, $form, $rows) = @_;
321 $main::lxdebug->enter_sub();
323 $form->{DUNNING_PDFS_STORAGE} = [];
325 # Catch any error, either exception or a call to form->error
326 # and return it to the calling function.
329 local $form->{__ERROR_HANDLER} = sub { die @_ };
330 $rc = SL::DB->client->with_transaction(\&_save_dunning, $self, $myconfig, $form, $rows);
336 # Save PDFs in filemanagement and webdav after transation succeeded,
337 # because otherwise files in the storage may exists if the transaction
338 # failed. Ignore all errors.
339 # Todo: Maybe catch errors and display them as warnings or non fatal errors in the status.
340 if (!$error && $form->{DUNNING_PDFS_STORAGE} && scalar @{ $form->{DUNNING_PDFS_STORAGE} }) {
341 _store_pdf_to_webdav_and_filemanagement($_->{dunning_id}, $_->{path}, $_->{name}) for @{ $form->{DUNNING_PDFS_STORAGE} };
344 $error = 'unknown error' if !$error && !$rc;
345 $rc->{error} = $error if $error;
347 $::lxdebug->leave_sub;
354 my ($self, $myconfig, $form, $rows) = @_;
356 my $dbh = SL::DB->client->dbh;
358 my ($query, @values);
360 my ($dunning_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
362 my $q_update_ar = qq|UPDATE ar SET dunning_config_id = ? WHERE id = ?|;
363 my $h_update_ar = prepare_query($form, $dbh, $q_update_ar);
365 my $q_insert_dunning =
366 qq|INSERT INTO dunning (id, dunning_id, dunning_config_id, dunning_level, trans_id,
367 fee, interest, transdate, duedate, original_invoice_printed)
369 (SELECT dunning_level FROM dunning_config WHERE id = ?),
373 WHERE dunning_level <= (SELECT dunning_level FROM dunning_config WHERE id = ?)),
374 (SELECT (amount - paid) * (current_date - duedate) FROM ar WHERE id = ?)
375 * (SELECT interest_rate FROM dunning_config WHERE id = ?)
378 current_date + (SELECT payment_terms FROM dunning_config WHERE id = ?),
380 my $h_insert_dunning = prepare_query($form, $dbh, $q_insert_dunning);
383 my ($next_dunning_config_id, $customer_id);
384 my ($send_email, $print_invoice) = (0, 0);
386 foreach my $row (@{ $rows }) {
387 if ($row->{credit_note}) {
389 %{ $form->{LIST_CREDIT_NOTES}{$row->{customer_id}}{$row->{invoice_id}} } = (
390 open_amount => $form->{"open_amount_$i"},
391 amount => $form->{"amount_$i"},
392 invnumber => $form->{"invnumber_$i"},
393 invdate => $form->{"invdate_$i"},
397 push @invoice_ids, $row->{invoice_id};
398 $next_dunning_config_id = $row->{next_dunning_config_id};
399 $customer_id = $row->{customer_id};
401 @values = ($row->{next_dunning_config_id}, $row->{invoice_id});
402 do_statement($form, $h_update_ar, $q_update_ar, @values);
404 $send_email |= $row->{email};
405 $print_invoice |= $row->{print_invoice};
407 my ($row_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
408 my $next_config_id = conv_i($row->{next_dunning_config_id});
409 my $invoice_id = conv_i($row->{invoice_id});
411 @values = ($row_id, $dunning_id, $next_config_id,
412 $next_config_id, $invoice_id, $next_config_id,
413 $invoice_id, $next_config_id, $next_config_id,
415 do_statement($form, $h_insert_dunning, $q_insert_dunning, @values);
417 RecordLinks->create_links(
420 'from_table' => 'ar',
421 'from_ids' => $invoice_id,
422 'to_table' => 'dunning',
426 # die this transaction, because for this customer only credit notes are
428 die "only credit notes are selected for this customer\n" unless $customer_id;
430 $h_update_ar->finish();
431 $h_insert_dunning->finish();
433 $form->{DUNNING_PDFS_EMAIL} = [];
435 $form->{dunning_id} = $dunning_id;
436 $form->{media} = 'email' if $send_email;
437 $self->create_invoice_for_fees($myconfig, $form, $dbh, $dunning_id);
439 $self->print_invoice_for_fees($myconfig, $form, $dunning_id, $dbh);
440 $self->print_dunning($myconfig, $form, $dunning_id, $dbh);
442 if ($print_invoice) {
443 $self->print_original_invoice($myconfig, $form, $dunning_id, $_) for @invoice_ids;
447 $self->send_email($myconfig, $form, $dunning_id, $dbh);
450 return ({dunning_id => $dunning_id, print_original_invoice => $print_invoice, send_email => $send_email});
454 $main::lxdebug->enter_sub();
456 my ($self, $myconfig, $form, $dunning_id, $dbh) = @_;
460 dcfg.email_body, dcfg.email_subject, dcfg.email_attachment,
461 COALESCE (NULLIF(aba.dunning_mail, ''), NULLIF(aba.email,''),
462 NULLIF(c.dunning_mail, ''),
463 NULLIF(c.invoice_mail, ''), c.email) AS recipient, c.name,
464 (SELECT login from employee where id = ar.employee_id) as invoice_employee_login
466 LEFT JOIN dunning_config dcfg ON (d.dunning_config_id = dcfg.id)
467 LEFT JOIN ar ON (d.trans_id = ar.id)
468 LEFT JOIN customer c ON (ar.customer_id = c.id)
469 LEFT JOIN additional_billing_addresses aba ON (aba.id = ar.billing_address_id)
470 WHERE (d.dunning_id = ?)
472 my $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
474 # without a recipient, we cannot send a mail
475 if (!$ref || !$ref->{recipient}) {
476 $main::lxdebug->leave_sub();
477 die $main::locale->text("No email recipient for customer #1 defined.", $ref->{name});
480 # without a sender we cannot send a mail
481 # two cases: check mail from 1. current user OR 2. employee who created the invoice
483 if ($::instance_conf->get_dunning_creator eq 'current_employee') {
484 $from = $myconfig->{email};
485 die $main::locale->text('No email for current user #1 defined.', $myconfig->{name}) unless $from;
488 $from = SL::DB::Manager::AuthUser->find_by(login => $ref->{invoice_employee_login})->get_config_value("email");
489 $sign = SL::DB::Manager::AuthUser->find_by(login => $ref->{invoice_employee_login})->get_config_value("signature");
492 } or die $main::locale->text('No email for user with login #1 defined.', $ref->{invoice_employee_login});
495 my $html_template = SL::Template::create(type => 'HTML', form => $form, myconfig => $myconfig);
496 $html_template->set_tag_style('<%', '%>');
498 my $template = SL::Template::create(type => 'PlainText', form => $form, myconfig => $myconfig);
499 my $mail = Mailer->new();
500 $mail->{bcc} = $form->get_bcc_defaults($myconfig, $form->{bcc});
501 $mail->{from} = $from;
502 $mail->{to} = $ref->{recipient};
503 $mail->{subject} = $template->parse_block($ref->{email_subject});
504 $mail->{message} = $html_template->parse_block($ref->{email_body});
505 $mail->{content_type} = 'text/html';
506 my $sign_backup = $::myconfig{signature};
507 $::myconfig{signature} = $sign if $sign;
508 $mail->{message} .= $form->create_email_signature();
509 $::myconfig{signature} = $sign_backup if $sign;
511 $mail->{message} =~ s/\r\n/\n/g;
513 if ($ref->{email_attachment} && @{ $form->{DUNNING_PDFS_EMAIL} }) {
514 $mail->{attachments} = $form->{DUNNING_PDFS_EMAIL};
517 $query = qq|SELECT id FROM dunning WHERE dunning_id = ?|;
518 my @ids = selectall_array_query($form, $dbh, $query, $dunning_id);
519 $mail->{record_id} = \@ids;
520 $mail->{record_type} = 'dunning';
522 my $error = $mail->send();
523 die "Mailer error during 'send': $error\n" if $error;
525 $main::lxdebug->leave_sub();
528 sub set_template_options {
529 $main::lxdebug->enter_sub();
531 my ($self, $myconfig, $form) = @_;
533 my $defaults = SL::DB::Default->get;
534 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
535 $form->{templates} = $defaults->templates;
536 $form->{language} = $form->get_template_language($myconfig);
537 $form->{printer_code} = $form->get_printer_code($myconfig);
539 if ($form->{language} ne "") {
540 $form->{language} = "_" . $form->{language};
543 if ($form->{printer_code} ne "") {
544 $form->{printer_code} = "_" . $form->{printer_code};
547 my $extension = 'html';
548 if ($form->{format} eq 'postscript') {
549 $form->{postscript} = 1;
552 } elsif ($form->{"format"} =~ /pdf/) {
554 $extension = $form->{'format'} =~ m/opendocument/i ? 'odt' : 'tex';
556 } elsif ($form->{"format"} =~ /opendocument/) {
557 $form->{opendocument} = 1;
559 } elsif ($form->{"format"} =~ /excel/) {
565 # search for the template
567 push @template_files, "$form->{formname}_email$form->{language}$form->{printer_code}.$extension" if $form->{media} eq 'email';
568 push @template_files, "$form->{formname}$form->{language}$form->{printer_code}.$extension";
569 push @template_files, "$form->{formname}.$extension";
570 push @template_files, "default.$extension";
573 for my $filename (@template_files) {
574 if (-f ($defaults->templates . "/$filename")) {
575 $form->{IN} = $filename;
580 if (!defined $form->{IN}) {
581 $::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));
584 # prepare meta information for template introspection
585 $form->{template_meta} = {
586 formname => $form->{formname},
587 language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id} || undef),
588 format => $form->{format},
589 media => $form->{media},
590 extension => $extension,
591 printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id} || undef),
592 today => DateTime->today,
595 $main::lxdebug->leave_sub();
600 $main::lxdebug->enter_sub();
602 my ($self, $myconfig, $form) = @_;
604 # connect to database
605 my $dbh = SL::DB->client->dbh;
610 $form->{customer_id} = $1 if ($form->{customer} =~ /--(\d+)$/);
612 if ($form->{customer_id}) {
613 $where .= qq| AND (a.customer_id = ?)|;
614 push(@values, $form->{customer_id});
616 } elsif ($form->{customer}) {
617 $where .= qq| AND (ct.name ILIKE ?)|;
618 push(@values, like($form->{customer}));
621 if ($form->{department_id}) {
622 $where .= qq| AND (a.department_id = ?)|;
623 push(@values, $form->{department_id});
626 if ($form->{payment_id}) {
627 $where .= " AND a.payment_id = ?";
628 push(@values, $form->{payment_id});
631 if ($form->{invoice}) {
632 $where .= " AND a.invoice = ?";
633 push(@values, $form->{invoice});
637 "ordnumber" => "a.ordnumber",
638 "invnumber" => "a.invnumber",
639 "notes" => "a.notes",
640 "country" => "ct.country",
642 foreach my $key (keys(%columns)) {
643 next unless ($form->{$key});
644 $where .= qq| AND $columns{$key} ILIKE ?|;
645 push(@values, like($form->{$key}));
648 if ($form->{dunning_level}) {
649 $where .= qq| AND nextcfg.id = ?|;
650 push(@values, conv_i($form->{dunning_level}));
653 $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount});
654 if ($form->{minamount}) {
655 $where .= qq| AND ((a.amount - a.paid) > ?) |;
656 push(@values, trim($form->{minamount}));
662 WHERE dunning_level = (SELECT MAX(dunning_level) FROM dunning_config)|;
663 my ($id_for_max_dunning_level) = selectrow_query($form, $dbh, $query);
665 if (!$form->{l_include_direct_debit}) {
666 $where .= qq| AND NOT COALESCE(a.direct_debit, FALSE) |;
668 my $paid = ($form->{l_include_credit_notes}) ? "WHERE (a.paid <> a.amount)" : "WHERE (a.paid < a.amount)";
672 a.id, a.invoice, a.ordnumber, a.transdate, a.invnumber, a.amount, a.language_id,
673 ct.name AS customername, a.customer_id, a.duedate,
674 a.amount - a.paid AS open_amount,
676 pt.description as payment_term,
677 dep.description as departmentname,
678 COALESCE (NULLIF(aba.dunning_mail, ''), NULLIF(aba.email,''),
679 NULLIF(ct.dunning_mail, ''),
680 NULLIF(ct.invoice_mail, ''), ct.email) AS recipient,
681 cfg.dunning_description, cfg.dunning_level,
683 d.transdate AS dunning_date, d.duedate AS dunning_duedate,
686 a.duedate + cfg.terms - current_date AS nextlevel,
687 current_date - COALESCE(d.duedate, a.duedate) AS pastdue,
688 current_date + cfg.payment_terms AS next_duedate,
690 nextcfg.dunning_description AS next_dunning_description,
691 nextcfg.id AS next_dunning_config_id,
692 nextcfg.terms, nextcfg.active, nextcfg.email, nextcfg.print_original_invoice
696 LEFT JOIN customer ct ON (a.customer_id = ct.id)
697 LEFT JOIN additional_billing_addresses aba ON (aba.id = a.billing_address_id)
698 LEFT JOIN department dep ON (a.department_id = dep.id)
699 LEFT JOIN payment_terms pt ON (a.payment_id = pt.id)
700 LEFT JOIN dunning_config cfg ON (a.dunning_config_id = cfg.id)
701 LEFT JOIN dunning_config nextcfg ON
706 WHERE dunning_level >
707 COALESCE((SELECT dunning_level
709 WHERE id = a.dunning_config_id
710 ORDER BY dunning_level DESC
713 ORDER BY dunning_level ASC
716 LEFT JOIN dunning d ON (d.id = (
719 WHERE (d2.trans_id = a.id)
720 AND (d2.dunning_level = cfg.dunning_level)
723 AND (a.duedate < current_date)
724 AND ct.dunning_lock = false
728 ORDER BY ct.name, a.id, transdate, duedate |;
729 my $sth = prepare_execute_query($form, $dbh, $query, $id_for_max_dunning_level, @values);
731 $form->{DUNNINGS} = [];
733 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
734 next if ($ref->{pastdue} < $ref->{terms});
735 $ref->{credit_note} = 1 if ($ref->{amount} < 0 && $form->{l_include_credit_notes});
736 $ref->{interest} = $form->round_amount($ref->{interest}, 2);
737 push(@{ $form->{DUNNINGS} }, $ref);
742 $query = qq|SELECT id, dunning_description FROM dunning_config ORDER BY dunning_level|;
743 $form->{DUNNING_CONFIG} = selectall_hashref_query($form, $dbh, $query);
745 $main::lxdebug->leave_sub();
750 $main::lxdebug->enter_sub();
752 my ($self, $myconfig, $form) = @_;
754 # connect to database
755 my $dbh = SL::DB->client->dbh;
757 my $where = qq| WHERE (da.trans_id = a.id)|;
761 if ($form->{customer_id}) {
762 $where .= qq| AND (a.customer_id = ?)|;
763 push(@values, $form->{customer_id});
765 } elsif ($form->{customer}) {
766 $where .= qq| AND (ct.name ILIKE ?)|;
767 push(@values, like($form->{customer}));
771 "ordnumber" => "a.ordnumber",
772 "invnumber" => "a.invnumber",
773 "notes" => "a.notes",
775 foreach my $key (keys(%columns)) {
776 next unless ($form->{$key});
777 $where .= qq| AND $columns{$key} ILIKE ?|;
778 push(@values, like($form->{$key}));
781 if ($form->{dunning_id}) {
782 $where .= qq| AND da.dunning_id = ?|;
783 push(@values, conv_i($form->{dunning_id}));
786 if ($form->{dunning_level}) {
787 $where .= qq| AND a.dunning_config_id = ?|;
788 push(@values, conv_i($form->{dunning_level}));
791 if ($form->{department_id}) {
792 $where .= qq| AND a.department_id = ?|;
793 push @values, conv_i($form->{department_id});
796 $form->{minamount} = $form->parse_amount($myconfig, $form->{minamount});
797 if ($form->{minamount}) {
798 $where .= qq| AND ((a.amount - a.paid) > ?) |;
799 push(@values, $form->{minamount});
802 if (!$form->{showold}) {
803 $where .= qq| AND (a.amount > a.paid) AND (da.dunning_config_id = a.dunning_config_id) |;
806 if ($form->{transdatefrom}) {
807 $where .= qq| AND a.transdate >= ?|;
808 push(@values, $form->{transdatefrom});
810 if ($form->{transdateto}) {
811 $where .= qq| AND a.transdate <= ?|;
812 push(@values, $form->{transdateto});
814 if ($form->{dunningfrom}) {
815 $where .= qq| AND da.transdate >= ?|;
816 push(@values, $form->{dunningfrom});
818 if ($form->{dunningto}) {
819 $where .= qq| AND da.transdate >= ?|;
820 push(@values, $form->{dunningto});
823 if ($form->{salesman_id}) {
824 $where .= qq| AND a.salesman_id = ?|;
825 push(@values, conv_i($form->{salesman_id}));
829 'dunning_description' => [ qw(dn.dunning_description da.dunning_id customername invnumber) ],
830 'customername' => [ qw(customername da.dunning_id invnumber) ],
831 'invnumber' => [ qw(a.invnumber) ],
832 'transdate' => [ qw(a.transdate a.invnumber) ],
833 'duedate' => [ qw(a.duedate a.invnumber) ],
834 'dunning_date' => [ qw(dunning_date da.dunning_id a.invnumber) ],
835 'dunning_duedate' => [ qw(dunning_duedate da.dunning_id a.invnumber) ],
836 'dunning_id' => [ qw(dunning_id a.invnumber) ],
837 'salesman' => [ qw(salesman) ],
840 my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
841 my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : 'customername';
842 my $sortorder = join ', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} };
845 qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount, a.language_id,
846 ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
847 da.interest, dn.dunning_description, dn.dunning_level, da.transdate AS dunning_date,
848 da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id,
849 da.id AS dunning_table_id,
852 JOIN customer ct ON (a.customer_id = ct.id)
853 LEFT JOIN employee e2 ON (a.salesman_id = e2.id), dunning da
854 LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id)
856 ORDER BY $sortorder|;
858 $form->{DUNNINGS} = selectall_hashref_query($form, $dbh, $query, @values);
860 foreach my $ref (@{ $form->{DUNNINGS} }) {
861 map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest);
864 $main::lxdebug->leave_sub();
869 $main::lxdebug->enter_sub();
871 my ($self, $myconfig, $form, $copies, %params) = @_;
873 # Don't allow access outside of $spool.
874 map { $_ =~ s|.*/||; } @{ $form->{DUNNING_PDFS} };
877 $copies = 1 unless $copies;
878 my $spool = $::lx_office_conf{paths}->{spool};
879 my $inputfiles = join " ", map { "$spool/$_ " x $copies } @{ $form->{DUNNING_PDFS} };
880 my $dunning_id = $form->{dunning_id};
882 $dunning_id =~ s|[^\d]||g;
884 my $in = IO::File->new($::lx_office_conf{applications}->{ghostscript} . " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=- $inputfiles |");
885 $form->error($main::locale->text('Could not spawn ghostscript.')) unless $in;
887 my $dunning_filename = $form->get_formname_translation('dunning');
888 my $attachment_filename = "${dunning_filename}_${dunning_id}.pdf";
890 if ($params{return_content}) {
891 $content = read_file($in);
894 if ($form->{media} eq 'printer') {
895 $form->get_printer_code($myconfig);
897 if ($form->{printer_command}) {
898 $out = IO::File->new("| $form->{printer_command}");
901 $form->error($main::locale->text('Could not spawn the printer command.')) unless $out;
903 $::locale->with_raw_io($out, sub { $out->print($_) while <$in> });
906 print qq|Content-Type: Application/PDF\n| .
907 qq|Content-Disposition: attachment; filename=$attachment_filename\n\n|;
909 $::locale->with_raw_io(\*STDOUT, sub { print while <$in> });
915 map { unlink("$spool/$_") } @{ $form->{DUNNING_PDFS} };
917 $main::lxdebug->leave_sub();
918 return ($attachment_filename, $content) if $params{return_content};
922 $main::lxdebug->enter_sub();
924 my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
926 # connect to database
927 my $dbh = $provided_dbh || SL::DB->client->dbh;
929 $dunning_id =~ s|[^\d]||g;
931 my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
932 if ($form->{"language_id"}) {
933 ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) =
934 AM->get_language_details($myconfig, $form, $form->{language_id});
936 $output_dateformat = $myconfig->{dateformat};
937 $output_numberformat = $myconfig->{numberformat};
938 $output_longdates = 1;
944 da.transdate AS dunning_date,
945 da.duedate AS dunning_duedate,
947 dcfg.template AS formname,
948 dcfg.email_subject, dcfg.email_body, dcfg.email_attachment,
950 ar.transdate, ar.duedate, ar.customer_id,
951 ar.invnumber, ar.ordnumber, ar.cp_id,
952 ar.amount, ar.netamount, ar.paid,
953 ar.employee_id, ar.salesman_id,
954 (SELECT cu.name FROM currencies cu WHERE cu.id = ar.currency_id) AS curr,
955 (SELECT description from department WHERE id = ar.department_id) AS department,
956 ar.amount - ar.paid AS open_amount,
957 ar.amount - ar.paid + da.fee + da.interest AS linetotal
960 LEFT JOIN dunning_config dcfg ON (dcfg.id = da.dunning_config_id)
961 LEFT JOIN ar ON (ar.id = da.trans_id)
962 WHERE (da.dunning_id = ?)|;
964 my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id);
966 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
968 $form->{TEMPLATE_ARRAYS} = {};
969 map({ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} = []; } keys(%{$ref}));
972 map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest linetotal);
973 map { $form->{$_} = $ref->{$_} } keys %$ref;
974 map { push @{ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} }, $ref->{$_} } keys %$ref;
978 # if we have some credit notes to add, do a safety check on the first customer id
979 # and add one entry for each credit note
980 if ($form->{LIST_CREDIT_NOTES} && $form->{LIST_CREDIT_NOTES}->{$form->{TEMPLATE_ARRAYS}->{"dn_customer_id"}[0]}) {
981 my $first_customer_id = $form->{TEMPLATE_ARRAYS}->{"dn_customer_id"}[0];
982 while ( my ($cred_id, $value) = each(%{ $form->{LIST_CREDIT_NOTES}->{$first_customer_id} } ) ) {
983 map { push @{ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} }, $value->{$_} } keys %{ $value };
988 c.id AS customer_id, c.name, c.street, c.zipcode, c.city,
989 c.country, c.department_1, c.department_2, c.email, c.customernumber,
990 c.greeting, c.contact, c.phone, c.fax, c.homepage,
991 c.email, c.taxincluded, c.business_id, c.taxnumber, c.iban,
992 c.ustid, c.currency_id, curr.name as currency,
996 LEFT JOIN ar ON (d.trans_id = ar.id)
997 LEFT JOIN customer c ON (ar.customer_id = c.id)
998 LEFT JOIN contacts co ON (ar.cp_id = co.cp_id)
999 LEFT JOIN employee e ON (ar.salesman_id = e.id)
1000 LEFT JOIN currencies curr ON (c.currency_id = curr.id)
1001 WHERE (d.dunning_id = ?)
1003 my $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
1004 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
1008 cfg.interest_rate, cfg.template AS formname, cfg.dunning_level,
1009 cfg.email_subject, cfg.email_body, cfg.email_attachment,
1010 d.transdate AS dunning_date,
1013 WHERE dunning_id = ?)
1015 (SELECT SUM(interest)
1017 WHERE dunning_id = ?)
1019 (SELECT SUM(amount) - SUM(paid)
1024 WHERE dunning_id = ?))
1025 AS total_open_amount
1027 LEFT JOIN dunning_config cfg ON (d.dunning_config_id = cfg.id)
1028 WHERE d.dunning_id = ?
1030 $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id, $dunning_id, $dunning_id, $dunning_id);
1031 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
1033 $form->{interest_rate} = $form->format_amount($myconfig, $ref->{interest_rate} * 100);
1034 $form->{fee} = $form->format_amount($myconfig, $ref->{fee}, 2);
1035 $form->{total_interest} = $form->format_amount($myconfig, $form->round_amount($ref->{total_interest}, 2), 2);
1036 my $total_open_amount = $ref->{total_open_amount};
1037 if ($form->{l_include_credit_notes}) {
1038 # a bit stupid, but redo calc because of credit notes
1039 $total_open_amount = 0;
1040 foreach my $amount (@{ $form->{TEMPLATE_ARRAYS}->{dn_open_amount} }) {
1041 $total_open_amount += $form->parse_amount($myconfig, $amount, 2);
1044 $form->{total_open_amount} = $form->format_amount($myconfig, $form->round_amount($total_open_amount, 2), 2);
1045 $form->{total_amount} = $form->format_amount($myconfig, $form->round_amount($ref->{fee} + $ref->{total_interest} + $total_open_amount, 2), 2);
1047 $::form->format_dates($output_dateformat, $output_longdates,
1048 qw(dn_dunning_date dn_dunning_duedate dn_transdate dn_duedate
1049 dunning_date dunning_duedate transdate duedate)
1051 $::form->reformat_numbers($output_numberformat, 2, qw(
1052 dn_amount dn_netamount dn_paid dn_open_amount dn_fee dn_interest dn_linetotal
1053 amount netamount paid open_amount fee interest linetotal
1054 total_interest total_open_interest total_amount total_open_amount
1056 $::form->reformat_numbers($output_numberformat, undef, qw(interest_rate));
1058 $self->set_customer_cvars($myconfig, $form);
1059 $self->set_template_options($myconfig, $form);
1061 my $filename = "dunning_${dunning_id}_" . Common::unique_id() . ".pdf";
1062 my $spool = $::lx_office_conf{paths}->{spool};
1063 $form->{OUT} = "${spool}/$filename";
1064 $form->{keep_tmpfile} = 1;
1066 delete $form->{tmpfile};
1068 my $employee_id = ($::instance_conf->get_dunning_creator eq 'invoice_employee') ?
1069 $form->{employee_id} :
1070 SL::DB::Manager::Employee->current->id;
1072 $form->get_employee_data('prefix' => 'employee', 'id' => $employee_id);
1073 $form->get_employee_data('prefix' => 'salesman', 'id' => $form->{salesman_id});
1075 $form->{attachment_type} = "dunning";
1076 if ( $form->{dunning_level} ) {
1077 $form->{attachment_type} .= $form->{dunning_level} if $form->{dunning_level} < 4;
1079 $form->{attachment_filename} = $form->get_formname_translation($form->{attachment_type}) . "_${dunning_id}.pdf";
1080 $form->{attachment_id} = $form->{invoice_id};
1082 # this generates the file in the spool directory
1083 $form->parse_template($myconfig);
1085 push @{ $form->{DUNNING_PDFS} } , $filename;
1086 push @{ $form->{DUNNING_PDFS_EMAIL} } , { 'path' => "${spool}/$filename",
1087 'name' => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" };
1088 push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1089 'path' => "${spool}/$filename",
1090 'name' => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" };
1092 $main::lxdebug->leave_sub();
1095 sub print_invoice_for_fees {
1096 $main::lxdebug->enter_sub();
1098 my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
1100 my $dbh = $provided_dbh || SL::DB->client->dbh;
1102 my ($query, @values, $sth);
1106 d.fee_interest_ar_id,
1107 d.trans_id AS invoice_id,
1111 LEFT JOIN dunning_config dcfg ON (d.dunning_config_id = dcfg.id)
1112 WHERE d.dunning_id = ?|;
1113 my ($ar_id, $invoice_id, $template, $dunning_level) = selectrow_query($form, $dbh, $query, $dunning_id);
1116 $main::lxdebug->leave_sub();
1120 my $saved_form = save_form();
1122 $query = qq|SELECT SUM(fee), SUM(interest) FROM dunning WHERE id = ?|;
1123 my ($fee_total, $interest_total) = selectrow_query($form, $dbh, $query, $dunning_id);
1127 ar.invnumber, ar.transdate AS invdate, ar.amount, ar.netamount,
1128 ar.duedate, ar.notes, ar.notes AS invoicenotes, ar.customer_id,
1130 c.name, c.department_1, c.department_2, c.street, c.zipcode, c.city, c.country,
1131 c.contact, c.customernumber, c.phone, c.fax, c.email,
1132 c.taxnumber, c.greeting
1135 LEFT JOIN customer c ON (ar.customer_id = c.id)
1137 my $ref = selectfirst_hashref_query($form, $dbh, $query, $ar_id);
1138 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
1140 $query = qq|SELECT * FROM employee WHERE login = ?|;
1141 $ref = selectfirst_hashref_query($form, $dbh, $query, $::myconfig{login});
1142 map { $form->{"employee_${_}"} = $ref->{$_} } keys %{ $ref };
1144 $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY acc_trans_id ASC|;
1145 $sth = prepare_execute_query($form, $dbh, $query, $ar_id);
1147 my ($row, $fee, $interest) = (0, 0, 0);
1149 while ($ref = $sth->fetchrow_hashref()) {
1150 next if ($ref->{amount} < 0);
1155 $fee = $ref->{amount};
1157 $interest = $ref->{amount};
1161 $form->{fee} = $form->round_amount($fee, 2);
1162 $form->{interest} = $form->round_amount($interest, 2);
1163 $form->{invamount} = $form->round_amount($fee + $interest, 2);
1164 $form->{dunning_id} = $dunning_id;
1165 $form->{formname} = "${template}_invoice";
1167 map { $form->{$_} = $form->format_amount($myconfig, $form->{$_}, 2) } qw(fee interest invamount);
1169 $self->set_customer_cvars($myconfig, $form);
1170 $self->set_template_options($myconfig, $form);
1172 my $filename = Common::unique_id() . "dunning_invoice_" . $form->{invnumber} . ".pdf";
1174 my $spool = $::lx_office_conf{paths}->{spool};
1175 $form->{OUT} = "$spool/$filename";
1176 $form->{keep_tmpfile} = 1;
1177 delete $form->{tmpfile};
1179 map { delete $form->{$_} } grep /^[a-z_]+_\d+$/, keys %{ $form };
1181 my $attachment_filename = $form->get_formname_translation('dunning_invoice') . "_" . $form->{invnumber} . ".pdf";
1182 $form->{attachment_filename} = $attachment_filename;
1183 $form->{attachment_type} = "dunning";
1184 $form->{attachment_id} = $invoice_id;
1185 $form->parse_template($myconfig);
1187 restore_form($saved_form);
1189 push @{ $form->{DUNNING_PDFS} }, $filename;
1190 push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$filename",
1191 'name' => $attachment_filename };
1192 push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1193 'path' => "${spool}/$filename",
1194 'name' => $attachment_filename };
1196 $main::lxdebug->leave_sub();
1199 sub set_customer_cvars {
1200 my ($self, $myconfig, $form) = @_;
1202 my $custom_variables = CVar->get_custom_variables(dbh => $form->get_standard_dbh,
1204 trans_id => $form->{customer_id});
1205 map { $form->{"vc_cvar_$_->{name}"} = $_->{value} } @{ $custom_variables };
1207 $form->{cp_greeting} = GenericTranslations->get(dbh => $form->get_standard_dbh,
1208 translation_type => 'greetings::' . ($form->{cp_gender} eq 'f' ? 'female' : 'male'),
1209 language_id => $form->{language_id},
1210 allow_fallback => 1);
1211 if ($form->{cp_id}) {
1212 $custom_variables = CVar->get_custom_variables(dbh => $form->get_standard_dbh,
1213 module => 'Contacts',
1214 trans_id => $form->{cp_id});
1215 $form->{"cp_cvar_$_->{name}"} = $_->{value} for @{ $custom_variables };
1220 sub print_original_invoice {
1221 my ($self, $myconfig, $form, $dunning_id, $invoice_id) = @_;
1222 # get one invoice as object and print to pdf
1223 my $invoice = SL::DB::Invoice->new(id => $invoice_id)->load;
1225 die "Invalid invoice object" unless ref($invoice) eq 'SL::DB::Invoice';
1227 my $filestore_enabled = SL::DB::Default->get->webdav
1228 || SL::DB::Default->get->doc_storage;
1229 if ($::instance_conf->get_dunning_original_invoice_creation_mode eq 'use_last_created_or_create_new'
1230 && $filestore_enabled) {
1231 my ($file_name, $file_path);
1232 # search file in files and webdav
1233 if (SL::DB::Default->get->doc_storage) {
1234 my $file_entry = SL::DB::Manager::File->get_first(
1236 object_type => $invoice->type,
1237 object_id => $invoice->id,
1241 my $file = SL::File::Object->new(
1242 db_file => $file_entry,
1243 id => $file_entry->id,
1246 $file_name = $file->file_name();
1247 $file_path = $file->get_file();
1249 } elsif (SL::DB::Default->get->webdav) {
1250 my $webdav = SL::Webdav->new(
1251 type => $invoice->type,
1252 number => $invoice->record_number,
1254 my @latest_object = $webdav->get_all_latest();
1255 if (scalar @latest_object) {
1256 $file_name = $latest_object[0]->basename . "." . $latest_object[0]->extension;
1257 $file_path = $latest_object[0]->full_filedescriptor();
1261 my $attachment_filename = $form->get_formname_translation('invoice') . "_" . $invoice->invnumber . ".pdf";
1262 if ($file_name ne '' and $file_path ne '') {
1263 my $spool = $::lx_office_conf{paths}->{spool};
1264 my $spool_path = File::Spec->catfile($spool, $file_name);
1266 copy($file_path, $spool_path) or die "The copy operation failed: $!";
1268 push @{ $form->{DUNNING_PDFS} } , $file_name;
1269 push @{ $form->{DUNNING_PDFS_EMAIL} } , {
1270 'path' => $file_path,
1271 'name' => $file_name, };
1272 push @{ $form->{DUNNING_PDFS_STORAGE} }, {
1273 'dunning_id' => $dunning_id,
1274 'path' => $file_path,
1275 'name' => $file_name };
1280 my $print_form = Form->new('');
1281 $print_form->{type} = 'invoice';
1282 $print_form->{formname} = 'invoice',
1283 $print_form->{format} = 'pdf',
1284 $print_form->{media} = 'file';
1285 # no language override, should always be the object's language
1286 $invoice->flatten_to_form($print_form, format_amounts => 1);
1287 for my $i (1 .. $print_form->{rowcount}) {
1288 $print_form->{"sellprice_$i"} = $print_form->{"fxsellprice_$i"};
1290 $print_form->prepare_for_printing;
1292 my $filename = SL::Helper::CreatePDF->create_pdf(
1293 template => 'invoice.tex',
1294 variables => $print_form,
1295 return => 'file_name',
1296 variable_content_types => {
1297 longdescription => 'html',
1298 partnotes => 'html',
1300 $print_form->get_variable_content_types_for_cvars,
1304 my $spool = $::lx_office_conf{paths}->{spool};
1305 my ($volume, $directory, $file_name) = File::Spec->splitpath($filename);
1306 my $full_file_name = File::Spec->catfile($spool, $file_name);
1308 move($filename, $full_file_name) or die "The move operation failed: $!";
1310 # form get_formname_translation should use language_id_$i
1311 my $saved_reicpient_locale = $form->{recipient_locale};
1312 $form->{recipient_locale} = $invoice->language;
1314 my $attachment_filename = $form->get_formname_translation('invoice') . "_" . $invoice->invnumber . ".pdf";
1316 push @{ $form->{DUNNING_PDFS} }, $file_name;
1317 push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$file_name",
1318 'name' => $attachment_filename };
1319 push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1320 'path' => "${spool}/$file_name",
1321 'name' => $attachment_filename };
1323 $form->{recipient_locale} = $saved_reicpient_locale;
1326 sub _store_pdf_to_webdav_and_filemanagement {
1327 my ($dunning_id, $path, $name) =@_;
1331 if ($::instance_conf->get_doc_storage) {
1334 object_id => $dunning_id,
1335 object_type => 'dunning',
1336 mime_type => 'application/pdf',
1337 source => 'created',
1338 file_type => 'document',
1344 push @errors, $::locale->text('Storing PDF in storage backend failed: #1', $@);
1348 if ($::instance_conf->get_webdav_documents) {
1350 my $webdav = SL::Webdav->new(
1352 number => $dunning_id,
1354 my $webdav_file = SL::Webdav::File->new(
1358 $webdav_file->store(file => $path);
1360 push @errors, $::locale->text('Storing PDF to webdav folder failed: #1', $@);