X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/64c39b744b9fba960b32315ac7ea36477c85e8a5..672ff8cc19df543a6683bb55f450d15ac2eba871:/SL/WH.pm diff --git a/SL/WH.pm b/SL/WH.pm index b93eebdd6..7ef012d91 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -158,13 +158,13 @@ sub transfer_assembly { # Hier wird das prepared Statement für die Schleife über alle Lagerplätze vorbereitet my $transferPartSQL = qq|INSERT INTO inventory (parts_id, warehouse_id, bin_id, chargenumber, comment, employee_id, qty, trans_id, trans_type_id) - VALUES (?, ?, ?, ?, ?,(SELECT id FROM employee WHERE login = ?), ?, nextval('id'), + VALUES (?, ?, ?, ?, ?,(SELECT id FROM employee WHERE login = ?), ?, nextval('id'), (SELECT id FROM transfer_type WHERE direction = 'out' AND description = 'used'))|; my $sthTransferPartSQL = prepare_query($form, $dbh, $transferPartSQL); my $kannNichtFertigen =""; # der return-string für die fehlermeldung inkl. welche waren zum fertigen noch fehlen - while (my $hash_ref = $sth_part_qty_assembly->fetchrow_hashref()) { # Schleife für $query=select parts_id,qty from assembly + while (my $hash_ref = $sth_part_qty_assembly->fetchrow_hashref()) { # Schleife für $query=select parts_id,qty from assembly my $partsQTY = $hash_ref->{qty} * $params{qty}; # benötigte teile * anzahl erzeugnisse my $currentPart_ID = $hash_ref->{parts_id}; @@ -174,7 +174,7 @@ sub transfer_assembly { 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) . " Stueck der Ware:" . get_part_description($self, parts_id => $currentPart_ID) . ", um das Erzeugnis herzustellen.
"; # Konnte die Menge nicht mit der aktuellen Anzahl der Waren fertigen + $kannNichtFertigen .= "Zum Fertigen fehlen:" . abs($partsQTY - $max_parts) . " Einheiten der Ware:" . get_part_description($self, parts_id => $currentPart_ID) . ", um das Erzeugnis herzustellen.
"; # Konnte die Menge nicht mit der aktuellen Anzahl der Waren fertigen next; # die weiteren Überprüfungen sind unnötig } @@ -215,9 +215,9 @@ sub transfer_assembly { return $kannNichtFertigen; } - # soweit alles gut. Jetzt noch die wirkliche Lagerbewegung für das Erzeugnis ausführen ... + # soweit alles gut. Jetzt noch die wirkliche Lagerbewegung für das Erzeugnis ausführen ... my $transferAssemblySQL = qq|INSERT INTO inventory (parts_id, warehouse_id, bin_id, chargenumber, comment, employee_id, qty, trans_id, trans_type_id) - VALUES (?, ?, ?, ?, ?, (SELECT id FROM employee WHERE login = ?), ?, nextval('id'), + VALUES (?, ?, ?, ?, ?, (SELECT id FROM employee WHERE login = ?), ?, nextval('id'), (SELECT id FROM transfer_type WHERE direction = 'in' AND description = 'stock'))|; my $sthTransferAssemblySQL = prepare_query($form, $dbh, $transferAssemblySQL); do_statement($form, $sthTransferAssemblySQL, $transferAssemblySQL, $params{assembly_id}, $params{dst_warehouse_id}, $params{dst_bin_id}, $params{chargenumber}, $params{comment}, $params{login}, $params{qty}); @@ -301,11 +301,14 @@ sub get_warehouse_journal { $filter{na} = '-' unless $filter{na}; # make order, search in $filter and $form - $form->{sort} = $filter{sort} unless $form->{sort}; - $form->{order} = ($form->{sort} = 'itime') unless $form->{sort}; - $form->{sort} = 'itime' if $form->{sort} eq "date"; - $form->{order} = $filter{order} unless $form->{order}; - $form->{sort} .= (($form->{order}) ? " DESC" : " ASC"); + my $sort_col = $form->{sort}; + my $sort_order = $form->{order}; + + $sort_col = $filter{sort} unless $sort_col; + $sort_order = ($sort_col = 'itime') unless $sort_col; + $sort_col = 'itime' if $sort_col eq 'date'; + $sort_order = $filter{order} unless $sort_order; + my $sort_spec = "${sort_col} " . ($sort_order ? " DESC" : " ASC"); my $where_clause = join(" AND ", @filter_ary) . " AND " if (@filter_ary); @@ -325,6 +328,7 @@ sub get_warehouse_journal { "comment" => "i1.comment", "trans_type" => "tt.description", "trans_id" => "i1.trans_id", + "oe_id" => "COALESCE(i1.oe_id, i2.oe_id)", "date" => "i1.itime::DATE", "itime" => "i1.itime", "employee" => "e.name", @@ -400,10 +404,49 @@ sub get_warehouse_journal { WHERE $where_clause i1.qty > 0 AND i1.trans_id IN ( SELECT i.trans_id FROM inventory i GROUP BY i.trans_id HAVING COUNT(i.trans_id) = 1 ) GROUP BY $group_clause - ORDER BY r_$form->{sort}|; + ORDER BY r_${sort_spec}|; my $sth = prepare_execute_query($form, $dbh, $query, @filter_vars, @filter_vars, @filter_vars); + my ($h_oe_id, $q_oe_id); + if ($form->{l_oe_id}) { + $q_oe_id = <fetchrow_hashref(NAME_lc)) { map { /^r_/; $ref->{"$'"} = $ref->{$_} } keys %$ref; @@ -420,10 +463,16 @@ sub get_warehouse_journal { next if (('<=' eq $f_qty_op) && ($qty > $f_qty)); } + if ($h_oe_id && $ref->{oe_id}) { + do_statement($form, $h_oe_id, $q_oe_id, ($ref->{oe_id}) x 4); + $ref->{oe_id_info} = $h_oe_id->fetchrow_hashref() || {}; + } + push @contents, $ref; } $sth->finish(); + $h_oe_id->finish() if $h_oe_id; $main::lxdebug->leave_sub(); @@ -438,6 +487,7 @@ sub get_warehouse_journal { # - partsid - will return matches with this parts_id only # - description - will return only matches where the given string is a substring of the description # - chargenumber - will return only matches where the given string is a substring of the chargenumber +# - ean - will return only matches where the given string is a substring of the ean as stored in the table parts (article) # - charge_ids - must be an arrayref. will return contents with these ids only # - expires_in - will only return matches that expire within the given number of days # will also add a column named 'has_expired' containing if the match has already expired or not @@ -463,7 +513,7 @@ sub get_warehouse_report { my $dbh = $form->get_standard_dbh($myconfig); # filters - my (@filter_ary, @filter_vars, @wh_bin_filter_ary, @wh_bin_filter_vars, $columns, $group_by); + my (@filter_ary, @filter_vars, @wh_bin_filter_ary, @wh_bin_filter_vars); delete $form->{include_empty_bins} unless ($form->{l_warehousedescription} || $form->{l_bindescription}); @@ -499,6 +549,10 @@ sub get_warehouse_report { push @filter_ary, "i.chargenumber ILIKE ?"; push @filter_vars, '%' . $filter{chargenumber} . '%'; } + if ($filter{ean}) { + push @filter_ary, "p.ean ILIKE ?"; + push @filter_vars, '%' . $filter{ean} . '%'; + } # prepare qty comparison for later filtering my ($f_qty_op, $f_qty, $f_qty_base_unit); @@ -516,12 +570,15 @@ sub get_warehouse_report { map { $form->{"l_${_}id"} = "Y" if ($form->{"l_${_}description"} || $form->{"l_${_}number"}); } qw(warehouse bin); # make order, search in $filter and $form - $form->{sort} = $filter{sort} unless $form->{sort}; - $form->{sort} = "parts_id" unless $form->{sort}; - $form->{order} = $filter{order} unless $form->{order}; - $form->{sort} =~ s/ASC|DESC//; # kill stuff left in from previous queries - my $orderby = $form->{sort}; - $form->{sort} .= (($form->{order}) ? " DESC" : " ASC"); + my $sort_col = $form->{sort}; + my $sort_order = $form->{order}; + + $sort_col = $filter{sort} unless $sort_col; + $sort_col = "parts_id" unless $sort_col; + $sort_order = $filter{order} unless $sort_order; + $sort_col =~ s/ASC|DESC//; # kill stuff left in from previous queries + my $orderby = $sort_col; + my $sort_spec = "${sort_col} " . ($sort_order ? " DESC" : " ASC"); my $where_clause = join " AND ", ("1=1", @filter_ary); @@ -534,6 +591,7 @@ sub get_warehouse_report { "bindescription" => "b.description", "binid" => "b.id", "chargenumber" => "i.chargenumber", + "ean" => "p.ean", "chargeid" => "c.id", "warehousedescription" => "w.description", "partunit" => "p.unit", @@ -557,15 +615,14 @@ sub get_warehouse_report { my $query = qq|SELECT $select_clause - $columns FROM inventory i LEFT JOIN parts p ON i.parts_id = p.id LEFT JOIN bin b ON i.bin_id = b.id LEFT JOIN warehouse w ON i.warehouse_id = w.id $joins WHERE $where_clause - GROUP BY $group_clause $group_by - ORDER BY $form->{sort}|; + GROUP BY $group_clause + ORDER BY $sort_spec|; my $sth = prepare_execute_query($form, $dbh, $query, @filter_vars); @@ -591,7 +648,7 @@ sub get_warehouse_report { @all_fields = keys %{ $ref } unless (@all_fields); } - $ref->{stock_value} *= $ref->{qty}; + $ref->{stock_value} = ($ref->{stock_value} || 0) * $ref->{qty}; push @contents, $ref; } @@ -721,7 +778,7 @@ $main::lxdebug->enter_sub(); my $self = shift; my %params = @_; - Common::check_params(\%params, qw(parts_id warehouse_id)); #die brauchen wir + Common::check_params(\%params, qw(parts_id warehouse_id)); #die brauchen wir my $myconfig = \%main::myconfig; my $form = $main::form; @@ -731,10 +788,10 @@ $main::lxdebug->enter_sub(); my $query = qq| SELECT SUM(qty), bin_id, chargenumber FROM inventory where parts_id = ? AND warehouse_id = ? GROUP BY bin_id, chargenumber|; 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 chargen und Lagerorte (s.a. SQL-Query oben) - $max_qty_parts += $ref->{sum}; + $max_qty_parts += $ref->{sum}; } $main::lxdebug->leave_sub(); @@ -752,7 +809,7 @@ $main::lxdebug->enter_sub(); my $self = shift; my %params = @_; - Common::check_params(\%params, qw(parts_id )); #die brauchen wir + Common::check_params(\%params, qw(parts_id )); #die brauchen wir my $myconfig = \%main::myconfig; my $form = $main::form; @@ -762,9 +819,9 @@ $main::lxdebug->enter_sub(); my $query = qq| SELECT partnumber, description FROM parts where id = ? |; my $sth = prepare_execute_query($form, $dbh, $query, ,$params{parts_id}); #info: aufruf zu DBUtils.pm - - my $ref = $sth->fetchrow_hashref(); - my $part_description = $ref->{partnumber} . " " . $ref->{description}; + + my $ref = $sth->fetchrow_hashref(); + my $part_description = $ref->{partnumber} . " " . $ref->{description}; $main::lxdebug->leave_sub();