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 ( $oldrow ne $row ) {
54 if ( $oldrow->country ne $row->country ) {
55 $cell_style = 'border-top:1px solid #000000';
56 } elsif ( $oldrow->state ne $row->state ) {
57 $cell_style = 'border-top:1px solid #cccccc'; #default?
58 } elsif ( $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',
86 my $taxnum = $param{'row'}->taxnum;
87 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
90 include( '/elements/popup_link.html',
91 'label' => $param{'label'},
93 'actionlabel' => $param{'desc'},
95 #default# 'width' => 540,
96 #default# 'color' => '#333399',
104 my $taxnum = $param{'row'}->taxnum;
105 my $url = "${p}edit/process/cust_main_county-collapse.cgi?$taxnum";
106 $url = "javascript:collapse_areyousure('$url')";
108 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
112 sub separate_taxclasses_link {
114 my $taxnum = $row->taxnum;
115 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
117 qq!<FONT SIZE="-1"><A HREF="$url">!;
120 #un-separate taxclasses too
126 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
128 #my $conf = new FS::Conf;
129 #my $money_char = $conf->config('money_char') || '$';
130 my $enable_taxclasses = $conf->exists('enable_taxclasses');
134 my $html_init = <<END;
136 function collapse_areyousure(href) {
137 if (confirm("Are you sure you want to remove all county tax rates for this state?") == true)
138 window.location.href = href;
142 Click on <u>add states</u> to specify a country's tax rates by state or province.
143 <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.
146 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
147 if $enable_taxclasses;
148 $html_init .= '<BR><BR>';
150 $html_init .= include('/elements/init_overlib.html');
155 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
159 $cgi->delete('country');
162 if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
164 $title = "$state, $title";
166 $cgi->delete('state');
169 if ( $country && $state &&
170 $cgi->param('county') =~
171 /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
175 if ( $county eq '__NONE__' ) {
176 $title = "No county, $title";
178 $title = "$county county, $title";
181 $cgi->delete('county');
183 $title = " for $title" if $title;
186 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
188 $title .= " for $taxclass tax class";
190 $cgi->delete('taxclass');
192 if ( $country || $taxclass ) {
193 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
196 $cgi->param('dummy', 1);
199 "window.location = '". $cgi->self_url.
200 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
201 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
202 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
204 #restore this so pagination works
205 $cgi->param('country', $country) if $country;
206 $cgi->param('state', $state ) if $state;
207 $cgi->param('county', $county ) if $county;
208 $cgi->param('taxclass', $county ) if $taxclass;
211 '<BR>( show country: '.
212 include('/elements/select-country.html',
213 'country' => $country,
214 'onchange' => $filter_change,
215 'empty_label' => '(all)',
216 'disable_empty' => 0,
217 'disable_stateupdate' => 1,
220 my %states_hash = $country ? states_hash($country) : ();
221 if ( scalar(keys(%states_hash)) > 1 ) {
224 include('/elements/select-state.html',
225 'country' => $country,
227 'onchange' => $filter_change,
228 'empty_label' => '(all)',
229 'disable_empty' => 0,
230 'disable_countyupdate' => 1,
234 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
235 ' <OPTION VALUE="" SELECTED>'.
239 my @counties = ( $country && $state ) ? counties($state, $country) : ();
240 if ( scalar(@counties) > 1 ) {
243 include('/elements/select-county.html',
244 'country' => $country,
247 'onchange' => $filter_change,
248 'empty_label' => '(all)',
249 'empty_data_label' => '(none)',
250 'empty_data_value' => '__NONE__',
251 'disable_empty' => 0,
252 'disable_countyupdate' => 1,
256 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
257 ' <OPTION VALUE="" SELECTED>'.
261 $html_posttotal .= ' )';
263 my $bulk_popup_link =
264 include( '/elements/popup_link_onclick.html',
265 'action' => "${p}edit/bulk-cust_main_county.html?taxnum=MAGIC_taxnum_MAGIC",
266 'actionlabel' => 'Bulk add new tax',
269 #default# 'width' => 540,
270 #default# 'color' => '#333399',
273 my $html_foot = <<END;
274 <SCRIPT TYPE="text/javascript">
276 function setAll(setTo) {
277 theForm = document.taxesForm;
278 for (i=0,n=theForm.elements.length;i<n;i++) {
279 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
280 theForm.elements[i].checked = setTo;
285 function toggleAll() {
286 theForm = document.taxesForm;
287 for (i=0,n=theForm.elements.length;i<n;i++) {
288 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
289 if ( theForm.elements[i].checked == true ) {
290 theForm.elements[i].checked = false;
292 theForm.elements[i].checked = true;
298 function bulkPopup(action) {
299 var bulk_popup_link = "$bulk_popup_link";
301 theForm = document.taxesForm;
302 for (i=0,n=theForm.elements.length;i<n;i++) {
303 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
304 && theForm.elements[i].checked == true
306 var name = theForm.elements[i].name;
307 var taxnum = name.replace(/cust_main_county/, '');
308 if ( bulkstring != '' ) {
309 bulkstring = bulkstring + ',';
311 bulkstring = bulkstring + taxnum;
315 bulkstring = bulkstring + ';action=' + action;
316 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
317 alert('Too many selections'); // should do some session thing...
320 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
321 eval(bulk_popup_link);
327 <A HREF="javascript:setAll(true)">select all</A> |
328 <A HREF="javascript:setAll(false)">unselect all</A> |
329 <A HREF="javascript:toggleAll()">toggle all</A>
331 <A HREF="javascript:void(0);" onClick="bulkPopup('add');">Add new tax to selected</A>
333 <A HREF="javascript:void(0);" onClick="bulkPopup('edit');">Bulk edit selected</A>
338 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
340 $hashref->{'country'} = $country;
341 $count_query .= ' WHERE country = '. dbh->quote($country);
344 $hashref->{'state'} = $state;
345 $count_query .= ' AND state = '. dbh->quote($state);
348 if ( $county eq '__NONE__' ) {
349 $hashref->{'county'} = '';
350 $count_query .= " AND ( county = '' OR county IS NULL ) ";
352 $hashref->{'county'} = $county;
353 $count_query .= ' AND county = '. dbh->quote($county);
357 $hashref->{'taxclass'} = $taxclass;
358 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
359 ' taxclass = '. dbh->quote($taxclass);
365 my @header = ( 'Country', 'State/Province', 'County',);
366 my @header2 = ( '', '', '', );
367 my @links = ( '', '', '', );
368 my @link_onclicks = ( '', '', '', );
372 sub { my $country = shift->country;
373 code2country($country). " ($country)";
375 sub { state_label($_[0]->state, $_[0]->country).
378 : ' '. expand_link( desc => 'Add States',
380 label => 'add states',
385 ? $_[0]->county. ' '.
386 collapse_link( label=> 'remove counties',
390 expand_link( desc => 'Add Counties',
392 label => 'add counties',
399 sub { shift->state ? '000000' : '999999' },
400 sub { shift->county ? '000000' : '999999' },
403 if ( $conf->exists('enable_taxclasses') ) {
404 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
405 push @header2, '(per-package classification)';
406 push @fields, sub { $_[0]->taxclass || '(all) '.
407 separate_taxclasses_link($_[0], 'Separate Taxclasses').
408 'separate taxclasses</A></FONT>'
410 push @color, sub { shift->taxclass ? '000000' : '999999' };
412 push @link_onclicks, '';
425 '(printed on invoices)',
433 my $cust_main_county = shift;
436 if ( $cb_oldrow->country ne $cust_main_county->country
437 || $cb_oldrow->state ne $cust_main_county->state
438 || $cb_oldrow->county ne $cust_main_county->county
439 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
449 $cb_oldrow = $cust_main_county;
452 my $taxnum = $cust_main_county->taxnum;
453 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
461 sub { shift->taxname || 'Tax' },
462 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
468 sub { shift->taxname ? '000000' : '666666' },
469 sub { shift->tax ? '000000' : '666666' },
475 my @cell_style = map $cell_style_sub, (1..scalar(@header));
477 push @links, '', '', $edit_link, '';
478 push @link_onclicks, '', '', $edit_onclick, '';