X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/bc40bcabc425b99f3b79a5544684a6fe8674adfe..88d162cc5e8e8d3810059d918a1eef6a2b205984:/SL/SEPA.pm diff --git a/SL/SEPA.pm b/SL/SEPA.pm index 280906307..a9ba2f3da 100644 --- a/SL/SEPA.pm +++ b/SL/SEPA.pm @@ -8,6 +8,7 @@ use Data::Dumper; use SL::DBUtils; use SL::DB::Invoice; use SL::DB::PurchaseInvoice; +use SL::DB; use SL::Locale::String qw(t8); use DateTime; @@ -45,7 +46,9 @@ sub retrieve_open_invoices { COALESCE(vc.iban, '') <> '' AND COALESCE(vc.bic, '') <> '' ${mandate} AS vc_bank_info_ok, - ${arap}.amount - ${arap}.paid - COALESCE(open_transfers.amount, 0) AS open_amount + ${arap}.amount - ${arap}.paid - COALESCE(open_transfers.amount, 0) AS open_amount, + COALESCE(open_transfers.amount, 0) AS transfer_amount, + pt.description as pt_description FROM ${arap} LEFT JOIN ${vc} vc ON (${arap}.${vc}_id = vc.id) @@ -63,6 +66,7 @@ sub retrieve_open_invoices { ORDER BY lower(vc.name) ASC, lower(${arap}.invnumber) ASC |; + # $main::lxdebug->message(LXDebug->DEBUG2(),"sepa add query:".$query); my $results = selectall_hashref_query($form, $dbh, $query); @@ -87,8 +91,16 @@ sub retrieve_open_invoices { } sub create_export { + my ($self, %params) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_create_export, $self, %params); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _create_export { my $self = shift; my %params = @_; @@ -100,7 +112,7 @@ sub create_export { my $vc = $params{vc} eq 'customer' ? 'customer' : 'vendor'; my $ARAP = uc $arap; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + my $dbh = $params{dbh} || SL::DB->client->dbh; my ($export_id) = selectfirst_array_query($form, $dbh, qq|SELECT nextval('sepa_export_id_seq')|); my $query = @@ -189,10 +201,6 @@ sub create_export { $h_insert->finish(); $h_item_id->finish(); - $dbh->commit() unless ($params{dbh}); - - $main::lxdebug->leave_sub(); - return $export_id; } @@ -267,15 +275,16 @@ sub close_export { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; - my @ids = ref $params{id} eq 'ARRAY' ? @{ $params{id} } : ($params{id}); - my $placeholders = join ', ', ('?') x scalar @ids; - my $query = qq|UPDATE sepa_export SET closed = TRUE WHERE id IN ($placeholders)|; + my @ids = ref $params{id} eq 'ARRAY' ? @{ $params{id} } : ($params{id}); + my $placeholders = join ', ', ('?') x scalar @ids; + my $query = qq|UPDATE sepa_export SET closed = TRUE WHERE id IN ($placeholders)|; - do_query($form, $dbh, $query, map { conv_i($_) } @ids); - - $dbh->commit() unless ($params{dbh}); + do_query($form, $dbh, $query, map { conv_i($_) } @ids); + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); } @@ -402,8 +411,16 @@ SQL } sub post_payment { + my ($self, %params) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, %params); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _post_payment { my $self = shift; my %params = @_; @@ -416,7 +433,7 @@ sub post_payment { my $mult = $params{vc} eq 'customer' ? -1 : 1; my $ARAP = uc $arap; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + my $dbh = $params{dbh} || SL::DB->client->dbh; my @items = ref $params{items} eq 'ARRAY' ? @{ $params{items} } : ($params{items}); @@ -502,9 +519,7 @@ sub post_payment { map { $_->[0]->finish() } values %handles; - $dbh->commit() unless ($params{dbh}); - - $main::lxdebug->leave_sub(); + return 1; } 1;