Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e73b17d6

Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt

  • ID e73b17d69ae188821a87c133edb315284d74dfb5
  • Vorgänger 4a826447
  • Nachfolger 74c7135d

Beim Speichern von Lieferscheinen wird überprüft, ob der dazugehörige Auftrag nun komplett geliefert wurde. Wenn ja, so wird der Auftrag sowohl als geliefert als auch als geschlossen markiert.

Unterschiede anzeigen:

SL/DO.pm
342 342
  # save printed, emailed, queued
343 343
  $form->save_status($dbh);
344 344

  
345
  $self->close_order_if_delivered('do_id' => $form->{id},
346
                                  'type'  => $form->{type} eq 'sales_delivery_order' ? 'sales' : 'purchase',
347
                                  'dbh'   => $dbh,);
348

  
345 349
  my $rc = $dbh->commit();
346 350

  
347 351
  $form->{saved_donumber} = $form->{donumber};
......
353 357
  return $rc;
354 358
}
355 359

  
356
sub close_order {
360
sub close_order_if_delivered {
357 361
  $main::lxdebug->enter_sub();
358 362

  
359
  my ($self)   = @_;
363
  my $self   = shift;
364
  my %params = @_;
360 365

  
361
  my $myconfig = \%main::myconfig;
362
  my $form     = $main::form;
366
  Common::check_params(\%params, qw(do_id type));
363 367

  
364
  return $main::lxdebug->leave_sub() unless ($form->{id});
368
  my $myconfig    = \%main::myconfig;
369
  my $form        = $main::form;
365 370

  
366
  my $dbh = $form->get_standard_dbh($myconfig);
367
  do_query($form, $dbh, qq|UPDATE do SET closed = TRUE where id = ?|, conv_i($form->{id}));
368
  $dbh->commit();
371
  my $dbh         = $params{dbh} || $form->get_standard_dbh($myconfig);
372

  
373
  my $query       = qq|SELECT ordnumber FROM delivery_orders WHERE id = ?|;
374
  my ($ordnumber) = selectfirst_array_query($form, $dbh, $query, conv_i($params{do_id}));
375

  
376
  return $main::lxdebug->leave_sub() if (!$ordnumber);
377

  
378
  my $vc      = $params{type} eq 'purchase' ? 'vendor' : 'customer';
379
  $query      = qq|SELECT id
380
                   FROM oe
381
                   WHERE NOT COALESCE(quotation, FALSE)
382
                     AND (COALESCE(${vc}_id, 0) > 0)
383
                     AND (ordnumber = ?)
384
                   ORDER BY id
385
                   LIMIT 1|;
386

  
387
  my ($oe_id) = selectfirst_array_query($form, $dbh, $query, $ordnumber);
388

  
389
  return $main::lxdebug->leave_sub() if (!$oe_id);
390

  
391
  my $all_units = AM->retrieve_all_units();
392

  
393
  my %shipped   = $self->get_shipped_qty('type'      => $params{type},
394
                                         'ordnumber' => $ordnumber,);
395
  my %ordered   = ();
396

  
397
  $query        = qq|SELECT oi.parts_id, oi.qty, oi.unit, p.unit AS partunit
398
                     FROM orderitems oi
399
                     LEFT JOIN parts p ON (oi.parts_id = p.id)
400
                     WHERE (oi.trans_id = ?)|;
401
  my $sth       = prepare_execute_query($form, $dbh, $query, $oe_id);
402

  
403
  while (my $ref = $sth->fetchrow_hashref()) {
404
    $ref->{baseqty} = $ref->{qty} * $all_units->{$ref->{unit}}->{factor} / $all_units->{$ref->{partunit}}->{factor};
405

  
406
    if ($ordered{$ref->{parts_id}}) {
407
      $ordered{$ref->{parts_id}}->{baseqty} += $ref->{baseqty};
408
    } else {
409
      $ordered{$ref->{parts_id}}             = $ref;
410
    }
411
  }
412

  
413
  $sth->finish();
414

  
415
  map { $_->{baseqty} = $_->{qty} * $all_units->{$_->{unit}}->{factor} / $all_units->{$_->{partunit}}->{factor} } values %shipped;
416

  
417
  my $delivered = 1;
418
  foreach my $part (values %ordered) {
419
    if (!$shipped{$part->{parts_id}} || ($shipped{$part->{parts_id}}->{baseqty} < $part->{baseqty})) {
420
      $delivered = 0;
421
      last;
422
    }
423
  }
424

  
425
  if ($delivered) {
426
    $query = qq|UPDATE oe
427
                SET delivered = TRUE, closed = TRUE
428
                WHERE id = ?|;
429
    do_query($form, $dbh, $query, $oe_id);
430

  
431
    $dbh->commit() if (!$params{dbh});
432
  }
369 433

  
370 434
  $main::lxdebug->leave_sub();
371 435
}

Auch abrufbar als: Unified diff