ORDER BY cp.cp_id
LIMIT 1|;
my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
-
+ # we have no values, probably a invalid contact person. hotfix and first idea for issue #10
+ if (!$ref) {
+ my $customer = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id});
+ if ($customer) {
+ $ref->{name} = $customer->name;
+ $ref->{street} = $customer->street;
+ $ref->{zipcode} = $customer->zipcode;
+ $ref->{country} = $customer->country;
+ }
+ my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
+ if ($contact) {
+ $ref->{cp_name} = $contact->cp_name;
+ $ref->{cp_givenname} = $contact->cp_givenname;
+ $ref->{cp_gender} = $contact->cp_gender;
+ }
+ }
# remove id and taxincluded before copy back
delete @$ref{qw(id taxincluded)};
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.
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,
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.