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');
36 if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
38 $title = "$data_vendor";
40 $cgi->delete('data_vendor');
42 $title = " for $title" if $title;
44 my $taxproductnum = $1
45 if ( $cgi->param('taxproductnum') =~ /^(\d+)$/ );
47 if ( $cgi->param('tax_group') =~ /^([- \w\(\).\/]+)$/ );
49 if ( $cgi->param('tax_item') =~ /^([- \w\(\).\/&%]+)$/ );
51 if ( $cgi->param('tax_provider') =~ /^([ \w]+)$/ );
53 if ( $cgi->param('tax_customer') =~ /^([ \w]+)$/ );
55 if ( $cgi->param('id') =~ /^([ \w]+)$/ );
57 my $select_onclick = sub {
59 my $taxnum = $row->taxproductnum;
60 my $desc = $row->description;
61 "parent.document.getElementById('$id').value = $taxnum;".
62 "parent.document.getElementById('${id}_description').value = '$desc';".
67 my $selected_part_pkg_taxproduct;
69 $selected_part_pkg_taxproduct =
70 qsearchs('part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum });
76 $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
79 if ($tax_group || $tax_item || $tax_customer || $tax_provider) {
80 my $compare = "LIKE '". ( $tax_group || "%" ). " : ". ( $tax_item || "%" ). " : ".
81 ( $tax_provider || "%" ). " : ". ( $tax_customer || "%" ). "'";
82 $compare = "= '$tax_group:$tax_item:$tax_provider:$tax_customer'"
83 if ($tax_group && $tax_item && $tax_provider && $tax_customer);
85 $extra_sql .= ($extra_sql =~ /WHERE/ ? ' AND ' : ' WHERE ').
86 "description $compare";
89 $cgi->delete('tax_group');
90 $cgi->delete('tax_item');
91 $cgi->delete('tax_provider');
92 $cgi->delete('tax_customer');
95 if ( $tax_group || $tax_item || $tax_provider || $tax_customer ) {
96 push @menubar, 'View all tax products' => $p.'browse/part_pkg_taxproduct.cgi';
99 $cgi->param('dummy', 1);
101 #restore this so pagination works
102 $cgi->param('data_vendor', $data_vendor) if $data_vendor;
103 $cgi->param('tax_group', $tax_group) if $tax_group;
104 $cgi->param('tax_item', $tax_item ) if $tax_item;
105 $cgi->param('tax_provider', $tax_provider ) if $tax_provider;
106 $cgi->param('tax_customer', $tax_customer ) if $tax_customer;
108 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql";
110 my @header = ( 'Data Vendor', 'Group', 'Item', 'Provider', 'Customer' );
111 my @links = ( $select_link,
117 my @link_onclicks = ( $select_onclick,
127 sub { shift->description =~ /^(.*):.*:.*:.*$/; $1;},
128 sub { shift->description =~ /^.*:(.*):.*:.*$/; $1;},
129 sub { shift->description =~ /^.*:.*:(.*):.*$/; $1;},
130 sub { shift->description =~ /^.*:.*:.*:(.*)$/; $1;},
135 $html_init = '<TABLE><TR><TD>Current tax product: </TD><TD>'.
136 $selected_part_pkg_taxproduct->description.
137 '</TD></TR></TABLE><BR><BR>'
138 if $selected_part_pkg_taxproduct;
140 my $type = $cgi->param('_type');
143 <INPUT NAME="_type" TYPE="hidden" VALUE="$type">
144 <INPUT NAME="taxproductnum" TYPE="hidden" VALUE="$taxproductnum">
145 <INPUT NAME="id" TYPE="hidden" VALUE="$id">
148 <TD><SELECT NAME="data_vendor" onChange="this.form.submit()">
151 my $sql = "SELECT DISTINCT data_vendor FROM part_pkg_taxproduct ORDER BY data_vendor";
153 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
154 $sth->execute or die $sth->errstr;
155 for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) {
156 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
157 ($_->[0] eq $data_vendor ? " SELECTED" : "").
163 <!-- cch specific -->
164 <TD><SELECT NAME="tax_group" onChange="this.form.submit()">
167 $sql = "SELECT DISTINCT ".
168 qq!substring(description from '#"%#" : % : % : %' for '#'),!.
169 qq!substring(description from '#"%#" : % : % : %' for '#')!.
170 "FROM part_pkg_taxproduct ORDER BY 1";
172 $sth = $dbh->prepare($sql) or die $dbh->errstr;
173 $sth->execute or die $sth->errstr;
174 for (['', '(choose group)'], @{$sth->fetchall_arrayref}) {
175 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
176 ($_->[0] eq $tax_group ? " SELECTED" : "").
183 <TD><SELECT NAME="tax_item" onChange="this.form.submit()">
186 $sql = "SELECT DISTINCT ".
187 qq!substring(description from '% : #"%#" : %: %' for '#'),!.
188 qq!substring(description from '% : #"%#" : %: %' for '#')!.
189 "FROM part_pkg_taxproduct ORDER BY 1";
191 $sth = $dbh->prepare($sql) or die $dbh->errstr;
192 $sth->execute or die $sth->errstr;
193 for (@{$sth->fetchall_arrayref}) {
194 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
195 ($_->[0] eq $tax_item ? " SELECTED" : "").
196 '">'. ($_->[0] ? $_->[1] : '(choose item)');
202 <TD><SELECT NAME="tax_provider" onChange="this.form.submit()">
205 $sql = "SELECT DISTINCT ".
206 qq!substring(description from '% : % : #"%#" : %' for '#'),!.
207 qq!substring(description from '% : % : #"%#" : %' for '#')!.
208 "FROM part_pkg_taxproduct ORDER BY 1";
210 $sth = $dbh->prepare($sql) or die $dbh->errstr;
211 $sth->execute or die $sth->errstr;
212 for (@{$sth->fetchall_arrayref}) {
213 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
214 ($_->[0] eq $tax_provider ? " SELECTED" : "").
215 '">'. ($_->[0] ? $_->[1] : '(choose provider type)');
221 <TD><SELECT NAME="tax_customer" onChange="this.form.submit()">
224 $sql = "SELECT DISTINCT ".
225 qq!substring(description from '% : % : % : #"%#"' for '#'),!.
226 qq!substring(description from '% : % : % : #"%#"' for '#')!.
227 "FROM part_pkg_taxproduct ORDER BY 1";
229 $sth = $dbh->prepare($sql) or die $dbh->errstr;
230 $sth->execute or die $sth->errstr;
231 for (@{$sth->fetchall_arrayref}) {
232 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
233 ($_->[0] eq $tax_customer ? " SELECTED" : "").
234 '">'. ($_->[0] ? $_->[1] : '(choose customer type)');