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/IC.pm
325 325
    }
326 326

  
327 327
    if ($form->{item} eq 'assembly') {
328
      if ($form->{onhand} != 0) {
329
        &adjust_inventory($dbh, $form, $form->{id}, $form->{onhand} * -1);
330
      }
331

  
332 328
      # delete assembly records
333 329
      do_query($form, $dbh, qq|DELETE FROM assembly WHERE id = ?|, conv_i($form->{id}));
334

  
335
      $form->{onhand} += $form->{stock};
336 330
    }
337 331

  
338 332
    # delete tax records
......
352 346
    do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber) VALUES (?, '')|, $form->{id});
353 347

  
354 348
    $form->{orphaned} = 1;
355
    $form->{onhand} = $form->{stock} if $form->{item} eq 'assembly';
356 349
    if ($form->{partnumber} eq "" && $form->{"item"} eq "service") {
357 350
      $form->{partnumber} = $form->update_defaults($myconfig, "servicenumber");
358 351
    }
......
532 525
      }
533 526
    }
534 527

  
535
    # adjust onhand for the parts
536
    if ($form->{onhand} != 0) {
537
      &adjust_inventory($dbh, $form, $form->{id}, $form->{onhand});
538
    }
539

  
540 528
    @a = localtime;
541 529
    $a[5] += 1900;
542 530
    $a[4]++;
......
544 532

  
545 533
    $form->get_employee($dbh);
546 534

  
547
    # add inventory record
548
    $query =
549
      qq|INSERT INTO inventory (warehouse_id, parts_id, qty, shippingdate, employee_id)
550
         VALUES (0, ?, ?, '$shippingdate', ?)|;
551
    @values = (conv_i($form->{id}), $form->{stock}, conv_i($form->{employee_id}));
552
    do_query($form, $dbh, $query, @values);
553

  
554 535
  }
555 536

  
556 537
  #set expense_accno=inventory_accno if they are different => bilanz
......
650 631
  $main::lxdebug->leave_sub();
651 632
}
652 633

  
653
sub restock_assemblies {
654
  $main::lxdebug->enter_sub();
655

  
656
  my ($self, $myconfig, $form) = @_;
657

  
658
  # connect to database
659
  my $dbh = $form->dbconnect_noauto($myconfig);
660

  
661
  for my $i (1 .. $form->{rowcount}) {
662

  
663
    $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
664

  
665
    if ($form->{"qty_$i"} != 0) {
666
      &adjust_inventory($dbh, $form, $form->{"id_$i"}, $form->{"qty_$i"});
667
    }
668

  
669
  }
670

  
671
  my $rc = $dbh->commit;
672
  $dbh->disconnect;
673

  
674
  $main::lxdebug->leave_sub();
675

  
676
  return $rc;
677
}
678

  
679
sub adjust_inventory {
680
  $main::lxdebug->enter_sub();
681

  
682
  my ($dbh, $form, $id, $qty) = @_;
683

  
684
  my $query =
685
    qq|SELECT p.id, p.inventory_accno_id, p.assembly, a.qty
686
       FROM parts p, assembly a
687
       WHERE (a.parts_id = p.id) AND (a.id = ?)|;
688
  my $sth = prepare_execute_query($form, $dbh, $query, conv_i($id));
689

  
690
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
691

  
692
    my $allocate = $qty * $ref->{qty};
693

  
694
    # is it a service item, then loop
695
    $ref->{inventory_accno_id} *= 1;
696
    next if (($ref->{inventory_accno_id} == 0) && !$ref->{assembly});
697

  
698
    # adjust parts onhand
699
    $form->update_balance($dbh, "parts", "onhand",
700
                          qq|id = $ref->{id}|,
701
                          $allocate * -1);
702
  }
703

  
704
  $sth->finish;
705

  
706
  # update assembly
707
  my $rc = $form->update_balance($dbh, "parts", "onhand", qq|id = ?|, $qty, $id);
708

  
709
  $main::lxdebug->leave_sub();
710

  
711
  return $rc;
712
}
713

  
714 634
sub delete {
715 635
  $main::lxdebug->enter_sub();
716 636

  
......
1014 934

  
1015 935
  $form->{parts} = selectall_hashref_query($form, $dbh, $query, @bind_vars);
1016 936

  
937
  map { $_->{onhand} *= 1 } @{ $form->{parts} };
938

  
1017 939
##  my $where = qq|1 = 1|;
1018 940
##  my (@values, $var, $flds, $group, $limit);
1019 941
##

Auch abrufbar als: Unified diff