Übergabe des Templates an den ReportGenerator nicht über $form, sondern über ReportGe...
[kivitendo-erp.git] / SL / DN.pm
index 587379b..2b6cd63 100644 (file)
--- a/SL/DN.pm
+++ b/SL/DN.pm
@@ -109,7 +109,7 @@ sub save_config {
                (dunning_level, dunning_description, email_subject, email_body,
                 template, fee, interest_rate, active, auto, email,
                 email_attachment, payment_terms, terms, create_invoices_for_fees)
-             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
+             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
       }
       do_query($form, $dbh, $query, @values);
     }
@@ -198,6 +198,7 @@ sub create_invoice_for_fees {
   }
 
   my ($ar_id) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
+  my $curr = $form->get_default_currency($myconfig);
 
   $query =
     qq|INSERT INTO ar (id,          invnumber, transdate, gldate, customer_id,
@@ -220,7 +221,7 @@ sub create_invoice_for_fees {
          ?,                     -- netamount
          0,                     -- paid
          -- duedate:
-         (SELECT duedate FROM dunning WHERE dunning_id = ?),
+         (SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1),
          'f',                   -- invoice
          ?,                     -- curr
          ?,                     -- notes
@@ -233,7 +234,7 @@ sub create_invoice_for_fees {
              $amount,
              $amount,
              $dunning_id,       # duedate
-             (split m/:/, $myconfig->{currency})[0], # currency
+             $curr,             # default currency
              sprintf($main::locale->text('Automatically created invoice for fee and interest for dunning %s'), $dunning_id), # notes
              $form->{login});   # employee_id
   do_query($form, $dbh, $query, @values);
@@ -265,7 +266,7 @@ sub create_invoice_for_fees {
 sub save_dunning {
   $main::lxdebug->enter_sub();
 
-  my ($self, $myconfig, $form, $rows, $userspath, $spool, $sendmail) = @_;
+  my ($self, $myconfig, $form, $rows, $userspath, $spool) = @_;
   # connect to database
   my $dbh = $form->dbconnect_noauto($myconfig);
 
@@ -685,7 +686,7 @@ sub print_dunning {
          dcfg.email_subject, dcfg.email_body, dcfg.email_attachment,
 
          ar.transdate,       ar.duedate,      ar.customer_id,
-         ar.invnumber,       ar.ordnumber,
+         ar.invnumber,       ar.ordnumber,    ar.cp_id,
          ar.amount,          ar.netamount,    ar.paid,
          ar.amount - ar.paid AS open_amount,
          ar.amount - ar.paid + da.fee + da.interest AS linetotal
@@ -711,10 +712,13 @@ sub print_dunning {
   $query =
     qq|SELECT
          c.id AS customer_id, c.name,         c.street,       c.zipcode, c.city,
-         c.country,           c.department_1, c.department_2, c.email, c.customernumber
+         c.country,           c.department_1, c.department_2, c.email, c.customernumber,
+         -- contact information
+         co.*
        FROM dunning d
-       LEFT JOIN ar         ON (d.trans_id = ar.id)
-       LEFT JOIN customer c ON (ar.customer_id = c.id)
+       LEFT JOIN ar          ON (d.trans_id = ar.id)
+       LEFT JOIN customer c  ON (ar.customer_id = c.id)
+       LEFT JOIN contacts co ON (ar.cp_id = co.cp_id)
        WHERE (d.dunning_id = ?)
        LIMIT 1|;
   $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
@@ -802,7 +806,7 @@ sub print_invoice_for_fees {
 
   $query =
     qq|SELECT
-         ar.invnumber, ar.transdate, ar.amount, ar.netamount,
+         ar.invnumber, ar.transdate AS invdate, ar.amount, ar.netamount,
          ar.duedate,   ar.notes,     ar.notes AS invoicenotes,
 
          c.name,      c.department_1,   c.department_2, c.street, c.zipcode, c.city, c.country,