X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Ftaxproduct.cgi;h=a397f23643999d36ed593ff1aa27ee5a04b6963b;hp=b22849343f4fd774857ed75ce6882ec9b4165c78;hb=HEAD;hpb=f4bb9273f1ba174858e221fd37f6dd1dca4119e9 diff --git a/httemplate/misc/taxproduct.cgi b/httemplate/misc/taxproduct.cgi index b22849343..a397f2364 100644 --- a/httemplate/misc/taxproduct.cgi +++ b/httemplate/misc/taxproduct.cgi @@ -1,24 +1,35 @@ +<% encode_json(\@results) %>\ <%once> my $conf = FS::Conf->new; my $vendor = $conf->config('tax_data_vendor'); <%init> + my $term = $cgi->param('term'); -warn "taxproduct.cgi?$term"; # XXX debug -my $search = { table => 'part_pkg_taxproduct' }; -if ( $term =~ /^\d+$/ ) { - $search->{extra_sql} = " WHERE taxproduct LIKE '$term%'"; +#warn "taxproduct.cgi?$term"; # XXX debug + +my $search = { + table => 'part_pkg_taxproduct', + hashref => { 'data_vendor' => $vendor } +}; + +if ( $term =~ /^[A-Z]?\d+$/ ) { + $search->{extra_sql} = " AND taxproduct ILIKE '$term%'"; $search->{order_by} = " ORDER BY taxproduct ASC"; } elsif ( length($term) ) { $term = dbh->quote( lc($term) ); # protect against bad strings - $search->{extra_sql} = " WHERE POSITION($term IN LOWER(description)) > 0"; + $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"; } + +$search->{extra_sql} .= ' AND length(taxproduct) > 4' + if $vendor eq 'compliance_solutions'; + my @taxproducts = qsearch($search); my @results = map { { label => $_->taxproduct . ' ' . $_->description, value => $_->taxproductnum } } @taxproducts; + -<% encode_json(\@results) %>\