X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FSEPA.pm;h=b8cdee03f2235923ee62a3f597a8ab701e9e2f0d;hb=28fc24763b02fab97f8a81a100dd8c16ac42b650;hp=8e7306e3101e67d2f6221bcc8fd855222b265ec9;hpb=4c9ae7fe80ec4b8bebca3935ac6c3d2cca788fae;p=kivitendo-erp.git diff --git a/SL/SEPA.pm b/SL/SEPA.pm index 8e7306e31..b8cdee03f 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; @@ -49,13 +50,13 @@ sub retrieve_open_invoices { FROM ${arap} LEFT JOIN ${vc} vc ON (${arap}.${vc}_id = vc.id) - LEFT JOIN (SELECT sei.ap_id, SUM(sei.amount) AS amount + LEFT JOIN (SELECT sei.${arap}_id, SUM(sei.amount) + SUM(COALESCE(sei.skonto_amount,0)) AS amount FROM sepa_export_items sei LEFT JOIN sepa_export se ON (sei.sepa_export_id = se.id) WHERE NOT se.closed AND (se.vc = '${vc}') - GROUP BY sei.ap_id) - AS open_transfers ON (${arap}.id = open_transfers.ap_id) + GROUP BY sei.${arap}_id) + AS open_transfers ON (${arap}.id = open_transfers.${arap}_id) LEFT JOIN payment_terms pt ON (${payment_term_type}.payment_id = pt.id) @@ -87,8 +88,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 +109,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 +198,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 +272,16 @@ sub close_export { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - - 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)|; + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; - do_query($form, $dbh, $query, map { conv_i($_) } @ids); + 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)|; - $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(); } @@ -322,13 +328,24 @@ sub list_exports { if ($filter->{invnumber}) { push @where_sub, "arap.invnumber ILIKE ?"; - push @values_sub, '%' . $filter->{invnumber} . '%'; + push @values_sub, like($filter->{invnumber}); $joins_sub{$arap} = 1; } + if ($filter->{message_id}) { + push @values, like($filter->{message_id}); + push @where, <{vc}) { push @where_sub, "vc.name ILIKE ?"; - push @values_sub, '%' . $filter->{vc} . '%'; + push @values_sub, like($filter->{vc}); $joins_sub{$arap} = 1; $joins_sub{vc} = 1; } @@ -370,6 +387,9 @@ sub list_exports { (SELECT SUM(sei.amount) FROM sepa_export_items sei WHERE (sei.sepa_export_id = se.id)) AS sum_amounts, + (SELECT string_agg(semi.message_id, ', ') + FROM sepa_export_message_ids semi + WHERE semi.sepa_export_id = se.id) AS message_ids, e.name AS employee FROM sepa_export se LEFT JOIN ( @@ -388,8 +408,16 @@ sub list_exports { } 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 = @_; @@ -402,7 +430,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}); @@ -488,9 +516,7 @@ sub post_payment { map { $_->[0]->finish() } values %handles; - $dbh->commit() unless ($params{dbh}); - - $main::lxdebug->leave_sub(); + return 1; } 1;