summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-09-06 12:42:34 -0700
committerMark Wells <mark@freeside.biz>2016-09-06 13:30:56 -0700
commit91a6e5e58df70ffad1234cb80ab76eaeaf8359b9 (patch)
treeea607cc6d9e876a56f37d021676585880bc8fa7f /httemplate/misc
parent5a7d43dfb77b2dd9ddae36f4e188e80e8a6b5ec6 (diff)
UI improvements for selecting taxproducts, #71555 and #71556
Diffstat (limited to 'httemplate/misc')
-rw-r--r--httemplate/misc/taxproduct.cgi24
1 files changed, 24 insertions, 0 deletions
diff --git a/httemplate/misc/taxproduct.cgi b/httemplate/misc/taxproduct.cgi
new file mode 100644
index 000000000..b22849343
--- /dev/null
+++ b/httemplate/misc/taxproduct.cgi
@@ -0,0 +1,24 @@
+<%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' };
+if ( $term =~ /^\d+$/ ) {
+ $search->{extra_sql} = " WHERE 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} = " WHERE 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) %>\