Merge von 825,826 aus unstable: Bugfix 165
[kivitendo-erp.git] / SL / GL.pm
index a080b85..3b0e74e 100644 (file)
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -38,6 +38,8 @@
 
 package GL;
 
+use Data::Dumper;
+
 sub delete_transaction {
   my ($self, $myconfig, $form) = @_;
   $main::lxdebug->enter_sub();
@@ -342,6 +344,19 @@ sub all_transactions {
 
   my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE: q|'0'|;
 
+     my $sortorder = join ', ', $form->sort_columns(qw(transdate reference source description accno));
+     my %ordinal = ( transdate => 6,
+                     reference => 4,
+                     source => 7,
+                 description => 5 );
+     map { $sortorder =~ s/$_/$ordinal{$_}/ } keys %ordinal;
+   
+     if ($form->{sort}) {
+         $sortorder = $form->{sort} . ",";
+     } else {
+        $sortorder = "";
+      }
+  
   my $query =
     qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax,
                  g.description, ac.transdate, ac.source, ac.trans_id,
@@ -371,7 +386,7 @@ sub all_transactions {
                 AND ac.chart_id = c.id
                 AND a.vendor_id = ct.id
                 AND a.id = ac.trans_id
-                ORDER BY transdate, trans_id, taxkey DESC, sorttax DESC, oid|;
+                ORDER BY $sortorder transdate, trans_id, taxkey DESC, sorttax DESC,oid|;
   my $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
   my $trans_id = "";
@@ -505,6 +520,7 @@ sub all_transactions {
     ($form->{gifi_account_description}) = $sth->fetchrow_array;
     $sth->finish;
   }
+  print(STDERR Dumper($form->{GL}));
   $main::lxdebug->leave_sub();
 
   $dbh->disconnect;