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,
19 <script src="<% $fsurl %>elements/jquery.js"></script>
21 var category_labels = <% encode_json(\%category_labels) %>;
22 $().ready(function() {
23 var new_taxproduct = $('#new_taxproduct');
24 var new_category_desc = $('#new_category_desc');
25 var new_taxproduct_desc = $('#new_taxproduct_desc');
26 var new_taxproduct_submit = $('#new_taxproduct_submit');
28 new_taxproduct.on('keyup', function() {
29 var curr_value = this.value || '';
30 var a = curr_value.match(/^\d{2}/);
32 if (a) { // there is a category code in the box
34 if (category_labels[category]) { // it matches an existing category
35 new_category_desc.val(category_labels[category]);
36 new_category_desc.prop('disabled', true);
38 new_category_desc.val('');
39 new_category_desc.prop('disabled', false);
42 new_category_desc.prop('disabled', true);
44 if (curr_value.match(/^\d{6}$/)) {
45 new_taxproduct_submit.prop('disabled', false);
47 new_taxproduct_submit.prop('disabled', true);
51 new_taxproduct_submit.on('click', function() {
52 select_taxproduct( -1,
55 + new_category_desc.val()
57 + new_taxproduct_desc.val()
61 // post the values back to the parent form
62 function select_taxproduct(taxproductnum, description) {
63 parent.document.getElementById('<% $id %>').value = taxproductnum;
64 parent.document.getElementById('<% $id %>_description').value = description;
71 <FONT SIZE="+1"><B><% emt('Add tax product') %></B></FONT>
72 <% ntable('#cccccc', 2) %>
73 <& /elements/tr-input-text.html,
74 'label' => emt('Product code'),
75 'field' => 'new_taxproduct',
76 'id' => 'new_taxproduct',
80 <& /elements/tr-input-text.html,
81 'label' => emt('Category'),
82 'field' => 'new_category_desc',
83 'id' => 'new_category_desc',
86 <& /elements/tr-input-text.html,
87 'label' => emt('Product'),
88 'field' => 'new_taxproduct_desc',
89 'id' => 'new_taxproduct_desc',
92 <input type="button" id="new_taxproduct_submit" disabled=1 value="Add">
97 # taxproduct is 6 digits: 2-digit category code + 4-digit detail code.
98 # Description is also two parts, corresponding to those codes, separated with
101 my (@category_codes, @taxproduct_codes, %category_labels, %taxproduct_labels);
102 foreach my $row ( qsearch({
103 table => 'part_pkg_taxproduct',
104 select => 'DISTINCT substr(taxproduct, 1, 2) AS code, '.
105 "substring(description from '(.*):') AS label",
106 hashref => { data_vendor => 'suretax' },
109 $category_labels{$row->get('code')} = $row->get('label');
112 @category_codes = sort {$a <=> $b} keys %category_labels;
116 % my ($category_code) = @_;
117 <FORM ACTION="<% $cgi->url %>" METHOD="GET">
118 <& /elements/select.html,
119 field => 'category_code',
120 options => \@category_codes,
121 labels => \%category_labels,
122 curr_value => $category_code,
123 onchange => 'this.form.submit()',
125 <& /elements/hidden.html,
127 curr_value => $cgi->param('id'),
133 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
135 $cgi->param('id') =~ /^\w+$/ or die "missing id parameter";
136 my $id = $cgi->param('id');
138 my $select_onclick = sub {
140 my $taxnum = $row->taxproductnum;
141 my $code = $row->taxproduct;
142 my $desc = $row->description;
143 "select_taxproduct('$taxnum', '$desc')";
147 my $title = 'Tax Products';
149 my $hashref = { data_vendor => 'suretax' };
151 my ($category_code, $taxproduct);
152 if ( $cgi->param('category_code') =~ /^(\d+)$/ ) {
154 $taxproduct = $category_code . '%';
159 $hashref->{taxproduct} = { op => 'LIKE', value => $taxproduct };
161 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct ".
162 "WHERE data_vendor = 'suretax' AND ".
163 "taxproduct LIKE '$taxproduct'";
178 my @link_onclicks = ( $select_onclick, $select_onclick );