X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBankTransaction.pm;h=053abb4105b43293e29104ad2b5c9273aaa0312c;hb=2c3ecbd0419d17ac7c7a202d491377e59bea74a1;hp=d5d7c55262a90321654191ffc5eb166cfaa23c7b;hpb=a87694dc525b4eabff11029f1e5401621e2bd3bc;p=kivitendo-erp.git diff --git a/SL/DB/BankTransaction.pm b/SL/DB/BankTransaction.pm index d5d7c5526..053abb410 100644 --- a/SL/DB/BankTransaction.pm +++ b/SL/DB/BankTransaction.pm @@ -8,6 +8,7 @@ use strict; use SL::DB::MetaSetup::BankTransaction; use SL::DB::Manager::BankTransaction; use SL::DB::Helper::LinkedRecords; +use Carp; require SL::DB::Invoice; require SL::DB::PurchaseInvoice; @@ -49,7 +50,7 @@ sub linked_invoices { sub get_agreement_with_invoice { my ($self, $invoice) = @_; - die "first argument is not an invoice object" + carp "get_agreement_with_invoice needs an invoice object as its first argument" unless ref($invoice) eq 'SL::DB::Invoice' or ref($invoice) eq 'SL::DB::PurchaseInvoice'; my %points = ( @@ -64,12 +65,14 @@ sub get_agreement_with_invoice { exact_amount => 4, exact_open_amount => 4, invnumber_in_purpose => 2, + own_invnumber_in_purpose => 5, # overpayment => -1, # either other invoice is more likely, or several invoices paid at once payment_before_invoice => -2, payment_within_30_days => 1, remote_account_number => 3, skonto_exact_amount => 5, wrong_sign => -1, + sepa_export_item => 5, ); my ($agreement,$rule_matches); @@ -113,11 +116,16 @@ sub get_agreement_with_invoice { #search invoice number in purpose my $invnumber = $invoice->invnumber; - # invnumbernhas to have at least 3 characters - if ( length($invnumber) > 2 && $self->purpose =~ /\b$invnumber\b/i ) { + # invnumber has to have at least 3 characters + my $squashed_purpose = $self->purpose; + $squashed_purpose =~ s/ //g; + if (length($invnumber) > 4 && $squashed_purpose =~ /$invnumber/ && $invoice->is_sales){ + $agreement += $points{own_invnumber_in_purpose}; + $rule_matches .= 'own_invnumber_in_purpose(' . $points{'own_invnumber_in_purpose'} . ') '; + } elsif (length($invnumber) > 3 && $squashed_purpose =~ /$invnumber/ ) { $agreement += $points{invnumber_in_purpose}; $rule_matches .= 'invnumber_in_purpose(' . $points{'invnumber_in_purpose'} . ') '; - }; + } #check sign if ( $invoice->is_sales && $self->amount < 0 ) { @@ -200,6 +208,28 @@ sub get_agreement_with_invoice { }; }; + # if there is exactly one non-executed sepa_export_item for the invoice + if ( my $seis = $invoice->find_sepa_export_items({ executed => 0 }) ) { + if ( scalar @$seis == 1 ) { + my $sei = $seis->[0]; + + # test for amount and id matching only, sepa transfer date and bank + # transaction date needn't match + my $arap = $invoice->is_sales ? 'ar' : 'ap'; + if ( abs($self->amount) == ($sei->amount) + && $invoice->id == $sei->arap_id + ) { + $agreement += $points{sepa_export_item}; + $rule_matches .= 'sepa_export_item(' . $points{'sepa_export_item'} . ') '; + }; + } else { + # zero or more than one sepa_export_item, do nothing for this invoice + # zero: do nothing, no sepa_export_item exists, no match + # more than one: does this ever apply? Currently you can't create sepa + # exports for invoices that already have a non-executed sepa_export + }; + }; + return ($agreement,$rule_matches); };