]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/BankTransaction.pm
BankTransaction: Verlinkungen auf alten Vorlagencode upgedated.
[mfinanz.git] / SL / Controller / BankTransaction.pm
index a9a944087b616129cd536d1436ac0bd401daebda..64198ee402a0a69c059ba574c2ef75bb349e6c38 100644 (file)
@@ -381,8 +381,12 @@ sub action_save_invoices {
                        return -1 if (!$a->is_sales and $a->amount < 0);
                        return 1; } @invoices                    if $bank_transaction->amount < 0;
 
+    my $max_invoices = scalar(@invoices);
+    my $n_invoices   = 0;
+
     foreach my $invoice (@invoices) {
 
+      $n_invoices++ ;
       # Check if bank_transaction already has a link to the invoice, may only be linked once per invoice
       # This might be caused by the user reloading a page and resending the form
       die t8("Bank transaction with id #1 has already been linked to #2.", $bank_transaction->id, $invoice->displayable_name)
@@ -402,7 +406,7 @@ sub action_save_invoices {
         last;
       }
       # pay invoice or go to the next bank transaction if the amount is not sufficiently high
-      if ($invoice->open_amount <= $amount_of_transaction) {
+      if ($invoice->open_amount <= $amount_of_transaction && $n_invoices < $max_invoices) {
         # first calculate new bank transaction amount ...
         if ($invoice->is_sales) {
           $amount_of_transaction -= $sign * $invoice->open_amount;
@@ -438,6 +442,7 @@ sub action_save_invoices {
       SL::DB::RecordLink->new(@props)->save;
 
       # "close" a sepa_export_item if it exists
+      # code duplicated in action_save_proposals!
       # currently only works, if there is only exactly one open sepa_export_item
       if ( my $seis = $invoice->find_sepa_export_items({ executed => 0 }) ) {
         if ( scalar @$seis == 1 ) {
@@ -488,6 +493,17 @@ sub action_save_proposals {
         );
 
     SL::DB::RecordLink->new(@props)->save;
+
+    # code duplicated in action_save_invoices!
+    # "close" a sepa_export_item if it exists
+    # currently only works, if there is only exactly one open sepa_export_item
+    if ( my $seis = $arap->find_sepa_export_items({ executed => 0 }) ) {
+      if ( scalar @$seis == 1 ) {
+        # moved the execution and the check for sepa_export into a method,
+        # this isn't part of a transaction, though
+        $seis->[0]->set_executed if $arap->id == $seis->[0]->arap_id;
+      };
+    };
   }
 
   flash('ok', t8('#1 proposal(s) saved.', scalar @{ $::form->{proposal_ids} }));