1 <& search.html, %opt &>
3 Currently does nothing but insert the classnames for fields chosen from an
8 my $query = $opt{query};
9 my $svcdb = $query->{'table'};
11 # to avoid looking up the inventory class of every service in the database,
12 # keep as much of the base query as possible.
13 my $item_query = { %$query };
14 $item_query->{'table'} = 'inventory_item';
15 $item_query->{'addl_from'} =
16 " JOIN ( $svcdb ". $query->{'addl_from'} .
17 ") ON inventory_item.svcnum = $svcdb.svcnum ".
18 " JOIN inventory_class ON (inventory_item.classnum = inventory_class.classnum)";
19 # avoid conflict with inventory_item.agentnum
20 $item_query->{'extra_sql'} =~ s/ agentnum/ cust_main.agentnum/g;
21 $item_query->{'select'} = 'inventory_item.svcnum, '.
22 'inventory_item.svc_field, '.
23 'inventory_class.classname';
24 my @items = qsearch($item_query);
26 foreach my $i (@items) {
27 $item_fields{ $i->svc_field } ||= {};
28 $item_fields{ $i->svc_field }{ $i->svcnum } = $i->classname;
31 $opt{'sort_fields'} ||= [];
32 for ( my $i = 0; $i < @{ $opt{'fields'} }; $i++ ) {
33 my $f = $opt{'fields'}[$i];
34 next if ref($f); # it's not a plain table column
35 $opt{'sort_fields'}[$i] ||= $f;
36 my $classnames = $item_fields{$f}; # hashref of svcnum -> classname
37 next if !$classnames; # there are no inventory items in this column
38 $opt{'fields'}[$i] = sub {
40 if ( exists($classnames->{$svc->svcnum}) ) {
41 return $svc->$f . '<BR><I>('. $classnames->{$svc->svcnum} . ')</I>';