commit 0e0ff15052f7cb7ed1a2b04235a8a217da97a183
Author: Jan Büren <jan@kivitendo-premium.de>
Date:   Sat Dec 18 14:13:07 2010 +0100

    Standard-Auswahl für Umlaufvermögenskonto (Bank) mandantenweit setzen. Ferner yearend aus AM.pm entfernt und schliessende </options> für selectAP_paid Array hinzugefügt

diff --git a/SL/AM.pm b/SL/AM.pm
index 12a4ad7d3..df7d9d2c0 100644
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -1358,7 +1358,7 @@ sub save_defaults {
   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
 
   my %accnos;
-  map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno);
+  map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno ar_paid_accno);
 
   $form->{curr}  =~ s/ //g;
   my @currencies =  grep { $_ ne '' } split m/:/, $form->{curr};
@@ -1373,6 +1373,7 @@ sub save_defaults {
         expense_accno_id   = (SELECT c.id FROM chart c WHERE c.accno = ?),
         fxgain_accno_id    = (SELECT c.id FROM chart c WHERE c.accno = ?),
         fxloss_accno_id    = (SELECT c.id FROM chart c WHERE c.accno = ?),
+        ar_paid_accno_id   = (SELECT c.id FROM chart c WHERE c.accno = ?),
         invnumber          = ?,
         cnnumber           = ?,
         sonumber           = ?,
@@ -1385,19 +1386,18 @@ sub save_defaults {
         servicenumber      = ?,
         sdonumber          = ?,
         pdonumber          = ?,
-        yearend            = ?,
         curr               = ?,
         businessnumber     = ?,
         weightunit         = ?|;
   my @values = ($accnos{inventory_accno}, $accnos{income_accno}, $accnos{expense_accno},
-                $accnos{fxgain_accno},    $accnos{fxloss_accno},
+                $accnos{fxgain_accno},    $accnos{fxloss_accno}, $accnos{ar_paid_accno},
                 $form->{invnumber},       $form->{cnnumber},
                 $form->{sonumber},        $form->{ponumber},
                 $form->{sqnumber},        $form->{rfqnumber},
                 $form->{customernumber},  $form->{vendornumber},
                 $form->{articlenumber},   $form->{servicenumber},
                 $form->{sdonumber},       $form->{pdonumber},
-                $form->{yearend},         $currency,
+                $currency,
                 $form->{businessnumber},  $form->{weightunit});
   do_query($form, $dbh, $query, @values);
 
@@ -1492,6 +1492,7 @@ sub defaultaccounts {
   $form->{defaults}{IC_expense}   = $form->{defaults}{expense_accno_id};
   $form->{defaults}{FX_gain}      = $form->{defaults}{fxgain_accno_id};
   $form->{defaults}{FX_loss}      = $form->{defaults}{fxloss_accno_id};
+  $form->{defaults}{AR_paid}      = $form->{defaults}{ar_paid_accno_id};
 
   $form->{defaults}{weightunit} ||= 'kg';
 
@@ -1571,6 +1572,24 @@ sub defaultaccounts {
       if $ref->{taxnumber};
     $form->{taxrates}{ $ref->{accno} }{rate} = $ref->{rate} if $ref->{rate};
   }
+  # Abfrage für Standard Umlaufvermögenskonto
+  $query =
+    qq|SELECT id, accno, description, link | .
+    qq|FROM chart | .
+    qq|WHERE link LIKE ? |.
+    qq|ORDER BY accno|;
+  $sth = prepare_execute_query($form, $dbh, $query, '%AR%');
+  $sth->execute || $form->dberror($query);#
+  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+    foreach my $item (split(/:/, $ref->{link})) {
+      if ($item eq "AR_paid") {
+        %{ $form->{IC}{AR_paid}{ $ref->{accno} } } = (
+                                             id          => $ref->{id},
+                                             description => $ref->{description}
+          );
+      }
+    }
+  }
 
   $sth->finish;
   $dbh->disconnect;
diff --git a/SL/IS.pm b/SL/IS.pm
index 8e7dcc9f1..590923361 100644
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -2159,4 +2159,21 @@ sub is_storno {
   return $result;
 }
 
+sub get_standard_accno_current_assets {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $query = qq| SELECT accno FROM chart WHERE id = (SELECT ar_paid_accno_id FROM defaults)|;
+  my ($result) = selectrow_query($form, $dbh, $query);
+
+  $dbh->disconnect();
+
+  $main::lxdebug->leave_sub();
+
+  return $result;
+}
+
 1;
diff --git a/bin/mozilla/cp.pl b/bin/mozilla/cp.pl
index b3efdec57..721a4a8cf 100644
--- a/bin/mozilla/cp.pl
+++ b/bin/mozilla/cp.pl
@@ -78,15 +78,21 @@ sub payment {
 
   CP->paymentaccounts(\%myconfig, \%$form);
 
+  # Standard Konto für Umlaufvermögen
+  my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
   $form->{selectaccount} = "";
   $form->{"select$form->{ARAP}"} = "";
 
-  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
-    @{ $form->{PR}{"$form->{ARAP}_paid"} };
-  map {
-    $form->{"select$form->{ARAP}"} .=
-      "<option>$_->{accno}--$_->{description}\n"
-  } @{ $form->{PR}{ $form->{ARAP} } };
+  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n";
+        $form->{account}        = "$_->{accno}--$_->{description}" if ($_->{accno} eq $accno_arap) } @{ $form->{PR}{"$form->{ARAP}_paid"} };
+
+  # Braucht man das hier überhaupt? Erstmal auskommentieren .. jan 18.12.2010
+  #  map {
+  #    $form->{"select$form->{ARAP}"} .=
+  #      "<option>$_->{accno}--$_->{description}\n"
+  #  } @{ $form->{PR}{ $form->{ARAP} } };
+  # ENDE LOESCHMICH in 2012
 
   # currencies
   # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl
index 1dafe8451..ced248f48 100644
--- a/bin/mozilla/ir.pl
+++ b/bin/mozilla/ir.pl
@@ -171,7 +171,7 @@ sub invoice_links {
   foreach my $key (keys %{ $form->{AP_links} }) {
 
     foreach my $ref (@{ $form->{AP_links}{$key} }) {
-      $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
+      $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
     }
 
     next unless $form->{acc_trans}{$key};
@@ -393,9 +393,17 @@ sub form_footer {
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
 
+  # Standard Konto für Umlaufvermögen
+  my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
   for my $i (1 .. $form->{paidaccounts}) {
     $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
-    $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+    if (!$form->{"AP_paid_$i"}) {
+      $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
+    } else {
+      $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+    }
+
     $totalpaid += $form->{"paid_$i"};
   }
 
diff --git a/sql/Pg-upgrade2/add_ar_paid_defaults.sql b/sql/Pg-upgrade2/add_ar_paid_defaults.sql
new file mode 100644
index 000000000..43b257e6a
--- /dev/null
+++ b/sql/Pg-upgrade2/add_ar_paid_defaults.sql
@@ -0,0 +1,5 @@
+-- @tag: add_ar_paid_defaults 
+-- @description: Standardkonto für ar_paid (Umlaufvermögenskonto == Bank) in der Tabelle defaults hinzugefügt
+-- @depends: release_2_6_1
+-- @charset: utf-8
+ALTER TABLE defaults ADD COLUMN ar_paid_accno_id integer;
diff --git a/templates/webpages/am/edit_defaults.html b/templates/webpages/am/edit_defaults.html
index 315673b03..d346b893f 100644
--- a/templates/webpages/am/edit_defaults.html
+++ b/templates/webpages/am/edit_defaults.html
@@ -116,6 +116,16 @@
       </select>
      </td>
     </tr>
+     <tr>
+     <th align="right" nowrap>[% 'Current assets account' | $T8 %]</th>
+     <td colspan="3">
+      <select name="ar_paid_accno">
+       [%- FOREACH row = ACCNOS_AR_PAID %]
+       <option value="[% HTML.escape(row.value) %]"[% IF row.selected %] selected[% END %]>[% HTML.escape(row.name) %]</option>
+       [%- END %]
+      </select>
+     </td>
+    </tr>
 
     <tr class="listheading">
      <th colspan="4">[% 'Miscellaneous' | $T8 %]</th>
