X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/aaa8864737fdd4c1ca6d27b423256d62b7a4b2ec..a695cc30eec6422260f0e9a9b00bbc209649d212:/SL/Controller/BankTransaction.pm diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index c220f3c1c..5dea0c55f 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -26,6 +26,7 @@ use SL::DB::RecordTemplate; use SL::DB::SepaExportItem; use SL::DBUtils qw(like); +use List::UtilsBy qw(partition_by); use List::MoreUtils qw(any); use List::Util qw(max); @@ -119,22 +120,22 @@ sub action_list { push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices }; my %sepa_exports; + my %sepa_export_items_by_id = partition_by { $_->ar_id || $_->ap_id } @$all_open_sepa_export_items; + # first collect sepa export items to open invoices foreach my $open_invoice (@all_open_invoices){ $open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount,2); $open_invoice->{skonto_type} = 'without_skonto'; - foreach ( @{$all_open_sepa_export_items}) { - if (($_->ap_id && $_->ap_id == $open_invoice->id) || ($_->ar_id && $_->ar_id == $open_invoice->id)) { - my $factor = ($_->ar_id == $open_invoice->id ? 1 : -1); - #$main::lxdebug->message(LXDebug->DEBUG2(),"sepa_exitem=".$_->id." for invoice ".$open_invoice->id." factor=".$factor); - $open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2); - $open_invoice->{skonto_type} = $_->payment_type; - $sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ }; - $sepa_exports{$_->sepa_export_id}->{count}++; - $sepa_exports{$_->sepa_export_id}->{is_ar}++ if $_->ar_id == $open_invoice->id; - $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor; - push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice; - } + foreach (@{ $sepa_export_items_by_id{ $open_invoice->id } || [] }) { + my $factor = ($_->ar_id == $open_invoice->id ? 1 : -1); + $open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2); + + $open_invoice->{skonto_type} = $_->payment_type; + $sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ }; + $sepa_exports{$_->sepa_export_id}->{count}++; + $sepa_exports{$_->sepa_export_id}->{is_ar}++ if $_->ar_id == $open_invoice->id; + $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor; + push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice; } } @@ -181,7 +182,9 @@ sub action_list { # score is stored in $bt->{agreement} foreach my $open_invoice (@all_open_invoices) { - ($open_invoice->{agreement}, $open_invoice->{rule_matches}) = $bt->get_agreement_with_invoice($open_invoice); + ($open_invoice->{agreement}, $open_invoice->{rule_matches}) = $bt->get_agreement_with_invoice($open_invoice, + sepa_export_items => $all_open_sepa_export_items, + ); $open_invoice->{realamount} = $::form->format_amount(\%::myconfig, $open_invoice->amount * ($open_invoice->{is_ar} ? 1 : -1), 2); }