In Einkaufsbelegen Übersetzungen von Artikeln berücksichtigen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 16 Jun 2011 10:41:57 +0000 (12:41 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 16 Jun 2011 10:41:57 +0000 (12:41 +0200)
Fix für Bug 1677.

SL/IR.pm
SL/IS.pm

index f87cdf8..1f30c6b 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -1129,6 +1129,19 @@ sub retrieve_item {
        WHERE $where|;
   my $sth = prepare_execute_query($form, $dbh, $query, @values);
 
+  my @translation_queries = ( [ qq|SELECT tr.translation, tr.longdescription
+                                   FROM translation tr
+                                   WHERE tr.language_id = ? AND tr.parts_id = ?| ],
+                              [ qq|SELECT tr.translation, tr.longdescription
+                                   FROM translation tr
+                                   WHERE tr.language_id IN
+                                     (SELECT id
+                                      FROM language
+                                      WHERE article_code = (SELECT article_code FROM language WHERE id = ?))
+                                     AND tr.parts_id = ?
+                                   LIMIT 1| ] );
+  map { push @{ $_ }, prepare_query($form, $dbh, $_->[0]) } @translation_queries;
+
   $form->{item_list} = [];
   while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
 
@@ -1178,6 +1191,16 @@ sub retrieve_item {
         $form->{taxaccounts}                 .= "$ptr->{accno} ";
       }
 
+      if ($form->{language_id}) {
+        for my $spec (@translation_queries) {
+          do_statement($form, $spec->[1], $spec->[0], conv_i($form->{language_id}), conv_i($ref->{id}));
+          my ($translation, $longdescription) = $spec->[1]->fetchrow_array;
+          next unless $translation;
+          $ref->{description} = $translation;
+          $ref->{longdescription} = $longdescription;
+          last;
+        }
+      }
     }
 
     $stw->finish();
@@ -1190,6 +1213,7 @@ sub retrieve_item {
   }
 
   $sth->finish();
+  $_->[1]->finish for @translation_queries;
 
   foreach my $item (@{ $form->{item_list} }) {
     my $custom_variables = CVar->get_custom_variables(module   => 'IC',
index 3210b12..e3390fc 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -1848,6 +1848,19 @@ sub retrieve_item {
        WHERE $where|;
   my $sth = prepare_execute_query($form, $dbh, $query, @values);
 
+  my @translation_queries = ( [ qq|SELECT tr.translation, tr.longdescription
+                                   FROM translation tr
+                                   WHERE tr.language_id = ? AND tr.parts_id = ?| ],
+                              [ qq|SELECT tr.translation, tr.longdescription
+                                   FROM translation tr
+                                   WHERE tr.language_id IN
+                                     (SELECT id
+                                      FROM language
+                                      WHERE article_code = (SELECT article_code FROM language WHERE id = ?))
+                                     AND tr.parts_id = ?
+                                   LIMIT 1| ] );
+  map { push @{ $_ }, prepare_query($form, $dbh, $_->[0]) } @translation_queries;
+
   while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
 
     # In der Buchungsgruppe ist immer ein Bestandskonto verknuepft, auch wenn
@@ -1915,33 +1928,15 @@ sub retrieve_item {
 
     $stw->finish;
     chop $ref->{taxaccounts};
+
     if ($form->{language_id}) {
-      $query =
-        qq|SELECT tr.translation, tr.longdescription
-           FROM translation tr
-           WHERE tr.language_id = ? AND tr.parts_id = ?|;
-      @values = (conv_i($form->{language_id}), conv_i($ref->{id}));
-      my ($translation, $longdescription) = selectrow_query($form, $dbh, $query, @values);
-      if ($translation ne "") {
+      for my $spec (@translation_queries) {
+        do_statement($form, $spec->[1], $spec->[0], conv_i($form->{language_id}), conv_i($ref->{id}));
+        my ($translation, $longdescription) = $spec->[1]->fetchrow_array;
+        next unless $translation;
         $ref->{description} = $translation;
         $ref->{longdescription} = $longdescription;
-
-      } else {
-        $query =
-          qq|SELECT tr.translation, tr.longdescription
-             FROM translation tr
-             WHERE tr.language_id IN
-               (SELECT id
-                FROM language
-                WHERE article_code = (SELECT article_code FROM language WHERE id = ?))
-               AND tr.parts_id = ?
-             LIMIT 1|;
-        @values = (conv_i($form->{language_id}), conv_i($ref->{id}));
-        my ($translation, $longdescription) = selectrow_query($form, $dbh, $query, @values);
-        if ($translation ne "") {
-          $ref->{description} = $translation;
-          $ref->{longdescription} = $longdescription;
-        }
+        last;
       }
     }
 
@@ -1964,6 +1959,7 @@ sub retrieve_item {
     }
   }
   $sth->finish;
+  $_->[1]->finish for @translation_queries;
 
   foreach my $item (@{ $form->{item_list} }) {
     my $custom_variables = CVar->get_custom_variables(module   => 'IC',