mason error
[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</TH>
25         <TH><FONT SIZE=-1>Tax</FONT></TH>
26         <TH><FONT SIZE=-1>Exempt<BR>per<BR>month</TH>
27       </TR>
28 END
29
30 my @regions = sort {    $a->country  cmp $b->country
31                      or $a->state    cmp $b->state
32                      or $a->county   cmp $b->county
33                      or $a->taxclass cmp $b->taxclass
34                    } qsearch('cust_main_county',{});
35
36 my $sup=0;
37 #foreach $cust_main_county ( @regions ) {
38 for ( my $i=0; $i<@regions; $i++ ) { 
39   my $cust_main_county = $regions[$i];
40   my $hashref = $cust_main_county->hashref;
41   print <<END;
42       <TR>
43         <TD BGCOLOR="#ffffff">$hashref->{country}</TD>
44 END
45
46   my $j;
47   if ( $sup ) {
48     $sup--;
49   } else {
50
51     #lookahead
52     for ( $j=1; $i+$j<@regions; $j++ ) {
53       last if $hashref->{country} ne $regions[$i+$j]->country
54            || $hashref->{state} ne $regions[$i+$j]->state
55            || $hashref->{tax} != $regions[$i+$j]->tax
56            || $hashref->{exempt_amount} != $regions[$i+$j]->exempt_amount;
57     }
58
59     my $newsup=0;
60     if ( $j>1 && $i+$j+1 < @regions
61          && ( $hashref->{state} ne $regions[$i+$j+1]->state 
62               || $hashref->{country} ne $regions[$i+$j+1]->country
63               )
64          && ( ! $i
65               || $hashref->{state} ne $regions[$i-1]->state 
66               || $hashref->{country} ne $regions[$i-1]->country
67               )
68        ) {
69        $sup = $j-1;
70     } else {
71       $j = 1;
72     }
73
74     print "<TD ROWSPAN=$j", $hashref->{state}
75         ? ' BGCOLOR="#ffffff">'. $hashref->{state}
76         : qq! BGCOLOR="#cccccc">(ALL) <FONT SIZE=-1>!.
77           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
78           qq!">expand country</A></FONT>!;
79
80     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;
81
82     print "</TD>";
83   }
84
85 #  $sup=$newsup;
86
87   print "<TD";
88   if ( $hashref->{county} ) {
89     print ' BGCOLOR="#ffffff">'. $hashref->{county};
90   } else {
91     print ' BGCOLOR="#cccccc">(ALL)';
92     if ( $hashref->{state} ) {
93       print qq!<FONT SIZE=-1>!.
94           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
95           qq!">expand state</A></FONT>!;
96     }
97   }
98   print "</TD>";
99
100   print "<TD";
101   if ( $hashref->{taxclass} ) {
102     print ' BGCOLOR="#ffffff">'. $hashref->{taxclass};
103   } else {
104     print ' BGCOLOR="#cccccc">(ALL)';
105     if ( $enable_taxclasses ) {
106       print qq!<FONT SIZE=-1>!.
107             qq!<A HREF="${p}edit/cust_main_county-expand.cgi?taxclass!.
108             $hashref->{taxnum}. qq!">expand taxclasses</A></FONT>!;
109     }
110
111   }
112   print "</TD>";
113
114   print "<TD BGCOLOR=\"#ffffff\">$hashref->{tax}%</TD>".
115         '<TD BGCOLOR="#ffffff">$'.
116           sprintf("%.2f", $hashref->{exempt_amount} || 0). '</TD>'.
117         '</TR>';
118
119 }
120
121 print <<END;
122     </TABLE>
123   </BODY>
124 </HTML>
125 END
126
127 %>