Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 865972a5

Von Bernd Bleßmann vor etwa 11 Jahren hinzugefügt

  • ID 865972a5b6e87408474ae159ac7e3f7f6d6e43bd
  • Vorgänger ec3aabf0
  • Nachfolger 21187f8b

handle_order und handle_item aus check_objects ausgelagert

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
237 237

  
238 238
  $self->controller->track_progress(phase => 'building data', progress => 0);
239 239

  
240
  my $i;
240
  my $i = 0;
241 241
  my $num_data = scalar @{ $self->controller->data };
242 242
  foreach my $entry (@{ $self->controller->data }) {
243 243
    $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0;
244 244

  
245 245
    if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
246

  
247
      my $vc_obj;
248
      if (any { $entry->{raw_data}->{$_} } qw(customer customernumber customer_id)) {
249
        $self->check_vc($entry, 'customer_id');
250
        $vc_obj = SL::DB::Customer->new(id => $entry->{object}->customer_id)->load if $entry->{object}->customer_id;
251
      } elsif (any { $entry->{raw_data}->{$_} } qw(vendor vendornumber vendor_id)) {
252
        $self->check_vc($entry, 'vendor_id');
253
        $vc_obj = SL::DB::Vendor->new(id => $entry->{object}->vendor_id)->load if $entry->{object}->vendor_id;
254
      } else {
255
        push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor missing');
256
      }
257

  
258
      $self->check_contact($entry);
259
      $self->check_language($entry);
260
      $self->check_payment($entry);
261
      $self->check_department($entry);
262
      $self->check_project($entry, global => 1);
263
      $self->check_ct_shipto($entry);
264
      $self->check_taxzone($entry);
265
      $self->check_currency($entry);
266

  
267
      if ($vc_obj) {
268
        # copy from customer if not given
269
        foreach (qw(payment_id language_id taxzone_id currency_id)) {
270
          $entry->{object}->$_($vc_obj->$_) unless $entry->{object}->$_;
271
        }
272
      }
273

  
274
      # ToDo: salesman and emloyee by name
275
      # salesman from customer or login if not given
276
      if (!$entry->{object}->salesman) {
277
        if ($vc_obj && $vc_obj->salesman_id) {
278
          $entry->{object}->salesman(SL::DB::Manager::Employee->find_by(id => $vc_obj->salesman_id));
279
        } else {
280
          $entry->{object}->salesman(SL::DB::Manager::Employee->find_by(login => $::myconfig{login}));
281
        }
282
      }
283

  
284
      # employee from login if not given
285
      if (!$entry->{object}->employee_id) {
286
        $entry->{object}->employee_id(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})->id);
287
      }
288

  
246
      $self->handle_order($entry);
289 247
    }
290 248
  } continue {
291 249
    $i++;
......
301 259

  
302 260
  foreach my $entry (@{ $self->controller->data }) {
303 261
    if ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) {
304

  
305
      next if !$self->check_part($entry);
306

  
307
      my $part_obj = SL::DB::Part->new(id => $entry->{object}->parts_id)->load;
308

  
309
      # copy from part if not given
310
      $entry->{object}->description($part_obj->description) unless $entry->{object}->description;
311
      $entry->{object}->longdescription($part_obj->notes)   unless $entry->{object}->longdescription;
312
      $entry->{object}->unit($part_obj->unit)               unless $entry->{object}->unit;
313

  
314
      # set to 0 if not given
315
      $entry->{object}->discount(0)      unless $entry->{object}->discount;
316
      $entry->{object}->ship(0)          unless $entry->{object}->ship;
317

  
318
      $self->check_project($entry, global => 0);
319
      $self->check_price_factor($entry);
320
      $self->check_pricegroup($entry);
262
      $self->handle_item($entry);
321 263
    }
322 264
  }
323 265

  
......
422 364

  
423 365
}
424 366

  
367
sub handle_order {
368
  my ($self, $entry) = @_;
369

  
370
  my $object = $entry->{object};
371

  
372
  my $vc_obj;
373
  if (any { $entry->{raw_data}->{$_} } qw(customer customernumber customer_id)) {
374
    $self->check_vc($entry, 'customer_id');
375
    $vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->customer_id;
376
  } elsif (any { $entry->{raw_data}->{$_} } qw(vendor vendornumber vendor_id)) {
377
    $self->check_vc($entry, 'vendor_id');
378
    $vc_obj = SL::DB::Vendor->new(id => $object->vendor_id)->load if $object->vendor_id;
379
  } else {
380
    push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor missing');
381
  }
382

  
383
  $self->check_contact($entry);
384
  $self->check_language($entry);
385
  $self->check_payment($entry);
386
  $self->check_department($entry);
387
  $self->check_project($entry, global => 1);
388
  $self->check_ct_shipto($entry);
389
  $self->check_taxzone($entry);
390
  $self->check_currency($entry);
391

  
392
  if ($vc_obj) {
393
    # copy from customer if not given
394
    foreach (qw(payment_id language_id taxzone_id currency_id)) {
395
      $object->$_($vc_obj->$_) unless $object->$_;
396
    }
397
  }
398

  
399
  $self->handle_salesman($entry);
400
  $self->handle_employee($entry);
401
}
402

  
403
# ToDo: salesman by name
404
sub handle_salesman {
405
  my ($self, $entry) = @_;
406

  
407
  my $object = $entry->{object};
408
  my $vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->customer_id;
409
  $vc_obj    = SL::DB::Vendor->new(id   => $object->vendor_id)->load   if (!$vc_obj && $object->vendor_id);
410

  
411
  # salesman from customer/vendor or login if not given
412
  if (!$object->salesman) {
413
    if ($vc_obj && $vc_obj->salesman_id) {
414
      $object->salesman(SL::DB::Manager::Employee->find_by(id => $vc_obj->salesman_id));
415
    } else {
416
      $object->salesman(SL::DB::Manager::Employee->find_by(login => $::myconfig{login}));
417
    }
418
  }
419
}
420

  
421
# ToDo: employee by name
422
sub handle_employee {
423
  my ($self, $entry) = @_;
424

  
425
  my $object = $entry->{object};
426

  
427
  # employee from login if not given
428
  if (!$object->employee_id) {
429
    $object->employee_id(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})->id);
430
  }
431
}
425 432

  
426 433
sub check_language {
427 434
  my ($self, $entry) = @_;
......
454 461
  return 1;
455 462
}
456 463

  
464
sub handle_item {
465
  my ($self, $entry) = @_;
466

  
467
  my $object = $entry->{object};
468
  return unless $self->check_part($entry);
469

  
470
  my $part_obj = SL::DB::Part->new(id => $object->parts_id)->load;
471

  
472
  # copy from part if not given
473
  $object->description($part_obj->description) unless $object->description;
474
  $object->longdescription($part_obj->notes)   unless $object->longdescription;
475
  $object->unit($part_obj->unit)               unless $object->unit;
476

  
477
  # set to 0 if not given
478
  $object->discount(0) unless $object->discount;
479
  $object->ship(0)     unless $object->ship;
480

  
481
  $self->check_project($entry, global => 0);
482
  $self->check_price_factor($entry);
483
  $self->check_pricegroup($entry);
484
}
485

  
457 486
sub check_part {
458 487
  my ($self, $entry) = @_;
459 488

  

Auch abrufbar als: Unified diff