From: Jan Büren Date: Mon, 16 Jul 2018 10:31:51 +0000 (+0200) Subject: behebt #356 Bei Zuweisung von zwei Kreditorengutschrift per Kontoauszug verbuchen... X-Git-Tag: release-3.5.4~355 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ace13a46b4c48674267d176c3c641930a444d48b;p=kivitendo-erp.git behebt #356 Bei Zuweisung von zwei Kreditorengutschrift per Kontoauszug verbuchen fehlerhaft Programmkorrektur für Testfall #b75c6cbb82023b0d6 --- diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index dd36fce2e..3d98e9fec 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -655,22 +655,21 @@ sub save_single_bank_transaction { memo => $memo, transdate => $bank_transaction->transdate->to_kivitendo); } else { - # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary - - # this catches credit_notes and negative sales invoices - if ( $invoice->is_sales && $invoice->amount < 0 ) { - # $invoice->open_amount is negative for credit_notes - # $bank_transaction->amount is negative for outgoing transactions - # so $amount_of_transaction is negative but needs positive - $amount_of_transaction *= -1; - - } elsif (!$invoice->is_sales && $invoice->invoice_type =~ m/ap_transaction|purchase_invoice/) { - # $invoice->open_amount may be negative for ap_transaction but may be positiv for negativ ap_transaction - # if $invoice->open_amount is negative $bank_transaction->amount is positve - # if $invoice->open_amount is positive $bank_transaction->amount is negative - # but amount of transaction is for both positive - $amount_of_transaction *= -1 if $invoice->open_amount == - $amount_of_transaction; - } + # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary + + # $invoice->open_amount is negative for credit_notes + # $bank_transaction->amount is negative for outgoing transactions + # so $amount_of_transaction is negative but needs positive + # $invoice->open_amount may be negative for ap_transaction but may be positiv for negative ap_transaction + # if $invoice->open_amount is negative $bank_transaction->amount is positve + # if $invoice->open_amount is positive $bank_transaction->amount is negative + # but amount of transaction is for both positive + + $amount_of_transaction *= -1 if ($invoice->amount < 0); + + # if we have a skonto case - the last invoice needs skonto + $amount_of_transaction = $invoice->amount_less_skonto if ($payment_type eq 'with_skonto_pt'); + my $overpaid_amount = $amount_of_transaction - $invoice->open_amount; $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id,