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,
28 my $conf = new FS::Conf;
29 my $money_char = $conf->config('money_char') || '$';
31 my $exempt_sub = sub {
32 my $cust_main_county = shift;
36 sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount )
37 if $cust_main_county->exempt_amount > 0;
39 push @exempt, 'Setup fee'
40 if $cust_main_county->setuptax =~ /^Y$/i;
42 push @exempt, 'Recurring fee'
43 if $cust_main_county->recurtax =~ /^Y$/i;
45 [ map [ {'data'=>$_} ], @exempt ];
50 my $cell_style_sub = sub {
52 if ( $cs_oldrow ne $row ) {
54 if ( $cs_oldrow->country ne $row->country ) {
55 $cell_style = 'border-top:1px solid #000000';
56 } elsif ( $cs_oldrow->state ne $row->state ) {
57 $cell_style = 'border-top:1px solid #cccccc'; #default?
58 } elsif ( $cs_oldrow->state eq $row->state ) {
59 #$cell_style = 'border-top:dashed 1px dark gray';
60 $cell_style = 'border-top:1px dashed #cccccc';
68 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
69 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
71 my $edit_onclick = sub {
73 my $taxnum = $row->taxnum;
74 include( '/elements/popup_link_onclick.html',
75 'action' => "${p}edit/cust_main_county.html?$taxnum",
76 'actionlabel' => 'Edit tax rate',
78 #default# 'width' => 540,
79 #default# 'color' => '#333399',
87 if ( $ex_oldrow eq $param{'row'} ) {
90 $ex_oldrow = $param{'row'};
93 my $taxnum = $param{'row'}->taxnum;
94 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
97 include( '/elements/popup_link.html',
98 'label' => $param{'label'},
100 'actionlabel' => $param{'desc'},
102 #default# 'width' => 540,
103 #default# 'color' => '#333399',
111 my $row = $param{'row'};
112 my $col = $param{'col'};
114 if $col eq 'county' and $row->city
116 'table' => 'cust_main_county',
118 'country' => $row->country,
119 'state' => $row->state,
120 'city' => { op=>'!=', value=>'' },
122 'order_by' => 'LIMIT 1',
125 my %above = ( 'city' => 'county',
129 #XXX can still show the link when you have some counties broken down into
130 #cities and others not :/
132 my $taxnum = $param{'row'}->taxnum;
133 my $url = "${p}edit/process/cust_main_county-collapse.cgi?$taxnum";
134 $url = "javascript:collapse_areyousure('$url', '$col', '$above{$col}')";
136 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
140 sub separate_taxclasses_link {
142 my $taxnum = $row->taxnum;
143 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
145 qq!<FONT SIZE="-1"><A HREF="$url">!;
148 #un-separate taxclasses too
154 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
156 #my $conf = new FS::Conf;
157 #my $money_char = $conf->config('money_char') || '$';
158 my $enable_taxclasses = $conf->exists('enable_taxclasses');
162 my $html_init = <<END;
164 function collapse_areyousure(href,col,above) {
165 if (confirm('Are you sure you want to remove all ' + col + ' tax rates for this ' + above + '?') == true)
166 window.location.href = href;
170 Click on <u>add states</u> to specify a country's tax rates by state or province.
171 <BR>Click on <u>add counties</u> to specify a state's tax rates by county, or <u>remove counties</u> to remove per-county tax rates.
172 <BR>Click on <u>add cities</u> to specify a county's tax rates by city, or <u>remove cities</u> to remove per-city tax rates.
175 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
176 if $enable_taxclasses;
177 $html_init .= '<BR><BR>';
179 $html_init .= include('/elements/init_overlib.html');
184 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
188 $cgi->delete('country');
191 if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
193 $title = "$state, $title";
195 $cgi->delete('state');
198 if ( $country && $state &&
199 $cgi->param('county') =~
200 /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
204 if ( $county eq '__NONE__' ) {
205 $title = "No county, $title";
207 $title = "$county county, $title";
210 $cgi->delete('county');
212 $title = " for $title" if $title;
215 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
217 $title .= " for $taxclass tax class";
219 $cgi->delete('taxclass');
221 if ( $country || $taxclass ) {
222 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
225 $cgi->param('dummy', 1);
228 "window.location = '". $cgi->self_url.
229 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
230 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
231 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
233 #restore this so pagination works
234 $cgi->param('country', $country) if $country;
235 $cgi->param('state', $state ) if $state;
236 $cgi->param('county', $county ) if $county;
237 $cgi->param('taxclass', $county ) if $taxclass;
240 '<BR>( show country: '.
241 include('/elements/select-country.html',
242 'country' => $country,
243 'onchange' => $filter_change,
244 'empty_label' => '(all)',
245 'disable_empty' => 0,
246 'disable_stateupdate' => 1,
249 my %states_hash = $country ? states_hash($country) : ();
250 if ( scalar(keys(%states_hash)) > 1 ) {
253 include('/elements/select-state.html',
254 'country' => $country,
256 'onchange' => $filter_change,
257 'empty_label' => '(all)',
258 'disable_empty' => 0,
259 'disable_countyupdate' => 1,
263 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
264 ' <OPTION VALUE="" SELECTED>'.
268 my @counties = ( $country && $state ) ? counties($state, $country) : ();
269 if ( scalar(@counties) > 1 ) {
272 include('/elements/select-county.html',
273 'country' => $country,
276 'onchange' => $filter_change,
277 'empty_label' => '(all)',
278 'empty_data_label' => '(none)',
279 'empty_data_value' => '__NONE__',
280 'disable_empty' => 0,
281 'disable_cityupdate' => 1,
285 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
286 ' <OPTION VALUE="" SELECTED>'.
290 $html_posttotal .= ' )';
292 my $bulk_popup_link =
293 include( '/elements/popup_link_onclick.html',
294 'action' => "${p}edit/bulk-cust_main_county.html?taxnum=MAGIC_taxnum_MAGIC",
295 'actionlabel' => 'Bulk add new tax',
298 #default# 'width' => 540,
299 #default# 'color' => '#333399',
302 my $html_foot = <<END;
303 <SCRIPT TYPE="text/javascript">
305 function setAll(setTo) {
306 theForm = document.taxesForm;
307 for (i=0,n=theForm.elements.length;i<n;i++) {
308 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
309 theForm.elements[i].checked = setTo;
314 function toggleAll() {
315 theForm = document.taxesForm;
316 for (i=0,n=theForm.elements.length;i<n;i++) {
317 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
318 if ( theForm.elements[i].checked == true ) {
319 theForm.elements[i].checked = false;
321 theForm.elements[i].checked = true;
327 function bulkPopup(action) {
328 var bulk_popup_link = "$bulk_popup_link";
330 theForm = document.taxesForm;
331 for (i=0,n=theForm.elements.length;i<n;i++) {
332 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
333 && theForm.elements[i].checked == true
335 var name = theForm.elements[i].name;
336 var taxnum = name.replace(/cust_main_county/, '');
337 if ( bulkstring != '' ) {
338 bulkstring = bulkstring + ',';
340 bulkstring = bulkstring + taxnum;
344 bulkstring = bulkstring + ';action=' + action;
345 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
346 alert('Too many selections'); // should do some session thing...
349 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
350 eval(bulk_popup_link);
356 <A HREF="javascript:setAll(true)">select all</A> |
357 <A HREF="javascript:setAll(false)">unselect all</A> |
358 <A HREF="javascript:toggleAll()">toggle all</A>
360 <A HREF="javascript:void(0);" onClick="bulkPopup('add');">Add new tax to selected</A>
362 <A HREF="javascript:void(0);" onClick="bulkPopup('edit');">Bulk edit selected</A>
367 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
369 $hashref->{'country'} = $country;
370 $count_query .= ' WHERE country = '. dbh->quote($country);
373 $hashref->{'state'} = $state;
374 $count_query .= ' AND state = '. dbh->quote($state);
377 if ( $county eq '__NONE__' ) {
378 $hashref->{'county'} = '';
379 $count_query .= " AND ( county = '' OR county IS NULL ) ";
381 $hashref->{'county'} = $county;
382 $count_query .= ' AND county = '. dbh->quote($county);
386 $hashref->{'taxclass'} = $taxclass;
387 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
388 ' taxclass = '. dbh->quote($taxclass);
394 my @header = ( 'Country', 'State/Province', 'County', 'City' );
395 my @header2 = ( '', '', '', '', );
396 my @links = ( '', '', '', '', );
397 my @link_onclicks = ( '', '', '', '', );
401 sub { my $country = shift->country;
402 code2country($country). " ($country)";
404 sub { state_label($_[0]->state, $_[0]->country).
407 : ' '. expand_link( desc => 'Add States',
409 label => 'add states',
414 ? $_[0]->county. ' '.
415 collapse_link( col => 'county',
416 label=> 'remove counties',
420 expand_link( desc => 'Add Counties',
422 label => 'add counties',
426 ? $_[0]->city. ' '.
427 collapse_link( col => 'city',
428 label=> 'remove cities',
432 expand_link( desc => 'Add Cities',
434 label => 'add cities',
441 sub { shift->state ? '000000' : '999999' },
442 sub { shift->county ? '000000' : '999999' },
443 sub { shift->city ? '000000' : '999999' },
446 if ( $conf->exists('enable_taxclasses') ) {
447 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
448 push @header2, '(per-package classification)';
449 push @fields, sub { $_[0]->taxclass || '(all) '.
450 separate_taxclasses_link($_[0], 'Separate Taxclasses').
451 'separate taxclasses</A></FONT>'
453 push @color, sub { shift->taxclass ? '000000' : '999999' };
455 push @link_onclicks, '';
468 '(printed on invoices)',
476 my $cust_main_county = shift;
479 if ( $cb_oldrow->city ne $cust_main_county->city
480 || $cb_oldrow->county ne $cust_main_county->county
481 || $cb_oldrow->state ne $cust_main_county->state
482 || $cb_oldrow->country ne $cust_main_county->country
483 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
493 $cb_oldrow = $cust_main_county;
496 my $taxnum = $cust_main_county->taxnum;
497 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
505 sub { shift->taxname || 'Tax' },
506 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
512 sub { shift->taxname ? '000000' : '666666' },
513 sub { shift->tax ? '000000' : '666666' },
519 my @cell_style = map $cell_style_sub, (1..scalar(@header));
521 push @links, '', '', $edit_link, '';
522 push @link_onclicks, '', '', $edit_onclick, '';