From 6f1b36cfb8b26f6c8540ba5f36e48b9188d9470a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 22 Sep 2014 15:43:40 +0200 Subject: [PATCH] select_item: Belegmasken finden jetzt auch Warennummern aus makemodels MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Außerdem die Präsentation von select_item angepasst, so dass ersichtlich wird woher die gefundenen Waren stammen. --- SL/IR.pm | 34 +++++++++++++++++++++++--- SL/IS.pm | 25 ++++++++++++++++++- locale/de/all | 1 + templates/webpages/io/select_item.html | 2 ++ 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/SL/IR.pm b/SL/IR.pm index b36e6065a..e465224b8 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -1191,11 +1191,27 @@ sub retrieve_item { $where .= " AND lower(${table_column}) LIKE lower(?)"; push @values, '%' . $form->{"${field}_${i}"} . '%'; } - #Es soll auch nach EAN gesucht werden, ohne Einschränkung durch Beschreibung + + my (%mm_by_id); if ($form->{"partnumber_$i"} && !$form->{"description_$i"}) { - $where .= qq| OR (NOT p.obsolete = '1' AND p.ean = ? )|; - push @values, $form->{"partnumber_$i"}; - } + $where .= qq| OR (NOT p.obsolete = '1' AND p.ean = ? )|; + push @values, $form->{"partnumber_$i"}; + + # also search hits in makemodels, but only cache the results by id and merge later + my $mm_query = qq| + SELECT parts_id, model FROM makemodel + LEFT JOIN parts ON parts.id = parts_id + WHERE NOT parts.obsolete AND model ILIKE ? AND (make IS NULL OR make = ?); + |; + my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, '%' . $form->{"partnumber_$i"} . '%', $::form->{vendor_id}); + my @mm_ids = map { $_->{parts_id} } @$mm_results; + push @{$mm_by_id{ $_->{parts_id} } ||= []}, $_ for @$mm_results; + + if (@mm_ids) { + $where .= qq| OR p.id IN (| . join(',', ('?') x @mm_ids) . qq|)|; + push @values, @mm_ids; + } + } # Search for part ID overrides all other criteria. if ($form->{"id_${i}"}) { @@ -1227,6 +1243,7 @@ sub retrieve_item { p.unit, p.assembly, p.onhand, p.formel, p.notes AS partnotes, p.notes AS longdescription, p.not_discountable, p.inventory_accno_id, p.price_factor_id, + p.ean, pfac.factor AS price_factor, @@ -1278,6 +1295,15 @@ sub retrieve_item { $form->{item_list} = []; while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + if ($mm_by_id{$ref->{id}}) { + $ref->{makemodels} = $mm_by_id{$ref->{id}}; + push @{ $ref->{matches} ||= [] }, $::locale->text('Model') . ': ' . join ', ', map { $_->{model} } @{ $mm_by_id{$ref->{id}} }; + } + + if ($ref->{ean} eq $::form->{"partnumber_$i"}) { + push @{ $ref->{matches} ||= [] }, $::locale->text('EAN') . ': ' . $ref->{ean}; + } + # In der Buchungsgruppe ist immer ein Bestandskonto verknuepft, auch wenn # es sich um eine Dienstleistung handelt. Bei Dienstleistungen muss das # Buchungskonto also aus dem Ergebnis rausgenommen werden. diff --git a/SL/IS.pm b/SL/IS.pm index e3ed35ff0..1398ed872 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1910,10 +1910,23 @@ sub retrieve_item { push @values, '%' . $form->{"${field}_${i}"} . '%'; } - #Es soll auch nach EAN gesucht werden, ohne Einschränkung durch Beschreibung + my (%mm_by_id); if ($form->{"partnumber_$i"} && !$form->{"description_$i"}) { $where .= qq| OR (NOT p.obsolete = '1' AND p.ean = ? )|; push @values, $form->{"partnumber_$i"}; + + # also search hits in makemodels, but only cache the results by id and merge later + my $mm_query = qq| + SELECT parts_id, model FROM makemodel LEFT JOIN parts ON parts.id = parts_id WHERE NOT parts.obsolete AND model ILIKE ?; + |; + my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, '%' . $form->{"partnumber_$i"} . '%'); + my @mm_ids = map { $_->{parts_id} } @$mm_results; + push @{$mm_by_id{ $_->{parts_id} } ||= []}, $_ for @$mm_results; + + if (@mm_ids) { + $where .= qq| OR p.id IN (| . join(',', ('?') x @mm_ids) . qq|)|; + push @values, @mm_ids; + } } # Search for part ID overrides all other criteria. @@ -1947,6 +1960,7 @@ sub retrieve_item { qq|SELECT p.id, p.partnumber, p.description, p.sellprice, p.listprice, p.inventory_accno_id, p.lastcost, + p.ean, c1.accno AS inventory_accno, c1.new_chart_id AS inventory_new_chart, @@ -2002,6 +2016,15 @@ sub retrieve_item { while (my $ref = $sth->fetchrow_hashref('NAME_lc')) { + if ($mm_by_id{$ref->{id}}) { + $ref->{makemodels} = $mm_by_id{$ref->{id}}; + push @{ $ref->{matches} ||= [] }, $::locale->text('Model') . ': ' . join ', ', map { $_->{model} } @{ $mm_by_id{$ref->{id}} }; + } + + if ($ref->{ean} eq $::form->{"partnumber_$i"}) { + push @{ $ref->{matches} ||= [] }, $::locale->text('EAN') . ': ' . $ref->{ean}; + } + # In der Buchungsgruppe ist immer ein Bestandskonto verknuepft, auch wenn # es sich um eine Dienstleistung handelt. Bei Dienstleistungen muss das # Buchungskonto also aus dem Ergebnis rausgenommen werden. diff --git a/locale/de/all b/locale/de/all index a0ca961de..693b9f565 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1664,6 +1664,7 @@ $self->{texts} = { 'Orphaned' => 'Nie benutzt', 'Orphaned currencies' => 'Verwaiste Währungen', 'Other' => 'Sonstiges', + 'Other Matches' => 'Andere Treffer', 'Other users\' follow-ups' => 'Wiedervorlagen anderer Benutzer', 'Other values are ignored.' => 'Andere Eingaben werden ignoriert.', 'Others' => 'Andere', diff --git a/templates/webpages/io/select_item.html b/templates/webpages/io/select_item.html index 803e93ea7..351489e6f 100644 --- a/templates/webpages/io/select_item.html +++ b/templates/webpages/io/select_item.html @@ -9,6 +9,7 @@   [% LxERP.t8('Number') %] [% LxERP.t8('Part Description') %] + [% LxERP.t8('Other Matches') %] [% LxERP.t8('Price') %] [%- IF IS_PURCHASE %] [% LxERP.t8('ROP') %] @@ -22,6 +23,7 @@ [% HTML.escape(item.partnumber) %] [% HTML.escape(item.description) %] + [% HTML.escape(item.matches).join('
') %] [% LxERP.format_amount(item.display_sellprice, 2) %] [%- IF IS_PURCHASE %] [% LxERP.format_amount(item.rop, '') %] -- 2.20.1