stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / misc / taxproduct.cgi
1 <%once>
2 my $conf = FS::Conf->new;
3 my $vendor = $conf->config('tax_data_vendor');
4 </%once>
5 <%init>
6 my $term = $cgi->param('term');
7 warn "taxproduct.cgi?$term"; # XXX debug
8 my $search = { table => 'part_pkg_taxproduct' };
9 if ( $term =~ /^\d+$/ ) {
10   $search->{extra_sql} = " WHERE taxproduct LIKE '$term%'";
11   $search->{order_by} = " ORDER BY taxproduct ASC";
12 } elsif ( length($term) ) {
13   $term = dbh->quote( lc($term) ); # protect against bad strings
14   $search->{extra_sql} = " WHERE POSITION($term IN LOWER(description)) > 0";
15   # and sort by how close to the beginning of the string it is
16   $search->{order_by} = " ORDER BY POSITION($term IN LOWER(description)) ASC, LOWER(description) ASC, taxproduct ASC";
17 }
18 my @taxproducts = qsearch($search);
19 my @results = map {
20   { label => $_->taxproduct . ' ' . $_->description,
21     value => $_->taxproductnum } 
22 } @taxproducts;
23 </%init>
24 <% encode_json(\@results) %>\