Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e10fb8ac

Von Jan Büren vor etwa 1 Monat 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
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

  
t/db_helper/payment.t
1698 1698
  is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 1)), 1, "one day after invdate is skontoable");
1699 1699
  is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 4)), 1, "four days after invdate is skontoable");
1700 1700

  
1701
  throws_ok{
1702
    $invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 6));
1703
  } 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";
1701
  is($invoice2->within_skonto_period(transdate => DateTime->now()->add(days => 6)), ''); # not within skonto period
1704 1702

  
1705 1703
}
1706 1704

  

Auch abrufbar als: Unified diff