commit d8f857c7a3a8705e85acb5e7f8bcfe8fe2dabf7f
Author: Sven Schöling <s.schoeling@googlemail.com>
Date:   Tue Aug 25 12:42:17 2009 +0200

    Einkaufsrechnungen Buchungskonto

diff --git a/SL/AP.pm b/SL/AP.pm
index 4187c72cf..6ec28627c 100644
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -390,7 +390,7 @@ sub ap_transactions {
   my ($self, $myconfig, $form) = @_;
 
   # connect to database
-  my $dbh = $form->dbconnect($myconfig);
+  my $dbh = $form->get_standard_dbh($myconfig);
 
   my $query =
     qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, a.amount, a.paid, | .
@@ -400,13 +400,16 @@ sub ap_transactions {
     qq|  e.name AS employee, | .
     qq|  v.vendornumber, v.country, v.ustid, | .
     qq|  tz.description AS taxzone, | .
-    qq|  pt.description AS payment_terms | .
+    qq|  pt.description AS payment_terms, | .
+    qq{  ch.accno || ' -- ' || ch.description AS charts } .
     qq|FROM ap a | .
     qq|JOIN vendor v ON (a.vendor_id = v.id) | .
     qq|LEFT JOIN employee e ON (a.employee_id = e.id) | .
     qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id) | .
     qq|LEFT JOIN tax_zones tz ON (tz.id = v.taxzone_id)| .
-    qq|LEFT JOIN payment_terms pt ON (pt.id = v.payment_id)|;
+    qq|LEFT JOIN payment_terms pt ON (pt.id = v.payment_id)| .
+    qq|LEFT JOIN acc_trans at ON (at.trans_id = a.id)| .
+    qq|INNER JOIN chart ch ON (ch.id = at.chart_id AND ch.link ~ 'AP[[:>:]]')|;
 
   my $where = '';
   my @values;
@@ -474,17 +477,9 @@ sub ap_transactions {
 
   $query .= " ORDER BY $sortorder";
 
-  my $sth = $dbh->prepare($query);
-  $sth->execute(@values) ||
-    $form->dberror($query . " (" . join(", ", @values) . ")");
+  my @result = selectall_hashref_query($form, $dbh, $query, @values);
 
-  $form->{AP} = [];
-  while (my $ap = $sth->fetchrow_hashref(NAME_lc)) {
-    push @{ $form->{AP} }, $ap;
-  }
-
-  $sth->finish;
-  $dbh->disconnect;
+  $form->{AP} = [ @result ];
 
   $main::lxdebug->leave_sub();
 }
diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl
index f23caf2ae..f88229309 100644
--- a/bin/mozilla/ap.pl
+++ b/bin/mozilla/ap.pl
@@ -1342,6 +1342,8 @@ sub search {
           <tr>
 		<td align=right><input name="l_payment_terms" class=checkbox type=checkbox value=Y></td>
 		<td nowrap>| . $locale->text('Payment Terms') . qq|</td>
+		<td align=right><input name="l_charts" class=checkbox type=checkbox value=Y></td>
+		<td nowrap>| . $locale->text('Buchungskonto') . qq|</td>
           </tr>
 	    </table>
 	  </td>
@@ -1406,7 +1408,7 @@ sub ap_transactions {
   my @columns =
     qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
        due duedate transaction_description notes employee globalprojectnumber
-       vendornumber country ustid taxzone payment_terms);
+       vendornumber country ustid taxzone payment_terms charts);
 
   my @hidden_variables = map { "l_${_}" } @columns;
   push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
@@ -1436,6 +1438,7 @@ sub ap_transactions {
     'ustid'                   => { 'text' => $locale->text('USt-IdNr.'), },
     'taxzone'                 => { 'text' => $locale->text('Steuersatz'), },
     'payment_terms'           => { 'text' => $locale->text('Payment Terms'), },
+    'charts'                  => { 'text' => $locale->text('Buchungskonto'), },
   );
 
   foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
diff --git a/locale/de/ap b/locale/de/ap
index 4bf7b37b2..7de98d5fe 100644
--- a/locale/de/ap
+++ b/locale/de/ap
@@ -28,6 +28,7 @@ $self->{texts} = {
   'Bin List'                    => 'Lagerliste',
   'Binding to the LDAP server as "#1" failed. Please check config/authentication.pl.' => 'Die Anmeldung am LDAP-Server als "#1" schlug fehl. Bitte &uuml;berpr&uuml;fen Sie die Angaben in config/authentication.pl.',
   'Bis'                         => 'bis',
+  'Buchungskonto'               => 'Buchungskonto',
   'CANCELED'                    => 'Storniert',
   'CR'                          => 'H',
   'CRM admin'                   => 'Administration',
