Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e10fb8ac

Von Jan Büren vor 11 Monaten hinzugefügt

  • ID e10fb8ac38aa7fc58e041b2d8a4f2a7607399d5f
  • Vorgänger 6e4892b3
  • Nachfolger 9f93f10d

PH->within_skonto_period refactored. Liefert jetzt undef oder 1 zurück

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
sub open_amount_fx {
validate_pos(
@_,
{ can => [ qw(forex get_exchangerate) ],
{ can => [ qw(forex get_exchangerate open_amount) ],
callbacks => { 'has forex' => sub { return $_[0]->forex },
'has exchangerate' => sub { return $_[0]->get_exchangerate > 0 } } },
{ callbacks => {
......
isa => 'DateTime',
callbacks => {
'self has a skonto date' => sub { ref $self->skonto_date eq 'DateTime' },
'is within skonto period' => sub { return shift() <= $self->skonto_date },
},
},
}
);
# then return true
return 1;
# return 1 if requested date (or today) is inside skonto period
# this will also return 1 if date is before the invoice date
my (%params) = @_;
return $params{transdate} <= $self->skonto_date;
}
sub valid_skonto_amount {
......
my $bt = SL::DB::BankTransaction->new(id => $bt_id)->load;
croak "No Bank Transaction with ID $bt_id found" unless ref $bt eq 'SL::DB::BankTransaction';
if (eval { $self->within_skonto_period(transdate => $bt->transdate); 1; } ) {
if (ref $self->skonto_date eq 'DateTime' && $self->within_skonto_period(transdate => $bt->transdate)) {
push(@options, { payment_type => 'without_skonto', display => t8('without skonto') });
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), selected => 1 });
push(@options, { payment_type => 'with_fuzzy_skonto_pt', display => t8('with fuzzy skonto acc. to pt')});
......
=item C<within_skonto_period [transdate =E<gt> DateTime]>
Returns 1 if skonto_date is in a skontoable period.
Needs the mandatory named param 'transdate' as a 'DateTime', usually a bank
transaction date for imported bank data.
Returns 1 if skonto_date is in a skontoable period otherwise undef.
Expects transdate to be set and to be a DateTime object.
Expects calling object to be a Invoice object with a skonto_date set.
Throws a error if any of the two mandantory conditions are not met.
If the conditions are met the routine simply checks if the param transdate
is within the max allowed date of the invoices skonto date.
Example usage:
Checks if the invoice has skontoable payment terms configured and whether the date
is within the skonto max date.
my $inv = SL::DB::Invoice->new;
my $bt = SL::DB::BankTransaction->new;
If one of the condition fails, a hopefully helpful error message is returned.
my $payment_date_is_skontoable =
(ref $inv->skonto_date eq 'DateTime' && $inv->within_skonto_period(transdate => $bt->transdate));
=item C<valid_skonto_amount>
t/db_helper/payment.t
is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 1)), 1, "one day after invdate is skontoable");
is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 4)), 1, "four days after invdate is skontoable");
throws_ok{
$invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 6));
} qr /The 'transdate' parameter .* to SL::DB::Helper::Payment::within_skonto_period did not pass the 'is within skonto period' callback/, "One day after skonto date throws correct error message";
is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 6)), ''); # not within skonto period
}

Auch abrufbar als: Unified diff