Revision 5092b0bb
Von Jan Büren vor 6 Tagen hinzugefügt
- ID 5092b0bb98b978ec718dfcfe5fa9eaab72dc9e6a
- Vorgänger 6fa8f517
SL/Controller/BankTransaction.pm | ||
---|---|---|
98 | 98 |
@where |
99 | 99 |
], |
100 | 100 |
); |
101 |
|
|
102 |
my $has_batch_transaction = (grep { $_->is_batch_transaction } @{ $bank_transactions }) ? 1 : undef; |
|
103 |
|
|
101 | 104 |
# credit notes have a negative amount, treat differently |
102 | 105 |
my $all_open_ar_invoices = SL::DB::Manager::Invoice->get_all(where => [ or => [ amount => { gt => \'paid' }, # '} make emacs happy |
103 | 106 |
and => [ type => 'credit_note', |
... | ... | |
109 | 112 |
|
110 | 113 |
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice->get_all(where => [amount => { ne => \'paid' }], # '}] make emacs happy |
111 | 114 |
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']); |
|
117 | 115 |
|
118 | 116 |
my @all_open_invoices; |
119 | 117 |
# filter out invoices with less than 1 cent outstanding |
120 | 118 |
push @all_open_invoices, map { $_->{is_ar}=1 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices }; |
121 | 119 |
push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices }; |
122 | 120 |
|
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 |
} |
|
140 | 146 |
} |
141 | 147 |
} |
142 |
|
|
143 | 148 |
# try to match each bank_transaction with each of the possible open invoices |
144 | 149 |
# by awarding points |
145 | 150 |
my @proposals; |
... | ... | |
154 | 159 |
|
155 | 160 |
$bt->{remote_name} .= $bt->{remote_name_1} if $bt->{remote_name_1}; |
156 | 161 |
|
157 |
if ( $bt->is_batch_transaction ) { |
|
162 |
if ($has_batch_transaction && $bt->is_batch_transaction ) {
|
|
158 | 163 |
my $found=0; |
159 | 164 |
foreach ( keys %sepa_exports) { |
160 | 165 |
if ( abs(($sepa_exports{$_}->{amount} * 1) - ($bt->amount * 1)) < 0.01 ) { |
Auch abrufbar als: Unified diff
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.