X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FWH.pm;h=22f4a4195b209217bd5ae687ebd64ab102ed445f;hb=74959706407d96a119832a3c807ee4d4d2c53639;hp=3087dfff4ade3b06f213b3776af03a8fedcf67a0;hpb=52d18c0134db2b418fe119723958efe8e79ac4f3;p=kivitendo-erp.git diff --git a/SL/WH.pm b/SL/WH.pm index 3087dfff4..22f4a4195 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -38,6 +38,9 @@ use SL::AM; use SL::DBUtils; use SL::Form; +use SL::DB::Unit; +use SL::DB::Assembly; + use warnings; use strict; @@ -56,7 +59,7 @@ sub transfer { require SL::DB::Employee; require SL::DB::Inventory; - my $employee = SL::DB::Manager::Employee->find_by(login => $::form->{login}); + my $employee = SL::DB::Manager::Employee->find_by(login => $::myconfig{login}); my ($now) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT current_date|); my @directions = (undef, qw(out in transfer)); @@ -76,7 +79,7 @@ sub transfer { my @trans_ids; my $db = SL::DB::Inventory->new->db; - $db->do_transaction(sub{ + $db->with_transaction(sub{ while (my $transfer = shift @args) { my ($trans_id) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT nextval('id')|); @@ -107,7 +110,7 @@ sub transfer { trans_id => $trans_id, shippingdate => !$transfer->{shippingdate} || $transfer->{shippingdate} eq 'current_date' ? $now : $transfer->{shippingdate}, - map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id orderitems_id comment), + map { $_ => $transfer->{$_} } qw(chargenumber bestbefore oe_id delivery_order_items_stock_id invoice_id comment), ); if ($unit) { @@ -138,10 +141,12 @@ sub transfer { $part->update_attributes(warehouse_id => conv_i($transfer->{dst_warehouse_id})); $part->update_attributes(bin_id => conv_i($transfer->{dst_bin_id})); } - } + } push @trans_ids, $trans_id; } + + 1; }) or do { $::form->error("Warehouse transfer error: " . join("\n", (split(/\n/, $db->error))[0..2])); }; @@ -158,6 +163,17 @@ sub transfer_assembly { my %params = @_; Common::check_params(\%params, qw(assembly_id dst_warehouse_id login qty unit dst_bin_id chargenumber bestbefore comment)); + + my $unit = SL::DB::Manager::Unit->find_by(name => $params{unit}); + if ($unit) { + my $assembly = SL::DB::Manager::Assembly->get_all( + query => [ id => $params{assembly_id} ], + with_objects => ['part'], + limit => 1, + )->[0]; + $params{qty} = $unit->convert_to($params{qty}, $assembly->part->unit_obj); + } + # my $maxcreate=WH->check_assembly_max_create(assembly_id =>$params{'assembly_id'}, dbh => $my_dbh); my $myconfig = \%main::myconfig; @@ -394,6 +410,7 @@ sub get_warehouse_journal { "trans_type" => "tt.description", "trans_id" => "i1.trans_id", "oe_id" => "COALESCE(i1.oe_id, i2.oe_id)", + "invoice_id" => "COALESCE(i1.invoice_id, i2.invoice_id)", "date" => "i1.itime::DATE", "itime" => "i1.itime", "employee" => "e.name", @@ -410,6 +427,8 @@ sub get_warehouse_journal { "warehouse_from" => "'$filter{na}'", }; + $form->{l_invoice_id} = $form->{l_oe_id} if $form->{l_oe_id}; + # build the select clauses. # take all the requested ones from the first hash and overwrite them from the out/in hashes if present. for my $i ('trans', 'out', 'in') { @@ -509,6 +528,18 @@ sub get_warehouse_journal { SELECT ap.id AS id, ap.invnumber AS number, 'purchase_invoice' AS type FROM ap WHERE ap.id = ? + + UNION + + SELECT ar.id AS id, ar.invnumber AS number, 'sales_invoice' AS type + FROM ar + WHERE ar.id = (SELECT trans_id FROM invoice WHERE id = ?) + + UNION + + SELECT ap.id AS id, ap.invnumber AS number, 'purchase_invoice' AS type + FROM ap + WHERE ap.id = (SELECT trans_id FROM invoice WHERE id = ?) SQL $h_oe_id = prepare_query($form, $dbh, $q_oe_id); } @@ -529,8 +560,9 @@ SQL 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); + if ($h_oe_id && ($ref->{oe_id} || $ref->{invoice_id})) { + my $id = $ref->{oe_id} ? $ref->{oe_id} : $ref->{invoice_id}; + do_statement($form, $h_oe_id, $q_oe_id, ($id) x 6); $ref->{oe_id_info} = $h_oe_id->fetchrow_hashref() || {}; }