X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIC.pm;h=50c1172b0a8fcb49acdc9f70ff421668660460d7;hb=63b3e9b39fe288260a3d6103db86359b3339f21a;hp=eaa932c00768ad3d9123917dfc8743f07a260222;hpb=93618a69a94243bf03ed2a9e856d8d4e67036394;p=kivitendo-erp.git diff --git a/SL/IC.pm b/SL/IC.pm index eaa932c00..50c1172b0 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -41,6 +41,8 @@ use YAML; use SL::CVar; use SL::DBUtils; +use strict; + sub get_part { $main::lxdebug->enter_sub(); @@ -412,6 +414,7 @@ sub save { ve = ?, gv = ?, ean = ?, + has_sernumber = ?, not_discountable = ?, microfiche = ?, partsgroup_id = ?, @@ -441,6 +444,7 @@ sub save { conv_i($form->{ve}), conv_i($form->{gv}), $form->{ean}, + $form->{has_sernumber} ? 't' : 'f', $form->{not_discountable} ? 't' : 'f', $form->{microfiche}, conv_i($partsgroup_id), @@ -790,8 +794,8 @@ sub all_parts { pfac => 'LEFT JOIN price_factors pfac ON (pfac.id = p.price_factor_id)', invoice_oi => q|LEFT JOIN ( - SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, deliverydate, 'invoice' AS ioi FROM invoice UNION - SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi FROM orderitems + SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, deliverydate, 'invoice' AS ioi, id FROM invoice UNION + SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi, id FROM orderitems ) AS ioi ON ioi.parts_id = p.id|, apoe => q|LEFT JOIN ( @@ -820,6 +824,10 @@ sub all_parts { description => 'p.', qty => 'ioi.', serialnumber => 'ioi.', + quotation => 'apoe.', + cv => 'cv.', + "ioi.id" => ' ', + "ioi.ioi" => ' ', ); # if the join condition in these blocks are met, the column @@ -831,12 +839,15 @@ sub all_parts { [ 'deliverydate', 'ioi.', 'invoice_oi' ], [ 'transdate', 'apoe.', 'apoe' ], [ 'unit', 'ioi.', 'invoice_oi' ], + [ 'sellprice', 'ioi.', 'invoice_oi' ], ); # careful with renames. these are HARD, and any filters done on the original column will break my %renamed_columns = ( 'factor' => 'price_factor', 'SUM(ioi.qty)' => 'soldtotal', + 'ioi.id' => 'ioi_id', + 'ioi.ioi' => 'ioi', ); if (($form->{searchitems} eq 'assembly') && $form->{l_lastcost}) { @@ -926,14 +937,16 @@ sub all_parts { #my $order_clause = " ORDER BY $form->{sort} $sort_order"; - my $limit_clause = " LIMIT 100" if $form->{top100}; + my $limit_clause; + $limit_clause = " LIMIT 100" if $form->{top100}; + $limit_clause = " LIMIT " . $form->{limit} * 1 if $form->{limit} * 1; #=== joins and complicated filters ========# my $bsooqr = any { $form->{$_} } @oe_flags; my @bsooqr_tokens = (); - push @select_tokens, @qsooqr_flags if $bsooqr; + push @select_tokens, @qsooqr_flags, 'quotation', 'cv', 'ioi.id', 'ioi.ioi' if $bsooqr; push @select_tokens, @deliverydate_flags if $bsooqr && $form->{l_deliverydate}; push @select_tokens, $q_assembly_lastcost if ($form->{searchitems} eq 'assembly') && $form->{l_lastcost}; push @bsooqr_tokens, q|module = 'ir' AND NOT ioi.assemblyitem| if $form->{bought}; @@ -1001,7 +1014,15 @@ sub all_parts { push @bind_vars, @cvar_values; } - my $query = qq|SELECT DISTINCT $select_clause FROM parts p $join_clause WHERE $where_clause $group_clause $order_clause $limit_clause|; + my $query = <<" SQL"; + SELECT DISTINCT $select_clause + FROM parts p + $join_clause + WHERE $where_clause + $group_clause + $order_clause + $limit_clause + SQL $form->{parts} = selectall_hashref_query($form, $dbh, $query, @bind_vars); @@ -1041,6 +1062,8 @@ sub all_parts { } $main::lxdebug->leave_sub(); + + return wantarray ? @{ $form->{parts} } : $form->{parts}; } sub _create_filter_for_priceupdate { @@ -1559,7 +1582,7 @@ sub get_basic_part_info { my $dbh = $form->get_standard_dbh($myconfig); - my $query = qq|SELECT id, partnumber, description, unit FROM parts WHERE id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)|; + my $query = qq|SELECT * FROM parts WHERE id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)|; my $info = selectall_hashref_query($form, $dbh, $query, map { conv_i($_) } @ids);