Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 69e03937

Von Jan Büren vor mehr als 5 Jahren hinzugefügt

  • ID 69e03937db84180c261015cedb3a97c01c017477
  • Vorgänger fca94606
  • Nachfolger 6c0095f1

Payment::pay_invoice um Zahlungsbedingung freies Skonto erweitert

POD angepasst. Falls der Zahlungstyp free_skonto und der Parameter
skonto_amount übergeben wird, so wird dieser anstelle von einem
berechneten Skonto-Betrag verbucht. Das Vorzeichen wird entsprechend
nur "durchgereicht" und der Parameter überlager simplerweise den
Wert total_skonto_amount beim Verbuchen der Skonto-AccTrans-Einträge

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
37 37
  $params{payment_type} = 'without_skonto' unless $params{payment_type};
38 38
  validate_payment_type($params{payment_type});
39 39

  
40
  # check for required parameters
40
  # check for required parameters and optional params depending on payment_type
41 41
  Common::check_params(\%params, qw(chart_id transdate));
42 42
  if ( $params{'payment_type'} eq 'without_skonto' && abs($params{'amount'}) < 0) {
43 43
    croak "invalid amount for payment_type 'without_skonto': $params{'amount'}\n";
44 44
  }
45

  
45
  if ($params{'payment_type'} eq 'free_skonto') {
46
    # we dont like too much automagic for this payment type.
47
    # we force caller input for amount and skonto amount
48
    Common::check_params(\%params, qw(amount skonto_amount));
49
    # secondly we dont want to handle credit notes and purchase credit notes
50
    croak("Cannot use 'free skonto' for credit or debit notes") if ($params{amount} <= 0 || $params{skonto_amount} <= 0);
51
    # both amount have to be rounded
52
    $params{skonto_amount} = _round($params{skonto_amount});
53
    $params{amount}        = _round($params{amount});
54
    # lastly skonto_amount has to be smaller than the open invoice amount or payment amount ;-)
55
    if ($params{skonto_amount} > abs($self->open_amount) || $params{skonto_amount} > $params{amount}) {
56
      croak("Skonto amount higher than the payment or invoice amount");
57
    }
58
  }
46 59

  
47 60
  my $transdate_obj;
48 61
  if (ref($params{transdate} eq 'DateTime')) {
......
130 143
    # taxkey 0
131 144

  
132 145
    unless ( $params{payment_type} eq 'difference_as_skonto' ) {
133
      # cases with_skonto_pt and without_skonto
146
      # cases with_skonto_pt, free_skonto and without_skonto
134 147

  
135 148
      # for case with_skonto_pt we need to know the corrected amount at this
136 149
      # stage if we are going to use $params{amount}
......
198 211
        }
199 212
      }
200 213
    }
201

  
202
    if ( $params{payment_type} eq 'difference_as_skonto' or $params{payment_type} eq 'with_skonto_pt' ) {
214
    # better everything except without_skonto
215
    if ($params{payment_type} eq 'difference_as_skonto' or $params{payment_type} eq 'with_skonto_pt'
216
        or $params{payment_type} eq 'free_skonto' ) {
203 217

  
204 218
      my $total_skonto_amount;
205 219
      if ( $params{payment_type} eq 'with_skonto_pt' ) {
206 220
        $total_skonto_amount = $self->skonto_amount;
207 221
      } elsif ( $params{payment_type} eq 'difference_as_skonto' ) {
208 222
        $total_skonto_amount = $self->open_amount;
209
      };
210

  
223
      } elsif ( $params{payment_type} eq 'free_skonto') {
224
        $total_skonto_amount = $params{skonto_amount};
225
      }
211 226
      my @skonto_bookings = $self->skonto_charts($total_skonto_amount);
212 227

  
213 228
      # error checking:
......
256 271
      # with_skonto_pt for completely unpaid invoices we just use the value
257 272
      # from the invoice
258 273
      $arap_amount = $total_open_amount;
274
    } elsif ( $params{payment_type} eq 'free_skonto' ) {
275
      # we forced positive values and forced rounding at the beginning
276
      # therefore the above comment can be safely applied for this payment type
277
      $arap_amount = $params{amount} + $params{skonto_amount};
259 278
    }
260 279

  
261 280
    # regardless of payment_type there is always only exactly one arap booking
......
636 655
    push(@options, { payment_type => 'without_skonto', display => t8('without skonto'), selected => 1 });
637 656
    # wrong call to presenter or not implemented? disabled option is ignored
638 657
    # push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), disabled => 1 });
658
    push(@options, { payment_type => 'free_skonto', display => t8('free skonto') });
639 659
    return @options;
640 660
  }
641 661
  # valid skonto date, check if skonto is preferred
......
647 667
    push(@options, { payment_type => 'without_skonto', display => t8('without skonto') , selected => 1 });
648 668
    push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt')});
649 669
  }
670
  push(@options, { payment_type => 'free_skonto', display => t8('free skonto') });
650 671
  return @options;
651 672
}
652 673

  
......
712 733
sub validate_payment_type {
713 734
  my $payment_type = shift;
714 735

  
715
  my %allowed_payment_types = map { $_ => 1 } qw(without_skonto with_skonto_pt difference_as_skonto);
736
  my %allowed_payment_types = map { $_ => 1 } qw(without_skonto with_skonto_pt difference_as_skonto free_skonto);
716 737
  croak "illegal payment type: $payment_type, must be one of: " . join(' ', keys %allowed_payment_types) unless $allowed_payment_types{ $payment_type };
717 738

  
718 739
  return 1;
......
762 783
The params C<transdate> and C<chart_id> are mandantory.
763 784
If the default payment ('without_skonto') is used the param amount is also
764 785
mandantory.
786
If the payment type ('free_skonto') is used the number param skonto_amount
787
is as well mandantory and has to be lower than the currently open invoice amount.
765 788

  
766 789
Transdate can either be a date object or a date string.
767 790
Chart_id is the id of the payment booking chart.

Auch abrufbar als: Unified diff