Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4a1385db

Von Tamino Steinert vor 24 Tagen hinzugefügt

  • ID 4a1385db1366f4fd266abc3741c28f53428362fc
  • Vorgänger e98cf5de
  • Nachfolger 47326326

FIX: S:D:PeriodicInvoiceConfig: Positionen nicht im voraus berechnen

Unterschiede anzeigen:

SL/DB/PeriodicInvoicesConfig.pm
80 80

  
81 81
  my $item_config = $item->periodic_invoice_items_config;
82 82
  if ($item_config) {
83
    return if $item_config->periodicity eq 'n';
84
    if ($item_config->periodicity eq 'o') {
85
      return if $item->periodic_invoice_items_config->once_invoice_id;
86
      my $next_period_start_date = $self->get_next_period_start_date(order_item => $item);
87
      my $period = $self->get_billing_period_length || 1;
88
      return if $period_start_date < $next_period_start_date
89
        || $period_start_date >= add_months($next_period_start_date, $period);
90
    }
91
    if ($item_config->terminated || !$item_config->extend_automatically_by) {
92
      return if $item_config->end_date && $item_config->end_date < $period_start_date;
93
    }
83

  
84
    return if $item_config->start_date && $item_config->start_date > $period_start_date;
94 85

  
95 86
    my $i_period = $item_config->get_item_period_length;
96 87
    my $b_period = $self->get_billing_period_length;
97
    return $new_item if $i_period == 0 || $b_period == 0;
98 88

  
99
    if ($i_period > $b_period) {
100
      return if $item_config->start_date && $item_config->start_date > $period_start_date;
89
    return if $item_config->periodicity eq 'n';
90
    if ($item_config->periodicity eq 'o') {
91
      return if $item_config->once_invoice_id;
92
      my $start_date = $item_config->start_date
93
        || $self->get_previous_billed_period_start_date
94
        || $self->first_billing_date || $self->start_date;
95
      my @dates = $self->calculate_invoice_dates(
96
        start_date => $start_date,
97
        end_date => add_months($start_date, $b_period),
98
      );
99
      my $once_date = scalar @dates ? $dates[0] : undef;
100
      return if $period_start_date != $once_date;
101
      return $new_item;
102
    } elsif ($i_period > $b_period) {
103
      if ($item_config->terminated || !$item_config->extend_automatically_by) {
104
        return if $item_config->end_date && $item_config->end_date < $period_start_date;
105
      }
101 106
      my $start_date = $item_config->start_date
102 107
        || $self->first_billing_date || $self->start_date;
103 108
      my $months_from_start_date =
104 109
          ($period_start_date->year  - $start_date->year) * 12
105 110
        + ($period_start_date->month - $start_date->month);
111
      $months_from_start_date-- if $start_date->day > $period_start_date->day;
106 112
      my $first_in_sub_period = $months_from_start_date % ($i_period / $b_period) == 0 ? 1 : 0;
107 113
      return if !$first_in_sub_period;
108
    } elsif ($i_period < $b_period) {
109
      my $periods = 0;
114
    } elsif ($i_period < $b_period) { # calc items period in last billing period
110 115
      my $max_periods = $b_period / $i_period;
111
      my $periods_from_start = 0;
112
      my $i_start_date = $period_start_date;
116
      my $periods = $max_periods;
113 117
      if ($item_config->start_date) {
114
        while ($i_start_date < $item_config->start_date) {
115
          $periods_from_start++;
116
          $i_start_date = add_months($period_start_date, $periods_from_start);
117
        }
118
        $periods-- while $periods > 0
119
          && add_months($period_start_date, -1 * ($periods - 1) * $i_period) < $item_config->start_date;
118 120
      }
119
      if ($item_config->end_date
120
        && ($item_config->terminated || !$item_config->extend_automatically_by)) {
121
        $periods++ while $periods < ($max_periods - $periods_from_start)
122
          && add_months($i_start_date, $periods * $i_period) <= $item_config->end_date;
123
        return if $periods == 0;
124
      } else {
125
        $periods = $max_periods - $periods_from_start;
121
      if ($item_config->end_date) {
122
        my $periods_from_end = 0;
123
        $periods_from_end++ while $periods_from_end < $periods
124
          && add_months($period_start_date, -1 * ($periods_from_end)) > $item_config->end_date;
125
        $periods -= $periods_from_end;
126 126
      }
127
      return if $periods == 0;
127 128
      $new_item->qty($new_item->qty * $periods);
128 129
    }
129 130
  }
......
234 235
  return @start_dates;
235 236
}
236 237

  
237
sub get_next_period_start_date {
238
  my $self = shift;
239

  
240
  my %params = validate(@_, {
241
    order_item => { isa => 'SL::DB::OrderItem' },
242
  });
243

  
244
  my $item = $params{order_item};
245

  
246
  my $last_created_on_date = $self->get_previous_billed_period_start_date;
247

  
248
  return (
249
      $item->periodic_invoice_items_config ?
250
        $item->periodic_invoice_items_config->start_date
251
      : undef
252
    )
253
    || $self->first_billing_date || $self->start_date unless $last_created_on_date;
254

  
255
  my $billing_len = $item->periodic_invoice_items_config ?
256
      $item->periodic_invoice_items_config->get_item_period_length
257
    : $self->get_billing_period_length;
258

  
259

  
260
  my @dates = $self->calculate_invoice_dates(
261
    end_date => add_months($last_created_on_date, $billing_len)
262
  );
263

  
264
  return scalar @dates ? $dates[0] : undef;
265
}
266

  
267 238
sub get_billing_period_length {
268 239
  my $self = shift;
269 240
  return $PERIOD_LENGTHS{ $self->periodicity };

Auch abrufbar als: Unified diff