X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/29795499e0623f7ff7ea739ed3b61d66dad0e7c6..777bf75cfcfc81a87479a508ea900de4a64c483e:/SL/IC.pm diff --git a/SL/IC.pm b/SL/IC.pm index 8520f5091..a84647fce 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -203,37 +203,25 @@ sub get_part { $sth->finish; # is it an orphan - $query = - qq|SELECT i.parts_id - FROM invoice i - WHERE (i.parts_id = ?) - - UNION - - SELECT o.parts_id - FROM orderitems o - WHERE (o.parts_id = ?) + my @referencing_tables = qw(invoice orderitems invoice inventory rmaitems); + my %column_map = ( ); + my $parts_id = conv_i($form->{id}); - UNION + $form->{orphaned} = 1; - SELECT a.parts_id - FROM assembly a - WHERE (a.parts_id = ?)|; - @values = (conv_i($form->{id}), conv_i($form->{id}), conv_i($form->{id})); - ($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values); - $form->{orphaned} = !$form->{orphaned}; + foreach my $table (@referencing_tables) { + my $column = $column_map{$table} || 'parts_id'; + $query = qq|SELECT $column FROM $table WHERE $column = ? LIMIT 1|; + my ($found) = selectrow_query($form, $dbh, $query, $parts_id); - $form->{"unit_changeable"} = 1; - foreach my $table (qw(invoice assembly orderitems inventory license)) { - $query = qq|SELECT COUNT(*) FROM $table WHERE parts_id = ?|; - my ($count) = selectrow_query($form, $dbh, $query, conv_i($form->{"id"})); - - if ($count) { - $form->{"unit_changeable"} = 0; + if ($found) { + $form->{orphaned} = 0; last; } } + $form->{"unit_changeable"} = $form->{orphaned}; + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -265,6 +253,8 @@ sub get_pricegroups { $dbh->disconnect; $main::lxdebug->leave_sub(); + + return $pricegroups; } sub retrieve_buchungsgruppen { @@ -724,9 +714,9 @@ sub delete { # connect to database, turn off AutoCommit my $dbh = $form->dbconnect_noauto($myconfig); - my %columns = ( "assembly" => "id", "alternate" => "id", "parts" => "id" ); + my %columns = ( "assembly" => "id", "parts" => "id" ); - for my $table (qw(prices partstax makemodel inventory assembly parts)) { + for my $table (qw(prices partstax makemodel inventory assembly license translation parts)) { my $column = defined($columns{$table}) ? $columns{$table} : "parts_id"; do_query($form, $dbh, qq|DELETE FROM $table WHERE $column = ?|, @values); } @@ -930,7 +920,17 @@ sub all_parts { my @sort_cols = (@simple_filters, qw(id bin priceupdate onhand invnumber ordnumber quonumber name serialnumber soldtotal deliverydate)); $form->{sort} = 'id' unless grep { $form->{"l_$_"} } grep { $form->{sort} eq $_ } @sort_cols; - my $order_clause = " ORDER BY $form->{sort} " . ($form->{revers} ? 'DESC' : 'ASC'); + + my $sort_order = ($form->{revers} ? ' DESC' : ' ASC'); + + # special case: sorting by partnumber + # since partnumbers are expected to be prefixed integers, a special sorting is implemented sorting first lexically by prefix and then by suffix. + # and yes, that expression is designed to hold that array of regexes only once, so the map is kinda messy, sorry about that. + # ToDO: implement proper functional sorting + $form->{sort} = join ', ', map { push @select_tokens, $_; ($table_prefix{$_} = "substring(partnumber,'[") . $_ } qw|^[:digit:]]+') [:digit:]]+')::INTEGER| + if $form->{sort} eq 'partnumber'; + + my $order_clause = " ORDER BY $form->{sort} $sort_order"; my $limit_clause = " LIMIT 100" if $form->{top100}; @@ -980,7 +980,8 @@ sub all_parts { #============= build query ================# - my %table_prefix = ( + %table_prefix = ( + %table_prefix, deliverydate => 'apoe.', serialnumber => 'ioi.', transdate => 'apoe.', trans_id => 'ioi.', module => 'apoe.', name => 'cv.', @@ -1679,11 +1680,14 @@ sub retrieve_languages { $query = qq|SELECT l.id, l.description, tr.translation, tr.longdescription FROM language l - LEFT OUTER JOIN translation tr ON (tr.language_id = l.id) AND (tr.parts_id = ?)|; + LEFT OUTER JOIN translation tr ON (tr.language_id = l.id) AND (tr.parts_id = ?) + ORDER BY lower(l.description)|; @values = (conv_i($form->{id})); } else { - $query = qq|SELECT id, description FROM language|; + $query = qq|SELECT id, description + FROM language + ORDER BY lower(description)|; } my $languages = selectall_hashref_query($form, $dbh, $query, @values);