X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIC.pm;h=868fb741748649aa43dbf15ed6c1666e13a46a0e;hb=cf96c5880f1ba0694298d7541fedce47c8c99051;hp=0b836a0a17029e633532d8567956971a2ae5a178;hpb=9c29f7183bb2e2861553339789d7ac8ba7dd188d;p=kivitendo-erp.git diff --git a/SL/IC.pm b/SL/IC.pm index 0b836a0a1..868fb7417 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -37,7 +37,6 @@ package IC; use Data::Dumper; use List::MoreUtils qw(all any uniq); -use YAML; use SL::CVar; use SL::DBUtils; @@ -314,7 +313,11 @@ sub all_parts { # special case smart search if ($form->{all}) { - $form->{"l_$_"} = 1 for qw(partnumber description unit sellprice lastcost cvar_packaging linetotal); + $form->{"l_$_"} = 1 for qw(partnumber description unit sellprice lastcost linetotal); + $form->{l_service} = 1 if $form->{searchitems} eq 'service' || $form->{searchitems} eq ''; + $form->{l_assembly} = 1 if $form->{searchitems} eq 'assembly' || $form->{searchitems} eq ''; + $form->{l_part} = 1 if $form->{searchitems} eq 'part' || $form->{searchitems} eq ''; + $form->{l_assortment} = 1 if $form->{searchitems} eq 'assortment' || $form->{searchitems} eq ''; push @where_tokens, "p.partnumber ILIKE ? OR p.description ILIKE ?"; push @bind_vars, (like($form->{all})) x 2; } @@ -523,6 +526,22 @@ sub all_parts { push @bind_vars, @cvar_values; } + # simple search for assemblies by items used in assemblies + if ($form->{bom} eq '2' && $form->{l_assembly}) { + # nuke where clause and bind vars + $where_clause = ' 1=1 AND p.id in (SELECT id from assembly where parts_id IN ' . + ' (select id from parts where 1=1 AND '; + @bind_vars = (); + # use only like filter for items used in assemblies + foreach (@like_filters) { + next unless $form->{$_}; + $form->{"l_$_"} = '1'; # show the column + $where_clause .= " $_ ILIKE ? "; + push @bind_vars, like($form->{$_}); + } + $where_clause .='))'; + } + my $query = <<" SQL"; SELECT DISTINCT $select_clause FROM parts p @@ -787,7 +806,8 @@ sub retrieve_accounts { SQL my $query_tax = <{"taxaccounts_$index"} = $ref->{"accno"}; $form->{"taxaccounts"} .= "$ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/; - $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber); + $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber tax_id); } $sth_tax->finish; @@ -902,6 +922,25 @@ sub prepare_parts_for_printing { $sth->finish(); + $query = qq|SELECT + cp.parts_id, + cp.customer_partnumber AS customer_model, + c.name AS customer_make + FROM part_customer_prices cp + LEFT JOIN customer c ON (cp.customer_id = c.id) + WHERE cp.parts_id IN ($placeholders)|; + + my %customermodel = (); + + $sth = prepare_execute_query($form, $dbh, $query, @part_ids); + + while (my $ref = $sth->fetchrow_hashref()) { + $customermodel{$ref->{parts_id}} ||= []; + push @{ $customermodel{$ref->{parts_id}} }, $ref; + } + + $sth->finish(); + my @columns = qw(ean image microfiche drawing); $query = qq|SELECT id, | . join(', ', @columns) . qq| @@ -911,7 +950,7 @@ sub prepare_parts_for_printing { my %data = selectall_as_map($form, $dbh, $query, 'id', \@columns, @part_ids); my %template_arrays; - map { $template_arrays{$_} = [] } (qw(make model), @columns); + map { $template_arrays{$_} = [] } (qw(make model customer_make customer_model), @columns); foreach my $i (1 .. $rowcount) { my $id = $form->{"${prefix}${i}"}; @@ -925,11 +964,21 @@ sub prepare_parts_for_printing { push @{ $template_arrays{make} }, []; push @{ $template_arrays{model} }, []; - next if (!$makemodel{$id}); + if ($makemodel{$id}) { + foreach my $ref (@{ $makemodel{$id} }) { + map { push @{ $template_arrays{$_}->[-1] }, $ref->{$_} } qw(make model); + } + } + + push @{ $template_arrays{customer_make} }, []; + push @{ $template_arrays{customer_model} }, []; - foreach my $ref (@{ $makemodel{$id} }) { - map { push @{ $template_arrays{$_}->[-1] }, $ref->{$_} } qw(make model); + if ($customermodel{$id}) { + foreach my $ref (@{ $customermodel{$id} }) { + push @{ $template_arrays{$_}->[-1] }, $ref->{$_} for qw(customer_make customer_model); + } } + } my $parts = SL::DB::Manager::Part->get_all(query => [ id => \@part_ids ]); @@ -950,24 +999,4 @@ sub prepare_parts_for_printing { return %template_arrays; } -sub normalize_text_blocks { - $main::lxdebug->enter_sub(); - - my $self = shift; - my %params = @_; - - my $form = $params{form} || $main::form; - - # check if feature is enabled (select normalize_part_descriptions from defaults) - return unless ($::instance_conf->get_normalize_part_descriptions); - - foreach (qw(description notes)) { - $form->{$_} =~ s/\s+$//s; - $form->{$_} =~ s/^\s+//s; - $form->{$_} =~ s/ {2,}/ /g; - } - $main::lxdebug->leave_sub(); -} - - 1;