commit 94944f0868721e5140fc97f78948c298a122dcbe
Author: Bernd Bleßmann <bernd@kivitendo-premium.de>
Date:   Tue Feb 7 22:55:21 2012 +0100

    Sprache bei Mahnungen
    
    In den Auflistungen wird zu den Rechnungen die jeweilige Rechnungssprache
    mit angezeigt. Diese Sprache wird beim Drucken der Mahnungen auch verwendet
    (Bei Rechnung zusammenfassen nur die erste Sprache).
    Mit der SelectionBox unten kann man die Sprachauswahl überschreiben
    (, sofern man nicht den Link zur Mahnung in der Auflistung verwendet).

diff --git a/SL/DN.pm b/SL/DN.pm
index a1db029ca..6d00f438a 100644
--- a/SL/DN.pm
+++ b/SL/DN.pm
@@ -509,7 +509,7 @@ sub get_invoices {
 
   $query =
     qq|SELECT
-         a.id, a.ordnumber, a.transdate, a.invnumber, a.amount,
+         a.id, a.ordnumber, a.transdate, a.invnumber, a.amount, a.language_id,
          ct.name AS customername, a.customer_id, a.duedate,
          a.amount - a.paid AS open_amount,
 
@@ -669,7 +669,7 @@ sub get_dunning {
   my $sortorder = join ', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} };
 
   my $query =
-    qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount,
+    qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount, a.language_id,
          ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
          da.interest, dn.dunning_description, da.transdate AS dunning_date,
          da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id,
diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl
index 6c3492b98..4b6210ba4 100644
--- a/bin/mozilla/dn.pl
+++ b/bin/mozilla/dn.pl
@@ -133,6 +133,10 @@ sub show_invoices {
       map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } };
     }
     map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount open_amount fee interest);
+
+    if ($row->{'language_id'}) {
+      $row->{language} = SL::DB::Manager::Language->find_by('id' => $row->{'language_id'})->{'description'};
+    }
   }
 
   $form->get_lists('printers'  => 'printers',
@@ -150,6 +154,8 @@ sub show_invoices {
                                           'no_opendocument' => 1,);
 
   $form->header();
+  $form->{onload} = "document.getElementsByName('language_id')[0].disabled =
+        !document.getElementsByName('force_lang')[0].checked;";
   print $form->parse_html_template("dunning/show_invoices");
 
   $main::lxdebug->leave_sub();
@@ -199,6 +205,8 @@ sub save_dunning {
   my @rows = ();
   undef($form->{DUNNING_PDFS});
 
+  my $saved_language_id = $form->{language_id};
+
   if ($form->{groupinvoices}) {
     my %dunnings_for;
 
@@ -214,6 +222,7 @@ sub save_dunning {
       push @{ $level }, { "row"                    => $i,
                           "invoice_id"             => $form->{"inv_id_$i"},
                           "customer_id"            => $form->{"customer_id_$i"},
+                          "language_id"            => $form->{"language_id_$i"},
                           "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
                           "email"                  => $form->{"email_$i"}, };
     }
@@ -221,7 +230,9 @@ sub save_dunning {
     foreach my $levels (values %dunnings_for) {
       foreach my $level (values %{ $levels }) {
         next unless scalar @{ $level };
-
+        if (!$form->{force_lang}) {
+          $form->{language_id} = @{$level}[0]->{language_id};
+        }
         DN->save_dunning(\%myconfig, $form, $level);
       }
     }
@@ -233,12 +244,18 @@ sub save_dunning {
       my $level = [ { "row"                    => $i,
                       "invoice_id"             => $form->{"inv_id_$i"},
                       "customer_id"            => $form->{"customer_id_$i"},
+                      "language_id"            => $form->{"language_id_$i"},
                       "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
                       "email"                  => $form->{"email_$i"}, } ];
+      if (!$form->{force_lang}) {
+        $form->{language_id} = @{$level}[0]->{language_id};
+      }
       DN->save_dunning(\%myconfig, $form, $level);
     }
   }
 
+  $form->{language_id} = $saved_language_id;
+
   if($form->{DUNNING_PDFS}) {
     DN->melt_pdfs(\%myconfig, $form, $form->{copies});
   }
@@ -352,6 +369,7 @@ sub show_dunning {
     'checkbox'            => { 'text' => '', 'visible' => 'HTML' },
     'dunning_description' => { 'text' => $locale->text('Dunning Level') },
     'customername'        => { 'text' => $locale->text('Customername') },
+    'language'            => { 'text' => $locale->text('Language') },
     'invnumber'           => { 'text' => $locale->text('Invnumber') },
     'transdate'           => { 'text' => $locale->text('Invdate') },
     'duedate'             => { 'text' => $locale->text('Invoice Duedate') },
@@ -364,12 +382,12 @@ sub show_dunning {
   );
 
   $report->set_columns(%column_defs);
-  $report->set_column_order(qw(checkbox dunning_description customername invnumber transdate
+  $report->set_column_order(qw(checkbox dunning_description customername language invnumber transdate
                                duedate amount dunning_date dunning_duedate fee interest salesman));
   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
   my $edit_url  = sub { build_std_url('script=' . ($_[0]->{invoice} ? 'is' : 'ar') . '.pl', 'action=edit', 'callback') . '&id=' . $::form->escape($_[0]->{id}) };
-  my $print_url = build_std_url('action=print_dunning', 'format=pdf', 'media=screen') . '&dunning_id=';
+  my $print_url = sub { build_std_url('action=print_dunning', 'format=pdf', 'media=screen', 'dunning_id='.$_[0]->{dunning_id}, 'language_id=' . $_[0]->{language_id}) };
   my $sort_url  = build_std_url('action=show_dunning', grep { $form->{$_} } @filter_field_list);
 
   foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate salesman)) {
@@ -396,6 +414,10 @@ sub show_dunning {
       $first_row_for_dunning = 1;
     }
 
+    if ($ref->{'language_id'}) {
+      $ref->{language} = SL::DB::Manager::Language->find_by('id' => $ref->{'language_id'})->{'description'};
+    }
+
     my $row = { };
     foreach my $column (keys %{ $ref }) {
       $row->{$column} = {
@@ -404,7 +426,7 @@ sub show_dunning {
         'align' => $alignment{$column},
 
         'link'  => (  $column eq 'invnumber'           ? $edit_url->($ref)
-                    : $column eq 'dunning_description' ? $print_url . E($ref->{dunning_id})
+                    : $column eq 'dunning_description' ? $print_url->($ref)
                     :                                    ''),
       };
     }
@@ -416,6 +438,13 @@ sub show_dunning {
       'align'    => 'center',
     };
 
+    if ($first_row_for_dunning) {
+      $row->{language} = {'raw_data' => $cgi->hidden('-name' => "language_id_$i", '-value' => $ref->{language_id})
+                                        . " $ref->{language}" };
+    } else {
+      $row->{language} = { };
+    }
+
     push @{ $current_dunning_rows }, $row;
 
     $previous_dunning_id   = $ref->{dunning_id};
@@ -432,6 +461,8 @@ sub show_dunning {
 
   $report->set_options_from_form();
 
+  $form->{onload} = "document.getElementsByName('language_id')[0].disabled =
+        !document.getElementsByName('force_lang')[0].checked;";
   $report->generate_with_headers();
 
   $main::lxdebug->leave_sub();
@@ -448,6 +479,7 @@ sub print_dunning {
   $form->{rowcount}     = 1;
   $form->{selected_1}   = 1;
   $form->{dunning_id_1} = $form->{dunning_id};
+  $form->{language_id_1} = $form->{language_id};
 
   print_multiple();
 
@@ -466,6 +498,7 @@ sub print_multiple {
   $form->{title} = $locale->text('Print dunnings');
 
   my @dunning_ids = map { $form->{"dunning_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount});
+  my @language_ids = map { $form->{"language_id_$_"} } grep { $form->{"selected_$_"} } (1..$form->{rowcount});
 
   if (!scalar @dunning_ids) {
     $form->error($locale->text('No dunnings have been selected for printing.'));
@@ -473,10 +506,17 @@ sub print_multiple {
 
   $form->{DUNNING_PDFS} = [];
 
+  my $saved_language_id = $form->{language_id};
+  my $i = 0;
   foreach my $dunning_id (@dunning_ids) {
+    if (!$form->{force_lang}) {
+      $form->{language_id} = $language_ids[$i];
+    }
     DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id);
     DN->print_dunning(\%myconfig, $form, $dunning_id);
+    $i++;
   }
+  $form->{language_id} = $saved_language_id;
 
   if (scalar @{ $form->{DUNNING_PDFS} }) {
     $form->{dunning_id} = strftime("%Y%m%d", localtime time);
diff --git a/locale/de/all b/locale/de/all
index d9af546fe..4228c5821 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -1280,6 +1280,7 @@ $self->{texts} = {
   'Output Number Format'        => 'Zahlenformat (Ausgabe)',
   'Outputformat'                => 'Ausgabeformat',
   'Overdue sales quotations and requests for quotations' => 'Überfällige Angebote und Preisanfragen',
+  'Override invoice language'   => 'Diese Sprache verwenden',
   'PAYMENT POSTED'              => 'Rechung gebucht',
   'PDF'                         => 'PDF',
   'PDF (OpenDocument/OASIS)'    => 'PDF (OpenDocument/OASIS)',
diff --git a/locale/en/all b/locale/en/all
index 4fc79c12a..91b5d5d91 100644
--- a/locale/en/all
+++ b/locale/en/all
@@ -1180,6 +1180,7 @@ $self->{texts} = {
   'Output Number Format'        => '',
   'Outputformat'                => '',
   'Overdue sales quotations and requests for quotations' => '',
+  'Override invoice language'   => '',
   'Own Product'                 => '',
   'PAYMENT POSTED'              => '',
   'PDF'                         => '',
diff --git a/templates/webpages/dunning/show_dunning_bottom.html b/templates/webpages/dunning/show_dunning_bottom.html
index 0f452a46d..f3eca3194 100644
--- a/templates/webpages/dunning/show_dunning_bottom.html
+++ b/templates/webpages/dunning/show_dunning_bottom.html
@@ -1,7 +1,11 @@
 [%- USE T8 %]
 [% USE HTML %]  <input type="hidden" name="rowcount" value="[% rowcount %]">
 
-  <p>[% PRINT_OPTIONS %]</p>
+  <p>
+    <input type="checkbox" name="force_lang" size="6" value="1" onclick="document.getElementsByName('language_id')[0].disabled = !document.getElementsByName('force_lang')[0].checked;">
+    [% 'Override invoice language' | T8 %]
+    [% PRINT_OPTIONS %]
+  </p>
 
   <p>
    [% 'Dunnings' | $T8 %]<br>
diff --git a/templates/webpages/dunning/show_invoices.html b/templates/webpages/dunning/show_invoices.html
index cd8c43422..2f99cc6db 100644
--- a/templates/webpages/dunning/show_invoices.html
+++ b/templates/webpages/dunning/show_invoices.html
@@ -4,7 +4,8 @@
 [% L.javascript_tag('jquery.checkall') %]
 [% SET all_active = 1 %][% FOREACH row = DUNNINGS %][% IF !row.active %][% SET all_active = 0 %][% LAST %][% END %][% END %]
 [% SET all_email = 1 %][% FOREACH row = DUNNINGS %][% IF !row.email %][% SET all_email = 0 %][% LAST %][% END %][% END %]
-<body>
+<body [% IF onload %] onload="[% onload %]"[% END %]>
+
  <script type="text/javascript" src="js/common.js"></script>
  <script type="text/javascript" src="js/dunning.js"></script>
 
@@ -28,6 +29,7 @@
    </th>
 
    <th class="listheading">[% 'Customername' | $T8 %]</th>
+   <th class="listheading">[% 'Language' | $T8 %]</th>
    <th class="listheading">[% 'Invno.' | $T8 %]</th>
    <th class="listheading">[% 'Invdate' | $T8 %]</th>
    <th class="listheading">[% 'Inv. Duedate' | $T8 %]</th>
@@ -57,6 +59,7 @@
      <td><input type="checkbox" name="active_[% loop.count %]" value="1" [% IF row.active %]checked[% END %]></td>
      <td><input type="checkbox" name="email_[% loop.count %]" value="1" [% IF row.email %]checked[% END %]></td>
      <td><input type="hidden" name="customername_[% loop.count %]" size="6" value="[% HTML.escape(row.customername) %]">[% HTML.escape(row.customername) %]</td>
+     <td><input type="hidden" name="language_id_[% loop.count %]" size="6" value="[% HTML.escape(row.language_id) %]">[% HTML.escape(row.language) %]</td>
      <td>
       <input type="hidden" name="invnumber_[% loop.count %]" size="6" value="[% HTML.escape(row.invnumber) %]">
       <a href="is.pl?action=edit&type=invoice&id=[% row.id | url %]">[% HTML.escape(row.invnumber) %]</a>
@@ -74,6 +77,8 @@
 
   <hr size=3 noshade>
 
+  <input type="checkbox" name="force_lang" size="6" value="1" onclick="document.getElementsByName('language_id')[0].disabled = !document.getElementsByName('force_lang')[0].checked;">
+  [% 'Override invoice language' | T8 %]
   [% PRINT_OPTIONS %]
 
   <br>
diff --git a/templates/webpages/report_generator/html_report.html b/templates/webpages/report_generator/html_report.html
index 8b2d25330..8c6250e39 100644
--- a/templates/webpages/report_generator/html_report.html
+++ b/templates/webpages/report_generator/html_report.html
@@ -1,5 +1,5 @@
 [%- USE T8 %]
-[% USE HTML %]<body>
+[% USE HTML %]<body[% IF onload %] onload="[% onload %]"[% END %]>
 
  <style type="text/css">
   <!--
