Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 78117a92

Von Jan Büren vor etwa 2 Jahren hinzugefügt

  • ID 78117a92625aa3900aaa8164e3a37c8075504b06
  • Vorgänger 07cd18f5
  • Nachfolger fd9eb2e3

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
);
......
484 484
  };
485 485

  
486 486
  return $skonto_configured;
487
};
488

  
489
sub open_sepa_transfer_amount {
490
  my $self = shift;
491
#  die "was buggy for ar and not really in use at all";
492
  my ($vc, $key, $type);
493
  if ( ref($self) eq 'SL::DB::Invoice' ) {
494
    $vc   = 'customer';
495
    $key  = 'ar_id';  # BUGGY ar_id
496
    $type = 'ar';
497
  } else {
498
    $vc   = 'vendor';
499
    $key  = 'ap_id';
500
    $type = 'ap';
501
  };
502

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

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

  
509
  return $open_sepa_amount || 0;
510

  
511 487
}
512 488

  
513 489
sub _skonto_charts_and_tax_correction {
......
696 672
  return undef unless $rate;
697 673

  
698 674
  return $self->is_sales ? $rate->buy : $rate->sell; # also undef if not defined
699
};
700

  
701
sub get_payment_suggestions {
702

  
703
  my ($self, %params) = @_;
704

  
705
  my $open_amount = $self->open_amount;
706
  $open_amount   -= $self->open_sepa_transfer_amount if $params{sepa};
707

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

  
743 677
# locales for payment type
744 678
#

Auch abrufbar als: Unified diff