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,
8 'disabled_statuspos' => 5,
10 'count_query' => $count_query,
12 'header2' => \@header2,
16 'cell_style' => \@cell_style,
18 'link_onclicks' => \@link_onclicks,
23 my $conf = new FS::Conf;
24 my $money_char = $conf->config('money_char') || '$';
29 my $units = $tax_rate->unittype_name;
30 $units =~ s/ / /g;
34 ($tax_rate->tax * 100). '% <FONT SIZE="-1">(edit)</FONT>'
35 if $tax_rate->tax > 0 || $tax_rate->taxbase > 0;
37 ($tax_rate->excessrate * 100). '% <FONT SIZE="-1">(edit)</FONT>'
38 if $tax_rate->excessrate > 0;
40 $money_char. $tax_rate->fee.
41 qq! per $units<FONT SIZE="-1">(edit)</FONT>!
42 if $tax_rate->fee > 0 || $tax_rate->feebase > 0;
44 $money_char. $tax_rate->excessfee.
45 qq! per $units<FONT SIZE="-1">(edit)</FONT>!
46 if $tax_rate->excessfee > 0;
49 [ map [ {'data'=>$_} ], @rate ];
55 my $maxtype = $tax_rate->maxtype_name;
56 $maxtype =~ s/ / /g;
58 my $units = $tax_rate->unittype_name;
59 $units =~ s/ / /g;
63 sprintf("$money_char%.2f %s", $tax_rate->taxbase, $maxtype )
64 if $tax_rate->taxbase > 0;
66 sprintf("$money_char%.2f tax", $tax_rate->taxmax )
67 if $tax_rate->taxmax > 0;
69 $tax_rate->feebase. " $units". ($tax_rate->feebase == 1 ? '' : 's')
70 if $tax_rate->feebase > 0;
72 $tax_rate->feemax. " $units". ($tax_rate->feebase == 1 ? '' : 's')
73 if $tax_rate->feemax > 0;
75 push @limit, 'Excluding setup fee'
76 if $tax_rate->setuptax =~ /^Y$/i;
78 push @limit, 'Excluding recurring fee'
79 if $tax_rate->recurtax =~ /^Y$/i;
81 [ map [ {'data'=>$_} ], @limit ];
86 my $cell_style_sub = sub {
88 if ( $oldrow ne $row ) {
90 if ( $oldrow->country ne $row->country ) {
91 $cell_style = 'border-top:1px solid #000000';
92 } elsif ( $oldrow->state ne $row->state ) {
93 $cell_style = 'border-top:1px solid #cccccc'; #default?
94 } elsif ( $oldrow->state eq $row->state ) {
95 #$cell_style = 'border-top:dashed 1px dark gray';
96 $cell_style = 'border-top:1px dashed #cccccc';
104 my $select_link = [ 'javascript:void(0);', sub { ''; } ];
106 my $select_onclick = sub {
108 my $taxnum = $row->taxnum;
109 my $color = '#333399';
110 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;!;
117 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
122 my $data_vendor = '';
123 if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) {
125 $title = "$data_vendor";
127 $cgi->delete('data_vendor');
130 if ( $cgi->param('geocode') =~ /^(\w+)$/ ) {
132 $title = " geocode $geocode";
134 $cgi->delete('geocode');
136 $title = " for $title" if $title;
138 my $taxclassnum = '';
139 if ( $cgi->param('taxclassnum') =~ /^(\d+)$/ ) {
141 my $tax_class = qsearchs('tax_class', {'taxclassnum' => $taxclassnum});
143 $title .= " for ". $tax_class->taxclass.
144 " (". $tax_class->description. ") tax class";
149 $cgi->delete('taxclassnum');
152 if ( $cgi->param('tax_type') =~ /^(\d+)$/ );
154 if ( $cgi->param('tax_cat') =~ /^(\d+)$/ );
156 if ($tax_type || $tax_cat ) {
157 my $compare = "LIKE '". ( $tax_type || "%" ). ":". ( $tax_cat || "%" ). "'";
158 $compare = "= '$tax_type:$tax_cat'" if ($tax_type && $tax_cat);
160 qsearch({ 'table' => 'tax_class',
162 'extra_sql' => "WHERE taxclass $compare",
165 $tax_class[0]->description =~ /^(.*):(.*)/;
167 $title .= " $tax_type ($1) tax type" if $tax_type;
168 $title .= " and" if ($tax_type && $tax_cat);
169 $title .= " $tax_cat ($2) tax category" if $tax_cat;
175 $cgi->delete('tax_type');
176 $cgi->delete('tax_cat');
178 if ( $geocode || $taxclassnum ) {
179 push @menubar, 'View all tax rates' => $p.'browse/tax_rate.cgi';
182 $cgi->param('dummy', 1);
184 #restore this so pagination works
185 $cgi->param('data_vendor', $data_vendor) if $data_vendor;
186 $cgi->param('geocode', $geocode) if $geocode;
187 $cgi->param('taxclassnum', $taxclassnum ) if $taxclassnum;
188 $cgi->param('tax_type', $tax_type ) if $tax_type;
189 $cgi->param('tax_cat', $tax_cat ) if $tax_cat;
191 my $html_form = include('/elements/init_overlib.html'). '<BR><BR>'.
194 include('/elements/popup_link.html',
196 'action' => $p. "misc/enable_or_disable_tax.html?action=$_&".
198 'label' => ucfirst($_). ' all these taxes',
199 'actionlabel' => ucfirst($_). ' taxes',
206 my ($query, $count_query) = FS::tax_rate::browse_queries(scalar($cgi->Vars));
210 my @header = ( 'Location Code', );
211 my @header2 = ( '', );
213 my @link_onclicks = ( '', );
224 push @header, qq!Tax class (<A HREF="${p}edit/tax_class.html">add new</A>)!;
225 push @header2, '(per-tax classification)';
226 push @fields, 'taxclass_description';
227 push @color, '000000';
229 push @link_onclicks, '';
232 push @header, 'Tax name',
237 push @header2, '(printed on invoices)',
243 sub { shift->taxname || 'Tax' },
249 sub { shift->taxname ? '000000' : '666666' },
250 sub { shift->tax ? '000000' : '666666' },
256 my @cell_style = map $cell_style_sub, (1..scalar(@header));
258 push @links, '', $select_link, '';
259 push @link_onclicks, '', $select_onclick, '';
264 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws.js"></SCRIPT>
265 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_iframe.js"></SCRIPT>
266 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_draggable.js"></SCRIPT>
267 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/iframecontentmws.js"></SCRIPT>
275 <TD><SELECT NAME="data_vendor" onChange="this.form.submit()">
278 my $sql = "SELECT DISTINCT data_vendor FROM tax_rate ORDER BY data_vendor";
280 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
281 $sth->execute or die $sth->errstr;
282 for (['(choose data vendor)'], @{$sth->fetchall_arrayref}) {
283 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
284 ($_->[0] eq $data_vendor ? " SELECTED" : "").
290 <TD><INPUT NAME="geocode" TYPE="text" SIZE="12" VALUE="$geocode"></TD>
293 <TD><INPUT NAME="taxclassnum" TYPE="text" SIZE="12" VALUE="$taxclassnum"></TD>
294 <TD><INPUT TYPE="submit" VALUE="Filter by tax_class"></TD>
297 <!-- cch specific -->
298 <TD><SELECT NAME="tax_type" onChange="this.form.submit()">
301 $sql = "SELECT DISTINCT ".
302 "substring(taxclass from 1 for position(':' in taxclass)-1),".
303 "substring(description from 1 for position(':' in description)-1) ".
304 "FROM tax_class WHERE data_vendor='cch' ORDER BY 2";
306 $sth = $dbh->prepare($sql) or die $dbh->errstr;
307 $sth->execute or die $sth->errstr;
308 for (['', '(choose tax type)'], @{$sth->fetchall_arrayref}) {
309 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
310 ($_->[0] eq $tax_type ? " SELECTED" : "").
317 <TD><SELECT NAME="tax_cat" onChange="this.form.submit()">
320 $sql = "SELECT DISTINCT ".
321 "substring(taxclass from position(':' in taxclass)+1),".
322 "substring(description from position(':' in description)+1) ".
323 "from tax_class WHERE data_vendor='cch' ORDER BY 2";
325 $sth = $dbh->prepare($sql) or die $dbh->errstr;
326 $sth->execute or die $sth->errstr;
327 for (['', '(choose tax category)'], @{$sth->fetchall_arrayref}) {
328 $html_init .= '<OPTION VALUE="'. $_->[0]. '"'.
329 ($_->[0] eq $tax_cat ? " SELECTED" : "").
339 <TD><INPUT TYPE="submit" VALUE="Filter by geocode"></TD>