Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 27c7723d

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 27c7723d1415d794be692704fb6f8c3717025742
  • Vorgänger 80fa0349
  • Nachfolger 459b3c8d

Zeiterfassung: Konvertierung: Refoctored -> Fehlermeldungen

Unterschiede anzeigen:

SL/BackgroundJob/ConvertTimeRecordings.pm
100 100
    die "Not a valid parameter: $param" unless exists $valid_params{$param};
101 101
  }
102 102

  
103
  # set defaults
103 104
  $self->params(
104 105
    { map { ($_ => $data->{$_} // $valid_params{$_}) } keys %valid_params }
105 106
  );
......
168 169
      $do = SL::DB::DeliveryOrder->new_from_time_recordings($time_recordings_by_customer_id{$customer_id}, %convert_params);
169 170
      1;
170 171
    }) {
171
      $::lxdebug->message(LXDebug->WARN(),
172
                          "ConvertTimeRecordings: creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}});
173
      push @{ $self->{job_errors} }, "ConvertTimeRecordings: creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}};
174

  
172
      $self->log_error("creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}});
175 173
    }
176 174

  
177 175
    if ($do) {
......
180 178
        $_->update_attributes(booked => 1) for @{$time_recordings_by_customer_id{$customer_id}};
181 179
        1;
182 180
      })) {
183
        $::lxdebug->message(LXDebug->WARN(),
184
                            "ConvertTimeRecordings: saving delivery order failed for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}});
185
        push @{ $self->{job_errors} }, "ConvertTimeRecordings: saving delivery order failed for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}};
181
        $self->log_error('saving delivery order failed for time recording ids ' . join ', ', map { $_->id } @{$time_recordings_by_customer_id{$customer_id}});
186 182
      } else {
187 183
        push @donumbers, $do->donumber;
188 184
      }
......
208 204
      $do = SL::DB::DeliveryOrder->new_from_time_recordings($time_recordings_by_order_id->{$related_order_id}, related_order => $related_order, %convert_params);
209 205
      1;
210 206
    }) {
211
      $::lxdebug->message(LXDebug->WARN(),
212
                          "ConvertTimeRecordings: creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}});
213
      push @{ $self->{job_errors} }, "ConvertTimeRecordings: creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}};
207
      $self->log_error("creating delivery order failed ($@) for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}});
214 208
    }
215 209

  
216 210
    if ($do) {
......
244 238

  
245 239
        1;
246 240
      })) {
247
        $::lxdebug->message(LXDebug->WARN(),
248
                            "ConvertTimeRecordings: saving delivery order failed for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}});
249
        push @{ $self->{job_errors} }, "ConvertTimeRecordings: saving delivery order failed for time recording ids " . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}};
241
        $self->log_error('saving delivery order failed for time recording ids ' . join ', ', map { $_->id } @{$time_recordings_by_order_id->{$related_order_id}});
242

  
250 243
      } else {
251 244
        push @donumbers, $do->donumber;
252 245
      }
......
270 263
    #$project_id ||= $self->default_project_id;
271 264

  
272 265
    if (!$project_id) {
273
      my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : no project id';
274
      $::lxdebug->message(LXDebug->WARN(), $err_msg);
275
      push @{ $self->{job_errors} }, $err_msg;
266
      $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : no project id');
276 267
      return;
277 268
    }
278 269

  
279 270
    my $project = SL::DB::Project->load_cached($project_id);
280 271

  
281 272
    if (!$project) {
282
      my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : project not found';
283
      $::lxdebug->message(LXDebug->WARN(), $err_msg);
284
      push @{ $self->{job_errors} }, $err_msg;
273
      $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : project not found');
285 274
      return;
286 275
    }
287 276
    if (!$project->active || !$project->valid) {
288
      my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : project not active or not valid';
289
      $::lxdebug->message(LXDebug->WARN(), $err_msg);
290
      push @{ $self->{job_errors} }, $err_msg;
277
      $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : project not active or not valid');
291 278
      return;
292 279
    }
293 280
    if ($project->customer_id && $project->customer_id != $tr->customer_id) {
294
      my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : project customer does not match customer of time recording';
295
      $::lxdebug->message(LXDebug->WARN(), $err_msg);
296
      push @{ $self->{job_errors} }, $err_msg;
281
      $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : project customer does not match customer of time recording');
297 282
      return;
298 283
    }
299 284

  
......
309 294
  }
310 295

  
311 296
  if (!scalar @$orders) {
312
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : no order found';
313
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
314
    push @{ $self->{job_errors} }, $err_msg;
297
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : no order found');
315 298
    return;
316 299
  }
317 300

  
......
323 306
  $part_id ||= $self->params->{part_id};
324 307

  
325 308
  if (!$part_id) {
326
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : no part id';
327
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
328
    push @{ $self->{job_errors} }, $err_msg;
309
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : no part id');
329 310
    return;
330 311
  }
331 312
  my $part = SL::DB::Part->load_cached($part_id);
332 313
  if (!$part->unit_obj->is_time_based) {
333
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : part unit is not time based';
334
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
335
    push @{ $self->{job_errors} }, $err_msg;
314
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : part unit is not time based');
336 315
    return;
337 316
  }
338 317

  
......
344 323
  }
345 324

  
346 325
  if (1 != scalar @matching_orders) {
347
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : no or more than one orders do match';
348
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
349
    push @{ $self->{job_errors} }, $err_msg;
326
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : no or more than one orders do match');
350 327
    return;
351 328
  }
352 329

  
353 330
  my $matching_order = $matching_orders[0];
354 331

  
355 332
  if (!$matching_order->is_sales) {
356
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : found order is not a sales order';
357
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
358
    push @{ $self->{job_errors} }, $err_msg;
333
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : found order is not a sales order');
359 334
    return;
360 335
  }
361 336

  
362 337
  if ($matching_order->customer_id != $tr->customer_id) {
363
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : customer of order does not match customer of time recording';
364
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
365
    push @{ $self->{job_errors} }, $err_msg;
338
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : customer of order does not match customer of time recording');
366 339
    return;
367 340
  }
368 341

  
369 342
  if ($tr->project_id && $tr->project_id != ($matching_order->globalproject_id || 0)) {
370
    my $err_msg = 'ConvertTimeRecordings: searching related order failed for time recording id ' . $tr->id . ' : project of order does not match project of time recording';
371
    $::lxdebug->message(LXDebug->WARN(), $err_msg);
372
    push @{ $self->{job_errors} }, $err_msg;
343
    $self->log_error('searching related order failed for time recording id ' . $tr->id . ' : project of order does not match project of time recording');
373 344
    return;
374 345
  }
375 346

  
376 347
  return $matching_order;
377 348
}
378 349

  
350
sub log_error {
351
  my ($self, $msg) = @_;
352

  
353
  my $dbg = 0;
354

  
355
  push @{ $self->{job_errors} }, $msg;
356
  $::lxdebug->message(LXDebug->WARN(), 'ConvertTimeRecordings: ' . $msg) if $dbg;
357
}
358

  
379 359
1;
380 360

  
381 361
# possible data

Auch abrufbar als: Unified diff