- #search customer/vendor number in purpose
- my $cvnumber;
- $cvnumber = $open_invoice->customer->customernumber if $open_invoice->is_sales;
- $cvnumber = $open_invoice->vendor->vendornumber if ! $open_invoice->is_sales;
- $bt->purpose =~ /\b$cvnumber\b/i ? ($open_invoice->{agreement}++) : ();
-
- #compare customer/vendor name and account holder
- my $cvname;
- $cvname = $open_invoice->customer->name if $open_invoice->is_sales;
- $cvname = $open_invoice->vendor->name if ! $open_invoice->is_sales;
- $bt->remote_name =~ /\b$cvname\b/i ? ($open_invoice->{agreement}++) : ();
-
- #Compare transdate of bank_transaction with transdate of invoice
- #Check if words in remote_name appear in cvname
- $open_invoice->{agreement} += &check_string($bt->remote_name,$cvname);
-
- $open_invoice->{agreement} -= 1 if $datediff < -5; # dies hebelt eventuell Vorkasse aus
- $open_invoice->{agreement} += 1 if $datediff < 30; # dies hebelt eventuell Vorkasse aus
-
- # only if we already have a good agreement, let date further change value of agreement.
- # this is so that if there are several open invoices which are all equal (rent jan, rent feb...) the one with the best date match is chose over the others
- # another way around this is to just pre-filter by periods instead of matching everything
- if ( $open_invoice->{agreement} > 5 ) {
- if ( $datediff == 0 ) {
- $open_invoice->{agreement} += 3;
- } elsif ( $datediff > 0 and $datediff <= 14 ) {
- $open_invoice->{agreement} += 2;
- } elsif ( $datediff >14 and $datediff < 35) {
- $open_invoice->{agreement} += 1;
- } elsif ( $datediff >34 and $datediff < 120) {
- $open_invoice->{agreement} += 1;
- } elsif ( $datediff < 0 ) {
- $open_invoice->{agreement} -= 1;
- } else {
- # e.g. datediff > 120
- };
- };