1 <& /elements/header-popup.html, $title &>
2 <& /browse/elements/browse.html,
3 'name_singular' => 'tax product',
4 'html_form' => include('.form', $category_code),
6 'table' => 'part_pkg_taxproduct',
8 'order_by' => 'ORDER BY taxproduct',
10 'count_query' => $count_query,
15 'link_onclicks' => \@link_onclicks,
22 <script src="<% $fsurl %>elements/jquery.js"></script>
24 var category_labels = <% encode_json(\%category_labels) %>;
25 $().ready(function() {
26 var new_taxproduct = $('#new_taxproduct');
27 var new_category_desc = $('#new_category_desc');
28 var new_taxproduct_desc = $('#new_taxproduct_desc');
29 var new_taxproduct_submit = $('#new_taxproduct_submit');
31 new_taxproduct.on('keyup', function() {
32 var curr_value = this.value || '';
33 var a = curr_value.match(/^\d{2}/);
35 if (a) { // there is a category code in the box
37 if (category_labels[category]) { // it matches an existing category
38 new_category_desc.val(category_labels[category]);
39 new_category_desc.prop('disabled', true);
41 new_category_desc.val('');
42 new_category_desc.prop('disabled', false);
45 new_category_desc.prop('disabled', true);
47 if (curr_value.match(/^\d{6}$/)) {
48 new_taxproduct_submit.prop('disabled', false);
50 new_taxproduct_submit.prop('disabled', true);
54 new_taxproduct_submit.on('click', function() {
55 select_taxproduct( -1,
58 + new_category_desc.val()
60 + new_taxproduct_desc.val()
64 // post the values back to the parent form
65 function select_taxproduct(taxproductnum, description) {
66 parent.document.getElementById('<% $id %>').value = taxproductnum;
67 parent.document.getElementById('<% $id %>_description').value = description;
72 <DIV STYLE="width: 50%">
74 <label for="new_taxproduct">New tax product code</label>
75 <input type="text" size="6" name="new_taxproduct" id="new_taxproduct">
77 <label for="new_category_desc">Category</label>
78 <input type="text" name="new_category_desc" id="new_category_desc" disabled=1>
80 <label for="new_taxproduct_desc">Product</label>
81 <input type="text" name="new_taxproduct_desc" id="new_taxproduct_desc">
83 <input type="button" id="new_taxproduct_submit" disabled=1 value="Add">
89 # taxproduct is 6 digits: 2-digit category code + 4-digit detail code.
90 # Description is also two parts, corresponding to those codes, separated with
93 my (@category_codes, @taxproduct_codes, %category_labels, %taxproduct_labels);
94 foreach my $row ( qsearch({
95 table => 'part_pkg_taxproduct',
96 select => 'DISTINCT substr(taxproduct, 1, 2) AS code, '.
97 "substring(description from '(.*):') AS label",
98 hashref => { data_vendor => 'suretax' },
101 $category_labels{$row->get('code')} = $row->get('label');
104 @category_codes = sort {$a <=> $b} keys %category_labels;
108 % my ($category_code) = @_;
109 <FORM ACTION="<% $cgi->url %>" METHOD="GET">
110 <& /elements/select.html,
111 field => 'category_code',
112 options => \@category_codes,
113 labels => \%category_labels,
114 curr_value => $category_code,
115 onchange => 'this.form.submit()',
117 <& /elements/hidden.html,
119 curr_value => $cgi->param('id'),
125 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
127 $cgi->param('id') =~ /^\w+$/ or die "missing id parameter";
128 my $id = $cgi->param('id');
130 my $select_onclick = sub {
132 my $taxnum = $row->taxproductnum;
133 my $code = $row->taxproduct;
134 my $desc = $row->description;
135 "select_taxproduct('$taxnum', '$desc')";
139 my $title = 'Tax Products';
141 my $hashref = { data_vendor => 'suretax' };
143 my ($category_code, $taxproduct);
144 if ( $cgi->param('category_code') =~ /^(\d+)$/ ) {
146 $taxproduct = $category_code . '%';
151 $hashref->{taxproduct} = { op => 'LIKE', value => $taxproduct };
153 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct ".
154 "WHERE data_vendor = 'suretax' AND ".
155 "taxproduct LIKE '$taxproduct'";
170 my @link_onclicks = ( $select_onclick, $select_onclick );