From: G. Richardson Date: Thu, 21 Jul 2016 12:30:40 +0000 (+0200) Subject: Controller BankTransaction - Einrückungen und Kommentare X-Git-Tag: release-3.5.4~2182 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=75063bf3a632f9d54e2f200cd659724432e0ef82;p=kivitendo-erp.git Controller BankTransaction - Einrückungen und Kommentare --- diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 63fc7499b..cb964f467 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -357,25 +357,44 @@ sub action_save_invoices { my ($self) = @_; my $invoice_hash = delete $::form->{invoice_ids}; # each key (the bt line with a bt_id) contains an array of invoice_ids + + # e.g. three partial payments with bt_ids 54, 55 and 56 for invoice with id 74: + # $invoice_hash = { + # '55' => [ + # '74' + # ], + # '54' => [ + # '74' + # ], + # '56' => [ + # '74' + # ] + # }; + # + # or if the payment with bt_id 44 is used to pay invoices with ids 50, 51 and 52 + # $invoice_hash = { + # '44' => [ '50', '51', 52' ] + # }; + my $skonto_hash = delete $::form->{invoice_skontos} || {}; # array containing the payment type, could be empty # a bank_transaction may be assigned to several invoices, i.e. a customer # might pay several open invoices with one transaction while ( my ($bt_id, $invoice_ids) = each(%$invoice_hash) ) { - my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id); - my $sign = $bank_transaction->amount < 0 ? -1 : 1; + my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id); + my $sign = $bank_transaction->amount < 0 ? -1 : 1; my $amount_of_transaction = $sign * $bank_transaction->amount; my @invoices; foreach my $invoice_id (@{ $invoice_ids }) { push @invoices, (SL::DB::Manager::Invoice->find_by(id => $invoice_id) || SL::DB::Manager::PurchaseInvoice->find_by(id => $invoice_id)); } - @invoices = sort { return 1 if ($a->is_sales and $a->amount > 0); + @invoices = sort { return 1 if ( $a->is_sales and $a->amount > 0); return 1 if (!$a->is_sales and $a->amount < 0); return -1; } @invoices if $bank_transaction->amount > 0; - @invoices = sort { return -1 if ($a->is_sales and $a->amount > 0); + @invoices = sort { return -1 if ( $a->is_sales and $a->amount > 0); return -1 if (!$a->is_sales and $a->amount < 0); return 1; } @invoices if $bank_transaction->amount < 0; @@ -420,7 +439,7 @@ sub action_save_invoices { amount => $invoice->open_amount, payment_type => $payment_type, transdate => $bank_transaction->transdate->to_kivitendo); - } else { + } else { # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id, trans_id => $invoice->id, amount => $amount_of_transaction,