Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 34eac2fb

Von Jan Büren vor etwa 1 Jahr hinzugefügt

  • ID 34eac2fbbace8a9ff320a4ba1850e8853300f145
  • Vorgänger 1936b277
  • Nachfolger 5b062234

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>

Auch abrufbar als: Unified diff