Project

General

Profile

Revision a6a97a5f

Added by Bernd Bleßmann 7 months ago

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)

View differences:

SL/DB/Helper/Payment.pm
338 338

  
339 339
  my $self = shift;
340 340

  
341
  my $is_sales = ref($self) eq 'SL::DB::Invoice';
342

  
343
  my $skonto_date;
344

  
345
  if ( $is_sales ) {
346
    return undef unless ref $self->payment_terms;
347
    return undef unless $self->payment_terms->terms_skonto > 0;
348
    $skonto_date = DateTime->from_object(object => $self->transdate)->add(days => $self->payment_terms->terms_skonto);
349
  } else {
350
    return undef unless ref $self->vendor->payment_terms;
351
    return undef unless $self->vendor->payment_terms->terms_skonto > 0;
352
    $skonto_date = DateTime->from_object(object => $self->transdate)->add(days => $self->vendor->payment_terms->terms_skonto);
353
  };
354

  
355
  return $skonto_date;
341
  return undef unless ref $self->payment_terms;
342
  return undef unless $self->payment_terms->terms_skonto > 0;
343
  return DateTime->from_object(object => $self->transdate)->add(days => $self->payment_terms->terms_skonto);
356 344
};
357 345

  
358 346
sub reference_account {
......
442 430
sub percent_skonto {
443 431
  my $self = shift;
444 432

  
445
  my $is_sales = ref($self) eq 'SL::DB::Invoice';
446

  
447 433
  my $percent_skonto = 0;
448 434

  
449
  if ( $is_sales ) {
450
    return undef unless ref $self->payment_terms;
451
    return undef unless $self->payment_terms->percent_skonto > 0;
452
    $percent_skonto = $self->payment_terms->percent_skonto;
453
  } else {
454
    return undef unless ref $self->vendor->payment_terms;
455
    return undef unless $self->vendor->payment_terms->terms_skonto > 0;
456
    $percent_skonto = $self->vendor->payment_terms->percent_skonto;
457
  };
435
  return undef unless ref $self->payment_terms;
436
  return undef unless $self->payment_terms->percent_skonto > 0;
437
  $percent_skonto = $self->payment_terms->percent_skonto;
458 438

  
459 439
  return $percent_skonto;
460 440
};
......
540 520
  # TODO: check whether there are negative values in invoice / acc_trans ... credited items
541 521

  
542 522
  # don't check whether skonto applies, because user may want to override this
543
  # return undef unless $self->percent_skonto;  # for is_sales
544
  # return undef unless $self->vendor->payment_terms->percent_skonto;  # for purchase
523
  # return undef unless $self->percent_skonto;
545 524

  
546 525
  my $is_sales = ref($self) eq 'SL::DB::Invoice';
547 526

  
......
905 884
=item C<percent_skonto>
906 885

  
907 886
Returns the configured skonto percentage of the payment terms of an invoice,
908
e.g. 0.02 for 2%. Payment terms come from invoice settings for ar, from vendor
909
settings for ap.
887
e.g. 0.02 for 2%. Payment terms come from invoice settingssettings for ap.
910 888

  
911 889
=item C<amount_less_skonto>
912 890

  
913
If the invoice has a payment term (via ar for sales, via vendor for purchase),
891
If the invoice has a payment term,
914 892
calculate the amount to be paid in the case of skonto.  This doesn't check,
915 893
whether skonto applies (i.e. skonto doesn't wasn't exceeded), it just subtracts
916 894
the configured percentage (e.g. 2%) from the total amount.
SL/SEPA.pm
29 29

  
30 30
  my $mandate  = $params{vc} eq 'customer' ? " AND COALESCE(vc.mandator_id, '') <> '' AND vc.mandate_date_of_signature IS NOT NULL " : '';
31 31

  
32
  # in query: for customers, use payment terms from invoice, for vendors use
33
  # payment terms from vendor settings
34
  # currently there is no option in vendor invoices for setting payment terms,
35
  # so the vendor settings are always used
36

  
37
  my $payment_term_type = $params{vc} eq 'customer' ? "${arap}" : 'vc';
38

  
39 32
  # open_amount is not the current open amount according to bookkeeping, but
40 33
  # the open amount minus the SEPA transfer amounts that haven't been closed yet
41 34
  my $query =
......
63 56
                  GROUP BY sei.${arap}_id)
64 57
         AS open_transfers ON (${arap}.id = open_transfers.${arap}_id)
65 58

  
66
       LEFT JOIN payment_terms pt ON (${payment_term_type}.payment_id = pt.id)
59
       LEFT JOIN payment_terms pt ON (${arap}.payment_id = pt.id)
67 60

  
68 61
       WHERE ${arap}.amount > (COALESCE(open_transfers.amount, 0) + ${arap}.paid)
69 62

  
......
591 584
Otherwise the function just dies with a short notice of the id.
592 585

  
593 586
=cut
594

  
595

  
596

  
597

  
t/db_helper/payment.t
763 763
  # $params{amount} = '226'; # pass full amount
764 764
  $params{payment_type} = 'with_skonto_pt';
765 765

  
766
  $ap_transaction->payment_terms($ap_transaction->vendor->payment);
766 767
  $ap_transaction->pay_invoice( %params );
767 768

  
768 769
  my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);

Also available in: Unified diff