use SL::MoreCommon;
use SL::DB::Default;
use SL::DB::TaxZone;
+use SL::DB;
use List::Util qw(min);
use strict;
sub post_invoice {
+ my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_post_invoice, $self, $myconfig, $form, $provided_dbh, $payments_only);
+
+ $::lxdebug->leave_sub;
+ return $rc;
+}
+
+sub _post_invoice {
my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
- # connect to database, turn off autocommit
- my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ my $dbh = $provided_dbh || SL::DB->client->dbh;
my $restricter = SL::HTML::Restrict->create;
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
$query = qq|UPDATE ap SET paid = ? WHERE id = ?|;
do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id}));
$form->new_lastmtime('ap');
- if (!$provided_dbh) {
- $dbh->commit();
- $dbh->disconnect();
- }
- $main::lxdebug->leave_sub();
return;
}
$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();
-
- return $rc;
+ return 1;
}
sub reverse_invoice {
my ($self, $myconfig, $form) = @_;
my $query;
# connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
+ my $dbh = SL::DB->client->dbh;
- &reverse_invoice($dbh, $form);
+ SL::DB->client->with_transaction(sub{
- my @values = (conv_i($form->{id}));
-
- # delete zero entries
- # wtf? use case for this?
- $query = qq|DELETE FROM acc_trans WHERE amount = 0|;
- do_query($form, $dbh, $query);
+ &reverse_invoice($dbh, $form);
+ my @values = (conv_i($form->{id}));
- my @queries = (
- qq|DELETE FROM invoice WHERE trans_id = ?|,
- qq|DELETE FROM ap WHERE id = ?|,
- );
+ # delete zero entries
+ # wtf? use case for this?
+ $query = qq|DELETE FROM acc_trans WHERE amount = 0|;
+ do_query($form, $dbh, $query);
- map { do_query($form, $dbh, $_, @values) } @queries;
- my $rc = $dbh->commit;
- $dbh->disconnect;
+ my @queries = (
+ qq|DELETE FROM invoice WHERE trans_id = ?|,
+ qq|DELETE FROM ap WHERE id = ?|,
+ );
- $main::lxdebug->leave_sub();
+ map { do_query($form, $dbh, $_, @values) } @queries;
+ });
- return $rc;
+ return 1;
}
sub retrieve_invoice {
}
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 get_duedate {