8fbd7faadadba0780aefee02c79eaa426d4f54b0
[freeside.git] / httemplate / browse / cust_main_county.cgi
1 <!-- mason kludge -->
2 <%
3
4 print header("Tax Rate Listing", menubar(
5   'Main Menu' => $p,
6   'Edit tax rates' => $p. "edit/cust_main_county.cgi",
7 )),<<END;
8     Click on <u>expand country</u> to specify a country's tax rates by state.
9     <BR>Click on <u>expand state</u> to specify a state's tax rates by county.
10     <BR><BR>
11 END
12 print &table(), <<END;
13       <TR>
14         <TH><FONT SIZE=-1>Country</FONT></TH>
15         <TH><FONT SIZE=-1>State</FONT></TH>
16         <TH>County</TH>
17         <TH><FONT SIZE=-1>Tax</FONT></TH>
18       </TR>
19 END
20
21 my @regions = sort {    $a->country cmp $b->country
22                      or $a->state   cmp $b->state
23                      or $a->county  cmp $b->county
24                    } qsearch('cust_main_county',{});
25
26 my $sup=0;
27 #foreach $cust_main_county ( @regions ) {
28 for ( my $i=0; $i<@regions; $i++ ) { 
29   my $cust_main_county = $regions[$i];
30   my $hashref = $cust_main_county->hashref;
31   print <<END;
32       <TR>
33         <TD>$hashref->{country}</TD>
34 END
35
36   my $j;
37   if ( $sup ) {
38     $sup--;
39   } else {
40
41     #lookahead
42     for ( $j=1; $i+$j<@regions; $j++ ) {
43       last if $hashref->{country} ne $regions[$i+$j]->country
44            || $hashref->{state} ne $regions[$i+$j]->state
45            || $hashref->{tax} != $regions[$i+$j]->tax;
46     }
47
48     my $newsup=0;
49     if ( $j>1 && $i+$j+1 < @regions
50          && ( $hashref->{state} ne $regions[$i+$j+1]->state 
51               || $hashref->{country} ne $regions[$i+$j+1]->country
52               )
53          && ( ! $i
54               || $hashref->{state} ne $regions[$i-1]->state 
55               || $hashref->{country} ne $regions[$i-1]->country
56               )
57        ) {
58        $sup = $j-1;
59     } else {
60       $j = 1;
61     }
62
63     print "<TD ROWSPAN=$j>", $hashref->{state}
64         ? $hashref->{state}
65         : qq!(ALL) <FONT SIZE=-1>!.
66           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
67           qq!">expand country</A></FONT>!;
68
69     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;
70
71     print "</TD>";
72   }
73
74 #  $sup=$newsup;
75
76   print "<TD>";
77   if ( $hashref->{county} ) {
78     print $hashref->{county};
79   } else {
80     print "(ALL)";
81     if ( $hashref->{state} ) {
82       print qq!<FONT SIZE=-1>!.
83           qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}.
84           qq!">expand state</A></FONT>!;
85     }
86   }
87   print "</TD>";
88
89   print <<END;
90         <TD>$hashref->{tax}%</TD>
91       </TR>
92 END
93
94 }
95
96 print <<END;
97     </TABLE>
98     </CENTER>
99   </BODY>
100 </HTML>
101 END
102
103 %>