X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/80499f9da1fb349fd4ee2a5eef5a64c872240feb..c815c7236e442a9117808af8a3cc8445f5a35203:/SL/WH.pm diff --git a/SL/WH.pm b/SL/WH.pm index 3cc2e2375..af66e3bac 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -182,9 +182,14 @@ sub transfer_assembly { # on assembly.parts_id = parts.id where assembly.id = ? and # (inventory_accno_id IS NOT NULL or parts.assembly = TRUE)|; + # Lager in dem die Bestandteile gesucht werden kann entweder das Ziellager sein oder ist per Mandantenkonfig + # auf das Standardlager des Bestandteiles schaltbar - my $query = qq|select parts_id,qty from assembly inner join parts on assembly.parts_id = parts.id - where assembly.id = ? and (inventory_accno_id IS NOT NULL or parts.assembly = TRUE)|; + my $use_default_warehouse = $::instance_conf->get_transfer_default_warehouse_for_assembly; + + my $query = qq|SELECT assembly.parts_id, assembly.qty, parts.warehouse_id + FROM assembly INNER JOIN parts ON assembly.parts_id = parts.id + WHERE assembly.id = ? AND (inventory_accno_id IS NOT NULL OR parts.assembly = TRUE)|; my $sth_part_qty_assembly = prepare_execute_query($form, $dbh, $query, $params{assembly_id}); @@ -202,19 +207,53 @@ sub transfer_assembly { my $schleife_durchlaufen=0; # Falls die Schleife nicht ausgeführt wird -> Keine Einzelteile definiert. Bessere Idee? jan while (my $hash_ref = $sth_part_qty_assembly->fetchrow_hashref()) { #Schleife für select parts_id,(...) from assembly $schleife_durchlaufen=1; # Erzeugnis definiert - my $partsQTY = $hash_ref->{qty} * $params{qty}; # benötigte teile * anzahl erzeugnisse - my $currentPart_ID = $hash_ref->{parts_id}; + my $partsQTY = $hash_ref->{qty} * $params{qty}; # benötigte teile * anzahl erzeugnisse + my $currentPart_ID = $hash_ref->{parts_id}; + + my $currentPart_WH_ID = $use_default_warehouse && $hash_ref->{warehouse_id} ? $hash_ref->{warehouse_id} : $params{dst_warehouse_id}; + my $no_check = 0; + + # Prüfen ob Erzeugnis-Teile Standardlager haben. + if ($use_default_warehouse && ! $hash_ref->{warehouse_id}) { + # Prüfen ob in Mandantenkonfiguration ein Standardlager aktiviert isti. + if ($::instance_conf->get_transfer_default_ignore_onhand) { + $currentPart_WH_ID = $::instance_conf->get_warehouse_id_ignore_onhand; + $no_check = 1; + } else { + $kannNichtFertigen .= "Kein Standardlager: " . + " Die Ware " . $self->get_part_description(parts_id => $currentPart_ID) . + " hat kein Standardlager definiert " . + ", um das Erzeugnis herzustellen.
"; + next; + } + } + my $warehouse_info = $self->get_basic_warehouse_info('id'=> $currentPart_WH_ID); + my $warehouse_desc = $warehouse_info->{"warehouse_description"}; + + # Fertigen ohne Prüfung nach Bestand + if ($no_check) { + my $temppart_bin_id = $::instance_conf->get_bin_id_ignore_onhand; + my $temppart_chargenumber = ""; + my $temppart_bestbefore = localtime(); + my $temppart_qty = $partsQTY * -1; + + do_statement($form, $sthTransferPartSQL, $transferPartSQL, $currentPart_ID, $currentPart_WH_ID, + $temppart_bin_id, $temppart_chargenumber, $temppart_bestbefore, 'Verbraucht für ' . + $self->get_part_description(parts_id => $params{assembly_id}), $params{login}, $temppart_qty); + next; + } # Überprüfen, ob diese Anzahl gefertigt werden kann - my $max_parts = $self->get_max_qty_parts(parts_id => $currentPart_ID, # $self->method() == this.method() - warehouse_id => $params{dst_warehouse_id}); + my $max_parts = $self->get_max_qty_parts(parts_id => $currentPart_ID, # $self->method() == this.method() + warehouse_id => $currentPart_WH_ID); if ($partsQTY > $max_parts){ # Gibt es hier ein Problem mit nicht "escapten" Zeichen? # 25.4.09 Antwort: Ja. Aber erst wenn im Frontend die locales-Funktion aufgerufen wird - $kannNichtFertigen .= "Zum Fertigen fehlen:" . abs($partsQTY - $max_parts) . - " Einheiten der Ware:" . $self->get_part_description(parts_id => $currentPart_ID) . + $kannNichtFertigen .= "Zum Fertigen fehlen: " . abs($partsQTY - $max_parts) . + " Einheiten der Ware: " . $self->get_part_description(parts_id => $currentPart_ID) . + " im Lager: " . $warehouse_desc . ", um das Erzeugnis herzustellen.
"; # Konnte die Menge nicht mit der aktuellen Anzahl der Waren fertigen next; # die weiteren Überprüfungen sind unnötig, daher das nächste elemente prüfen (genaue Ausgabe, was noch fehlt) } @@ -228,7 +267,7 @@ sub transfer_assembly { my $tempquery = qq|SELECT SUM(qty), bin_id, chargenumber, bestbefore FROM inventory WHERE warehouse_id = ? AND parts_id = ? GROUP BY bin_id, chargenumber, bestbefore having SUM(qty)>0|; - my $tempsth = prepare_execute_query($form, $dbh, $tempquery, $params{dst_warehouse_id}, $currentPart_ID); + my $tempsth = prepare_execute_query($form, $dbh, $tempquery, $currentPart_WH_ID, $currentPart_ID); # Alle Werte zu dem einzelnen Artikel, die wir später auslagern my $tmpPartsQTY = $partsQTY; @@ -246,7 +285,7 @@ sub transfer_assembly { # wenn * -1 als berechnung in der parameter-übergabe angegeben wird. # Dieser Wert IST und BLEIBT positiv!! Hilfe. # Liegt das daran, dass dieser Wert aus einem SQL-Statement stammt? - do_statement($form, $sthTransferPartSQL, $transferPartSQL, $currentPart_ID, $params{dst_warehouse_id}, + do_statement($form, $sthTransferPartSQL, $transferPartSQL, $currentPart_ID, $currentPart_WH_ID, $temppart_bin_id, $temppart_chargenumber, $temppart_bestbefore, 'Verbraucht für ' . $self->get_part_description(parts_id => $params{assembly_id}), $params{login}, $temppart_qty); @@ -256,7 +295,7 @@ sub transfer_assembly { # auf jeden fall war der internal-server-error nach aktivierung von strict und warnings plus ein paar my-definitionen weg } else { # okay, wir haben weniger oder gleich Waren die wir wegbuchen müssen, wir können also aufhören $tmpPartsQTY *=-1; - do_statement($form, $sthTransferPartSQL, $transferPartSQL, $currentPart_ID, $params{dst_warehouse_id}, + do_statement($form, $sthTransferPartSQL, $transferPartSQL, $currentPart_ID, $currentPart_WH_ID, $temppart_bin_id, $temppart_chargenumber, $temppart_bestbefore, 'Verbraucht für ' . $self->get_part_description(parts_id => $params{assembly_id}), $params{login}, $tmpPartsQTY); last; # beendet die schleife (springt zum letzten element) @@ -877,6 +916,40 @@ sub get_basic_bin_info { return map { $_->{bin_id} => $_ } @{ $result }; } + +sub get_basic_warehouse_info { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, qw(id)); + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh(); + + my @ids = 'ARRAY' eq ref $params{id} ? @{ $params{id} } : ($params{id}); + + my $query = + qq|SELECT w.id AS warehouse_id, w.description AS warehouse_description + FROM warehouse w + WHERE w.id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)|; + + my $result = selectall_hashref_query($form, $dbh, $query, map { conv_i($_) } @ids); + + if ('' eq ref $params{id}) { + $result = $result->[0] || { }; + $main::lxdebug->leave_sub(); + + return $result; + } + + $main::lxdebug->leave_sub(); + + return map { $_->{warehouse_id} => $_ } @{ $result }; +} # # Eingabe: Teilenummer, Lagernummer (warehouse) # Ausgabe: Die maximale Anzahl der Teile in diesem Lager @@ -895,9 +968,9 @@ $main::lxdebug->enter_sub(); my $dbh = $params{dbh} || $form->get_standard_dbh(); my $query = qq| SELECT SUM(qty), bin_id, chargenumber, bestbefore FROM inventory where parts_id = ? AND warehouse_id = ? GROUP BY bin_id, chargenumber, bestbefore|; - my $sth_QTY = prepare_execute_query($form, $dbh, $query, ,$params{parts_id}, $params{warehouse_id}); #info: aufruf an DBUtils.pm + my $max_qty_parts = 0; #Initialisierung mit 0 while (my $ref = $sth_QTY->fetchrow_hashref()) { # wir laufen über alle Haltbarkeiten, chargen und Lagerorte (s.a. SQL-Query oben) $max_qty_parts += $ref->{sum}; @@ -1087,6 +1160,106 @@ An expiration date. Note that this is not by default used by C =back +=head2 create_assembly \%PARAMS, [ \%PARAMS, ... ] + +Creates an assembly if all defined items are available. + +Assembly item(s) will be stocked out and the assembly will be stocked in, +taking into account the qty and units which can be defined for each +assembly item seperately. + +The calling params originate from C but only parts_id with the +attribute assembly are processed. + +The typical params would be: + + my %TRANSFER = ( + 'login' => $::myconfig{login}, + 'dst_warehouse_id' => $form->{warehouse_id}, + 'dst_bin_id' => $form->{bin_id}, + 'chargenumber' => $form->{chargenumber}, + 'bestbefore' => $form->{bestbefore}, + 'assembly_id' => $form->{parts_id}, + 'qty' => $form->{qty}, + 'comment' => $form->{comment} + ); + +=head3 Prerequisites + +All of these prerequisites have to be trueish, otherwise the function will exit +unsuccessfully with a return value of undef. + +=over 4 + +=item Mandantory params + + assembly_id, qty, login, dst_warehouse_id and dst_bin_id are mandatory. + +=item Subset named 'Assembly' of data set 'Part' + + assembly_id has to be an id in the table parts with the valid subset assembly. + +=item Assembly is composed of assembly item(s) + + There has to be at least one data set in the table assembly referenced to this assembly_id. + +=item Assembly cannot be destroyed or disassembled + + Assemblies are like cakes. You cannot disassemble it. NEVER. + No negative nor zero qty's are valid inputs. + +=item The assembly item(s) have to be in the same warehouse + + inventory.warehouse_id equals dst_warehouse_id (client configurable). + +=item The assembly item(s) have to be in stock with the qty needed + + I can only make a cake by receipt if I have ALL ingredients and + in the needed stock amount. + The qty of stocked in assembly item(s) has to fit into the + number of the qty of the assemblies, which are going to be created (client configurable). + +=item assembly item(s) with the parts set 'service' are ignored + + The subset 'Services' of part will not transferred for assembly item(s). + +=back + +Client configurable prerequisites can be changed with different +prerequisites as described in client_config (s.a. next chapter). + + +=head2 default creation of assembly + +The valid state of the assembly item(s) used for the assembly process are +'out' for the general direction and 'used' as the specific reason. +The valid state of the assembly is 'in' for the direction and 'assembled' +as the specific reason. + +The method is transaction safe, in case of errors not a single entry will be made +in inventory. + +Two prerequisites can be changed with this global parameters + +=over 2 + +=item $::instance_conf->get_transfer_default_warehouse_for_assembly + + If trueish we try to get all the items form the default bins defined in parts + and do not try to find them in the destination warehouse. Returns an + error if not all items have set a default bin in parts. + +=item $::instance_conf->get_bin_id_ignore_onhand + + If trueish we can create assemblies even if we do not have enough items in stock. + The needed qty will be booked in a special bin, which has to be configured in + the client config. + +=back + + + + =head1 BUGS None yet.