Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 620b6457

Von Bernd Bleßmann vor fast 2 Jahren hinzugefügt

  • ID 620b645722df4c1d3636a9141ce423f21389e1d6
  • Vorgänger 3ed8f261
  • Nachfolger d5145a56

Umsatzstatistik-Chart: Lücken mit leeren Einträgen füllen

Unterschiede anzeigen:

SL/Controller/CustomerVendorTurnover.pm
120 120
  return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{id};
121 121

  
122 122
  my $sort_dir   = 'DESC';
123
  my $fill_holes = 0;
123 124

  
124 125
  if ($::request->type eq 'json') {
125 126
    $sort_dir   = 'ASC';
127
    $fill_holes = 1;
126 128
  }
127 129

  
128 130
  my $dbh = SL::DB->client->dbh;
......
159 161
SQL
160 162
  $self->{turnover_statistic} = selectall_hashref_query($::form, $dbh, $query, $cv);
161 163

  
164
  if ('month' eq $::form->{mode} && $fill_holes && @{$self->{turnover_statistic}} > 1) {
165
    my $date_part_to_months = sub { my ($m, $y) = $_[0] =~ m{^(\d{1,2})/(\d{1,4})$}; return $m + 12*$y; };
166
    my $months_to_date_part = sub { my $y = int($_[0]/12); my $m = $_[0] - 12*$y; $m ||= 12; return "$m/$y"; };
167
    my $start_month         = $date_part_to_months->($self->{turnover_statistic}[ 0]->{date_part});
168
    my $end_month           = $date_part_to_months->($self->{turnover_statistic}[-1]->{date_part});
169
    my $step                = ($start_month > $end_month) ? -1 : 1;
170
    my $next_month          = $start_month;
171
    my @new_stats           = ();
172
    foreach my $stat (@{$self->{turnover_statistic}}) {
173
      while ($date_part_to_months->($stat->{date_part}) != $next_month) {
174
        push @new_stats, {date_part => $months_to_date_part->($next_month)};
175
        $next_month += $step;
176
      }
177
      push @new_stats, $stat;
178
      $next_month += $step;
179
    }
180
    $self->{turnover_statistic} = \@new_stats;
181
  }
182

  
183
  if ('month' ne $::form->{mode} && $fill_holes && @{$self->{turnover_statistic}} > 1) {
184
    my $start          = $self->{turnover_statistic}[ 0]->{date_part};
185
    my $end            = $self->{turnover_statistic}[-1]->{date_part};
186
    my $step           = ($start > $end) ? -1 : 1;
187
    my $next_date_part = $start;
188
    my @new_stats = ();
189
    foreach my $stat (@{$self->{turnover_statistic}}) {
190
      while ($stat->{date_part} != $next_date_part) {
191
        push @new_stats, {date_part => $next_date_part};
192
        $next_date_part += $step;
193
      }
194
      push @new_stats, $stat;
195
      $next_date_part += $step;
196
    }
197
    $self->{turnover_statistic} = \@new_stats;
198
  }
199

  
162 200
  if ($::request->type eq 'json') {
163 201
    $self->render(\ SL::JSON::to_json($self->{turnover_statistic}), { layout => 0, type => 'json', process => 0 });
164 202
  } else {

Auch abrufbar als: Unified diff