]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/BankTransaction.pm
Whitespace
[mfinanz.git] / SL / DB / BankTransaction.pm
index 26c38e51b04ca2d4af60c9a730400412ac67eee6..1d8705e9a3341125db3b330a83d0703cb0a4ad74 100644 (file)
@@ -47,6 +47,11 @@ sub linked_invoices {
   return [ @linked_invoices ];
 }
 
+sub is_batch_transaction {
+  $_[0]->transaction_code eq "191";
+}
+
+
 sub get_agreement_with_invoice {
   my ($self, $invoice) = @_;
 
@@ -73,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;
@@ -209,17 +220,13 @@ 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 there is exactly one non-executed sepa_export_item for the invoice
+  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};
+      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 {
@@ -227,6 +234,8 @@ sub get_agreement_with_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.
     }
   }