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 && $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
153 if ( $county eq '__NONE__' ) {
154 $title = "No county, $title";
156 $title = "$county county, $title";
159 $cgi->delete('county');
161 $title = " for $title" if $title;
164 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
166 $title .= " for $taxclass tax class";
168 $cgi->delete('taxclass');
170 if ( $country || $taxclass ) {
171 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
174 $cgi->param('dummy', 1);
177 "window.location = '". $cgi->self_url.
178 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
179 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
180 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
182 #restore this so pagination works
183 $cgi->param('country', $country) if $country;
184 $cgi->param('state', $state ) if $state;
185 $cgi->param('county', $county ) if $county;
186 $cgi->param('taxclass', $county ) if $taxclass;
189 '<BR>( show country: '.
190 include('/elements/select-country.html',
191 'country' => $country,
192 'onchange' => $filter_change,
193 'empty_label' => '(all)',
194 'disable_empty' => 0,
195 'disable_stateupdate' => 1,
198 my %states_hash = $country ? states_hash($country) : ();
199 if ( scalar(keys(%states_hash)) > 1 ) {
202 include('/elements/select-state.html',
203 'country' => $country,
205 'onchange' => $filter_change,
206 'empty_label' => '(all)',
207 'disable_empty' => 0,
208 'disable_countyupdate' => 1,
212 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
213 ' <OPTION VALUE="" SELECTED>'.
217 my @counties = ( $country && $state ) ? counties($state, $country) : ();
218 if ( scalar(@counties) > 1 ) {
221 include('/elements/select-county.html',
222 'country' => $country,
225 'onchange' => $filter_change,
226 'empty_label' => '(all)',
227 'empty_data_label' => '(none)',
228 'empty_data_value' => '__NONE__',
229 'disable_empty' => 0,
230 'disable_countyupdate' => 1,
234 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
235 ' <OPTION VALUE="" SELECTED>'.
239 $html_posttotal .= ' )';
241 my $bulk_popup_link =
242 include( '/elements/popup_link_onclick.html',
243 'action' => "${p}edit/bulk-cust_main_county.html?MAGIC_taxnum_MAGIC",
244 'actionlabel' => 'Bulk add new tax',
247 #default# 'width' => 540,
248 #default# 'color' => '#333399',
251 my $html_foot = <<END;
252 <SCRIPT TYPE="text/javascript">
254 function setAll(setTo) {
255 theForm = document.taxesForm;
256 for (i=0,n=theForm.elements.length;i<n;i++) {
257 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
258 theForm.elements[i].checked = setTo;
263 function toggleAll() {
264 theForm = document.taxesForm;
265 for (i=0,n=theForm.elements.length;i<n;i++) {
266 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
267 if ( theForm.elements[i].checked == true ) {
268 theForm.elements[i].checked = false;
270 theForm.elements[i].checked = true;
276 function bulkPopup() {
277 var bulk_popup_link = "$bulk_popup_link";
279 theForm = document.taxesForm;
280 for (i=0,n=theForm.elements.length;i<n;i++) {
281 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
282 && theForm.elements[i].checked == true
284 var name = theForm.elements[i].name;
285 var taxnum = name.replace(/cust_main_county/, '');
286 if ( bulkstring != '' ) {
287 bulkstring = bulkstring + ',';
289 bulkstring = bulkstring + taxnum;
293 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
294 alert('Too many selections'); // should do some session thing...
297 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
298 eval(bulk_popup_link);
304 <A HREF="javascript:setAll(true)">select all</A> |
305 <A HREF="javascript:setAll(false)">unselect all</A> |
306 <A HREF="javascript:toggleAll()">toggle all</A>
308 <A HREF="javascript:void(0);" onClick="bulkPopup();">Add new tax to selected</A>
313 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
315 $hashref->{'country'} = $country;
316 $count_query .= ' WHERE country = '. dbh->quote($country);
319 $hashref->{'state'} = $state;
320 $count_query .= ' AND state = '. dbh->quote($state);
323 if ( $county eq '__NONE__' ) {
324 $hashref->{'county'} = '';
325 $count_query .= " AND ( county = '' OR county IS NULL ) ";
327 $hashref->{'county'} = $county;
328 $count_query .= ' AND county = '. dbh->quote($county);
332 $hashref->{'taxclass'} = $taxclass;
333 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
334 ' taxclass = '. dbh->quote($taxclass);
340 my @header = ( 'Country', 'State/Province', 'County',);
341 my @header2 = ( '', '', '', );
342 my @links = ( '', '', '', );
343 my @link_onclicks = ( '', '', '', );
347 sub { my $country = shift->country;
348 code2country($country). " ($country)";
350 sub { state_label($_[0]->state, $_[0]->country).
353 : ' '. expand_link( desc => 'Add States',
355 label => 'add states',
359 sub { $_[0]->county || '(all) '.
360 expand_link( desc => 'Add Counties',
362 label => 'add counties',
369 sub { shift->state ? '000000' : '999999' },
370 sub { shift->county ? '000000' : '999999' },
373 if ( $conf->exists('enable_taxclasses') ) {
374 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
375 push @header2, '(per-package classification)';
376 push @fields, sub { $_[0]->taxclass || '(all) '.
377 separate_taxclasses_link($_[0], 'Separate Taxclasses').
378 'separate taxclasses</A></FONT>'
380 push @color, sub { shift->taxclass ? '000000' : '999999' };
382 push @link_onclicks, '';
395 '(printed on invoices)',
403 my $cust_main_county = shift;
406 if ( $cb_oldrow->country ne $cust_main_county->country
407 || $cb_oldrow->state ne $cust_main_county->state
408 || $cb_oldrow->county ne $cust_main_county->county
409 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
419 $cb_oldrow = $cust_main_county;
422 my $taxnum = $cust_main_county->taxnum;
423 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
431 sub { shift->taxname || 'Tax' },
432 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
438 sub { shift->taxname ? '000000' : '666666' },
439 sub { shift->tax ? '000000' : '666666' },
445 my @cell_style = map $cell_style_sub, (1..scalar(@header));
447 push @links, '', '', $edit_link, '';
448 push @link_onclicks, '', '', $edit_onclick, '';