1 <% include( 'elements/browse.html',
2 'title' => "Tax Rates $title",
3 'name_singular' => 'tax rate',
4 'menubar' => \@menubar,
5 'html_init' => $html_init,
6 'html_form' => $html_form,
10 'order_by' => 'ORDER BY geocode, taxclassnum',
11 'extra_sql' => $extra_sql,
13 'count_query' => $count_query,
15 'header2' => \@header2,
19 'cell_style' => \@cell_style,
21 'link_onclicks' => \@link_onclicks,
26 my $conf = new FS::Conf;
27 my $money_char = $conf->config('money_char') || '$';
32 my $units = $tax_rate->unittype_name;
33 $units =~ s/ / /g;
37 ($tax_rate->tax * 100). '% <FONT SIZE="-1">(edit)</FONT>'
38 if $tax_rate->tax > 0 || $tax_rate->taxbase > 0;
40 ($tax_rate->excessrate * 100). '% <FONT SIZE="-1">(edit)</FONT>'
41 if $tax_rate->excessrate > 0;
43 $money_char. $tax_rate->fee.
44 qq! per $units<FONT SIZE="-1">(edit)</FONT>!
45 if $tax_rate->fee > 0 || $tax_rate->feebase > 0;
47 $money_char. $tax_rate->excessfee.
48 qq! per $units<FONT SIZE="-1">(edit)</FONT>!
49 if $tax_rate->excessfee > 0;
52 [ map [ {'data'=>$_} ], @rate ];
58 my $maxtype = $tax_rate->maxtype_name;
59 $maxtype =~ s/ / /g;
61 my $units = $tax_rate->unittype_name;
62 $units =~ s/ / /g;
66 sprintf("$money_char%.2f %s", $tax_rate->taxbase, $maxtype )
67 if $tax_rate->taxbase > 0;
69 sprintf("$money_char%.2f tax", $tax_rate->taxmax )
70 if $tax_rate->taxmax > 0;
72 $tax_rate->feebase. " $units". ($tax_rate->feebase == 1 ? '' : 's')
73 if $tax_rate->feebase > 0;
75 $tax_rate->feemax. " $units". ($tax_rate->feebase == 1 ? '' : 's')
76 if $tax_rate->feemax > 0;
78 push @limit, 'Excluding setup fee'
79 if $tax_rate->setuptax =~ /^Y$/i;
81 push @limit, 'Excluding recurring fee'
82 if $tax_rate->recurtax =~ /^Y$/i;
84 [ map [ {'data'=>$_} ], @limit ];
89 my $cell_style_sub = sub {
91 if ( $oldrow ne $row ) {
93 if ( $oldrow->country ne $row->country ) {
94 $cell_style = 'border-top:1px solid #000000';
95 } elsif ( $oldrow->state ne $row->state ) {
96 $cell_style = 'border-top:1px solid #cccccc'; #default?
97 } elsif ( $oldrow->state eq $row->state ) {
98 #$cell_style = 'border-top:dashed 1px dark gray';
99 $cell_style = 'border-top:1px dashed #cccccc';
107 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
109 my $select_onclick = sub {
111 my $taxnum = $row->taxnum;
112 my $color = '#333399';
113 qq!overlib( OLiframeContent('${p}edit/tax_rate.html?$taxnum', 540, 620, 'edit_tax_rate_popup' ), CAPTION, 'Edit tax rate', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;!;
120 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
125 my $data_vendor = '';
126 if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
128 $title = "$data_vendor";
130 $cgi->delete('data_vendor');
133 if ( $cgi->param('geocode') =~ /^(\w+)$/ ) {
135 $title = " geocode $geocode";
137 $cgi->delete('geocode');
139 $title = " for $title" if $title;
141 my $taxclassnum = '';
142 if ( $cgi->param('taxclassnum') =~ /^(\d+)$/ ) {
144 my $tax_class = qsearchs('tax_class', {'taxclassnum' => $taxclassnum});
146 $title .= " for ". $tax_class->taxclass.
147 " (". $tax_class->description. ") tax class";
152 $cgi->delete('taxclassnum');
155 if ( $cgi->param('tax_type') =~ /^(\d+)$/ );
157 if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
159 my @taxclassnum = ();
160 if ($tax_type || $tax_cat ) {
161 my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
162 $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
164 qsearch({ 'table' => 'tax_class',
166 'extra_sql' => "WHERE taxclass $compare",
169 @taxclassnum = map { $_->taxclassnum } @tax_class;
170 $tax_class[0]->description =~ /^(.*):(.*)/;
172 $title .= " $tax_type ($1) tax type" if $tax_type;
173 $title .= " and" if ($tax_type && $tax_cat);
174 $title .= " $tax_cat ($2) tax category" if $tax_cat;
180 $cgi->delete('tax_type');
181 $cgi->delete('tax_cat');
183 if ( $geocode || $taxclassnum ) {
184 push @menubar, 'View all tax rates' => $p.'browse/tax_rate.cgi';
187 $cgi->param('dummy', 1);
189 #restore this so pagination works
190 $cgi->param('data_vendor', $data_vendor) if $data_vendor;
191 $cgi->param('geocode', $geocode) if $geocode;
192 $cgi->param('taxclassnum', $taxclassnum ) if $taxclassnum;
193 $cgi->param('tax_type', $tax_type ) if $tax_type;
194 $cgi->param('tax_cat', $tax_cat ) if $tax_cat;
196 my $html_form = include('/elements/init_overlib.html'). '<BR><BR>'.
199 include('/elements/popup_link.html',
201 'action' => $p. "misc/enable_or_disable_tax.html?action=$_&".
203 'label' => ucfirst($_). ' all these taxes',
204 'actionlabel' => ucfirst($_). ' taxes',
213 if ( $data_vendor ) {
214 $extra_sql .= ' WHERE data_vendor = '. dbh->quote($data_vendor);
218 $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
219 ' geocode LIKE '. dbh->quote($geocode.'%');
222 if ( $taxclassnum ) {
223 $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
224 ' taxclassnum = '. dbh->quote($taxclassnum);
227 if ( @taxclassnum ) {
228 $extra_sql .= ( $extra_sql =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
229 join(' OR ', map { " taxclassnum = $_ " } @taxclassnum );
232 my $count_query = "SELECT COUNT(*) FROM tax_rate $extra_sql";
236 my @header = ( 'Location Code', );
237 my @header2 = ( '', );
239 my @link_onclicks = ( '', );
250 push @header, qq!Tax class (<A HREF="${p}edit/tax_class.html">add new</A>)!;
251 push @header2, '(per-tax classification)';
252 push @fields, 'taxclass_description';
253 push @color, '000000';
255 push @link_onclicks, '';
258 push @header, 'Tax name',
263 push @header2, '(printed on invoices)',
269 sub { shift->taxname || 'Tax' },
275 sub { shift->taxname ? '000000' : '666666' },
276 sub { shift->tax ? '000000' : '666666' },
282 my @cell_style = map $cell_style_sub, (1..scalar(@header));
284 push @links, '', $select_link, '';
285 push @link_onclicks, '', $select_onclick, '';
290 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws.js"></SCRIPT>
291 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_iframe.js"></SCRIPT>
292 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_draggable.js"></SCRIPT>
293 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/iframecontentmws.js"></SCRIPT>
301 <TD><SELECT NAME="data_vendor" onChange="this.form.submit()">
304 my $sql = "SELECT DISTINCT data_vendor FROM tax_rate ORDER BY data_vendor";
306 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
307 $sth->execute or die $sth->errstr;
308 for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) {
309 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
310 ($_->[0] eq $data_vendor ? " SELECTED" : "").
316 <TD><INPUT NAME="geocode" TYPE="text" SIZE="12" VALUE="$geocode"></TD>
319 <TD><INPUT NAME="taxclassnum" TYPE="text" SIZE="12" VALUE="$taxclassnum"></TD>
320 <TD><INPUT TYPE="submit" VALUE="Filter by tax_class"></TD>
323 <!-- cch specific -->
324 <TD><SELECT NAME="tax_type" onChange="this.form.submit()">
327 $sql = "SELECT DISTINCT ".
328 "substring(taxclass from 1 for position(':' in taxclass)-1),".
329 "substring(description from 1 for position(':' in description)-1) ".
330 "FROM tax_class WHERE data_vendor='cch' ORDER BY 2";
332 $sth = $dbh->prepare($sql) or die $dbh->errstr;
333 $sth->execute or die $sth->errstr;
334 for (['', '(choose tax type)'], @{$sth->fetchall_arrayref}) {
335 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
336 ($_->[0] eq $tax_type ? " SELECTED" : "").
343 <TD><SELECT NAME="tax_cat" onChange="this.form.submit()">
346 $sql = "SELECT DISTINCT ".
347 "substring(taxclass from position(':' in taxclass)+1),".
348 "substring(description from position(':' in description)+1) ".
349 "from tax_class WHERE data_vendor='cch' ORDER BY 2";
351 $sth = $dbh->prepare($sql) or die $dbh->errstr;
352 $sth->execute or die $sth->errstr;
353 for (['', '(choose tax category)'], @{$sth->fetchall_arrayref}) {
354 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
355 ($_->[0] eq $tax_cat ? " SELECTED" : "").
365 <TD><INPUT TYPE="submit" VALUE="Filter by geocode"></TD>