use strict;
+use List::Util qw(max);
+
use SL::DB::MetaSetup::PaymentTerm;
use SL::DB::Manager::PaymentTerm;
use SL::DB::Helper::ActsAsList;
my $reference_date = $params{reference_date} || DateTime->today_local;
$reference_date = DateTime->from_kivitendo($reference_date) unless ref($reference_date) eq 'DateTime';
+ if (!$self->auto_calculation) {
+ my $due_date = $params{due_date} || $reference_date;
+ $due_date = DateTime->from_kivitendo($due_date) unless ref($due_date) eq 'DateTime';
+
+ return max $due_date, $reference_date;
+ }
+
my $terms = ($params{terms} // 'net') eq 'discount' ? 'terms_skonto' : 'terms_netto';
my $date = $reference_date->add(days => $self->$terms);
=item C<calc_date [%params]>
Calculates and returns a due date as an instance of L<DateTime> by
-adding one of C<$self>'s terms fields. Note that the resulting date
-will be the following Monday if the result falls on a weekend.
+adding one of C<$self>'s terms fields if automatic calculation is on;
+otherwise returns the currently-set due date (which must be provided)
+or the reference date, whichever is later.
+
+Note that for automatic calculation the resulting date will be the
+following Monday if the result falls on a weekend.
C<%params> can contain the following parameters:
Defaults to the current date if unset.
+=item C<due_date>
+
+A currently set due date. If automatic calculation is off then this
+date will be returned if it is provided and greater than or equal to
+the C<reference_date>. Otherwise the reference date will be returned.
+
=item C<terms>
Can be either C<net> or C<discount>. For C<net> the number of days to