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';
37 if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
39 $title = "$data_vendor";
41 $cgi->delete('data_vendor');
43 $title = " for $title" if $title;
45 my $taxproductnum = $1
46 if ( $cgi->param('taxproductnum') =~ /^(\d+)$/ );
48 if ( $cgi->param('tax_group') =~ /^([- \w\(\).\/]+)$/ );
50 if ( $cgi->param('tax_item') =~ /^([- \w\(\).\/&%]+)$/ );
52 if ( $cgi->param('tax_provider') =~ /^([ \w]+)$/ );
54 if ( $cgi->param('tax_customer') =~ /^([ \w]+)$/ );
56 if ( $cgi->param('id') =~ /^([ \w]+)$/ );
59 if ( $cgi->param('onclick') =~ /^(\w+)$/ );
60 $cgi->delete('onclick');
62 my $remove_onclick = <<EOS
63 parent.document.getElementById('$id').value = '';
64 parent.document.getElementById('${id}_description').value = '';
69 my $select_onclick = sub {
71 my $taxnum = $row->taxproductnum;
72 my $desc = $row->description;
73 "parent.document.getElementById('$id').value = $taxnum;".
74 "parent.document.getElementById('${id}_description').value = '$desc';".
79 my $selected_part_pkg_taxproduct;
81 $selected_part_pkg_taxproduct =
82 qsearchs('part_pkg_taxproduct', { 'taxproductnum' => $taxproductnum });
88 $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
91 if ($tax_group || $tax_item || $tax_customer || $tax_provider) {
92 my $compare = "LIKE '". ( $tax_group || "%" ). " : ". ( $tax_item || "%" ). " : ".
93 ( $tax_provider || "%" ). " : ". ( $tax_customer || "%" ). "'";
94 $compare = "= '$tax_group:$tax_item:$tax_provider:$tax_customer'"
95 if ($tax_group && $tax_item && $tax_provider && $tax_customer);
97 $extra_sql .= ($extra_sql =~ /WHERE/ ? ' AND ' : ' WHERE ').
98 "description $compare";
101 $cgi->delete('tax_group');
102 $cgi->delete('tax_item');
103 $cgi->delete('tax_provider');
104 $cgi->delete('tax_customer');
107 if ( $tax_group || $tax_item || $tax_provider || $tax_customer ) {
108 push @menubar, 'View all tax products' => $p.'browse/part_pkg_taxproduct.cgi';
111 $cgi->param('dummy', 1);
113 #restore this so pagination works
114 $cgi->param('data_vendor', $data_vendor) if $data_vendor;
115 $cgi->param('tax_group', $tax_group) if $tax_group;
116 $cgi->param('tax_item', $tax_item ) if $tax_item;
117 $cgi->param('tax_provider', $tax_provider ) if $tax_provider;
118 $cgi->param('tax_customer', $tax_customer ) if $tax_customer;
119 $cgi->param('onclick', $onclick ) if $onclick;
121 my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql";
123 my @header = ( 'Data Vendor', 'Group', 'Item', 'Provider', 'Customer' );
124 my @links = ( $select_link,
130 my @link_onclicks = ( $select_onclick,
140 sub { shift->description =~ /^(.*):.*:.*:.*$/; $1;},
141 sub { shift->description =~ /^.*:(.*):.*:.*$/; $1;},
142 sub { shift->description =~ /^.*:.*:(.*):.*$/; $1;},
143 sub { shift->description =~ /^.*:.*:.*:(.*)$/; $1;},
148 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
149 $html_init = '<TABLE><TR><TD><A HREF="javascript:void(0)" '.
150 qq!onClick="$remove_onclick">(remove)</A> !.
151 'Current tax product: </TD><TD>'.
152 $selected_part_pkg_taxproduct->description.
153 '</TD></TR></TABLE><BR><BR>'
154 if $selected_part_pkg_taxproduct;
156 my $type = $cgi->param('_type');
159 <INPUT NAME="_type" TYPE="hidden" VALUE="$type">
160 <INPUT NAME="taxproductnum" TYPE="hidden" VALUE="$taxproductnum">
161 <INPUT NAME="onclick" TYPE="hidden" VALUE="$onclick">
162 <INPUT NAME="id" TYPE="hidden" VALUE="$id">
165 <TD><SELECT NAME="data_vendor" onChange="this.form.submit()">
168 my $sql = "SELECT DISTINCT data_vendor FROM part_pkg_taxproduct ORDER BY data_vendor";
170 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
171 $sth->execute or die $sth->errstr;
172 for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) {
173 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
174 ($_->[0] eq $data_vendor ? " SELECTED" : "").
180 <!-- cch specific -->
181 <TD><SELECT NAME="tax_group" onChange="this.form.submit()">
184 $sql = "SELECT DISTINCT ".
185 qq!substring(description from '#"%#" : % : % : %' for '#'),!.
186 qq!substring(description from '#"%#" : % : % : %' for '#')!.
187 "FROM part_pkg_taxproduct ORDER BY 1";
189 $sth = $dbh->prepare($sql) or die $dbh->errstr;
190 $sth->execute or die $sth->errstr;
191 for (['', '(choose group)'], @{$sth->fetchall_arrayref}) {
192 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
193 ($_->[0] eq $tax_group ? " SELECTED" : "").
200 <TD><SELECT NAME="tax_item" onChange="this.form.submit()">
203 $sql = "SELECT DISTINCT ".
204 qq!substring(description from '% : #"%#" : %: %' for '#'),!.
205 qq!substring(description from '% : #"%#" : %: %' for '#')!.
206 "FROM part_pkg_taxproduct ORDER BY 1";
208 $sth = $dbh->prepare($sql) or die $dbh->errstr;
209 $sth->execute or die $sth->errstr;
210 for (@{$sth->fetchall_arrayref}) {
211 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
212 ($_->[0] eq $tax_item ? " SELECTED" : "").
213 '">'. ($_->[0] ? $_->[1] : '(choose item)');
219 <TD><SELECT NAME="tax_provider" onChange="this.form.submit()">
222 $sql = "SELECT DISTINCT ".
223 qq!substring(description from '% : % : #"%#" : %' for '#'),!.
224 qq!substring(description from '% : % : #"%#" : %' for '#')!.
225 "FROM part_pkg_taxproduct ORDER BY 1";
227 $sth = $dbh->prepare($sql) or die $dbh->errstr;
228 $sth->execute or die $sth->errstr;
229 for (@{$sth->fetchall_arrayref}) {
230 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
231 ($_->[0] eq $tax_provider ? " SELECTED" : "").
232 '">'. ($_->[0] ? $_->[1] : '(choose provider type)');
238 <TD><SELECT NAME="tax_customer" onChange="this.form.submit()">
241 $sql = "SELECT DISTINCT ".
242 qq!substring(description from '% : % : % : #"%#"' for '#'),!.
243 qq!substring(description from '% : % : % : #"%#"' for '#')!.
244 "FROM part_pkg_taxproduct ORDER BY 1";
246 $sth = $dbh->prepare($sql) or die $dbh->errstr;
247 $sth->execute or die $sth->errstr;
248 for (@{$sth->fetchall_arrayref}) {
249 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
250 ($_->[0] eq $tax_customer ? " SELECTED" : "").
251 '">'. ($_->[0] ? $_->[1] : '(choose customer type)');