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