X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f36da7b69b6e8f47bab976e827f5b0f8311cf4c5..59320b5a20c6fe1286f0460182d0a8566d19c0eb:/SL/DB/BankTransaction.pm diff --git a/SL/DB/BankTransaction.pm b/SL/DB/BankTransaction.pm index 1c2a6dc7f..1d8705e9a 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; @@ -46,10 +47,15 @@ sub linked_invoices { return [ @linked_invoices ]; } +sub is_batch_transaction { + $_[0]->transaction_code eq "191"; +} + + 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 = ( @@ -72,10 +78,16 @@ sub get_agreement_with_invoice { skonto_exact_amount => 5, wrong_sign => -1, sepa_export_item => 5, + batch_sepa_transaction => 20, ); my ($agreement,$rule_matches); + if ( $self->is_batch_transaction && $self->{sepa_export_ok}) { + $agreement += $points{batch_sepa_transaction}; + $rule_matches .= 'batch_sepa_transaction(' . $points{'batch_sepa_transaction'} . ') '; + } + # compare banking arrangements my ($iban, $bank_code, $account_number); $bank_code = $invoice->customer->bank_code if $invoice->is_sales; @@ -111,6 +123,7 @@ sub get_agreement_with_invoice { if ( $invoice->skonto_date && abs(abs($invoice->amount_less_skonto) - abs($self->amount)) < 0.01) { $agreement += $points{skonto_exact_amount}; $rule_matches .= 'skonto_exact_amount(' . $points{'skonto_exact_amount'} . ') '; + $invoice->{skonto_type} = 'with_skonto_pt'; }; #search invoice number in purpose @@ -149,7 +162,7 @@ sub get_agreement_with_invoice { my $cvname; $cvname = $invoice->customer->name if $invoice->is_sales; $cvname = $invoice->vendor->name if ! $invoice->is_sales; - if ( $cvname && $self->purpose =~ /\b$cvname\b/i ) { + if ( $cvname && $self->purpose =~ /\b\Q$cvname\E\b/i ) { $agreement += $points{cust_vend_name_in_purpose}; $rule_matches .= 'cust_vend_name_in_purpose(' . $points{'cust_vend_name_in_purpose'} . ') '; }; @@ -208,26 +221,23 @@ 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 ) { + if ( my $seis = $invoice->{sepa_export_item} ) { + 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'} . ') '; - }; + if ( abs(abs($self->amount) - abs($sei->amount)) < 0.01 ) { + $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 - }; - }; + # TODO: Catch the more than one case. User is allowed to split + # payments for one invoice item in one sepa export. + } + } return ($agreement,$rule_matches); };