From: Bernd Bleßmann Date: Fri, 11 Sep 2020 15:19:14 +0000 (+0200) Subject: SEPA-Überweisungen: Zahlungsbedingungen f. Skonto aus EK-Rechnungen übernehmen … X-Git-Tag: release-3.5.6.1~29 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a6a97a5fb2ea27466c69d6d4bd7472c9c12fec05;p=kivitendo-erp.git SEPA-Überweisungen: Zahlungsbedingungen f. Skonto aus EK-Rechnungen übernehmen … … und nicht aus den Lieferanten-Stammdaten. Hier könnte es im VK und EK noch eine Art fallback auf die Zahlungsbedingungen aus den Kunden-/Lieferanten-Stammdaten geben - so dass diese zusätzlich als Auswahl angeboten werden, sofern sie nicht in der Rechnung angegeben sind. Refs #444 (redmine) --- diff --git a/SL/DB/Helper/Payment.pm b/SL/DB/Helper/Payment.pm index dfc5b797f..a778e927f 100644 --- a/SL/DB/Helper/Payment.pm +++ b/SL/DB/Helper/Payment.pm @@ -338,21 +338,9 @@ sub skonto_date { my $self = shift; - my $is_sales = ref($self) eq 'SL::DB::Invoice'; - - my $skonto_date; - - if ( $is_sales ) { - return undef unless ref $self->payment_terms; - return undef unless $self->payment_terms->terms_skonto > 0; - $skonto_date = DateTime->from_object(object => $self->transdate)->add(days => $self->payment_terms->terms_skonto); - } else { - return undef unless ref $self->vendor->payment_terms; - return undef unless $self->vendor->payment_terms->terms_skonto > 0; - $skonto_date = DateTime->from_object(object => $self->transdate)->add(days => $self->vendor->payment_terms->terms_skonto); - }; - - return $skonto_date; + return undef unless ref $self->payment_terms; + return undef unless $self->payment_terms->terms_skonto > 0; + return DateTime->from_object(object => $self->transdate)->add(days => $self->payment_terms->terms_skonto); }; sub reference_account { @@ -442,19 +430,11 @@ sub remaining_skonto_days { sub percent_skonto { my $self = shift; - my $is_sales = ref($self) eq 'SL::DB::Invoice'; - my $percent_skonto = 0; - if ( $is_sales ) { - return undef unless ref $self->payment_terms; - return undef unless $self->payment_terms->percent_skonto > 0; - $percent_skonto = $self->payment_terms->percent_skonto; - } else { - return undef unless ref $self->vendor->payment_terms; - return undef unless $self->vendor->payment_terms->terms_skonto > 0; - $percent_skonto = $self->vendor->payment_terms->percent_skonto; - }; + return undef unless ref $self->payment_terms; + return undef unless $self->payment_terms->percent_skonto > 0; + $percent_skonto = $self->payment_terms->percent_skonto; return $percent_skonto; }; @@ -540,8 +520,7 @@ sub skonto_charts { # TODO: check whether there are negative values in invoice / acc_trans ... credited items # don't check whether skonto applies, because user may want to override this - # return undef unless $self->percent_skonto; # for is_sales - # return undef unless $self->vendor->payment_terms->percent_skonto; # for purchase + # return undef unless $self->percent_skonto; my $is_sales = ref($self) eq 'SL::DB::Invoice'; @@ -905,12 +884,11 @@ Example (1200 is the AR account for SKR04): =item C Returns the configured skonto percentage of the payment terms of an invoice, -e.g. 0.02 for 2%. Payment terms come from invoice settings for ar, from vendor -settings for ap. +e.g. 0.02 for 2%. Payment terms come from invoice settingssettings for ap. =item C -If the invoice has a payment term (via ar for sales, via vendor for purchase), +If the invoice has a payment term, calculate the amount to be paid in the case of skonto. This doesn't check, whether skonto applies (i.e. skonto doesn't wasn't exceeded), it just subtracts the configured percentage (e.g. 2%) from the total amount. diff --git a/SL/SEPA.pm b/SL/SEPA.pm index 373711d47..fc92bcf16 100644 --- a/SL/SEPA.pm +++ b/SL/SEPA.pm @@ -29,13 +29,6 @@ sub retrieve_open_invoices { my $mandate = $params{vc} eq 'customer' ? " AND COALESCE(vc.mandator_id, '') <> '' AND vc.mandate_date_of_signature IS NOT NULL " : ''; - # in query: for customers, use payment terms from invoice, for vendors use - # payment terms from vendor settings - # currently there is no option in vendor invoices for setting payment terms, - # so the vendor settings are always used - - my $payment_term_type = $params{vc} eq 'customer' ? "${arap}" : 'vc'; - # open_amount is not the current open amount according to bookkeeping, but # the open amount minus the SEPA transfer amounts that haven't been closed yet my $query = @@ -63,7 +56,7 @@ sub retrieve_open_invoices { GROUP BY sei.${arap}_id) AS open_transfers ON (${arap}.id = open_transfers.${arap}_id) - LEFT JOIN payment_terms pt ON (${payment_term_type}.payment_id = pt.id) + LEFT JOIN payment_terms pt ON (${arap}.payment_id = pt.id) WHERE ${arap}.amount > (COALESCE(open_transfers.amount, 0) + ${arap}.paid) @@ -591,7 +584,3 @@ Returns undef if the deletion was successfully. Otherwise the function just dies with a short notice of the id. =cut - - - - diff --git a/t/db_helper/payment.t b/t/db_helper/payment.t index f165b476a..89610d6df 100644 --- a/t/db_helper/payment.t +++ b/t/db_helper/payment.t @@ -763,6 +763,7 @@ sub test_default_ap_transaction_two_charts_19_7_with_skonto { # $params{amount} = '226'; # pass full amount $params{payment_type} = 'with_skonto_pt'; + $ap_transaction->payment_terms($ap_transaction->vendor->payment); $ap_transaction->pay_invoice( %params ); my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);