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