From aa8bfdd2331283841bb804a991b251ab5d72c0b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Fri, 22 Mar 2019 08:50:13 +0100 Subject: [PATCH] Bankverbuchungen: freies Skonto auch abziehen. Code-Vereinfachung (not_assigned) Vergessen, den freien Skonto-Betrag von invoice_amount abzuziehen. Not-Aus-Schalter in feeb3fc8352. Jetzt auch im Controller saubere Fehlermeldung ausgeben. --- SL/Controller/BankTransaction.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 638da64c9..a937451c4 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -570,7 +570,6 @@ sub save_single_bank_transaction { my $worker = sub { my $bt_id = $data{bank_transaction_id}; my $sign = $bank_transaction->amount < 0 ? -1 : 1; - my $not_assigned_amount = $bank_transaction->not_assigned_amount; my $payment_received = $bank_transaction->amount > 0; my $payment_sent = $bank_transaction->amount < 0; @@ -617,9 +616,8 @@ sub save_single_bank_transaction { my $memo = ($data{memos} // [])->[$n_invoices]; $n_invoices++ ; - - - if (!$not_assigned_amount && $invoice->open_amount) { + if ( ($payment_sent && $bank_transaction->not_assigned_amount >= 0) + || ($payment_received && $bank_transaction->not_assigned_amount <= 0)) { return { %data, result => 'error', @@ -654,10 +652,11 @@ sub save_single_bank_transaction { # should be better done elsewhere - changing not_assigned_amount to abs feels seriously bogus my $open_amount = $payment_type eq 'with_skonto_pt' ? $invoice->amount_less_skonto : $invoice->open_amount; - $open_amount = abs($open_amount); - $not_assigned_amount = abs($not_assigned_amount); - my $amount_for_booking = ($open_amount < $not_assigned_amount) ? $open_amount : $not_assigned_amount; - my $amount_for_payment = $amount_for_booking; + $open_amount = abs($open_amount); + $open_amount -= $free_skonto_amount if ($payment_type eq 'free_skonto'); + my $not_assigned_amount = abs($bank_transaction->not_assigned_amount); + my $amount_for_booking = ($open_amount < $not_assigned_amount) ? $open_amount : $not_assigned_amount; + my $amount_for_payment = $amount_for_booking; # get the right direction for the payment bookings (all amounts < 0 are stornos, credit notes or negative ap) $amount_for_payment *= -1 if $invoice->amount < 0; -- 2.20.1