Revision 34eac2fb
SL/DB/Helper/Payment.pm | ||
---|---|---|
439 | 439 |
sub open_amount_fx { |
440 | 440 |
validate_pos( |
441 | 441 |
@_, |
442 |
{ can => [ qw(forex get_exchangerate) ], |
|
442 |
{ can => [ qw(forex get_exchangerate open_amount) ],
|
|
443 | 443 |
callbacks => { 'has forex' => sub { return $_[0]->forex }, |
444 | 444 |
'has exchangerate' => sub { return $_[0]->get_exchangerate > 0 } } }, |
445 | 445 |
{ callbacks => { |
... | ... | |
714 | 714 |
isa => 'DateTime', |
715 | 715 |
callbacks => { |
716 | 716 |
'self has a skonto date' => sub { ref $self->skonto_date eq 'DateTime' }, |
717 |
'is within skonto period' => sub { return shift() <= $self->skonto_date }, |
|
718 | 717 |
}, |
719 | 718 |
}, |
720 | 719 |
} |
721 | 720 |
); |
722 | 721 |
# then return true |
723 |
return 1; |
|
722 |
|
|
723 |
# return 1 if requested date (or today) is inside skonto period |
|
724 |
# this will also return 1 if date is before the invoice date |
|
725 |
my (%params) = @_; |
|
726 |
return $params{transdate} <= $self->skonto_date; |
|
724 | 727 |
} |
725 | 728 |
|
726 | 729 |
sub valid_skonto_amount { |
... | ... | |
758 | 761 |
my $bt = SL::DB::BankTransaction->new(id => $bt_id)->load; |
759 | 762 |
croak "No Bank Transaction with ID $bt_id found" unless ref $bt eq 'SL::DB::BankTransaction'; |
760 | 763 |
|
761 |
if (eval { $self->within_skonto_period(transdate => $bt->transdate); 1; } ) {
|
|
764 |
if (ref $self->skonto_date eq 'DateTime' && $self->within_skonto_period(transdate => $bt->transdate)) {
|
|
762 | 765 |
push(@options, { payment_type => 'without_skonto', display => t8('without skonto') }); |
763 | 766 |
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), selected => 1 }); |
764 | 767 |
push(@options, { payment_type => 'with_fuzzy_skonto_pt', display => t8('with fuzzy skonto acc. to pt')}); |
... | ... | |
1017 | 1020 |
|
1018 | 1021 |
=item C<within_skonto_period [transdate =E<gt> DateTime]> |
1019 | 1022 |
|
1020 |
Returns 1 if skonto_date is in a skontoable period. |
|
1021 |
Needs the mandatory named param 'transdate' as a 'DateTime', usually a bank |
|
1022 |
transaction date for imported bank data. |
|
1023 |
Returns 1 if skonto_date is in a skontoable period otherwise undef. |
|
1024 |
|
|
1025 |
|
|
1026 |
Expects transdate to be set and to be a DateTime object. |
|
1027 |
Expects calling object to be a Invoice object with a skonto_date set. |
|
1028 |
|
|
1029 |
Throws a error if any of the two mandantory conditions are not met. |
|
1030 |
|
|
1031 |
If the conditions are met the routine simply checks if the param transdate |
|
1032 |
is within the max allowed date of the invoices skonto date. |
|
1033 |
|
|
1034 |
Example usage: |
|
1023 | 1035 |
|
1024 |
Checks if the invoice has skontoable payment terms configured and whether the date
|
|
1025 |
is within the skonto max date.
|
|
1036 |
my $inv = SL::DB::Invoice->new;
|
|
1037 |
my $bt = SL::DB::BankTransaction->new;
|
|
1026 | 1038 |
|
1027 |
If one of the condition fails, a hopefully helpful error message is returned. |
|
1039 |
my $payment_date_is_skontoable = |
|
1040 |
(ref $inv->skonto_date eq 'DateTime' && $inv->within_skonto_period(transdate => $bt->transdate)); |
|
1028 | 1041 |
|
1029 | 1042 |
=item C<valid_skonto_amount> |
1030 | 1043 |
|
Auch abrufbar als: Unified diff
PH->within_skonto_period refactored. Liefert jetzt undef oder 1 zurück