Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 83914eeb

Von Moritz Bunkus vor fast 17 Jahren hinzugefügt

  • ID 83914eeb2e95cdf587565952eef54be59dd58693
  • Vorgänger 5c184abc
  • Nachfolger bb439145

Lagerverwaltung implementiert.

Unterschiede anzeigen:

SL/AM.pm
2407 2407
  $main::lxdebug->leave_sub();
2408 2408
}
2409 2409

  
2410
sub save_warehouse {
2411
  $main::lxdebug->enter_sub();
2412

  
2413
  my ($self, $myconfig, $form) = @_;
2414

  
2415
  # connect to database
2416
  my $dbh = $form->get_standard_dbh($myconfig);
2417

  
2418
  my ($query, @values, $sth);
2419

  
2420
  if (!$form->{id}) {
2421
    $query        = qq|SELECT nextval('id')|;
2422
    ($form->{id}) = selectrow_query($form, $dbh, $query);
2423

  
2424
    $query        = qq|INSERT INTO warehouse (id, sortkey) VALUES (?, (SELECT COALESCE(MAX(sortkey), 0) + 1 FROM warehouse))|;
2425
    do_query($form, $dbh, $query, $form->{id});
2426
  }
2427

  
2428
  do_query($form, $dbh, qq|UPDATE warehouse SET description = ?, invalid = ? WHERE id = ?|,
2429
           $form->{description}, $form->{invalid} ? 't' : 'f', conv_i($form->{id}));
2430

  
2431
  if (0 < $form->{number_of_new_bins}) {
2432
    $query = qq|INSERT INTO bin (warehouse_id, description) VALUES (?, ?)|;
2433
    $sth   = prepare_query($form, $dbh, $query);
2434

  
2435
    foreach my $i (1..$form->{number_of_new_bins}) {
2436
      do_statement($form, $sth, $query, conv_i($form->{id}), "$form->{prefix}${i}");
2437
    }
2438

  
2439
    $sth->finish();
2440
  }
2441

  
2442
  $dbh->commit();
2443

  
2444
  $main::lxdebug->leave_sub();
2445
}
2446

  
2447
sub save_bins {
2448
  $main::lxdebug->enter_sub();
2449

  
2450
  my ($self, $myconfig, $form) = @_;
2451

  
2452
  # connect to database
2453
  my $dbh = $form->get_standard_dbh($myconfig);
2454

  
2455
  my ($query, @values, $commit_necessary, $sth);
2456

  
2457
  @values = map { $form->{"id_${_}"} } grep { $form->{"delete_${_}"} } (1..$form->{rowcount});
2458

  
2459
  if (@values) {
2460
    $query = qq|DELETE FROM bin WHERE id IN (| . join(', ', ('?') x scalar(@values)) . qq|)|;
2461
    do_query($form, $dbh, $query, @values);
2462

  
2463
    $commit_necessary = 1;
2464
  }
2465

  
2466
  $query = qq|UPDATE bin SET description = ? WHERE id = ?|;
2467
  $sth   = prepare_query($form, $dbh, $query);
2468

  
2469
  foreach my $row (1..$form->{rowcount}) {
2470
    next if ($form->{"delete_${row}"});
2471

  
2472
    do_statement($form, $sth, $query, $form->{"description_${row}"}, conv_i($form->{"id_${row}"}));
2473

  
2474
    $commit_necessary = 1;
2475
  }
2476

  
2477
  $sth->finish();
2478

  
2479
  $dbh->commit() if ($commit_necessary);
2480

  
2481
  $main::lxdebug->leave_sub();
2482
}
2483

  
2484
sub delete_warehouse {
2485
  $main::lxdebug->enter_sub();
2486

  
2487
  my ($self, $myconfig, $form) = @_;
2488

  
2489
  # connect to database
2490
  my $dbh = $form->get_standard_dbh($myconfig);
2491

  
2492
  my $id      = conv_i($form->{id});
2493
  my $query   = qq|SELECT i.bin_id FROM inventory i WHERE i.bin_id IN (SELECT b.id FROM bin b WHERE b.warehouse_id = ?) LIMIT 1|;
2494
  my ($count) = selectrow_query($form, $dbh, $query, $id);
2495

  
2496
  if ($count) {
2497
    $main::lxdebug->leave_sub();
2498
    return 0;
2499
  }
2500

  
2501
  do_query($form, $dbh, qq|DELETE FROM warehouse_access WHERE warehouse_id = ?|, conv_i($form->{id}));
2502
  do_query($form, $dbh, qq|DELETE FROM bin              WHERE warehouse_id = ?|, conv_i($form->{id}));
2503
  do_query($form, $dbh, qq|DELETE FROM warehouse        WHERE id           = ?|, conv_i($form->{id}));
2504

  
2505
  $dbh->commit();
2506

  
2507
  $main::lxdebug->leave_sub();
2508

  
2509
  return 1;
2510
}
2511

  
2512
sub get_all_warehouses {
2513
  $main::lxdebug->enter_sub();
2514

  
2515
  my ($self, $myconfig, $form) = @_;
2516

  
2517
  # connect to database
2518
  my $dbh = $form->get_standard_dbh($myconfig);
2519

  
2520
  my $query = qq|SELECT w.id, w.description, w.invalid
2521
                 FROM warehouse w
2522
                 ORDER BY w.sortkey|;
2523

  
2524
  $form->{WAREHOUSES} = selectall_hashref_query($form, $dbh, $query);
2525

  
2526
  $main::lxdebug->leave_sub();
2527
}
2528

  
2529
sub get_warehouse {
2530
  $main::lxdebug->enter_sub();
2531

  
2532
  my ($self, $myconfig, $form) = @_;
2533

  
2534
  # connect to database
2535
  my $dbh = $form->get_standard_dbh($myconfig);
2536

  
2537
  my $id    = conv_i($form->{id});
2538
  my $query = qq|SELECT w.description, w.invalid
2539
                 FROM warehouse w
2540
                 WHERE w.id = ?|;
2541

  
2542
  my $ref   = selectfirst_hashref_query($form, $dbh, $query, $id, $id);
2543

  
2544
  map { $form->{$_} = $ref->{$_} } keys %{ $ref };
2545

  
2546
  $query = qq|SELECT b.*, EXISTS
2547
                (SELECT i.warehouse_id
2548
                 FROM inventory i
2549
                 WHERE i.bin_id = b.id
2550
                 LIMIT 1)
2551
                AS in_use
2552
              FROM bin b
2553
              WHERE b.warehouse_id = ?|;
2554

  
2555
  $form->{BINS} = selectall_hashref_query($form, $dbh, $query, conv_i($form->{id}));
2556

  
2557
  $main::lxdebug->leave_sub();
2558
}
2410 2559

  
2411 2560
1;

Auch abrufbar als: Unified diff