fix linking to account list per access number
[freeside.git] / httemplate / browse / cust_main_county.cgi
1 <!-- mason kludge -->
2 <%
3
4 my $conf = new FS::Conf;
5 my $enable_taxclasses = $conf->exists('enable_taxclasses');
6
7 print header("Tax Rate Listing", menubar(
8   'Main Menu' => $p,
9   'Edit tax rates' => $p. "edit/cust_main_county.cgi",
10 )),<<END;
11     Click on <u>expand country</u> to specify a country's tax rates by state.
12     <BR>Click on <u>expand state</u> to specify a state's tax rates by county.
13 END
14
15 if ( $enable_taxclasses ) {
16   print '<BR>Click on <u>expand taxclasses</u> to specify tax classes';
17 }
18
19 print '<BR><BR>'. &table(). <<END;
20       <TR>
21         <TH><FONT SIZE=-1>Country</FONT></TH>
22         <TH><FONT SIZE=-1>State</FONT></TH>
23         <TH>County</TH>
24         <TH>Taxclass<BR><FONT SIZE=-1>(per-package classification)</FONT></TH>
25         <TH>Tax name<BR><FONT SIZE=-1>(printed on invoices)</FONT></TH>
26         <TH><FONT SIZE=-1>Tax</FONT></TH>
27         <TH><FONT SIZE=-1>Exemption</TH>
28       </TR>
29 END
30
31 my @regions = sort {    $a->country  cmp $b->country
32                      or $a->state    cmp $b->state
33                      or $a->county   cmp $b->county
34                      or $a->taxclass cmp $b->taxclass
35                    } qsearch('cust_main_county',{});
36
37 my $sup=0;
38 #foreach $cust_main_county ( @regions ) {
39 for ( my $i=0; $i<@regions; $i++ ) { 
40   my $cust_main_county = $regions[$i];
41   my $hashref = $cust_main_county->hashref;
42   print <<END;
43       <TR>
44         <TD BGCOLOR="#ffffff">$hashref->{country}</TD>
45 END
46
47   my $j;
48   if ( $sup ) {
49     $sup--;
50   } else {
51
52     #lookahead
53     for ( $j=1; $i+$j<@regions; $j++ ) {
54       last if $hashref->{country} ne $regions[$i+$j]->country
55            || $hashref->{state} ne $regions[$i+$j]->state
56            || $hashref->{tax} != $regions[$i+$j]->tax
57            || $hashref->{exempt_amount} != $regions[$i+$j]->exempt_amount
58            || $hashref->{setuptax} ne $regions[$i+$j]->setuptax
59            || $hashref->{recurtax} ne $regions[$i+$j]->recurtax;
60     }
61
62     my $newsup=0;
63     if ( $j>1 && $i+$j+1 < @regions
64          && ( $hashref->{state} ne $regions[$i+$j+1]->state 
65               || $hashref->{country} ne $regions[$i+$j+1]->country
66               )
67          && ( ! $i
68               || $hashref->{state} ne $regions[$i-1]->state 
69               || $hashref->{country} ne $regions[$i-1]->country
70               )
71        ) {
72        $sup = $j-1;
73     } else {
74       $j = 1;
75     }
76
77     print "<TD ROWSPAN=$j", $hashref->{state}
78         ? ' BGCOLOR="#ffffff">'. $hashref->{state}
79         : qq! BGCOLOR="#cccccc">(ALL) <FONT SIZE=-1>!.
80           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
81           qq!">expand country</A></FONT>!;
82
83     print qq! <FONT SIZE=-1><A HREF="${p}edit/process/cust_main_county-collapse.cgi?!. $hashref->{taxnum}. qq!">collapse state</A></FONT>! if $j>1;
84
85     print "</TD>";
86   }
87
88 #  $sup=$newsup;
89
90   print "<TD";
91   if ( $hashref->{county} ) {
92     print ' BGCOLOR="#ffffff">'. $hashref->{county};
93   } else {
94     print ' BGCOLOR="#cccccc">(ALL)';
95     if ( $hashref->{state} ) {
96       print qq!<FONT SIZE=-1>!.
97           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
98           qq!">expand state</A></FONT>!;
99     }
100   }
101   print "</TD>";
102
103   print "<TD";
104   if ( $hashref->{taxclass} ) {
105     print ' BGCOLOR="#ffffff">'. $hashref->{taxclass};
106   } else {
107     print ' BGCOLOR="#cccccc">(ALL)';
108     if ( $enable_taxclasses ) {
109       print qq!<FONT SIZE=-1>!.
110             qq!<A HREF="${p}edit/cust_main_county-expand.cgi?taxclass!.
111             $hashref->{taxnum}. qq!">expand taxclasses</A></FONT>!;
112     }
113
114   }
115   print "</TD>";
116
117   print "<TD";
118   if ( $hashref->{taxname} ) {
119     print ' BGCOLOR="#ffffff">'. $hashref->{taxname};
120   } else {
121     print ' BGCOLOR="#cccccc">Tax';
122   }
123   print "</TD>";
124
125   print "<TD BGCOLOR=\"#ffffff\">$hashref->{tax}%</TD>".
126         '<TD BGCOLOR="#ffffff">';
127   print '$'. sprintf("%.2f", $hashref->{exempt_amount} ).
128         '&nbsp;per&nbsp;month<BR>'
129     if $hashref->{exempt_amount} > 0;
130   print 'Setup&nbsp;fee<BR>' if $hashref->{setuptax} =~ /^Y$/i;
131   print 'Recurring&nbsp;fee<BR>' if $hashref->{recurtax} =~ /^Y$/i;
132   print '</TD></TR>';
133
134 }
135
136 print <<END;
137     </TABLE>
138   </BODY>
139 </HTML>
140 END
141
142 %>