Mehr Frieden -General Kyrylo Budanov:
[kivitendo-erp.git] / SL / DN.pm
index ea47209..76ee1b8 100644 (file)
--- a/SL/DN.pm
+++ b/SL/DN.pm
@@ -487,13 +487,17 @@ sub send_email {
     } or die $main::locale->text('No email for user with login #1 defined.', $ref->{invoice_employee_login});
   }
 
+  my $html_template = SL::Template::create(type => 'HTML',      form => $form, myconfig => $myconfig);
+  $html_template->set_tag_style('<%', '%>');
+
   my $template     = SL::Template::create(type => 'PlainText', form => $form, myconfig => $myconfig);
   my $mail         = Mailer->new();
   $mail->{bcc}     = $form->get_bcc_defaults($myconfig, $form->{bcc});
   $mail->{from}    = $from;
   $mail->{to}      = $ref->{recipient};
   $mail->{subject} = $template->parse_block($ref->{email_subject});
-  $mail->{message} = $template->parse_block($ref->{email_body});
+  $mail->{message} = $html_template->parse_block($ref->{email_body});
+  $mail->{content_type} = 'text/html';
   my $sign_backup  = $::myconfig{signature};
   $::myconfig{signature} = $sign if $sign;
   $mail->{message} .= $form->create_email_signature();
@@ -505,6 +509,11 @@ sub send_email {
     $mail->{attachments} = $form->{DUNNING_PDFS_EMAIL};
   }
 
+  $query  = qq|SELECT id FROM dunning WHERE dunning_id = ?|;
+  my @ids = selectall_array_query($form, $dbh, $query, $dunning_id);
+  $mail->{record_id}   = \@ids;
+  $mail->{record_type} = 'dunning';
+
   $mail->send();
 
   $main::lxdebug->leave_sub();
@@ -648,8 +657,9 @@ sub get_invoices {
          ct.name AS customername, a.customer_id, a.duedate,
          a.amount - a.paid AS open_amount,
          a.direct_debit,
+         pt.description as payment_term,
          dep.description as departmentname,
-
+         ct.invoice_mail AS cv_email,
          cfg.dunning_description, cfg.dunning_level,
 
          d.transdate AS dunning_date, d.duedate AS dunning_duedate,
@@ -667,6 +677,7 @@ sub get_invoices {
 
        LEFT JOIN customer ct ON (a.customer_id = ct.id)
        LEFT JOIN department dep ON (a.department_id = dep.id)
+       LEFT JOIN payment_terms pt ON (a.payment_id = pt.id)
        LEFT JOIN dunning_config cfg ON (a.dunning_config_id = cfg.id)
        LEFT JOIN dunning_config nextcfg ON
          (nextcfg.id =
@@ -815,6 +826,7 @@ sub get_dunning {
          ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
          da.interest, dn.dunning_description, dn.dunning_level, da.transdate AS dunning_date,
          da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id,
+         da.id AS dunning_table_id,
          e2.name AS salesman
        FROM ar a
        JOIN customer ct ON (a.customer_id = ct.id)
@@ -957,7 +969,7 @@ sub print_dunning {
          c.country,           c.department_1, c.department_2, c.email,     c.customernumber,
          c.greeting,          c.contact,      c.phone,        c.fax,       c.homepage,
          c.email,             c.taxincluded,  c.business_id,  c.taxnumber, c.iban,
-         c.ustid,
+         c.ustid,             c.currency_id,  curr.name as currency,
          ar.id AS invoice_id,
          co.*
        FROM dunning d
@@ -965,6 +977,7 @@ sub print_dunning {
        LEFT JOIN customer c  ON (ar.customer_id = c.id)
        LEFT JOIN contacts co ON (ar.cp_id = co.cp_id)
        LEFT JOIN employee e  ON (ar.salesman_id = e.id)
+       LEFT JOIN currencies curr ON (c.currency_id = curr.id)
        WHERE (d.dunning_id = ?)
        LIMIT 1|;
   my $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
@@ -1136,7 +1149,7 @@ sub print_invoice_for_fees {
   $self->set_customer_cvars($myconfig, $form);
   $self->set_template_options($myconfig, $form);
 
-  my $filename = Common::unique_id() . "dunning_invoice_${dunning_id}.pdf";
+  my $filename = Common::unique_id() . "dunning_invoice_" . $form->{invnumber} . ".pdf";
 
   my $spool             = $::lx_office_conf{paths}->{spool};
   $form->{OUT}          = "$spool/$filename";
@@ -1145,7 +1158,7 @@ sub print_invoice_for_fees {
 
   map { delete $form->{$_} } grep /^[a-z_]+_\d+$/, keys %{ $form };
 
-  my $attachment_filename      = $form->get_formname_translation('dunning_invoice') . "_${dunning_id}.pdf";
+  my $attachment_filename      = $form->get_formname_translation('dunning_invoice') . "_" . $form->{invnumber} . ".pdf";
   $form->{attachment_filename} = $attachment_filename;
   $form->{attachment_type}     = "dunning";
   $form->{attachment_id}       = $invoice_id;
@@ -1211,6 +1224,7 @@ sub print_original_invoice {
                      longdescription => 'html',
                      partnotes       => 'html',
                      notes           => 'html',
+                     $print_form->get_variable_content_types_for_cvars,
                    },
   );