Einen Test für Postgres-Datenbankcluster hinzugefügt, ob sie anständig mit Umlauten...
[kivitendo-erp.git] / SL / AP.pm
index 2da4eca..24054c8 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -56,14 +56,8 @@ sub post_transaction {
   if ($form->{currency} eq $form->{defaultcurrency}) {
     $form->{exchangerate} = 1;
   } else {
-    $exchangerate =
-      $form->check_exchangerate($myconfig, $form->{currency},
-                                $form->{transdate}, 'sell');
-
-    $form->{exchangerate} =
-      ($exchangerate)
-      ? $exchangerate
-      : $form->parse_amount($myconfig, $form->{exchangerate});
+    $exchangerate         = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'sell');
+    $form->{exchangerate} = $exchangerate || $form->parse_amount($myconfig, $form->{exchangerate});
   }
 
   for $i (1 .. $form->{rowcount}) {
@@ -271,14 +265,8 @@ sub post_transaction {
       if ($form->{currency} eq $form->{defaultcurrency}) {
         $form->{"exchangerate_$i"} = 1;
       } else {
-        $exchangerate =
-          $form->check_exchangerate($myconfig, $form->{currency},
-                                    $form->{"datepaid_$i"}, 'sell');
-
-        $form->{"exchangerate_$i"} =
-          ($exchangerate)
-          ? $exchangerate
-          : $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
+        $exchangerate              = $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
+        $form->{"exchangerate_$i"} = $exchangerate || $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
       }
       $form->{"AP_paid_$i"} =~ s/\"//g;
 
@@ -476,15 +464,16 @@ sub ap_transactions {
 
   my @a = (transdate, invnumber, name);
   push @a, "employee" if $self->{l_employee};
-  my $sortorder = join(', ', @a);
+  my $sortdir   = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
+  my $sortorder = join(', ', map { "$_ $sortdir" } @a);
 
   if (grep({ $_ eq $form->{sort} }
            qw(transdate id invnumber ordnumber name netamount tax amount
               paid datepaid due duedate notes employee))) {
-    $sortorder = $form->{sort};
+    $sortorder = $form->{sort} . " $sortdir";
   }
 
-  $query .= " ORDER by $sortorder";
+  $query .= " ORDER BY $sortorder";
 
   my $sth = $dbh->prepare($query);
   $sth->execute(@values) ||
@@ -765,7 +754,7 @@ sub storno {
   $storno_row->{invnumber}  = 'Storno-' . $storno_row->{invnumber};
   $storno_row->{amount}    *= -1;
   $storno_row->{netamount} *= -1;
-  $storno_row->{paid}       = $storno_amount->{amount};
+  $storno_row->{paid}       = $storno_row->{amount};
 
   delete @$storno_row{qw(itime mtime)};
 
@@ -776,7 +765,7 @@ sub storno {
   do_query($form, $dbh, $query, $id);
 
   # now copy acc_trans entries
-  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ?|;
+  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.oid|;
   my $rowref = selectall_hashref_query($form, $dbh, $query, $id); 
 
   # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/