use SL::DB::Language;
use SL::TransNumber;
use SL::Util qw(trim);
+use SL::DB;
use strict;
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my $query =
qq|SELECT * | .
FROM defaults|;
($form->{AR_amount_fee}, $form->{AR_amount_interest}, $form->{AR}) = selectrow_query($form, $dbh, $query);
- $dbh->disconnect();
-
$main::lxdebug->leave_sub();
}
sub save_config {
+ my ($self, $myconfig, $form) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_save_config, $self, $myconfig, $form);
+
+ $::lxdebug->leave_sub;
+ return $rc;
+}
+
+sub _save_config {
my ($self, $myconfig, $form) = @_;
- # connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
+ my $dbh = SL::DB->client->dbh;
my ($query, @values);
@values = (conv_i($form->{AR_amount_fee}), conv_i($form->{AR_amount_interest}), conv_i($form->{AR}));
do_query($form, $dbh, $query, @values);
- $dbh->commit();
- $dbh->disconnect();
-
- $main::lxdebug->leave_sub();
+ return 1;
}
sub create_invoice_for_fees {
$main::lxdebug->leave_sub();
}
+
sub save_dunning {
+ my ($self, $myconfig, $form, $rows) = @_;
$main::lxdebug->enter_sub();
+ my $rc = SL::DB->client->with_transaction(\&_save_dunning, $self, $myconfig, $form, $rows);
+ $::lxdebug->leave_sub;
+
+ return $rc;
+}
+
+
+sub _save_dunning {
my ($self, $myconfig, $form, $rows) = @_;
- # connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
+
+ my $dbh = SL::DB->client->dbh;
my ($query, @values);
$self->send_email($myconfig, $form, $dunning_id, $dbh);
}
- $dbh->commit();
- $dbh->disconnect();
-
- $main::lxdebug->leave_sub();
+ return 1;
}
sub send_email {
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my $where;
my @values;
$query = qq|SELECT id, dunning_description FROM dunning_config ORDER BY dunning_level|;
$form->{DUNNING_CONFIG} = selectall_hashref_query($form, $dbh, $query);
- $dbh->disconnect;
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my $where = qq| WHERE (da.trans_id = a.id)|;
map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest);
}
- $dbh->disconnect;
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
# connect to database
- my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ my $dbh = $provided_dbh || SL::DB->client->dbh;
$dunning_id =~ s|[^\d]||g;
$form->parse_template($myconfig);
- $dbh->disconnect() unless $provided_dbh;
-
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
- my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect($myconfig);
+ my $dbh = $provided_dbh || SL::DB->client->dbh;
my ($query, @values, $sth);
push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'filename' => "${spool}/$filename",
'name' => "dunning_invoice_${dunning_id}.pdf" };
- $dbh->disconnect() unless $provided_dbh;
-
$main::lxdebug->leave_sub();
}