Skip to content

Commit 5092b0b

Browse files
committed
Code 191 Randfall nur berechnen, wenn dieser auch im Datenbestand vorkommt
Ich hab exakt einen Mandanten gefunden, der folgende Transaktionscodes gespeichert hat: select distinct transaction_code from bank_transactions; transaction_code ------------------ 116 TRF 105 MSC 835 191 159 51 DDT 166 STO 303 117 SEC CHG CHK Der Code 191 befindet sich in 10 von 6800 Bankbewegungen, dennoch wird bei jeder Verbuchungsabfrage über alle offene SEPA Exporte iteriert, um diesen Fall auf Verdacht zu berechnen. Damit ist jetzt Schluss! Die aktuelle Bankbewegungen lassen sich sehr simpel mit einer Zeile vorher analysieren, ob sich die gesamte Aktion überhaupt lohnt.
1 parent 6fa8f51 commit 5092b0b

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

SL/Controller/BankTransaction.pm

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ sub gather_bank_transactions_and_proposals {
9898
@where
9999
],
100100
);
101+
102+
my $has_batch_transaction = (grep { $_->is_batch_transaction } @{ $bank_transactions }) ? 1 : undef;
103+
101104
# credit notes have a negative amount, treat differently
102105
my $all_open_ar_invoices = SL::DB::Manager::Invoice->get_all(where => [ or => [ amount => { gt => \'paid' }, # '} make emacs happy
103106
and => [ type => 'credit_note',
@@ -109,37 +112,39 @@ sub gather_bank_transactions_and_proposals {
109112

110113
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice->get_all(where => [amount => { ne => \'paid' }], # '}] make emacs happy
111114
with_objects => ['vendor' ,'payment_terms']);
112-
my $all_open_sepa_export_items = SL::DB::Manager::SepaExportItem->get_all(where => [chart_id => $params{bank_account}->chart_id ,
113-
'sepa_export.executed' => 0,
114-
'sepa_export.closed' => 0
115-
],
116-
with_objects => ['sepa_export']);
117115

118116
my @all_open_invoices;
119117
# filter out invoices with less than 1 cent outstanding
120118
push @all_open_invoices, map { $_->{is_ar}=1 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices };
121119
push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
122120

123-
my %sepa_exports;
124-
my %sepa_export_items_by_id = partition_by { $_->ar_id || $_->ap_id } @$all_open_sepa_export_items;
125-
126-
# first collect sepa export items to open invoices
127-
foreach my $open_invoice (@all_open_invoices){
128-
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount,2);
129-
$open_invoice->{skonto_type} = 'without_skonto';
130-
foreach (@{ $sepa_export_items_by_id{ $open_invoice->id } || [] }) {
131-
my $factor = ($_->ar_id == $open_invoice->id ? 1 : -1);
132-
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2);
133-
134-
$open_invoice->{skonto_type} = $_->payment_type;
135-
$sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
136-
$sepa_exports{$_->sepa_export_id}->{count}++;
137-
$sepa_exports{$_->sepa_export_id}->{is_ar}++ if $_->ar_id == $open_invoice->id;
138-
$sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
139-
push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice;
121+
122+
my (%sepa_exports, %sepa_export_items_by_id, $all_open_sepa_export_items);
123+
if ($has_batch_transaction) {
124+
$all_open_sepa_export_items = SL::DB::Manager::SepaExportItem->get_all(where => [chart_id => $params{bank_account}->chart_id ,
125+
'sepa_export.executed' => 0,
126+
'sepa_export.closed' => 0
127+
],
128+
with_objects => ['sepa_export']);
129+
%sepa_export_items_by_id = partition_by { $_->ar_id || $_->ap_id } @$all_open_sepa_export_items;
130+
131+
# first collect sepa export items to open invoices
132+
foreach my $open_invoice (@all_open_invoices){
133+
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount,2);
134+
$open_invoice->{skonto_type} = 'without_skonto';
135+
foreach (@{ $sepa_export_items_by_id{ $open_invoice->id } || [] }) {
136+
my $factor = ($_->ar_id == $open_invoice->id ? 1 : -1);
137+
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2);
138+
139+
$open_invoice->{skonto_type} = $_->payment_type;
140+
$sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
141+
$sepa_exports{$_->sepa_export_id}->{count}++;
142+
$sepa_exports{$_->sepa_export_id}->{is_ar}++ if $_->ar_id == $open_invoice->id;
143+
$sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
144+
push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice;
145+
}
140146
}
141147
}
142-
143148
# try to match each bank_transaction with each of the possible open invoices
144149
# by awarding points
145150
my @proposals;
@@ -154,7 +159,7 @@ sub gather_bank_transactions_and_proposals {
154159

155160
$bt->{remote_name} .= $bt->{remote_name_1} if $bt->{remote_name_1};
156161

157-
if ( $bt->is_batch_transaction ) {
162+
if ($has_batch_transaction && $bt->is_batch_transaction ) {
158163
my $found=0;
159164
foreach ( keys %sepa_exports) {
160165
if ( abs(($sepa_exports{$_}->{amount} * 1) - ($bt->amount * 1)) < 0.01 ) {

0 commit comments

Comments
 (0)