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 $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 });
83 $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
86 if ($tax_group || $tax_item || $tax_customer || $tax_provider) {
87 my $compare = "LIKE '". ( $tax_group || "%" ). " : ". ( $tax_item || "%" ). " : ".
88 ( $tax_provider || "%" ). " : ". ( $tax_customer || "%" ). "'";
89 $compare = "= '$tax_group:$tax_item:$tax_provider:$tax_customer'"
90 if ($tax_group && $tax_item && $tax_provider && $tax_customer);
92 $extra_sql .= ($extra_sql =~ /WHERE/ ? ' AND ' : ' WHERE ').
93 "description $compare";
96 $cgi->delete('tax_group');
97 $cgi->delete('tax_item');
98 $cgi->delete('tax_provider');
99 $cgi->delete('tax_customer');
102 if ( $tax_group || $tax_item || $tax_provider || $tax_customer ) {
103 push @menubar, 'View all tax products' => $p.'browse/part_pkg_taxproduct.cgi';
106 $cgi->param('dummy', 1);
108 #restore this so pagination works
109 $cgi->param('data_vendor', $data_vendor) if $data_vendor;
110 $cgi->param('tax_group', $tax_group) if $tax_group;
111 $cgi->param('tax_item', $tax_item ) if $tax_item;
112 $cgi->param('tax_provider', $tax_provider ) if $tax_provider;
113 $cgi->param('tax_customer', $tax_customer ) if $tax_customer;
115 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql";
117 my @header = ( 'Data Vendor', 'Group', 'Item', 'Provider', 'Customer' );
118 my @links = ( $select_link,
124 my @link_onclicks = ( $select_onclick,
134 sub { shift->description =~ /^(.*):.*:.*:.*$/; $1;},
135 sub { shift->description =~ /^.*:(.*):.*:.*$/; $1;},
136 sub { shift->description =~ /^.*:.*:(.*):.*$/; $1;},
137 sub { shift->description =~ /^.*:.*:.*:(.*)$/; $1;},
142 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
143 $html_init = '<TABLE><TR><TD><A HREF="javascript:void(0)" '.
144 qq!onClick="$remove_onclick">(remove)</A> !.
145 'Current tax product: </TD><TD>'.
146 $selected_part_pkg_taxproduct->description.
147 '</TD></TR></TABLE><BR><BR>'
148 if $selected_part_pkg_taxproduct;
150 my $type = $cgi->param('_type');
153 <INPUT NAME="_type" TYPE="hidden" VALUE="$type">
154 <INPUT NAME="taxproductnum" TYPE="hidden" VALUE="$taxproductnum">
155 <INPUT NAME="id" TYPE="hidden" VALUE="$id">
158 <TD><SELECT NAME="data_vendor" onChange="this.form.submit()">
161 my $sql = "SELECT DISTINCT data_vendor FROM part_pkg_taxproduct ORDER BY data_vendor";
163 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
164 $sth->execute or die $sth->errstr;
165 for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) {
166 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
167 ($_->[0] eq $data_vendor ? " SELECTED" : "").
173 <!-- cch specific -->
174 <TD><SELECT NAME="tax_group" onChange="this.form.submit()">
177 $sql = "SELECT DISTINCT ".
178 qq!substring(description from '#"%#" : % : % : %' for '#'),!.
179 qq!substring(description from '#"%#" : % : % : %' for '#')!.
180 "FROM part_pkg_taxproduct ORDER BY 1";
182 $sth = $dbh->prepare($sql) or die $dbh->errstr;
183 $sth->execute or die $sth->errstr;
184 for (['', '(choose group)'], @{$sth->fetchall_arrayref}) {
185 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
186 ($_->[0] eq $tax_group ? " SELECTED" : "").
193 <TD><SELECT NAME="tax_item" onChange="this.form.submit()">
196 $sql = "SELECT DISTINCT ".
197 qq!substring(description from '% : #"%#" : %: %' for '#'),!.
198 qq!substring(description from '% : #"%#" : %: %' for '#')!.
199 "FROM part_pkg_taxproduct ORDER BY 1";
201 $sth = $dbh->prepare($sql) or die $dbh->errstr;
202 $sth->execute or die $sth->errstr;
203 for (@{$sth->fetchall_arrayref}) {
204 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
205 ($_->[0] eq $tax_item ? " SELECTED" : "").
206 '">'. ($_->[0] ? $_->[1] : '(choose item)');
212 <TD><SELECT NAME="tax_provider" onChange="this.form.submit()">
215 $sql = "SELECT DISTINCT ".
216 qq!substring(description from '% : % : #"%#" : %' for '#'),!.
217 qq!substring(description from '% : % : #"%#" : %' for '#')!.
218 "FROM part_pkg_taxproduct ORDER BY 1";
220 $sth = $dbh->prepare($sql) or die $dbh->errstr;
221 $sth->execute or die $sth->errstr;
222 for (@{$sth->fetchall_arrayref}) {
223 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
224 ($_->[0] eq $tax_provider ? " SELECTED" : "").
225 '">'. ($_->[0] ? $_->[1] : '(choose provider type)');
231 <TD><SELECT NAME="tax_customer" onChange="this.form.submit()">
234 $sql = "SELECT DISTINCT ".
235 qq!substring(description from '% : % : % : #"%#"' for '#'),!.
236 qq!substring(description from '% : % : % : #"%#"' for '#')!.
237 "FROM part_pkg_taxproduct ORDER BY 1";
239 $sth = $dbh->prepare($sql) or die $dbh->errstr;
240 $sth->execute or die $sth->errstr;
241 for (@{$sth->fetchall_arrayref}) {
242 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
243 ($_->[0] eq $tax_customer ? " SELECTED" : "").
244 '">'. ($_->[0] ? $_->[1] : '(choose customer type)');