108 |
108 |
|
109 |
109 |
my @all_open_invoices;
|
110 |
110 |
# filter out invoices with less than 1 cent outstanding
|
111 |
|
push @all_open_invoices, grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices };
|
112 |
|
push @all_open_invoices, grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
|
|
111 |
push @all_open_invoices, map { $_->{is_ar}=1 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices };
|
|
112 |
push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
|
113 |
113 |
$main::lxdebug->message(LXDebug->DEBUG2(),"bank_account=".$::form->{filter}{bank_account}." invoices: ".scalar(@{ $all_open_ar_invoices }).
|
114 |
114 |
" + ".scalar(@{ $all_open_ap_invoices })." transactions=".scalar(@{ $bank_transactions }));
|
115 |
115 |
|
... | ... | |
123 |
123 |
$open_invoice->{skonto_type} = 'without_skonto';
|
124 |
124 |
foreach ( @{$all_open_sepa_export_items}) {
|
125 |
125 |
if ( $_->ap_id == $open_invoice->id || $_->ar_id == $open_invoice->id ) {
|
126 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"exitem=".$_->id." for invoice ".$open_invoice->id);
|
|
126 |
my $factor = ( $_->ar_id == $open_invoice->id>0?1:-1);
|
|
127 |
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2);
|
|
128 |
$main::lxdebug->message(LXDebug->DEBUG2(),"exitem=".$_->id." for invoice ".$open_invoice->id." factor=".$factor);
|
127 |
129 |
$open_invoice->{sepa_export_item} = $_ ;
|
128 |
130 |
$open_invoice->{skonto_type} = $_->payment_type;
|
129 |
131 |
$sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
|
130 |
132 |
$sepa_exports{$_->sepa_export_id}->{count}++ ;
|
131 |
133 |
$sepa_exports{$_->sepa_export_id}->{is_ar}++ if $_->ar_id == $open_invoice->id;
|
132 |
|
$sepa_exports{$_->sepa_export_id}->{amount} += $_->amount;
|
|
134 |
$sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
|
133 |
135 |
push ( @{ $sepa_exports{$_->sepa_export_id}->{invoices}} , $open_invoice );
|
134 |
136 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"amount for export id ".$_->sepa_export_id." = ".
|
135 |
137 |
# $sepa_exports{$_->sepa_export_id}->{amount}." count = ".
|
... | ... | |
158 |
160 |
|
159 |
161 |
if ( $self->is_collective_transaction($bt) ) {
|
160 |
162 |
foreach ( keys %sepa_exports) {
|
161 |
|
my $factor = ($sepa_exports{$_}->{is_ar}>0?1:-1);
|
162 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"Exp ID=".$_." factor=".$factor." compare sum amount ".($sepa_exports{$_}->{amount} *1) ." == ".($bt->amount * $factor));
|
163 |
|
if ( $bt->transactioncode eq '191' && ($sepa_exports{$_}->{amount} * 1) eq ($bt->amount * $factor) ) {
|
|
163 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"Exp ID=".$_." compare sum amount ".($sepa_exports{$_}->{amount} *1) ." == ".($bt->amount * 1));
|
|
164 |
if ( $bt->transactioncode eq '191' && ($sepa_exports{$_}->{amount} * 1) eq ($bt->amount * 1) ) {
|
164 |
165 |
## jupp
|
165 |
166 |
$bt->{proposals} = $sepa_exports{$_}->{invoices} ;
|
|
167 |
$bt->{agreement} = 20;
|
|
168 |
$bt->{rule_matches} = 'sepa_export_item(20)';
|
166 |
169 |
$sepa_exports{$_}->{proposed}=1;
|
167 |
170 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"has ".scalar($bt->{proposals})." invoices");
|
168 |
171 |
push(@proposals, $bt);
|
... | ... | |
172 |
175 |
}
|
173 |
176 |
next unless $bt->{remote_name}; # bank has no name, usually fees, use create invoice to assign
|
174 |
177 |
|
175 |
|
foreach ( keys %sepa_exports) {
|
176 |
|
my $factor = ($sepa_exports{$_}->{is_ar}>0?1:-1);
|
177 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"exp count=".$sepa_exports{$_}->{count}." factor=".$factor." proposed=".$sepa_exports{$_}->{proposed});
|
178 |
|
if ( $sepa_exports{$_}->{count} == 1 ) {
|
179 |
|
my $oinvoice = @{ $sepa_exports{$_}->{invoices}}[0];
|
180 |
|
my $eitem = $sepa_exports{$_}->{item};
|
181 |
|
$eitem->amount($eitem->amount*1);
|
182 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"remote account '".$bt->{remote_account_number}."' bt_amount=". ($bt->amount * $factor));
|
183 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"compare with '".$eitem->vc_iban."' amount=".$eitem->amount);
|
184 |
|
if ( $bt->{remote_account_number} eq $eitem->vc_iban && $eitem->amount eq ($bt->amount * $factor)) {
|
185 |
|
## jupp
|
186 |
|
$bt->{proposals} = $sepa_exports{$_}->{invoices} ;
|
187 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(),"found invoice");
|
188 |
|
$sepa_exports{$_}->{proposed}=1;
|
189 |
|
push(@proposals, $bt);
|
190 |
|
next;
|
|
178 |
foreach ( @{$all_open_sepa_export_items}) {
|
|
179 |
last if scalar (@all_sepa_invoices) == 0;
|
|
180 |
foreach my $open_invoice (@all_sepa_invoices){
|
|
181 |
if ( $_->ap_id == $open_invoice->id || $_->ar_id == $open_invoice->id ) {
|
|
182 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"exitem2=".$_->id." for invoice ".$open_invoice->id);
|
|
183 |
my $factor = ( $_->ar_id == $open_invoice->id?1:-1);
|
|
184 |
$_->amount($_->amount*1);
|
|
185 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"remote account '".$bt->{remote_account_number}."' bt_amount=". ($bt->amount * $factor));
|
|
186 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"compare with '".$_->vc_iban."' amount=".$_->amount);
|
|
187 |
if ( $bt->{remote_account_number} eq $_->vc_iban && $_->amount eq ($bt->amount * $factor)) {
|
|
188 |
push ($bt->{proposals},$open_invoice );
|
|
189 |
$bt->{agreement} = 20;
|
|
190 |
$bt->{rule_matches} = 'sepa_export_item(20)';
|
|
191 |
#$main::lxdebug->message(LXDebug->DEBUG2(),"found invoice");
|
|
192 |
@all_sepa_invoices = grep { $_ != $open_invoice } @all_sepa_invoices;
|
|
193 |
last;
|
|
194 |
}
|
191 |
195 |
}
|
192 |
|
}
|
|
196 |
}
|
193 |
197 |
}
|
194 |
198 |
|
195 |
199 |
# try to match the current $bt to each of the open_invoices, saving the
|
... | ... | |
203 |
207 |
|
204 |
208 |
foreach my $open_invoice (@all_open_invoices){
|
205 |
209 |
($open_invoice->{agreement}, $open_invoice->{rule_matches}) = $bt->get_agreement_with_invoice($open_invoice);
|
206 |
|
# $main::lxdebug->message(LXDebug->DEBUG2(),"agreement=".$open_invoice->{agreement}." rules matches=".$open_invoice->{rule_matches});
|
|
210 |
$open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*($open_invoice->{is_ar}?1:-1),2);
|
|
211 |
# $main::lxdebug->message(LXDebug->DEBUG2(),"agreement=".$open_invoice->{agreement}." rules matches=".$open_invoice->{rule_matches});
|
207 |
212 |
};
|
208 |
213 |
|
209 |
214 |
my $agreement = 15;
|
Bankimport: SEPA-Exporte werden manchmal nicht mehr erkannt
Wenn mehrere SEPA Anweisungen in einem Export sind, werden diese nicht gefunden
Nun bessere Implementierung
Nebenbei die Vorzeichen-Anzeige korrigiert