Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / browse / part_pkg_taxproduct / suretax.html
1 <& /elements/header-popup.html, $title &>
2 <& /browse/elements/browse.html,
3   'name_singular'  => 'tax product',
4   'html_form'      => include('.form', $category_code),
5   'query'          => {
6                         'table'     => 'part_pkg_taxproduct',
7                         'hashref'   => $hashref,
8                         'order_by'  => 'ORDER BY taxproduct',
9                       },
10   'count_query'    => $count_query,
11   'header'         => \@header,
12   'fields'         => \@fields,
13   'align'          => $align,
14   'links'          => [],
15   'link_onclicks'  => \@link_onclicks,
16   'nohtmlheader'   => 1,
17   'disable_total'  => 1,
18 &>
19 <script src="<% $fsurl %>elements/jquery.js"></script>
20 <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');
27
28   new_taxproduct.on('keyup', function() {
29     var curr_value = this.value || '';
30     var a = curr_value.match(/^\d{2}/);
31     var f = this.form;
32     if (a) { // there is a category code in the box
33       var category = a[0];
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);
37       } else {
38         new_category_desc.val('');
39         new_category_desc.prop('disabled', false);
40       }
41     } else {
42       new_category_desc.prop('disabled', true);
43     }
44     if (curr_value.match(/^\d{6}$/)) {
45       new_taxproduct_submit.prop('disabled', false);
46     } else {
47       new_taxproduct_submit.prop('disabled', true);
48     }
49   });
50
51   new_taxproduct_submit.on('click', function() {
52     select_taxproduct( -1,
53                        new_taxproduct.val()
54                           + ' '
55                           + new_category_desc.val()
56                           + ':'
57                           + new_taxproduct_desc.val()
58                      );
59   });
60 });
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;
65   parent.cClick();
66 }
67   
68 </script>  
69 <BR>
70 <FORM NAME="myform">
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',
77       'size'      => 6,
78       'maxlength' => 6,
79     &>
80     <& /elements/tr-input-text.html,
81       'label'     => emt('Category'),
82       'field'     => 'new_category_desc',
83       'id'        => 'new_category_desc',
84       'disabled'  => 1
85     &>
86     <& /elements/tr-input-text.html,
87       'label'     => emt('Product'),
88       'field'     => 'new_taxproduct_desc',
89       'id'        => 'new_taxproduct_desc',
90     &>
91   </table>
92   <input type="button" id="new_taxproduct_submit" disabled=1 value="Add">
93 </FORM>
94 <& /elements/footer-popup.html &>
95 <%shared>
96 # populate dropdown
97
98 # taxproduct is 6 digits: 2-digit category code + 4-digit detail code.
99 # Description is also two parts, corresponding to those codes, separated with
100 # a :.
101
102 my (@category_codes, @taxproduct_codes, %category_labels, %taxproduct_labels);
103 foreach my $row ( qsearch({
104   table   => 'part_pkg_taxproduct',
105   select  => 'DISTINCT substr(taxproduct, 1, 2) AS code, '.
106              "substring(description from '(.*):') AS label",
107   hashref => { data_vendor => 'suretax' },
108   }))
109 {
110   $category_labels{$row->get('code')} = $row->get('label');
111 }
112
113 @category_codes = sort {$a <=> $b} keys %category_labels;
114
115 </%shared>
116 <%def .form>
117 % my ($category_code) = @_;
118 <FORM ACTION="<% $cgi->url %>" METHOD="GET">
119 <& /elements/select.html,
120   field       => 'category_code',
121   options     => \@category_codes,
122   labels      => \%category_labels,
123   curr_value  => $category_code,
124   onchange    => 'this.form.submit()',
125 &>
126 <& /elements/hidden.html,
127   field       => 'id',
128   curr_value  => scalar($cgi->param('id')),
129 &>
130 </%def>
131 <%init>
132
133 die "access denied"
134   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
135
136 $cgi->param('id') =~ /^\w+$/ or die "missing id parameter";
137 my $id = $cgi->param('id');
138
139 my $select_onclick = sub {
140   my $row = shift;
141   my $taxnum = $row->taxproductnum;
142   my $desc = $row->taxproduct . ' ' . $row->description;
143   "select_taxproduct('$taxnum', '$desc')";
144 };
145
146 my @menubar;
147 my $title = 'Tax Products';
148
149 my $hashref = { data_vendor => 'suretax' };
150
151 my ($category_code, $taxproduct);
152 if ( $cgi->param('category_code') =~ /^(\d+)$/ ) {
153   $category_code = $1;
154   $taxproduct = $category_code . '%';
155 } else {
156   $taxproduct = '%';
157 }
158
159 $hashref->{taxproduct} = { op => 'LIKE', value => $taxproduct };
160
161 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct ".
162                   "WHERE data_vendor = 'suretax' AND ".
163                   "taxproduct LIKE '$taxproduct'";
164
165 my @fields = (
166   'taxproduct',
167   'description',
168   'note'
169 );
170
171 my @header = (
172   'Code',
173   'Description',
174   '',
175 );
176
177 my $align = 'lll';
178 my @link_onclicks = ( $select_onclick, $select_onclick );
179
180 </%init>