doh, revert stuff that shouldn't have been checked in
[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>Exempt<BR>per<BR>month</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     }
59
60     my $newsup=0;
61     if ( $j>1 && $i+$j+1 < @regions
62          && ( $hashref->{state} ne $regions[$i+$j+1]->state 
63               || $hashref->{country} ne $regions[$i+$j+1]->country
64               )
65          && ( ! $i
66               || $hashref->{state} ne $regions[$i-1]->state 
67               || $hashref->{country} ne $regions[$i-1]->country
68               )
69        ) {
70        $sup = $j-1;
71     } else {
72       $j = 1;
73     }
74
75     print "<TD ROWSPAN=$j", $hashref->{state}
76         ? ' BGCOLOR="#ffffff">'. $hashref->{state}
77         : qq! BGCOLOR="#cccccc">(ALL) <FONT SIZE=-1>!.
78           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
79           qq!">expand country</A></FONT>!;
80
81     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;
82
83     print "</TD>";
84   }
85
86 #  $sup=$newsup;
87
88   print "<TD";
89   if ( $hashref->{county} ) {
90     print ' BGCOLOR="#ffffff">'. $hashref->{county};
91   } else {
92     print ' BGCOLOR="#cccccc">(ALL)';
93     if ( $hashref->{state} ) {
94       print qq!<FONT SIZE=-1>!.
95           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
96           qq!">expand state</A></FONT>!;
97     }
98   }
99   print "</TD>";
100
101   print "<TD";
102   if ( $hashref->{taxclass} ) {
103     print ' BGCOLOR="#ffffff">'. $hashref->{taxclass};
104   } else {
105     print ' BGCOLOR="#cccccc">(ALL)';
106     if ( $enable_taxclasses ) {
107       print qq!<FONT SIZE=-1>!.
108             qq!<A HREF="${p}edit/cust_main_county-expand.cgi?taxclass!.
109             $hashref->{taxnum}. qq!">expand taxclasses</A></FONT>!;
110     }
111
112   }
113   print "</TD>";
114
115   print "<TD";
116   if ( $hashref->{taxname} ) {
117     print ' BGCOLOR="#ffffff">'. $hashref->{taxname};
118   } else {
119     print ' BGCOLOR="#cccccc">Tax';
120   }
121   print "</TD>";
122
123   print "<TD BGCOLOR=\"#ffffff\">$hashref->{tax}%</TD>".
124         '<TD BGCOLOR="#ffffff">$'.
125           sprintf("%.2f", $hashref->{exempt_amount} || 0). '</TD>'.
126         '</TR>';
127
128 }
129
130 print <<END;
131     </TABLE>
132   </BODY>
133 </HTML>
134 END
135
136 %>