Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / RC.pm
index 89904d8..d7d71a3 100644 (file)
--- a/SL/RC.pm
+++ b/SL/RC.pm
@@ -25,7 +25,8 @@
 # GNU General Public License for more details.
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1335, USA.
 #======================================================================
 #
 # Account reconciliation routines
@@ -35,6 +36,7 @@
 package RC;
 
 use SL::DBUtils;
+use SL::DB;
 
 use strict;
 
@@ -43,8 +45,7 @@ sub paymentaccounts {
 
   my ($self, $myconfig, $form) = @_;
 
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
+  my $dbh = SL::DB->client->dbh;
 
   my $query =
     qq|SELECT accno, description | .
@@ -53,7 +54,6 @@ sub paymentaccounts {
     qq|ORDER BY accno|;
 
   $form->{PR} = selectall_hashref_query($form, $dbh, $query);
-  $dbh->disconnect;
 
   $main::lxdebug->leave_sub();
 }
@@ -64,7 +64,7 @@ sub payment_transactions {
   my ($self, $myconfig, $form) = @_;
 
   # connect to database, turn AutoCommit off
-  my $dbh = $form->dbconnect_noauto($myconfig);
+  my $dbh = SL::DB->client->dbh;
 
   my ($query, @values);
 
@@ -211,12 +211,10 @@ sub payment_transactions {
     push(@values, conv_i($form->{filter_amount}));
   }
 
-  $query .= " ORDER BY 3,7,8 LIMIT 6";
+  $query .= " ORDER BY 3,7,8";
 
   $form->{PR} = selectall_hashref_query($form, $dbh, $query, @values);
 
-  $dbh->disconnect;
-
   $main::lxdebug->leave_sub();
 }
 
@@ -225,30 +223,30 @@ sub reconcile {
 
   my ($self, $myconfig, $form) = @_;
 
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
-
-  my ($query, $i);
+  SL::DB->client->with_transaction(sub {
+    my $dbh = SL::DB->client->dbh;
 
-  # clear flags
-  for $i (1 .. $form->{rowcount}) {
-    if ($form->{"cleared_$i"}) {
-      $query =
-        qq|UPDATE acc_trans SET cleared = '1' | .
-        qq|WHERE acc_trans_id = ?|;
-      do_query($form, $dbh, $query, $form->{"oid_$i"});
+    my ($query, $i);
 
-      # clear fx_transaction
-      if ($form->{"fxoid_$i"}) {
+    # clear flags
+    for $i (1 .. $form->{rowcount}) {
+      if ($form->{"cleared_$i"}) {
         $query =
           qq|UPDATE acc_trans SET cleared = '1' | .
           qq|WHERE acc_trans_id = ?|;
-        do_query($form, $dbh, $query, $form->{"fxoid_$i"});
+        do_query($form, $dbh, $query, $form->{"oid_$i"});
+
+        # clear fx_transaction
+        if ($form->{"fxoid_$i"}) {
+          $query =
+            qq|UPDATE acc_trans SET cleared = '1' | .
+            qq|WHERE acc_trans_id = ?|;
+          do_query($form, $dbh, $query, $form->{"fxoid_$i"});
+        }
       }
     }
-  }
-
-  $dbh->disconnect;
+    1;
+  }) or do { die SL::DB->client->error };
 
   $main::lxdebug->leave_sub();
 }
@@ -259,7 +257,7 @@ sub get_statement_balance {
   my ($self, $myconfig, $form) = @_;
 
   # connect to database, turn AutoCommit off
-  my $dbh = $form->dbconnect_noauto($myconfig);
+  my $dbh = SL::DB->client->dbh;
 
   my ($query, @values);
 
@@ -277,8 +275,6 @@ sub get_statement_balance {
 
   ($form->{statement_balance}) = selectrow_query($form, $dbh, $query, @values);
 
-  $dbh->disconnect;
-
   $main::lxdebug->leave_sub();
 }