Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4070dbf3

Von Sven Schöling vor mehr als 12 Jahren hinzugefügt

  • ID 4070dbf38e04b168fe43bd3a6e5a3f28f77e986d
  • Vorgänger 8545bbce
  • Nachfolger 5104dee4

Suche nach Ansprechpartnern

Merge aus zwei verschiedenen Implementierungen der gleichen Funktionalität

Features:
- behandelt Ansprechparter als direkte Suchziele wie Kunden und Lieferanten (1)
- Suche ähnlich den bekannten Suchmasken (1)
- Suche nach direktem Suchwort (2)
- Verlinkung einer Schnellsuche in der menunew header Leiste (2)

Unterschiede anzeigen:

SL/CT.pm
1207 1207
  $main::lxdebug->leave_sub();
1208 1208
}
1209 1209

  
1210
sub search_contacts {
1211
  $::lxdebug->enter_sub;
1212

  
1213
  my $self      = shift;
1214
  my %params    = @_;
1215

  
1216
  my $dbh       = $params{dbh} || $::form->get_standard_dbh;
1217
  my $vc        = $params{db} eq 'customer' ? 'customer' : 'vendor';
1218

  
1219
  my %sortspecs = (
1220
    'cp_name'   => 'cp_name, cp_givenname',
1221
    'vcname'    => 'vcname, cp_name, cp_givenname',
1222
    'vcnumber'  => 'vcnumber, cp_name, cp_givenname',
1223
    );
1224

  
1225
  my %sortcols  = map { $_ => 1 } qw(cp_name cp_givenname cp_phone1 cp_phone2 cp_mobile1 cp_email vcname vcnumber);
1226

  
1227
  my $order_by  = $sortcols{$::form->{sort}} ? $::form->{sort} : 'cp_name';
1228
  $::form->{sort} = $order_by;
1229
  $order_by     = $sortspecs{$order_by} if ($sortspecs{$order_by});
1230

  
1231
  my $sortdir   = $::form->{sortdir} ? 'ASC' : 'DESC';
1232
  $order_by     =~ s/,/ ${sortdir},/g;
1233
  $order_by    .= " $sortdir";
1234

  
1235
  my @where_tokens = ();
1236
  my @values;
1237

  
1238
  if ($params{search_term}) {
1239
    my @tokens;
1240
    push @tokens,
1241
      'cp.cp_name      ILIKE ?',
1242
      'cp.cp_givenname ILIKE ?',
1243
      'cp.cp_email     ILIKE ?';
1244
    push @values, ('%' . $params{search_term} . '%') x 3;
1245

  
1246
    if (($params{search_term} =~ m/\d/) && ($params{search_term} !~ m/[^\d \(\)+\-]/)) {
1247
      my $number =  $params{search_term};
1248
      $number    =~ s/[^\d]//g;
1249
      $number    =  join '[ /\(\)+\-]*', split(m//, $number);
1250

  
1251
      push @tokens, map { "($_ ~ '$number')" } qw(cp_phone1 cp_phone2 cp_mobile1 cp_mobile2);
1252
    }
1253

  
1254
    push @where_tokens, map { "($_)" } join ' OR ', @tokens;
1255
  }
1256

  
1257
  if (my $filter = $params{filter}) {
1258
    for (qw(name title givenname email project abteilung)) {
1259
      next unless $filter->{"cp_$_"};
1260
      add_token(\@where_tokens, \@values, col =>  "cp.cp_$_", val => $filter->{"cp_$_"}, method => 'ILIKE', esc => 'substr');
1261
    }
1262

  
1263
    push @where_tokens, 'cp.cp_cv_id IS NOT NULL' if $filter->{status} eq 'active';
1264
    push @where_tokens, 'cp.cp_cv_id IS NULL'     if $filter->{status} eq 'orphaned';
1265
  }
1266

  
1267
  my $where = @where_tokens ? 'WHERE ' . join ' AND ', @where_tokens : '';
1268

  
1269
  my $query     = qq|SELECT cp.*,
1270
                       COALESCE(c.id,             v.id)           AS vcid,
1271
                       COALESCE(c.name,           v.name)         AS vcname,
1272
                       COALESCE(c.customernumber, v.vendornumber) AS vcnumber,
1273
                       CASE WHEN c.name IS NULL THEN 'vendor' ELSE 'customer' END AS db
1274
                     FROM contacts cp
1275
                     LEFT JOIN customer c ON (cp.cp_cv_id = c.id)
1276
                     LEFT JOIN vendor v   ON (cp.cp_cv_id = v.id)
1277
                     $where
1278
                     ORDER BY $order_by|;
1279

  
1280
  my $contacts  = selectall_hashref_query($::form, $dbh, $query, @values);
1281

  
1282
  $::lxdebug->leave_sub;
1283

  
1284
  return @{ $contacts };
1285
}
1286

  
1287

  
1210 1288
1;

Auch abrufbar als: Unified diff