1 <% include( '../elements/browse.html',
2 'title' => "Tax Products $title",
3 'name_singular' => 'tax product',
4 'menubar' => \@menubar,
5 'html_init' => $html_init,
7 'table' => 'part_pkg_taxproduct',
9 'order_by' => 'ORDER BY description',
10 'extra_sql' => $extra_sql,
12 'count_query' => $count_query,
17 'link_onclicks' => \@link_onclicks,
22 my $conf = new FS::Conf;
24 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
30 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
34 my $onclick = 'cClick';
36 my $data_vendor = 'cch';
38 $title = " for $title" if $title;
40 my $taxproductnum = $1
41 if ( $cgi->param('taxproductnum') =~ /^(\d+)$/ );
43 if ( $cgi->param('tax_group') =~ /^([- \w\(\).\/]+)$/ );
45 if ( $cgi->param('tax_item') =~ /^([- \w\(\).\/&%]+)$/ );
47 if ( $cgi->param('tax_provider') =~ /^([ \w]+)$/ );
49 if ( $cgi->param('tax_customer') =~ /^([ \w]+)$/ );
51 if ( $cgi->param('id') =~ /^([ \w]+)$/ );
54 if ( $cgi->param('onclick') =~ /^(\w+)$/ );
55 $cgi->delete('onclick');
57 my $remove_onclick = <<EOS
58 parent.document.getElementById('$id').value = '';
59 parent.document.getElementById('${id}_description').value = '';
64 my $select_onclick = sub {
66 my $taxnum = $row->taxproductnum;
67 my $desc = $row->description;
68 "parent.document.getElementById('$id').value = $taxnum;".
69 "parent.document.getElementById('${id}_description').value = '$desc';".
74 my $selected_part_pkg_taxproduct;
76 $selected_part_pkg_taxproduct =
77 qsearchs('part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum });
81 my $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
83 if ($tax_group || $tax_item || $tax_customer || $tax_provider) {
84 my $compare = "LIKE '". ( $tax_group || "%" ). " : ". ( $tax_item || "%" ). " : ".
85 ( $tax_provider || "%" ). " : ". ( $tax_customer || "%" ). "'";
86 $compare = "= '$tax_group:$tax_item:$tax_provider:$tax_customer'"
87 if ($tax_group && $tax_item && $tax_provider && $tax_customer);
89 $extra_sql .= ($extra_sql =~ /WHERE/ ? ' AND ' : ' WHERE ').
90 "description $compare";
93 $cgi->delete('tax_group');
94 $cgi->delete('tax_item');
95 $cgi->delete('tax_provider');
96 $cgi->delete('tax_customer');
99 if ( $tax_group || $tax_item || $tax_provider || $tax_customer ) {
100 push @menubar, 'View all tax products' => $p.'browse/part_pkg_taxproduct/cch.html';
103 $cgi->param('dummy', 1);
105 #restore this so pagination works
106 $cgi->param('tax_group', $tax_group) if $tax_group;
107 $cgi->param('tax_item', $tax_item ) if $tax_item;
108 $cgi->param('tax_provider', $tax_provider ) if $tax_provider;
109 $cgi->param('tax_customer', $tax_customer ) if $tax_customer;
110 $cgi->param('onclick', $onclick ) if $onclick;
112 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql";
114 my @header = ( 'Group', 'Item', 'Provider', 'Customer' );
115 my @links = ( $select_link,
120 my @link_onclicks = ( $select_onclick,
128 sub { shift->description =~ /^(.*):.*:.*:.*$/; $1;},
129 sub { shift->description =~ /^.*:(.*):.*:.*$/; $1;},
130 sub { shift->description =~ /^.*:.*:(.*):.*$/; $1;},
131 sub { shift->description =~ /^.*:.*:.*:(.*)$/; $1;},
136 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
137 $html_init = '<TABLE><TR><TD><A HREF="javascript:void(0)" '.
138 qq!onClick="$remove_onclick">(remove)</A> !.
139 'Current tax product: </TD><TD>'.
140 $selected_part_pkg_taxproduct->description.
141 '</TD></TR></TABLE><BR><BR>'
142 if $selected_part_pkg_taxproduct;
144 my $type = $cgi->param('_type');
147 <INPUT NAME="_type" TYPE="hidden" VALUE="$type">
148 <INPUT NAME="taxproductnum" TYPE="hidden" VALUE="$taxproductnum">
149 <INPUT NAME="onclick" TYPE="hidden" VALUE="$onclick">
150 <INPUT NAME="id" TYPE="hidden" VALUE="$id">
153 <TD><SELECT NAME="tax_group" onChange="this.form.submit()">
156 my $sql = "SELECT DISTINCT ".
157 qq!substring(description from '#"%#" : % : % : %' for '#'),!.
158 qq!substring(description from '#"%#" : % : % : %' for '#')!.
159 "FROM part_pkg_taxproduct ORDER BY 1";
162 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
163 $sth->execute or die $sth->errstr;
164 for (['', '(choose group)'], @{$sth->fetchall_arrayref}) {
165 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
166 ($_->[0] eq $tax_group ? " SELECTED" : "").
173 <TD><SELECT NAME="tax_item" onChange="this.form.submit()">
176 $sql = "SELECT DISTINCT ".
177 qq!substring(description from '% : #"%#" : %: %' for '#'),!.
178 qq!substring(description from '% : #"%#" : %: %' for '#')!.
179 "FROM part_pkg_taxproduct ORDER BY 1";
181 $sth = $dbh->prepare($sql) or die $dbh->errstr;
182 $sth->execute or die $sth->errstr;
183 for (@{$sth->fetchall_arrayref}) {
184 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
185 ($_->[0] eq $tax_item ? " SELECTED" : "").
186 '">'. ($_->[0] ? $_->[1] : '(choose item)');
192 <TD><SELECT NAME="tax_provider" onChange="this.form.submit()">
195 $sql = "SELECT DISTINCT ".
196 qq!substring(description from '% : % : #"%#" : %' for '#'),!.
197 qq!substring(description from '% : % : #"%#" : %' for '#')!.
198 "FROM part_pkg_taxproduct ORDER BY 1";
200 $sth = $dbh->prepare($sql) or die $dbh->errstr;
201 $sth->execute or die $sth->errstr;
202 for (@{$sth->fetchall_arrayref}) {
203 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
204 ($_->[0] eq $tax_provider ? " SELECTED" : "").
205 '">'. ($_->[0] ? $_->[1] : '(choose provider type)');
211 <TD><SELECT NAME="tax_customer" onChange="this.form.submit()">
214 $sql = "SELECT DISTINCT ".
215 qq!substring(description from '% : % : % : #"%#"' for '#'),!.
216 qq!substring(description from '% : % : % : #"%#"' for '#')!.
217 "FROM part_pkg_taxproduct ORDER BY 1";
219 $sth = $dbh->prepare($sql) or die $dbh->errstr;
220 $sth->execute or die $sth->errstr;
221 for (@{$sth->fetchall_arrayref}) {
222 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
223 ($_->[0] eq $tax_customer ? " SELECTED" : "").
224 '">'. ($_->[0] ? $_->[1] : '(choose customer type)');