Whitespace Purge
[kivitendo-erp.git] / SL / AP.pm
index 7629381..5143245 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -96,10 +96,7 @@ sub post_transaction {
       qq|ORDER BY c.accno|;
     $sth = $dbh->prepare($query);
     $sth->execute($form->{"tax_id_$i"}) || $form->dberror($query . " (" . $form->{"tax_id_$i"} . ")");
-    ($form->{AP_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) =
-      $sth->fetchrow_array;
-    $form->{AP_amounts}{"tax_$i"}{taxkey}    = $form->{"taxkey_$i"};
-    $form->{AP_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"};
+    ($form->{AP_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = $sth->fetchrow_array();
 
     $sth->finish;
     if ($form->{taxincluded} *= 1) {
@@ -212,7 +209,6 @@ sub post_transaction {
       if ($form->{"amount_$i"} != 0) {
         my $project_id;
         $project_id = conv_i($form->{"project_id_$i"});
-        $taxkey = $form->{AP_amounts}{"amount_$i"}{taxkey};
 
         # insert detail records in acc_trans
         $query =
@@ -222,7 +218,7 @@ sub post_transaction {
           qq|  ?, ?, ?, ?)|;
         @values = ($form->{id}, $form->{AP_amounts}{"amount_$i"},
                    $form->{"amount_$i"}, conv_date($form->{transdate}),
-                   $project_id, $taxkey);
+                   $project_id, $form->{"taxkey_$i"});
         do_query($form, $dbh, $query, @values);
 
         if ($form->{"tax_$i"} != 0) {
@@ -234,7 +230,7 @@ sub post_transaction {
             qq|  ?, ?, ?, ?)|;
           @values = ($form->{id}, $form->{AP_amounts}{"tax_$i"},
                      $form->{"tax_$i"}, conv_date($form->{transdate}),
-                     $project_id, $taxkey);
+                     $project_id, $form->{"taxkey_$i"});
           do_query($form, $dbh, $query, @values);
         }
 
@@ -399,7 +395,7 @@ sub ap_transactions {
   my $query =
     qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, a.amount, a.paid, | .
     qq|  a.ordnumber, v.name, a.invoice, a.netamount, a.datepaid, a.notes, | .
-    qq|  a.globalproject_id, | .
+    qq|  a.globalproject_id, a.storno, a.storno_id, | .
     qq|  pr.projectnumber AS globalprojectnumber, | .
     qq|  e.name AS employee | .
     qq|FROM ap a | .
@@ -407,7 +403,7 @@ sub ap_transactions {
     qq|LEFT JOIN employee e ON (a.employee_id = e.id) | .
     qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id) |;
 
-  my $where = qq| WHERE COALESCE(storno, false) != true |;
+  my $where = '';
   my @values;
 
   if ($form->{vendor_id}) {
@@ -458,21 +454,20 @@ sub ap_transactions {
   }
 
   if ($where) {
-#     substr($where, 0, 4) = "WHERE";
+    substr($where, 0, 4, " WHERE ");
     $query .= $where;
   }
 
   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};
+  if (grep({ $_ eq $form->{sort} } qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee transaction_description))) {
+    $sortorder = $form->{sort} . " $sortdir";
   }
 
-  $query .= " ORDER by $sortorder";
+  $query .= " ORDER BY $sortorder";
 
   my $sth = $dbh->prepare($query);
   $sth->execute(@values) ||