Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2cbf256e

Von Jan Büren vor mehr als 1 Jahr hinzugefügt

  • ID 2cbf256e06497dc41b9c0023afabc07dc6c4e6e8
  • Vorgänger a791952b
  • Nachfolger f8ea96a8

Payment-Helper: subtilen toten Code entfernt

Aufruf über SEPA.pm war 'eigentlich' schon immer überflüssig

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
4 4

  
5 5
use parent qw(Exporter);
6 6
our @EXPORT = qw(pay_invoice);
7
our @EXPORT_OK = qw(skonto_date amount_less_skonto within_skonto_period percent_skonto reference_account open_amount skonto_amount check_skonto_configuration valid_skonto_amount get_payment_suggestions validate_payment_type open_sepa_transfer_amount get_payment_select_options_for_bank_transaction exchangerate forex _skonto_charts_and_tax_correction);
7
our @EXPORT_OK = qw(skonto_date amount_less_skonto within_skonto_period percent_skonto reference_account open_amount skonto_amount check_skonto_configuration valid_skonto_amount validate_payment_type get_payment_select_options_for_bank_transaction exchangerate forex _skonto_charts_and_tax_correction);
8 8
our %EXPORT_TAGS = (
9 9
  "ALL" => [@EXPORT, @EXPORT_OK],
10 10
);
......
492 492
  };
493 493

  
494 494
  return $skonto_configured;
495
};
496

  
497
sub open_sepa_transfer_amount {
498
  my $self = shift;
499
#  die "was buggy for ar and not really in use at all";
500
  my ($vc, $key, $type);
501
  if ( ref($self) eq 'SL::DB::Invoice' ) {
502
    $vc   = 'customer';
503
    $key  = 'ar_id';  # BUGGY ar_id
504
    $type = 'ar';
505
  } else {
506
    $vc   = 'vendor';
507
    $key  = 'ap_id';
508
    $type = 'ap';
509
  };
510

  
511
  my $sql = qq|SELECT SUM(sei.amount) AS amount FROM sepa_export_items sei | .
512
            qq| LEFT JOIN sepa_export se ON (sei.sepa_export_id = se.id)   | .
513
            qq| WHERE $key = ? AND NOT se.closed AND (se.vc = '$vc')       |;
514

  
515
  my ($open_sepa_amount) = $self->db->dbh->selectrow_array($sql, undef, $self->id);
516

  
517
  return $open_sepa_amount || 0;
518

  
519 495
}
520 496

  
521 497
sub _skonto_charts_and_tax_correction {
......
704 680
  return undef unless $rate;
705 681

  
706 682
  return $self->is_sales ? $rate->buy : $rate->sell; # also undef if not defined
707
};
708

  
709
sub get_payment_suggestions {
710

  
711
  my ($self, %params) = @_;
712

  
713
  my $open_amount = $self->open_amount;
714
  $open_amount   -= $self->open_sepa_transfer_amount if $params{sepa};
715

  
716
  $self->{invoice_amount_suggestion} = $open_amount;
717
  undef $self->{payment_select_options};
718
  push(@{$self->{payment_select_options}} , { payment_type => 'without_skonto',  display => t8('without skonto') });
719
  if ( $self->within_skonto_period ) {
720
    # If there have been no payments yet suggest amount_less_skonto, otherwise the open amount
721
    if ( $open_amount &&                   # invoice amount not 0
722
         $open_amount == $self->amount &&  # no payments yet, or sum of payments and sepa export amounts is zero
723
         $self->check_skonto_configuration) {
724
      $self->{invoice_amount_suggestion} = $self->amount_less_skonto;
725
      push(@{$self->{payment_select_options}} , { payment_type => 'with_skonto_pt',  display => t8('with skonto acc. to pt') , selected => 1 });
726
    } else {
727
      if ( ( $self->valid_skonto_amount($self->open_amount) || $self->valid_skonto_amount($open_amount) ) and not $params{sepa} ) {
728
        # Will never be reached
729
        die "This case is as dead as the dead cat. Go to start, don't pick 2,000 \$";
730
        $self->{invoice_amount_suggestion} = $open_amount;
731
        # only suggest difference_as_skonto if open_amount exactly matches skonto_amount
732
        # AND we aren't in SEPA mode
733
        my $selected = 0;
734
        $selected = 1 if _round($open_amount) == _round($self->skonto_amount);
735
        push(@{$self->{payment_select_options}} , { payment_type => 'difference_as_skonto',  display => t8('difference as skonto') , selected => $selected });
736
      };
737
    };
738
  } else {
739
    # invoice was configured with skonto, but skonto date has passed, or no skonto available
740
    $self->{invoice_amount_suggestion} = $open_amount;
741
    # difference_as_skonto doesn't make any sense for SEPA transfer, as this doesn't cause any actual payment
742
    if ( $self->valid_skonto_amount($self->open_amount) && not $params{sepa} ) {
743
      # probably also dead code
744
      die "This case is as dead as the dead cat. Go to start, don't pick 2,000 \$";
745
      push(@{$self->{payment_select_options}} , { payment_type => 'difference_as_skonto',  display => t8('difference as skonto') , selected => 0 });
746
    };
747
  };
748
  return 1;
749
};
683
}
750 684

  
751 685
# locales for payment type
752 686
#

Auch abrufbar als: Unified diff