use SL::DB::Default;
use SL::TransNumber;
use SL::Util qw(trim);
+use SL::DB;
use strict;
sub post_transaction {
+ my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, $payments_only);
+
+ $::lxdebug->leave_sub;
+ return $rc;
+}
+
+sub _post_transaction {
my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
my ($query, $sth, $null, $taxrate, $amount, $tax);
my @values;
- my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ my $dbh = $provided_dbh || SL::DB->client->dbh;
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
# set exchangerate
$datev->export;
if ($datev->errors) {
- $dbh->rollback;
die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors;
}
}
- my $rc = 1;
- if (!$provided_dbh) {
- $rc = $dbh->commit();
- $dbh->disconnect();
- }
-
- $main::lxdebug->leave_sub() and return $rc;
+ return 1;
}
sub _delete_payments {
}
sub post_payment {
+ my ($self, $myconfig, $form, $locale) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, $myconfig, $form, $locale);
+
+ $::lxdebug->leave_sub;
+ return $rc;
+}
+
+sub _post_payment {
my ($self, $myconfig, $form, $locale) = @_;
- # connect to database, turn off autocommit
- my $dbh = $form->dbconnect_noauto($myconfig);
+ my $dbh = SL::DB->client->dbh;
my (%payments, $old_form, $row, $item, $query, %keep_vars);
restore_form($old_form);
- my $rc = $dbh->commit();
- $dbh->disconnect();
-
- $main::lxdebug->leave_sub();
-
- return $rc;
+ return 1;
}
sub delete_transaction {
my ($self, $myconfig, $form) = @_;
- # connect to database, turn AutoCommit off
- my $dbh = $form->dbconnect_noauto($myconfig);
-
- # acc_trans entries are deleted by database triggers.
- my $query = qq|DELETE FROM ar WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- # commit
- my $rc = $dbh->commit;
- $dbh->disconnect;
+ SL::DB->client->with_transaction(sub {
+ # acc_trans entries are deleted by database triggers.
+ my $query = qq|DELETE FROM ar WHERE id = ?|;
+ do_query($form, SL::DB->client->dbh, $query, $form->{id});
+ });
$main::lxdebug->leave_sub();
- return $rc;
+ return 1;
}
sub ar_transactions {
$form->{forex} = $form->{exchangerate};
$exchangerate = $form->{exchangerate} ? $form->{exchangerate} : 1;
- # expected keys: AR, AR_paid, AR_tax, AR_amount
+ # expected keys: AR, AR_paid, AR_tax, AR_amount
foreach my $key (keys %{ $form->{AR_links} }) {
$j = 0;
$k = 0;
}
sub storno {
+ my ($self, $form, $myconfig, $id) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_storno, $self, $form, $myconfig, $id);
+
+ $::lxdebug->leave_sub;
+ return $rc;
+}
+
+
+sub _storno {
my ($self, $form, $myconfig, $id) = @_;
my ($query, $new_id, $storno_row, $acc_trans_rows);
- my $dbh = $form->get_standard_dbh($myconfig);
+ my $dbh = SL::DB->client->dbh;
$query = qq|SELECT nextval('glid')|;
($new_id) = selectrow_query($form, $dbh, $query);
map { IO->set_datepaid(table => 'ar', id => $_, dbh => $dbh) } ($id, $new_id);
- $dbh->commit;
-
- $main::lxdebug->leave_sub();
+ return 1;
}