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_posttotal' => $html_posttotal,
7 'html_form' => '<FORM NAME="taxesForm">',
8 'html_foot' => $html_foot,
10 'table' => 'cust_main_county',
11 'hashref' => $hashref,
13 'ORDER BY country, state, county, taxclass',
15 'count_query' => $count_query,
17 'header2' => \@header2,
21 'cell_style' => \@cell_style,
23 'link_onclicks' => \@link_onclicks,
27 % # <FONT SIZE=-1><A HREF="<% $p %>edit/process/cust_main_county-collapse.cgi?<% $hashref->{taxnum} %>">collapse state</A></FONT>
32 my $conf = new FS::Conf;
33 my $money_char = $conf->config('money_char') || '$';
35 my $exempt_sub = sub {
36 my $cust_main_county = shift;
40 sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount )
41 if $cust_main_county->exempt_amount > 0;
43 push @exempt, 'Setup fee'
44 if $cust_main_county->setuptax =~ /^Y$/i;
46 push @exempt, 'Recurring fee'
47 if $cust_main_county->recurtax =~ /^Y$/i;
49 [ map [ {'data'=>$_} ], @exempt ];
54 my $cell_style_sub = sub {
56 if ( $oldrow ne $row ) {
58 if ( $oldrow->country ne $row->country ) {
59 $cell_style = 'border-top:1px solid #000000';
60 } elsif ( $oldrow->state ne $row->state ) {
61 $cell_style = 'border-top:1px solid #cccccc'; #default?
62 } elsif ( $oldrow->state eq $row->state ) {
63 #$cell_style = 'border-top:dashed 1px dark gray';
64 $cell_style = 'border-top:1px dashed #cccccc';
72 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
73 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
75 my $edit_onclick = sub {
77 my $taxnum = $row->taxnum;
78 include( '/elements/popup_link_onclick.html',
79 'action' => "${p}edit/cust_main_county.html?$taxnum",
80 'actionlabel' => 'Edit tax rate',
82 #default# 'width' => 540,
83 #default# 'color' => '#333399',
90 my $taxnum = $param{'row'}->taxnum;
91 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
94 include( '/elements/popup_link.html',
95 'label' => $param{'label'},
97 'actionlabel' => $param{'desc'},
99 #default# 'width' => 540,
100 #default# 'color' => '#333399',
105 sub separate_taxclasses_link {
107 my $taxnum = $row->taxnum;
108 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
110 qq!<FONT SIZE="-1"><A HREF="$url">!;
117 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
119 #my $conf = new FS::Conf;
120 #my $money_char = $conf->config('money_char') || '$';
121 my $enable_taxclasses = $conf->exists('enable_taxclasses');
126 "Click on <u>add states</u> to specify a country's tax rates by state or province.
127 <BR>Click on <u>add counties</u> to specify a state's tax rates by county.";
128 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
129 if $enable_taxclasses;
130 $html_init .= '<BR><BR>';
132 $html_init .= include('/elements/init_overlib.html');
137 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
141 $cgi->delete('country');
144 if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
146 $title = "$state, $title";
148 $cgi->delete('state');
151 if ( $country && $state &&
152 $cgi->param('county') =~
153 /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
157 if ( $county eq '__NONE__' ) {
158 $title = "No county, $title";
160 $title = "$county county, $title";
163 $cgi->delete('county');
165 $title = " for $title" if $title;
168 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
170 $title .= " for $taxclass tax class";
172 $cgi->delete('taxclass');
174 if ( $country || $taxclass ) {
175 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
178 $cgi->param('dummy', 1);
181 "window.location = '". $cgi->self_url.
182 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
183 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
184 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
186 #restore this so pagination works
187 $cgi->param('country', $country) if $country;
188 $cgi->param('state', $state ) if $state;
189 $cgi->param('county', $county ) if $county;
190 $cgi->param('taxclass', $county ) if $taxclass;
193 '<BR>( show country: '.
194 include('/elements/select-country.html',
195 'country' => $country,
196 'onchange' => $filter_change,
197 'empty_label' => '(all)',
198 'disable_empty' => 0,
199 'disable_stateupdate' => 1,
202 my %states_hash = $country ? states_hash($country) : ();
203 if ( scalar(keys(%states_hash)) > 1 ) {
206 include('/elements/select-state.html',
207 'country' => $country,
209 'onchange' => $filter_change,
210 'empty_label' => '(all)',
211 'disable_empty' => 0,
212 'disable_countyupdate' => 1,
216 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
217 ' <OPTION VALUE="" SELECTED>'.
221 my @counties = ( $country && $state ) ? counties($state, $country) : ();
222 if ( scalar(@counties) > 1 ) {
225 include('/elements/select-county.html',
226 'country' => $country,
229 'onchange' => $filter_change,
230 'empty_label' => '(all)',
231 'empty_data_label' => '(none)',
232 'empty_data_value' => '__NONE__',
233 'disable_empty' => 0,
234 'disable_countyupdate' => 1,
238 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
239 ' <OPTION VALUE="" SELECTED>'.
243 $html_posttotal .= ' )';
245 my $bulk_popup_link =
246 include( '/elements/popup_link_onclick.html',
247 'action' => "${p}edit/bulk-cust_main_county.html?MAGIC_taxnum_MAGIC",
248 'actionlabel' => 'Bulk add new tax',
251 #default# 'width' => 540,
252 #default# 'color' => '#333399',
255 my $html_foot = <<END;
256 <SCRIPT TYPE="text/javascript">
258 function setAll(setTo) {
259 theForm = document.taxesForm;
260 for (i=0,n=theForm.elements.length;i<n;i++) {
261 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
262 theForm.elements[i].checked = setTo;
267 function toggleAll() {
268 theForm = document.taxesForm;
269 for (i=0,n=theForm.elements.length;i<n;i++) {
270 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
271 if ( theForm.elements[i].checked == true ) {
272 theForm.elements[i].checked = false;
274 theForm.elements[i].checked = true;
280 function bulkPopup() {
281 var bulk_popup_link = "$bulk_popup_link";
283 theForm = document.taxesForm;
284 for (i=0,n=theForm.elements.length;i<n;i++) {
285 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
286 && theForm.elements[i].checked == true
288 var name = theForm.elements[i].name;
289 var taxnum = name.replace(/cust_main_county/, '');
290 if ( bulkstring != '' ) {
291 bulkstring = bulkstring + ',';
293 bulkstring = bulkstring + taxnum;
297 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
298 alert('Too many selections'); // should do some session thing...
301 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
302 eval(bulk_popup_link);
308 <A HREF="javascript:setAll(true)">select all</A> |
309 <A HREF="javascript:setAll(false)">unselect all</A> |
310 <A HREF="javascript:toggleAll()">toggle all</A>
312 <A HREF="javascript:void(0);" onClick="bulkPopup();">Add new tax to selected</A>
317 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
319 $hashref->{'country'} = $country;
320 $count_query .= ' WHERE country = '. dbh->quote($country);
323 $hashref->{'state'} = $state;
324 $count_query .= ' AND state = '. dbh->quote($state);
327 if ( $county eq '__NONE__' ) {
328 $hashref->{'county'} = '';
329 $count_query .= " AND ( county = '' OR county IS NULL ) ";
331 $hashref->{'county'} = $county;
332 $count_query .= ' AND county = '. dbh->quote($county);
336 $hashref->{'taxclass'} = $taxclass;
337 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
338 ' taxclass = '. dbh->quote($taxclass);
344 my @header = ( 'Country', 'State/Province', 'County',);
345 my @header2 = ( '', '', '', );
346 my @links = ( '', '', '', );
347 my @link_onclicks = ( '', '', '', );
351 sub { my $country = shift->country;
352 code2country($country). " ($country)";
354 sub { state_label($_[0]->state, $_[0]->country).
357 : ' '. expand_link( desc => 'Add States',
359 label => 'add states',
363 sub { $_[0]->county || '(all) '.
364 expand_link( desc => 'Add Counties',
366 label => 'add counties',
373 sub { shift->state ? '000000' : '999999' },
374 sub { shift->county ? '000000' : '999999' },
377 if ( $conf->exists('enable_taxclasses') ) {
378 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
379 push @header2, '(per-package classification)';
380 push @fields, sub { $_[0]->taxclass || '(all) '.
381 separate_taxclasses_link($_[0], 'Separate Taxclasses').
382 'separate taxclasses</A></FONT>'
384 push @color, sub { shift->taxclass ? '000000' : '999999' };
386 push @link_onclicks, '';
399 '(printed on invoices)',
407 my $cust_main_county = shift;
410 if ( $cb_oldrow->country ne $cust_main_county->country
411 || $cb_oldrow->state ne $cust_main_county->state
412 || $cb_oldrow->county ne $cust_main_county->county
413 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
423 $cb_oldrow = $cust_main_county;
426 my $taxnum = $cust_main_county->taxnum;
427 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
435 sub { shift->taxname || 'Tax' },
436 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
442 sub { shift->taxname ? '000000' : '666666' },
443 sub { shift->tax ? '000000' : '666666' },
449 my @cell_style = map $cell_style_sub, (1..scalar(@header));
451 push @links, '', '', $edit_link, '';
452 push @link_onclicks, '', '', $edit_onclick, '';